@helia/routers 3.1.3-9f51b175 → 3.1.3-e502d45f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +18 -19
- package/dist/index.min.js.map +4 -4
- package/package.json +14 -21
package/dist/index.min.js
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaRouters = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var HeliaRouters=(()=>{var
|
|
3
|
-
`,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return w;function w(A,m,T){var B=this;if(!(B instanceof w))return new w(A,m,T);B.time=+A||0,B.nano=+m||0,B.year=+T||0,C(B)}function C(A){var m,T,B,I=A.year,g=A.time,y=A.nano,p=((y<0||a<=y)&&(y-=(T=Math.floor(y/a))*a,g+=T,T=1),I%t);return(g<-i||i<g||p)&&((m=f(g/o))&&(I+=m*t,g-=m*o),(B=b(g)).setUTCFullYear(p+B.getUTCFullYear()),B=(g=+B)+(m=f((I-=p)/t))*o,m&&-i<=B&&B<=i&&(I-=m*t,g=B),T=1),T&&(A.year=I,A.time=g,A.nano=y),A}function b(A){var m=new Date(0);return m.setTime(A),m}function P(I,B){I=+I||0;var T=f((B=(B|0)*s)/n)+f(I/n),B=B%n+I%n,I=f(B/n);return I&&(T+=I,B-=I*n),new w(1e3*B,0,T*t)}function S(A,m,T,B,I,g){return function(p,v){var L=C(this);p=p||new Array(8),k(p,v|=0);var R=Math.floor(L.time/1e3),L=L.year*(r*e/t),D=f(L/s)+f(R/s),L=L%s+R%s,R=Math.floor(L/s);return R&&(D+=R,L-=R*s),y(p,v+I,D),y(p,v+g,L),p};function y(p,v,D){p[v+A]=D>>24&255,p[v+m]=D>>16&255,p[v+T]=D>>8&255,p[v+B]=255&D}}function N(A,m,T,B,I,g){return function(p,v){k(p,v|=0);var D=y(p,v+I);return P(y(p,v+g),D)};function y(p,v){return 16777216*p[v+A]+(p[v+m]<<16|p[v+T]<<8|p[v+B])}}function k(A,m){if(A=A&&A.length,A==null)throw new TypeError("Invalid Buffer");if(A<m+8)throw new RangeError("Out of range")}function F(A){return(9<A?"":"0")+(0|A)}function V(A,m){return(c+(0|A)).substr(-m)}}()});var Hf=xa((YE,ea)=>{"use strict";var $0=Object.prototype.hasOwnProperty,vt="~";function En(){}Object.create&&(En.prototype=Object.create(null),new En().__proto__||(vt=!1));function q0(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function qf(e,t,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new q0(r,n||e,o),s=vt?vt+t:t;return e._events[s]?e._events[s].fn?e._events[s]=[e._events[s],i]:e._events[s].push(i):(e._events[s]=i,e._eventsCount++),e}function Lo(e,t){--e._eventsCount===0?e._events=new En:delete e._events[t]}function bt(){this._events=new En,this._eventsCount=0}bt.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)$0.call(r,n)&&t.push(vt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};bt.prototype.listeners=function(t){var r=vt?vt+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};bt.prototype.listenerCount=function(t){var r=vt?vt+t:t,n=this._events[r];return n?n.fn?1:n.length:0};bt.prototype.emit=function(t,r,n,o,i,s){var a=vt?vt+t:t;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,u,l;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,o),!0;case 5:return c.fn.call(c.context,r,n,o,i),!0;case 6:return c.fn.call(c.context,r,n,o,i,s),!0}for(l=1,u=new Array(f-1);l<f;l++)u[l-1]=arguments[l];c.fn.apply(c.context,u)}else{var d=c.length,h;for(l=0;l<d;l++)switch(c[l].once&&this.removeListener(t,c[l].fn,void 0,!0),f){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,r);break;case 3:c[l].fn.call(c[l].context,r,n);break;case 4:c[l].fn.call(c[l].context,r,n,o);break;default:if(!u)for(h=1,u=new Array(f-1);h<f;h++)u[h-1]=arguments[h];c[l].fn.apply(c[l].context,u)}}return!0};bt.prototype.on=function(t,r,n){return qf(this,t,r,n,!1)};bt.prototype.once=function(t,r,n){return qf(this,t,r,n,!0)};bt.prototype.removeListener=function(t,r,n,o){var i=vt?vt+t:t;if(!this._events[i])return this;if(!r)return Lo(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&Lo(this,i);else{for(var a=0,c=[],f=s.length;a<f;a++)(s[a].fn!==r||o&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[i]=c.length===1?c[0]:c:Lo(this,i)}return this};bt.prototype.removeAllListeners=function(t){var r;return t?(r=vt?vt+t:t,this._events[r]&&Lo(this,r)):(this._events=new En,this._eventsCount=0),this};bt.prototype.off=bt.prototype.removeListener;bt.prototype.addListener=bt.prototype.on;bt.prefixed=vt;bt.EventEmitter=bt;typeof ea<"u"&&(ea.exports=bt)});var lm={};It(lm,{delegatedHTTPRouting:()=>Qf,delegatedHTTPRoutingDefaults:()=>$o,httpGatewayRouting:()=>al,libp2pRouting:()=>cl});var ba=Symbol.for("@libp2p/content-routing");var zo=Symbol.for("@libp2p/peer-id");var Ea=Symbol.for("@libp2p/peer-routing");var st=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},tr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Ct=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Tn=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},er=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var rr=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Wo={};It(Wo,{base32:()=>ee,base32hex:()=>Al,base32hexpad:()=>Cl,base32hexpadupper:()=>Tl,base32hexupper:()=>Il,base32pad:()=>Sl,base32padupper:()=>vl,base32upper:()=>El,base32z:()=>Bl});var gm=new Uint8Array(0);function Sa(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 ae(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 va(e){return new TextEncoder().encode(e)}function Aa(e){return new TextDecoder().decode(e)}function ml(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 a=e.length,c=e.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var w=0,C=0,b=0,P=x.length;b!==P&&x[b]===0;)b++,w++;for(var S=(P-b)*u+1>>>0,N=new Uint8Array(S);b!==P;){for(var k=x[b],F=0,V=S-1;(k!==0||F<C)&&V!==-1;V--,F++)k+=256*N[V]>>>0,N[V]=k%a>>>0,k=k/a>>>0;if(k!==0)throw new Error("Non-zero carry");C=F,b++}for(var A=S-C;A!==S&&N[A]===0;)A++;for(var m=c.repeat(w);A<S;++A)m+=e.charAt(N[A]);return m}function d(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var w=0;if(x[w]!==" "){for(var C=0,b=0;x[w]===c;)C++,w++;for(var P=(x.length-w)*f+1>>>0,S=new Uint8Array(P);x[w];){var N=r[x.charCodeAt(w)];if(N===255)return;for(var k=0,F=P-1;(N!==0||k<b)&&F!==-1;F--,k++)N+=a*S[F]>>>0,S[F]=N%256>>>0,N=N/256>>>0;if(N!==0)throw new Error("Non-zero carry");b=k,w++}if(x[w]!==" "){for(var V=P-b;V!==P&&S[V]===0;)V++;for(var A=new Uint8Array(C+(P-V)),m=C;V!==P;)A[m++]=S[V++];return A}}}function h(x){var w=d(x);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:h}}var yl=ml,gl=yl,Ca=gl;var jo=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")}},Go=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 Ta(this,t)}},Zo=class{decoders;constructor(t){this.decoders=t}or(t){return Ta(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 Ta(e,t){return new Zo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Yo=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 jo(t,r,n),this.decoder=new Go(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function nr({name:e,prefix:t,encode:r,decode:n}){return new Yo(e,t,r,n)}function Ce({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ca(r,e);return nr({prefix:t,name:e,encode:n,decode:i=>ae(o(i))})}function xl(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let f=0;f<o;++f){let u=t[e[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function wl(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],s+=8;s>r;)s-=r,i+=t[o&a>>s];if(s!==0&&(i+=t[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function bl(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=bl(n);return nr({prefix:t,name:e,encode(i){return wl(i,n,r)},decode(i){return xl(i,o,r,e)}})}var ee=nt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),El=nt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Sl=nt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),vl=nt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Al=nt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Il=nt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Cl=nt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Tl=nt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Bl=nt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Xo={};It(Xo,{base58btc:()=>W,base58flickr:()=>_l});var W=Ce({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),_l=Ce({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ti={};It(ti,{base64:()=>Jo,base64pad:()=>Pl,base64url:()=>Qo,base64urlpad:()=>Dl});var Jo=nt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Pl=nt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Qo=nt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Dl=nt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function Ul(e,t){try{if(typeof e=="string"&&e.length>0)return Rl(e);if(typeof e=="number"&&isFinite(e))return t?.long?Ll(e):Nl(e);throw new Error("Value is not a string or number.")}catch(r){let n=Ol(r)?`${r.message}. value=${JSON.stringify(e)}`:"An unknown error has occured.";throw new Error(n)}}function Rl(e){if(e=String(e),e.length>100)throw new Error("Value exceeds the maximum length of 100 characters.");let t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(!t)return NaN;let r=parseFloat(t[1]),n=(t[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return r*315576e5;case"weeks":case"week":case"w":return r*6048e5;case"days":case"day":case"d":return r*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return r*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return r*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return r*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:throw new Error(`The unit ${n} was matched, but no matching case exists.`)}}var _n=Ul;function Nl(e){let t=Math.abs(e);return 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 Ll(e){let t=Math.abs(e);return t>=864e5?Bn(e,t,864e5,"day"):t>=36e5?Bn(e,t,36e5,"hour"):t>=6e4?Bn(e,t,6e4,"minute"):t>=1e3?Bn(e,t,1e3,"second"):`${e} ms`}function Bn(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function Ol(e){return typeof e=="object"&&e!==null&&"message"in e}function ei(e){r.debug=r,r.default=r,r.coerce=c,r.disable=i,r.enable=o,r.enabled=s,r.humanize=_n,r.destroy=f,Object.keys(e).forEach(u=>{r[u]=e[u]}),r.names=[],r.skips=[],r.formatters={};function t(u){let l=0;for(let d=0;d<u.length;d++)l=(l<<5)-l+u.charCodeAt(d),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=t;function r(u){let l,d=null,h,x;function w(...C){if(!w.enabled)return;let b=w,P=Number(new Date),S=P-(l||P);b.diff=S,b.prev=l,b.curr=P,l=P,C[0]=r.coerce(C[0]),typeof C[0]!="string"&&C.unshift("%O");let N=0;C[0]=C[0].replace(/%([a-zA-Z%])/g,(F,V)=>{if(F==="%%")return"%";N++;let A=r.formatters[V];if(typeof A=="function"){let m=C[N];F=A.call(b,m),C.splice(N,1),N--}return F}),r.formatArgs.call(b,C),(b.log||r.log).apply(b,C)}return w.namespace=u,w.useColors=r.useColors(),w.color=r.selectColor(u),w.extend=n,w.destroy=r.destroy,Object.defineProperty(w,"enabled",{enumerable:!0,configurable:!1,get:()=>d!==null?d:(h!==r.namespaces&&(h=r.namespaces,x=r.enabled(u)),x),set:C=>{d=C}}),typeof r.init=="function"&&r.init(w),w}function n(u,l){let d=r(this.namespace+(typeof l>"u"?":":l)+u);return d.log=this.log,d}function o(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];let l,d=(typeof u=="string"?u:"").split(/[\s,]+/),h=d.length;for(l=0;l<h;l++)d[l]&&(u=d[l].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(a),...r.skips.map(a).map(l=>"-"+l)].join(",");return r.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let l,d;for(l=0,d=r.skips.length;l<d;l++)if(r.skips[l].test(u))return!1;for(l=0,d=r.names.length;l<d;l++)if(r.names[l].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function c(u){return u instanceof Error?u.stack??u.message:u}function f(){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 Pn=ql(),kl=["#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 Kl(){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 Fl(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+_n(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 Vl=console.debug??console.log??(()=>{});function Ml(e){try{e?Pn?.setItem("debug",e):Pn?.removeItem("debug")}catch{}}function $l(){let e;try{e=Pn?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function ql(){try{return localStorage}catch{}}function Hl(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Ba=ei({formatArgs:Fl,save:Ml,load:$l,useColors:Kl,setupFormatters:Hl,colors:kl,storage:Pn,log:Vl});var Tt=Ba;Tt.formatters.b=e=>e==null?"undefined":W.baseEncode(e);Tt.formatters.t=e=>e==null?"undefined":ee.baseEncode(e);Tt.formatters.m=e=>e==null?"undefined":Jo.baseEncode(e);Tt.formatters.p=e=>e==null?"undefined":e.toString();Tt.formatters.c=e=>e==null?"undefined":e.toString();Tt.formatters.k=e=>e==null?"undefined":e.toString();Tt.formatters.a=e=>e==null?"undefined":e.toString();Tt.formatters.e=e=>e==null?"undefined":_a(e.stack)??_a(e.message)??e.toString();function zl(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 Te(e){let t=zl(`${e}:trace`);return Tt.enabled(`${e}:trace`)&&Tt.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(t=Tt(`${e}:trace`)),Object.assign(Tt(e),{error:Tt(`${e}:error`),trace:t})}function _a(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var ri={};It(ri,{base36:()=>or,base36upper:()=>jl});var or=Ce({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),jl=Ce({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Gl=Ua,Pa=128,Zl=127,Yl=~Zl,Wl=Math.pow(2,31);function Ua(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Wl;)t[r++]=e&255|Pa,e/=128;for(;e&Yl;)t[r++]=e&255|Pa,e>>>=7;return t[r]=e|0,Ua.bytes=r-n+1,t}var Xl=ni,Jl=128,Da=127;function ni(e,n){var r=0,n=n||0,o=0,i=n,s,a=e.length;do{if(i>=a)throw ni.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&Da)<<o:(s&Da)*Math.pow(2,o),o+=7}while(s>=Jl);return ni.bytes=i-n,r}var Ql=Math.pow(2,7),td=Math.pow(2,14),ed=Math.pow(2,21),rd=Math.pow(2,28),nd=Math.pow(2,35),od=Math.pow(2,42),id=Math.pow(2,49),sd=Math.pow(2,56),ad=Math.pow(2,63),cd=function(e){return e<Ql?1:e<td?2:e<ed?3:e<rd?4:e<nd?5:e<od?6:e<id?7:e<sd?8:e<ad?9:10},ud={encode:Gl,decode:Xl,encodingLength:cd},fd=ud,kr=fd;function Kr(e,t=0){return[kr.decode(e,t),kr.decode.bytes]}function ir(e,t,r=0){return kr.encode(e,t,r),t}function sr(e){return kr.encodingLength(e)}function jt(e,t){let r=t.byteLength,n=sr(e),o=n+sr(r),i=new Uint8Array(o+r);return ir(e,i,0),ir(r,i,n),i.set(t,o),new ar(e,r,t,i)}function Ve(e){let t=ae(e),[r,n]=Kr(t),[o,i]=Kr(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new ar(r,o,s,t)}function Ra(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Sa(e.bytes,r.bytes)}}var ar=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Na(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return dd(r,oi(e),t??W.encoder);default:return hd(r,oi(e),t??ee.encoder)}}var La=new WeakMap;function oi(e){let t=La.get(e);if(t==null){let r=new Map;return La.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!==Fr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==pd)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=jt(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&&Ra(t.multihash,n.multihash)}toString(t){return Na(this,t)}toJSON(){return{"/":Na(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??Oa(n,o,i.bytes))}else if(r[md]===!0){let{version:n,multihash:o,code:i}=r,s=Ve(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!==Fr)throw new Error(`Version 0 CID must use dag-pb (code: ${Fr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Oa(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Fr,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=ae(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 ar(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[l,d]=Kr(t.subarray(r));return r+=d,l},o=n(),i=Fr;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),f=r+c,u=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(t,r){let[n,o]=ld(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 oi(i).set(n,t),i}};function ld(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 ee.prefix:{let r=t??ee;return[ee.prefix,r.decode(e)]}case or.prefix:{let r=t??or;return[or.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 dd(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 hd(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 Fr=112,pd=18;function Oa(e,t,r){let n=sr(e),o=n+sr(t),i=new Uint8Array(o+r.byteLength);return ir(e,i,0),ir(t,i,n),i.set(r,o),i}var md=Symbol.for("@ipld/js-cid/CID");var ii={};It(ii,{identity:()=>Pt});var ka=0,yd="identity",Ka=ae;function gd(e){return jt(ka,Ka(e))}var Pt={code:ka,name:yd,encode:Ka,digest:gd};function X(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 ce(e=0){return new Uint8Array(e)}function Dt(e=0){return new Uint8Array(e)}function Mt(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=Dt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Va=Symbol.for("@achingbrain/uint8arraylist");function Fa(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 cr(e){return!!e?.[Va]}var Ut=class e{bufs;length;[Va]=!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(cr(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(cr(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=Fa(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Fa(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(cr(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 Mt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Mt(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],a=o,c=a+s.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,u=r>a&&r<=c;if(f&&u){if(t===a&&r===c){n.push(s);break}let l=t-a;n.push(s.subarray(l,l+(r-t)));break}if(f){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(u){if(r===c){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!cr(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 l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=r;l<=c;l+=u){u=0;for(let d=f;d>=0;d--){let h=this.get(l+d);if(n[d]!==h){u=Math.max(1,d-a[h]);break}}if(u===0)return l}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=Dt(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=ce(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=ce(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=ce(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=Dt(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=ce(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=ce(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=ce(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=ce(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=ce(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(!X(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 si={};It(si,{base10:()=>xd});var xd=Ce({prefix:"9",name:"base10",alphabet:"0123456789"});var ai={};It(ai,{base16:()=>wd,base16upper:()=>bd});var wd=nt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),bd=nt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ci={};It(ci,{base2:()=>Ed});var Ed=nt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ui={};It(ui,{base256emoji:()=>Cd});var Ma=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}"),Sd=Ma.reduce((e,t,r)=>(e[r]=t,e),[]),vd=Ma.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Ad(e){return e.reduce((t,r)=>(t+=Sd[r],t),"")}function Id(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=vd[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Cd=nr({prefix:"\u{1F680}",name:"base256emoji",encode:Ad,decode:Id});var fi={};It(fi,{base8:()=>Td});var Td=nt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var li={};It(li,{identity:()=>Bd});var Bd=nr({prefix:"\0",name:"identity",encode:e=>Aa(e),decode:e=>va(e)});var hy=new TextEncoder,py=new TextDecoder;var pi={};It(pi,{sha256:()=>Vr,sha512:()=>Dd});function hi({name:e,code:t,encode:r}){return new di(e,t,r)}var di=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?jt(this.code,r):r.then(n=>jt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function qa(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Vr=hi({name:"sha2-256",code:18,encode:qa("SHA-256")}),Dd=hi({name:"sha2-512",code:19,encode:qa("SHA-512")});var Mr={...li,...ci,...fi,...si,...ai,...Wo,...ri,...Xo,...ti,...ui},Cy={...pi,...ii};function za(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Ha=za("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),mi=za("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=Dt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Ud={utf8:Ha,"utf-8":Ha,hex:Mr.base16,latin1:mi,ascii:mi,binary:mi,...Mr},Un=Ud;function q(e,t="utf8"){let r=Un[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function H(e,t="utf8"){let r=Un[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Rd=parseInt("11111",2),yi=parseInt("10000000",2),Nd=parseInt("01111111",2),ja={0:$r,1:$r,2:Ld,3:Kd,4:Fd,5:kd,6:Od,16:$r,22:$r,48:$r};function ue(e,t={offset:0}){let r=e[t.offset]&Rd;if(t.offset++,ja[r]!=null)return ja[r](e,t);throw new Error("No decoder for tag "+r)}function qr(e,t){let r=0;if((e[t.offset]&yi)===yi){let n=e[t.offset]&Nd,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){qr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=ue(e,t);if(n===null)break;r.push(n)}return r}function Ld(e,t){let r=qr(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 Od(e,t){let r=qr(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 a=`${i}.${s}`,c=[];for(;t.offset<n;){let f=e[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let l=0;l<c.length;l++)u+=c[l]<<l*7;a+=`.${u}`,c=[]}}return a}function kd(e,t){return t.offset++,null}function Kd(e,t){let r=qr(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 Fd(e,t){let r=qr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Vd(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new Ut;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function gi(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Vd(e.byteLength);return new Ut(Uint8Array.from([t.byteLength|yi]),t)}function Bt(e){let t=new Ut,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new Ut(Uint8Array.from([2]),gi(t),t)}function Rn(e){let t=Uint8Array.from([0]),r=new Ut(t,e);return new Ut(Uint8Array.from([3]),gi(r),r)}function Be(e,t=48){let r=new Ut;for(let n of e)r.append(n);return new Ut(Uint8Array.from([t]),gi(r),r)}async function Ga(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 Md=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),$d=Uint8Array.from([6,5,43,129,4,0,34]),qd=Uint8Array.from([6,5,43,129,4,0,35]),Hd={ext:!0,kty:"EC",crv:"P-256"},zd={ext:!0,kty:"EC",crv:"P-384"},jd={ext:!0,kty:"EC",crv:"P-521"},xi=32,wi=48,bi=66;function Ei(e){let t=ue(e);return Za(t)}function Za(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===xi*2+1)return n=H(t.subarray(r,r+xi),"base64url"),o=H(t.subarray(r+xi),"base64url"),new ur({...Hd,key_ops:["verify"],x:n,y:o});if(t.byteLength===wi*2+1)return n=H(t.subarray(r,r+wi),"base64url"),o=H(t.subarray(r+wi),"base64url"),new ur({...zd,key_ops:["verify"],x:n,y:o});if(t.byteLength===bi*2+1)return n=H(t.subarray(r,r+bi),"base64url"),o=H(t.subarray(r+bi),"base64url"),new ur({...jd,key_ops:["verify"],x:n,y:o});throw new st(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ya(e){return Be([Bt(Uint8Array.from([1])),Be([Gd(e.crv)],160),Be([Rn(new Ut(Uint8Array.from([4]),q(e.x??"","base64url"),q(e.y??"","base64url")))],161)]).subarray()}function Gd(e){if(e==="P-256")return Md;if(e==="P-384")return $d;if(e==="P-521")return qd;throw new st(`Invalid curve ${e}`)}var ur=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ya(this.jwk)),this._raw}toMultihash(){return Pt.digest(fr(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:X(this.raw,t.raw)}async verify(t,r,n){return Ga(this.jwk,r,t,n)}};var $e=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function le(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Hr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function _t(e,...t){if(!le(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Nn(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Hr(e.outputLen),Hr(e.blockLen)}function dr(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 Xa(e,t){_t(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function de(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Ln(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Gt(e,t){return e<<32-t|e>>>t}var Ja=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Zd=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function $t(e){if(_t(e),Ja)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Zd[e[r]];return t}var fe={_0:48,_9:57,A:65,F:70,a:97,f:102};function Wa(e){if(e>=fe._0&&e<=fe._9)return e-fe._0;if(e>=fe.A&&e<=fe.F)return e-(fe.A-10);if(e>=fe.a&&e<=fe.f)return e-(fe.a-10)}function qe(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Ja)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=Wa(e.charCodeAt(i)),a=Wa(e.charCodeAt(i+1));if(s===void 0||a===void 0){let c=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function Si(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function zr(e){return typeof e=="string"&&(e=Si(e)),_t(e),e}function Et(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];_t(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}var lr=class{};function vi(e){let t=n=>e().update(zr(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function hr(e=32){if($e&&typeof $e.getRandomValues=="function")return $e.getRandomValues(new Uint8Array(e));if($e&&typeof $e.randomBytes=="function")return Uint8Array.from($e.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Yd(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(r>>o&i),a=Number(r&i),c=n?4:0,f=n?0:4;e.setUint32(t+c,s,n),e.setUint32(t+f,a,n)}function Qa(e,t,r){return e&t^~e&r}function tc(e,t,r){return e&t^e&r^t&r}var jr=class extends lr{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Ln(this.buffer)}update(t){dr(this),t=zr(t),_t(t);let{view:r,buffer:n,blockLen:o}=this,i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=Ln(t);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){dr(this),Xa(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,de(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)r[l]=0;Yd(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=Ln(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return t.destroyed=s,t.finished=i,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},he=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ht=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var On=BigInt(4294967295),ec=BigInt(32);function Wd(e,t=!1){return t?{h:Number(e&On),l:Number(e>>ec&On)}:{h:Number(e>>ec&On)|0,l:Number(e&On)|0}}function rc(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:a}=Wd(e[i],t);[n[i],o[i]]=[s,a]}return[n,o]}var Ai=(e,t,r)=>e>>>r,Ii=(e,t,r)=>e<<32-r|t>>>r,He=(e,t,r)=>e>>>r|t<<32-r,ze=(e,t,r)=>e<<32-r|t>>>r,Gr=(e,t,r)=>e<<64-r|t>>>r-32,Zr=(e,t,r)=>e>>>r-32|t<<64-r;function re(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var nc=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),oc=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ic=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),sc=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,ac=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),cc=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;var Jd=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]),_e=new Uint32Array(64),kn=class extends jr{constructor(t=32){super(64,t,8,!1),this.A=he[0]|0,this.B=he[1]|0,this.C=he[2]|0,this.D=he[3]|0,this.E=he[4]|0,this.F=he[5]|0,this.G=he[6]|0,this.H=he[7]|0}get(){let{A:t,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[t,r,n,o,i,s,a,c]}set(t,r,n,o,i,s,a,c){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=a|0,this.H=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)_e[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let d=_e[l-15],h=_e[l-2],x=Gt(d,7)^Gt(d,18)^d>>>3,w=Gt(h,17)^Gt(h,19)^h>>>10;_e[l]=w+_e[l-7]+x+_e[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let d=Gt(a,6)^Gt(a,11)^Gt(a,25),h=u+d+Qa(a,c,f)+Jd[l]+_e[l]|0,w=(Gt(n,2)^Gt(n,13)^Gt(n,22))+tc(n,o,i)|0;u=f,f=c,c=a,a=s+h|0,s=i,i=o,o=n,n=h+w|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,i,s,a,c,f,u)}roundClean(){de(_e)}destroy(){this.set(0,0,0,0,0,0,0,0),de(this.buffer)}};var uc=rc(["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))),Qd=uc[0],th=uc[1],Pe=new Uint32Array(80),De=new Uint32Array(80),Ci=class extends jr{constructor(t=64){super(128,t,16,!1),this.Ah=ht[0]|0,this.Al=ht[1]|0,this.Bh=ht[2]|0,this.Bl=ht[3]|0,this.Ch=ht[4]|0,this.Cl=ht[5]|0,this.Dh=ht[6]|0,this.Dl=ht[7]|0,this.Eh=ht[8]|0,this.El=ht[9]|0,this.Fh=ht[10]|0,this.Fl=ht[11]|0,this.Gh=ht[12]|0,this.Gl=ht[13]|0,this.Hh=ht[14]|0,this.Hl=ht[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:d,Gh:h,Gl:x,Hh:w,Hl:C}=this;return[t,r,n,o,i,s,a,c,f,u,l,d,h,x,w,C]}set(t,r,n,o,i,s,a,c,f,u,l,d,h,x,w,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=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=d|0,this.Gh=h|0,this.Gl=x|0,this.Hh=w|0,this.Hl=C|0}process(t,r){for(let S=0;S<16;S++,r+=4)Pe[S]=t.getUint32(r),De[S]=t.getUint32(r+=4);for(let S=16;S<80;S++){let N=Pe[S-15]|0,k=De[S-15]|0,F=He(N,k,1)^He(N,k,8)^Ai(N,k,7),V=ze(N,k,1)^ze(N,k,8)^Ii(N,k,7),A=Pe[S-2]|0,m=De[S-2]|0,T=He(A,m,19)^Gr(A,m,61)^Ai(A,m,6),B=ze(A,m,19)^Zr(A,m,61)^Ii(A,m,6),I=ic(V,B,De[S-7],De[S-16]),g=sc(I,F,T,Pe[S-7],Pe[S-16]);Pe[S]=g|0,De[S]=I|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:d,Fh:h,Fl:x,Gh:w,Gl:C,Hh:b,Hl:P}=this;for(let S=0;S<80;S++){let N=He(l,d,14)^He(l,d,18)^Gr(l,d,41),k=ze(l,d,14)^ze(l,d,18)^Zr(l,d,41),F=l&h^~l&w,V=d&x^~d&C,A=ac(P,k,V,th[S],De[S]),m=cc(A,b,N,F,Qd[S],Pe[S]),T=A|0,B=He(n,o,28)^Gr(n,o,34)^Gr(n,o,39),I=ze(n,o,28)^Zr(n,o,34)^Zr(n,o,39),g=n&i^n&a^i&a,y=o&s^o&c^s&c;b=w|0,P=C|0,w=h|0,C=x|0,h=l|0,x=d|0,{h:l,l:d}=re(f|0,u|0,m|0,T|0),f=a|0,u=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let p=nc(T,I,y);n=oc(p,m,B,g),o=p|0}({h:n,l:o}=re(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=re(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=re(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=re(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:d}=re(this.Eh|0,this.El|0,l|0,d|0),{h,l:x}=re(this.Fh|0,this.Fl|0,h|0,x|0),{h:w,l:C}=re(this.Gh|0,this.Gl|0,w|0,C|0),{h:b,l:P}=re(this.Hh|0,this.Hl|0,b|0,P|0),this.set(n,o,i,s,a,c,f,u,l,d,h,x,w,C,b,P)}roundClean(){de(Pe,De)}destroy(){de(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Kn=vi(()=>new kn);var fc=vi(()=>new Ci);var _i=BigInt(0),Bi=BigInt(1);function pe(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function Rt(e,t,r=""){let n=le(e),o=e?.length,i=t!==void 0;if(!n||i&&o!==t){let s=r&&`"${r}" `,a=i?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`;throw new Error(s+"expected Uint8Array"+a+", got "+c)}return e}function Yr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function lc(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?_i:BigInt("0x"+e)}function pr(e){return lc($t(e))}function me(e){return _t(e),lc($t(Uint8Array.from(e).reverse()))}function Fn(e,t){return qe(e.toString(16).padStart(t*2,"0"))}function Pi(e,t){return Fn(e,t).reverse()}function Z(e,t,r){let n;if(typeof t=="string")try{n=qe(t)}catch(i){throw new Error(e+" must be hex string or Uint8Array, cause: "+i)}else if(le(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function dc(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function Di(e){return Uint8Array.from(e)}var Ti=e=>typeof e=="bigint"&&_i<=e;function hc(e,t,r){return Ti(e)&&Ti(t)&&Ti(r)&&t<=e&&e<r}function Wr(e,t,r,n){if(!hc(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Vn(e){let t;for(t=0;e>_i;e>>=Bi,t+=1);return t}var Ue=e=>(Bi<<BigInt(e))-Bi;function pc(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=h=>new Uint8Array(h),o=h=>Uint8Array.of(h),i=n(e),s=n(e),a=0,c=()=>{i.fill(1),s.fill(0),a=0},f=(...h)=>r(s,i,...h),u=(h=n(0))=>{s=f(o(0),h),i=f(),h.length!==0&&(s=f(o(1),h),i=f())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,x=[];for(;h<t;){i=f();let w=i.slice();x.push(w),h+=i.length}return Et(...x)};return(h,x)=>{c(),u(h);let w;for(;!(w=x(l()));)u();return c(),w}}function Re(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,i,s){let a=e[o];if(s&&a===void 0)return;let c=typeof a;if(c!==i||a===null)throw new Error(`param "${o}" is invalid: expected ${i}, got ${c}`)}Object.entries(t).forEach(([o,i])=>n(o,i,!1)),Object.entries(r).forEach(([o,i])=>n(o,i,!0))}var Ui=()=>{throw new Error("not implemented")};function mr(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 St=BigInt(0),ut=BigInt(1),je=BigInt(2),gc=BigInt(3),xc=BigInt(4),wc=BigInt(5),eh=BigInt(7),bc=BigInt(8),rh=BigInt(9),Ec=BigInt(16);function ot(e,t){let r=e%t;return r>=St?r:t+r}function J(e,t,r){let n=e;for(;t-- >St;)n*=n,n%=r;return n}function mc(e,t){if(e===St)throw new Error("invert: expected non-zero number");if(t<=St)throw new Error("invert: expected positive modulus, got "+t);let r=ot(e,t),n=t,o=St,i=ut,s=ut,a=St;for(;r!==St;){let f=n/r,u=n%r,l=o-s*f,d=i-a*f;n=r,r=u,o=s,i=a,s=l,a=d}if(n!==ut)throw new Error("invert: does not exist");return ot(o,t)}function Ri(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Sc(e,t){let r=(e.ORDER+ut)/xc,n=e.pow(t,r);return Ri(e,n,t),n}function nh(e,t){let r=(e.ORDER-wc)/bc,n=e.mul(t,je),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,je),o),a=e.mul(i,e.sub(s,e.ONE));return Ri(e,a,t),a}function oh(e){let t=Nt(e),r=vc(e),n=r(t,t.neg(t.ONE)),o=r(t,n),i=r(t,t.neg(n)),s=(e+eh)/Ec;return(a,c)=>{let f=a.pow(c,s),u=a.mul(f,n),l=a.mul(f,o),d=a.mul(f,i),h=a.eql(a.sqr(u),c),x=a.eql(a.sqr(l),c);f=a.cmov(f,u,h),u=a.cmov(d,l,x);let w=a.eql(a.sqr(u),c),C=a.cmov(f,u,w);return Ri(a,C,c),C}}function vc(e){if(e<gc)throw new Error("sqrt is not defined for small field");let t=e-ut,r=0;for(;t%je===St;)t/=je,r++;let n=je,o=Nt(e);for(;yc(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Sc;let i=o.pow(n,t),s=(t+ut)/je;return function(c,f){if(c.is0(f))return f;if(yc(c,f)!==1)throw new Error("Cannot find square root");let u=r,l=c.mul(c.ONE,i),d=c.pow(f,t),h=c.pow(f,s);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let x=1,w=c.sqr(d);for(;!c.eql(w,c.ONE);)if(x++,w=c.sqr(w),x===u)throw new Error("Cannot find square root");let C=ut<<BigInt(u-x-1),b=c.pow(l,C);u=x,l=c.sqr(b),d=c.mul(d,l),h=c.mul(h,b)}return h}}function ih(e){return e%xc===gc?Sc:e%bc===wc?nh:e%Ec===rh?oh(e):vc(e)}var ye=(e,t)=>(ot(e,t)&ut)===ut,sh=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ni(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=sh.reduce((n,o)=>(n[o]="function",n),t);return Re(e,r),e}function ah(e,t,r){if(r<St)throw new Error("invalid exponent, negatives unsupported");if(r===St)return e.ONE;if(r===ut)return t;let n=e.ONE,o=t;for(;r>St;)r&ut&&(n=e.mul(n,o)),o=e.sqr(o),r>>=ut;return n}function Xr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((s,a,c)=>e.is0(a)?s:(n[c]=s,e.mul(s,a)),e.ONE),i=e.inv(o);return t.reduceRight((s,a,c)=>e.is0(a)?s:(n[c]=e.mul(s,n[c]),e.mul(s,a)),i),n}function yc(e,t){let r=(e.ORDER-ut)/je,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 Mn(e,t){t!==void 0&&Hr(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Nt(e,t,r=!1,n={}){if(e<=St)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,i,s=!1,a;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let d=t;d.BITS&&(o=d.BITS),d.sqrt&&(i=d.sqrt),typeof d.isLE=="boolean"&&(r=d.isLE),typeof d.modFromBytes=="boolean"&&(s=d.modFromBytes),a=d.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(i=n.sqrt);let{nBitLength:c,nByteLength:f}=Mn(e,o);if(f>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let u,l=Object.freeze({ORDER:e,isLE:r,BITS:c,BYTES:f,MASK:Ue(c),ZERO:St,ONE:ut,allowedLengths:a,create:d=>ot(d,e),isValid:d=>{if(typeof d!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof d);return St<=d&&d<e},is0:d=>d===St,isValidNot0:d=>!l.is0(d)&&l.isValid(d),isOdd:d=>(d&ut)===ut,neg:d=>ot(-d,e),eql:(d,h)=>d===h,sqr:d=>ot(d*d,e),add:(d,h)=>ot(d+h,e),sub:(d,h)=>ot(d-h,e),mul:(d,h)=>ot(d*h,e),pow:(d,h)=>ah(l,d,h),div:(d,h)=>ot(d*mc(h,e),e),sqrN:d=>d*d,addN:(d,h)=>d+h,subN:(d,h)=>d-h,mulN:(d,h)=>d*h,inv:d=>mc(d,e),sqrt:i||(d=>(u||(u=ih(e)),u(l,d))),toBytes:d=>r?Pi(d,f):Fn(d,f),fromBytes:(d,h=!0)=>{if(a){if(!a.includes(d.length)||d.length>f)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+d.length);let w=new Uint8Array(f);w.set(d,r?0:w.length-d.length),d=w}if(d.length!==f)throw new Error("Field.fromBytes: expected "+f+" bytes, got "+d.length);let x=r?me(d):pr(d);if(s&&(x=ot(x,e)),!h&&!l.isValid(x))throw new Error("invalid field element: outside of range 0..ORDER");return x},invertBatch:d=>Xr(l,d),cmov:(d,h,x)=>x?h:d});return Object.freeze(l)}function Ac(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=Ac(e);return t+Math.ceil(t/2)}function Oi(e,t,r=!1){let n=e.length,o=Ac(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?me(e):pr(e),a=ot(s,t-ut)+ut;return r?Pi(a,o):Fn(a,o)}var yr=BigInt(0),Ge=BigInt(1);function Jr(e,t){let r=t.negate();return e?r:t}function ge(e,t){let r=Xr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Bc(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function ki(e,t){Bc(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,i=Ue(e),s=BigInt(e);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function Ic(e,t,r){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r,a=Number(e&o),c=e>>s;a>n&&(a-=i,c+=Ge);let f=t*n,u=f+Math.abs(a)-1,l=a===0,d=a<0,h=t%2!==0;return{nextN:c,offset:u,isZero:l,isNeg:d,isNegF:h,offsetF:f}}function ch(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function uh(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var Ki=new WeakMap,_c=new WeakMap;function Fi(e){return _c.get(e)||1}function Cc(e){if(e!==yr)throw new Error("invalid wNAF")}var gr=class{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>yr;)r&Ge&&(n=n.add(o)),o=o.double(),r>>=Ge;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=ki(r,this.bits),i=[],s=t,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let f=1;f<o;f++)a=a.add(s),i.push(a);s=a.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=ki(t,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:f,isZero:u,isNeg:l,isNegF:d,offsetF:h}=Ic(n,a,s);n=c,u?i=i.add(Jr(d,r[h])):o=o.add(Jr(l,r[f]))}return Cc(n),{p:o,f:i}}wNAFUnsafe(t,r,n,o=this.ZERO){let i=ki(t,this.bits);for(let s=0;s<i.windows&&n!==yr;s++){let{nextN:a,offset:c,isZero:f,isNeg:u}=Ic(n,s,i);if(n=a,!f){let l=r[c];o=o.add(u?l.negate():l)}}return Cc(n),o}getPrecomputes(t,r,n){let o=Ki.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Ki.set(r,o))),o}cached(t,r,n){let o=Fi(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let i=Fi(t);return i===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,t,n),r,o)}createCache(t,r){Bc(r,this.bits),_c.set(t,r),Ki.delete(t)}hasCache(t){return Fi(t)!==1}};function Pc(e,t,r,n){let o=t,i=e.ZERO,s=e.ZERO;for(;r>yr||n>yr;)r&Ge&&(i=i.add(o)),n&Ge&&(s=s.add(o)),o=o.double(),r>>=Ge,n>>=Ge;return{p1:i,p2:s}}function xr(e,t,r,n){ch(r,e),uh(n,t);let o=r.length,i=n.length;if(o!==i)throw new Error("arrays of points and scalars must have equal length");let s=e.ZERO,a=Vn(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let f=Ue(c),u=new Array(Number(f)+1).fill(s),l=Math.floor((t.BITS-1)/c)*c,d=s;for(let h=l;h>=0;h-=c){u.fill(s);for(let w=0;w<i;w++){let C=n[w],b=Number(C>>BigInt(h)&f);u[b]=u[b].add(r[w])}let x=s;for(let w=u.length-1,C=s;w>0;w--)C=C.add(u[w]),x=x.add(C);if(d=d.add(x),h!==0)for(let w=0;w<c;w++)d=d.double()}return d}function Tc(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ni(t),t}else return Nt(e,{isLE:r})}function $n(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 c of["p","n","h"]){let f=t[c];if(!(typeof f=="bigint"&&f>yr))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Tc(t.p,r.Fp,n),i=Tc(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:i}}var Ne=BigInt(0),ft=BigInt(1),Vi=BigInt(2),fh=BigInt(8);function lh(e,t,r,n){let o=e.sqr(r),i=e.sqr(n),s=e.add(e.mul(t.a,o),i),a=e.add(e.ONE,e.mul(t.d,e.mul(o,i)));return e.eql(s,a)}function dh(e,t={}){let r=$n("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s}=i;Re(t,{},{uvRatio:"function"});let a=Vi<<BigInt(o.BYTES*8)-ft,c=C=>n.create(C),f=t.uvRatio||((C,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(C,b))}}catch{return{isValid:!1,value:Ne}}});if(!lh(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function u(C,b,P=!1){let S=P?ft:Ne;return Wr("coordinate "+C,b,S,a),b}function l(C){if(!(C instanceof x))throw new Error("ExtendedPoint expected")}let d=mr((C,b)=>{let{X:P,Y:S,Z:N}=C,k=C.is0();b==null&&(b=k?fh:n.inv(N));let F=c(P*b),V=c(S*b),A=n.mul(N,b);if(k)return{x:Ne,y:ft};if(A!==ft)throw new Error("invZ was invalid");return{x:F,y:V}}),h=mr(C=>{let{a:b,d:P}=i;if(C.is0())throw new Error("bad point: ZERO");let{X:S,Y:N,Z:k,T:F}=C,V=c(S*S),A=c(N*N),m=c(k*k),T=c(m*m),B=c(V*b),I=c(m*c(B+A)),g=c(T+c(P*c(V*A)));if(I!==g)throw new Error("bad point: equation left != right (1)");let y=c(S*N),p=c(k*F);if(y!==p)throw new Error("bad point: equation left != right (2)");return!0});class x{constructor(b,P,S,N){this.X=u("x",b),this.Y=u("y",P),this.Z=u("z",S,!0),this.T=u("t",N),Object.freeze(this)}static CURVE(){return i}static fromAffine(b){if(b instanceof x)throw new Error("extended point not allowed");let{x:P,y:S}=b||{};return u("x",P),u("y",S),new x(P,S,ft,c(P*S))}static fromBytes(b,P=!1){let S=n.BYTES,{a:N,d:k}=i;b=Di(Rt(b,S,"point")),pe(P,"zip215");let F=Di(b),V=b[S-1];F[S-1]=V&-129;let A=me(F),m=P?a:n.ORDER;Wr("point.y",A,Ne,m);let T=c(A*A),B=c(T-ft),I=c(k*T-N),{isValid:g,value:y}=f(B,I);if(!g)throw new Error("bad point: invalid y coordinate");let p=(y&ft)===ft,v=(V&128)!==0;if(!P&&y===Ne&&v)throw new Error("bad point: x=0 and x_0=1");return v!==p&&(y=c(-y)),x.fromAffine({x:y,y:A})}static fromHex(b,P=!1){return x.fromBytes(Z("point",b),P)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,P=!0){return w.createCache(this,b),P||this.multiply(Vi),this}assertValidity(){h(this)}equals(b){l(b);let{X:P,Y:S,Z:N}=this,{X:k,Y:F,Z:V}=b,A=c(P*V),m=c(k*N),T=c(S*V),B=c(F*N);return A===m&&T===B}is0(){return this.equals(x.ZERO)}negate(){return new x(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:b}=i,{X:P,Y:S,Z:N}=this,k=c(P*P),F=c(S*S),V=c(Vi*c(N*N)),A=c(b*k),m=P+S,T=c(c(m*m)-k-F),B=A+F,I=B-V,g=A-F,y=c(T*I),p=c(B*g),v=c(T*g),D=c(I*B);return new x(y,p,D,v)}add(b){l(b);let{a:P,d:S}=i,{X:N,Y:k,Z:F,T:V}=this,{X:A,Y:m,Z:T,T:B}=b,I=c(N*A),g=c(k*m),y=c(V*S*B),p=c(F*T),v=c((N+k)*(A+m)-I-g),D=p-y,L=p+y,R=c(g-P*I),O=c(v*D),K=c(L*R),$=c(v*R),tt=c(D*L);return new x(O,K,tt,$)}subtract(b){return this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:P,f:S}=w.cached(this,b,N=>ge(x,N));return ge(x,[P,S])[0]}multiplyUnsafe(b,P=x.ZERO){if(!o.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===Ne?x.ZERO:this.is0()||b===ft?this:w.unsafe(this,b,S=>ge(x,S),P)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return w.unsafe(this,i.n).is0()}toAffine(b){return d(this,b)}clearCofactor(){return s===ft?this:this.multiplyUnsafe(s)}toBytes(){let{x:b,y:P}=this.toAffine(),S=n.toBytes(P);return S[S.length-1]|=b&ft?128:0,S}toHex(){return $t(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(b){return ge(x,b)}static msm(b,P){return xr(x,o,b,P)}_setWindowSize(b){this.precompute(b)}toRawBytes(){return this.toBytes()}}x.BASE=new x(i.Gx,i.Gy,ft,c(i.Gx*i.Gy)),x.ZERO=new x(Ne,ft,ft,Ne),x.Fp=n,x.Fn=o;let w=new gr(x,o.BITS);return x.BASE.precompute(8),x}var qn=class{constructor(t){this.ep=t}static fromBytes(t){Ui()}static fromHex(t){Ui()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return $t(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function hh(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');Re(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:i,Fn:s}=e,a=r.randomBytes||hr,c=r.adjustScalarBytes||(m=>m),f=r.domain||((m,T,B)=>{if(pe(B,"phflag"),T.length||B)throw new Error("Contexts/pre-hash are not supported");return m});function u(m){return s.create(me(m))}function l(m){let T=S.secretKey;m=Z("private key",m,T);let B=Z("hashed private key",t(m),2*T),I=c(B.slice(0,T)),g=B.slice(T,2*T),y=u(I);return{head:I,prefix:g,scalar:y}}function d(m){let{head:T,prefix:B,scalar:I}=l(m),g=o.multiply(I),y=g.toBytes();return{head:T,prefix:B,scalar:I,point:g,pointBytes:y}}function h(m){return d(m).pointBytes}function x(m=Uint8Array.of(),...T){let B=Et(...T);return u(t(f(B,Z("context",m),!!n)))}function w(m,T,B={}){m=Z("message",m),n&&(m=n(m));let{prefix:I,scalar:g,pointBytes:y}=d(T),p=x(B.context,I,m),v=o.multiply(p).toBytes(),D=x(B.context,v,y,m),L=s.create(p+D*g);if(!s.isValid(L))throw new Error("sign failed: invalid s");let R=Et(v,s.toBytes(L));return Rt(R,S.signature,"result")}let C={zip215:!0};function b(m,T,B,I=C){let{context:g,zip215:y}=I,p=S.signature;m=Z("signature",m,p),T=Z("message",T),B=Z("publicKey",B,S.publicKey),y!==void 0&&pe(y,"zip215"),n&&(T=n(T));let v=p/2,D=m.subarray(0,v),L=me(m.subarray(v,p)),R,O,K;try{R=e.fromBytes(B,y),O=e.fromBytes(D,y),K=o.multiplyUnsafe(L)}catch{return!1}if(!y&&R.isSmallOrder())return!1;let $=x(g,O.toBytes(),R.toBytes(),T);return O.add(R.multiplyUnsafe($)).subtract(K).clearCofactor().is0()}let P=i.BYTES,S={secretKey:P,publicKey:P,signature:2*P,seed:P};function N(m=a(S.seed)){return Rt(m,S.seed,"seed")}function k(m){let T=A.randomSecretKey(m);return{secretKey:T,publicKey:h(T)}}function F(m){return le(m)&&m.length===s.BYTES}function V(m,T){try{return!!e.fromBytes(m,T)}catch{return!1}}let A={getExtendedPublicKey:d,randomSecretKey:N,isValidSecretKey:F,isValidPublicKey:V,toMontgomery(m){let{y:T}=e.fromBytes(m),B=S.publicKey,I=B===32;if(!I&&B!==57)throw new Error("only defined for 25519 and 448");let g=I?i.div(ft+T,ft-T):i.div(T-ft,T+ft);return i.toBytes(g)},toMontgomeryPriv(m){let T=S.secretKey;Rt(m,T);let B=t(m.subarray(0,T));return c(B).subarray(0,T)},randomPrivateKey:N,precompute(m=8,T=e.BASE){return T.precompute(m,!1)}};return Object.freeze({keygen:k,getPublicKey:h,sign:w,verify:b,utils:A,Point:e,lengths:S})}function ph(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=Nt(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},i={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:i}}function mh(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function Dc(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=ph(e),i=dh(t,r),s=hh(i,n,o);return mh(e,s)}var yh=BigInt(0),xe=BigInt(1),Uc=BigInt(2),Ng=BigInt(3),gh=BigInt(5),xh=BigInt(8),wr=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Qr={p:wr,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:xh,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function wh(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=wr,a=e*e%i*e%i,c=J(a,Uc,i)*a%i,f=J(c,xe,i)*e%i,u=J(f,gh,i)*f%i,l=J(u,t,i)*u%i,d=J(l,r,i)*l%i,h=J(d,n,i)*d%i,x=J(h,o,i)*h%i,w=J(x,o,i)*h%i,C=J(w,t,i)*u%i;return{pow_p_5_8:J(C,Uc,i)*e%i,b2:a}}function bh(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Mi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Hi(e,t){let r=wr,n=ot(t*t*t,r),o=ot(n*n*t,r),i=wh(e*o).pow_p_5_8,s=ot(e*n*i,r),a=ot(t*s*s,r),c=s,f=ot(s*Mi,r),u=a===e,l=a===ot(-e,r),d=a===ot(-e*Mi,r);return u&&(s=c),(l||d)&&(s=f),ye(s,r)&&(s=ot(-s,r)),{isValid:u||l,value:s}}var Le=Nt(Qr.p,{isLE:!0}),Eh=Nt(Qr.n,{isLE:!0}),Sh={...Qr,Fp:Le,hash:fc,adjustScalarBytes:bh,uvRatio:Hi},we=Dc(Sh);var $i=Mi,vh=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Ah=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Ih=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Ch=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Rc=e=>Hi(xe,e),Th=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),qi=e=>we.Point.Fp.create(me(e)&Th);function Nc(e){let{d:t}=Qr,r=wr,n=b=>Le.create(b),o=n($i*e*e),i=n((o+xe)*Ih),s=BigInt(-1),a=n((s-t*o)*n(o+t)),{isValid:c,value:f}=Hi(i,a),u=n(f*e);ye(u,r)||(u=n(-u)),c||(f=u),c||(s=o);let l=n(s*(o-xe)*Ch-a),d=f*f,h=n((f+f)*a),x=n(l*vh),w=n(xe-d),C=n(xe+d);return new we.Point(n(h*C),n(w*x),n(x*C),n(h*w))}function Bh(e){_t(e,64);let t=qi(e.subarray(0,32)),r=Nc(t),n=qi(e.subarray(32,64)),o=Nc(n);return new be(r.add(o))}var be=class e extends qn{constructor(t){super(t)}static fromAffine(t){return new e(we.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return Bh(Z("ristrettoHash",t,64))}static fromBytes(t){_t(t,32);let{a:r,d:n}=Qr,o=wr,i=N=>Le.create(N),s=qi(t);if(!dc(Le.toBytes(s),t)||ye(s,o))throw new Error("invalid ristretto255 encoding 1");let a=i(s*s),c=i(xe+r*a),f=i(xe-r*a),u=i(c*c),l=i(f*f),d=i(r*n*u-l),{isValid:h,value:x}=Rc(i(d*l)),w=i(x*f),C=i(x*w*d),b=i((s+s)*w);ye(b,o)&&(b=i(-b));let P=i(c*C),S=i(b*P);if(!h||ye(S,o)||P===yh)throw new Error("invalid ristretto255 encoding 2");return new e(new we.Point(b,P,xe,S))}static fromHex(t){return e.fromBytes(Z("ristrettoHex",t,32))}static msm(t,r){return xr(e,we.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,i=wr,s=C=>Le.create(C),a=s(s(n+r)*s(n-r)),c=s(t*r),f=s(c*c),{value:u}=Rc(s(a*f)),l=s(u*a),d=s(u*c),h=s(l*d*o),x;if(ye(o*h,i)){let C=s(r*$i),b=s(t*$i);t=C,r=b,x=s(l*Ah)}else x=d;ye(t*h,i)&&(r=s(-r));let w=s((n-r)*x);return ye(w,i)&&(w=s(-w)),Le.toBytes(w)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:i}=t.ep,s=f=>Le.create(f),a=s(r*i)===s(n*o),c=s(n*i)===s(r*o);return a||c}is0(){return this.equals(e.ZERO)}};be.BASE=new be(we.Point.BASE);be.ZERO=new be(we.Point.ZERO);be.Fp=Le;be.Fn=Eh;var tn=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Hn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Lc={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Hn("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 qt=Lc;var zn=32;var zi,_h=(async()=>{try{return await qt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Ph(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await qt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await qt.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 Dh(e,t,r){return we.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Oc(e,t,r){return zi==null&&(zi=await _h),zi?Ph(e,t,r):Dh(e,t,r)}function jn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Gn=class{type="Ed25519";raw;constructor(t){this.raw=ji(t,zn)}toMultihash(){return Pt.digest(fr(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:X(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Oc(this.raw,r,t);return jn(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}};function Gi(e){return e=ji(e,zn),new Gn(e)}function ji(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new st(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Rh=Math.pow(2,7),Nh=Math.pow(2,14),Lh=Math.pow(2,21),Zi=Math.pow(2,28),Yi=Math.pow(2,35),Wi=Math.pow(2,42),Xi=Math.pow(2,49),Q=128,xt=127;function ne(e){if(e<Rh)return 1;if(e<Nh)return 2;if(e<Lh)return 3;if(e<Zi)return 4;if(e<Yi)return 5;if(e<Wi)return 6;if(e<Xi)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function en(e,t,r=0){switch(ne(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 Ji(e,t){let r=e[t],n=0;if(n+=r&xt,r<Q||(r=e[t+1],n+=(r&xt)<<7,r<Q)||(r=e[t+2],n+=(r&xt)<<14,r<Q)||(r=e[t+3],n+=(r&xt)<<21,r<Q)||(r=e[t+4],n+=(r&xt)*Zi,r<Q)||(r=e[t+5],n+=(r&xt)*Yi,r<Q)||(r=e[t+6],n+=(r&xt)*Wi,r<Q)||(r=e[t+7],n+=(r&xt)*Xi,r<Q))return n;throw new RangeError("Could not decode varint")}function Oh(e,t){let r=e.get(t),n=0;if(n+=r&xt,r<Q||(r=e.get(t+1),n+=(r&xt)<<7,r<Q)||(r=e.get(t+2),n+=(r&xt)<<14,r<Q)||(r=e.get(t+3),n+=(r&xt)<<21,r<Q)||(r=e.get(t+4),n+=(r&xt)*Zi,r<Q)||(r=e.get(t+5),n+=(r&xt)*Yi,r<Q)||(r=e.get(t+6),n+=(r&xt)*Wi,r<Q)||(r=e.get(t+7),n+=(r&xt)*Xi,r<Q))return n;throw new RangeError("Could not decode varint")}function Qi(e,t=0){return e instanceof Uint8Array?Ji(e,t):Oh(e,t)}var ts=new Float32Array([-0]),Oe=new Uint8Array(ts.buffer);function Kc(e,t,r){ts[0]=e,t[r]=Oe[0],t[r+1]=Oe[1],t[r+2]=Oe[2],t[r+3]=Oe[3]}function Fc(e,t){return Oe[0]=e[t],Oe[1]=e[t+1],Oe[2]=e[t+2],Oe[3]=e[t+3],ts[0]}var es=new Float64Array([-0]),wt=new Uint8Array(es.buffer);function Vc(e,t,r){es[0]=e,t[r]=wt[0],t[r+1]=wt[1],t[r+2]=wt[2],t[r+3]=wt[3],t[r+4]=wt[4],t[r+5]=wt[5],t[r+6]=wt[6],t[r+7]=wt[7]}function Mc(e,t){return wt[0]=e[t],wt[1]=e[t+1],wt[2]=e[t+2],wt[3]=e[t+3],wt[4]=e[t+4],wt[5]=e[t+5],wt[6]=e[t+6],wt[7]=e[t+7],es[0]}var Kh=BigInt(Number.MAX_SAFE_INTEGER),Fh=BigInt(Number.MIN_SAFE_INTEGER),Lt=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 Ze;if(t<Kh&&t>Fh)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>$c&&(o=0n,++n>$c&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ze;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):Ze}},Ze=new Lt(0,0);Ze.toBigInt=function(){return 0n};Ze.zzEncode=Ze.zzDecode=function(){return this};Ze.length=function(){return 1};var $c=4294967296n;function qc(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 Hc(e,t,r){if(r-t<1)return"";let o,i=[],s=0,a;for(;t<r;)a=e[t++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&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 rs(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 Zt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Zn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var ns=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,Zt(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 Zt(this,4);return Zn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Zt(this,4);return Zn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Zt(this,4);let t=Fc(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Zt(this,4);let t=Mc(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 Zt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Hc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Zt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Zt(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 Lt(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 Zt(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 Zt(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 Zt(this,8);let t=Zn(this.buf,this.pos+=4),r=Zn(this.buf,this.pos+=4);return new Lt(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=Ji(this.buf,this.pos);return this.pos+=ne(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 os(e){return new ns(e instanceof Uint8Array?e:e.subarray())}function br(e,t,r){let n=os(e);return t.decode(n,void 0,r)}function is(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return Dt(s);o+s>t&&(n=Dt(t),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Ye=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function ss(){}var cs=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Vh=is();function Mh(e){return globalThis.Buffer!=null?Dt(e):Vh(e)}var nn=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ye(ss,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Ye(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new us((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(Yn,10,Lt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Lt.fromBigInt(t);return this._push(Yn,r.length(),r)}uint64Number(t){return this._push(en,ne(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=Lt.fromBigInt(t).zzEncode();return this._push(Yn,r.length(),r)}sint64Number(t){let r=Lt.fromNumber(t).zzEncode();return this._push(Yn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(as,1,t?1:0)}fixed32(t){return this._push(rn,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Lt.fromBigInt(t);return this._push(rn,4,r.lo)._push(rn,4,r.hi)}fixed64Number(t){let r=Lt.fromNumber(t);return this._push(rn,4,r.lo)._push(rn,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(Kc,4,t)}double(t){return this._push(Vc,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(as,1,0):this.uint32(r)._push(qh,r,t)}string(t){let r=qc(t);return r!==0?this.uint32(r)._push(rs,r,t):this._push(as,1,0)}fork(){return this.states=new cs(this),this.head=this.tail=new Ye(ss,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 Ye(ss,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=Mh(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function as(e,t,r){t[r]=e&255}function $h(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var us=class extends Ye{next;constructor(t,r){super($h,t,r),this.next=void 0}};function Yn(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 rn(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 qh(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(nn.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Hh,t,e),this},nn.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(zh,t,e),this});function Hh(e,t,r){t.set(e,r)}function zh(e,t,r){e.length<40?rs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(q(e),r)}function fs(){return new nn}function Er(e,t){let r=fs();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Sr;(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"})(Sr||(Sr={}));function Wn(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function on(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(i,s){let a=t(i);s.int32(a)},n=function(i){let s=i.int32();return t(s)};return Wn("enum",Sr.VARINT,r,n)}function vr(e,t){return Wn("message",Sr.LENGTH_DELIMITED,e,t)}var it;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(it||(it={}));var ls;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(ls||(ls={}));(function(e){e.codec=()=>on(ls)})(it||(it={}));var oe;(function(e){let t;e.codec=()=>(t==null&&(t=vr((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),it.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let a=r.uint32();switch(a>>>3){case 1:{i.Type=it.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>Er(r,e.codec()),e.decode=(r,n)=>br(r,e.codec(),n)})(oe||(oe={}));var ds;(function(e){let t;e.codec=()=>(t==null&&(t=vr((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),it.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let a=r.uint32();switch(a>>>3){case 1:{i.Type=it.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>Er(r,e.codec()),e.decode=(r,n)=>br(r,e.codec(),n)})(ds||(ds={}));var an={};It(an,{MAX_RSA_KEY_SIZE:()=>hs,generateRSAKeyPair:()=>Wc,jwkToJWKKeyPair:()=>Xc,jwkToPkcs1:()=>Yh,jwkToPkix:()=>gs,jwkToRSAPrivateKey:()=>Es,pkcs1MessageToJwk:()=>ms,pkcs1MessageToRSAPrivateKey:()=>xs,pkcs1ToJwk:()=>Zh,pkcs1ToRSAPrivateKey:()=>Yc,pkixMessageToJwk:()=>ys,pkixMessageToRSAPublicKey:()=>bs,pkixToJwk:()=>Wh,pkixToRSAPublicKey:()=>ws});var Xn=Kn;var Ar=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=an.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:X(this.raw,t.raw)}verify(t,r,n){return Zc(this.jwk,r,t,n)}},sn=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=an.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:X(this.raw,t.raw)}sign(t,r){return Gc(this.jwk,t,r)}};var hs=8192,ps=18,jh=1062,Gh=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Zh(e){let t=ue(e);return ms(t)}function ms(e){return{n:H(e[1],"base64url"),e:H(e[2],"base64url"),d:H(e[3],"base64url"),p:H(e[4],"base64url"),q:H(e[5],"base64url"),dp:H(e[6],"base64url"),dq:H(e[7],"base64url"),qi:H(e[8],"base64url"),kty:"RSA"}}function Yh(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new st("JWK was missing components");return Be([Bt(Uint8Array.from([0])),Bt(q(e.n,"base64url")),Bt(q(e.e,"base64url")),Bt(q(e.d,"base64url")),Bt(q(e.p,"base64url")),Bt(q(e.q,"base64url")),Bt(q(e.dp,"base64url")),Bt(q(e.dq,"base64url")),Bt(q(e.qi,"base64url"))]).subarray()}function Wh(e){let t=ue(e,{offset:0});return ys(t)}function ys(e){let t=ue(e[1],{offset:0});return{kty:"RSA",n:H(t[0],"base64url"),e:H(t[1],"base64url")}}function gs(e){if(e.n==null||e.e==null)throw new st("JWK was missing components");return Be([Gh,Rn(Be([Bt(q(e.n,"base64url")),Bt(q(e.e,"base64url"))]))]).subarray()}function Yc(e){let t=ue(e);return xs(t)}function xs(e){let t=ms(e);return Es(t)}function ws(e,t){if(e.byteLength>=jh)throw new tr("Key size is too large");let r=ue(e,{offset:0});return bs(r,e,t)}function bs(e,t,r){let n=ys(e);if(r==null){let o=Xn(oe.encode({Type:it.RSA,Data:t}));r=jt(ps,o)}return new Ar(n,r)}function Es(e){if(Qc(e)>hs)throw new st("Key size is too large");let t=Xc(e),r=Xn(oe.encode({Type:it.RSA,Data:gs(t.publicKey)})),n=jt(ps,r);return new sn(t.privateKey,new Ar(t.publicKey,n))}async function Wc(e){if(e>hs)throw new st("Key size is too large");let t=await Jc(e),r=Xn(oe.encode({Type:it.RSA,Data:gs(t.publicKey)})),n=jt(ps,r);return new sn(t.privateKey,new Ar(t.publicKey,n))}function Xc(e){if(e==null)throw new st("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Jc(e,t){let r=await qt.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 Xh(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Gc(e,t,r){let n=await qt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await qt.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 Zc(e,t,r,n){let o=await qt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await qt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),i}async function Xh(e,t){if(e.privateKey==null||e.publicKey==null)throw new st("Private and public key are required");let r=await Promise.all([qt.get().subtle.exportKey("jwk",e.privateKey),qt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Qc(e){if(e.kty!=="RSA")throw new st("invalid key type");if(e.n==null)throw new st("invalid key modulus");return q(e.n,"base64url").length*8}var Jn=class extends lr{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Nn(t);let n=zr(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?t.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=t.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),de(i)}update(t){return dr(this),this.iHash.update(t),this}digestInto(t){dr(this),_t(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=i,t.blockLen=s,t.outputLen=a,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()}},Ss=(e,t,r)=>new Jn(e,t).update(r).digest();Ss.create=(e,t)=>new Jn(e,t);var tu=(e,t)=>(e+(e>=0?t:-t)/eu)/t;function Jh(e,t,r){let[[n,o],[i,s]]=t,a=tu(s*e,r),c=tu(-o*e,r),f=e-a*n-c*i,u=-a*o-c*s,l=f<Se,d=u<Se;l&&(f=-f),d&&(u=-u);let h=Ue(Math.ceil(Vn(r)/2))+Cr;if(f<Se||f>=h||u<Se||u>=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:f,k2neg:d,k2:u}}function As(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function vs(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return pe(r.lowS,"lowS"),pe(r.prehash,"prehash"),r.format!==void 0&&As(r.format),r}var Is=class extends Error{constructor(t=""){super(t)}},Ee={Err:Is,_tlv:{encode:(e,t)=>{let{Err:r}=Ee;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=Yr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?Yr(o.length/2|128):"";return Yr(e)+i+o+t},decode(e,t){let{Err:r}=Ee,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 c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)s=s<<8|u;if(n+=c,s<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+s)}}},_int:{encode(e){let{Err:t}=Ee;if(e<Se)throw new t("integer: negative integers are not allowed");let r=Yr(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}=Ee;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 pr(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Ee,o=Z("signature",e),{v:i,l:s}=n.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:f,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=Ee,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),i=n+o;return t.encode(48,i)}},Se=BigInt(0),Cr=BigInt(1),eu=BigInt(2),Qn=BigInt(3),Qh=BigInt(4);function Ir(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=Z("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function tp(e,t={}){let r=$n("weierstrass",e,t),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s,n:a}=i;Re(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=t;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=nu(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(I,g,y){let{x:p,y:v}=g.toAffine(),D=n.toBytes(p);if(pe(y,"isCompressed"),y){u();let L=!n.isOdd(v);return Et(ru(L),D)}else return Et(Uint8Array.of(4),D,n.toBytes(v))}function d(I){Rt(I,void 0,"Point");let{publicKey:g,publicKeyUncompressed:y}=f,p=I.length,v=I[0],D=I.subarray(1);if(p===g&&(v===2||v===3)){let L=n.fromBytes(D);if(!n.isValid(L))throw new Error("bad point: is not on curve, wrong x");let R=w(L),O;try{O=n.sqrt(R)}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(v&1)===1!==K&&(O=n.neg(O)),{x:L,y:O}}else if(p===y&&v===4){let L=n.BYTES,R=n.fromBytes(D.subarray(0,L)),O=n.fromBytes(D.subarray(L,L*2));if(!C(R,O))throw new Error("bad point: is not on curve");return{x:R,y:O}}else throw new Error(`bad point: got length ${p}, expected compressed=${g} or uncompressed=${y}`)}let h=t.toBytes||l,x=t.fromBytes||d;function w(I){let g=n.sqr(I),y=n.mul(g,I);return n.add(n.add(y,n.mul(I,i.a)),i.b)}function C(I,g){let y=n.sqr(g),p=w(I);return n.eql(y,p)}if(!C(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let b=n.mul(n.pow(i.a,Qn),Qh),P=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(b,P)))throw new Error("bad curve params: a or b");function S(I,g,y=!1){if(!n.isValid(g)||y&&n.is0(g))throw new Error(`bad point coordinate ${I}`);return g}function N(I){if(!(I instanceof m))throw new Error("ProjectivePoint expected")}function k(I){if(!c||!c.basises)throw new Error("no endo");return Jh(I,c.basises,o.ORDER)}let F=mr((I,g)=>{let{X:y,Y:p,Z:v}=I;if(n.eql(v,n.ONE))return{x:y,y:p};let D=I.is0();g==null&&(g=D?n.ONE:n.inv(v));let L=n.mul(y,g),R=n.mul(p,g),O=n.mul(v,g);if(D)return{x:n.ZERO,y:n.ZERO};if(!n.eql(O,n.ONE))throw new Error("invZ was invalid");return{x:L,y:R}}),V=mr(I=>{if(I.is0()){if(t.allowInfinityPoint&&!n.is0(I.Y))return;throw new Error("bad point: ZERO")}let{x:g,y}=I.toAffine();if(!n.isValid(g)||!n.isValid(y))throw new Error("bad point: x or y not field elements");if(!C(g,y))throw new Error("bad point: equation left != right");if(!I.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function A(I,g,y,p,v){return y=new m(n.mul(y.X,I),y.Y,y.Z),g=Jr(p,g),y=Jr(v,y),g.add(y)}class m{constructor(g,y,p){this.X=S("x",g),this.Y=S("y",y,!0),this.Z=S("z",p),Object.freeze(this)}static CURVE(){return i}static fromAffine(g){let{x:y,y:p}=g||{};if(!g||!n.isValid(y)||!n.isValid(p))throw new Error("invalid affine point");if(g instanceof m)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(p)?m.ZERO:new m(y,p,n.ONE)}static fromBytes(g){let y=m.fromAffine(x(Rt(g,void 0,"point")));return y.assertValidity(),y}static fromHex(g){return m.fromBytes(Z("pointHex",g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,y=!0){return B.createCache(this,g),y||this.multiply(Qn),this}assertValidity(){V(this)}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){N(g);let{X:y,Y:p,Z:v}=this,{X:D,Y:L,Z:R}=g,O=n.eql(n.mul(y,R),n.mul(D,v)),K=n.eql(n.mul(p,R),n.mul(L,v));return O&&K}negate(){return new m(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b:y}=i,p=n.mul(y,Qn),{X:v,Y:D,Z:L}=this,R=n.ZERO,O=n.ZERO,K=n.ZERO,$=n.mul(v,v),tt=n.mul(D,D),Y=n.mul(L,L),z=n.mul(v,D);return z=n.add(z,z),K=n.mul(v,L),K=n.add(K,K),R=n.mul(g,K),O=n.mul(p,Y),O=n.add(R,O),R=n.sub(tt,O),O=n.add(tt,O),O=n.mul(R,O),R=n.mul(z,R),K=n.mul(p,K),Y=n.mul(g,Y),z=n.sub($,Y),z=n.mul(g,z),z=n.add(z,K),K=n.add($,$),$=n.add(K,$),$=n.add($,Y),$=n.mul($,z),O=n.add(O,$),Y=n.mul(D,L),Y=n.add(Y,Y),$=n.mul(Y,z),R=n.sub(R,$),K=n.mul(Y,tt),K=n.add(K,K),K=n.add(K,K),new m(R,O,K)}add(g){N(g);let{X:y,Y:p,Z:v}=this,{X:D,Y:L,Z:R}=g,O=n.ZERO,K=n.ZERO,$=n.ZERO,tt=i.a,Y=n.mul(i.b,Qn),z=n.mul(y,D),et=n.mul(p,L),ct=n.mul(v,R),At=n.add(y,p),rt=n.add(D,L);At=n.mul(At,rt),rt=n.add(z,et),At=n.sub(At,rt),rt=n.add(y,v);let gt=n.add(D,R);return rt=n.mul(rt,gt),gt=n.add(z,ct),rt=n.sub(rt,gt),gt=n.add(p,v),O=n.add(L,R),gt=n.mul(gt,O),O=n.add(et,ct),gt=n.sub(gt,O),$=n.mul(tt,rt),O=n.mul(Y,ct),$=n.add(O,$),O=n.sub(et,$),$=n.add(et,$),K=n.mul(O,$),et=n.add(z,z),et=n.add(et,z),ct=n.mul(tt,ct),rt=n.mul(Y,rt),et=n.add(et,ct),ct=n.sub(z,ct),ct=n.mul(tt,ct),rt=n.add(rt,ct),z=n.mul(et,rt),K=n.add(K,z),z=n.mul(gt,rt),O=n.mul(At,O),O=n.sub(O,z),z=n.mul(At,et),$=n.mul(gt,$),$=n.add($,z),new m(O,K,$)}subtract(g){return this.add(g.negate())}is0(){return this.equals(m.ZERO)}multiply(g){let{endo:y}=t;if(!o.isValidNot0(g))throw new Error("invalid scalar: out of range");let p,v,D=L=>B.cached(this,L,R=>ge(m,R));if(y){let{k1neg:L,k1:R,k2neg:O,k2:K}=k(g),{p:$,f:tt}=D(R),{p:Y,f:z}=D(K);v=tt.add(z),p=A(y.beta,$,Y,L,O)}else{let{p:L,f:R}=D(g);p=L,v=R}return ge(m,[p,v])[0]}multiplyUnsafe(g){let{endo:y}=t,p=this;if(!o.isValid(g))throw new Error("invalid scalar: out of range");if(g===Se||p.is0())return m.ZERO;if(g===Cr)return p;if(B.hasCache(this))return this.multiply(g);if(y){let{k1neg:v,k1:D,k2neg:L,k2:R}=k(g),{p1:O,p2:K}=Pc(m,p,D,R);return A(y.beta,O,K,v,L)}else return B.unsafe(p,g)}multiplyAndAddUnsafe(g,y,p){let v=this.multiplyUnsafe(y).add(g.multiplyUnsafe(p));return v.is0()?void 0:v}toAffine(g){return F(this,g)}isTorsionFree(){let{isTorsionFree:g}=t;return s===Cr?!0:g?g(m,this):B.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:g}=t;return s===Cr?this:g?g(m,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(g=!0){return pe(g,"isCompressed"),this.assertValidity(),h(m,this,g)}toHex(g=!0){return $t(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(g=!0){return this.toBytes(g)}_setWindowSize(g){this.precompute(g)}static normalizeZ(g){return ge(m,g)}static msm(g,y){return xr(m,o,g,y)}static fromPrivateKey(g){return m.BASE.multiply(Ir(o,g))}}m.BASE=new m(i.Gx,i.Gy,n.ONE),m.ZERO=new m(n.ZERO,n.ONE,n.ZERO),m.Fp=n,m.Fn=o;let T=o.BITS,B=new gr(m,t.endo?Math.ceil(T/2):T);return m.BASE.precompute(8),m}function ru(e){return Uint8Array.of(e?2:3)}function nu(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function ep(e,t={}){let{Fn:r}=e,n=t.randomBytes||hr,o=Object.assign(nu(e.Fp,r),{seed:Li(r.ORDER)});function i(h){try{return!!Ir(r,h)}catch{return!1}}function s(h,x){let{publicKey:w,publicKeyUncompressed:C}=o;try{let b=h.length;return x===!0&&b!==w||x===!1&&b!==C?!1:!!e.fromBytes(h)}catch{return!1}}function a(h=n(o.seed)){return Oi(Rt(h,o.seed,"seed"),r.ORDER)}function c(h,x=!0){return e.BASE.multiply(Ir(r,h)).toBytes(x)}function f(h){let x=a(h);return{secretKey:x,publicKey:c(x)}}function u(h){if(typeof h=="bigint")return!1;if(h instanceof e)return!0;let{secretKey:x,publicKey:w,publicKeyUncompressed:C}=o;if(r.allowedLengths||x===w)return;let b=Z("key",h).length;return b===w||b===C}function l(h,x,w=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(x)===!1)throw new Error("second arg must be public key");let C=Ir(r,h);return e.fromHex(x).multiply(C).toBytes(w)}return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:f,Point:e,utils:{isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a,isValidPrivateKey:i,randomPrivateKey:a,normPrivateKeyToScalar:h=>Ir(r,h),precompute(h=8,x=e.BASE){return x.precompute(h,!1)}},lengths:o})}function rp(e,t,r={}){Nn(t),Re(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||hr,o=r.hmac||((y,...p)=>Ss(t,y,Et(...p))),{Fp:i,Fn:s}=e,{ORDER:a,BITS:c}=s,{keygen:f,getPublicKey:u,getSharedSecret:l,utils:d,lengths:h}=ep(e,r),x={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},w="compact";function C(y){let p=a>>Cr;return y>p}function b(y,p){if(!s.isValidNot0(p))throw new Error(`invalid signature ${y}: out of range 1..Point.Fn.ORDER`);return p}function P(y,p){As(p);let v=h.signature,D=p==="compact"?v:p==="recovered"?v+1:void 0;return Rt(y,D,`${p} signature`)}class S{constructor(p,v,D){this.r=b("r",p),this.s=b("s",v),D!=null&&(this.recovery=D),Object.freeze(this)}static fromBytes(p,v=w){P(p,v);let D;if(v==="der"){let{r:K,s:$}=Ee.toSig(Rt(p));return new S(K,$)}v==="recovered"&&(D=p[0],v="compact",p=p.subarray(1));let L=s.BYTES,R=p.subarray(0,L),O=p.subarray(L,L*2);return new S(s.fromBytes(R),s.fromBytes(O),D)}static fromHex(p,v){return this.fromBytes(qe(p),v)}addRecoveryBit(p){return new S(this.r,this.s,p)}recoverPublicKey(p){let v=i.ORDER,{r:D,s:L,recovery:R}=this;if(R==null||![0,1,2,3].includes(R))throw new Error("recovery id invalid");if(a*eu<v&&R>1)throw new Error("recovery id is ambiguous for h>1 curve");let K=R===2||R===3?D+a:D;if(!i.isValid(K))throw new Error("recovery id 2 or 3 invalid");let $=i.toBytes(K),tt=e.fromBytes(Et(ru((R&1)===0),$)),Y=s.inv(K),z=k(Z("msgHash",p)),et=s.create(-z*Y),ct=s.create(L*Y),At=e.BASE.multiplyUnsafe(et).add(tt.multiplyUnsafe(ct));if(At.is0())throw new Error("point at infinify");return At.assertValidity(),At}hasHighS(){return C(this.s)}toBytes(p=w){if(As(p),p==="der")return qe(Ee.hexFromSig(this));let v=s.toBytes(this.r),D=s.toBytes(this.s);if(p==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return Et(Uint8Array.of(this.recovery),v,D)}return Et(v,D)}toHex(p){return $t(this.toBytes(p))}assertValidity(){}static fromCompact(p){return S.fromBytes(Z("sig",p),"compact")}static fromDER(p){return S.fromBytes(Z("sig",p),"der")}normalizeS(){return this.hasHighS()?new S(this.r,s.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return $t(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return $t(this.toBytes("compact"))}}let N=r.bits2int||function(p){if(p.length>8192)throw new Error("input is too large");let v=pr(p),D=p.length*8-c;return D>0?v>>BigInt(D):v},k=r.bits2int_modN||function(p){return s.create(N(p))},F=Ue(c);function V(y){return Wr("num < 2^"+c,y,Se,F),s.toBytes(y)}function A(y,p){return Rt(y,void 0,"message"),p?Rt(t(y),void 0,"prehashed message"):y}function m(y,p,v){if(["recovered","canonical"].some(et=>et in v))throw new Error("sign() legacy options not supported");let{lowS:D,prehash:L,extraEntropy:R}=vs(v,x);y=A(y,L);let O=k(y),K=Ir(s,p),$=[V(K),V(O)];if(R!=null&&R!==!1){let et=R===!0?n(h.secretKey):R;$.push(Z("extraEntropy",et))}let tt=Et(...$),Y=O;function z(et){let ct=N(et);if(!s.isValidNot0(ct))return;let At=s.inv(ct),rt=e.BASE.multiply(ct).toAffine(),gt=s.create(rt.x);if(gt===Se)return;let In=s.create(At*s.create(Y+gt*K));if(In===Se)return;let ya=(rt.x===gt?0:2)|Number(rt.y&Cr),ga=In;return D&&C(In)&&(ga=s.neg(In),ya^=1),new S(gt,ga,ya)}return{seed:tt,k2sig:z}}function T(y,p,v={}){y=Z("message",y);let{seed:D,k2sig:L}=m(y,p,v);return pc(t.outputLen,s.BYTES,o)(D,L)}function B(y){let p,v=typeof y=="string"||le(y),D=!v&&y!==null&&typeof y=="object"&&typeof y.r=="bigint"&&typeof y.s=="bigint";if(!v&&!D)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(D)p=new S(y.r,y.s);else if(v){try{p=S.fromBytes(Z("sig",y),"der")}catch(L){if(!(L instanceof Ee.Err))throw L}if(!p)try{p=S.fromBytes(Z("sig",y),"compact")}catch{return!1}}return p||!1}function I(y,p,v,D={}){let{lowS:L,prehash:R,format:O}=vs(D,x);if(v=Z("publicKey",v),p=A(Z("message",p),R),"strict"in D)throw new Error("options.strict was renamed to lowS");let K=O===void 0?B(y):S.fromBytes(Z("sig",y),O);if(K===!1)return!1;try{let $=e.fromBytes(v);if(L&&K.hasHighS())return!1;let{r:tt,s:Y}=K,z=k(p),et=s.inv(Y),ct=s.create(z*et),At=s.create(tt*et),rt=e.BASE.multiplyUnsafe(ct).add($.multiplyUnsafe(At));return rt.is0()?!1:s.create(rt.x)===tt}catch{return!1}}function g(y,p,v={}){let{prehash:D}=vs(v,x);return p=A(p,D),S.fromBytes(y,"recovered").recoverPublicKey(p).toBytes()}return Object.freeze({keygen:f,getPublicKey:u,getSharedSecret:l,utils:d,lengths:h,Point:e,sign:T,verify:I,recoverPublicKey:g,Signature:S,hash:t})}function np(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(s=>Math.ceil(s/2)))):void 0,o=Nt(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),i={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:i}}function op(e){let{CURVE:t,curveOpts:r}=np(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function ip(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,Mn(r.Fn.ORDER,r.Fn.BITS))})}function ou(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=op(e),i=tp(t,r),s=rp(i,n,o);return ip(e,s)}function iu(e,t){let r=n=>ou({...e,hash:n});return{...r(t),create:r}}var Ts={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},sp={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var su=BigInt(2);function ap(e){let t=Ts.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=e*e*e%t,u=f*f*e%t,l=J(u,r,t)*u%t,d=J(l,r,t)*u%t,h=J(d,su,t)*f%t,x=J(h,o,t)*h%t,w=J(x,i,t)*x%t,C=J(w,a,t)*w%t,b=J(C,c,t)*C%t,P=J(b,a,t)*w%t,S=J(P,r,t)*u%t,N=J(S,s,t)*x%t,k=J(N,n,t)*f%t,F=J(k,su,t);if(!Cs.eql(Cs.sqr(F),e))throw new Error("Cannot find square root");return F}var Cs=Nt(Ts.p,{sqrt:ap}),Tr=iu({...Ts,Fp:Cs,lowS:!0,endo:sp},Kn);function au(e,t,r,n){let o=Vr.digest(r instanceof Uint8Array?r:r.subarray());if(jn(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Tr.verify(t,i,e))).catch(i=>{throw i.name==="AbortError"?i:new tn(String(i))});try{return n?.signal?.throwIfAborted(),Tr.verify(t,o.digest,e)}catch(i){throw new tn(String(i))}}var to=class{type="secp256k1";raw;_key;constructor(t){this._key=uu(t),this.raw=cu(this._key)}toMultihash(){return Pt.digest(fr(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:X(this.raw,t.raw)}verify(t,r,n){return au(this._key,r,t,n)}};function Bs(e){return new to(e)}function cu(e){return Tr.ProjectivePoint.fromHex(e).toRawBytes(!0)}function uu(e){try{return Tr.ProjectivePoint.fromHex(e),e}catch(t){throw new tr(String(t))}}function fu(e,t){let{Type:r,Data:n}=oe.decode(e),o=n??new Uint8Array;switch(r){case it.RSA:return ws(o,t);case it.Ed25519:return Gi(o);case it.secp256k1:return Bs(o);case it.ECDSA:return Ei(o);default:throw new rr}}function eo(e){let{Type:t,Data:r}=oe.decode(e.digest),n=r??new Uint8Array;switch(t){case it.Ed25519:return Gi(n);case it.secp256k1:return Bs(n);case it.ECDSA:return Ei(n);default:throw new rr}}function fr(e){return oe.encode({Type:it[e.type],Data:e.raw})}var lu=Symbol.for("nodejs.util.inspect.custom"),cp=114,cn=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()})`}[zo]=!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(cp,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return X(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return X(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[lu](){return`PeerId(${this.toString()})`}},ro=class extends cn{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},no=class extends cn{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},oo=class extends cn{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},up=2336,un=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Pt.digest(q(this.url))}[lu](){return`PeerId(${this.url})`}[zo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return j.createV1(up,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=H(t)),t.toString()===this.toString())}};var fp=114,du=2336;function hu(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=Ve(W.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return _s(j.parse(e));if(t==null)throw new st('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=Ve(t.decode(e))}return pu(r)}function pu(e){if(dp(e))return new ro({multihash:e});if(lp(e))try{let t=eo(e);if(t.type==="Ed25519")return new no({multihash:e,publicKey:t});if(t.type==="secp256k1")return new oo({multihash:e,publicKey:t})}catch{let r=H(e.digest);return new un(new URL(r))}throw new er("Supplied PeerID Multihash is invalid")}function _s(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==fp&&e.code!==du)throw new Tn("Supplied PeerID CID is invalid");if(e.code===du){let t=H(e.multihash.digest);return new un(new URL(t))}return pu(e.multihash)}function lp(e){return e.code===Pt.code}function dp(e){return e.code===Vr.code}var pt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},ve=class extends Error{static name="ValidationError";name="ValidationError"},fn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},io=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var so=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,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,t);if(!Number.isNaN(d))return d});if(u===void 0)break;if(i*=t,i+=u,i>f||(s+=1,r!==void 0&&s>r))return}if(s!==0)return!n&&c&&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),[a]=t(i.subarray(0,s));return r.set(i.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var hp=45,pp=15,ao=new so;function Ps(e){if(!(e.length>pp))return ao.new(e).parseWith(()=>ao.readIPv4Addr())}function Ds(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>hp))return ao.new(e).parseWith(()=>ao.readIPv6Addr())}function co(e){return!!Ps(e)}function yu(e){return!!Ds(e)}function Rs(e){return t=>H(t,e)}function Ns(e){return t=>q(t,e)}function Br(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function We(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function gu(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=q(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=We(n);return Mt([r,o],r.length+o.length)}function xu(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=ee.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=We(n);return Mt([r,o],r.length+o.length)}function Ls(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=H(t,"base32"),o=Br(r);return`${n}:${o}`}var Os=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new pt("Invalid byte value in IP address");t[n]=o}),t},wu=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let i=co(r[n]),s;i&&(s=Os(r[n]),r[n]=H(s.subarray(0,2),"base16")),s!=null&&++n<8&&r.splice(n,0,H(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 pt("Invalid byte value in IP address");o[t++]=i>>8&255,o[t++]=i&255}return o},bu=function(e){if(e.byteLength!==4)throw new pt("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Eu=function(e){if(e.byteLength!==16)throw new pt("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 pt(`Invalid IPv6 address "${r}"`)}};function Su(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new pt(`Invalid IPv6 address "${e}"`)}}var Us=Object.values(Mr).map(e=>e.decoder),mp=function(){let e=Us[0].or(Us[1]);return Us.slice(2).forEach(t=>e=e.or(t)),e}();function vu(e){return mp.decode(e)}function Au(e){return t=>e.encoder.encode(t)}function yp(e){if(parseInt(e).toString()!==e)throw new ve("Value must be an integer")}function gp(e){if(e<0)throw new ve("Value must be a positive integer, or zero")}function xp(e){return t=>{if(t>e)throw new ve(`Value must be smaller than or equal to ${e}`)}}function wp(...e){return t=>{for(let r of e)r(t)}}var ln=wp(yp,gp,xp(65535));var lt=-1,ks=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 io(`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)}))}},Ot=new ks,Yp=[{code:4,name:"ip4",size:32,valueToBytes:Os,bytesToValue:bu,validate:e=>{if(!co(e))throw new ve(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:We,bytesToValue:Br,validate:ln},{code:273,name:"udp",size:16,valueToBytes:We,bytesToValue:Br,validate:ln},{code:33,name:"dccp",size:16,valueToBytes:We,bytesToValue:Br,validate:ln},{code:41,name:"ip6",size:128,valueToBytes:wu,bytesToValue:Eu,stringToValue:Su,validate:e=>{if(!yu(e))throw new ve(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:lt},{code:43,name:"ipcidr",size:8,bytesToValue:Rs("base10"),valueToBytes:Ns("base10")},{code:53,name:"dns",size:lt,resolvable:!0},{code:54,name:"dns4",size:lt,resolvable:!0},{code:55,name:"dns6",size:lt,resolvable:!0},{code:56,name:"dnsaddr",size:lt,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:We,bytesToValue:Br,validate:ln},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:lt,path:!0,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:lt,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:Ls,valueToBytes:gu},{code:445,name:"onion3",size:296,bytesToValue:Ls,valueToBytes:xu},{code:446,name:"garlic64",size:lt},{code:447,name:"garlic32",size:lt},{code:448,name:"tls"},{code:449,name:"sni",size:lt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:lt,bytesToValue:Au(Qo),valueToBytes:vu},{code:480,name:"http"},{code:481,name:"http-path",size:lt,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:lt}];Yp.forEach(e=>{Ot.addProtocol(e)});function Iu(e){let t=[],r=0;for(;r<e.length;){let n=Qi(e,r),o=Ot.getProtocol(n),i=ne(n),s=Wp(o,e,r+i),a=0;s>0&&o.size===lt&&(a=ne(s));let c=i+a+s,f={code:n,name:o.name,bytes:e.subarray(r,r+c)};if(s>0){let u=r+i+a,l=e.subarray(u,u+s);f.value=o.bytesToValue?.(l)??H(l)}t.push(f),r+=c}return t}function Cu(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=Ot.getProtocol(n.code),i=ne(n.code),s,a=0,c=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??q(n.value),a=s.byteLength,o.size===lt&&(c=ne(a)));let f=new Uint8Array(i+c+a),u=0;en(n.code,f,u),u+=i,s!=null&&(o.size===lt&&(en(a,f,u),u+=c),f.set(s,u)),n.bytes=f}r.push(n.bytes),t+=n.bytes.byteLength}return Mt(r,t)}function Tu(e){if(e.charAt(0)!=="/")throw new pt('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 a=i===e.length-1;if(s==="/"||a){let c=Ot.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new pt(`Component ${o} was missing value`);r="value"}else if(r==="value"){let f={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new pt(`Component ${o} was missing value`);f.value=c.stringToValue?.(n)??n}t.push(f),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new pt("Incomplete multiaddr");return t}function Bu(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=Ot.getProtocol(t.code);if(r==null)throw new pt(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Wp(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Qi(t,r)}var Xp=Symbol.for("nodejs.util.inspect.custom"),zs=Symbol.for("@multiformats/multiaddr"),Jp=[53,54,55,56],Hs=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}};function Qp(e){if(e==null&&(e="/"),Pu(e))return e.getComponents();if(e instanceof Uint8Array)return Iu(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Tu(e);if(Array.isArray(e))return e;throw new pt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var po=class e{[zs]=!0;#t;#n;#e;constructor(t="/",r={}){this.#t=Qp(t),r.validate!==!1&&t0(this)}get bytes(){return this.#e==null&&(this.#e=Cu(this.#t)),this.#e}toString(){return this.#n==null&&(this.#n=Bu(this.#t)),this.#n}toJSON(){return this.toString()}toOptions(){let t,r,n,o,i="";for(let{code:a,name:c,value:f}of this.#t)a===42&&(i=`%${f??""}`),Jp.includes(a)&&(r="tcp",o=443,n=`${f??""}${i}`,t=a===55?6:4),(a===6||a===273)&&(r=c==="tcp"?"tcp":"udp",o=parseInt(f??"")),(a===4||a===41)&&(r="tcp",n=`${f??""}${i}`,t=a===41?6:4);if(t==null||r==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:r,port:o}}getComponents(){return[...this.#t]}protos(){return this.#t.map(({code:t,value:r})=>{let n=Ot.getProtocol(t);return{code:t,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#t.map(({code:t})=>t)}protoNames(){return this.#t.map(({name:t})=>t)}tuples(){return this.#t.map(({code:t,value:r})=>{if(r==null)return[t];let n=Ot.getProtocol(t),o=[t];return r!=null&&o.push(n.valueToBytes?.(r)??q(r)),o})}stringTuples(){return this.#t.map(({code:t,value:r})=>r==null?[t]:[t,r])}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: ${t.toString()}`);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})}getPeerId(){try{let t=[];this.#t.forEach(({code:n,value:o})=>{n===421&&t.push([n,o]),n===290&&(t=[])});let r=t.pop();if(r?.[1]!=null){let n=r[1];return n[0]==="Q"||n[0]==="1"?H(W.decode(`z${n}`),"base58btc"):H(j.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let t of this.#t)if(Ot.getProtocol(t.code).path)return t.value??null;return null}equals(t){return X(this.bytes,t.bytes)}async resolve(t){let r=this.protos().find(i=>i.resolvable);if(r==null)return[this];let n=_u.get(r.name);if(n==null)throw new Hs(`no available resolver for ${r.name}`);return(await n(this,t)).map(i=>Xe(i))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(){return!(this.#t.length!==2||this.#t[0].code!==4&&this.#t[0].code!==41||this.#t[1].code!==6&&this.#t[1].code!==273)}[Xp](){return`Multiaddr(${this.toString()})`}};function t0(e){e.getComponents().forEach(t=>{let r=Ot.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}var y1=parseInt("0xFFFF",16),g1=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var _u=new Map;function Pu(e){return!!e?.[zs]}function Xe(e){return new po(e)}function hn(e){let t=new globalThis.AbortController;function r(){t.abort();for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}for(let i of e){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=t.signal;return o.clear=n,o}async function*mo(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 K0=Ho(Gs(),1);var Yt=class extends Error{static name="SignatureVerificationError";constructor(t="Record signature verification failed"){super(t),this.name="SignatureVerificationError"}},yo=class extends Error{static name="RecordExpiredError";constructor(t="Record has expired"){super(t),this.name="RecordExpiredError"}},_r=class extends Error{static name="UnsupportedValidityError";constructor(t="The validity type is unsupported"){super(t),this.name="UnsupportedValidityError"}},go=class extends Error{static name="RecordTooLargeError";constructor(t="The record is too large"){super(t),this.name="RecordTooLargeError"}},xo=class extends Error{static name="InvalidValueError";constructor(t="Value must be a valid content path starting with /"){super(t),this.name="InvalidValueError"}},wo=class extends Error{static name="InvalidRecordDataError";constructor(t="Invalid record data"){super(t),this.name="InvalidRecordDataError"}},pn=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(t="Invalid embedded public key"){super(t),this.name="InvalidEmbeddedPublicKeyError"}};var Wt;(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=()=>on(r)}(t=e.ValidityType||(e.ValidityType={}));let n;e.codec=()=>(n==null&&(n=vr((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 a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let f=o.uint32();switch(f>>>3){case 1:{a.value=o.bytes();break}case 2:{a.signatureV1=o.bytes();break}case 3:{a.validityType=e.ValidityType.codec().decode(o);break}case 4:{a.validity=o.bytes();break}case 5:{a.sequence=o.uint64();break}case 6:{a.ttl=o.uint64();break}case 7:{a.pubKey=o.bytes();break}case 8:{a.signatureV2=o.bytes();break}case 9:{a.data=o.bytes();break}default:{o.skipType(f&7);break}}}return a})),n),e.encode=o=>Er(o,e.codec()),e.decode=(o,i)=>br(o,e.codec(),i)})(Wt||(Wt={}));var i0=["string","number","bigint","symbol"],s0=["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 Ru(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(i0.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(a0(e))return"Buffer";let r=c0(e);return r||"Object"}function a0(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function c0(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(s0.includes(t))return t}var E=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}};E.uint=new E(0,"uint",!0);E.negint=new E(1,"negint",!0);E.bytes=new E(2,"bytes",!0);E.string=new E(3,"string",!0);E.array=new E(4,"array",!1);E.map=new E(5,"map",!1);E.tag=new E(6,"tag",!1);E.float=new E(7,"float",!0);E.false=new E(7,"false",!0);E.true=new E(7,"true",!0);E.null=new E(7,"null",!0);E.undefined=new E(7,"undefined",!0);E.break=new E(7,"break",!0);var U=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Pr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",u0=new TextDecoder,f0=new TextEncoder;function bo(e){return Pr&&globalThis.Buffer.isBuffer(e)}function ku(e){return e instanceof Uint8Array?bo(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Ku=Pr?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):Lu(e,t,r):(e,t,r)=>r-t>64?u0.decode(e.subarray(t,r)):Lu(e,t,r),Fu=Pr?e=>e.length>64?globalThis.Buffer.from(e):Nu(e):e=>e.length>64?f0.encode(e):Nu(e);var Dr=Pr?(e,t,r)=>bo(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Vu=Pr?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),ku(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},Mu=Pr?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function $u(e,t){if(bo(e)&&bo(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 Nu(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 Lu(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 a,c,f,u;switch(s){case 1:o<128&&(i=o);break;case 2:a=e[t+1],(a&192)===128&&(u=(o&31)<<6|a&63,u>127&&(i=u));break;case 3:a=e[t+1],c=e[t+2],(a&192)===128&&(c&192)===128&&(u=(o&15)<<12|(a&63)<<6|c&63,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:a=e[t+1],c=e[t+2],f=e[t+3],(a&192)===128&&(c&192)===128&&(f&192)===128&&(u=(o&15)<<18|(a&63)<<12|(c&63)<<6|f&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 l0(n)}var Ou=4096;function l0(e){let t=e.length;if(t<=Ou)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Ou));return r}var d0=256,Eo=class{constructor(t=d0){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=Mu(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=Dr(n,0,this.cursor)}else r=Vu(this.chunks,this.cursor);return t&&this.reset(),r}};var M="CBOR decode error:",Zs="CBOR encode error:",mn=[];mn[23]=1;mn[24]=2;mn[25]=3;mn[26]=5;mn[27]=9;function Ae(e,t,r){if(e.length-t<r)throw new Error(`${M} not enough data for type`)}var dt=[24,256,65536,4294967296,BigInt("18446744073709551616")];function kt(e,t,r){Ae(e,t,1);let n=e[t];if(r.strict===!0&&n<dt[0])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);return n}function Kt(e,t,r){Ae(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<dt[1])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);return n}function Ft(e,t,r){Ae(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<dt[2])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);return n}function Vt(e,t,r){Ae(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<dt[3])throw new Error(`${M} 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(`${M} integers outside of the safe integer range are not supported`)}function qu(e,t,r,n){return new U(E.uint,kt(e,t+1,n),2)}function Hu(e,t,r,n){return new U(E.uint,Kt(e,t+1,n),3)}function zu(e,t,r,n){return new U(E.uint,Ft(e,t+1,n),5)}function ju(e,t,r,n){return new U(E.uint,Vt(e,t+1,n),9)}function Ht(e,t){return mt(e,0,t.value)}function mt(e,t,r){if(r<dt[0]){let n=Number(r);e.push([t|n])}else if(r<dt[1]){let n=Number(r);e.push([t|24,n])}else if(r<dt[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<dt[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<dt[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(`${M} encountered BigInt larger than allowable range`)}}Ht.encodedSize=function(t){return mt.encodedSize(t.value)};mt.encodedSize=function(t){return t<dt[0]?1:t<dt[1]?2:t<dt[2]?3:t<dt[3]?5:9};Ht.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function Gu(e,t,r,n){return new U(E.negint,-1-kt(e,t+1,n),2)}function Zu(e,t,r,n){return new U(E.negint,-1-Kt(e,t+1,n),3)}function Yu(e,t,r,n){return new U(E.negint,-1-Ft(e,t+1,n),5)}var Ys=BigInt(-1),Wu=BigInt(1);function Xu(e,t,r,n){let o=Vt(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new U(E.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${M} integers outside of the safe integer range are not supported`);return new U(E.negint,Ys-BigInt(o),9)}function So(e,t){let r=t.value,n=typeof r=="bigint"?r*Ys-Wu:r*-1-1;mt(e,t.type.majorEncoded,n)}So.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*Ys-Wu:r*-1-1;return n<dt[0]?1:n<dt[1]?2:n<dt[2]?3:n<dt[3]?5:9};So.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function yn(e,t,r,n){Ae(e,t,r+n);let o=Dr(e,t+r,t+r+n);return new U(E.bytes,o,r+n)}function Ju(e,t,r,n){return yn(e,t,1,r)}function Qu(e,t,r,n){return yn(e,t,2,kt(e,t+1,n))}function tf(e,t,r,n){return yn(e,t,3,Kt(e,t+1,n))}function ef(e,t,r,n){return yn(e,t,5,Ft(e,t+1,n))}function rf(e,t,r,n){let o=Vt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer bytes lengths not supported`);return yn(e,t,9,o)}function vo(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===E.string?Fu(e.value):e.value),e.encodedBytes}function Ur(e,t){let r=vo(t);mt(e,t.type.majorEncoded,r.length),e.push(r)}Ur.encodedSize=function(t){let r=vo(t);return mt.encodedSize(r.length)+r.length};Ur.compareTokens=function(t,r){return p0(vo(t),vo(r))};function p0(e,t){return e.length<t.length?-1:e.length>t.length?1:$u(e,t)}function gn(e,t,r,n,o){let i=r+n;Ae(e,t,i);let s=new U(E.string,Ku(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=Dr(e,t+r,t+i)),s}function nf(e,t,r,n){return gn(e,t,1,r,n)}function of(e,t,r,n){return gn(e,t,2,kt(e,t+1,n),n)}function sf(e,t,r,n){return gn(e,t,3,Kt(e,t+1,n),n)}function af(e,t,r,n){return gn(e,t,5,Ft(e,t+1,n),n)}function cf(e,t,r,n){let o=Vt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer string lengths not supported`);return gn(e,t,9,o,n)}var uf=Ur;function Rr(e,t,r,n){return new U(E.array,n,r)}function ff(e,t,r,n){return Rr(e,t,1,r)}function lf(e,t,r,n){return Rr(e,t,2,kt(e,t+1,n))}function df(e,t,r,n){return Rr(e,t,3,Kt(e,t+1,n))}function hf(e,t,r,n){return Rr(e,t,5,Ft(e,t+1,n))}function pf(e,t,r,n){let o=Vt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer array lengths not supported`);return Rr(e,t,9,o)}function mf(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${M} indefinite length items not allowed`);return Rr(e,t,1,1/0)}function Ao(e,t){mt(e,E.array.majorEncoded,t.value)}Ao.compareTokens=Ht.compareTokens;Ao.encodedSize=function(t){return mt.encodedSize(t.value)};function Nr(e,t,r,n){return new U(E.map,n,r)}function yf(e,t,r,n){return Nr(e,t,1,r)}function gf(e,t,r,n){return Nr(e,t,2,kt(e,t+1,n))}function xf(e,t,r,n){return Nr(e,t,3,Kt(e,t+1,n))}function wf(e,t,r,n){return Nr(e,t,5,Ft(e,t+1,n))}function bf(e,t,r,n){let o=Vt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer map lengths not supported`);return Nr(e,t,9,o)}function Ef(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${M} indefinite length items not allowed`);return Nr(e,t,1,1/0)}function Io(e,t){mt(e,E.map.majorEncoded,t.value)}Io.compareTokens=Ht.compareTokens;Io.encodedSize=function(t){return mt.encodedSize(t.value)};function Sf(e,t,r,n){return new U(E.tag,r,1)}function vf(e,t,r,n){return new U(E.tag,kt(e,t+1,n),2)}function Af(e,t,r,n){return new U(E.tag,Kt(e,t+1,n),3)}function If(e,t,r,n){return new U(E.tag,Ft(e,t+1,n),5)}function Cf(e,t,r,n){return new U(E.tag,Vt(e,t+1,n),9)}function Co(e,t){mt(e,E.tag.majorEncoded,t.value)}Co.compareTokens=Ht.compareTokens;Co.encodedSize=function(t){return mt.encodedSize(t.value)};var b0=20,E0=21,S0=22,v0=23;function Tf(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${M} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new U(E.null,null,1):new U(E.undefined,void 0,1)}function Bf(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${M} indefinite length items not allowed`);return new U(E.break,void 0,1)}function Ws(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${M} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${M} Infinity values are not supported`)}return new U(E.float,e,t)}function _f(e,t,r,n){return Ws(Xs(e,t+1),3,n)}function Pf(e,t,r,n){return Ws(Js(e,t+1),5,n)}function Df(e,t,r,n){return Ws(Lf(e,t+1),9,n)}function To(e,t,r){let n=t.value;if(n===!1)e.push([E.float.majorEncoded|b0]);else if(n===!0)e.push([E.float.majorEncoded|E0]);else if(n===null)e.push([E.float.majorEncoded|S0]);else if(n===void 0)e.push([E.float.majorEncoded|v0]);else{let o,i=!1;(!r||r.float64!==!0)&&(Rf(n),o=Xs(Xt,1),n===o||Number.isNaN(n)?(Xt[0]=249,e.push(Xt.slice(0,3)),i=!0):(Nf(n),o=Js(Xt,1),n===o&&(Xt[0]=250,e.push(Xt.slice(0,5)),i=!0))),i||(A0(n),o=Lf(Xt,1),Xt[0]=251,e.push(Xt.slice(0,9)))}}To.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){Rf(n);let o=Xs(Xt,1);if(n===o||Number.isNaN(n))return 3;if(Nf(n),o=Js(Xt,1),n===o)return 5}return 9};var Uf=new ArrayBuffer(9),zt=new DataView(Uf,1),Xt=new Uint8Array(Uf,0);function Rf(e){if(e===1/0)zt.setUint16(0,31744,!1);else if(e===-1/0)zt.setUint16(0,64512,!1);else if(Number.isNaN(e))zt.setUint16(0,32256,!1);else{zt.setFloat32(0,e);let t=zt.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)zt.setUint16(0,31744,!1);else if(r===0)zt.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?zt.setUint16(0,0):o<-14?zt.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):zt.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Xs(e,t){if(e.length-t<2)throw new Error(`${M} 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 Nf(e){zt.setFloat32(0,e,!1)}function Js(e,t){if(e.length-t<4)throw new Error(`${M} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function A0(e){zt.setFloat64(0,e,!1)}function Lf(e,t){if(e.length-t<8)throw new Error(`${M} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}To.compareTokens=Ht.compareTokens;function G(e,t,r){throw new Error(`${M} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Bo(e){return()=>{throw new Error(`${M} ${e}`)}}var _=[];for(let e=0;e<=23;e++)_[e]=G;_[24]=qu;_[25]=Hu;_[26]=zu;_[27]=ju;_[28]=G;_[29]=G;_[30]=G;_[31]=G;for(let e=32;e<=55;e++)_[e]=G;_[56]=Gu;_[57]=Zu;_[58]=Yu;_[59]=Xu;_[60]=G;_[61]=G;_[62]=G;_[63]=G;for(let e=64;e<=87;e++)_[e]=Ju;_[88]=Qu;_[89]=tf;_[90]=ef;_[91]=rf;_[92]=G;_[93]=G;_[94]=G;_[95]=Bo("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)_[e]=nf;_[120]=of;_[121]=sf;_[122]=af;_[123]=cf;_[124]=G;_[125]=G;_[126]=G;_[127]=Bo("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)_[e]=ff;_[152]=lf;_[153]=df;_[154]=hf;_[155]=pf;_[156]=G;_[157]=G;_[158]=G;_[159]=mf;for(let e=160;e<=183;e++)_[e]=yf;_[184]=gf;_[185]=xf;_[186]=wf;_[187]=bf;_[188]=G;_[189]=G;_[190]=G;_[191]=Ef;for(let e=192;e<=215;e++)_[e]=Sf;_[216]=vf;_[217]=Af;_[218]=If;_[219]=Cf;_[220]=G;_[221]=G;_[222]=G;_[223]=G;for(let e=224;e<=243;e++)_[e]=Bo("simple values are not supported");_[244]=G;_[245]=G;_[246]=G;_[247]=Tf;_[248]=Bo("simple values are not supported");_[249]=_f;_[250]=Pf;_[251]=Df;_[252]=G;_[253]=G;_[254]=G;_[255]=Bf;var Jt=[];for(let e=0;e<24;e++)Jt[e]=new U(E.uint,e,1);for(let e=-1;e>=-24;e--)Jt[31-e]=new U(E.negint,e,1);Jt[64]=new U(E.bytes,new Uint8Array(0),1);Jt[96]=new U(E.string,"",1);Jt[128]=new U(E.array,0,1);Jt[160]=new U(E.map,0,1);Jt[244]=new U(E.false,!1,1);Jt[245]=new U(E.true,!0,1);Jt[246]=new U(E.null,null,1);function C0(){let e=[];return e[E.uint.major]=Ht,e[E.negint.major]=So,e[E.bytes.major]=Ur,e[E.string.major]=uf,e[E.array.major]=Ao,e[E.map.major]=Io,e[E.tag.major]=Co,e[E.float.major]=To,e}var tE=C0(),eE=new Eo,_o=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(`${Zs} object contains circular references`);return new e(r,t)}},ke={null:new U(E.null,null),undefined:new U(E.undefined,void 0),true:new U(E.true,!0),false:new U(E.false,!1),emptyArray:new U(E.array,0),emptyMap:new U(E.map,0)},Ke={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new U(E.float,e):e>=0?new U(E.uint,e):new U(E.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new U(E.uint,e):new U(E.negint,e)},Uint8Array(e,t,r,n){return new U(E.bytes,e)},string(e,t,r,n){return new U(E.string,e)},boolean(e,t,r,n){return e?ke.true:ke.false},null(e,t,r,n){return ke.null},undefined(e,t,r,n){return ke.undefined},ArrayBuffer(e,t,r,n){return new U(E.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new U(E.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[ke.emptyArray,new U(E.break)]:ke.emptyArray;n=_o.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=Qs(s,r,n);return r.addBreakTokens?[new U(E.array,e.length),o,new U(E.break)]:[new U(E.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?[ke.emptyMap,new U(E.break)]:ke.emptyMap;n=_o.createCheck(n,e);let a=[],c=0;for(let f of i)a[c++]=[Qs(f,r,n),Qs(o?e.get(f):e[f],r,n)];return T0(a,r),r.addBreakTokens?[new U(E.map,s),a,new U(E.break)]:[new U(E.map,s),a]}};Ke.Map=Ke.Object;Ke.Buffer=Ke.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Ke[`${e}Array`]=Ke.DataView;function Qs(e,t={},r){let n=Ru(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||Ke[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=Ke[n];if(!i)throw new Error(`${Zs} unsupported type: ${n}`);return i(e,n,t,r)}function T0(e,t){t.mapSorter&&e.sort(t.mapSorter)}var B0={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Po=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=Jt[t];if(r===void 0){let n=_[t];if(!n)throw new Error(`${M} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},xn=Symbol.for("DONE"),Do=Symbol.for("BREAK");function _0(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=Lr(t,r);if(i===Do){if(e.value===1/0)break;throw new Error(`${M} got unexpected break to lengthed array`)}if(i===xn)throw new Error(`${M} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function P0(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 a=Lr(t,r);if(a===Do){if(e.value===1/0)break;throw new Error(`${M} got unexpected break to lengthed map`)}if(a===xn)throw new Error(`${M} found map but not enough entries (got ${s} [no key], expected ${e.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${M} non-string keys not supported (got ${typeof a})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${M} found repeat map key "${a}"`);let c=Lr(t,r);if(c===xn)throw new Error(`${M} found map but not enough entries (got ${s} [no value], expected ${e.value})`);n?i.set(a,c):o[a]=c}return n?i:o}function Lr(e,t){if(e.done())return xn;let r=e.next();if(r.type===E.break)return Do;if(r.type.terminal)return r.value;if(r.type===E.array)return _0(r,e,t);if(r.type===E.map)return P0(r,e,t);if(r.type===E.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=Lr(e,t);return t.tags[r.value](n)}throw new Error(`${M} tag not supported (${r.value})`)}throw new Error("unsupported")}function Of(e,t){if(!(e instanceof Uint8Array))throw new Error(`${M} data to decode must be a Uint8Array`);t=Object.assign({},B0,t);let r=t.tokenizer||new Po(e,t),n=Lr(r,t);if(n===xn)throw new Error(`${M} did not find any content to decode`);if(n===Do)throw new Error(`${M} got unexpected break`);return[n,e.subarray(r.pos())]}function ta(e,t){let[r,n]=Of(e,t);if(n.length>0)throw new Error(`${M} too many terminals, data makes no sense`);return r}var R0=Te("ipns:utils"),kf=q("/ipns/");var N0=0,L0=18;function Kf(e){let t;if(e.pubKey!=null)try{t=fu(e.pubKey)}catch(r){throw R0.error(r),r}if(t!=null)return t}function Ff(e){let t=q("ipns-signature:");return Mt([t,e])}function Qe(e){return"signatureV1"in e?Wt.encode({value:q(e.value),signatureV1:e.signatureV1,validityType:e.validityType,validity:q(e.validity),sequence:e.sequence,ttl:e.ttl,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data}):Wt.encode({pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data})}function ie(e){let t=Wt.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 Yt("Missing data or signatureV2");let r=Vf(t.data),n=O0(r.Value),o=H(r.Validity);if(t.value!=null&&t.signatureV1!=null)return k0(t),{value:n,validityType:Wt.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:Wt.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 wn(e){return Mt([kf,e.bytes])}function Ie(e){let t=Ve(e.slice(kf.length));if(!Uo(t,N0)&&!Uo(t,L0))throw new er("Multihash in IPNS key was not identity or sha2-256");return t}function Vf(e){let t=ta(e);if(t.ValidityType===0)t.ValidityType=Wt.ValidityType.EOL;else throw new _r("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 O0(e){let t=H(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 xo("Value must be a valid content path starting with /")}function k0(e){if(e.data==null)throw new wo("Record data is missing");let t=Vf(e.data);if(!X(t.Value,e.value??new Uint8Array(0)))throw new Yt('Field "value" did not match between protobuf and CBOR');if(!X(t.Validity,e.validity??new Uint8Array(0)))throw new Yt('Field "validity" did not match between protobuf and CBOR');if(t.ValidityType!==e.validityType)throw new Yt('Field "validityType" did not match between protobuf and CBOR');if(t.Sequence!==e.sequence)throw new Yt('Field "sequence" did not match between protobuf and CBOR');if(t.TTL!==e.ttl)throw new Yt('Field "ttl" did not match between protobuf and CBOR')}function Uo(e,t){return e.code===t}var AE=Te("ipns"),IE=300*1e9,F0="/ipns/",CE=F0.length;var Mf=Ho(Gs(),1);var Ro=Te("ipns:validator"),V0=1024*10;async function M0(e,t){let r=ie(t),n;try{let o=Ff(r.data);n=await e.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw Ro.error("record signature verification failed"),new Yt("Record signature verification failed");if(r.validityType===Wt.ValidityType.EOL){if(Mf.default.fromString(r.validity).toDate().getTime()<Date.now())throw Ro.error("record has expired"),new yo("record has expired")}else if(r.validityType!=null)throw Ro.error("the validity type is unsupported"),new _r("The validity type is unsupported");Ro("ipns record for %s is valid",r.value)}async function $f(e,t){if(t.byteLength>V0)throw new go("The record is too large");let r=Ie(e),n;Uo(r,0)&&(n=eo(r));let o=ie(t),i=Kf(o)??n;if(i==null)throw new pn("Could not extract public key from IPNS record or routing key");let s=wn(i.toMultihash());if(!X(s,e))throw new pn("Embedded public key did not match routing key");await M0(i,t)}var No=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MESSAGE_LENGTH"};async function*bn(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)),cr(i)&&(i=i.subarray()),o+=n.decode(i,{stream:!0}),o.length>(t?.maxMessageLength??o.length))throw new No("Incoming message too long");let s=o.split(r);o=s.pop()??"";for(let a=0;a<s.length;a++)yield JSON.parse(s[a])}o+=n.decode(),o!==""&&(yield JSON.parse(o))}function se(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var ra=Ho(Hf(),1);var Sn=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},na=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},zf=e=>globalThis.DOMException===void 0?new na(e):new DOMException(e),jf=e=>{let t=e.reason===void 0?zf("This operation was aborted."):e.reason;return t instanceof Error?t:zf(t)};function oa(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=t,s,a,f=new Promise((u,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:h}=t;h.aborted&&l(jf(h)),a=()=>{l(jf(h))},h.addEventListener("abort",a,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(u,l);return}let d=new Sn;s=i.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(h){l(h)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?u():o instanceof Error?l(o):(d.message=o??`Promise timed out after ${r} milliseconds`,l(d))},r),(async()=>{try{u(await e)}catch(h){l(h)}})()}).finally(()=>{f.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return f.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},f}function ia(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 vn=class{#t=[];enqueue(t,r){r={priority:0,...r};let n={priority:r.priority,id:r.id,run:t};if(this.size===0||this.#t[this.size-1].priority>=r.priority){this.#t.push(n);return}let o=ia(this.#t,n,(i,s)=>s.priority-i.priority);this.#t.splice(o,0,n)}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 ra.default{#t;#n;#e=0;#h;#a;#p=0;#o;#c;#r;#m;#i=0;#u;#s;#y;#w=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:vn,...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})`);this.#t=t.carryoverConcurrencyCount,this.#n=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#h=t.intervalCap,this.#a=t.interval,this.#r=new t.queueClass,this.#m=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#y=t.throwOnTimeout===!0,this.#s=t.autoStart===!1}get#b(){return this.#n||this.#e<this.#h}get#E(){return this.#i<this.#u}#S(){this.#i--,this.#f(),this.emit("next")}#v(){this.#x(),this.#g(),this.#c=void 0}get#A(){let t=Date.now();if(this.#o===void 0){let r=this.#p-t;if(r<0)this.#e=this.#t?this.#i:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},r)),!0}return!1}#f(){if(this.#r.size===0)return this.#o&&clearInterval(this.#o),this.#o=void 0,this.emit("empty"),this.#i===0&&this.emit("idle"),!1;if(!this.#s){let t=!this.#A;if(this.#b&&this.#E){let r=this.#r.dequeue();return r?(this.emit("active"),r(),t&&this.#g(),!0):!1}}return!1}#g(){this.#n||this.#o!==void 0||(this.#o=setInterval(()=>{this.#x()},this.#a),this.#p=Date.now()+this.#a)}#x(){this.#e===0&&this.#i===0&&this.#o&&(clearInterval(this.#o),this.#o=void 0),this.#e=this.#t?this.#i:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}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.#u=t,this.#l()}async#I(t){return new Promise((r,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}setPriority(t,r){this.#r.setPriority(t,r)}async add(t,r={}){return r.id??=(this.#w++).toString(),r={timeout:this.timeout,throwOnTimeout:this.#y,...r},new Promise((n,o)=>{this.#r.enqueue(async()=>{this.#i++,this.#e++;try{r.signal?.throwIfAborted();let i=t({signal:r.signal});r.timeout&&(i=oa(Promise.resolve(i),{milliseconds:r.timeout})),r.signal&&(i=Promise.race([i,this.#I(r.signal)]));let s=await i;n(s),this.emit("completed",s)}catch(i){if(i instanceof Sn&&!r.throwOnTimeout){n();return}o(i),this.emit("error",i)}finally{this.#S()}},r),this.emit("add"),this.#f()})}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}start(){return this.#s?(this.#s=!1,this.#l(),this):this}pause(){this.#s=!0}clear(){this.#r=new this.#m}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.#i===0&&this.#r.size===0||await this.#d("idle")}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.#i}get isPaused(){return this.#s}};var Or=class extends Error{static name="InvalidRequestError";constructor(t="Invalid request"){super(t),this.name="InvalidRequestError"}},Qt=class extends Error{static name="BadResponseError";constructor(t="Bad response"){super(t),this.name="BadResponseError"}};function H0(e){return e[Symbol.asyncIterator]!=null}function z0(e){if(H0(e))return(async()=>{for await(let t of e)return t})();for(let t of e)return t}var Oo=z0;function j0(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 Gf=j0;function G0(e){return e[Symbol.asyncIterator]!=null}function Z0(e,t){let r=0;if(G0(e))return async function*(){for await(let c of e)yield t(c,r++)}();let n=Gf(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 c of n)yield t(c,r++)}();let a=t;return function*(){yield s;for(let c of n)yield a(c,r++)}()}var ko=Z0;var Zf=q("/ipns/");function Yf(e){return X(e.subarray(0,Zf.byteLength),Zf)}var Ko=class{client;constructor(t){this.client=t}async*findProviders(t,r={}){yield*ko(this.client.getProviders(t,r),n=>({id:n.ID,multiaddrs:n.Addrs??[]}))}async provide(){}async cancelReprovide(){}async put(t,r,n){if(!Yf(t))return;let o=Ie(t),i=j.createV1(114,o),s=ie(r);await this.client.putIPNS(i,s,n)}async get(t,r){if(!Yf(t))throw new Ct("Not found");let n=Ie(t),o=j.createV1(114,n);try{let i=await this.client.getIPNS(o,r);return Qe(i)}catch(i){throw i.name==="BadResponseError"?new Ct("Not found"):i}}},Fo=class{client;constructor(t){this.client=t}async findPeer(t,r={}){let n=await Oo(this.client.getPeers(t,r));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new Ct("Not found")}async*getClosestPeers(t,r={}){}};var yt=Te("delegated-routing-v1-http-api-client"),Vo={concurrentRequests:4,timeout:3e4,cacheTTL:300*1e3,cacheName:"delegated-routing-v1-cache"},Mo=class{started;httpQueue;shutDownController;clientUrl;timeout;contentRouting;peerRouting;filterAddrs;filterProtocols;inFlightRequests;cacheName;cache;cacheTTL;constructor(t,r={}){this.started=!1,this.shutDownController=new AbortController,this.shutDownController.signal,this.httpQueue=new An({concurrency:r.concurrentRequests??Vo.concurrentRequests}),this.inFlightRequests=new Map,this.clientUrl=t instanceof URL?t:new URL(t),this.timeout=r.timeout??Vo.timeout,this.filterAddrs=r.filterAddrs,this.filterProtocols=r.filterProtocols,this.contentRouting=new Ko(this),this.peerRouting=new Fo(this),this.cacheName=r.cacheName??Vo.cacheName,this.cacheTTL=r.cacheTTL??Vo.cacheTTL}get[ba](){return this.contentRouting}get[Ea](){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&&yt("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={}){yt("getProviders starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=hn([this.shutDownController.signal,n,r.signal]);let i=se(),s=se();this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let a=new URL(`${this.clientUrl}routing/v1/providers/${t.toString()}`);this.#n(a,r.filterAddrs,r.filterProtocols);let c={headers:{Accept:"application/x-ndjson"},signal:o},f=await this.#e(a.toString(),c);if(f==null)throw new Qt("No response received");if(!f.ok)throw f.status===404?new Ct("No matching records found"):f.status===422?new Or("Request does not conform to schema or semantic constraints"):new Qt(`Unexpected status code: ${f.status}`);if(f.body==null)throw new Qt("Routing response had no body");let u=f.headers.get("Content-Type");if(u==null)throw new Qt("No Content-Type header received");if(u?.startsWith("application/json")){let l=await f.json();for(let d of l.Providers){let h=this.#t(d);h!=null&&(yield h)}}else if(u.includes("application/x-ndjson"))for await(let l of bn(mo(f.body))){let d=this.#t(l);d!=null&&(yield d)}else throw new Qt(`Unsupported Content-Type: ${u}`)}finally{o.clear(),s.resolve(),yt("getProviders finished: %c",t)}}async*getPeers(t,r={}){yt("getPeers starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=hn([this.shutDownController.signal,n,r.signal]);let i=se(),s=se();this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let a=new URL(`${this.clientUrl}routing/v1/peers/${t.toCID().toString()}`);this.#n(a,r.filterAddrs,r.filterProtocols);let c={headers:{Accept:"application/x-ndjson"},signal:o},f=await this.#e(a.toString(),c);if(f.status===404)throw new Ct("No matching records found");if(f.status===422)throw new Or("Request does not conform to schema or semantic constraints");if(f.body==null)throw new Qt("Routing response had no body");if(f.headers.get("Content-Type")==="application/json"){let l=await f.json();for(let d of l.Peers){let h=this.#t(d);h!=null&&(yield h)}}else for await(let l of bn(mo(f.body))){let d=this.#t(l);d!=null&&(yield d)}}catch(a){yt.error("getPeers errored:",a)}finally{o.clear(),s.resolve(),yt("getPeers finished: %c",t)}}async getIPNS(t,r={}){yt("getIPNS starts: %s",t);let n=AbortSignal.timeout(this.timeout),o=hn([this.shutDownController.signal,n,r.signal]);let i=se(),s=se();this.httpQueue.add(async()=>(i.resolve(),s.promise));let a=`${this.clientUrl}routing/v1/ipns/${t}`;try{await i.promise;let c={headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:o},f=await this.#e(a,c);if(yt("getIPNS GET %s %d",a,f.status),f.status===404)throw new Ct("No matching records found");if(f.status===422)throw new Or("Request does not conform to schema or semantic constraints");if(f.body==null)throw new Qt("GET ipns response had no body");let u=await f.arrayBuffer(),l=new Uint8Array(u,0,u.byteLength);return r.validate!==!1&&await $f(wn(t.multihash),l),ie(l)}catch(c){throw yt.error("getIPNS GET %s error:",a,c),c}finally{o.clear(),s.resolve(),yt("getIPNS finished: %s",t)}}async putIPNS(t,r,n={}){yt("putIPNS starts: %c",t);let o=AbortSignal.timeout(this.timeout),i=hn([this.shutDownController.signal,o,n.signal]);let s=se(),a=se();this.httpQueue.add(async()=>(s.resolve(),a.promise));let c=`${this.clientUrl}routing/v1/ipns/${t}`;try{await s.promise;let f=Qe(r),u={method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:f,signal:i},l=await this.#e(c,u);if(yt("putIPNS PUT %s %d",c,l.status),l.status!==200)throw new Qt("PUT ipns response had status other than 200")}catch(f){throw yt.error("putIPNS PUT %s error:",c,f.stack),f}finally{i.clear(),a.resolve(),yt("putIPNS finished: %c",t)}}#t(t){try{let r=[],n=t.Addrs?.map(Xe)??[];return t.Protocols!=null&&r.push(...t.Protocols),t.Protocol!=null&&(r.push(t.Protocol),delete t.Protocol),{...t,Schema:"peer",ID:hu(t.ID),Addrs:n,Protocols:r}}catch(r){yt.error("could not conform record to peer schema",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 c=await this.cache?.match(t);if(c!=null){if(parseInt(c.headers.get("x-cache-expires")??"0",10)>Date.now())return yt("returning cached response for %s",o),c;await this.cache?.delete(t)}}let i=this.inFlightRequests.get(o);if(i!=null){let c=await i;return yt("deduplicating outgoing request for %s",o),c.clone()}let s=fetch(t,r).then(async c=>{if(this.cache!=null&&c.ok&&n==="GET"){let f=Date.now()+this.cacheTTL,u=new Headers(c.headers);u.set("x-cache-expires",f.toString());let l=new Response(c.clone().body,{status:c.status,statusText:c.statusText,headers:u});await this.cache.put(t,l)}return c}).finally(()=>{this.inFlightRequests.delete(o)});return this.inFlightRequests.set(o,s),await s}};function Wf(e,t={}){return new Mo(new URL(e),t)}function $o(){return{filterProtocols:["unknown","transport-bitswap","transport-ipfs-gateway-http"],filterAddrs:["https","webtransport","webrtc","webrtc-direct","wss","tls"]}}var Xf=q("/ipns/");function Jf(e){return X(e.subarray(0,Xf.byteLength),Xf)}var sa=class{client;constructor(t,r={}){this.client=Wf(t,r)}async provide(t,r){}async cancelReprovide(t,r){}async*findProviders(t,r){yield*ko(this.client.getProviders(t,r),n=>({id:n.ID,multiaddrs:n.Addrs,protocols:n.Protocols}))}async put(t,r,n){if(!Jf(t))return;let o=Ie(t),i=j.createV1(114,o),s=ie(r);await this.client.putIPNS(i,s,n)}async get(t,r){if(!Jf(t))throw new Ct("Not found");let n=Ie(t),o=j.createV1(114,n);try{let i=await this.client.getIPNS(o,r);return Qe(i)}catch(i){throw i.name==="BadResponseError"?new Ct("Not found"):i}}async findPeer(t,r){let n=await Oo(this.client.getPeers(t,r));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new Ct("Not found")}async*getClosestPeers(t,r){}};function Qf(e,t){let r=t??$o();return new sa(new URL(e),r)}var tl="[a-fA-F\\d:]",Fe=e=>e&&e.includeBoundaries?`(?:(?<=\\s|^)(?=${tl})|(?<=${tl})(?=\\s|$))`:"",te="(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}",at="[a-fA-F\\d]{1,4}",qo=`
|
|
2
|
+
"use strict";var HeliaRouters=(()=>{var Fl=Object.create;var _n=Object.defineProperty;var $l=Object.getOwnPropertyDescriptor;var ql=Object.getOwnPropertyNames;var zl=Object.getPrototypeOf,Hl=Object.prototype.hasOwnProperty;var Da=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Bt=(e,t)=>{for(var r in t)_n(e,r,{get:t[r],enumerable:!0})},Pa=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ql(t))!Hl.call(e,o)&&o!==r&&_n(e,o,{get:()=>t[o],enumerable:!(n=$l(t,o))||n.enumerable});return e};var Jo=(e,t,r)=>(r=e!=null?Fl(zl(e)):{},Pa(t||!e||!e.__esModule?_n(r,"default",{value:e,enumerable:!0}):r,e)),jl=e=>Pa(_n({},"__esModule",{value:!0}),e);var Js=Da((IE,Xs)=>{var vE=(function(){typeof Xs<"u"&&(Xs.exports=T);var e=86400,t=3200,r=146097*t/400,n=e*r,o=1e3*n,i=864e13,s=4294967296,c=1e6,a="000000000",u=Math.trunc||function(h){var p=h-h%1;return p==0&&(h<0||h===0&&1/h!=1/0)?-0:p},f=T.prototype,l=(T.fromDate=function(h){return new T(+h)},T.fromInt64BE=R(0,1,2,3,0,4),T.fromInt64LE=R(3,2,1,0,4,0),T.fromString=function(D){var p,B=new T,D=(D+="").replace(/^\s*[+\-]?\d+/,function(m){var m=+m,y=1970+(m-1970)%400;return B.year=m-y,y}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(I,m,y){return m<0&&(y*=-1),p=6e4*(60*+m+ +y),""}).replace(/\.\d+$/,function(I){return B.nano=+(I+a).substr(1,9),""}).split(/\D+/);if(1<D.length?D[1]--:D[1]=0,B.time=p=Date.UTC.apply(Date,D)-(p||0),isNaN(p))throw new TypeError("Invalid Date");return C(B)},T.fromTimeT=function(h){return _(h,0)},f.year=0,f.time=0,f.nano=0,f.addNano=function(h){return this.nano+=+h||0,this},f.getNano=function(){var h=C(this);return(h.time%1e3*c+ +h.nano+1e9)%1e9},f.getTimeT=function(){var p=C(this),h=Math.floor(p.time/1e3),p=p.year;return p&&(h+=p*r*e/t),h},f.getYear=function(){return this.toDate().getUTCFullYear()+this.year},f.toDate=function(){return w(C(this).time)},f.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},f.toString=function(h){var p=this,B=p.toDate(),D={H:function(){return V(B.getUTCHours())},L:function(){return q(B.getUTCMilliseconds(),3)},M:function(){return V(B.getUTCMinutes())},N:function(){return q(p.getNano(),9)},S:function(){return V(B.getUTCSeconds())},Y:function(){var I=p.getYear();return 999999<I?"+"+I:9999<I?"+"+q(I,6):0<=I?q(I,4):-999999<=I?"-"+q(-I,6):I},a:function(){return E[B.getUTCDay()]},b:function(){return g[B.getUTCMonth()]},d:function(){return V(B.getUTCDate())},e:function(){return(function(I){return(9<I?"":" ")+(0|I)})(B.getUTCDate())},m:function(){return V(B.getUTCMonth()+1)}};return(function I(m){return m.replace(/%./g,function(y){var S=y[1],d=b[S],S=D[S];return d?I(d):S?S():y})})(h||l)},f.writeInt64BE=v(0,1,2,3,0,4),f.writeInt64LE=v(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),g=["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 T;function T(h,p,B){var D=this;if(!(D instanceof T))return new T(h,p,B);D.time=+h||0,D.nano=+p||0,D.year=+B||0,C(D)}function C(h){var p,B,D,I=h.year,m=h.time,y=h.nano,d=((y<0||c<=y)&&(y-=(B=Math.floor(y/c))*c,m+=B,B=1),I%t);return(m<-i||i<m||d)&&((p=u(m/o))&&(I+=p*t,m-=p*o),(D=w(m)).setUTCFullYear(d+D.getUTCFullYear()),D=(m=+D)+(p=u((I-=d)/t))*o,p&&-i<=D&&D<=i&&(I-=p*t,m=D),B=1),B&&(h.year=I,h.time=m,h.nano=y),h}function w(h){var p=new Date(0);return p.setTime(h),p}function _(I,D){I=+I||0;var B=u((D=(D|0)*s)/n)+u(I/n),D=D%n+I%n,I=u(D/n);return I&&(B+=I,D-=I*n),new T(1e3*D,0,B*t)}function v(h,p,B,D,I,m){return function(d,S){var O=C(this);d=d||new Array(8),K(d,S|=0);var U=Math.floor(O.time/1e3),O=O.year*(r*e/t),P=u(O/s)+u(U/s),O=O%s+U%s,U=Math.floor(O/s);return U&&(P+=U,O-=U*s),y(d,S+I,P),y(d,S+m,O),d};function y(d,S,P){d[S+h]=P>>24&255,d[S+p]=P>>16&255,d[S+B]=P>>8&255,d[S+D]=255&P}}function R(h,p,B,D,I,m){return function(d,S){K(d,S|=0);var P=y(d,S+I);return _(y(d,S+m),P)};function y(d,S){return 16777216*d[S+h]+(d[S+p]<<16|d[S+B]<<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 V(h){return(9<h?"":"0")+(0|h)}function q(h,p){return(a+(0|h)).substr(-p)}})()});var il=Da((mS,sa)=>{"use strict";var u0=Object.prototype.hasOwnProperty,_t="~";function wn(){}Object.create&&(wn.prototype=Object.create(null),new wn().__proto__||(_t=!1));function f0(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function ol(e,t,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new f0(r,n||e,o),s=_t?_t+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 ko(e,t){--e._eventsCount===0?e._events=new wn:delete e._events[t]}function Ct(){this._events=new wn,this._eventsCount=0}Ct.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)u0.call(r,n)&&t.push(_t?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};Ct.prototype.listeners=function(t){var r=_t?_t+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};Ct.prototype.listenerCount=function(t){var r=_t?_t+t:t,n=this._events[r];return n?n.fn?1:n.length:0};Ct.prototype.emit=function(t,r,n,o,i,s){var c=_t?_t+t:t;if(!this._events[c])return!1;var a=this._events[c],u=arguments.length,f,l;if(a.fn){switch(a.once&&this.removeListener(t,a.fn,void 0,!0),u){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(l=1,f=new Array(u-1);l<u;l++)f[l-1]=arguments[l];a.fn.apply(a.context,f)}else{var g=a.length,E;for(l=0;l<g;l++)switch(a[l].once&&this.removeListener(t,a[l].fn,void 0,!0),u){case 1:a[l].fn.call(a[l].context);break;case 2:a[l].fn.call(a[l].context,r);break;case 3:a[l].fn.call(a[l].context,r,n);break;case 4:a[l].fn.call(a[l].context,r,n,o);break;default:if(!f)for(E=1,f=new Array(u-1);E<u;E++)f[E-1]=arguments[E];a[l].fn.apply(a[l].context,f)}}return!0};Ct.prototype.on=function(t,r,n){return ol(this,t,r,n,!1)};Ct.prototype.once=function(t,r,n){return ol(this,t,r,n,!0)};Ct.prototype.removeListener=function(t,r,n,o){var i=_t?_t+t:t;if(!this._events[i])return this;if(!r)return ko(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&ko(this,i);else{for(var c=0,a=[],u=s.length;c<u;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:ko(this,i)}return this};Ct.prototype.removeAllListeners=function(t){var r;return t?(r=_t?_t+t:t,this._events[r]&&ko(this,r)):(this._events=new wn,this._eventsCount=0),this};Ct.prototype.off=Ct.prototype.removeListener;Ct.prototype.addListener=Ct.prototype.on;Ct.prefixed=_t;Ct.EventEmitter=Ct;typeof sa<"u"&&(sa.exports=Ct)});var Ny={};Bt(Ny,{delegatedHTTPRouting:()=>pl,delegatedHTTPRoutingDefaults:()=>zo,httpGatewayRouting:()=>Ml,libp2pRouting:()=>Vl});var Ra=Symbol.for("@libp2p/content-routing");var Qo=Symbol.for("@libp2p/peer-id");var Oa=Symbol.for("@libp2p/peer-routing");var Bn=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}};var Qt=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Dn=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Pn=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var oi={};Bt(oi,{base32:()=>Dt,base32hex:()=>rd,base32hexpad:()=>od,base32hexpadupper:()=>id,base32hexupper:()=>nd,base32pad:()=>td,base32padupper:()=>ed,base32upper:()=>Ql,base32z:()=>sd});var Vy=new Uint8Array(0);function Na(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 se(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 Ua(e){return new TextEncoder().encode(e)}function La(e){return new TextDecoder().decode(e)}function Gl(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),u=Math.log(c)/Math.log(256),f=Math.log(256)/Math.log(c);function l(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var T=0,C=0,w=0,_=b.length;w!==_&&b[w]===0;)w++,T++;for(var v=(_-w)*f+1>>>0,R=new Uint8Array(v);w!==_;){for(var K=b[w],V=0,q=v-1;(K!==0||V<C)&&q!==-1;q--,V++)K+=256*R[q]>>>0,R[q]=K%c>>>0,K=K/c>>>0;if(K!==0)throw new Error("Non-zero carry");C=V,w++}for(var h=v-C;h!==v&&R[h]===0;)h++;for(var p=a.repeat(T);h<v;++h)p+=e.charAt(R[h]);return p}function g(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var T=0;if(b[T]!==" "){for(var C=0,w=0;b[T]===a;)C++,T++;for(var _=(b.length-T)*u+1>>>0,v=new Uint8Array(_);b[T];){var R=r[b.charCodeAt(T)];if(R===255)return;for(var K=0,V=_-1;(R!==0||K<w)&&V!==-1;V--,K++)R+=c*v[V]>>>0,v[V]=R%256>>>0,R=R/256>>>0;if(R!==0)throw new Error("Non-zero carry");w=K,T++}if(b[T]!==" "){for(var q=_-w;q!==_&&v[q]===0;)q++;for(var h=new Uint8Array(C+(_-q)),p=C;q!==_;)h[p++]=v[q++];return h}}}function E(b){var T=g(b);if(T)return T;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:g,decode:E}}var Zl=Gl,Wl=Zl,Ka=Wl;var ti=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")}},ei=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 Ma(this,t)}},ri=class{decoders;constructor(t){this.decoders=t}or(t){return Ma(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 Ma(e,t){return new ri({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var ni=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 ti(t,r,n),this.decoder=new ei(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function tr({name:e,prefix:t,encode:r,decode:n}){return new ni(e,t,r,n)}function Ee({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ka(r,e);return tr({prefix:t,name:e,encode:n,decode:i=>se(o(i))})}function Yl(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 u=0;u<o;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|f,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 Xl(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 Jl(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=Jl(n);return tr({prefix:t,name:e,encode(i){return Xl(i,n,r)},decode(i){return Yl(i,o,r,e)}})}var Dt=ot({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ql=ot({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),td=ot({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ed=ot({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),rd=ot({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),nd=ot({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),od=ot({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),id=ot({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),sd=ot({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ii={};Bt(ii,{base58btc:()=>W,base58flickr:()=>ad});var W=Ee({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ad=Ee({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var si={};Bt(si,{base64:()=>Kr,base64pad:()=>cd,base64url:()=>Mr,base64urlpad:()=>ud});var Kr=ot({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),cd=ot({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Mr=ot({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ud=ot({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function fd(e,t){if(typeof e=="string")return ld(e);if(typeof e=="number")return pd(e,t);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(e)}`)}var Rn=fd;function ld(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 dd(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 hd(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 pd(e,t){if(typeof e!="number"||!Number.isFinite(e))throw Error("Value provided to ms.format() must be of type number.");return t?.long?hd(e):dd(e)}function ke(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function ai(e){r.debug=r,r.default=r,r.coerce=a,r.disable=i,r.enable=o,r.enabled=s,r.humanize=Rn,r.destroy=u,Object.keys(e).forEach(f=>{r[f]=e[f]}),r.names=[],r.skips=[],r.formatters={};function t(f){let l=0;for(let g=0;g<f.length;g++)l=(l<<5)-l+f.charCodeAt(g),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=t;function r(f){let l,g=null,E,b;function T(...C){if(!T.enabled)return;let w=T,_=Number(new Date),v=_-(l||_);w.diff=v,w.prev=l,w.curr=_,l=_,C[0]=r.coerce(C[0]),typeof C[0]!="string"&&C.unshift("%O");let R=0;C[0]=C[0].replace(/%([a-zA-Z%])/g,(V,q)=>{if(V==="%%")return"%";R++;let h=r.formatters[q];if(typeof h=="function"){let p=C[R];V=h.call(w,p),C.splice(R,1),R--}return V}),r.formatArgs.call(w,C),(w.log||r.log).apply(w,C)}return T.namespace=f,T.useColors=r.useColors(),T.color=r.selectColor(f),T.extend=n,T.destroy=r.destroy,Object.defineProperty(T,"enabled",{enumerable:!0,configurable:!1,get:()=>g!==null?g:(E!==r.namespaces&&(E=r.namespaces,b=r.enabled(f)),b),set:C=>{g=C}}),typeof r.init=="function"&&r.init(T),T}function n(f,l){let g=r(this.namespace+(typeof l>"u"?":":l)+f);return g.log=this.log,g}function o(f){r.save(f),r.namespaces=f,r.names=[],r.skips=[];let l,g=(typeof f=="string"?f:"").split(/[\s,]+/),E=g.length;for(l=0;l<E;l++)g[l]&&(f=g[l].replace(/\*/g,".*?"),f[0]==="-"?r.skips.push(new RegExp("^"+f.substr(1)+"$")):r.names.push(new RegExp("^"+f+"$")))}function i(){let f=[...r.names.map(c),...r.skips.map(c).map(l=>"-"+l)].join(",");return r.enable(""),f}function s(f){if(f[f.length-1]==="*")return!0;let l,g;for(l=0,g=r.skips.length;l<g;l++)if(r.skips[l].test(f))return!1;for(l=0,g=r.names.length;l<g;l++)if(r.names[l].test(f))return!0;return!1}function c(f){return f.toString().substring(2,f.toString().length-2).replace(/\.\*\?$/,"*")}function a(f){return f instanceof Error?f.stack??f.message:f}function u(){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 On=Ed(),md=["#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 yd(){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 gd(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+Rn(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 xd=console.debug??console.log??(()=>{});function bd(e){try{e?On?.setItem("debug",e):On?.removeItem("debug")}catch{}}function wd(){let e;try{e=On?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function Ed(){try{return localStorage}catch{}}function Sd(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Va=ai({formatArgs:gd,save:bd,load:wd,useColors:yd,setupFormatters:Sd,colors:md,storage:On,log:xd});var X=Va;X.formatters.b=e=>e==null?"undefined":W.baseEncode(e);X.formatters.t=e=>e==null?"undefined":Dt.baseEncode(e);X.formatters.m=e=>e==null?"undefined":Kr.baseEncode(e);X.formatters.p=e=>e==null?"undefined":e.toString();X.formatters.c=e=>e==null?"undefined":e.toString();X.formatters.k=e=>e==null?"undefined":e.toString();X.formatters.a=e=>e==null?"undefined":e.toString();X.formatters.e=e=>e==null?"undefined":Fa(e.stack)??Fa(e.message)??e.toString();function vd(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 ci(e){let t=vd(`${e}:trace`);return X.enabled(`${e}:trace`)&&X.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(t=X(`${e}:trace`)),Object.assign(X(e),{error:X(`${e}:error`),trace:t,newScope:r=>ci(`${e}:${r}`)})}function Fa(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var ct=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},er=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var rr=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Nn=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Un=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var nr=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var ui=Symbol.for("@libp2p/peer-id");var fi={};Bt(fi,{base36:()=>or,base36upper:()=>Id});var or=Ee({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Id=Ee({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Cd=za,$a=128,Td=127,Ad=~Td,_d=Math.pow(2,31);function za(e,t,r){t=t||[],r=r||0;for(var n=r;e>=_d;)t[r++]=e&255|$a,e/=128;for(;e&Ad;)t[r++]=e&255|$a,e>>>=7;return t[r]=e|0,za.bytes=r-n+1,t}var Bd=li,Dd=128,qa=127;function li(e,n){var r=0,n=n||0,o=0,i=n,s,c=e.length;do{if(i>=c)throw li.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&qa)<<o:(s&qa)*Math.pow(2,o),o+=7}while(s>=Dd);return li.bytes=i-n,r}var Pd=Math.pow(2,7),Rd=Math.pow(2,14),Od=Math.pow(2,21),Nd=Math.pow(2,28),Ud=Math.pow(2,35),Ld=Math.pow(2,42),kd=Math.pow(2,49),Kd=Math.pow(2,56),Md=Math.pow(2,63),Vd=function(e){return e<Pd?1:e<Rd?2:e<Od?3:e<Nd?4:e<Ud?5:e<Ld?6:e<kd?7:e<Kd?8:e<Md?9:10},Fd={encode:Cd,decode:Bd,encodingLength:Vd},$d=Fd,Vr=$d;function Fr(e,t=0){return[Vr.decode(e,t),Vr.decode.bytes]}function ir(e,t,r=0){return Vr.encode(e,t,r),t}function sr(e){return Vr.encodingLength(e)}function te(e,t){let r=t.byteLength,n=sr(e),o=n+sr(r),i=new Uint8Array(o+r);return ir(e,i,0),ir(r,i,n),i.set(t,o),new ar(e,r,t,i)}function Se(e){let t=se(e),[r,n]=Fr(t),[o,i]=Fr(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new ar(r,o,s,t)}function Ha(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Na(e.bytes,r.bytes)}}var ar=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function ja(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return zd(r,di(e),t??W.encoder);default:return Hd(r,di(e),t??Dt.encoder)}}var Ga=new WeakMap;function di(e){let t=Ga.get(e);if(t==null){let r=new Map;return Ga.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!==$r)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==jd)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=te(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&&Ha(t.multihash,n.multihash)}toString(t){return ja(this,t)}toJSON(){return{"/":ja(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??Za(n,o,i.bytes))}else if(r[Gd]===!0){let{version:n,multihash:o,code:i}=r,s=Se(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!==$r)throw new Error(`Version 0 CID must use dag-pb (code: ${$r}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Za(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,$r,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=se(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 ar(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[l,g]=Fr(t.subarray(r));return r+=g,l},o=n(),i=$r;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(),u=r+a,f=u-s;return{version:o,codec:i,multihashCode:c,digestSize:a,multihashSize:f,size:u}}static parse(t,r){let[n,o]=qd(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 di(i).set(n,t),i}};function qd(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 Dt.prefix:{let r=t??Dt;return[Dt.prefix,r.decode(e)]}case or.prefix:{let r=t??or;return[or.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 zd(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 Hd(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 $r=112,jd=18;function Za(e,t,r){let n=sr(e),o=n+sr(t),i=new Uint8Array(o+r.byteLength);return ir(e,i,0),ir(t,i,n),i.set(r,o),i}var Gd=Symbol.for("@ipld/js-cid/CID");var hi={};Bt(hi,{identity:()=>mt});var Wa=0,Zd="identity",Ya=se;function Wd(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 te(Wa,Ya(e))}var mt={code:Wa,name:Zd,encode:Ya,digest:Wd};function Y(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 ae(e=0){return new Uint8Array(e)}function Ot(e=0){return new Uint8Array(e)}function yt(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=Ot(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Ja=Symbol.for("@achingbrain/uint8arraylist");function Xa(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 cr(e){return!!e?.[Ja]}var Nt=class e{bufs;length;[Ja]=!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(cr(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(cr(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=Xa(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Xa(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(cr(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 yt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:yt(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 u=t>=c&&t<a,f=r>c&&r<=a;if(u&&f){if(t===c&&r===a){n.push(s);break}let l=t-c;n.push(s.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(s);continue}n.push(s.subarray(t-c));continue}if(f){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(!cr(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 l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let c=s,a=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=a;l+=f){f=0;for(let g=u;g>=0;g--){let E=this.get(l+g);if(n[g]!==E){f=Math.max(1,g-c[E]);break}}if(f===0)return l}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=Ot(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=ae(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=ae(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=ae(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=Ot(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=ae(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=ae(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=ae(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=ae(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=ae(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(!Y(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 pi={};Bt(pi,{base10:()=>Yd});var Yd=Ee({prefix:"9",name:"base10",alphabet:"0123456789"});var mi={};Bt(mi,{base16:()=>Xd,base16upper:()=>Jd});var Xd=ot({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Jd=ot({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var yi={};Bt(yi,{base2:()=>Qd});var Qd=ot({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var gi={};Bt(gi,{base256emoji:()=>oh});var Qa=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}"),th=Qa.reduce((e,t,r)=>(e[r]=t,e),[]),eh=Qa.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function rh(e){return e.reduce((t,r)=>(t+=th[r],t),"")}function nh(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=eh[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var oh=tr({prefix:"\u{1F680}",name:"base256emoji",encode:rh,decode:nh});var xi={};Bt(xi,{base8:()=>ih});var ih=ot({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var bi={};Bt(bi,{identity:()=>sh});var sh=tr({prefix:"\0",name:"identity",encode:e=>La(e),decode:e=>Ua(e)});var Kg=new TextEncoder,Mg=new TextDecoder;var Si={};Bt(Si,{sha256:()=>Ke,sha512:()=>fh});var uh=20;function Ei({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new wi(e,t,r,n,o)}var wi=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??uh,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?tc(n,this.code,r?.truncate):n.then(o=>tc(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function tc(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 te(t,e)}function rc(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Ke=Ei({name:"sha2-256",code:18,encode:rc("SHA-256")}),fh=Ei({name:"sha2-512",code:19,encode:rc("SHA-512")});var Me={...bi,...yi,...xi,...pi,...mi,...oi,...fi,...ii,...si,...gi},Xg={...Si,...hi};function oc(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var nc=oc("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),vi=oc("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=Ot(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),lh={utf8:nc,"utf-8":nc,hex:Me.base16,latin1:vi,ascii:vi,binary:vi,...Me},kn=lh;function F(e,t="utf8"){let r=kn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function k(e,t="utf8"){let r=kn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var dh=parseInt("11111",2),Ii=parseInt("10000000",2),hh=parseInt("01111111",2),ic={0:qr,1:qr,2:ph,3:gh,4:xh,5:yh,6:mh,16:qr,22:qr,48:qr};function ce(e,t={offset:0}){let r=e[t.offset]&dh;if(t.offset++,ic[r]!=null)return ic[r](e,t);throw new Error("No decoder for tag "+r)}function zr(e,t){let r=0;if((e[t.offset]&Ii)===Ii){let n=e[t.offset]&hh,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 qr(e,t){zr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=ce(e,t);if(n===null)break;r.push(n)}return r}function ph(e,t){let r=zr(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 mh(e,t){let r=zr(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 u=e[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let f=0;for(let l=0;l<a.length;l++)f+=a[l]<<l*7;c+=`.${f}`,a=[]}}return c}function yh(e,t){return t.offset++,null}function gh(e,t){let r=zr(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 xh(e,t){let r=zr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function bh(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new Nt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Ci(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=bh(e.byteLength);return new Nt(Uint8Array.from([t.byteLength|Ii]),t)}function Pt(e){let t=new Nt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new Nt(Uint8Array.from([2]),Ci(t),t)}function Kn(e){let t=Uint8Array.from([0]),r=new Nt(t,e);return new Nt(Uint8Array.from([3]),Ci(r),r)}function Ie(e,t=48){let r=new Nt;for(let n of e)r.append(n);return new Nt(Uint8Array.from([t]),Ci(r),r)}async function sc(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 wh=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Eh=Uint8Array.from([6,5,43,129,4,0,34]),Sh=Uint8Array.from([6,5,43,129,4,0,35]),vh={ext:!0,kty:"EC",crv:"P-256"},Ih={ext:!0,kty:"EC",crv:"P-384"},Ch={ext:!0,kty:"EC",crv:"P-521"},Ti=32,Ai=48,_i=66;function Bi(e){let t=ce(e);return ac(t)}function ac(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Ti*2+1)return n=k(t.subarray(r,r+Ti),"base64url"),o=k(t.subarray(r+Ti),"base64url"),new ur({...vh,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ai*2+1)return n=k(t.subarray(r,r+Ai),"base64url"),o=k(t.subarray(r+Ai),"base64url"),new ur({...Ih,key_ops:["verify"],x:n,y:o});if(t.byteLength===_i*2+1)return n=k(t.subarray(r,r+_i),"base64url"),o=k(t.subarray(r+_i),"base64url"),new ur({...Ch,key_ops:["verify"],x:n,y:o});throw new ct(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function cc(e){return Ie([Pt(Uint8Array.from([1])),Ie([Th(e.crv)],160),Ie([Kn(new Nt(Uint8Array.from([4]),F(e.x??"","base64url"),F(e.y??"","base64url")))],161)]).subarray()}function Th(e){if(e==="P-256")return wh;if(e==="P-384")return Eh;if(e==="P-521")return Sh;throw new ct(`Invalid curve ${e}`)}var ur=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=cc(this.jwk)),this._raw}toMultihash(){return mt.digest(fr(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:Y(this.raw,t.raw)}async verify(t,r,n){return sc(this.jwk,r,t,n)}};function Ve(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function ee(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function H(e,t,r=""){let n=Ve(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");ee(e.outputLen),ee(e.blockLen)}function lr(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 fc(e,t){H(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 fe(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Vn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function zt(e,t){return e<<32-t|e>>>t}var lc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Ah=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function le(e){if(H(e),lc)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Ah[e[r]];return t}var ue={_0:48,_9:57,A:65,F:70,a:97,f:102};function uc(e){if(e>=ue._0&&e<=ue._9)return e-ue._0;if(e>=ue.A&&e<=ue.F)return e-(ue.A-10);if(e>=ue.a&&e<=ue.f)return e-(ue.a-10)}function de(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(lc)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=uc(e.charCodeAt(i)),c=uc(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 Rt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];H(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 Di(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 dr(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 Pi=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function dc(e,t,r){return e&t^~e&r}function hc(e,t,r){return e&t^e&r^t&r}var Hr=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=Vn(this.buffer)}update(t){lr(this),H(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=Vn(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){lr(this),fc(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,fe(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),i),this.process(n,0);let c=Vn(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=a/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,f[l],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()}},he=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var gt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Fn=BigInt(4294967295),pc=BigInt(32);function _h(e,t=!1){return t?{h:Number(e&Fn),l:Number(e>>pc&Fn)}:{h:Number(e>>pc&Fn)|0,l:Number(e&Fn)|0}}function mc(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}=_h(e[i],t);[n[i],o[i]]=[s,c]}return[n,o]}var Ri=(e,t,r)=>e>>>r,Oi=(e,t,r)=>e<<32-r|t>>>r,Fe=(e,t,r)=>e>>>r|t<<32-r,$e=(e,t,r)=>e<<32-r|t>>>r,jr=(e,t,r)=>e<<64-r|t>>>r-32,Gr=(e,t,r)=>e>>>r-32|t<<64-r;function re(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var yc=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),gc=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,xc=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),bc=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,wc=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Ec=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;var Dh=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]),Ce=new Uint32Array(64),Ni=class extends Hr{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 l=0;l<16;l++,r+=4)Ce[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let g=Ce[l-15],E=Ce[l-2],b=zt(g,7)^zt(g,18)^g>>>3,T=zt(E,17)^zt(E,19)^E>>>10;Ce[l]=T+Ce[l-7]+b+Ce[l-16]|0}let{A:n,B:o,C:i,D:s,E:c,F:a,G:u,H:f}=this;for(let l=0;l<64;l++){let g=zt(c,6)^zt(c,11)^zt(c,25),E=f+g+dc(c,a,u)+Dh[l]+Ce[l]|0,T=(zt(n,2)^zt(n,13)^zt(n,22))+hc(n,o,i)|0;f=u,u=a,a=c,c=s+E|0,s=i,i=o,o=n,n=E+T|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,i,s,c,a,u,f)}roundClean(){fe(Ce)}destroy(){this.set(0,0,0,0,0,0,0,0),fe(this.buffer)}},Ui=class extends Ni{A=he[0]|0;B=he[1]|0;C=he[2]|0;D=he[3]|0;E=he[4]|0;F=he[5]|0;G=he[6]|0;H=he[7]|0;constructor(){super(32)}};var Sc=mc(["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))),Ph=Sc[0],Rh=Sc[1],Te=new Uint32Array(80),Ae=new Uint32Array(80),Li=class extends Hr{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:u,El:f,Fh:l,Fl:g,Gh:E,Gl:b,Hh:T,Hl:C}=this;return[t,r,n,o,i,s,c,a,u,f,l,g,E,b,T,C]}set(t,r,n,o,i,s,c,a,u,f,l,g,E,b,T,C){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=g|0,this.Gh=E|0,this.Gl=b|0,this.Hh=T|0,this.Hl=C|0}process(t,r){for(let v=0;v<16;v++,r+=4)Te[v]=t.getUint32(r),Ae[v]=t.getUint32(r+=4);for(let v=16;v<80;v++){let R=Te[v-15]|0,K=Ae[v-15]|0,V=Fe(R,K,1)^Fe(R,K,8)^Ri(R,K,7),q=$e(R,K,1)^$e(R,K,8)^Oi(R,K,7),h=Te[v-2]|0,p=Ae[v-2]|0,B=Fe(h,p,19)^jr(h,p,61)^Ri(h,p,6),D=$e(h,p,19)^Gr(h,p,61)^Oi(h,p,6),I=xc(q,D,Ae[v-7],Ae[v-16]),m=bc(I,V,B,Te[v-7],Te[v-16]);Te[v]=m|0,Ae[v]=I|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:c,Cl:a,Dh:u,Dl:f,Eh:l,El:g,Fh:E,Fl:b,Gh:T,Gl:C,Hh:w,Hl:_}=this;for(let v=0;v<80;v++){let R=Fe(l,g,14)^Fe(l,g,18)^jr(l,g,41),K=$e(l,g,14)^$e(l,g,18)^Gr(l,g,41),V=l&E^~l&T,q=g&b^~g&C,h=wc(_,K,q,Rh[v],Ae[v]),p=Ec(h,w,R,V,Ph[v],Te[v]),B=h|0,D=Fe(n,o,28)^jr(n,o,34)^jr(n,o,39),I=$e(n,o,28)^Gr(n,o,34)^Gr(n,o,39),m=n&i^n&c^i&c,y=o&s^o&a^s&a;w=T|0,_=C|0,T=E|0,C=b|0,E=l|0,b=g|0,{h:l,l:g}=re(u|0,f|0,p|0,B|0),u=c|0,f=a|0,c=i|0,a=s|0,i=n|0,s=o|0;let d=yc(B,I,y);n=gc(d,p,D,m),o=d|0}({h:n,l:o}=re(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=re(this.Bh|0,this.Bl|0,i|0,s|0),{h:c,l:a}=re(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:f}=re(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:g}=re(this.Eh|0,this.El|0,l|0,g|0),{h:E,l:b}=re(this.Fh|0,this.Fl|0,E|0,b|0),{h:T,l:C}=re(this.Gh|0,this.Gl|0,T|0,C|0),{h:w,l:_}=re(this.Hh|0,this.Hl|0,w|0,_|0),this.set(n,o,i,s,c,a,u,f,l,g,E,b,T,C,w,_)}roundClean(){fe(Te,Ae)}destroy(){fe(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ki=class extends Li{Ah=gt[0]|0;Al=gt[1]|0;Bh=gt[2]|0;Bl=gt[3]|0;Ch=gt[4]|0;Cl=gt[5]|0;Dh=gt[6]|0;Dl=gt[7]|0;Eh=gt[8]|0;El=gt[9]|0;Fh=gt[10]|0;Fl=gt[11]|0;Gh=gt[12]|0;Gl=gt[13]|0;Hh=gt[14]|0;Hl=gt[15]|0;constructor(){super(64)}};var hr=Di(()=>new Ui,Pi(1));var vc=Di(()=>new ki,Pi(3));var Mi=BigInt(0),Ki=BigInt(1);function pe(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function Ic(e){if(typeof e=="bigint"){if(!$n(e))throw new Error("positive bigint expected, got "+e)}else ee(e);return e}function Zr(e){let t=Ic(e).toString(16);return t.length&1?"0"+t:t}function Cc(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Mi:BigInt("0x"+e)}function pr(e){return Cc(le(e))}function qe(e){return Cc(le(zn(H(e)).reverse()))}function qn(e,t){ee(t),e=Ic(e);let r=de(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function Vi(e,t){return qn(e,t).reverse()}function zn(e){return Uint8Array.from(e)}var $n=e=>typeof e=="bigint"&&Mi<=e;function Oh(e,t,r){return $n(e)&&$n(t)&&$n(r)&&t<=e&&e<r}function Wr(e,t,r,n){if(!Oh(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Fi(e){let t;for(t=0;e>Mi;e>>=Ki,t+=1);return t}var Yr=e=>(Ki<<BigInt(e))-Ki;function Tc(e,t,r){if(ee(e,"hashLen"),ee(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),u=n(e),f=0,l=()=>{a.fill(1),u.fill(0),f=0},g=(...C)=>r(u,Rt(a,...C)),E=(C=o)=>{u=g(i,C),a=g(),C.length!==0&&(u=g(s,C),a=g())},b=()=>{if(f++>=c)throw new Error("drbg: tried max amount of iterations");let C=0,w=[];for(;C<t;){a=g();let _=a.slice();w.push(_),C+=a.length}return Rt(...w)};return(C,w)=>{l(),E(C);let _;for(;!(_=w(b()));)E();return l(),_}}function _e(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 u=typeof a;if(u!==s||a===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${u}`)}let o=(i,s)=>Object.entries(i).forEach(([c,a])=>n(c,a,s));o(t,!1),o(r,!0)}function mr(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 Tt=BigInt(0),ut=BigInt(1),ze=BigInt(2),Bc=BigInt(3),Dc=BigInt(4),Pc=BigInt(5),Nh=BigInt(7),Rc=BigInt(8),Uh=BigInt(9),Oc=BigInt(16);function it(e,t){let r=e%t;return r>=Tt?r:t+r}function Q(e,t,r){let n=e;for(;t-- >Tt;)n*=n,n%=r;return n}function Ac(e,t){if(e===Tt)throw new Error("invert: expected non-zero number");if(t<=Tt)throw new Error("invert: expected positive modulus, got "+t);let r=it(e,t),n=t,o=Tt,i=ut,s=ut,c=Tt;for(;r!==Tt;){let u=n/r,f=n%r,l=o-s*u,g=i-c*u;n=r,r=f,o=s,i=c,s=l,c=g}if(n!==ut)throw new Error("invert: does not exist");return it(o,t)}function qi(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Nc(e,t){let r=(e.ORDER+ut)/Dc,n=e.pow(t,r);return qi(e,n,t),n}function Lh(e,t){let r=(e.ORDER-Pc)/Rc,n=e.mul(t,ze),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,ze),o),c=e.mul(i,e.sub(s,e.ONE));return qi(e,c,t),c}function kh(e){let t=yr(e),r=Uc(e),n=r(t,t.neg(t.ONE)),o=r(t,n),i=r(t,t.neg(n)),s=(e+Nh)/Oc;return(c,a)=>{let u=c.pow(a,s),f=c.mul(u,n),l=c.mul(u,o),g=c.mul(u,i),E=c.eql(c.sqr(f),a),b=c.eql(c.sqr(l),a);u=c.cmov(u,f,E),f=c.cmov(g,l,b);let T=c.eql(c.sqr(f),a),C=c.cmov(u,f,T);return qi(c,C,a),C}}function Uc(e){if(e<Bc)throw new Error("sqrt is not defined for small field");let t=e-ut,r=0;for(;t%ze===Tt;)t/=ze,r++;let n=ze,o=yr(e);for(;_c(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Nc;let i=o.pow(n,t),s=(t+ut)/ze;return function(a,u){if(a.is0(u))return u;if(_c(a,u)!==1)throw new Error("Cannot find square root");let f=r,l=a.mul(a.ONE,i),g=a.pow(u,t),E=a.pow(u,s);for(;!a.eql(g,a.ONE);){if(a.is0(g))return a.ZERO;let b=1,T=a.sqr(g);for(;!a.eql(T,a.ONE);)if(b++,T=a.sqr(T),b===f)throw new Error("Cannot find square root");let C=ut<<BigInt(f-b-1),w=a.pow(l,C);f=b,l=a.sqr(w),g=a.mul(g,l),E=a.mul(E,w)}return E}}function Kh(e){return e%Dc===Bc?Nc:e%Rc===Pc?Lh:e%Oc===Uh?kh(e):Uc(e)}var Lc=(e,t)=>(it(e,t)&ut)===ut,Mh=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function zi(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Mh.reduce((n,o)=>(n[o]="function",n),t);return _e(e,r),e}function Vh(e,t,r){if(r<Tt)throw new Error("invalid exponent, negatives unsupported");if(r===Tt)return e.ONE;if(r===ut)return t;let n=e.ONE,o=t;for(;r>Tt;)r&ut&&(n=e.mul(n,o)),o=e.sqr(o),r>>=ut;return n}function Xr(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 _c(e,t){let r=(e.ORDER-ut)/ze,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 Fh(e,t){t!==void 0&&ee(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var $i=class{ORDER;BITS;BYTES;isLE;ZERO=Tt;ONE=ut;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=Tt)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}=Fh(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 Tt<=t&&t<this.ORDER}is0(t){return t===Tt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&ut)===ut}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 Vh(this,t,r)}div(t,r){return it(t*Ac(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 Ac(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=Kh(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?Vi(t,this.BYTES):qn(t,this.BYTES)}fromBytes(t,r=!1){H(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 u=new Uint8Array(o);u.set(t,i?0:u.length-t.length),t=u}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let a=i?qe(t):pr(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 Xr(this,t)}cmov(t,r,n){return n?r:t}};function yr(e,t={}){return new $i(e,t)}function kc(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 Hi(e){let t=kc(e);return t+Math.ceil(t/2)}function ji(e,t,r=!1){H(e);let n=e.length,o=kc(t),i=Hi(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?qe(e):pr(e),c=it(s,t-ut)+ut;return r?Vi(c,o):qn(c,o)}var gr=BigInt(0),He=BigInt(1);function Jr(e,t){let r=t.negate();return e?r:t}function je(e,t){let r=Xr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Fc(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Gi(e,t){Fc(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,i=Yr(e),s=BigInt(e);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function Kc(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+=He);let u=t*n,f=u+Math.abs(c)-1,l=c===0,g=c<0,E=t%2!==0;return{nextN:a,offset:f,isZero:l,isNeg:g,isNegF:E,offsetF:u}}var Zi=new WeakMap,$c=new WeakMap;function Wi(e){return $c.get(e)||1}function Mc(e){if(e!==gr)throw new Error("invalid wNAF")}var xr=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>gr;)r&He&&(n=n.add(o)),o=o.double(),r>>=He;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Gi(r,this.bits),i=[],s=t,c=s;for(let a=0;a<n;a++){c=s,i.push(c);for(let u=1;u<o;u++)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=Gi(t,this.bits);for(let c=0;c<s.windows;c++){let{nextN:a,offset:u,isZero:f,isNeg:l,isNegF:g,offsetF:E}=Kc(n,c,s);n=a,f?i=i.add(Jr(g,r[E])):o=o.add(Jr(l,r[u]))}return Mc(n),{p:o,f:i}}wNAFUnsafe(t,r,n,o=this.ZERO){let i=Gi(t,this.bits);for(let s=0;s<i.windows&&n!==gr;s++){let{nextN:c,offset:a,isZero:u,isNeg:f}=Kc(n,s,i);if(n=c,!u){let l=r[a];o=o.add(f?l.negate():l)}}return Mc(n),o}getPrecomputes(t,r,n){let o=Zi.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Zi.set(r,o))),o}cached(t,r,n){let o=Wi(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let i=Wi(t);return i===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,t,n),r,o)}createCache(t,r){Fc(r,this.bits),$c.set(t,r),Zi.delete(t)}hasCache(t){return Wi(t)!==1}};function qc(e,t,r,n){let o=t,i=e.ZERO,s=e.ZERO;for(;r>gr||n>gr;)r&He&&(i=i.add(o)),n&He&&(s=s.add(o)),o=o.double(),r>>=He,n>>=He;return{p1:i,p2:s}}function Vc(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return zi(t),t}else return yr(e,{isLE:r})}function Hn(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 u=t[a];if(!(typeof u=="bigint"&&u>gr))throw new Error(`CURVE.${a} must be positive bigint`)}let o=Vc(t.p,r.Fp,n),i=Vc(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 jn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var Be=BigInt(0),ft=BigInt(1),Yi=BigInt(2),$h=BigInt(8);function qh(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 zc(e,t={}){let r=Hn("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s}=i;_e(t,{},{uvRatio:"function"});let c=Yi<<BigInt(o.BYTES*8)-ft,a=C=>n.create(C),u=t.uvRatio||((C,w)=>{try{return{isValid:!0,value:n.sqrt(n.div(C,w))}}catch{return{isValid:!1,value:Be}}});if(!qh(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function f(C,w,_=!1){let v=_?ft:Be;return Wr("coordinate "+C,w,v,c),w}function l(C){if(!(C instanceof b))throw new Error("EdwardsPoint expected")}let g=mr((C,w)=>{let{X:_,Y:v,Z:R}=C,K=C.is0();w==null&&(w=K?$h:n.inv(R));let V=a(_*w),q=a(v*w),h=n.mul(R,w);if(K)return{x:Be,y:ft};if(h!==ft)throw new Error("invZ was invalid");return{x:V,y:q}}),E=mr(C=>{let{a:w,d:_}=i;if(C.is0())throw new Error("bad point: ZERO");let{X:v,Y:R,Z:K,T:V}=C,q=a(v*v),h=a(R*R),p=a(K*K),B=a(p*p),D=a(q*w),I=a(p*a(D+h)),m=a(B+a(_*a(q*h)));if(I!==m)throw new Error("bad point: equation left != right (1)");let y=a(v*R),d=a(K*V);if(y!==d)throw new Error("bad point: equation left != right (2)");return!0});class b{static BASE=new b(i.Gx,i.Gy,ft,a(i.Gx*i.Gy));static ZERO=new b(Be,ft,ft,Be);static Fp=n;static Fn=o;X;Y;Z;T;constructor(w,_,v,R){this.X=f("x",w),this.Y=f("y",_),this.Z=f("z",v,!0),this.T=f("t",R),Object.freeze(this)}static CURVE(){return i}static fromAffine(w){if(w instanceof b)throw new Error("extended point not allowed");let{x:_,y:v}=w||{};return f("x",_),f("y",v),new b(_,v,ft,a(_*v))}static fromBytes(w,_=!1){let v=n.BYTES,{a:R,d:K}=i;w=zn(H(w,v,"point")),pe(_,"zip215");let V=zn(w),q=w[v-1];V[v-1]=q&-129;let h=qe(V),p=_?c:n.ORDER;Wr("point.y",h,Be,p);let B=a(h*h),D=a(B-ft),I=a(K*B-R),{isValid:m,value:y}=u(D,I);if(!m)throw new Error("bad point: invalid y coordinate");let d=(y&ft)===ft,S=(q&128)!==0;if(!_&&y===Be&&S)throw new Error("bad point: x=0 and x_0=1");return S!==d&&(y=a(-y)),b.fromAffine({x:y,y:h})}static fromHex(w,_=!1){return b.fromBytes(de(w),_)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(w=8,_=!0){return T.createCache(this,w),_||this.multiply(Yi),this}assertValidity(){E(this)}equals(w){l(w);let{X:_,Y:v,Z:R}=this,{X:K,Y:V,Z:q}=w,h=a(_*q),p=a(K*R),B=a(v*q),D=a(V*R);return h===p&&B===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:_,Y:v,Z:R}=this,K=a(_*_),V=a(v*v),q=a(Yi*a(R*R)),h=a(w*K),p=_+v,B=a(a(p*p)-K-V),D=h+V,I=D-q,m=h-V,y=a(B*I),d=a(D*m),S=a(B*m),P=a(I*D);return new b(y,d,P,S)}add(w){l(w);let{a:_,d:v}=i,{X:R,Y:K,Z:V,T:q}=this,{X:h,Y:p,Z:B,T:D}=w,I=a(R*h),m=a(K*p),y=a(q*v*D),d=a(V*B),S=a((R+K)*(h+p)-I-m),P=d-y,O=d+y,U=a(m-_*I),L=a(S*P),M=a(O*U),z=a(S*U),et=a(P*O);return new b(L,M,et,z)}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:_,f:v}=T.cached(this,w,R=>je(b,R));return je(b,[_,v])[0]}multiplyUnsafe(w,_=b.ZERO){if(!o.isValid(w))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return w===Be?b.ZERO:this.is0()||w===ft?this:T.unsafe(this,w,v=>je(b,v),_)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return T.unsafe(this,i.n).is0()}toAffine(w){return g(this,w)}clearCofactor(){return s===ft?this:this.multiplyUnsafe(s)}toBytes(){let{x:w,y:_}=this.toAffine(),v=n.toBytes(_);return v[v.length-1]|=w&ft?128:0,v}toHex(){return le(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let T=new xr(b,o.BITS);return b.BASE.precompute(8),b}function Hc(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');_e(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||dr,a=r.adjustScalarBytes||(h=>h),u=r.domain||((h,p,B)=>{if(pe(B,"phflag"),p.length||B)throw new Error("Contexts/pre-hash are not supported");return h});function f(h){return s.create(qe(h))}function l(h){let p=v.secretKey;H(h,v.secretKey,"secretKey");let B=H(t(h),2*p,"hashedSecretKey"),D=a(B.slice(0,p)),I=B.slice(p,2*p),m=f(D);return{head:D,prefix:I,scalar:m}}function g(h){let{head:p,prefix:B,scalar:D}=l(h),I=o.multiply(D),m=I.toBytes();return{head:p,prefix:B,scalar:D,point:I,pointBytes:m}}function E(h){return g(h).pointBytes}function b(h=Uint8Array.of(),...p){let B=Rt(...p);return f(t(u(B,H(h,void 0,"context"),!!n)))}function T(h,p,B={}){h=H(h,void 0,"message"),n&&(h=n(h));let{prefix:D,scalar:I,pointBytes:m}=g(p),y=b(B.context,D,h),d=o.multiply(y).toBytes(),S=b(B.context,d,m,h),P=s.create(y+S*I);if(!s.isValid(P))throw new Error("sign failed: invalid s");let O=Rt(d,s.toBytes(P));return H(O,v.signature,"result")}let C={zip215:!0};function w(h,p,B,D=C){let{context:I,zip215:m}=D,y=v.signature;h=H(h,y,"signature"),p=H(p,void 0,"message"),B=H(B,v.publicKey,"publicKey"),m!==void 0&&pe(m,"zip215"),n&&(p=n(p));let d=y/2,S=h.subarray(0,d),P=qe(h.subarray(d,y)),O,U,L;try{O=e.fromBytes(B,m),U=e.fromBytes(S,m),L=o.multiplyUnsafe(P)}catch{return!1}if(!m&&O.isSmallOrder())return!1;let M=b(I,U.toBytes(),O.toBytes(),p);return U.add(O.multiplyUnsafe(M)).subtract(L).clearCofactor().is0()}let _=i.BYTES,v={secretKey:_,publicKey:_,signature:2*_,seed:_};function R(h=c(v.seed)){return H(h,v.seed,"seed")}function K(h){return Ve(h)&&h.length===s.BYTES}function V(h,p){try{return!!e.fromBytes(h,p)}catch{return!1}}let q={getExtendedPublicKey:g,randomSecretKey:R,isValidSecretKey:K,isValidPublicKey:V,toMontgomery(h){let{y:p}=e.fromBytes(h),B=v.publicKey,D=B===32;if(!D&&B!==57)throw new Error("only defined for 25519 and 448");let I=D?i.div(ft+p,ft-p):i.div(p-ft,p+ft);return i.toBytes(I)},toMontgomerySecret(h){let p=v.secretKey;H(h,p);let B=t(h.subarray(0,p));return a(B).subarray(0,p)}};return Object.freeze({keygen:jn(R,E),getPublicKey:E,sign:T,verify:w,utils:q,Point:e,lengths:v})}var zh=BigInt(1),jc=BigInt(2);var Hh=BigInt(5),jh=BigInt(8),Xi=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Gh={p:Xi,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:jh,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Zh(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=Xi,c=e*e%i*e%i,a=Q(c,jc,i)*c%i,u=Q(a,zh,i)*e%i,f=Q(u,Hh,i)*u%i,l=Q(f,t,i)*f%i,g=Q(l,r,i)*l%i,E=Q(g,n,i)*g%i,b=Q(E,o,i)*E%i,T=Q(b,o,i)*E%i,C=Q(T,t,i)*f%i;return{pow_p_5_8:Q(C,jc,i)*e%i,b2:c}}function Wh(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Gc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Yh(e,t){let r=Xi,n=it(t*t*t,r),o=it(n*n*t,r),i=Zh(e*o).pow_p_5_8,s=it(e*n*i,r),c=it(t*s*s,r),a=s,u=it(s*Gc,r),f=c===e,l=c===it(-e,r),g=c===it(-e*Gc,r);return f&&(s=a),(l||g)&&(s=u),Lc(s,r)&&(s=it(-s,r)),{isValid:f||l,value:s}}var Xh=zc(Gh,{uvRatio:Yh});function Jh(e){return Hc(Xh,vc,Object.assign({adjustScalarBytes:Wh},e))}var Zc=Jh({});var Qr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Gn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Wc={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Gn("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 Ft=Wc;var Zn=32;var Ji,Qh=(async()=>{try{return await Ft.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function tp(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Ft.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Ft.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 ep(e,t,r){return Zc.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Yc(e,t,r){return Ji==null&&(Ji=await Qh),Ji?tp(e,t,r):ep(e,t,r)}function Wn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Yn=class{type="Ed25519";raw;constructor(t){this.raw=Qi(t,Zn)}toMultihash(){return mt.digest(fr(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:Y(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Yc(this.raw,r,t);return Wn(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}};function ts(e){return e=Qi(e,Zn),new Yn(e)}function Qi(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new ct(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var np=Math.pow(2,7),op=Math.pow(2,14),ip=Math.pow(2,21),es=Math.pow(2,28),rs=Math.pow(2,35),ns=Math.pow(2,42),os=Math.pow(2,49),tt=128,vt=127;function At(e){if(e<np)return 1;if(e<op)return 2;if(e<ip)return 3;if(e<es)return 4;if(e<rs)return 5;if(e<ns)return 6;if(e<os)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function De(e,t,r=0){switch(At(e)){case 8:t[r++]=e&255|tt,e/=128;case 7:t[r++]=e&255|tt,e/=128;case 6:t[r++]=e&255|tt,e/=128;case 5:t[r++]=e&255|tt,e/=128;case 4:t[r++]=e&255|tt,e>>>=7;case 3:t[r++]=e&255|tt,e>>>=7;case 2:t[r++]=e&255|tt,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function is(e,t){let r=e[t],n=0;if(n+=r&vt,r<tt||(r=e[t+1],n+=(r&vt)<<7,r<tt)||(r=e[t+2],n+=(r&vt)<<14,r<tt)||(r=e[t+3],n+=(r&vt)<<21,r<tt)||(r=e[t+4],n+=(r&vt)*es,r<tt)||(r=e[t+5],n+=(r&vt)*rs,r<tt)||(r=e[t+6],n+=(r&vt)*ns,r<tt)||(r=e[t+7],n+=(r&vt)*os,r<tt))return n;throw new RangeError("Could not decode varint")}function sp(e,t){let r=e.get(t),n=0;if(n+=r&vt,r<tt||(r=e.get(t+1),n+=(r&vt)<<7,r<tt)||(r=e.get(t+2),n+=(r&vt)<<14,r<tt)||(r=e.get(t+3),n+=(r&vt)<<21,r<tt)||(r=e.get(t+4),n+=(r&vt)*es,r<tt)||(r=e.get(t+5),n+=(r&vt)*rs,r<tt)||(r=e.get(t+6),n+=(r&vt)*ns,r<tt)||(r=e.get(t+7),n+=(r&vt)*os,r<tt))return n;throw new RangeError("Could not decode varint")}function br(e,t=0){return e instanceof Uint8Array?is(e,t):sp(e,t)}var ss=new Float32Array([-0]),Pe=new Uint8Array(ss.buffer);function Qc(e,t,r){ss[0]=e,t[r]=Pe[0],t[r+1]=Pe[1],t[r+2]=Pe[2],t[r+3]=Pe[3]}function tu(e,t){return Pe[0]=e[t],Pe[1]=e[t+1],Pe[2]=e[t+2],Pe[3]=e[t+3],ss[0]}var as=new Float64Array([-0]),It=new Uint8Array(as.buffer);function eu(e,t,r){as[0]=e,t[r]=It[0],t[r+1]=It[1],t[r+2]=It[2],t[r+3]=It[3],t[r+4]=It[4],t[r+5]=It[5],t[r+6]=It[6],t[r+7]=It[7]}function ru(e,t){return It[0]=e[t],It[1]=e[t+1],It[2]=e[t+2],It[3]=e[t+3],It[4]=e[t+4],It[5]=e[t+5],It[6]=e[t+6],It[7]=e[t+7],as[0]}var ap=BigInt(Number.MAX_SAFE_INTEGER),cp=BigInt(Number.MIN_SAFE_INTEGER),Ut=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 Ge;if(t<ap&&t>cp)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>nu&&(o=0n,++n>nu&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ge;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):Ge}},Ge=new Ut(0,0);Ge.toBigInt=function(){return 0n};Ge.zzEncode=Ge.zzDecode=function(){return this};Ge.length=function(){return 1};var nu=4294967296n;function ou(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 iu(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 cs(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 Ht(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Xn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var us=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,Ht(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 Ht(this,4);return Xn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ht(this,4);return Xn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ht(this,4);let t=tu(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ht(this,4);let t=ru(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 Ht(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return iu(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ht(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ht(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 Ut(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 Ht(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 Ht(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 Ht(this,8);let t=Xn(this.buf,this.pos+=4),r=Xn(this.buf,this.pos+=4);return new Ut(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=is(this.buf,this.pos);return this.pos+=At(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 fs(e){return new us(e instanceof Uint8Array?e:e.subarray())}function wr(e,t,r){let n=fs(e);return t.decode(n,void 0,r)}function ls(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return Ot(s);o+s>t&&(n=Ot(t),o=0);let c=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),c}}var Ze=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function ds(){}var ps=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},up=ls();function fp(e){return globalThis.Buffer!=null?Ot(e):up(e)}var en=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ze(ds,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Ze(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ms((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Jn,10,Ut.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Ut.fromBigInt(t);return this._push(Jn,r.length(),r)}uint64Number(t){return this._push(De,At(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=Ut.fromBigInt(t).zzEncode();return this._push(Jn,r.length(),r)}sint64Number(t){let r=Ut.fromNumber(t).zzEncode();return this._push(Jn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(hs,1,t?1:0)}fixed32(t){return this._push(tn,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Ut.fromBigInt(t);return this._push(tn,4,r.lo)._push(tn,4,r.hi)}fixed64Number(t){let r=Ut.fromNumber(t);return this._push(tn,4,r.lo)._push(tn,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(Qc,4,t)}double(t){return this._push(eu,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(hs,1,0):this.uint32(r)._push(dp,r,t)}string(t){let r=ou(t);return r!==0?this.uint32(r)._push(cs,r,t):this._push(hs,1,0)}fork(){return this.states=new ps(this),this.head=this.tail=new Ze(ds,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 Ze(ds,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=fp(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function hs(e,t,r){t[r]=e&255}function lp(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var ms=class extends Ze{next;constructor(t,r){super(lp,t,r),this.next=void 0}};function Jn(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 tn(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 dp(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(en.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(hp,t,e),this},en.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(pp,t,e),this});function hp(e,t,r){t.set(e,r)}function pp(e,t,r){e.length<40?cs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(F(e),r)}function ys(){return new en}function Er(e,t){let r=ys();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Sr;(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"})(Sr||(Sr={}));function Qn(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function rn(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 Qn("enum",Sr.VARINT,r,n)}function vr(e,t){return Qn("message",Sr.LENGTH_DELIMITED,e,t)}var st;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(st||(st={}));var gs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(gs||(gs={}));(function(e){e.codec=()=>rn(gs)})(st||(st={}));var ne;(function(e){let t;e.codec=()=>(t==null&&(t=vr((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=>Er(r,e.codec()),e.decode=(r,n)=>wr(r,e.codec(),n)})(ne||(ne={}));var xs;(function(e){let t;e.codec=()=>(t==null&&(t=vr((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=>Er(r,e.codec()),e.decode=(r,n)=>wr(r,e.codec(),n)})(xs||(xs={}));var on={};Bt(on,{MAX_RSA_KEY_SIZE:()=>bs,generateRSAKeyPair:()=>lu,jwkToJWKKeyPair:()=>du,jwkToPkcs1:()=>xp,jwkToPkix:()=>vs,jwkToRSAPrivateKey:()=>As,pkcs1MessageToJwk:()=>Es,pkcs1MessageToRSAPrivateKey:()=>Is,pkcs1ToJwk:()=>gp,pkcs1ToRSAPrivateKey:()=>fu,pkixMessageToJwk:()=>Ss,pkixMessageToRSAPublicKey:()=>Ts,pkixToJwk:()=>bp,pkixToRSAPublicKey:()=>Cs});var Ir=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=on.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:Y(this.raw,t.raw)}verify(t,r,n){return uu(this.jwk,r,t,n)}},nn=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=on.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Y(this.raw,t.raw)}sign(t,r){return cu(this.jwk,t,r)}};var bs=8192,ws=18,mp=1062,yp=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function gp(e){let t=ce(e);return Es(t)}function Es(e){return{n:k(e[1],"base64url"),e:k(e[2],"base64url"),d:k(e[3],"base64url"),p:k(e[4],"base64url"),q:k(e[5],"base64url"),dp:k(e[6],"base64url"),dq:k(e[7],"base64url"),qi:k(e[8],"base64url"),kty:"RSA"}}function xp(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 ct("JWK was missing components");return Ie([Pt(Uint8Array.from([0])),Pt(F(e.n,"base64url")),Pt(F(e.e,"base64url")),Pt(F(e.d,"base64url")),Pt(F(e.p,"base64url")),Pt(F(e.q,"base64url")),Pt(F(e.dp,"base64url")),Pt(F(e.dq,"base64url")),Pt(F(e.qi,"base64url"))]).subarray()}function bp(e){let t=ce(e,{offset:0});return Ss(t)}function Ss(e){let t=ce(e[1],{offset:0});return{kty:"RSA",n:k(t[0],"base64url"),e:k(t[1],"base64url")}}function vs(e){if(e.n==null||e.e==null)throw new ct("JWK was missing components");return Ie([yp,Kn(Ie([Pt(F(e.n,"base64url")),Pt(F(e.e,"base64url"))]))]).subarray()}function fu(e){let t=ce(e);return Is(t)}function Is(e){let t=Es(e);return As(t)}function Cs(e,t){if(e.byteLength>=mp)throw new er("Key size is too large");let r=ce(e,{offset:0});return Ts(r,e,t)}function Ts(e,t,r){let n=Ss(e);if(r==null){let o=hr(ne.encode({Type:st.RSA,Data:t}));r=te(ws,o)}return new Ir(n,r)}function As(e){if(pu(e)>bs)throw new ct("Key size is too large");let t=du(e),r=hr(ne.encode({Type:st.RSA,Data:vs(t.publicKey)})),n=te(ws,r);return new nn(t.privateKey,new Ir(t.publicKey,n))}async function lu(e){if(e>bs)throw new ct("Key size is too large");let t=await hu(e),r=hr(ne.encode({Type:st.RSA,Data:vs(t.publicKey)})),n=te(ws,r);return new nn(t.privateKey,new Ir(t.publicKey,n))}function du(e){if(e==null)throw new ct("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function hu(e,t){let r=await Ft.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 wp(r,t);return{privateKey:n[0],publicKey:n[1]}}async function cu(e,t,r){let n=await Ft.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Ft.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 uu(e,t,r,n){let o=await Ft.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Ft.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),i}async function wp(e,t){if(e.privateKey==null||e.publicKey==null)throw new ct("Private and public key are required");let r=await Promise.all([Ft.get().subtle.exportKey("jwk",e.privateKey),Ft.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function pu(e){if(e.kty!=="RSA")throw new ct("invalid key type");if(e.n==null)throw new ct("invalid key modulus");return F(e.n,"base64url").length*8}var to=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(Mn(t),H(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),fe(o)}update(t){return lr(this),this.iHash.update(t),this}digestInto(t){lr(this),H(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()}},_s=(e,t,r)=>new to(e,t).update(r).digest();_s.create=(e,t)=>new to(e,t);var mu=(e,t)=>(e+(e>=0?t:-t)/yu)/t;function Ep(e,t,r){let[[n,o],[i,s]]=t,c=mu(s*e,r),a=mu(-o*e,r),u=e-c*n-a*i,f=-c*o-a*s,l=u<me,g=f<me;l&&(u=-u),g&&(f=-f);let E=Yr(Math.ceil(Fi(r)/2))+Cr;if(u<me||u>=E||f<me||f>=E)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:u,k2neg:g,k2:f}}function Ds(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Bs(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return pe(r.lowS,"lowS"),pe(r.prehash,"prehash"),r.format!==void 0&&Ds(r.format),r}var Ps=class extends Error{constructor(t=""){super(t)}},Re={Err:Ps,_tlv:{encode:(e,t)=>{let{Err:r}=Re;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=Zr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?Zr(o.length/2|128):"";return Zr(e)+i+o+t},decode(e,t){let{Err:r}=Re,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 u=t.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)s=s<<8|f;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}=Re;if(e<me)throw new t("integer: negative integers are not allowed");let r=Zr(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}=Re;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 pr(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Re,o=H(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:u,l:f}=n.decode(2,a);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Re,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),i=n+o;return t.encode(48,i)}},me=BigInt(0),Cr=BigInt(1),yu=BigInt(2),eo=BigInt(3),Sp=BigInt(4);function gu(e,t={}){let r=Hn("weierstrass",e,t),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s,n:c}=i;_e(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 u=bu(n,o);function f(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(I,m,y){let{x:d,y:S}=m.toAffine(),P=n.toBytes(d);if(pe(y,"isCompressed"),y){f();let O=!n.isOdd(S);return Rt(xu(O),P)}else return Rt(Uint8Array.of(4),P,n.toBytes(S))}function g(I){H(I,void 0,"Point");let{publicKey:m,publicKeyUncompressed:y}=u,d=I.length,S=I[0],P=I.subarray(1);if(d===m&&(S===2||S===3)){let O=n.fromBytes(P);if(!n.isValid(O))throw new Error("bad point: is not on curve, wrong x");let U=T(O),L;try{L=n.sqrt(U)}catch(et){let J=et instanceof Error?": "+et.message:"";throw new Error("bad point: is not on curve, sqrt error"+J)}f();let M=n.isOdd(L);return(S&1)===1!==M&&(L=n.neg(L)),{x:O,y:L}}else if(d===y&&S===4){let O=n.BYTES,U=n.fromBytes(P.subarray(0,O)),L=n.fromBytes(P.subarray(O,O*2));if(!C(U,L))throw new Error("bad point: is not on curve");return{x:U,y:L}}else throw new Error(`bad point: got length ${d}, expected compressed=${m} or uncompressed=${y}`)}let E=t.toBytes||l,b=t.fromBytes||g;function T(I){let m=n.sqr(I),y=n.mul(m,I);return n.add(n.add(y,n.mul(I,i.a)),i.b)}function C(I,m){let y=n.sqr(m),d=T(I);return n.eql(y,d)}if(!C(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let w=n.mul(n.pow(i.a,eo),Sp),_=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(w,_)))throw new Error("bad curve params: a or b");function v(I,m,y=!1){if(!n.isValid(m)||y&&n.is0(m))throw new Error(`bad point coordinate ${I}`);return m}function R(I){if(!(I instanceof p))throw new Error("Weierstrass Point expected")}function K(I){if(!a||!a.basises)throw new Error("no endo");return Ep(I,a.basises,o.ORDER)}let V=mr((I,m)=>{let{X:y,Y:d,Z:S}=I;if(n.eql(S,n.ONE))return{x:y,y:d};let P=I.is0();m==null&&(m=P?n.ONE:n.inv(S));let O=n.mul(y,m),U=n.mul(d,m),L=n.mul(S,m);if(P)return{x:n.ZERO,y:n.ZERO};if(!n.eql(L,n.ONE))throw new Error("invZ was invalid");return{x:O,y:U}}),q=mr(I=>{if(I.is0()){if(t.allowInfinityPoint&&!n.is0(I.Y))return;throw new Error("bad point: ZERO")}let{x:m,y}=I.toAffine();if(!n.isValid(m)||!n.isValid(y))throw new Error("bad point: x or y not field elements");if(!C(m,y))throw new Error("bad point: equation left != right");if(!I.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function h(I,m,y,d,S){return y=new p(n.mul(y.X,I),y.Y,y.Z),m=Jr(d,m),y=Jr(S,y),m.add(y)}class p{static BASE=new p(i.Gx,i.Gy,n.ONE);static ZERO=new p(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,y,d){this.X=v("x",m),this.Y=v("y",y,!0),this.Z=v("z",d),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){let{x:y,y:d}=m||{};if(!m||!n.isValid(y)||!n.isValid(d))throw new Error("invalid affine point");if(m instanceof p)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(d)?p.ZERO:new p(y,d,n.ONE)}static fromBytes(m){let y=p.fromAffine(b(H(m,void 0,"point")));return y.assertValidity(),y}static fromHex(m){return p.fromBytes(de(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,y=!0){return D.createCache(this,m),y||this.multiply(eo),this}assertValidity(){q(this)}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){R(m);let{X:y,Y:d,Z:S}=this,{X:P,Y:O,Z:U}=m,L=n.eql(n.mul(y,U),n.mul(P,S)),M=n.eql(n.mul(d,U),n.mul(O,S));return L&&M}negate(){return new p(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:y}=i,d=n.mul(y,eo),{X:S,Y:P,Z:O}=this,U=n.ZERO,L=n.ZERO,M=n.ZERO,z=n.mul(S,S),et=n.mul(P,P),J=n.mul(O,O),G=n.mul(S,P);return G=n.add(G,G),M=n.mul(S,O),M=n.add(M,M),U=n.mul(m,M),L=n.mul(d,J),L=n.add(U,L),U=n.sub(et,L),L=n.add(et,L),L=n.mul(U,L),U=n.mul(G,U),M=n.mul(d,M),J=n.mul(m,J),G=n.sub(z,J),G=n.mul(m,G),G=n.add(G,M),M=n.add(z,z),z=n.add(M,z),z=n.add(z,J),z=n.mul(z,G),L=n.add(L,z),J=n.mul(P,O),J=n.add(J,J),z=n.mul(J,G),U=n.sub(U,z),M=n.mul(J,et),M=n.add(M,M),M=n.add(M,M),new p(U,L,M)}add(m){R(m);let{X:y,Y:d,Z:S}=this,{X:P,Y:O,Z:U}=m,L=n.ZERO,M=n.ZERO,z=n.ZERO,et=i.a,J=n.mul(i.b,eo),G=n.mul(y,P),rt=n.mul(d,O),pt=n.mul(S,U),Jt=n.add(y,d),nt=n.add(P,O);Jt=n.mul(Jt,nt),nt=n.add(G,rt),Jt=n.sub(Jt,nt),nt=n.add(y,S);let St=n.add(P,U);return nt=n.mul(nt,St),St=n.add(G,pt),nt=n.sub(nt,St),St=n.add(d,S),L=n.add(O,U),St=n.mul(St,L),L=n.add(rt,pt),St=n.sub(St,L),z=n.mul(et,nt),L=n.mul(J,pt),z=n.add(L,z),L=n.sub(rt,z),z=n.add(rt,z),M=n.mul(L,z),rt=n.add(G,G),rt=n.add(rt,G),pt=n.mul(et,pt),nt=n.mul(J,nt),rt=n.add(rt,pt),pt=n.sub(G,pt),pt=n.mul(et,pt),nt=n.add(nt,pt),G=n.mul(rt,nt),M=n.add(M,G),G=n.mul(St,nt),L=n.mul(Jt,L),L=n.sub(L,G),G=n.mul(Jt,rt),z=n.mul(St,z),z=n.add(z,G),new p(L,M,z)}subtract(m){return this.add(m.negate())}is0(){return this.equals(p.ZERO)}multiply(m){let{endo:y}=t;if(!o.isValidNot0(m))throw new Error("invalid scalar: out of range");let d,S,P=O=>D.cached(this,O,U=>je(p,U));if(y){let{k1neg:O,k1:U,k2neg:L,k2:M}=K(m),{p:z,f:et}=P(U),{p:J,f:G}=P(M);S=et.add(G),d=h(y.beta,z,J,O,L)}else{let{p:O,f:U}=P(m);d=O,S=U}return je(p,[d,S])[0]}multiplyUnsafe(m){let{endo:y}=t,d=this;if(!o.isValid(m))throw new Error("invalid scalar: out of range");if(m===me||d.is0())return p.ZERO;if(m===Cr)return d;if(D.hasCache(this))return this.multiply(m);if(y){let{k1neg:S,k1:P,k2neg:O,k2:U}=K(m),{p1:L,p2:M}=qc(p,d,P,U);return h(y.beta,L,M,S,O)}else return D.unsafe(d,m)}toAffine(m){return V(this,m)}isTorsionFree(){let{isTorsionFree:m}=t;return s===Cr?!0:m?m(p,this):D.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:m}=t;return s===Cr?this:m?m(p,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(m=!0){return pe(m,"isCompressed"),this.assertValidity(),E(p,this,m)}toHex(m=!0){return le(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let B=o.BITS,D=new xr(p,t.endo?Math.ceil(B/2):B);return p.BASE.precompute(8),p}function xu(e){return Uint8Array.of(e?2:3)}function bu(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function vp(e,t={}){let{Fn:r}=e,n=t.randomBytes||dr,o=Object.assign(bu(e.Fp,r),{seed:Hi(r.ORDER)});function i(E){try{let b=r.fromBytes(E);return r.isValidNot0(b)}catch{return!1}}function s(E,b){let{publicKey:T,publicKeyUncompressed:C}=o;try{let w=E.length;return b===!0&&w!==T||b===!1&&w!==C?!1:!!e.fromBytes(E)}catch{return!1}}function c(E=n(o.seed)){return ji(H(E,o.seed,"seed"),r.ORDER)}function a(E,b=!0){return e.BASE.multiply(r.fromBytes(E)).toBytes(b)}function u(E){let{secretKey:b,publicKey:T,publicKeyUncompressed:C}=o;if(!Ve(E)||"_lengths"in r&&r._lengths||b===T)return;let w=H(E,void 0,"key").length;return w===T||w===C}function f(E,b,T=!0){if(u(E)===!0)throw new Error("first arg must be private key");if(u(b)===!1)throw new Error("second arg must be public key");let C=r.fromBytes(E);return e.fromBytes(b).multiply(C).toBytes(T)}let l={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:c},g=jn(c,a);return Object.freeze({getPublicKey:a,getSharedSecret:f,keygen:g,Point:e,utils:l,lengths:o})}function wu(e,t,r={}){Mn(t),_e(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||dr,o=r.hmac||((y,d)=>_s(t,y,d)),{Fp:i,Fn:s}=e,{ORDER:c,BITS:a}=s,{keygen:u,getPublicKey:f,getSharedSecret:l,utils:g,lengths:E}=vp(e,r),b={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},T=c*yu<i.ORDER;function C(y){let d=c>>Cr;return y>d}function w(y,d){if(!s.isValidNot0(d))throw new Error(`invalid signature ${y}: out of range 1..Point.Fn.ORDER`);return d}function _(){if(T)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function v(y,d){Ds(d);let S=E.signature,P=d==="compact"?S:d==="recovered"?S+1:void 0;return H(y,P)}class R{r;s;recovery;constructor(d,S,P){if(this.r=w("r",d),this.s=w("s",S),P!=null){if(_(),![0,1,2,3].includes(P))throw new Error("invalid recovery id");this.recovery=P}Object.freeze(this)}static fromBytes(d,S=b.format){v(d,S);let P;if(S==="der"){let{r:M,s:z}=Re.toSig(H(d));return new R(M,z)}S==="recovered"&&(P=d[0],S="compact",d=d.subarray(1));let O=E.signature/2,U=d.subarray(0,O),L=d.subarray(O,O*2);return new R(s.fromBytes(U),s.fromBytes(L),P)}static fromHex(d,S){return this.fromBytes(de(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 R(this.r,this.s,d)}recoverPublicKey(d){let{r:S,s:P}=this,O=this.assertRecovery(),U=O===2||O===3?S+c:S;if(!i.isValid(U))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let L=i.toBytes(U),M=e.fromBytes(Rt(xu((O&1)===0),L)),z=s.inv(U),et=V(H(d,void 0,"msgHash")),J=s.create(-et*z),G=s.create(P*z),rt=e.BASE.multiplyUnsafe(J).add(M.multiplyUnsafe(G));if(rt.is0())throw new Error("invalid recovery: point at infinify");return rt.assertValidity(),rt}hasHighS(){return C(this.s)}toBytes(d=b.format){if(Ds(d),d==="der")return de(Re.hexFromSig(this));let{r:S,s:P}=this,O=s.toBytes(S),U=s.toBytes(P);return d==="recovered"?(_(),Rt(Uint8Array.of(this.assertRecovery()),O,U)):Rt(O,U)}toHex(d){return le(this.toBytes(d))}}let K=r.bits2int||function(d){if(d.length>8192)throw new Error("input is too large");let S=pr(d),P=d.length*8-a;return P>0?S>>BigInt(P):S},V=r.bits2int_modN||function(d){return s.create(K(d))},q=Yr(a);function h(y){return Wr("num < 2^"+a,y,me,q),s.toBytes(y)}function p(y,d){return H(y,void 0,"message"),d?H(t(y),void 0,"prehashed message"):y}function B(y,d,S){let{lowS:P,prehash:O,extraEntropy:U}=Bs(S,b);y=p(y,O);let L=V(y),M=s.fromBytes(d);if(!s.isValidNot0(M))throw new Error("invalid private key");let z=[h(M),h(L)];if(U!=null&&U!==!1){let rt=U===!0?n(E.secretKey):U;z.push(H(rt,void 0,"extraEntropy"))}let et=Rt(...z),J=L;function G(rt){let pt=K(rt);if(!s.isValidNot0(pt))return;let Jt=s.inv(pt),nt=e.BASE.multiply(pt).toAffine(),St=s.create(nt.x);if(St===me)return;let An=s.create(Jt*s.create(J+St*M));if(An===me)return;let _a=(nt.x===St?0:2)|Number(nt.y&Cr),Ba=An;return P&&C(An)&&(Ba=s.neg(An),_a^=1),new R(St,Ba,T?void 0:_a)}return{seed:et,k2sig:G}}function D(y,d,S={}){let{seed:P,k2sig:O}=B(y,d,S);return Tc(t.outputLen,s.BYTES,o)(P,O).toBytes(S.format)}function I(y,d,S,P={}){let{lowS:O,prehash:U,format:L}=Bs(P,b);if(S=H(S,void 0,"publicKey"),d=p(d,U),!Ve(y)){let M=y instanceof R?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+M)}v(y,L);try{let M=R.fromBytes(y,L),z=e.fromBytes(S);if(O&&M.hasHighS())return!1;let{r:et,s:J}=M,G=V(d),rt=s.inv(J),pt=s.create(G*rt),Jt=s.create(et*rt),nt=e.BASE.multiplyUnsafe(pt).add(z.multiplyUnsafe(Jt));return nt.is0()?!1:s.create(nt.x)===et}catch{return!1}}function m(y,d,S={}){let{prehash:P}=Bs(S,b);return d=p(d,P),R.fromBytes(y,"recovered").recoverPublicKey(d).toBytes()}return Object.freeze({keygen:u,getPublicKey:f,getSharedSecret:l,utils:g,lengths:E,Point:e,sign:D,verify:I,recoverPublicKey:m,Signature:R,hash:t})}var Os={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Ip={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Eu=BigInt(2);function Cp(e){let t=Os.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=Q(f,r,t)*f%t,g=Q(l,r,t)*f%t,E=Q(g,Eu,t)*u%t,b=Q(E,o,t)*E%t,T=Q(b,i,t)*b%t,C=Q(T,c,t)*T%t,w=Q(C,a,t)*C%t,_=Q(w,c,t)*T%t,v=Q(_,r,t)*f%t,R=Q(v,s,t)*b%t,K=Q(R,n,t)*u%t,V=Q(K,Eu,t);if(!Rs.eql(Rs.sqr(V),e))throw new Error("Cannot find square root");return V}var Rs=yr(Os.p,{sqrt:Cp}),Tp=gu(Os,{Fp:Rs,endo:Ip}),Tr=wu(Tp,hr);function Su(e,t,r,n){let o=Ke.digest(r instanceof Uint8Array?r:r.subarray());if(Wn(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Tr.verify(t,i,e,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new Qr(String(i))});try{return n?.signal?.throwIfAborted(),Tr.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(i){throw new Qr(String(i))}}var ro=class{type="secp256k1";raw;_key;constructor(t){this._key=Iu(t),this.raw=vu(this._key)}toMultihash(){return mt.digest(fr(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:Y(this.raw,t.raw)}verify(t,r,n){return Su(this._key,r,t,n)}};function Ns(e){return new ro(e)}function vu(e){return Tr.Point.fromBytes(e).toBytes()}function Iu(e){try{return Tr.Point.fromBytes(e),e}catch(t){throw new er(String(t))}}function Cu(e,t){let{Type:r,Data:n}=ne.decode(e),o=n??new Uint8Array;switch(r){case st.RSA:return Cs(o,t);case st.Ed25519:return ts(o);case st.secp256k1:return Ns(o);case st.ECDSA:return Bi(o);default:throw new nr}}function Ar(e){let{Type:t,Data:r}=ne.decode(e.digest),n=r??new Uint8Array;switch(t){case st.Ed25519:return ts(n);case st.secp256k1:return Ns(n);case st.ECDSA:return Bi(n);default:throw new nr}}function fr(e){return ne.encode({Type:st[e.type],Data:e.raw})}var Tu=Symbol.for("nodejs.util.inspect.custom"),Ap=114,sn=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()})`}[Qo]=!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(Ap,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return Y(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return Y(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Tu](){return`PeerId(${this.toString()})`}},no=class extends sn{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},oo=class extends sn{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},io=class extends sn{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},_p=2336,an=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=mt.digest(F(this.url))}[Tu](){return`PeerId(${this.url})`}[Qo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return j.createV1(_p,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=k(t)),t.toString()===this.toString())}};var Bp=114,Au=2336;function _u(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=Se(W.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return Dp(j.parse(e));if(t==null)throw new Bn('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=Se(t.decode(e))}return Bu(r)}function Bu(e){if(Rp(e))return new no({multihash:e});if(Pp(e))try{let t=Ar(e);if(t.type==="Ed25519")return new oo({multihash:e,publicKey:t});if(t.type==="secp256k1")return new io({multihash:e,publicKey:t})}catch{let r=k(e.digest);return new an(new URL(r))}throw new Pn("Supplied PeerID Multihash is invalid")}function Dp(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Bp&&e.code!==Au)throw new Dn("Supplied PeerID CID is invalid");if(e.code===Au){let t=k(e.multihash.digest);return new an(new URL(t))}return Bu(e.multihash)}function Pp(e){return e.code===mt.code}function Rp(e){return e.code===Ke.code}var xt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},ye=class extends Error{static name="ValidationError";name="ValidationError"},cn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},so=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var ao=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",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let g=Number.parseInt(l,t);if(!Number.isNaN(g))return g});if(f===void 0)break;if(i*=t,i+=f,i>u||(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 Op=45,Np=15,co=new ao;function Us(e){if(!(e.length>Np))return co.new(e).parseWith(()=>co.readIPv4Addr())}function Ls(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Op))return co.new(e).parseWith(()=>co.readIPv6Addr())}function Oe(e){return!!Us(e)}function uo(e){return!!Ls(e)}function Ks(e){return t=>k(t,e)}function Ms(e){return t=>F(t,e)}function _r(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function We(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function Pu(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=F(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=We(n);return yt([r,o],r.length+o.length)}function Ru(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=Dt.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=We(n);return yt([r,o],r.length+o.length)}function Vs(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=k(t,"base32"),o=_r(r);return`${n}:${o}`}var Fs=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 xt("Invalid byte value in IP address");t[n]=o}),t},Ou=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let i=Oe(r[n]),s;i&&(s=Fs(r[n]),r[n]=k(s.subarray(0,2),"base16")),s!=null&&++n<8&&r.splice(n,0,k(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 xt("Invalid byte value in IP address");o[t++]=i>>8&255,o[t++]=i&255}return o},Nu=function(e){if(e.byteLength!==4)throw new xt("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Uu=function(e){if(e.byteLength!==16)throw new xt("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 xt(`Invalid IPv6 address "${r}"`)}};function Lu(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new xt(`Invalid IPv6 address "${e}"`)}}var ks=Object.values(Me).map(e=>e.decoder),Up=(function(){let e=ks[0].or(ks[1]);return ks.slice(2).forEach(t=>e=e.or(t)),e})();function ku(e){return Up.decode(e)}function Ku(e){return t=>e.encoder.encode(t)}function Lp(e){if(parseInt(e).toString()!==e)throw new ye("Value must be an integer")}function kp(e){if(e<0)throw new ye("Value must be a positive integer, or zero")}function Kp(e){return t=>{if(t>e)throw new ye(`Value must be smaller than or equal to ${e}`)}}function Mp(...e){return t=>{for(let r of e)r(t)}}var un=Mp(Lp,kp,Kp(65535));var lt=-1,$s=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 so(`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)}))}},Lt=new $s,mm=[{code:4,name:"ip4",size:32,valueToBytes:Fs,bytesToValue:Nu,validate:e=>{if(!Oe(e))throw new ye(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:We,bytesToValue:_r,validate:un},{code:273,name:"udp",size:16,valueToBytes:We,bytesToValue:_r,validate:un},{code:33,name:"dccp",size:16,valueToBytes:We,bytesToValue:_r,validate:un},{code:41,name:"ip6",size:128,valueToBytes:Ou,bytesToValue:Uu,stringToValue:Lu,validate:e=>{if(!uo(e))throw new ye(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:lt},{code:43,name:"ipcidr",size:8,bytesToValue:Ks("base10"),valueToBytes:Ms("base10")},{code:53,name:"dns",size:lt,resolvable:!0},{code:54,name:"dns4",size:lt,resolvable:!0},{code:55,name:"dns6",size:lt,resolvable:!0},{code:56,name:"dnsaddr",size:lt,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:We,bytesToValue:_r,validate:un},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:lt,path:!0,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:lt,bytesToValue:Ks("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Ms("base58btc")(e):j.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Vs,valueToBytes:Pu},{code:445,name:"onion3",size:296,bytesToValue:Vs,valueToBytes:Ru},{code:446,name:"garlic64",size:lt},{code:447,name:"garlic32",size:lt},{code:448,name:"tls"},{code:449,name:"sni",size:lt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:lt,bytesToValue:Ku(Mr),valueToBytes:ku},{code:480,name:"http"},{code:481,name:"http-path",size:lt,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:lt}];mm.forEach(e=>{Lt.addProtocol(e)});function Mu(e){let t=[],r=0;for(;r<e.length;){let n=br(e,r),o=Lt.getProtocol(n),i=At(n),s=ym(o,e,r+i),c=0;s>0&&o.size===lt&&(c=At(s));let a=i+c+s,u={code:n,name:o.name,bytes:e.subarray(r,r+a)};if(s>0){let f=r+i+c,l=e.subarray(f,f+s);u.value=o.bytesToValue?.(l)??k(l)}t.push(u),r+=a}return t}function Vu(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=Lt.getProtocol(n.code),i=At(n.code),s,c=0,a=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??F(n.value),c=s.byteLength,o.size===lt&&(a=At(c)));let u=new Uint8Array(i+a+c),f=0;De(n.code,u,f),f+=i,s!=null&&(o.size===lt&&(De(c,u,f),f+=a),u.set(s,f)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return yt(r,t)}function Fu(e){if(e.charAt(0)!=="/")throw new xt('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=Lt.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 xt(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new xt(`Component ${o} was missing value`);u.value=a.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new xt("Incomplete multiaddr");return t}function $u(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=Lt.getProtocol(t.code);if(r==null)throw new xt(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function ym(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:br(t,r)}var gm=Symbol.for("nodejs.util.inspect.custom"),Ys=Symbol.for("@multiformats/multiaddr"),xm=[53,54,55,56],Ws=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}};function bm(e){if(e==null&&(e="/"),zu(e))return e.getComponents();if(e instanceof Uint8Array)return Mu(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Fu(e);if(Array.isArray(e))return e;throw new xt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var mo=class e{[Ys]=!0;#t;#r;#e;constructor(t="/",r={}){this.#t=bm(t),r.validate!==!1&&wm(this)}get bytes(){return this.#e==null&&(this.#e=Vu(this.#t)),this.#e}toString(){return this.#r==null&&(this.#r=$u(this.#t)),this.#r}toJSON(){return this.toString()}toOptions(){let t,r,n,o,i="";for(let{code:c,name:a,value:u}of this.#t)c===42&&(i=`%${u??""}`),xm.includes(c)&&(r="tcp",o=443,n=`${u??""}${i}`,t=c===55?6:4),(c===6||c===273)&&(r=a==="tcp"?"tcp":"udp",o=parseInt(u??"")),(c===4||c===41)&&(r="tcp",n=`${u??""}${i}`,t=c===41?6:4);if(t==null||r==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:r,port:o}}getComponents(){return[...this.#t]}protos(){return this.#t.map(({code:t,value:r})=>{let n=Lt.getProtocol(t);return{code:t,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#t.map(({code:t})=>t)}protoNames(){return this.#t.map(({name:t})=>t)}tuples(){return this.#t.map(({code:t,value:r})=>{if(r==null)return[t];let n=Lt.getProtocol(t),o=[t];return r!=null&&o.push(n.valueToBytes?.(r)??F(r)),o})}stringTuples(){return this.#t.map(({code:t,value:r})=>r==null?[t]:[t,r])}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 cn(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);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})}getPeerId(){try{let t=[];this.#t.forEach(({code:n,value:o})=>{n===421&&t.push([n,o]),n===290&&(t=[])});let r=t.pop();if(r?.[1]!=null){let n=r[1];return n[0]==="Q"||n[0]==="1"?k(W.decode(`z${n}`),"base58btc"):k(j.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let t of this.#t)if(Lt.getProtocol(t.code).path)return t.value??null;return null}equals(t){return Y(this.bytes,t.bytes)}async resolve(t){let r=this.protos().find(i=>i.resolvable);if(r==null)return[this];let n=qu.get(r.name);if(n==null)throw new Ws(`no available resolver for ${r.name}`);return(await n(this,t)).map(i=>ln(i))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(){return!(this.#t.length!==2||this.#t[0].code!==4&&this.#t[0].code!==41||this.#t[1].code!==6&&this.#t[1].code!==273)}[gm](){return`Multiaddr(${this.toString()})`}};function wm(e){e.getComponents().forEach(t=>{let r=Lt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}var D2=parseInt("0xFFFF",16),P2=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var qu=new Map;function zu(e){return!!e?.[Ys]}function ln(e){return new mo(e)}function dn(e){let t=new globalThis.AbortController;function r(){t.abort();for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}for(let i of e){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=t.signal;return o.clear=n,o}async function*yo(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()}}X.formatters.b=e=>e==null?"undefined":W.baseEncode(e);X.formatters.t=e=>e==null?"undefined":Dt.baseEncode(e);X.formatters.m=e=>e==null?"undefined":Kr.baseEncode(e);X.formatters.p=e=>e==null?"undefined":e.toString();X.formatters.c=e=>e==null?"undefined":e.toString();X.formatters.k=e=>e==null?"undefined":e.toString();X.formatters.a=e=>e==null?"undefined":e.toString();X.formatters.e=e=>e==null?"undefined":Gu(e.stack)??Gu(e.message)??e.toString();function Cm(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 Ye(e){let t=Cm(`${e}:trace`);return X.enabled(`${e}:trace`)&&X.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(t=X(`${e}:trace`)),Object.assign(X(e),{error:X(`${e}:error`),trace:t,newScope:r=>Ye(`${e}:${r}`)})}function Gu(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var i0=Jo(Js(),1);var jt=class extends Error{static name="SignatureVerificationError";constructor(t="Record signature verification failed"){super(t),this.name="SignatureVerificationError"}},go=class extends Error{static name="RecordExpiredError";constructor(t="Record has expired"){super(t),this.name="RecordExpiredError"}},Br=class extends Error{static name="UnsupportedValidityError";constructor(t="The validity type is unsupported"){super(t),this.name="UnsupportedValidityError"}},xo=class extends Error{static name="RecordTooLargeError";constructor(t="The record is too large"){super(t),this.name="RecordTooLargeError"}},bo=class extends Error{static name="InvalidValueError";constructor(t="Value must be a valid content path starting with /"){super(t),this.name="InvalidValueError"}},wo=class extends Error{static name="InvalidRecordDataError";constructor(t="Invalid record data"){super(t),this.name="InvalidRecordDataError"}},hn=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(t="Invalid embedded public key"){super(t),this.name="InvalidEmbeddedPublicKeyError"}};var Gt;(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=()=>rn(r)})(t=e.ValidityType||(e.ValidityType={}));let n;e.codec=()=>(n==null&&(n=vr((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 u=o.uint32();switch(u>>>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(u&7);break}}}return c})),n),e.encode=o=>Er(o,e.codec()),e.decode=(o,i)=>wr(o,e.codec(),i)})(Gt||(Gt={}));var Eo=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Tm=["string","number","bigint","symbol"],Am=["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 Zu(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(Tm.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(_m(e))return"Buffer";let r=Bm(e);return r||"Object"}function _m(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function Bm(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(Am.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 N=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 Dr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Dm=new TextDecoder,Pm=new TextEncoder;function So(e){return Dr&&globalThis.Buffer.isBuffer(e)}function Ju(e){return e instanceof Uint8Array?So(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Qu=Dr?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):Yu(e,t,r):(e,t,r)=>r-t>64?Dm.decode(e.subarray(t,r)):Yu(e,t,r),tf=Dr?e=>e.length>64?globalThis.Buffer.from(e):Wu(e):e=>e.length>64?Pm.encode(e):Wu(e);var Pr=Dr?(e,t,r)=>So(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),ef=Dr?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Ju(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},rf=Dr?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function nf(e,t){if(So(e)&&So(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 Wu(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 Yu(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,u,f;switch(s){case 1:o<128&&(i=o);break;case 2:c=e[t+1],(c&192)===128&&(f=(o&31)<<6|c&63,f>127&&(i=f));break;case 3:c=e[t+1],a=e[t+2],(c&192)===128&&(a&192)===128&&(f=(o&15)<<12|(c&63)<<6|a&63,f>2047&&(f<55296||f>57343)&&(i=f));break;case 4:c=e[t+1],a=e[t+2],u=e[t+3],(c&192)===128&&(a&192)===128&&(u&192)===128&&(f=(o&15)<<18|(c&63)<<12|(a&63)<<6|u&63,f>65535&&f<1114112&&(i=f))}}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 Rm(n)}var Xu=4096;function Rm(e){let t=e.length;if(t<=Xu)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Xu));return r}var Om=256,vo=class{constructor(t=Om){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=rf(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=Pr(n,0,this.cursor)}else r=ef(this.chunks,this.cursor);return t&&this.reset(),r}};var $="CBOR decode error:",Qs="CBOR encode error:",pn=[];pn[23]=1;pn[24]=2;pn[25]=3;pn[26]=5;pn[27]=9;function ge(e,t,r){if(e.length-t<r)throw new Error(`${$} not enough data for type`)}var dt=[24,256,65536,4294967296,BigInt("18446744073709551616")];function kt(e,t,r){ge(e,t,1);let n=e[t];if(r.strict===!0&&n<dt[0])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);return n}function Kt(e,t,r){ge(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<dt[1])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);return n}function Mt(e,t,r){ge(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<dt[2])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);return n}function Vt(e,t,r){ge(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<dt[3])throw new Error(`${$} 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(`${$} integers outside of the safe integer range are not supported`)}function of(e,t,r,n){return new N(x.uint,kt(e,t+1,n),2)}function sf(e,t,r,n){return new N(x.uint,Kt(e,t+1,n),3)}function af(e,t,r,n){return new N(x.uint,Mt(e,t+1,n),5)}function cf(e,t,r,n){return new N(x.uint,Vt(e,t+1,n),9)}function $t(e,t){return bt(e,0,t.value)}function bt(e,t,r){if(r<dt[0]){let n=Number(r);e.push([t|n])}else if(r<dt[1]){let n=Number(r);e.push([t|24,n])}else if(r<dt[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<dt[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<dt[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(`${$} encountered BigInt larger than allowable range`)}}$t.encodedSize=function(t){return bt.encodedSize(t.value)};bt.encodedSize=function(t){return t<dt[0]?1:t<dt[1]?2:t<dt[2]?3:t<dt[3]?5:9};$t.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function uf(e,t,r,n){return new N(x.negint,-1-kt(e,t+1,n),2)}function ff(e,t,r,n){return new N(x.negint,-1-Kt(e,t+1,n),3)}function lf(e,t,r,n){return new N(x.negint,-1-Mt(e,t+1,n),5)}var ta=BigInt(-1),df=BigInt(1);function hf(e,t,r,n){let o=Vt(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new N(x.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${$} integers outside of the safe integer range are not supported`);return new N(x.negint,ta-BigInt(o),9)}function Io(e,t){let r=t.value,n=typeof r=="bigint"?r*ta-df:r*-1-1;bt(e,t.type.majorEncoded,n)}Io.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*ta-df:r*-1-1;return n<dt[0]?1:n<dt[1]?2:n<dt[2]?3:n<dt[3]?5:9};Io.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function mn(e,t,r,n){ge(e,t,r+n);let o=Pr(e,t+r,t+r+n);return new N(x.bytes,o,r+n)}function pf(e,t,r,n){return mn(e,t,1,r)}function mf(e,t,r,n){return mn(e,t,2,kt(e,t+1,n))}function yf(e,t,r,n){return mn(e,t,3,Kt(e,t+1,n))}function gf(e,t,r,n){return mn(e,t,5,Mt(e,t+1,n))}function xf(e,t,r,n){let o=Vt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer bytes lengths not supported`);return mn(e,t,9,o)}function Co(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===x.string?tf(e.value):e.value),e.encodedBytes}function Rr(e,t){let r=Co(t);bt(e,t.type.majorEncoded,r.length),e.push(r)}Rr.encodedSize=function(t){let r=Co(t);return bt.encodedSize(r.length)+r.length};Rr.compareTokens=function(t,r){return Um(Co(t),Co(r))};function Um(e,t){return e.length<t.length?-1:e.length>t.length?1:nf(e,t)}function yn(e,t,r,n,o){let i=r+n;ge(e,t,i);let s=new N(x.string,Qu(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=Pr(e,t+r,t+i)),s}function bf(e,t,r,n){return yn(e,t,1,r,n)}function wf(e,t,r,n){return yn(e,t,2,kt(e,t+1,n),n)}function Ef(e,t,r,n){return yn(e,t,3,Kt(e,t+1,n),n)}function Sf(e,t,r,n){return yn(e,t,5,Mt(e,t+1,n),n)}function vf(e,t,r,n){let o=Vt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer string lengths not supported`);return yn(e,t,9,o,n)}var If=Rr;function Or(e,t,r,n){return new N(x.array,n,r)}function Cf(e,t,r,n){return Or(e,t,1,r)}function Tf(e,t,r,n){return Or(e,t,2,kt(e,t+1,n))}function Af(e,t,r,n){return Or(e,t,3,Kt(e,t+1,n))}function _f(e,t,r,n){return Or(e,t,5,Mt(e,t+1,n))}function Bf(e,t,r,n){let o=Vt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer array lengths not supported`);return Or(e,t,9,o)}function Df(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${$} indefinite length items not allowed`);return Or(e,t,1,1/0)}function To(e,t){bt(e,x.array.majorEncoded,t.value)}To.compareTokens=$t.compareTokens;To.encodedSize=function(t){return bt.encodedSize(t.value)};function Nr(e,t,r,n){return new N(x.map,n,r)}function Pf(e,t,r,n){return Nr(e,t,1,r)}function Rf(e,t,r,n){return Nr(e,t,2,kt(e,t+1,n))}function Of(e,t,r,n){return Nr(e,t,3,Kt(e,t+1,n))}function Nf(e,t,r,n){return Nr(e,t,5,Mt(e,t+1,n))}function Uf(e,t,r,n){let o=Vt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer map lengths not supported`);return Nr(e,t,9,o)}function Lf(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${$} indefinite length items not allowed`);return Nr(e,t,1,1/0)}function Ao(e,t){bt(e,x.map.majorEncoded,t.value)}Ao.compareTokens=$t.compareTokens;Ao.encodedSize=function(t){return bt.encodedSize(t.value)};function kf(e,t,r,n){return new N(x.tag,r,1)}function Kf(e,t,r,n){return new N(x.tag,kt(e,t+1,n),2)}function Mf(e,t,r,n){return new N(x.tag,Kt(e,t+1,n),3)}function Vf(e,t,r,n){return new N(x.tag,Mt(e,t+1,n),5)}function Ff(e,t,r,n){return new N(x.tag,Vt(e,t+1,n),9)}function _o(e,t){bt(e,x.tag.majorEncoded,t.value)}_o.compareTokens=$t.compareTokens;_o.encodedSize=function(t){return bt.encodedSize(t.value)};var Fm=20,$m=21,qm=22,zm=23;function $f(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${$} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new N(x.null,null,1):new N(x.undefined,void 0,1)}function qf(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${$} indefinite length items not allowed`);return new N(x.break,void 0,1)}function ea(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${$} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${$} Infinity values are not supported`)}return new N(x.float,e,t)}function zf(e,t,r,n){return ea(ra(e,t+1),3,n)}function Hf(e,t,r,n){return ea(na(e,t+1),5,n)}function jf(e,t,r,n){return ea(Yf(e,t+1),9,n)}function Bo(e,t,r){let n=t.value;if(n===!1)e.push([x.float.majorEncoded|Fm]);else if(n===!0)e.push([x.float.majorEncoded|$m]);else if(n===null)e.push([x.float.majorEncoded|qm]);else if(n===void 0)e.push([x.float.majorEncoded|zm]);else{let o,i=!1;(!r||r.float64!==!0)&&(Zf(n),o=ra(Zt,1),n===o||Number.isNaN(n)?(Zt[0]=249,e.push(Zt.slice(0,3)),i=!0):(Wf(n),o=na(Zt,1),n===o&&(Zt[0]=250,e.push(Zt.slice(0,5)),i=!0))),i||(Hm(n),o=Yf(Zt,1),Zt[0]=251,e.push(Zt.slice(0,9)))}}Bo.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){Zf(n);let o=ra(Zt,1);if(n===o||Number.isNaN(n))return 3;if(Wf(n),o=na(Zt,1),n===o)return 5}return 9};var Gf=new ArrayBuffer(9),qt=new DataView(Gf,1),Zt=new Uint8Array(Gf,0);function Zf(e){if(e===1/0)qt.setUint16(0,31744,!1);else if(e===-1/0)qt.setUint16(0,64512,!1);else if(Number.isNaN(e))qt.setUint16(0,32256,!1);else{qt.setFloat32(0,e);let t=qt.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)qt.setUint16(0,31744,!1);else if(r===0)qt.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?qt.setUint16(0,0):o<-14?qt.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):qt.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function ra(e,t){if(e.length-t<2)throw new Error(`${$} 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 Wf(e){qt.setFloat32(0,e,!1)}function na(e,t){if(e.length-t<4)throw new Error(`${$} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function Hm(e){qt.setFloat64(0,e,!1)}function Yf(e,t){if(e.length-t<8)throw new Error(`${$} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}Bo.compareTokens=$t.compareTokens;function Z(e,t,r){throw new Error(`${$} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Do(e){return()=>{throw new Error(`${$} ${e}`)}}var A=[];for(let e=0;e<=23;e++)A[e]=Z;A[24]=of;A[25]=sf;A[26]=af;A[27]=cf;A[28]=Z;A[29]=Z;A[30]=Z;A[31]=Z;for(let e=32;e<=55;e++)A[e]=Z;A[56]=uf;A[57]=ff;A[58]=lf;A[59]=hf;A[60]=Z;A[61]=Z;A[62]=Z;A[63]=Z;for(let e=64;e<=87;e++)A[e]=pf;A[88]=mf;A[89]=yf;A[90]=gf;A[91]=xf;A[92]=Z;A[93]=Z;A[94]=Z;A[95]=Do("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)A[e]=bf;A[120]=wf;A[121]=Ef;A[122]=Sf;A[123]=vf;A[124]=Z;A[125]=Z;A[126]=Z;A[127]=Do("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)A[e]=Cf;A[152]=Tf;A[153]=Af;A[154]=_f;A[155]=Bf;A[156]=Z;A[157]=Z;A[158]=Z;A[159]=Df;for(let e=160;e<=183;e++)A[e]=Pf;A[184]=Rf;A[185]=Of;A[186]=Nf;A[187]=Uf;A[188]=Z;A[189]=Z;A[190]=Z;A[191]=Lf;for(let e=192;e<=215;e++)A[e]=kf;A[216]=Kf;A[217]=Mf;A[218]=Vf;A[219]=Ff;A[220]=Z;A[221]=Z;A[222]=Z;A[223]=Z;for(let e=224;e<=243;e++)A[e]=Do("simple values are not supported");A[244]=Z;A[245]=Z;A[246]=Z;A[247]=$f;A[248]=Do("simple values are not supported");A[249]=zf;A[250]=Hf;A[251]=jf;A[252]=Z;A[253]=Z;A[254]=Z;A[255]=qf;var Wt=[];for(let e=0;e<24;e++)Wt[e]=new N(x.uint,e,1);for(let e=-1;e>=-24;e--)Wt[31-e]=new N(x.negint,e,1);Wt[64]=new N(x.bytes,new Uint8Array(0),1);Wt[96]=new N(x.string,"",1);Wt[128]=new N(x.array,0,1);Wt[160]=new N(x.map,0,1);Wt[244]=new N(x.false,!1,1);Wt[245]=new N(x.true,!0,1);Wt[246]=new N(x.null,null,1);function Gm(){let e=[];return e[x.uint.major]=$t,e[x.negint.major]=Io,e[x.bytes.major]=Rr,e[x.string.major]=If,e[x.array.major]=To,e[x.map.major]=Ao,e[x.tag.major]=_o,e[x.float.major]=Bo,e}var w6=Gm(),E6=new vo,Po=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(`${Qs} object contains circular references`);return new e(r,t)}},Ne={null:new N(x.null,null),undefined:new N(x.undefined,void 0),true:new N(x.true,!0),false:new N(x.false,!1),emptyArray:new N(x.array,0),emptyMap:new N(x.map,0)},Ue={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new N(x.float,e):e>=0?new N(x.uint,e):new N(x.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new N(x.uint,e):new N(x.negint,e)},Uint8Array(e,t,r,n){return new N(x.bytes,e)},string(e,t,r,n){return new N(x.string,e)},boolean(e,t,r,n){return e?Ne.true:Ne.false},null(e,t,r,n){return Ne.null},undefined(e,t,r,n){return Ne.undefined},ArrayBuffer(e,t,r,n){return new N(x.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new N(x.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[Ne.emptyArray,new N(x.break)]:Ne.emptyArray;n=Po.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=oa(s,r,n);return r.addBreakTokens?[new N(x.array,e.length),o,new N(x.break)]:[new N(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?[Ne.emptyMap,new N(x.break)]:Ne.emptyMap;n=Po.createCheck(n,e);let c=[],a=0;for(let u of i)c[a++]=[oa(u,r,n),oa(o?e.get(u):e[u],r,n)];return Zm(c,r),r.addBreakTokens?[new N(x.map,s),c,new N(x.break)]:[new N(x.map,s),c]}};Ue.Map=Ue.Object;Ue.Buffer=Ue.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Ue[`${e}Array`]=Ue.DataView;function oa(e,t={},r){let n=Zu(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||Ue[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=Ue[n];if(!i)throw new Error(`${Qs} unsupported type: ${n}`);return i(e,n,t,r)}function Zm(e,t){t.mapSorter&&e.sort(t.mapSorter)}var Wm={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Ro=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=Wt[t];if(r===void 0){let n=A[t];if(!n)throw new Error(`${$} 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}},gn=Symbol.for("DONE"),Oo=Symbol.for("BREAK");function Ym(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=Ur(t,r);if(i===Oo){if(e.value===1/0)break;throw new Error(`${$} got unexpected break to lengthed array`)}if(i===gn)throw new Error(`${$} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function Xm(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=Ur(t,r);if(c===Oo){if(e.value===1/0)break;throw new Error(`${$} got unexpected break to lengthed map`)}if(c===gn)throw new Error(`${$} found map but not enough entries (got ${s} [no key], expected ${e.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${$} non-string keys not supported (got ${typeof c})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${$} found repeat map key "${c}"`);let a=Ur(t,r);if(a===gn)throw new Error(`${$} 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 Ur(e,t){if(e.done())return gn;let r=e.next();if(r.type===x.break)return Oo;if(r.type.terminal)return r.value;if(r.type===x.array)return Ym(r,e,t);if(r.type===x.map)return Xm(r,e,t);if(r.type===x.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=Ur(e,t);return t.tags[r.value](n)}throw new Error(`${$} tag not supported (${r.value})`)}throw new Error("unsupported")}function Xf(e,t){if(!(e instanceof Uint8Array))throw new Error(`${$} data to decode must be a Uint8Array`);t=Object.assign({},Wm,t);let r=t.tokenizer||new Ro(e,t),n=Ur(r,t);if(n===gn)throw new Error(`${$} did not find any content to decode`);if(n===Oo)throw new Error(`${$} got unexpected break`);return[n,e.subarray(r.pos())]}function ia(e,t){let[r,n]=Xf(e,t);if(n.length>0)throw new Error(`${$} too many terminals, data makes no sense`);return r}var t0=Ye("ipns:utils"),Jf=F("/ipns/");var e0=0,r0=18;function Qf(e){let t;if(e.pubKey!=null)try{t=Cu(e.pubKey)}catch(r){throw t0.error(r),r}if(t!=null)return t}function tl(e){let t=F("ipns-signature:");return yt([t,e])}function Je(e){return"signatureV1"in e?Gt.encode({value:F(e.value),signatureV1:e.signatureV1,validityType:e.validityType,validity:F(e.validity),sequence:e.sequence,ttl:e.ttl,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data}):Gt.encode({pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data})}function oe(e){let t=Gt.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 jt("Missing data or signatureV2");let r=el(t.data),n=n0(r.Value),o=k(r.Validity);if(t.value!=null&&t.signatureV1!=null)return o0(t),{value:n,validityType:Gt.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:Gt.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 xn(e){return yt([Jf,e.bytes])}function xe(e){let t=Se(e.slice(Jf.length));if(!No(t,e0)&&!No(t,r0))throw new Eo("Multihash in IPNS key was not identity or sha2-256");return t}function el(e){let t=ia(e);if(t.ValidityType===0)t.ValidityType=Gt.ValidityType.EOL;else throw new Br("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 n0(e){let t=k(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 bo("Value must be a valid content path starting with /")}function o0(e){if(e.data==null)throw new wo("Record data is missing");let t=el(e.data);if(!Y(t.Value,e.value??new Uint8Array(0)))throw new jt('Field "value" did not match between protobuf and CBOR');if(!Y(t.Validity,e.validity??new Uint8Array(0)))throw new jt('Field "validity" did not match between protobuf and CBOR');if(t.ValidityType!==e.validityType)throw new jt('Field "validityType" did not match between protobuf and CBOR');if(t.Sequence!==e.sequence)throw new jt('Field "sequence" did not match between protobuf and CBOR');if(t.TTL!==e.ttl)throw new jt('Field "ttl" did not match between protobuf and CBOR')}function No(e,t){return e.code===t}var z6=Ye("ipns"),H6=300*1e9,s0="/ipns/",j6=s0.length;var rl=Jo(Js(),1);var Uo=Ye("ipns:validator"),a0=1024*10;async function c0(e,t){let r=oe(t),n;try{let o=tl(r.data);n=await e.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw Uo.error("record signature verification failed"),new jt("Record signature verification failed");if(r.validityType===Gt.ValidityType.EOL){if(rl.default.fromString(r.validity).toDate().getTime()<Date.now())throw Uo.error("record has expired"),new go("record has expired")}else if(r.validityType!=null)throw Uo.error("the validity type is unsupported"),new Br("The validity type is unsupported");Uo("ipns record for %s is valid",r.value)}async function nl(e,t){if(t.byteLength>a0)throw new xo("The record is too large");let r=xe(e),n;No(r,0)&&(n=Ar(r));let o=oe(t),i=Qf(o)??n;if(i==null)throw new hn("Could not extract public key from IPNS record or routing key");let s=xn(i.toMultihash());if(!Y(s,e))throw new hn("Embedded public key did not match routing key");await c0(i,t)}var Lo=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MESSAGE_LENGTH"};async function*bn(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)),cr(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 ie(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var aa=Jo(il(),1);var En=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},ca=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},sl=e=>globalThis.DOMException===void 0?new ca(e):new DOMException(e),al=e=>{let t=e.reason===void 0?sl("This operation was aborted."):e.reason;return t instanceof Error?t:sl(t)};function ua(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=t,s,c,u=new Promise((f,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:E}=t;E.aborted&&l(al(E)),c=()=>{l(al(E))},E.addEventListener("abort",c,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(f,l);return}let g=new En;s=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(E){l(E)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?f():o instanceof Error?l(o):(g.message=o??`Promise timed out after ${r} milliseconds`,l(g))},r),(async()=>{try{f(await e)}catch(E){l(E)}})()}).finally(()=>{u.clear(),c&&t.signal&&t.signal.removeEventListener("abort",c)});return u.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},u}function fa(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){r={priority:0,...r};let n={priority:r.priority,id:r.id,run:t};if(this.size===0||this.#t[this.size-1].priority>=r.priority){this.#t.push(n);return}let o=fa(this.#t,n,(i,s)=>s.priority-i.priority);this.#t.splice(o,0,n)}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 vn=class extends aa.default{#t;#r;#e=0;#h;#a;#p=0;#o;#c;#n;#m;#i=0;#u;#s;#y;#b=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Sn,...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})`);this.#t=t.carryoverConcurrencyCount,this.#r=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#h=t.intervalCap,this.#a=t.interval,this.#n=new t.queueClass,this.#m=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#y=t.throwOnTimeout===!0,this.#s=t.autoStart===!1}get#w(){return this.#r||this.#e<this.#h}get#E(){return this.#i<this.#u}#S(){this.#i--,this.#f(),this.emit("next")}#v(){this.#x(),this.#g(),this.#c=void 0}get#I(){let t=Date.now();if(this.#o===void 0){let r=this.#p-t;if(r<0)this.#e=this.#t?this.#i:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},r)),!0}return!1}#f(){if(this.#n.size===0)return this.#o&&clearInterval(this.#o),this.#o=void 0,this.emit("empty"),this.#i===0&&this.emit("idle"),!1;if(!this.#s){let t=!this.#I;if(this.#w&&this.#E){let r=this.#n.dequeue();return r?(this.emit("active"),r(),t&&this.#g(),!0):!1}}return!1}#g(){this.#r||this.#o!==void 0||(this.#o=setInterval(()=>{this.#x()},this.#a),this.#p=Date.now()+this.#a)}#x(){this.#e===0&&this.#i===0&&this.#o&&(clearInterval(this.#o),this.#o=void 0),this.#e=this.#t?this.#i:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}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.#u=t,this.#l()}async#C(t){return new Promise((r,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}setPriority(t,r){this.#n.setPriority(t,r)}async add(t,r={}){return r.id??=(this.#b++).toString(),r={timeout:this.timeout,throwOnTimeout:this.#y,...r},new Promise((n,o)=>{this.#n.enqueue(async()=>{this.#i++;try{r.signal?.throwIfAborted(),this.#e++;let i=t({signal:r.signal});r.timeout&&(i=ua(Promise.resolve(i),{milliseconds:r.timeout})),r.signal&&(i=Promise.race([i,this.#C(r.signal)]));let s=await i;n(s),this.emit("completed",s)}catch(i){if(i instanceof En&&!r.throwOnTimeout){n();return}o(i),this.emit("error",i)}finally{this.#S()}},r),this.emit("add"),this.#f()})}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}start(){return this.#s?(this.#s=!1,this.#l(),this):this}pause(){this.#s=!0}clear(){this.#n=new this.#m}async onEmpty(){this.#n.size!==0&&await this.#d("empty")}async onSizeLessThan(t){this.#n.size<t||await this.#d("next",()=>this.#n.size<t)}async onIdle(){this.#i===0&&this.#n.size===0||await this.#d("idle")}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.#n.size}sizeBy(t){return this.#n.filter(t).length}get pending(){return this.#i}get isPaused(){return this.#s}};var Lr=class extends Error{static name="InvalidRequestError";constructor(t="Invalid request"){super(t),this.name="InvalidRequestError"}},Yt=class extends Error{static name="BadResponseError";constructor(t="Bad response"){super(t),this.name="BadResponseError"}};function l0(e){return e[Symbol.asyncIterator]!=null}function d0(e){if(l0(e))return(async()=>{for await(let t of e)return t})();for(let t of e)return t}var Ko=d0;function h0(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 cl=h0;function p0(e){return e[Symbol.asyncIterator]!=null}function m0(e,t){let r=0;if(p0(e))return(async function*(){for await(let a of e)yield t(a,r++)})();let n=cl(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 Mo=m0;var ul=F("/ipns/");function fl(e){return Y(e.subarray(0,ul.byteLength),ul)}var Vo=class{client;constructor(t){this.client=t}async*findProviders(t,r={}){yield*Mo(this.client.getProviders(t,r),n=>({id:n.ID,multiaddrs:n.Addrs??[]}))}async provide(){}async cancelReprovide(){}async put(t,r,n){if(!fl(t))return;let o=xe(t),i=j.createV1(114,o),s=oe(r);await this.client.putIPNS(i,s,n)}async get(t,r){if(!fl(t))throw new Qt("Not found");let n=xe(t),o=j.createV1(114,n);try{let i=await this.client.getIPNS(o,r);return Je(i)}catch(i){throw i.name==="BadResponseError"?new Qt("Not found"):i}}},Fo=class{client;constructor(t){this.client=t}async findPeer(t,r={}){let n=await Ko(this.client.getPeers(t,r));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new Qt("Not found")}async*getClosestPeers(t,r={}){}};var wt=ci("delegated-routing-v1-http-api-client"),$o={concurrentRequests:4,timeout:3e4,cacheTTL:300*1e3,cacheName:"delegated-routing-v1-cache"},qo=class{started;httpQueue;shutDownController;clientUrl;timeout;contentRouting;peerRouting;filterAddrs;filterProtocols;inFlightRequests;cacheName;cache;cacheTTL;constructor(t,r={}){this.started=!1,this.shutDownController=new AbortController,this.shutDownController.signal,this.httpQueue=new vn({concurrency:r.concurrentRequests??$o.concurrentRequests}),this.inFlightRequests=new Map,this.clientUrl=t instanceof URL?t:new URL(t),this.timeout=r.timeout??$o.timeout,this.filterAddrs=r.filterAddrs,this.filterProtocols=r.filterProtocols,this.contentRouting=new Vo(this),this.peerRouting=new Fo(this),this.cacheName=r.cacheName??$o.cacheName,this.cacheTTL=r.cacheTTL??$o.cacheTTL}get[Ra](){return this.contentRouting}get[Oa](){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&&wt("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={}){wt("getProviders starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=dn([this.shutDownController.signal,n,r.signal]);let i=ie(),s=ie();this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let c=new URL(`${this.clientUrl}routing/v1/providers/${t.toString()}`);this.#r(c,r.filterAddrs,r.filterProtocols);let a={headers:{Accept:"application/x-ndjson"},signal:o},u=await this.#e(c.toString(),a);if(u==null)throw new Yt("No response received");if(!u.ok)throw u.status===404?new Qt("No matching records found"):u.status===422?new Lr("Request does not conform to schema or semantic constraints"):new Yt(`Unexpected status code: ${u.status}`);if(u.body==null)throw new Yt("Routing response had no body");let f=u.headers.get("Content-Type");if(f==null)throw new Yt("No Content-Type header received");if(f?.startsWith("application/json")){let l=await u.json();for(let g of l.Providers){let E=this.#t(g);E!=null&&(yield E)}}else if(f.includes("application/x-ndjson"))for await(let l of bn(yo(u.body))){let g=this.#t(l);g!=null&&(yield g)}else throw new Yt(`Unsupported Content-Type: ${f}`)}finally{o.clear(),s.resolve(),wt("getProviders finished: %c",t)}}async*getPeers(t,r={}){wt("getPeers starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=dn([this.shutDownController.signal,n,r.signal]);let i=ie(),s=ie();this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let c=new URL(`${this.clientUrl}routing/v1/peers/${t.toCID().toString()}`);this.#r(c,r.filterAddrs,r.filterProtocols);let a={headers:{Accept:"application/x-ndjson"},signal:o},u=await this.#e(c.toString(),a);if(u.status===404)throw new Qt("No matching records found");if(u.status===422)throw new Lr("Request does not conform to schema or semantic constraints");if(u.body==null)throw new Yt("Routing response had no body");if(u.headers.get("Content-Type")==="application/json"){let l=await u.json();for(let g of l.Peers){let E=this.#t(g);E!=null&&(yield E)}}else for await(let l of bn(yo(u.body))){let g=this.#t(l);g!=null&&(yield g)}}catch(c){wt.error("getPeers errored:",c)}finally{o.clear(),s.resolve(),wt("getPeers finished: %c",t)}}async getIPNS(t,r={}){wt("getIPNS starts: %s",t);let n=AbortSignal.timeout(this.timeout),o=dn([this.shutDownController.signal,n,r.signal]);let i=ie(),s=ie();this.httpQueue.add(async()=>(i.resolve(),s.promise));let c=`${this.clientUrl}routing/v1/ipns/${t}`;try{await i.promise;let a={headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:o},u=await this.#e(c,a);if(wt("getIPNS GET %s %d",c,u.status),u.status===404)throw new Qt("No matching records found");if(u.status===422)throw new Lr("Request does not conform to schema or semantic constraints");if(u.body==null)throw new Yt("GET ipns response had no body");let f=await u.arrayBuffer(),l=new Uint8Array(f,0,f.byteLength);return r.validate!==!1&&await nl(xn(t.multihash),l),oe(l)}catch(a){throw wt.error("getIPNS GET %s error:",c,a),a}finally{o.clear(),s.resolve(),wt("getIPNS finished: %s",t)}}async putIPNS(t,r,n={}){wt("putIPNS starts: %c",t);let o=AbortSignal.timeout(this.timeout),i=dn([this.shutDownController.signal,o,n.signal]);let s=ie(),c=ie();this.httpQueue.add(async()=>(s.resolve(),c.promise));let a=`${this.clientUrl}routing/v1/ipns/${t}`;try{await s.promise;let u=Je(r),f={method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:u,signal:i},l=await this.#e(a,f);if(wt("putIPNS PUT %s %d",a,l.status),l.status!==200)throw new Yt("PUT ipns response had status other than 200")}catch(u){throw wt.error("putIPNS PUT %s error:",a,u.stack),u}finally{i.clear(),c.resolve(),wt("putIPNS finished: %c",t)}}#t(t){try{let r=[],n=t.Addrs?.map(ln)??[];return t.Protocols!=null&&r.push(...t.Protocols),t.Protocol!=null&&(r.push(t.Protocol),delete t.Protocol),{...t,Schema:"peer",ID:_u(t.ID),Addrs:n,Protocols:r}}catch(r){wt.error("could not conform record to peer schema",r)}}#r(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 wt("returning cached response for %s",o),a;await this.cache?.delete(t)}}let i=this.inFlightRequests.get(o);if(i!=null){let a=await i;return wt("deduplicating outgoing request for %s",o),a.clone()}let s=fetch(t,r).then(async a=>{if(this.cache!=null&&a.ok&&n==="GET"){let u=Date.now()+this.cacheTTL,f=new Headers(a.headers);f.set("x-cache-expires",u.toString());let l=new Response(a.clone().body,{status:a.status,statusText:a.statusText,headers:f});await this.cache.put(t,l)}return a}).finally(()=>{this.inFlightRequests.delete(o)});return this.inFlightRequests.set(o,s),await s}};function ll(e,t={}){return new qo(new URL(e),t)}function zo(){return{filterProtocols:["unknown","transport-bitswap","transport-ipfs-gateway-http"],filterAddrs:["https","webtransport","webrtc","webrtc-direct","wss","tls"]}}var dl=F("/ipns/");function hl(e){return Y(e.subarray(0,dl.byteLength),dl)}var la=class{client;constructor(t,r={}){this.client=ll(t,r)}async provide(t,r){}async cancelReprovide(t,r){}async*findProviders(t,r){yield*Mo(this.client.getProviders(t,r),n=>({id:n.ID,multiaddrs:n.Addrs,protocols:n.Protocols}))}async put(t,r,n){if(!hl(t))return;let o=xe(t),i=j.createV1(114,o),s=oe(r);await this.client.putIPNS(i,s,n)}async get(t,r){if(!hl(t))throw new rr("Not found");let n=xe(t),o=j.createV1(114,n);try{let i=await this.client.getIPNS(o,r);return Je(i)}catch(i){throw i.name==="BadResponseError"?new rr("Not found"):i}}async findPeer(t,r){let n=await Ko(this.client.getPeers(t,r));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new rr("Not found")}async*getClosestPeers(t,r){}};function pl(e,t){let r=t??zo();return new la(new URL(e),r)}var ml=Symbol.for("nodejs.util.inspect.custom"),y0=114,In=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()})`}[ui]=!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(y0,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return Y(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return Y(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[ml](){return`PeerId(${this.toString()})`}},Ho=class extends In{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},jo=class extends In{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Go=class extends In{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},g0=2336,Cn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=mt.digest(F(this.url))}[ml](){return`PeerId(${this.url})`}[ui]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return j.createV1(g0,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=k(t)),t.toString()===this.toString())}};var x0=114,yl=2336;function b0(e){if(E0(e))return new Ho({multihash:e});if(w0(e))try{let t=Ar(e);if(t.type==="Ed25519")return new jo({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Go({multihash:e,publicKey:t})}catch{let r=k(e.digest);return new Cn(new URL(r))}throw new Un("Supplied PeerID Multihash is invalid")}function gl(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==x0&&e.code!==yl)throw new Nn("Supplied PeerID CID is invalid");if(e.code===yl){let t=k(e.multihash.digest);return new Cn(new URL(t))}return b0(e.multihash)}function w0(e){return e.code===mt.code}function E0(e){return e.code===Ke.code}var Et=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},be=class extends Error{static name="ValidationError";name="ValidationError"},Zo=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Wo=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function ha(e){return t=>k(t,e)}function pa(e){return t=>F(t,e)}function kr(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function Qe(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function xl(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=F(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=Qe(n);return yt([r,o],r.length+o.length)}function bl(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=Dt.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=Qe(n);return yt([r,o],r.length+o.length)}function ma(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=k(t,"base32"),o=kr(r);return`${n}:${o}`}var ya=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 Et("Invalid byte value in IP address");t[n]=o}),t},wl=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let i=Oe(r[n]),s;i&&(s=ya(r[n]),r[n]=k(s.subarray(0,2),"base16")),s!=null&&++n<8&&r.splice(n,0,k(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 Et("Invalid byte value in IP address");o[t++]=i>>8&255,o[t++]=i&255}return o},El=function(e){if(e.byteLength!==4)throw new Et("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Sl=function(e){if(e.byteLength!==16)throw new Et("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 Et(`Invalid IPv6 address "${r}"`)}};function vl(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new Et(`Invalid IPv6 address "${e}"`)}}var da=Object.values(Me).map(e=>e.decoder),S0=(function(){let e=da[0].or(da[1]);return da.slice(2).forEach(t=>e=e.or(t)),e})();function Il(e){return S0.decode(e)}function Cl(e){return t=>e.encoder.encode(t)}function v0(e){if(parseInt(e).toString()!==e)throw new be("Value must be an integer")}function I0(e){if(e<0)throw new be("Value must be a positive integer, or zero")}function C0(e){return t=>{if(t>e)throw new be(`Value must be smaller than or equal to ${e}`)}}function T0(...e){return t=>{for(let r of e)r(t)}}var Tn=T0(v0,I0,C0(65535));var ht=-1,ga=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 Wo(`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)}))}},we=new ga,hy=[{code:4,name:"ip4",size:32,valueToBytes:ya,bytesToValue:El,validate:e=>{if(!Oe(e))throw new be(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Qe,bytesToValue:kr,validate:Tn},{code:273,name:"udp",size:16,valueToBytes:Qe,bytesToValue:kr,validate:Tn},{code:33,name:"dccp",size:16,valueToBytes:Qe,bytesToValue:kr,validate:Tn},{code:41,name:"ip6",size:128,valueToBytes:wl,bytesToValue:Sl,stringToValue:vl,validate:e=>{if(!uo(e))throw new be(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:ht},{code:43,name:"ipcidr",size:8,bytesToValue:ha("base10"),valueToBytes:pa("base10")},{code:53,name:"dns",size:ht},{code:54,name:"dns4",size:ht},{code:55,name:"dns6",size:ht},{code:56,name:"dnsaddr",size:ht},{code:132,name:"sctp",size:16,valueToBytes:Qe,bytesToValue:kr,validate:Tn},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ht,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:ht,bytesToValue:ha("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?pa("base58btc")(e):j.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:ma,valueToBytes:xl},{code:445,name:"onion3",size:296,bytesToValue:ma,valueToBytes:bl},{code:446,name:"garlic64",size:ht},{code:447,name:"garlic32",size:ht},{code:448,name:"tls"},{code:449,name:"sni",size:ht},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ht,bytesToValue:Cl(Mr),valueToBytes:Il},{code:480,name:"http"},{code:481,name:"http-path",size:ht,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:ht}];hy.forEach(e=>{we.addProtocol(e)});function Tl(e){let t=[],r=0;for(;r<e.length;){let n=br(e,r),o=we.getProtocol(n),i=At(n),s=py(o,e,r+i),c=0;s>0&&o.size===ht&&(c=At(s));let a=i+c+s,u={code:n,name:o.name,bytes:e.subarray(r,r+a)};if(s>0){let f=r+i+c,l=e.subarray(f,f+s);u.value=o.bytesToValue?.(l)??k(l)}t.push(u),r+=a}return t}function Al(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=we.getProtocol(n.code),i=At(n.code),s,c=0,a=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??F(n.value),c=s.byteLength,o.size===ht&&(a=At(c)));let u=new Uint8Array(i+a+c),f=0;De(n.code,u,f),f+=i,s!=null&&(o.size===ht&&(De(c,u,f),f+=a),u.set(s,f)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return yt(r,t)}function _l(e){if(e.charAt(0)!=="/")throw new Et('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=we.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 Et(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new Et(`Component ${o} was missing value`);u.value=a.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new Et("Incomplete multiaddr");return t}function Bl(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=we.getProtocol(t.code);if(r==null)throw new Et(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function py(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:br(t,r)}var my=Symbol.for("nodejs.util.inspect.custom"),xa=Symbol.for("@multiformats/multiaddr");function yy(e){if(e==null&&(e="/"),Dl(e))return e.getComponents();if(e instanceof Uint8Array)return Tl(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),_l(e);if(Array.isArray(e))return e;throw new Et("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Yo=class e{[xa]=!0;#t;#r;#e;constructor(t="/",r={}){this.#t=yy(t),r.validate!==!1&&gy(this)}get bytes(){return this.#e==null&&(this.#e=Al(this.#t)),this.#e}toString(){return this.#r==null&&(this.#r=Bl(this.#t)),this.#r}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 Zo(`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 Y(this.bytes,t.bytes)}[my](){return`Multiaddr(${this.toString()})`}};function gy(e){e.getComponents().forEach(t=>{let r=we.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function Dl(e){return!!e?.[xa]}function Pl(e){return new Yo(e)}var Rl="[a-fA-F\\d:]",Le=e=>e&&e.includeBoundaries?`(?:(?<=\\s|^)(?=${Rl})|(?<=${Rl})(?=\\s|$))`:"",Xt="(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}",at="[a-fA-F\\d]{1,4}",Xo=`
|
|
4
4
|
(?:
|
|
5
5
|
(?:${at}:){7}(?:${at}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
|
|
6
|
-
(?:${at}:){6}(?:${
|
|
7
|
-
(?:${at}:){5}(?::${
|
|
8
|
-
(?:${at}:){4}(?:(?::${at}){0,1}:${
|
|
9
|
-
(?:${at}:){3}(?:(?::${at}){0,2}:${
|
|
10
|
-
(?:${at}:){2}(?:(?::${at}){0,3}:${
|
|
11
|
-
(?:${at}:){1}(?:(?::${at}){0,4}:${
|
|
12
|
-
(?::(?:(?::${at}){0,5}:${
|
|
6
|
+
(?:${at}:){6}(?:${Xt}|:${at}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
|
|
7
|
+
(?:${at}:){5}(?::${Xt}|(?::${at}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
|
|
8
|
+
(?:${at}:){4}(?:(?::${at}){0,1}:${Xt}|(?::${at}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
|
|
9
|
+
(?:${at}:){3}(?:(?::${at}){0,2}:${Xt}|(?::${at}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
|
|
10
|
+
(?:${at}:){2}(?:(?::${at}){0,3}:${Xt}|(?::${at}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
|
|
11
|
+
(?:${at}:){1}(?:(?::${at}){0,4}:${Xt}|(?::${at}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
|
|
12
|
+
(?::(?:(?::${at}){0,5}:${Xt}|(?::${at}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
|
|
13
13
|
)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
|
|
14
|
-
`.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),
|
|
14
|
+
`.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),xy=new RegExp(`(?:^${Xt}$)|(?:^${Xo}$)`),by=new RegExp(`^${Xt}$`),wy=new RegExp(`^${Xo}$`),ba=e=>e&&e.exact?xy:new RegExp(`(?:${Le(e)}${Xt}${Le(e)})|(?:${Le(e)}${Xo}${Le(e)})`,"g");ba.v4=e=>e&&e.exact?by:new RegExp(`${Le(e)}${Xt}${Le(e)}`,"g");ba.v6=e=>e&&e.exact?wy:new RegExp(`${Le(e)}${Xo}${Le(e)}`,"g");var wa=ba;function Ea(e){let t=(...r)=>e(...r);return Object.defineProperty(t,"name",{value:`functionTimeout(${e.name||"<anonymous>"})`,configurable:!0}),t}function Ol(){return!1}var{toString:Ey}=Object.prototype;function Sa(e){return Ey.call(e)==="[object RegExp]"}var Nl={global:"g",ignoreCase:"i",multiline:"m",dotAll:"s",sticky:"y",unicode:"u"};function va(e,t={}){if(!Sa(e))throw new TypeError("Expected a RegExp instance");let r=Object.keys(Nl).map(o=>(typeof t[o]=="boolean"?t[o]:e[o])?Nl[o]:"").join(""),n=new RegExp(t.source||e.source,r);return n.lastIndex=typeof t.lastIndex=="number"?t.lastIndex:e.lastIndex,n}function Ia(e,t,{timeout:r}={}){try{return Ea(()=>va(e).test(t),{timeout:r})()}catch(n){if(Ol(n))return!1;throw n}}var Sy=15,vy=45,Ul={timeout:400};function Ca(e){return e.length>vy?!1:Ia(wa.v6({exact:!0}),e,Ul)}function Ll(e){return e.length>Sy?!1:Ia(wa.v4({exact:!0}),e,Ul)}var kl={http:"80",https:"443",ws:"80",wss:"443"},Iy=["http","https","ws","wss"];function Kl(e,t){t=t??{};let r=t.defaultDnsType??"dns",{scheme:n,hostname:o,port:i,path:s}=Cy(e),c=[Ty(o,r),Ay(i,n),_y(n)];s!=null&&c.push(By(s));let a="/"+c.filter(u=>!!u).reduce((u,f)=>u.concat(f),[]).join("/");return Pl(a)}function Cy(e){let[t]=e.split(":");Iy.includes(t)||(e="http"+e.substring(t.length));let{protocol:r,hostname:n,port:o,pathname:i,search:s}=new URL(e);if(o==null||o===""){let a=Dy(t);a!=null&&(o=a),a==null&&r==="http:"&&(o="80")}let c;return i!=null&&i!==""&&i!=="/"&&(i.startsWith("/")&&(i=i.substring(1)),c=i),s!=null&&s!==""&&(c=c??"",c+=s),{scheme:t,hostname:n,port:o,path:c}}function Ty(e,t){if(!(e==null||e==="")){if(Ll(e))return["ip4",e];if(Ca(e))return["ip6",e];if(e[0]==="["){let r=e.substring(1,e.length-1);if(Ca(r))return["ip6",r]}return[t,e]}}function Ay(e,t){if(!(e==null||e===""))return t==="udp"?["udp",e]:["tcp",e]}function _y(e){if(e.match(/^tcp$|^udp$/)==null)return e==="https"?["/tls/http"]:e==="wss"?["/tls/ws"]:[e]}function By(e){if(!(e==null||e===""))return["http-path",encodeURIComponent(e)]}function Dy(e){if(!(e==null||e===""||kl[e]==null))return kl[e]}var Py=["https://trustless-gateway.link","https://4everland.io"],Ry=2336;function Oy(e){return e=e.toString(),{id:gl(j.createV1(Ry,mt.digest(F(e)))),multiaddrs:[Kl(e)]}}var Ta=class{gateways;shuffle;constructor(t={}){this.gateways=(t.gateways??Py).map(r=>Oy(r)),this.shuffle=t.shuffle??!0}async*findProviders(t,r){yield*(this.shuffle?this.gateways.toSorted(()=>Math.random()>.5?1:-1):this.gateways).map(n=>({...n,protocols:["transport-ipfs-gateway-http"]}))}};function Ml(e={}){return new Ta(e)}var Aa=class{libp2p;constructor(t){this.libp2p=t}async provide(t,r){await this.libp2p.contentRouting.provide(t,r)}async cancelReprovide(t,r){await this.libp2p.contentRouting.cancelReprovide(t,r)}async*findProviders(t,r){yield*this.libp2p.contentRouting.findProviders(t,r)}async put(t,r,n){await this.libp2p.contentRouting.put(t,r,n)}async get(t,r){return this.libp2p.contentRouting.get(t,r)}async findPeer(t,r){return this.libp2p.peerRouting.findPeer(t,r)}async*getClosestPeers(t,r){yield*this.libp2p.peerRouting.getClosestPeers(t,r)}};function Vl(e){return new Aa(e)}return jl(Ny);})();
|
|
15
15
|
/*! Bundled license information:
|
|
16
16
|
|
|
17
|
-
@noble/hashes/
|
|
17
|
+
@noble/hashes/utils.js:
|
|
18
18
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
19
19
|
|
|
20
|
-
@noble/curves/
|
|
21
|
-
@noble/curves/
|
|
22
|
-
@noble/curves/
|
|
23
|
-
@noble/curves/
|
|
24
|
-
@noble/curves/
|
|
25
|
-
@noble/curves/
|
|
26
|
-
@noble/curves/
|
|
27
|
-
@noble/curves/esm/secp256k1.js:
|
|
20
|
+
@noble/curves/utils.js:
|
|
21
|
+
@noble/curves/abstract/modular.js:
|
|
22
|
+
@noble/curves/abstract/curve.js:
|
|
23
|
+
@noble/curves/abstract/edwards.js:
|
|
24
|
+
@noble/curves/ed25519.js:
|
|
25
|
+
@noble/curves/abstract/weierstrass.js:
|
|
26
|
+
@noble/curves/secp256k1.js:
|
|
28
27
|
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
29
28
|
*/
|
|
30
29
|
return HeliaRouters}));
|