@helia/routers 5.1.0 → 5.1.1-eb1908b3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,32 +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 Al=Object.create;var xn=Object.defineProperty;var Il=Object.getOwnPropertyDescriptor;var Tl=Object.getOwnPropertyNames;var Cl=Object.getPrototypeOf,Bl=Object.prototype.hasOwnProperty;var va=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),St=(e,t)=>{for(var r in t)xn(e,r,{get:t[r],enumerable:!0})},Aa=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Tl(t))!Bl.call(e,o)&&o!==r&&xn(e,o,{get:()=>t[o],enumerable:!(n=Il(t,o))||n.enumerable});return e};var Vo=(e,t,r)=>(r=e!=null?Al(Cl(e)):{},Aa(t||!e||!e.__esModule?xn(r,"default",{value:e,enumerable:!0}):r,e)),_l=e=>Aa(xn({},"__esModule",{value:!0}),e);var Ps=va((v1,Ns)=>{var S1=(function(){typeof Ns<"u"&&(Ns.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",f=Math.trunc||function(p){var y=p-p%1;return y==0&&(p<0||p===0&&1/p!=1/0)?-0:y},u=T.prototype,l=(T.fromDate=function(p){return new T(+p)},T.fromInt64BE=L(0,1,2,3,0,4),T.fromInt64LE=L(3,2,1,0,4,0),T.fromString=function(D){var y,_=new T,D=(D+="").replace(/^\s*[+\-]?\d+/,function(g){var g=+g,x=1970+(g-1970)%400;return _.year=g-x,x}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(A,g,x){return g<0&&(x*=-1),y=6e4*(60*+g+ +x),""}).replace(/\.\d+$/,function(A){return _.nano=+(A+a).substr(1,9),""}).split(/\D+/);if(1<D.length?D[1]--:D[1]=0,_.time=y=Date.UTC.apply(Date,D)-(y||0),isNaN(y))throw new TypeError("Invalid Date");return I(_)},T.fromTimeT=function(p){return C(p,0)},u.year=0,u.time=0,u.nano=0,u.addNano=function(p){return this.nano+=+p||0,this},u.getNano=function(){var p=I(this);return(p.time%1e3*c+ +p.nano+1e9)%1e9},u.getTimeT=function(){var y=I(this),p=Math.floor(y.time/1e3),y=y.year;return y&&(p+=y*r*e/t),p},u.getYear=function(){return this.toDate().getUTCFullYear()+this.year},u.toDate=function(){return w(I(this).time)},u.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},u.toString=function(p){var y=this,_=y.toDate(),D={H:function(){return F(_.getUTCHours())},L:function(){return M(_.getUTCMilliseconds(),3)},M:function(){return F(_.getUTCMinutes())},N:function(){return M(y.getNano(),9)},S:function(){return F(_.getUTCSeconds())},Y:function(){var A=y.getYear();return 999999<A?"+"+A:9999<A?"+"+M(A,6):0<=A?M(A,4):-999999<=A?"-"+M(-A,6):A},a:function(){return E[_.getUTCDay()]},b:function(){return m[_.getUTCMonth()]},d:function(){return F(_.getUTCDate())},e:function(){return(function(A){return(9<A?"":" ")+(0|A)})(_.getUTCDate())},m:function(){return F(_.getUTCMonth()+1)}};return(function A(g){return g.replace(/%./g,function(x){var S=x[1],d=b[S],S=D[S];return d?A(d):S?S():x})})(p||l)},u.writeInt64BE=v(0,1,2,3,0,4),u.writeInt64LE=v(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),m=["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(p,y,_){var D=this;if(!(D instanceof T))return new T(p,y,_);D.time=+p||0,D.nano=+y||0,D.year=+_||0,I(D)}function I(p){var y,_,D,A=p.year,g=p.time,x=p.nano,d=((x<0||c<=x)&&(x-=(_=Math.floor(x/c))*c,g+=_,_=1),A%t);return(g<-i||i<g||d)&&((y=f(g/o))&&(A+=y*t,g-=y*o),(D=w(g)).setUTCFullYear(d+D.getUTCFullYear()),D=(g=+D)+(y=f((A-=d)/t))*o,y&&-i<=D&&D<=i&&(A-=y*t,g=D),_=1),_&&(p.year=A,p.time=g,p.nano=x),p}function w(p){var y=new Date(0);return y.setTime(p),y}function C(A,D){A=+A||0;var _=f((D=(D|0)*s)/n)+f(A/n),D=D%n+A%n,A=f(D/n);return A&&(_+=A,D-=A*n),new T(1e3*D,0,_*t)}function v(p,y,_,D,A,g){return function(d,S){var P=I(this);d=d||new Array(8),k(d,S|=0);var U=Math.floor(P.time/1e3),P=P.year*(r*e/t),R=f(P/s)+f(U/s),P=P%s+U%s,U=Math.floor(P/s);return U&&(R+=U,P-=U*s),x(d,S+A,R),x(d,S+g,P),d};function x(d,S,R){d[S+p]=R>>24&255,d[S+y]=R>>16&255,d[S+_]=R>>8&255,d[S+D]=255&R}}function L(p,y,_,D,A,g){return function(d,S){k(d,S|=0);var R=x(d,S+A);return C(x(d,S+g),R)};function x(d,S){return 16777216*d[S+p]+(d[S+y]<<16|d[S+_]<<8|d[S+D])}}function k(p,y){if(p=p&&p.length,p==null)throw new TypeError("Invalid Buffer");if(p<y+8)throw new RangeError("Out of range")}function F(p){return(9<p?"":"0")+(0|p)}function M(p,y){return(a+(0|p)).substr(-y)}})()});var sl=va((JE,sa)=>{"use strict";var sm=Object.prototype.hasOwnProperty,It="~";function mn(){}Object.create&&(mn.prototype=Object.create(null),new mn().__proto__||(It=!1));function am(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function il(e,t,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new am(r,n||e,o),s=It?It+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 No(e,t){--e._eventsCount===0?e._events=new mn:delete e._events[t]}function Et(){this._events=new mn,this._eventsCount=0}Et.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)sm.call(r,n)&&t.push(It?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};Et.prototype.listeners=function(t){var r=It?It+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};Et.prototype.listenerCount=function(t){var r=It?It+t:t,n=this._events[r];return n?n.fn?1:n.length:0};Et.prototype.emit=function(t,r,n,o,i,s){var c=It?It+t:t;if(!this._events[c])return!1;var a=this._events[c],f=arguments.length,u,l;if(a.fn){switch(a.once&&this.removeListener(t,a.fn,void 0,!0),f){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,u=new Array(f-1);l<f;l++)u[l-1]=arguments[l];a.fn.apply(a.context,u)}else{var m=a.length,E;for(l=0;l<m;l++)switch(a[l].once&&this.removeListener(t,a[l].fn,void 0,!0),f){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(!u)for(E=1,u=new Array(f-1);E<f;E++)u[E-1]=arguments[E];a[l].fn.apply(a[l].context,u)}}return!0};Et.prototype.on=function(t,r,n){return il(this,t,r,n,!1)};Et.prototype.once=function(t,r,n){return il(this,t,r,n,!0)};Et.prototype.removeListener=function(t,r,n,o){var i=It?It+t:t;if(!this._events[i])return this;if(!r)return No(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&No(this,i);else{for(var c=0,a=[],f=s.length;c<f;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:No(this,i)}return this};Et.prototype.removeAllListeners=function(t){var r;return t?(r=It?It+t:t,this._events[r]&&No(this,r)):(this._events=new mn,this._eventsCount=0),this};Et.prototype.off=Et.prototype.removeListener;Et.prototype.addListener=Et.prototype.on;Et.prefixed=It;Et.EventEmitter=Et;typeof sa<"u"&&(sa.exports=Et)});var Dm={};St(Dm,{delegatedHTTPRouting:()=>pl,delegatedHTTPRoutingDefaults:()=>Mo,httpGatewayRouting:()=>Sl,libp2pRouting:()=>vl});var Ia=Symbol.for("@libp2p/content-routing");var ot=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 Tt=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var bn=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 wn=Symbol.for("@libp2p/peer-id");function Ta(e){return!!e?.[wn]}var Ca=Symbol.for("@libp2p/peer-routing");var jo={};St(jo,{base58btc:()=>X,base58flickr:()=>Ol});var Om=new Uint8Array(0);function Ba(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 _a(e){return new TextEncoder().encode(e)}function Da(e){return new TextDecoder().decode(e)}function Dl(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),f=Math.log(c)/Math.log(256),u=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,I=0,w=0,C=b.length;w!==C&&b[w]===0;)w++,T++;for(var v=(C-w)*u+1>>>0,L=new Uint8Array(v);w!==C;){for(var k=b[w],F=0,M=v-1;(k!==0||F<I)&&M!==-1;M--,F++)k+=256*L[M]>>>0,L[M]=k%c>>>0,k=k/c>>>0;if(k!==0)throw new Error("Non-zero carry");I=F,w++}for(var p=v-I;p!==v&&L[p]===0;)p++;for(var y=a.repeat(T);p<v;++p)y+=e.charAt(L[p]);return y}function m(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 I=0,w=0;b[T]===a;)I++,T++;for(var C=(b.length-T)*f+1>>>0,v=new Uint8Array(C);b[T];){var L=r[b.charCodeAt(T)];if(L===255)return;for(var k=0,F=C-1;(L!==0||k<w)&&F!==-1;F--,k++)L+=c*v[F]>>>0,v[F]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");w=k,T++}if(b[T]!==" "){for(var M=C-w;M!==C&&v[M]===0;)M++;for(var p=new Uint8Array(I+(C-M)),y=I;M!==C;)p[y++]=v[M++];return p}}}function E(b){var T=m(b);if(T)return T;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:m,decode:E}}var Rl=Dl,Nl=Rl,Na=Nl;var $o=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")}},qo=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 Pa(this,t)}},Ho=class{decoders;constructor(t){this.decoders=t}or(t){return Pa(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 Pa(e,t){return new Ho({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var zo=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 $o(t,r,n),this.decoder=new qo(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 zo(e,t,r,n)}function Ee({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Na(r,e);return nr({prefix:t,name:e,encode:n,decode:i=>ae(o(i))})}function Pl(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 f=0;f<o;++f){let u=t[e[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|u,s+=r,s>=8&&(s-=8,i[a++]=255&c>>s)}if(s>=r||(255&c<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Ll(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 Ul(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function it({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Ul(n);return nr({prefix:t,name:e,encode(i){return Ll(i,n,r)},decode(i){return Pl(i,o,r,e)}})}var X=Ee({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ol=Ee({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Go={};St(Go,{base32:()=>te,base32hex:()=>Fl,base32hexpad:()=>$l,base32hexpadupper:()=>ql,base32hexupper:()=>Vl,base32pad:()=>Kl,base32padupper:()=>Ml,base32upper:()=>kl,base32z:()=>Hl});var te=it({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),kl=it({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Kl=it({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ml=it({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Fl=it({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Vl=it({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),$l=it({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ql=it({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Hl=it({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Zo={};St(Zo,{base36:()=>or,base36upper:()=>zl});var or=Ee({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),zl=Ee({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ee={};St(ee,{Digest:()=>Ue,create:()=>Ht,decode:()=>Se,equals:()=>Wo,hasCode:()=>fd});var jl=Oa,La=128,Gl=127,Zl=~Gl,Yl=Math.pow(2,31);function Oa(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Yl;)t[r++]=e&255|La,e/=128;for(;e&Zl;)t[r++]=e&255|La,e>>>=7;return t[r]=e|0,Oa.bytes=r-n+1,t}var Wl=Yo,Xl=128,Ua=127;function Yo(e,n){var r=0,n=n||0,o=0,i=n,s,c=e.length;do{if(i>=c)throw Yo.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&Ua)<<o:(s&Ua)*Math.pow(2,o),o+=7}while(s>=Xl);return Yo.bytes=i-n,r}var Jl=Math.pow(2,7),Ql=Math.pow(2,14),td=Math.pow(2,21),ed=Math.pow(2,28),rd=Math.pow(2,35),nd=Math.pow(2,42),od=Math.pow(2,49),id=Math.pow(2,56),sd=Math.pow(2,63),ad=function(e){return e<Jl?1:e<Ql?2:e<td?3:e<ed?4:e<rd?5:e<nd?6:e<od?7:e<id?8:e<sd?9:10},cd={encode:jl,decode:Wl,encodingLength:ad},ud=cd,Rr=ud;function Nr(e,t=0){return[Rr.decode(e,t),Rr.decode.bytes]}function ir(e,t,r=0){return Rr.encode(e,t,r),t}function sr(e){return Rr.encodingLength(e)}function Ht(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 Ue(e,r,t,i)}function Se(e){let t=ae(e),[r,n]=Nr(t),[o,i]=Nr(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Ue(r,o,s,t)}function Wo(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ba(e.bytes,r.bytes)}}var Ue=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function fd(e,t){return e.code===t}function ka(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return dd(r,Xo(e),t??X.encoder);default:return hd(r,Xo(e),t??te.encoder)}}var Ka=new WeakMap;function Xo(e){let t=Ka.get(e);if(t==null){let r=new Map;return Ka.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!==Pr)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=Ht(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&&Wo(t.multihash,n.multihash)}toString(t){return ka(this,t)}toJSON(){return{"/":ka(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??Ma(n,o,i.bytes))}else if(r[md]===!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!==Pr)throw new Error(`Version 0 CID must use dag-pb (code: ${Pr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Ma(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Pr,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 Ue(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,m]=Nr(t.subarray(r));return r+=m,l},o=n(),i=Pr;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(),f=r+a,u=f-s;return{version:o,codec:i,multihashCode:c,digestSize:a,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 Xo(i).set(n,t),i}};function ld(e,t){switch(e[0]){case"Q":{let r=t??X;return[X.prefix,r.decode(`${X.prefix}${e}`)]}case X.prefix:{let r=t??X;return[X.prefix,r.decode(e)]}case te.prefix:{let r=t??te;return[te.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!==X.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 Pr=112,pd=18;function Ma(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 Jo={};St(Jo,{identity:()=>vt});var Fa=0,yd="identity",Va=ae;function gd(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 Ht(Fa,Va(e))}var vt={code:Fa,name:yd,encode:Va,digest:gd};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 ce(e=0){return new Uint8Array(e)}function ct(e=0){return new Uint8Array(e)}function Kt(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=ct(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var qa=Symbol.for("@achingbrain/uint8arraylist");function $a(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 ar(e){return!!e?.[qa]}var Rt=class e{bufs;length;[qa]=!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(ar(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(ar(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=$a(this.bufs,t);return r.buf[r.index]}set(t,r){let n=$a(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(ar(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 Kt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Kt(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 f=t>=c&&t<a,u=r>c&&r<=a;if(f&&u){if(t===c&&r===a){n.push(s);break}let l=t-c;n.push(s.subarray(l,l+(r-t)));break}if(f){if(t===0){n.push(s);continue}n.push(s.subarray(t-c));continue}if(u){if(r===a){n.push(s);break}n.push(s.subarray(0,r-c));break}n.push(s)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!ar(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,f=n.byteLength-1,u;for(let l=r;l<=a;l+=u){u=0;for(let m=f;m>=0;m--){let E=this.get(l+m);if(n[m]!==E){u=Math.max(1,m-c[E]);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=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=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=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=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(!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 Qo={};St(Qo,{base10:()=>xd});var xd=Ee({prefix:"9",name:"base10",alphabet:"0123456789"});var ti={};St(ti,{base16:()=>bd,base16upper:()=>wd});var bd=it({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),wd=it({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ei={};St(ei,{base2:()=>Ed});var Ed=it({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ri={};St(ri,{base256emoji:()=>Td});var Ha=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=Ha.reduce((e,t,r)=>(e[r]=t,e),[]),vd=Ha.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 Td=nr({prefix:"\u{1F680}",name:"base256emoji",encode:Ad,decode:Id});var ii={};St(ii,{base64:()=>ni,base64pad:()=>Cd,base64url:()=>oi,base64urlpad:()=>Bd});var ni=it({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Cd=it({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),oi=it({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Bd=it({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var si={};St(si,{base8:()=>_d});var _d=it({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ai={};St(ai,{identity:()=>Dd});var Dd=nr({prefix:"\0",name:"identity",encode:e=>Da(e),decode:e=>_a(e)});var by=new TextEncoder,wy=new TextDecoder;var za=85;var fi={};St(fi,{sha256:()=>Lr,sha512:()=>Pd});var Nd=20;function ui({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new ci(e,t,r,n,o)}var ci=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Nd,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?Ga(n,this.code,r?.truncate):n.then(o=>Ga(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ga(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 Ht(t,e)}function Ya(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Lr=ui({name:"sha2-256",code:18,encode:Ya("SHA-256")}),Pd=ui({name:"sha2-512",code:19,encode:Ya("SHA-512")});var Ur={...ai,...ei,...si,...Qo,...ti,...Go,...Zo,...jo,...ii,...ri},Ny={...fi,...Jo};function Xa(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Wa=Xa("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),li=Xa("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=ct(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Ld={utf8:Wa,"utf-8":Wa,hex:Ur.base16,latin1:li,ascii:li,binary:li,...Ur},Sn=Ld;function q(e,t="utf8"){let r=Sn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function z(e,t="utf8"){let r=Sn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Ud=parseInt("11111",2),di=parseInt("10000000",2),Od=parseInt("01111111",2),Ja={0:Or,1:Or,2:kd,3:Fd,4:Vd,5:Md,6:Kd,16:Or,22:Or,48:Or};function ue(e,t={offset:0}){let r=e[t.offset]&Ud;if(t.offset++,Ja[r]!=null)return Ja[r](e,t);throw new Error("No decoder for tag "+r)}function kr(e,t){let r=0;if((e[t.offset]&di)===di){let n=e[t.offset]&Od,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 Or(e,t){kr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=ue(e,t);if(n===null)break;r.push(n)}return r}function kd(e,t){let r=kr(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 Kd(e,t){let r=kr(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 f=e[t.offset];if(t.offset++,a.push(f&127),f<128){a.reverse();let u=0;for(let l=0;l<a.length;l++)u+=a[l]<<l*7;c+=`.${u}`,a=[]}}return c}function Md(e,t){return t.offset++,null}function Fd(e,t){let r=kr(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 Vd(e,t){let r=kr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function $d(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new Rt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function hi(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=$d(e.byteLength);return new Rt(Uint8Array.from([t.byteLength|di]),t)}function Ct(e){let t=new Rt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new Rt(Uint8Array.from([2]),hi(t),t)}function vn(e){let t=Uint8Array.from([0]),r=new Rt(t,e);return new Rt(Uint8Array.from([3]),hi(r),r)}function ve(e,t=48){let r=new Rt;for(let n of e)r.append(n);return new Rt(Uint8Array.from([t]),hi(r),r)}async function Qa(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 qd=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Hd=Uint8Array.from([6,5,43,129,4,0,34]),zd=Uint8Array.from([6,5,43,129,4,0,35]),jd={ext:!0,kty:"EC",crv:"P-256"},Gd={ext:!0,kty:"EC",crv:"P-384"},Zd={ext:!0,kty:"EC",crv:"P-521"},pi=32,mi=48,yi=66;function gi(e){let t=ue(e);return tc(t)}function tc(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===pi*2+1)return n=z(t.subarray(r,r+pi),"base64url"),o=z(t.subarray(r+pi),"base64url"),new cr({...jd,key_ops:["verify"],x:n,y:o});if(t.byteLength===mi*2+1)return n=z(t.subarray(r,r+mi),"base64url"),o=z(t.subarray(r+mi),"base64url"),new cr({...Gd,key_ops:["verify"],x:n,y:o});if(t.byteLength===yi*2+1)return n=z(t.subarray(r,r+yi),"base64url"),o=z(t.subarray(r+yi),"base64url"),new cr({...Zd,key_ops:["verify"],x:n,y:o});throw new ot(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ec(e){return ve([Ct(Uint8Array.from([1])),ve([Yd(e.crv)],160),ve([vn(new Rt(Uint8Array.from([4]),q(e.x??"","base64url"),q(e.y??"","base64url")))],161)]).subarray()}function Yd(e){if(e==="P-256")return qd;if(e==="P-384")return Hd;if(e==="P-521")return zd;throw new ot(`Invalid curve ${e}`)}var cr=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=ec(this.jwk)),this._raw}toMultihash(){return vt.digest(ur(this))}toCID(){return j.createV1(114,this.toMultihash())}toString(){return X.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 Qa(this.jwk,r,t,n)}};function Oe(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function re(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=Oe(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 An(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");re(e.outputLen),re(e.blockLen)}function fr(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 nc(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 le(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function In(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function zt(e,t){return e<<32-t|e>>>t}var oc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Wd=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function de(e){if(H(e),oc)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Wd[e[r]];return t}var fe={_0:48,_9:57,A:65,F:70,a:97,f:102};function rc(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 he(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(oc)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=rc(e.charCodeAt(i)),c=rc(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 Bt(...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 xi(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 lr(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 bi=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ic(e,t,r){return e&t^~e&r}function sc(e,t,r){return e&t^e&r^t&r}var Kr=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=In(this.buffer)}update(t){fr(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=In(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){fr(this),nc(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,le(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=In(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=a/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)c.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||=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()}},pe=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var mt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Tn=BigInt(4294967295),ac=BigInt(32);function Xd(e,t=!1){return t?{h:Number(e&Tn),l:Number(e>>ac&Tn)}:{h:Number(e>>ac&Tn)|0,l:Number(e&Tn)|0}}function cc(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}=Xd(e[i],t);[n[i],o[i]]=[s,c]}return[n,o]}var wi=(e,t,r)=>e>>>r,Ei=(e,t,r)=>e<<32-r|t>>>r,ke=(e,t,r)=>e>>>r|t<<32-r,Ke=(e,t,r)=>e<<32-r|t>>>r,Mr=(e,t,r)=>e<<64-r|t>>>r-32,Fr=(e,t,r)=>e>>>r-32|t<<64-r;function ne(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var uc=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),fc=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,lc=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),dc=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,hc=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),pc=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;var Qd=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]),Ae=new Uint32Array(64),Si=class extends Kr{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)Ae[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let m=Ae[l-15],E=Ae[l-2],b=zt(m,7)^zt(m,18)^m>>>3,T=zt(E,17)^zt(E,19)^E>>>10;Ae[l]=T+Ae[l-7]+b+Ae[l-16]|0}let{A:n,B:o,C:i,D:s,E:c,F:a,G:f,H:u}=this;for(let l=0;l<64;l++){let m=zt(c,6)^zt(c,11)^zt(c,25),E=u+m+ic(c,a,f)+Qd[l]+Ae[l]|0,T=(zt(n,2)^zt(n,13)^zt(n,22))+sc(n,o,i)|0;u=f,f=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,f=f+this.G|0,u=u+this.H|0,this.set(n,o,i,s,c,a,f,u)}roundClean(){le(Ae)}destroy(){this.set(0,0,0,0,0,0,0,0),le(this.buffer)}},vi=class extends Si{A=pe[0]|0;B=pe[1]|0;C=pe[2]|0;D=pe[3]|0;E=pe[4]|0;F=pe[5]|0;G=pe[6]|0;H=pe[7]|0;constructor(){super(32)}};var mc=cc(["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))),th=mc[0],eh=mc[1],Ie=new Uint32Array(80),Te=new Uint32Array(80),Ai=class extends Kr{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:f,El:u,Fh:l,Fl:m,Gh:E,Gl:b,Hh:T,Hl:I}=this;return[t,r,n,o,i,s,c,a,f,u,l,m,E,b,T,I]}set(t,r,n,o,i,s,c,a,f,u,l,m,E,b,T,I){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=f|0,this.El=u|0,this.Fh=l|0,this.Fl=m|0,this.Gh=E|0,this.Gl=b|0,this.Hh=T|0,this.Hl=I|0}process(t,r){for(let v=0;v<16;v++,r+=4)Ie[v]=t.getUint32(r),Te[v]=t.getUint32(r+=4);for(let v=16;v<80;v++){let L=Ie[v-15]|0,k=Te[v-15]|0,F=ke(L,k,1)^ke(L,k,8)^wi(L,k,7),M=Ke(L,k,1)^Ke(L,k,8)^Ei(L,k,7),p=Ie[v-2]|0,y=Te[v-2]|0,_=ke(p,y,19)^Mr(p,y,61)^wi(p,y,6),D=Ke(p,y,19)^Fr(p,y,61)^Ei(p,y,6),A=lc(M,D,Te[v-7],Te[v-16]),g=dc(A,F,_,Ie[v-7],Ie[v-16]);Ie[v]=g|0,Te[v]=A|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:c,Cl:a,Dh:f,Dl:u,Eh:l,El:m,Fh:E,Fl:b,Gh:T,Gl:I,Hh:w,Hl:C}=this;for(let v=0;v<80;v++){let L=ke(l,m,14)^ke(l,m,18)^Mr(l,m,41),k=Ke(l,m,14)^Ke(l,m,18)^Fr(l,m,41),F=l&E^~l&T,M=m&b^~m&I,p=hc(C,k,M,eh[v],Te[v]),y=pc(p,w,L,F,th[v],Ie[v]),_=p|0,D=ke(n,o,28)^Mr(n,o,34)^Mr(n,o,39),A=Ke(n,o,28)^Fr(n,o,34)^Fr(n,o,39),g=n&i^n&c^i&c,x=o&s^o&a^s&a;w=T|0,C=I|0,T=E|0,I=b|0,E=l|0,b=m|0,{h:l,l:m}=ne(f|0,u|0,y|0,_|0),f=c|0,u=a|0,c=i|0,a=s|0,i=n|0,s=o|0;let d=uc(_,A,x);n=fc(d,y,D,g),o=d|0}({h:n,l:o}=ne(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=ne(this.Bh|0,this.Bl|0,i|0,s|0),{h:c,l:a}=ne(this.Ch|0,this.Cl|0,c|0,a|0),{h:f,l:u}=ne(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:m}=ne(this.Eh|0,this.El|0,l|0,m|0),{h:E,l:b}=ne(this.Fh|0,this.Fl|0,E|0,b|0),{h:T,l:I}=ne(this.Gh|0,this.Gl|0,T|0,I|0),{h:w,l:C}=ne(this.Hh|0,this.Hl|0,w|0,C|0),this.set(n,o,i,s,c,a,f,u,l,m,E,b,T,I,w,C)}roundClean(){le(Ie,Te)}destroy(){le(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Ii=class extends Ai{Ah=mt[0]|0;Al=mt[1]|0;Bh=mt[2]|0;Bl=mt[3]|0;Ch=mt[4]|0;Cl=mt[5]|0;Dh=mt[6]|0;Dl=mt[7]|0;Eh=mt[8]|0;El=mt[9]|0;Fh=mt[10]|0;Fl=mt[11]|0;Gh=mt[12]|0;Gl=mt[13]|0;Hh=mt[14]|0;Hl=mt[15]|0;constructor(){super(64)}};var dr=xi(()=>new vi,bi(1));var yc=xi(()=>new Ii,bi(3));var Ci=BigInt(0),Ti=BigInt(1);function me(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function gc(e){if(typeof e=="bigint"){if(!Cn(e))throw new Error("positive bigint expected, got "+e)}else re(e);return e}function Vr(e){let t=gc(e).toString(16);return t.length&1?"0"+t:t}function xc(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Ci:BigInt("0x"+e)}function hr(e){return xc(de(e))}function Me(e){return xc(de(_n(H(e)).reverse()))}function Bn(e,t){re(t),e=gc(e);let r=he(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function Bi(e,t){return Bn(e,t).reverse()}function _n(e){return Uint8Array.from(e)}var Cn=e=>typeof e=="bigint"&&Ci<=e;function rh(e,t,r){return Cn(e)&&Cn(t)&&Cn(r)&&t<=e&&e<r}function $r(e,t,r,n){if(!rh(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function _i(e){let t;for(t=0;e>Ci;e>>=Ti,t+=1);return t}var qr=e=>(Ti<<BigInt(e))-Ti;function bc(e,t,r){if(re(e,"hashLen"),re(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=I=>new Uint8Array(I),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),c=1e3,a=n(e),f=n(e),u=0,l=()=>{a.fill(1),f.fill(0),u=0},m=(...I)=>r(f,Bt(a,...I)),E=(I=o)=>{f=m(i,I),a=m(),I.length!==0&&(f=m(s,I),a=m())},b=()=>{if(u++>=c)throw new Error("drbg: tried max amount of iterations");let I=0,w=[];for(;I<t;){a=m();let C=a.slice();w.push(C),I+=a.length}return Bt(...w)};return(I,w)=>{l(),E(I);let C;for(;!(C=w(b()));)E();return l(),C}}function Ce(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 f=typeof a;if(f!==s||a===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${f}`)}let o=(i,s)=>Object.entries(i).forEach(([c,a])=>n(c,a,s));o(t,!1),o(r,!0)}function pr(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 At=BigInt(0),ut=BigInt(1),Fe=BigInt(2),Sc=BigInt(3),vc=BigInt(4),Ac=BigInt(5),nh=BigInt(7),Ic=BigInt(8),oh=BigInt(9),Tc=BigInt(16);function st(e,t){let r=e%t;return r>=At?r:t+r}function J(e,t,r){let n=e;for(;t-- >At;)n*=n,n%=r;return n}function wc(e,t){if(e===At)throw new Error("invert: expected non-zero number");if(t<=At)throw new Error("invert: expected positive modulus, got "+t);let r=st(e,t),n=t,o=At,i=ut,s=ut,c=At;for(;r!==At;){let f=n/r,u=n%r,l=o-s*f,m=i-c*f;n=r,r=u,o=s,i=c,s=l,c=m}if(n!==ut)throw new Error("invert: does not exist");return st(o,t)}function Ri(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Cc(e,t){let r=(e.ORDER+ut)/vc,n=e.pow(t,r);return Ri(e,n,t),n}function ih(e,t){let r=(e.ORDER-Ac)/Ic,n=e.mul(t,Fe),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,Fe),o),c=e.mul(i,e.sub(s,e.ONE));return Ri(e,c,t),c}function sh(e){let t=mr(e),r=Bc(e),n=r(t,t.neg(t.ONE)),o=r(t,n),i=r(t,t.neg(n)),s=(e+nh)/Tc;return(c,a)=>{let f=c.pow(a,s),u=c.mul(f,n),l=c.mul(f,o),m=c.mul(f,i),E=c.eql(c.sqr(u),a),b=c.eql(c.sqr(l),a);f=c.cmov(f,u,E),u=c.cmov(m,l,b);let T=c.eql(c.sqr(u),a),I=c.cmov(f,u,T);return Ri(c,I,a),I}}function Bc(e){if(e<Sc)throw new Error("sqrt is not defined for small field");let t=e-ut,r=0;for(;t%Fe===At;)t/=Fe,r++;let n=Fe,o=mr(e);for(;Ec(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Cc;let i=o.pow(n,t),s=(t+ut)/Fe;return function(a,f){if(a.is0(f))return f;if(Ec(a,f)!==1)throw new Error("Cannot find square root");let u=r,l=a.mul(a.ONE,i),m=a.pow(f,t),E=a.pow(f,s);for(;!a.eql(m,a.ONE);){if(a.is0(m))return a.ZERO;let b=1,T=a.sqr(m);for(;!a.eql(T,a.ONE);)if(b++,T=a.sqr(T),b===u)throw new Error("Cannot find square root");let I=ut<<BigInt(u-b-1),w=a.pow(l,I);u=b,l=a.sqr(w),m=a.mul(m,l),E=a.mul(E,w)}return E}}function ah(e){return e%vc===Sc?Cc:e%Ic===Ac?ih:e%Tc===oh?sh(e):Bc(e)}var _c=(e,t)=>(st(e,t)&ut)===ut,ch=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ni(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=ch.reduce((n,o)=>(n[o]="function",n),t);return Ce(e,r),e}function uh(e,t,r){if(r<At)throw new Error("invalid exponent, negatives unsupported");if(r===At)return e.ONE;if(r===ut)return t;let n=e.ONE,o=t;for(;r>At;)r&ut&&(n=e.mul(n,o)),o=e.sqr(o),r>>=ut;return n}function Hr(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 Ec(e,t){let r=(e.ORDER-ut)/Fe,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&&re(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var Di=class{ORDER;BITS;BYTES;isLE;ZERO=At;ONE=ut;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=At)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 st(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return At<=t&&t<this.ORDER}is0(t){return t===At}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&ut)===ut}neg(t){return st(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return st(t*t,this.ORDER)}add(t,r){return st(t+r,this.ORDER)}sub(t,r){return st(t-r,this.ORDER)}mul(t,r){return st(t*r,this.ORDER)}pow(t,r){return uh(this,t,r)}div(t,r){return st(t*wc(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 wc(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=ah(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?Bi(t,this.BYTES):Bn(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 f=new Uint8Array(o);f.set(t,i?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let a=i?Me(t):hr(t);if(c&&(a=st(a,s)),!r&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(t){return Hr(this,t)}cmov(t,r,n){return n?r:t}};function mr(e,t={}){return new Di(e,t)}function Dc(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 Pi(e){let t=Dc(e);return t+Math.ceil(t/2)}function Li(e,t,r=!1){H(e);let n=e.length,o=Dc(t),i=Pi(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Me(e):hr(e),c=st(s,t-ut)+ut;return r?Bi(c,o):Bn(c,o)}var yr=BigInt(0),Ve=BigInt(1);function zr(e,t){let r=t.negate();return e?r:t}function $e(e,t){let r=Hr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Lc(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Ui(e,t){Lc(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,i=qr(e),s=BigInt(e);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function Rc(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+=Ve);let f=t*n,u=f+Math.abs(c)-1,l=c===0,m=c<0,E=t%2!==0;return{nextN:a,offset:u,isZero:l,isNeg:m,isNegF:E,offsetF:f}}var Oi=new WeakMap,Uc=new WeakMap;function ki(e){return Uc.get(e)||1}function Nc(e){if(e!==yr)throw new Error("invalid wNAF")}var gr=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>yr;)r&Ve&&(n=n.add(o)),o=o.double(),r>>=Ve;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Ui(r,this.bits),i=[],s=t,c=s;for(let a=0;a<n;a++){c=s,i.push(c);for(let f=1;f<o;f++)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=Ui(t,this.bits);for(let c=0;c<s.windows;c++){let{nextN:a,offset:f,isZero:u,isNeg:l,isNegF:m,offsetF:E}=Rc(n,c,s);n=a,u?i=i.add(zr(m,r[E])):o=o.add(zr(l,r[f]))}return Nc(n),{p:o,f:i}}wNAFUnsafe(t,r,n,o=this.ZERO){let i=Ui(t,this.bits);for(let s=0;s<i.windows&&n!==yr;s++){let{nextN:c,offset:a,isZero:f,isNeg:u}=Rc(n,s,i);if(n=c,!f){let l=r[a];o=o.add(u?l.negate():l)}}return Nc(n),o}getPrecomputes(t,r,n){let o=Oi.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Oi.set(r,o))),o}cached(t,r,n){let o=ki(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let i=ki(t);return i===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,t,n),r,o)}createCache(t,r){Lc(r,this.bits),Uc.set(t,r),Oi.delete(t)}hasCache(t){return ki(t)!==1}};function Oc(e,t,r,n){let o=t,i=e.ZERO,s=e.ZERO;for(;r>yr||n>yr;)r&Ve&&(i=i.add(o)),n&Ve&&(s=s.add(o)),o=o.double(),r>>=Ve,n>>=Ve;return{p1:i,p2:s}}function Pc(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 mr(e,{isLE:r})}function Dn(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 f=t[a];if(!(typeof f=="bigint"&&f>yr))throw new Error(`CURVE.${a} must be positive bigint`)}let o=Pc(t.p,r.Fp,n),i=Pc(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 Rn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var Be=BigInt(0),ft=BigInt(1),Ki=BigInt(2),lh=BigInt(8);function dh(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 kc(e,t={}){let r=Dn("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s}=i;Ce(t,{},{uvRatio:"function"});let c=Ki<<BigInt(o.BYTES*8)-ft,a=I=>n.create(I),f=t.uvRatio||((I,w)=>{try{return{isValid:!0,value:n.sqrt(n.div(I,w))}}catch{return{isValid:!1,value:Be}}});if(!dh(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function u(I,w,C=!1){let v=C?ft:Be;return $r("coordinate "+I,w,v,c),w}function l(I){if(!(I instanceof b))throw new Error("EdwardsPoint expected")}let m=pr((I,w)=>{let{X:C,Y:v,Z:L}=I,k=I.is0();w==null&&(w=k?lh:n.inv(L));let F=a(C*w),M=a(v*w),p=n.mul(L,w);if(k)return{x:Be,y:ft};if(p!==ft)throw new Error("invZ was invalid");return{x:F,y:M}}),E=pr(I=>{let{a:w,d:C}=i;if(I.is0())throw new Error("bad point: ZERO");let{X:v,Y:L,Z:k,T:F}=I,M=a(v*v),p=a(L*L),y=a(k*k),_=a(y*y),D=a(M*w),A=a(y*a(D+p)),g=a(_+a(C*a(M*p)));if(A!==g)throw new Error("bad point: equation left != right (1)");let x=a(v*L),d=a(k*F);if(x!==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,C,v,L){this.X=u("x",w),this.Y=u("y",C),this.Z=u("z",v,!0),this.T=u("t",L),Object.freeze(this)}static CURVE(){return i}static fromAffine(w){if(w instanceof b)throw new Error("extended point not allowed");let{x:C,y:v}=w||{};return u("x",C),u("y",v),new b(C,v,ft,a(C*v))}static fromBytes(w,C=!1){let v=n.BYTES,{a:L,d:k}=i;w=_n(H(w,v,"point")),me(C,"zip215");let F=_n(w),M=w[v-1];F[v-1]=M&-129;let p=Me(F),y=C?c:n.ORDER;$r("point.y",p,Be,y);let _=a(p*p),D=a(_-ft),A=a(k*_-L),{isValid:g,value:x}=f(D,A);if(!g)throw new Error("bad point: invalid y coordinate");let d=(x&ft)===ft,S=(M&128)!==0;if(!C&&x===Be&&S)throw new Error("bad point: x=0 and x_0=1");return S!==d&&(x=a(-x)),b.fromAffine({x,y:p})}static fromHex(w,C=!1){return b.fromBytes(he(w),C)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(w=8,C=!0){return T.createCache(this,w),C||this.multiply(Ki),this}assertValidity(){E(this)}equals(w){l(w);let{X:C,Y:v,Z:L}=this,{X:k,Y:F,Z:M}=w,p=a(C*M),y=a(k*L),_=a(v*M),D=a(F*L);return p===y&&_===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:C,Y:v,Z:L}=this,k=a(C*C),F=a(v*v),M=a(Ki*a(L*L)),p=a(w*k),y=C+v,_=a(a(y*y)-k-F),D=p+F,A=D-M,g=p-F,x=a(_*A),d=a(D*g),S=a(_*g),R=a(A*D);return new b(x,d,R,S)}add(w){l(w);let{a:C,d:v}=i,{X:L,Y:k,Z:F,T:M}=this,{X:p,Y:y,Z:_,T:D}=w,A=a(L*p),g=a(k*y),x=a(M*v*D),d=a(F*_),S=a((L+k)*(p+y)-A-g),R=d-x,P=d+x,U=a(g-C*A),O=a(S*R),K=a(P*U),$=a(S*U),et=a(R*P);return new b(O,K,et,$)}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:C,f:v}=T.cached(this,w,L=>$e(b,L));return $e(b,[C,v])[0]}multiplyUnsafe(w,C=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=>$e(b,v),C)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return T.unsafe(this,i.n).is0()}toAffine(w){return m(this,w)}clearCofactor(){return s===ft?this:this.multiplyUnsafe(s)}toBytes(){let{x:w,y:C}=this.toAffine(),v=n.toBytes(C);return v[v.length-1]|=w&ft?128:0,v}toHex(){return de(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let T=new gr(b,o.BITS);return b.BASE.precompute(8),b}function Kc(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');Ce(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||lr,a=r.adjustScalarBytes||(p=>p),f=r.domain||((p,y,_)=>{if(me(_,"phflag"),y.length||_)throw new Error("Contexts/pre-hash are not supported");return p});function u(p){return s.create(Me(p))}function l(p){let y=v.secretKey;H(p,v.secretKey,"secretKey");let _=H(t(p),2*y,"hashedSecretKey"),D=a(_.slice(0,y)),A=_.slice(y,2*y),g=u(D);return{head:D,prefix:A,scalar:g}}function m(p){let{head:y,prefix:_,scalar:D}=l(p),A=o.multiply(D),g=A.toBytes();return{head:y,prefix:_,scalar:D,point:A,pointBytes:g}}function E(p){return m(p).pointBytes}function b(p=Uint8Array.of(),...y){let _=Bt(...y);return u(t(f(_,H(p,void 0,"context"),!!n)))}function T(p,y,_={}){p=H(p,void 0,"message"),n&&(p=n(p));let{prefix:D,scalar:A,pointBytes:g}=m(y),x=b(_.context,D,p),d=o.multiply(x).toBytes(),S=b(_.context,d,g,p),R=s.create(x+S*A);if(!s.isValid(R))throw new Error("sign failed: invalid s");let P=Bt(d,s.toBytes(R));return H(P,v.signature,"result")}let I={zip215:!0};function w(p,y,_,D=I){let{context:A,zip215:g}=D,x=v.signature;p=H(p,x,"signature"),y=H(y,void 0,"message"),_=H(_,v.publicKey,"publicKey"),g!==void 0&&me(g,"zip215"),n&&(y=n(y));let d=x/2,S=p.subarray(0,d),R=Me(p.subarray(d,x)),P,U,O;try{P=e.fromBytes(_,g),U=e.fromBytes(S,g),O=o.multiplyUnsafe(R)}catch{return!1}if(!g&&P.isSmallOrder())return!1;let K=b(A,U.toBytes(),P.toBytes(),y);return U.add(P.multiplyUnsafe(K)).subtract(O).clearCofactor().is0()}let C=i.BYTES,v={secretKey:C,publicKey:C,signature:2*C,seed:C};function L(p=c(v.seed)){return H(p,v.seed,"seed")}function k(p){return Oe(p)&&p.length===s.BYTES}function F(p,y){try{return!!e.fromBytes(p,y)}catch{return!1}}let M={getExtendedPublicKey:m,randomSecretKey:L,isValidSecretKey:k,isValidPublicKey:F,toMontgomery(p){let{y}=e.fromBytes(p),_=v.publicKey,D=_===32;if(!D&&_!==57)throw new Error("only defined for 25519 and 448");let A=D?i.div(ft+y,ft-y):i.div(y-ft,y+ft);return i.toBytes(A)},toMontgomerySecret(p){let y=v.secretKey;H(p,y);let _=t(p.subarray(0,y));return a(_).subarray(0,y)}};return Object.freeze({keygen:Rn(L,E),getPublicKey:E,sign:T,verify:w,utils:M,Point:e,lengths:v})}var hh=BigInt(1),Mc=BigInt(2);var ph=BigInt(5),mh=BigInt(8),Mi=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),yh={p:Mi,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:mh,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function gh(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=Mi,c=e*e%i*e%i,a=J(c,Mc,i)*c%i,f=J(a,hh,i)*e%i,u=J(f,ph,i)*f%i,l=J(u,t,i)*u%i,m=J(l,r,i)*l%i,E=J(m,n,i)*m%i,b=J(E,o,i)*E%i,T=J(b,o,i)*E%i,I=J(T,t,i)*u%i;return{pow_p_5_8:J(I,Mc,i)*e%i,b2:c}}function xh(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Fc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function bh(e,t){let r=Mi,n=st(t*t*t,r),o=st(n*n*t,r),i=gh(e*o).pow_p_5_8,s=st(e*n*i,r),c=st(t*s*s,r),a=s,f=st(s*Fc,r),u=c===e,l=c===st(-e,r),m=c===st(-e*Fc,r);return u&&(s=a),(l||m)&&(s=f),_c(s,r)&&(s=st(-s,r)),{isValid:u||l,value:s}}var wh=kc(yh,{uvRatio:bh});function Eh(e){return Kc(wh,yc,Object.assign({adjustScalarBytes:xh},e))}var Vc=Eh({});var jr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Nn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var $c={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Nn("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 Mt=$c;var Pn=32;var Fi,Sh=(async()=>{try{return await Mt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function vh(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Mt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Mt.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 Ah(e,t,r){return Vc.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function qc(e,t,r){return Fi==null&&(Fi=await Sh),Fi?vh(e,t,r):Ah(e,t,r)}function Ln(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Un=class{type="Ed25519";raw;constructor(t){this.raw=Vi(t,Pn)}toMultihash(){return vt.digest(ur(this))}toCID(){return j.createV1(114,this.toMultihash())}toString(){return X.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=qc(this.raw,r,t);return Ln(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}};function $i(e){return e=Vi(e,Pn),new Un(e)}function Vi(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new ot(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Th=Math.pow(2,7),Ch=Math.pow(2,14),Bh=Math.pow(2,21),qi=Math.pow(2,28),Hi=Math.pow(2,35),zi=Math.pow(2,42),ji=Math.pow(2,49),Q=128,xt=127;function _t(e){if(e<Th)return 1;if(e<Ch)return 2;if(e<Bh)return 3;if(e<qi)return 4;if(e<Hi)return 5;if(e<zi)return 6;if(e<ji)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function qe(e,t,r=0){switch(_t(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 Gr(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)*qi,r<Q)||(r=e[t+5],n+=(r&xt)*Hi,r<Q)||(r=e[t+6],n+=(r&xt)*zi,r<Q)||(r=e[t+7],n+=(r&xt)*ji,r<Q))return n;throw new RangeError("Could not decode varint")}function _h(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)*qi,r<Q)||(r=e.get(t+5),n+=(r&xt)*Hi,r<Q)||(r=e.get(t+6),n+=(r&xt)*zi,r<Q)||(r=e.get(t+7),n+=(r&xt)*ji,r<Q))return n;throw new RangeError("Could not decode varint")}function Gi(e,t=0){return e instanceof Uint8Array?Gr(e,t):_h(e,t)}var Zi=new Float32Array([-0]),_e=new Uint8Array(Zi.buffer);function zc(e,t,r){Zi[0]=e,t[r]=_e[0],t[r+1]=_e[1],t[r+2]=_e[2],t[r+3]=_e[3]}function jc(e,t){return _e[0]=e[t],_e[1]=e[t+1],_e[2]=e[t+2],_e[3]=e[t+3],Zi[0]}var Yi=new Float64Array([-0]),bt=new Uint8Array(Yi.buffer);function Gc(e,t,r){Yi[0]=e,t[r]=bt[0],t[r+1]=bt[1],t[r+2]=bt[2],t[r+3]=bt[3],t[r+4]=bt[4],t[r+5]=bt[5],t[r+6]=bt[6],t[r+7]=bt[7]}function Zc(e,t){return bt[0]=e[t],bt[1]=e[t+1],bt[2]=e[t+2],bt[3]=e[t+3],bt[4]=e[t+4],bt[5]=e[t+5],bt[6]=e[t+6],bt[7]=e[t+7],Yi[0]}var Rh=BigInt(Number.MAX_SAFE_INTEGER),Nh=BigInt(Number.MIN_SAFE_INTEGER),Nt=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 He;if(t<Rh&&t>Nh)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>Yc&&(o=0n,++n>Yc&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return He;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):He}},He=new Nt(0,0);He.toBigInt=function(){return 0n};He.zzEncode=He.zzDecode=function(){return this};He.length=function(){return 1};var Yc=4294967296n;function Wc(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 Xc(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 Wi(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 jt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function On(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Xi=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,jt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw jt(this,4);return On(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw jt(this,4);return On(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw jt(this,4);let t=jc(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw jt(this,4);let t=Zc(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 jt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Xc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw jt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw jt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Nt(0,0),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 jt(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 jt(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 jt(this,8);let t=On(this.buf,this.pos+=4),r=On(this.buf,this.pos+=4);return new Nt(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=Gr(this.buf,this.pos);return this.pos+=_t(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 Zr(e){return new Xi(e instanceof Uint8Array?e:e.subarray())}function kn(e,t,r){let n=Zr(e);return t.decode(n,void 0,r)}function Ji(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return ct(s);o+s>t&&(n=ct(t),o=0);let c=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),c}}var ze=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Qi(){}var es=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Ph=Ji();function Lh(e){return globalThis.Buffer!=null?ct(e):Ph(e)}var Wr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ze(Qi,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 rs((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(Kn,10,Nt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Nt.fromBigInt(t);return this._push(Kn,r.length(),r)}uint64Number(t){return this._push(qe,_t(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=Nt.fromBigInt(t).zzEncode();return this._push(Kn,r.length(),r)}sint64Number(t){let r=Nt.fromNumber(t).zzEncode();return this._push(Kn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ts,1,t?1:0)}fixed32(t){return this._push(Yr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Nt.fromBigInt(t);return this._push(Yr,4,r.lo)._push(Yr,4,r.hi)}fixed64Number(t){let r=Nt.fromNumber(t);return this._push(Yr,4,r.lo)._push(Yr,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(zc,4,t)}double(t){return this._push(Gc,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(ts,1,0):this.uint32(r)._push(Oh,r,t)}string(t){let r=Wc(t);return r!==0?this.uint32(r)._push(Wi,r,t):this._push(ts,1,0)}fork(){return this.states=new es(this),this.head=this.tail=new ze(Qi,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(Qi,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=Lh(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function ts(e,t,r){t[r]=e&255}function Uh(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var rs=class extends ze{next;constructor(t,r){super(Uh,t,r),this.next=void 0}};function Kn(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 Yr(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 Oh(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Wr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(kh,t,e),this},Wr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Kh,t,e),this});function kh(e,t,r){t.set(e,r)}function Kh(e,t,r){e.length<40?Wi(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(q(e),r)}function ns(){return new Wr}function Mn(e,t){let r=ns();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Fn(e,t,r){let n=Zr(e);yield*t.stream(n,void 0,"$",r)}var Vn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function $n(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function os(e){function t(i){if(e[i.toString()]==null)throw new Error("Invalid enum value");return e[i]}let r=function(s,c){let a=t(s);c.int32(a)},n=function(s){let c=s.int32();return t(c)},o=function*(s){let c=s.int32();yield t(c)};return $n("enum",Vn.VARINT,r,n,o)}function qn(e,t,r){return $n("message",Vn.LENGTH_DELIMITED,e,t,r)}var tt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(tt||(tt={}));var is;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(is||(is={}));(function(e){e.codec=()=>os(is)})(tt||(tt={}));var oe;(function(e){let t;e.codec=()=>(t==null&&(t=qn((i,s,c={})=>{c.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),tt.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),c.lengthDelimited!==!1&&s.ldelim()},(i,s,c={})=>{let a={},f=s==null?i.len:i.pos+s;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{a.Type=tt.codec().decode(i);break}case 2:{a.Data=i.bytes();break}default:{i.skipType(u&7);break}}}return a},function*(i,s,c,a={}){let f=s==null?i.len:i.pos+s;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{yield{field:`${c}.Type`,value:tt.codec().decode(i)};break}case 2:{yield{field:`${c}.Data`,value:i.bytes()};break}default:{i.skipType(u&7);break}}}})),t);function r(i){return Mn(i,e.codec())}e.encode=r;function n(i,s){return kn(i,e.codec(),s)}e.decode=n;function o(i,s){return Fn(i,e.codec(),s)}e.stream=o})(oe||(oe={}));var ss;(function(e){let t;e.codec=()=>(t==null&&(t=qn((i,s,c={})=>{c.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),tt.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),c.lengthDelimited!==!1&&s.ldelim()},(i,s,c={})=>{let a={},f=s==null?i.len:i.pos+s;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{a.Type=tt.codec().decode(i);break}case 2:{a.Data=i.bytes();break}default:{i.skipType(u&7);break}}}return a},function*(i,s,c,a={}){let f=s==null?i.len:i.pos+s;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{yield{field:`${c}.Type`,value:tt.codec().decode(i)};break}case 2:{yield{field:`${c}.Data`,value:i.bytes()};break}default:{i.skipType(u&7);break}}}})),t);function r(i){return Mn(i,e.codec())}e.encode=r;function n(i,s){return kn(i,e.codec(),s)}e.decode=n;function o(i,s){return Fn(i,e.codec(),s)}e.stream=o})(ss||(ss={}));var Jr={};St(Jr,{MAX_RSA_KEY_SIZE:()=>as,generateRSAKeyPair:()=>nu,jwkToJWKKeyPair:()=>ou,jwkToPkcs1:()=>$h,jwkToPkix:()=>ls,jwkToRSAPrivateKey:()=>ms,pkcs1MessageToJwk:()=>us,pkcs1MessageToRSAPrivateKey:()=>ds,pkcs1ToJwk:()=>Vh,pkcs1ToRSAPrivateKey:()=>ru,pkixMessageToJwk:()=>fs,pkixMessageToRSAPublicKey:()=>ps,pkixToJwk:()=>qh,pkixToRSAPublicKey:()=>hs});var xr=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Jr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return j.createV1(114,this._multihash)}toString(){return X.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 eu(this.jwk,r,t,n)}},Xr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Jr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Y(this.raw,t.raw)}sign(t,r){return tu(this.jwk,t,r)}};var as=8192,cs=18,Mh=1062,Fh=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Vh(e){let t=ue(e);return us(t)}function us(e){return{n:z(e[1],"base64url"),e:z(e[2],"base64url"),d:z(e[3],"base64url"),p:z(e[4],"base64url"),q:z(e[5],"base64url"),dp:z(e[6],"base64url"),dq:z(e[7],"base64url"),qi:z(e[8],"base64url"),kty:"RSA"}}function $h(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new ot("JWK was missing components");return ve([Ct(Uint8Array.from([0])),Ct(q(e.n,"base64url")),Ct(q(e.e,"base64url")),Ct(q(e.d,"base64url")),Ct(q(e.p,"base64url")),Ct(q(e.q,"base64url")),Ct(q(e.dp,"base64url")),Ct(q(e.dq,"base64url")),Ct(q(e.qi,"base64url"))]).subarray()}function qh(e){let t=ue(e,{offset:0});return fs(t)}function fs(e){let t=ue(e[1],{offset:0});return{kty:"RSA",n:z(t[0],"base64url"),e:z(t[1],"base64url")}}function ls(e){if(e.n==null||e.e==null)throw new ot("JWK was missing components");return ve([Fh,vn(ve([Ct(q(e.n,"base64url")),Ct(q(e.e,"base64url"))]))]).subarray()}function ru(e){let t=ue(e);return ds(t)}function ds(e){let t=us(e);return ms(t)}function hs(e,t){if(e.byteLength>=Mh)throw new tr("Key size is too large");let r=ue(e,{offset:0});return ps(r,e,t)}function ps(e,t,r){let n=fs(e);if(r==null){let o=dr(oe.encode({Type:tt.RSA,Data:t}));r=Ht(cs,o)}return new xr(n,r)}function ms(e){if(su(e)>as)throw new ot("Key size is too large");let t=ou(e),r=dr(oe.encode({Type:tt.RSA,Data:ls(t.publicKey)})),n=Ht(cs,r);return new Xr(t.privateKey,new xr(t.publicKey,n))}async function nu(e){if(e>as)throw new ot("Key size is too large");let t=await iu(e),r=dr(oe.encode({Type:tt.RSA,Data:ls(t.publicKey)})),n=Ht(cs,r);return new Xr(t.privateKey,new xr(t.publicKey,n))}function ou(e){if(e==null)throw new ot("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function iu(e,t){let r=await Mt.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 Hh(r,t);return{privateKey:n[0],publicKey:n[1]}}async function tu(e,t,r){let n=await Mt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Mt.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 eu(e,t,r,n){let o=await Mt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Mt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),i}async function Hh(e,t){if(e.privateKey==null||e.publicKey==null)throw new ot("Private and public key are required");let r=await Promise.all([Mt.get().subtle.exportKey("jwk",e.privateKey),Mt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function su(e){if(e.kty!=="RSA")throw new ot("invalid key type");if(e.n==null)throw new ot("invalid key modulus");return q(e.n,"base64url").length*8}var Hn=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(An(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),le(o)}update(t){return fr(this),this.iHash.update(t),this}digestInto(t){fr(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()}},ys=(e,t,r)=>new Hn(e,t).update(r).digest();ys.create=(e,t)=>new Hn(e,t);var au=(e,t)=>(e+(e>=0?t:-t)/cu)/t;function zh(e,t,r){let[[n,o],[i,s]]=t,c=au(s*e,r),a=au(-o*e,r),f=e-c*n-a*i,u=-c*o-a*s,l=f<ye,m=u<ye;l&&(f=-f),m&&(u=-u);let E=qr(Math.ceil(_i(r)/2))+br;if(f<ye||f>=E||u<ye||u>=E)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:f,k2neg:m,k2:u}}function xs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function gs(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return me(r.lowS,"lowS"),me(r.prehash,"prehash"),r.format!==void 0&&xs(r.format),r}var bs=class extends Error{constructor(t=""){super(t)}},De={Err:bs,_tlv:{encode:(e,t)=>{let{Err:r}=De;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=Vr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?Vr(o.length/2|128):"";return Vr(e)+i+o+t},decode(e,t){let{Err:r}=De,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 f=t.subarray(n,n+a);if(f.length!==a)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+=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}=De;if(e<ye)throw new t("integer: negative integers are not allowed");let r=Vr(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}=De;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 hr(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=De,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:f,l:u}=n.decode(2,a);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=De,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),i=n+o;return t.encode(48,i)}},ye=BigInt(0),br=BigInt(1),cu=BigInt(2),zn=BigInt(3),jh=BigInt(4);function uu(e,t={}){let r=Dn("weierstrass",e,t),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s,n:c}=i;Ce(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 f=lu(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(A,g,x){let{x:d,y:S}=g.toAffine(),R=n.toBytes(d);if(me(x,"isCompressed"),x){u();let P=!n.isOdd(S);return Bt(fu(P),R)}else return Bt(Uint8Array.of(4),R,n.toBytes(S))}function m(A){H(A,void 0,"Point");let{publicKey:g,publicKeyUncompressed:x}=f,d=A.length,S=A[0],R=A.subarray(1);if(d===g&&(S===2||S===3)){let P=n.fromBytes(R);if(!n.isValid(P))throw new Error("bad point: is not on curve, wrong x");let U=T(P),O;try{O=n.sqrt(U)}catch(et){let W=et instanceof Error?": "+et.message:"";throw new Error("bad point: is not on curve, sqrt error"+W)}u();let K=n.isOdd(O);return(S&1)===1!==K&&(O=n.neg(O)),{x:P,y:O}}else if(d===x&&S===4){let P=n.BYTES,U=n.fromBytes(R.subarray(0,P)),O=n.fromBytes(R.subarray(P,P*2));if(!I(U,O))throw new Error("bad point: is not on curve");return{x:U,y:O}}else throw new Error(`bad point: got length ${d}, expected compressed=${g} or uncompressed=${x}`)}let E=t.toBytes||l,b=t.fromBytes||m;function T(A){let g=n.sqr(A),x=n.mul(g,A);return n.add(n.add(x,n.mul(A,i.a)),i.b)}function I(A,g){let x=n.sqr(g),d=T(A);return n.eql(x,d)}if(!I(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let w=n.mul(n.pow(i.a,zn),jh),C=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(w,C)))throw new Error("bad curve params: a or b");function v(A,g,x=!1){if(!n.isValid(g)||x&&n.is0(g))throw new Error(`bad point coordinate ${A}`);return g}function L(A){if(!(A instanceof y))throw new Error("Weierstrass Point expected")}function k(A){if(!a||!a.basises)throw new Error("no endo");return zh(A,a.basises,o.ORDER)}let F=pr((A,g)=>{let{X:x,Y:d,Z:S}=A;if(n.eql(S,n.ONE))return{x,y:d};let R=A.is0();g==null&&(g=R?n.ONE:n.inv(S));let P=n.mul(x,g),U=n.mul(d,g),O=n.mul(S,g);if(R)return{x:n.ZERO,y:n.ZERO};if(!n.eql(O,n.ONE))throw new Error("invZ was invalid");return{x:P,y:U}}),M=pr(A=>{if(A.is0()){if(t.allowInfinityPoint&&!n.is0(A.Y))return;throw new Error("bad point: ZERO")}let{x:g,y:x}=A.toAffine();if(!n.isValid(g)||!n.isValid(x))throw new Error("bad point: x or y not field elements");if(!I(g,x))throw new Error("bad point: equation left != right");if(!A.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function p(A,g,x,d,S){return x=new y(n.mul(x.X,A),x.Y,x.Z),g=zr(d,g),x=zr(S,x),g.add(x)}class y{static BASE=new y(i.Gx,i.Gy,n.ONE);static ZERO=new y(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(g,x,d){this.X=v("x",g),this.Y=v("y",x,!0),this.Z=v("z",d),Object.freeze(this)}static CURVE(){return i}static fromAffine(g){let{x,y:d}=g||{};if(!g||!n.isValid(x)||!n.isValid(d))throw new Error("invalid affine point");if(g instanceof y)throw new Error("projective point not allowed");return n.is0(x)&&n.is0(d)?y.ZERO:new y(x,d,n.ONE)}static fromBytes(g){let x=y.fromAffine(b(H(g,void 0,"point")));return x.assertValidity(),x}static fromHex(g){return y.fromBytes(he(g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,x=!0){return D.createCache(this,g),x||this.multiply(zn),this}assertValidity(){M(this)}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){L(g);let{X:x,Y:d,Z:S}=this,{X:R,Y:P,Z:U}=g,O=n.eql(n.mul(x,U),n.mul(R,S)),K=n.eql(n.mul(d,U),n.mul(P,S));return O&&K}negate(){return new y(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b:x}=i,d=n.mul(x,zn),{X:S,Y:R,Z:P}=this,U=n.ZERO,O=n.ZERO,K=n.ZERO,$=n.mul(S,S),et=n.mul(R,R),W=n.mul(P,P),G=n.mul(S,R);return G=n.add(G,G),K=n.mul(S,P),K=n.add(K,K),U=n.mul(g,K),O=n.mul(d,W),O=n.add(U,O),U=n.sub(et,O),O=n.add(et,O),O=n.mul(U,O),U=n.mul(G,U),K=n.mul(d,K),W=n.mul(g,W),G=n.sub($,W),G=n.mul(g,G),G=n.add(G,K),K=n.add($,$),$=n.add(K,$),$=n.add($,W),$=n.mul($,G),O=n.add(O,$),W=n.mul(R,P),W=n.add(W,W),$=n.mul(W,G),U=n.sub(U,$),K=n.mul(W,et),K=n.add(K,K),K=n.add(K,K),new y(U,O,K)}add(g){L(g);let{X:x,Y:d,Z:S}=this,{X:R,Y:P,Z:U}=g,O=n.ZERO,K=n.ZERO,$=n.ZERO,et=i.a,W=n.mul(i.b,zn),G=n.mul(x,R),rt=n.mul(d,P),pt=n.mul(S,U),Qt=n.add(x,d),nt=n.add(R,P);Qt=n.mul(Qt,nt),nt=n.add(G,rt),Qt=n.sub(Qt,nt),nt=n.add(x,S);let gt=n.add(R,U);return nt=n.mul(nt,gt),gt=n.add(G,pt),nt=n.sub(nt,gt),gt=n.add(d,S),O=n.add(P,U),gt=n.mul(gt,O),O=n.add(rt,pt),gt=n.sub(gt,O),$=n.mul(et,nt),O=n.mul(W,pt),$=n.add(O,$),O=n.sub(rt,$),$=n.add(rt,$),K=n.mul(O,$),rt=n.add(G,G),rt=n.add(rt,G),pt=n.mul(et,pt),nt=n.mul(W,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),K=n.add(K,G),G=n.mul(gt,nt),O=n.mul(Qt,O),O=n.sub(O,G),G=n.mul(Qt,rt),$=n.mul(gt,$),$=n.add($,G),new y(O,K,$)}subtract(g){return this.add(g.negate())}is0(){return this.equals(y.ZERO)}multiply(g){let{endo:x}=t;if(!o.isValidNot0(g))throw new Error("invalid scalar: out of range");let d,S,R=P=>D.cached(this,P,U=>$e(y,U));if(x){let{k1neg:P,k1:U,k2neg:O,k2:K}=k(g),{p:$,f:et}=R(U),{p:W,f:G}=R(K);S=et.add(G),d=p(x.beta,$,W,P,O)}else{let{p:P,f:U}=R(g);d=P,S=U}return $e(y,[d,S])[0]}multiplyUnsafe(g){let{endo:x}=t,d=this;if(!o.isValid(g))throw new Error("invalid scalar: out of range");if(g===ye||d.is0())return y.ZERO;if(g===br)return d;if(D.hasCache(this))return this.multiply(g);if(x){let{k1neg:S,k1:R,k2neg:P,k2:U}=k(g),{p1:O,p2:K}=Oc(y,d,R,U);return p(x.beta,O,K,S,P)}else return D.unsafe(d,g)}toAffine(g){return F(this,g)}isTorsionFree(){let{isTorsionFree:g}=t;return s===br?!0:g?g(y,this):D.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:g}=t;return s===br?this:g?g(y,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(g=!0){return me(g,"isCompressed"),this.assertValidity(),E(y,this,g)}toHex(g=!0){return de(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let _=o.BITS,D=new gr(y,t.endo?Math.ceil(_/2):_);return y.BASE.precompute(8),y}function fu(e){return Uint8Array.of(e?2:3)}function lu(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Gh(e,t={}){let{Fn:r}=e,n=t.randomBytes||lr,o=Object.assign(lu(e.Fp,r),{seed:Pi(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:I}=o;try{let w=E.length;return b===!0&&w!==T||b===!1&&w!==I?!1:!!e.fromBytes(E)}catch{return!1}}function c(E=n(o.seed)){return Li(H(E,o.seed,"seed"),r.ORDER)}function a(E,b=!0){return e.BASE.multiply(r.fromBytes(E)).toBytes(b)}function f(E){let{secretKey:b,publicKey:T,publicKeyUncompressed:I}=o;if(!Oe(E)||"_lengths"in r&&r._lengths||b===T)return;let w=H(E,void 0,"key").length;return w===T||w===I}function u(E,b,T=!0){if(f(E)===!0)throw new Error("first arg must be private key");if(f(b)===!1)throw new Error("second arg must be public key");let I=r.fromBytes(E);return e.fromBytes(b).multiply(I).toBytes(T)}let l={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:c},m=Rn(c,a);return Object.freeze({getPublicKey:a,getSharedSecret:u,keygen:m,Point:e,utils:l,lengths:o})}function du(e,t,r={}){An(t),Ce(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||lr,o=r.hmac||((x,d)=>ys(t,x,d)),{Fp:i,Fn:s}=e,{ORDER:c,BITS:a}=s,{keygen:f,getPublicKey:u,getSharedSecret:l,utils:m,lengths:E}=Gh(e,r),b={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},T=c*cu<i.ORDER;function I(x){let d=c>>br;return x>d}function w(x,d){if(!s.isValidNot0(d))throw new Error(`invalid signature ${x}: out of range 1..Point.Fn.ORDER`);return d}function C(){if(T)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function v(x,d){xs(d);let S=E.signature,R=d==="compact"?S:d==="recovered"?S+1:void 0;return H(x,R)}class L{r;s;recovery;constructor(d,S,R){if(this.r=w("r",d),this.s=w("s",S),R!=null){if(C(),![0,1,2,3].includes(R))throw new Error("invalid recovery id");this.recovery=R}Object.freeze(this)}static fromBytes(d,S=b.format){v(d,S);let R;if(S==="der"){let{r:K,s:$}=De.toSig(H(d));return new L(K,$)}S==="recovered"&&(R=d[0],S="compact",d=d.subarray(1));let P=E.signature/2,U=d.subarray(0,P),O=d.subarray(P,P*2);return new L(s.fromBytes(U),s.fromBytes(O),R)}static fromHex(d,S){return this.fromBytes(he(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 L(this.r,this.s,d)}recoverPublicKey(d){let{r:S,s:R}=this,P=this.assertRecovery(),U=P===2||P===3?S+c:S;if(!i.isValid(U))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let O=i.toBytes(U),K=e.fromBytes(Bt(fu((P&1)===0),O)),$=s.inv(U),et=F(H(d,void 0,"msgHash")),W=s.create(-et*$),G=s.create(R*$),rt=e.BASE.multiplyUnsafe(W).add(K.multiplyUnsafe(G));if(rt.is0())throw new Error("invalid recovery: point at infinify");return rt.assertValidity(),rt}hasHighS(){return I(this.s)}toBytes(d=b.format){if(xs(d),d==="der")return he(De.hexFromSig(this));let{r:S,s:R}=this,P=s.toBytes(S),U=s.toBytes(R);return d==="recovered"?(C(),Bt(Uint8Array.of(this.assertRecovery()),P,U)):Bt(P,U)}toHex(d){return de(this.toBytes(d))}}let k=r.bits2int||function(d){if(d.length>8192)throw new Error("input is too large");let S=hr(d),R=d.length*8-a;return R>0?S>>BigInt(R):S},F=r.bits2int_modN||function(d){return s.create(k(d))},M=qr(a);function p(x){return $r("num < 2^"+a,x,ye,M),s.toBytes(x)}function y(x,d){return H(x,void 0,"message"),d?H(t(x),void 0,"prehashed message"):x}function _(x,d,S){let{lowS:R,prehash:P,extraEntropy:U}=gs(S,b);x=y(x,P);let O=F(x),K=s.fromBytes(d);if(!s.isValidNot0(K))throw new Error("invalid private key");let $=[p(K),p(O)];if(U!=null&&U!==!1){let rt=U===!0?n(E.secretKey):U;$.push(H(rt,void 0,"extraEntropy"))}let et=Bt(...$),W=O;function G(rt){let pt=k(rt);if(!s.isValidNot0(pt))return;let Qt=s.inv(pt),nt=e.BASE.multiply(pt).toAffine(),gt=s.create(nt.x);if(gt===ye)return;let gn=s.create(Qt*s.create(W+gt*K));if(gn===ye)return;let Ea=(nt.x===gt?0:2)|Number(nt.y&br),Sa=gn;return R&&I(gn)&&(Sa=s.neg(gn),Ea^=1),new L(gt,Sa,T?void 0:Ea)}return{seed:et,k2sig:G}}function D(x,d,S={}){let{seed:R,k2sig:P}=_(x,d,S);return bc(t.outputLen,s.BYTES,o)(R,P).toBytes(S.format)}function A(x,d,S,R={}){let{lowS:P,prehash:U,format:O}=gs(R,b);if(S=H(S,void 0,"publicKey"),d=y(d,U),!Oe(x)){let K=x instanceof L?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+K)}v(x,O);try{let K=L.fromBytes(x,O),$=e.fromBytes(S);if(P&&K.hasHighS())return!1;let{r:et,s:W}=K,G=F(d),rt=s.inv(W),pt=s.create(G*rt),Qt=s.create(et*rt),nt=e.BASE.multiplyUnsafe(pt).add($.multiplyUnsafe(Qt));return nt.is0()?!1:s.create(nt.x)===et}catch{return!1}}function g(x,d,S={}){let{prehash:R}=gs(S,b);return d=y(d,R),L.fromBytes(x,"recovered").recoverPublicKey(d).toBytes()}return Object.freeze({keygen:f,getPublicKey:u,getSharedSecret:l,utils:m,lengths:E,Point:e,sign:D,verify:A,recoverPublicKey:g,Signature:L,hash:t})}var Es={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Zh={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var hu=BigInt(2);function Yh(e){let t=Es.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),f=e*e*e%t,u=f*f*e%t,l=J(u,r,t)*u%t,m=J(l,r,t)*u%t,E=J(m,hu,t)*f%t,b=J(E,o,t)*E%t,T=J(b,i,t)*b%t,I=J(T,c,t)*T%t,w=J(I,a,t)*I%t,C=J(w,c,t)*T%t,v=J(C,r,t)*u%t,L=J(v,s,t)*b%t,k=J(L,n,t)*f%t,F=J(k,hu,t);if(!ws.eql(ws.sqr(F),e))throw new Error("Cannot find square root");return F}var ws=mr(Es.p,{sqrt:Yh}),Wh=uu(Es,{Fp:ws,endo:Zh}),wr=du(Wh,dr);function pu(e,t,r,n){let o=Lr.digest(r instanceof Uint8Array?r:r.subarray());if(Ln(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),wr.verify(t,i,e,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new jr(String(i))});try{return n?.signal?.throwIfAborted(),wr.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(i){throw new jr(String(i))}}var jn=class{type="secp256k1";raw;_key;constructor(t){this._key=yu(t),this.raw=mu(this._key)}toMultihash(){return vt.digest(ur(this))}toCID(){return j.createV1(114,this.toMultihash())}toString(){return X.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 pu(this._key,r,t,n)}};function Ss(e){return new jn(e)}function mu(e){return wr.Point.fromBytes(e).toBytes()}function yu(e){try{return wr.Point.fromBytes(e),e}catch(t){throw new tr(String(t))}}function gu(e,t){let{Type:r,Data:n}=oe.decode(e),o=n??new Uint8Array;switch(r){case tt.RSA:return hs(o,t);case tt.Ed25519:return $i(o);case tt.secp256k1:return Ss(o);case tt.ECDSA:return gi(o);default:throw new rr}}function Gn(e){let{Type:t,Data:r}=oe.decode(e.digest),n=r??new Uint8Array;switch(t){case tt.Ed25519:return $i(n);case tt.secp256k1:return Ss(n);case tt.ECDSA:return gi(n);default:throw new rr}}function ur(e){return oe.encode({Type:tt[e.type],Data:e.raw})}var xu=Symbol.for("nodejs.util.inspect.custom"),Xh=114,Qr=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()})`}[wn]=!0;toString(){return this.string==null&&(this.string=X.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return j.createV1(Xh,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")}[xu](){return`PeerId(${this.toString()})`}},Zn=class extends Qr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Yn=class extends Qr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Wn=class extends Qr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Jh=2336,tn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=vt.digest(q(this.url))}[xu](){return`PeerId(${this.url})`}[wn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return j.createV1(Jh,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};var Qh=114,bu=2336;function wu(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=Se(X.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return vs(j.parse(e));if(t==null)throw new ot('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=Se(t.decode(e))}return Xn(r)}function Xn(e){if(ep(e))return new Zn({multihash:e});if(tp(e))try{let t=Gn(e);if(t.type==="Ed25519")return new Yn({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Wn({multihash:e,publicKey:t})}catch{let r=z(e.digest);return new tn(new URL(r))}throw new er("Supplied PeerID Multihash is invalid")}function vs(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Qh&&e.code!==bu)throw new bn("Supplied PeerID CID is invalid");if(e.code===bu){let t=z(e.multihash.digest);return new tn(new URL(t))}return Xn(e.multihash)}function tp(e){return e.code===vt.code}function ep(e){return e.code===Lr.code}var yt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},ge=class extends Error{static name="ValidationError";name="ValidationError"},Jn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Qn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var to=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",f=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let m=Number.parseInt(l,t);if(!Number.isNaN(m))return m});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&&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 rp=45,np=15,eo=new to;function Eu(e){if(!(e.length>np))return eo.new(e).parseWith(()=>eo.readIPv4Addr())}function Su(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>rp))return eo.new(e).parseWith(()=>eo.readIPv6Addr())}function ro(e){return!!Eu(e)}function vu(e){return!!Su(e)}function Is(e){return t=>z(t,e)}function Ts(e){return t=>q(t,e)}function Er(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function je(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function Au(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=je(n);return Kt([r,o],r.length+o.length)}function Iu(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=te.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=je(n);return Kt([r,o],r.length+o.length)}function Cs(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=z(t,"base32"),o=Er(r);return`${n}:${o}`}var Bs=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 yt("Invalid byte value in IP address");t[n]=o}),t},Tu=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let i=ro(r[n]),s;i&&(s=Bs(r[n]),r[n]=z(s.subarray(0,2),"base16")),s!=null&&++n<8&&r.splice(n,0,z(s.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let i=[n,1];for(n=9-r.length;n>0;n--)i.push("0");r.splice.apply(r,i)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let i=parseInt(r[n],16);if(isNaN(i)||i<0||i>65535)throw new yt("Invalid byte value in IP address");o[t++]=i>>8&255,o[t++]=i&255}return o},Cu=function(e){if(e.byteLength!==4)throw new yt("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Bu=function(e){if(e.byteLength!==16)throw new yt("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 yt(`Invalid IPv6 address "${r}"`)}};function _u(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new yt(`Invalid IPv6 address "${e}"`)}}var As=Object.values(Ur).map(e=>e.decoder),op=(function(){let e=As[0].or(As[1]);return As.slice(2).forEach(t=>e=e.or(t)),e})();function Du(e){return op.decode(e)}function Ru(e){return t=>e.encoder.encode(t)}function ip(e){if(parseInt(e).toString()!==e)throw new ge("Value must be an integer")}function sp(e){if(e<0)throw new ge("Value must be a positive integer, or zero")}function ap(e){return t=>{if(t>e)throw new ge(`Value must be smaller than or equal to ${e}`)}}function cp(...e){return t=>{for(let r of e)r(t)}}var en=cp(ip,sp,ap(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 Qn(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},xe=new _s,Yp=[{code:4,name:"ip4",size:32,valueToBytes:Bs,bytesToValue:Cu,validate:e=>{if(!ro(e))throw new ge(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:je,bytesToValue:Er,validate:en},{code:273,name:"udp",size:16,valueToBytes:je,bytesToValue:Er,validate:en},{code:33,name:"dccp",size:16,valueToBytes:je,bytesToValue:Er,validate:en},{code:41,name:"ip6",size:128,valueToBytes:Tu,bytesToValue:Bu,stringToValue:_u,validate:e=>{if(!vu(e))throw new ge(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:lt},{code:43,name:"ipcidr",size:8,bytesToValue:Is("base10"),valueToBytes:Ts("base10")},{code:53,name:"dns",size:lt},{code:54,name:"dns4",size:lt},{code:55,name:"dns6",size:lt},{code:56,name:"dnsaddr",size:lt},{code:132,name:"sctp",size:16,valueToBytes:je,bytesToValue:Er,validate:en},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:lt,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:lt,bytesToValue:Is("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Ts("base58btc")(e):j.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Cs,valueToBytes:Au},{code:445,name:"onion3",size:296,bytesToValue:Cs,valueToBytes:Iu},{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:Ru(oi),valueToBytes:Du},{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=>{xe.addProtocol(e)});function Nu(e){let t=[],r=0;for(;r<e.length;){let n=Gi(e,r),o=xe.getProtocol(n),i=_t(n),s=Wp(o,e,r+i),c=0;s>0&&o.size===lt&&(c=_t(s));let a=i+c+s,f={code:n,name:o.name,bytes:e.subarray(r,r+a)};if(s>0){let u=r+i+c,l=e.subarray(u,u+s);f.value=o.bytesToValue?.(l)??z(l)}t.push(f),r+=a}return t}function Pu(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=xe.getProtocol(n.code),i=_t(n.code),s,c=0,a=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??q(n.value),c=s.byteLength,o.size===lt&&(a=_t(c)));let f=new Uint8Array(i+a+c),u=0;qe(n.code,f,u),u+=i,s!=null&&(o.size===lt&&(qe(c,f,u),u+=a),f.set(s,u)),n.bytes=f}r.push(n.bytes),t+=n.bytes.byteLength}return Kt(r,t)}function Lu(e){if(e.charAt(0)!=="/")throw new yt('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=xe.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 yt(`Component ${o} was missing value`);r="value"}else if(r==="value"){let f={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new yt(`Component ${o} was missing value`);f.value=a.stringToValue?.(n)??n}t.push(f),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new yt("Incomplete multiaddr");return t}function Uu(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=xe.getProtocol(t.code);if(r==null)throw new yt(`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:Gi(t,r)}var Xp=Symbol.for("nodejs.util.inspect.custom"),Ds=Symbol.for("@multiformats/multiaddr");function Jp(e){if(e==null&&(e="/"),Ou(e))return e.getComponents();if(e instanceof Uint8Array)return Nu(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Lu(e);if(Array.isArray(e))return e;throw new yt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var no=class e{[Ds]=!0;#t;#n;#r;constructor(t="/",r={}){this.#t=Jp(t),r.validate!==!1&&Qp(this)}get bytes(){return this.#r==null&&(this.#r=Pu(this.#t)),this.#r}toString(){return this.#n==null&&(this.#n=Uu(this.#t)),this.#n}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Jn(`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)}[Xp](){return`Multiaddr(${this.toString()})`}};function Qp(e){e.getComponents().forEach(t=>{let r=xe.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function Ou(e){return!!e?.[Ds]}function oo(e){return new no(e)}function Sr(e){let t=new globalThis.AbortController;function r(){let i=e.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();t.abort(i);for(let s of e)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let i of e){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=t.signal;return o.clear=n,o}async function*rn(e,t={}){let r=e.getReader();try{for(;;){let n=await r.read();if(n.done)return;yield n.value}}finally{t.preventCancel!==!0&&await r.cancel(),r.releaseLock()}}function t0(e,t){if(typeof e=="string")return e0(e);if(typeof e=="number")return o0(e,t);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(e)}`)}var io=t0;function e0(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 r0(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 n0(e){let t=Math.abs(e);return t>=315576e5?Ge(e,t,315576e5,"year"):t>=26298e5?Ge(e,t,26298e5,"month"):t>=6048e5?Ge(e,t,6048e5,"week"):t>=864e5?Ge(e,t,864e5,"day"):t>=36e5?Ge(e,t,36e5,"hour"):t>=6e4?Ge(e,t,6e4,"minute"):t>=1e3?Ge(e,t,1e3,"second"):`${e} ms`}function o0(e,t){if(typeof e!="number"||!Number.isFinite(e))throw Error("Value provided to ms.format() must be of type number.");return t?.long?n0(e):r0(e)}function Ge(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function Rs(e){r.debug=r,r.default=r,r.coerce=a,r.disable=i,r.enable=o,r.enabled=s,r.humanize=io,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 m=0;m<u.length;m++)l=(l<<5)-l+u.charCodeAt(m),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=t;function r(u,l){let m,E=null,b,T;function I(...w){if(!I.enabled)return;let C=I,v=Number(new Date),L=v-(m||v);C.diff=L,C.prev=m,C.curr=v,m=v,w[0]=r.coerce(w[0]),typeof w[0]!="string"&&w.unshift("%O");let k=0;w[0]=w[0].replace(/%([a-zA-Z%])/g,(M,p)=>{if(M==="%%")return"%";k++;let y=r.formatters[p];if(typeof y=="function"){let _=w[k];M=y.call(C,_),w.splice(k,1),k--}return M}),r.formatArgs.call(C,w),l?.onLog!=null&&l.onLog(...w),(C.log||r.log).apply(C,w)}return I.namespace=u,I.useColors=r.useColors(),I.color=r.selectColor(u),I.extend=n,I.destroy=r.destroy,Object.defineProperty(I,"enabled",{enumerable:!0,configurable:!1,get:()=>E!==null?E:(b!==r.namespaces&&(b=r.namespaces,T=r.enabled(u)),T),set:w=>{E=w}}),typeof r.init=="function"&&r.init(I),I}function n(u,l){let m=r(this.namespace+(typeof l>"u"?":":l)+u);return m.log=this.log,m}function o(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];let l,m=(typeof u=="string"?u:"").split(/[\s,]+/),E=m.length;for(l=0;l<E;l++)m[l]&&(u=m[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(c),...r.skips.map(c).map(l=>"-"+l)].join(",");return r.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let l,m;for(l=0,m=r.skips.length;l<m;l++)if(r.skips[l].test(u))return!1;for(l=0,m=r.names.length;l<m;l++)if(r.names[l].test(u))return!0;return!1}function c(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function a(u){return u instanceof Error?u.stack??u.message:u}function 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 so=l0(),i0=["#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 s0(){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 a0(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+io(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 c0=console.debug??console.log??(()=>{});function u0(e){try{e?so?.setItem("debug",e):so?.removeItem("debug")}catch{}}function f0(){let e;try{e=so?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function l0(){try{return localStorage}catch{}}function d0(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var ku=Rs({formatArgs:a0,save:u0,load:f0,useColors:s0,setupFormatters:d0,colors:i0,storage:so,log:c0});var Dt=ku;Dt.formatters.b=e=>e==null?"undefined":X.baseEncode(e);Dt.formatters.t=e=>e==null?"undefined":te.baseEncode(e);Dt.formatters.m=e=>e==null?"undefined":ni.baseEncode(e);Dt.formatters.p=e=>e==null?"undefined":e.toString();Dt.formatters.c=e=>e==null?"undefined":e.toString();Dt.formatters.k=e=>e==null?"undefined":e.toString();Dt.formatters.a=e=>e==null?"undefined":e.toString();function Ku(e,t=""){let r=Mu(e.message),n=Mu(e.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
2
+ "use strict";var HeliaRouters=(()=>{var gl=Object.create;var Cn=Object.defineProperty;var bl=Object.getOwnPropertyDescriptor;var xl=Object.getOwnPropertyNames;var wl=Object.getPrototypeOf,El=Object.prototype.hasOwnProperty;var Ea=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Et=(e,t)=>{for(var r in t)Cn(e,r,{get:t[r],enumerable:!0})},Sa=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of xl(t))!El.call(e,o)&&o!==r&&Cn(e,o,{get:()=>t[o],enumerable:!(n=bl(t,o))||n.enumerable});return e};var Go=(e,t,r)=>(r=e!=null?gl(wl(e)):{},Sa(t||!e||!e.__esModule?Cn(r,"default",{value:e,enumerable:!0}):r,e)),Sl=e=>Sa(Cn({},"__esModule",{value:!0}),e);var js=Ea((x1,Hs)=>{var b1=(function(){typeof Hs<"u"&&(Hs.exports=v);var e=86400,t=3200,r=146097*t/400,n=e*r,o=1e3*n,i=864e13,s=4294967296,a=1e6,c="000000000",u=Math.trunc||function(w){var C=w-w%1;return C==0&&(w<0||w===0&&1/w!=1/0)?-0:C},f=v.prototype,l=(v.fromDate=function(w){return new v(+w)},v.fromInt64BE=U(0,1,2,3,0,4),v.fromInt64LE=U(3,2,1,0,4,0),v.fromString=function(P){var C,N=new v,P=(P+="").replace(/^\s*[+\-]?\d+/,function(g){var g=+g,T=1970+(g-1970)%400;return N.year=g-T,T}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(d,g,T){return g<0&&(T*=-1),C=6e4*(60*+g+ +T),""}).replace(/\.\d+$/,function(d){return N.nano=+(d+c).substr(1,9),""}).split(/\D+/);if(1<P.length?P[1]--:P[1]=0,N.time=C=Date.UTC.apply(Date,P)-(C||0),isNaN(C))throw new TypeError("Invalid Date");return y(N)},v.fromTimeT=function(w){return A(w,0)},f.year=0,f.time=0,f.nano=0,f.addNano=function(w){return this.nano+=+w||0,this},f.getNano=function(){var w=y(this);return(w.time%1e3*a+ +w.nano+1e9)%1e9},f.getTimeT=function(){var C=y(this),w=Math.floor(C.time/1e3),C=C.year;return C&&(w+=C*r*e/t),w},f.getYear=function(){return this.toDate().getUTCFullYear()+this.year},f.toDate=function(){return S(y(this).time)},f.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},f.toString=function(w){var C=this,N=C.toDate(),P={H:function(){return M(N.getUTCHours())},L:function(){return L(N.getUTCMilliseconds(),3)},M:function(){return M(N.getUTCMinutes())},N:function(){return L(C.getNano(),9)},S:function(){return M(N.getUTCSeconds())},Y:function(){var d=C.getYear();return 999999<d?"+"+d:9999<d?"+"+L(d,6):0<=d?L(d,4):-999999<=d?"-"+L(-d,6):d},a:function(){return m[N.getUTCDay()]},b:function(){return h[N.getUTCMonth()]},d:function(){return M(N.getUTCDate())},e:function(){return(function(d){return(9<d?"":" ")+(0|d)})(N.getUTCDate())},m:function(){return M(N.getUTCMonth()+1)}};return(function d(g){return g.replace(/%./g,function(T){var x=T[1],b=E[x],x=P[x];return b?d(b):x?x():T})})(w||l)},f.writeInt64BE=_(0,1,2,3,0,4),f.writeInt64LE=_(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],m=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],E={"%":"%",F:"%Y-%m-%d",n:`
3
+ `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return v;function v(w,C,N){var P=this;if(!(P instanceof v))return new v(w,C,N);P.time=+w||0,P.nano=+C||0,P.year=+N||0,y(P)}function y(w){var C,N,P,d=w.year,g=w.time,T=w.nano,b=((T<0||a<=T)&&(T-=(N=Math.floor(T/a))*a,g+=N,N=1),d%t);return(g<-i||i<g||b)&&((C=u(g/o))&&(d+=C*t,g-=C*o),(P=S(g)).setUTCFullYear(b+P.getUTCFullYear()),P=(g=+P)+(C=u((d-=b)/t))*o,C&&-i<=P&&P<=i&&(d-=C*t,g=P),N=1),N&&(w.year=d,w.time=g,w.nano=T),w}function S(w){var C=new Date(0);return C.setTime(w),C}function A(d,P){d=+d||0;var N=u((P=(P|0)*s)/n)+u(d/n),P=P%n+d%n,d=u(P/n);return d&&(N+=d,P-=d*n),new v(1e3*P,0,N*t)}function _(w,C,N,P,d,g){return function(b,x){var R=y(this);b=b||new Array(8),F(b,x|=0);var D=Math.floor(R.time/1e3),R=R.year*(r*e/t),I=u(R/s)+u(D/s),R=R%s+D%s,D=Math.floor(R/s);return D&&(I+=D,R-=D*s),T(b,x+d,I),T(b,x+g,R),b};function T(b,x,I){b[x+w]=I>>24&255,b[x+C]=I>>16&255,b[x+N]=I>>8&255,b[x+P]=255&I}}function U(w,C,N,P,d,g){return function(b,x){F(b,x|=0);var I=T(b,x+d);return A(T(b,x+g),I)};function T(b,x){return 16777216*b[x+w]+(b[x+C]<<16|b[x+N]<<8|b[x+P])}}function F(w,C){if(w=w&&w.length,w==null)throw new TypeError("Invalid Buffer");if(w<C+8)throw new RangeError("Out of range")}function M(w){return(9<w?"":"0")+(0|w)}function L(w,C){return(c+(0|w)).substr(-C)}})()});var Qf=Ea((xE,oa)=>{"use strict";var J0=Object.prototype.hasOwnProperty,vt="~";function Tn(){}Object.create&&(Tn.prototype=Object.create(null),new Tn().__proto__||(vt=!1));function Q0(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function Jf(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 $o(e,t){--e._eventsCount===0?e._events=new Tn:delete e._events[t]}function wt(){this._events=new Tn,this._eventsCount=0}wt.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)J0.call(r,n)&&t.push(vt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};wt.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};wt.prototype.listenerCount=function(t){var r=vt?vt+t:t,n=this._events[r];return n?n.fn?1:n.length:0};wt.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],u=arguments.length,f,l;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),u){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,f=new Array(u-1);l<u;l++)f[l-1]=arguments[l];c.fn.apply(c.context,f)}else{var h=c.length,m;for(l=0;l<h;l++)switch(c[l].once&&this.removeListener(t,c[l].fn,void 0,!0),u){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(!f)for(m=1,f=new Array(u-1);m<u;m++)f[m-1]=arguments[m];c[l].fn.apply(c[l].context,f)}}return!0};wt.prototype.on=function(t,r,n){return Jf(this,t,r,n,!1)};wt.prototype.once=function(t,r,n){return Jf(this,t,r,n,!0)};wt.prototype.removeListener=function(t,r,n,o){var i=vt?vt+t:t;if(!this._events[i])return this;if(!r)return $o(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&$o(this,i);else{for(var a=0,c=[],u=s.length;a<u;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:$o(this,i)}return this};wt.prototype.removeAllListeners=function(t){var r;return t?(r=vt?vt+t:t,this._events[r]&&$o(this,r)):(this._events=new Tn,this._eventsCount=0),this};wt.prototype.off=wt.prototype.removeListener;wt.prototype.addListener=wt.prototype.on;wt.prefixed=vt;wt.EventEmitter=wt;typeof oa<"u"&&(oa.exports=wt)});var Sm={};Et(Sm,{delegatedHTTPRouting:()=>al,delegatedHTTPRoutingDefaults:()=>Yo,httpGatewayRouting:()=>ml,libp2pRouting:()=>yl});var va=Symbol.for("@libp2p/content-routing");var et=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},rr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var At=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var _n=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},nr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var or=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Bn=Symbol.for("@libp2p/peer-id");function Ta(e){return!!e?.[Bn]}var Aa=Symbol.for("@libp2p/peer-routing");var ti={};Et(ti,{base58btc:()=>X,base58flickr:()=>Bl});var _m=new Uint8Array(0);function Ia(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 ue(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 Ca(e){return new TextEncoder().encode(e)}function _a(e){return new TextDecoder().decode(e)}function vl(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),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(E){if(E instanceof Uint8Array||(ArrayBuffer.isView(E)?E=new Uint8Array(E.buffer,E.byteOffset,E.byteLength):Array.isArray(E)&&(E=Uint8Array.from(E))),!(E instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(E.length===0)return"";for(var v=0,y=0,S=0,A=E.length;S!==A&&E[S]===0;)S++,v++;for(var _=(A-S)*f+1>>>0,U=new Uint8Array(_);S!==A;){for(var F=E[S],M=0,L=_-1;(F!==0||M<y)&&L!==-1;L--,M++)F+=256*U[L]>>>0,U[L]=F%a>>>0,F=F/a>>>0;if(F!==0)throw new Error("Non-zero carry");y=M,S++}for(var w=_-y;w!==_&&U[w]===0;)w++;for(var C=c.repeat(v);w<_;++w)C+=e.charAt(U[w]);return C}function h(E){if(typeof E!="string")throw new TypeError("Expected String");if(E.length===0)return new Uint8Array;var v=0;if(E[v]!==" "){for(var y=0,S=0;E[v]===c;)y++,v++;for(var A=(E.length-v)*u+1>>>0,_=new Uint8Array(A);E[v];){var U=r[E.charCodeAt(v)];if(U===255)return;for(var F=0,M=A-1;(U!==0||F<S)&&M!==-1;M--,F++)U+=a*_[M]>>>0,_[M]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");S=F,v++}if(E[v]!==" "){for(var L=A-S;L!==A&&_[L]===0;)L++;for(var w=new Uint8Array(y+(A-L)),C=y;L!==A;)w[C++]=_[L++];return w}}}function m(E){var v=h(E);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:h,decode:m}}var Tl=vl,Al=Tl,Ra=Al;var Wo=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Xo=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Da(this,t)}},Jo=class{decoders;constructor(t){this.decoders=t}or(t){return Da(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 Da(e,t){return new Jo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Qo=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 Wo(t,r,n),this.decoder=new Xo(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ir({name:e,prefix:t,encode:r,decode:n}){return new Qo(e,t,r,n)}function Ee({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ra(r,e);return ir({prefix:t,name:e,encode:n,decode:i=>ue(o(i))})}function Il(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 u=0;u<o;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,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 Cl(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 _l(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function rt({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=_l(n);return ir({prefix:t,name:e,encode(i){return Cl(i,n,r)},decode(i){return Il(i,o,r,e)}})}var X=Ee({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Bl=Ee({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ei={};Et(ei,{base32:()=>te,base32hex:()=>Ol,base32hexpad:()=>Ll,base32hexpadupper:()=>Nl,base32hexupper:()=>Fl,base32pad:()=>Dl,base32padupper:()=>Pl,base32upper:()=>Rl,base32z:()=>Ul});var te=rt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Rl=rt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Dl=rt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Pl=rt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ol=rt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Fl=rt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ll=rt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Nl=rt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ul=rt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ri={};Et(ri,{base36:()=>sr,base36upper:()=>kl});var sr=Ee({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),kl=Ee({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ee={};Et(ee,{Digest:()=>Ke,create:()=>Vt,decode:()=>Se,equals:()=>oi,hasCode:()=>nd});var Kl=Fa,Pa=128,$l=127,Ml=~$l,Vl=Math.pow(2,31);function Fa(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Vl;)t[r++]=e&255|Pa,e/=128;for(;e&Ml;)t[r++]=e&255|Pa,e>>>=7;return t[r]=e|0,Fa.bytes=r-n+1,t}var ql=ni,zl=128,Oa=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&Oa)<<o:(s&Oa)*Math.pow(2,o),o+=7}while(s>=zl);return ni.bytes=i-n,r}var Hl=Math.pow(2,7),jl=Math.pow(2,14),Yl=Math.pow(2,21),Zl=Math.pow(2,28),Gl=Math.pow(2,35),Wl=Math.pow(2,42),Xl=Math.pow(2,49),Jl=Math.pow(2,56),Ql=Math.pow(2,63),td=function(e){return e<Hl?1:e<jl?2:e<Yl?3:e<Zl?4:e<Gl?5:e<Wl?6:e<Xl?7:e<Jl?8:e<Ql?9:10},ed={encode:Kl,decode:ql,encodingLength:td},rd=ed,Kr=rd;function $r(e,t=0){return[Kr.decode(e,t),Kr.decode.bytes]}function ar(e,t,r=0){return Kr.encode(e,t,r),t}function cr(e){return Kr.encodingLength(e)}function Vt(e,t){let r=t.byteLength,n=cr(e),o=n+cr(r),i=new Uint8Array(o+r);return ar(e,i,0),ar(r,i,n),i.set(t,o),new Ke(e,r,t,i)}function Se(e){let t=ue(e),[r,n]=$r(t),[o,i]=$r(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Ke(r,o,s,t)}function oi(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ia(e.bytes,r.bytes)}}var Ke=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function nd(e,t){return e.code===t}function La(e,t){let{bytes:r,version:n}=e;return n===0?id(r,ii(e),t??X.encoder):sd(r,ii(e),t??te.encoder)}var Na=new WeakMap;function ii(e){let t=Na.get(e);if(t==null){let r=new Map;return Na.set(e,r),r}return t}var H=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!==Mr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==ad)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=Vt(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&&oi(t.multihash,n.multihash)}toString(t){return La(this,t)}toJSON(){return{"/":La(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??Ua(n,o,i.bytes))}else if(r[cd]===!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!==Mr)throw new Error(`Version 0 CID must use dag-pb (code: ${Mr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Ua(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Mr,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=ue(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 Ke(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,h]=$r(t.subarray(r));return r+=h,l},o=n(),i=Mr;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(),u=r+c,f=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,o]=od(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 ii(i).set(n,t),i}};function od(e,t){switch(e[0]){case"Q":{let r=t??X;return[X.prefix,r.decode(`${X.prefix}${e}`)]}case X.prefix:{let r=t??X;return[X.prefix,r.decode(e)]}case te.prefix:{let r=t??te;return[te.prefix,r.decode(e)]}case sr.prefix:{let r=t??sr;return[sr.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 id(e,t,r){let{prefix:n}=r;if(n!==X.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 sd(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 Mr=112,ad=18;function Ua(e,t,r){let n=cr(e),o=n+cr(t),i=new Uint8Array(o+r.byteLength);return ar(e,i,0),ar(t,i,n),i.set(r,o),i}var cd=Symbol.for("@ipld/js-cid/CID");var si={};Et(si,{identity:()=>St});var ka=0,ud="identity",Ka=ue;function fd(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 Vt(ka,Ka(e))}var St={code:ka,name:ud,encode:Ka,digest:fd};function W(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 fe(e=0){return new Uint8Array(e)}function _t(e=0){return new Uint8Array(e)}function Nt(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=_t(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Ma=Symbol.for("@achingbrain/uint8arraylist");function $a(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 ur(e){return!!e?.[Ma]}var Bt=class e{bufs;length;[Ma]=!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(ur(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}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(ur(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=$a(this.bufs,t);return r.buf[r.index]}set(t,r){let n=$a(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(ur(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 Nt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Nt(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 u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(s);break}let l=t-a;n.push(s.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(f){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(!ur(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,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let h=u;h>=0;h--){let m=this.get(l+h);if(n[h]!==m){f=Math.max(1,h-a[m]);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=_t(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=fe(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=fe(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=fe(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=_t(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=fe(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=fe(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=fe(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=fe(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=fe(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(!W(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 ai={};Et(ai,{base10:()=>ld});var ld=Ee({prefix:"9",name:"base10",alphabet:"0123456789"});var ci={};Et(ci,{base16:()=>dd,base16upper:()=>hd});var dd=rt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),hd=rt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ui={};Et(ui,{base2:()=>pd});var pd=rt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var fi={};Et(fi,{base256emoji:()=>xd});var Va=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}"),md=Va.reduce((e,t,r)=>(e[r]=t,e),[]),yd=Va.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function gd(e){return e.reduce((t,r)=>(t+=md[r],t),"")}function bd(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=yd[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var xd=ir({prefix:"\u{1F680}",name:"base256emoji",encode:gd,decode:bd});var hi={};Et(hi,{base64:()=>li,base64pad:()=>wd,base64url:()=>di,base64urlpad:()=>Ed});var li=rt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),wd=rt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),di=rt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ed=rt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var pi={};Et(pi,{base8:()=>Sd});var Sd=rt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var mi={};Et(mi,{identity:()=>vd});var vd=ir({prefix:"\0",name:"identity",encode:e=>_a(e),decode:e=>Ca(e)});var ly=new TextEncoder,dy=new TextDecoder;var qa=85;var bi={};Et(bi,{sha256:()=>Vr,sha512:()=>Id});var Ad=20;function gi({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new yi(e,t,r,n,o)}var yi=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Ad,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?Ha(n,this.code,r?.truncate):n.then(o=>Ha(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ha(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 Vt(t,e)}function Ya(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Vr=gi({name:"sha2-256",code:18,encode:Ya("SHA-256")}),Id=gi({name:"sha2-512",code:19,encode:Ya("SHA-512")});var qr={...mi,...ui,...pi,...ai,...ci,...ei,...ri,...ti,...hi,...fi},Ty={...bi,...si};function Ga(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Za=Ga("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),xi=Ga("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=_t(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Cd={utf8:Za,"utf-8":Za,hex:qr.base16,latin1:xi,ascii:xi,binary:xi,...qr},Dn=Cd;function V(e,t="utf8"){let r=Dn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function z(e,t="utf8"){let r=Dn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var _d=parseInt("11111",2),wi=parseInt("10000000",2),Bd=parseInt("01111111",2),Wa={0:zr,1:zr,2:Rd,3:Od,4:Fd,5:Pd,6:Dd,16:zr,22:zr,48:zr};function le(e,t={offset:0}){let r=e[t.offset]&_d;if(t.offset++,Wa[r]!=null)return Wa[r](e,t);throw new Error("No decoder for tag "+r)}function Hr(e,t){let r=0;if((e[t.offset]&wi)===wi){let n=e[t.offset]&Bd,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 zr(e,t){Hr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=le(e,t);if(n===null)break;r.push(n)}return r}function Rd(e,t){let r=Hr(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 Dd(e,t){let r=Hr(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 u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function Pd(e,t){return t.offset++,null}function Od(e,t){let r=Hr(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=Hr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Ld(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new Bt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Ei(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Ld(e.byteLength);return new Bt(Uint8Array.from([t.byteLength|wi]),t)}function It(e){let t=new Bt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new Bt(Uint8Array.from([2]),Ei(t),t)}function Pn(e){let t=Uint8Array.from([0]),r=new Bt(t,e);return new Bt(Uint8Array.from([3]),Ei(r),r)}function ve(e,t=48){let r=new Bt;for(let n of e)r.append(n);return new Bt(Uint8Array.from([t]),Ei(r),r)}async function Xa(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 Nd=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Ud=Uint8Array.from([6,5,43,129,4,0,34]),kd=Uint8Array.from([6,5,43,129,4,0,35]),Kd={ext:!0,kty:"EC",crv:"P-256"},$d={ext:!0,kty:"EC",crv:"P-384"},Md={ext:!0,kty:"EC",crv:"P-521"},Si=32,vi=48,Ti=66;function Ai(e){let t=le(e);return Ja(t)}function Ja(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Si*2+1)return n=z(t.subarray(r,r+Si),"base64url"),o=z(t.subarray(r+Si),"base64url"),new fr({...Kd,key_ops:["verify"],x:n,y:o});if(t.byteLength===vi*2+1)return n=z(t.subarray(r,r+vi),"base64url"),o=z(t.subarray(r+vi),"base64url"),new fr({...$d,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ti*2+1)return n=z(t.subarray(r,r+Ti),"base64url"),o=z(t.subarray(r+Ti),"base64url"),new fr({...Md,key_ops:["verify"],x:n,y:o});throw new et(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Qa(e){return ve([It(Uint8Array.from([1])),ve([Vd(e.crv)],160),ve([Pn(new Bt(Uint8Array.from([4]),V(e.x??"","base64url"),V(e.y??"","base64url")))],161)]).subarray()}function Vd(e){if(e==="P-256")return Nd;if(e==="P-384")return Ud;if(e==="P-521")return kd;throw new et(`Invalid curve ${e}`)}var fr=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Qa(this.jwk)),this._raw}toMultihash(){return St.digest(lr(this))}toCID(){return H.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}async verify(t,r,n){return Xa(this.jwk,r,t,n)}};function Ii(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function Te(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(`${r}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new RangeError(`${r}expected integer >= 0, got ${e}`)}}function Rt(e,t,r=""){let n=Ii(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}`,u=s+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return e}function On(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Te(e.outputLen),Te(e.blockLen),e.outputLen<1)throw new Error('"outputLen" must be >= 1');if(e.blockLen<1)throw new Error('"blockLen" must be >= 1')}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 Fn(e,t){Rt(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function he(...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 qt(e,t){return e<<32-t|e>>>t}var ec=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",qd=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Nn(e){if(Rt(e),ec)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=qd[e[r]];return t}var de={_0:48,_9:57,A:65,F:70,a:97,f:102};function tc(e){if(e>=de._0&&e<=de._9)return e-de._0;if(e>=de.A&&e<=de.F)return e-(de.A-10);if(e>=de.a&&e<=de.f)return e-(de.a-10)}function jr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(ec)try{return Uint8Array.fromHex(e)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=e.length,r=t/2;if(t%2)throw new RangeError("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=tc(e.charCodeAt(i)),a=tc(e.charCodeAt(i+1));if(s===void 0||a===void 0){let c=e[i]+e[i+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function Ci(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];Rt(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 _i(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.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function rc(e=32){Te(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var Bi=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function nc(e,t,r){return e&t^~e&r}function oc(e,t,r){return e&t^e&r^t&r}var Yr=class{blockLen;outputLen;canXOF=!1;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=Ln(this.buffer)}update(t){dr(this),Rt(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),Fn(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,he(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 a=Ln(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.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: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()}},pe=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var mt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Un=BigInt(4294967295),ic=BigInt(32);function zd(e,t=!1){return t?{h:Number(e&Un),l:Number(e>>ic&Un)}:{h:Number(e>>ic&Un)|0,l:Number(e&Un)|0}}function sc(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}=zd(e[i],t);[n[i],o[i]]=[s,a]}return[n,o]}var Ri=(e,t,r)=>e>>>r,Di=(e,t,r)=>e<<32-r|t>>>r,$e=(e,t,r)=>e>>>r|t<<32-r,Me=(e,t,r)=>e<<32-r|t>>>r,Zr=(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 ac=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),cc=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,uc=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),fc=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,lc=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),dc=(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]),Ae=new Uint32Array(64),Pi=class extends Yr{constructor(t){super(64,t,8,!1)}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)Ae[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let h=Ae[l-15],m=Ae[l-2],E=qt(h,7)^qt(h,18)^h>>>3,v=qt(m,17)^qt(m,19)^m>>>10;Ae[l]=v+Ae[l-7]+E+Ae[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let h=qt(a,6)^qt(a,11)^qt(a,25),m=f+h+nc(a,c,u)+jd[l]+Ae[l]|0,v=(qt(n,2)^qt(n,13)^qt(n,22))+oc(n,o,i)|0;f=u,u=c,c=a,a=s+m|0,s=i,i=o,o=n,n=m+v|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,u=u+this.G|0,f=f+this.H|0,this.set(n,o,i,s,a,c,u,f)}roundClean(){he(Ae)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),he(this.buffer)}},Oi=class extends Pi{A=pe[0]|0;B=pe[1]|0;C=pe[2]|0;D=pe[3]|0;E=pe[4]|0;F=pe[5]|0;G=pe[6]|0;H=pe[7]|0;constructor(){super(32)}};var hc=sc(["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))),Yd=hc[0],Zd=hc[1],Ie=new Uint32Array(80),Ce=new Uint32Array(80),Fi=class extends Yr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:h,Gh:m,Gl:E,Hh:v,Hl:y}=this;return[t,r,n,o,i,s,a,c,u,f,l,h,m,E,v,y]}set(t,r,n,o,i,s,a,c,u,f,l,h,m,E,v,y){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=u|0,this.El=f|0,this.Fh=l|0,this.Fl=h|0,this.Gh=m|0,this.Gl=E|0,this.Hh=v|0,this.Hl=y|0}process(t,r){for(let _=0;_<16;_++,r+=4)Ie[_]=t.getUint32(r),Ce[_]=t.getUint32(r+=4);for(let _=16;_<80;_++){let U=Ie[_-15]|0,F=Ce[_-15]|0,M=$e(U,F,1)^$e(U,F,8)^Ri(U,F,7),L=Me(U,F,1)^Me(U,F,8)^Di(U,F,7),w=Ie[_-2]|0,C=Ce[_-2]|0,N=$e(w,C,19)^Zr(w,C,61)^Ri(w,C,6),P=Me(w,C,19)^Gr(w,C,61)^Di(w,C,6),d=uc(L,P,Ce[_-7],Ce[_-16]),g=fc(d,M,N,Ie[_-7],Ie[_-16]);Ie[_]=g|0,Ce[_]=d|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:h,Fh:m,Fl:E,Gh:v,Gl:y,Hh:S,Hl:A}=this;for(let _=0;_<80;_++){let U=$e(l,h,14)^$e(l,h,18)^Zr(l,h,41),F=Me(l,h,14)^Me(l,h,18)^Gr(l,h,41),M=l&m^~l&v,L=h&E^~h&y,w=lc(A,F,L,Zd[_],Ce[_]),C=dc(w,S,U,M,Yd[_],Ie[_]),N=w|0,P=$e(n,o,28)^Zr(n,o,34)^Zr(n,o,39),d=Me(n,o,28)^Gr(n,o,34)^Gr(n,o,39),g=n&i^n&a^i&a,T=o&s^o&c^s&c;S=v|0,A=y|0,v=m|0,y=E|0,m=l|0,E=h|0,{h:l,l:h}=re(u|0,f|0,C|0,N|0),u=a|0,f=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let b=ac(N,d,T);n=cc(b,C,P,g),o=b|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:u,l:f}=re(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:h}=re(this.Eh|0,this.El|0,l|0,h|0),{h:m,l:E}=re(this.Fh|0,this.Fl|0,m|0,E|0),{h:v,l:y}=re(this.Gh|0,this.Gl|0,v|0,y|0),{h:S,l:A}=re(this.Hh|0,this.Hl|0,S|0,A|0),this.set(n,o,i,s,a,c,u,f,l,h,m,E,v,y,S,A)}roundClean(){he(Ie,Ce)}destroy(){this.destroyed=!0,he(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Li=class extends Fi{Ah=mt[0]|0;Al=mt[1]|0;Bh=mt[2]|0;Bl=mt[3]|0;Ch=mt[4]|0;Cl=mt[5]|0;Dh=mt[6]|0;Dl=mt[7]|0;Eh=mt[8]|0;El=mt[9]|0;Fh=mt[10]|0;Fl=mt[11]|0;Gh=mt[12]|0;Gl=mt[13]|0;Hh=mt[14]|0;Hl=mt[15]|0;constructor(){super(64)}};var hr=_i(()=>new Oi,Bi(1));var kn=_i(()=>new Li,Bi(3));var Y=(e,t,r)=>Rt(e,t,r),Ui=Te,pr=Nn,ct=(...e)=>Ci(...e),mr=e=>jr(e),Ve=Ii,Wr=e=>rc(e),$n=BigInt(0),Ni=BigInt(1);function zt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new TypeError(r+"expected boolean, got type="+typeof e)}return e}function Mn(e){if(typeof e=="bigint"){if(!Kn(e))throw new RangeError("positive bigint expected, got "+e)}else Ui(e);return e}function Ht(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function Xr(e){let t=Mn(e).toString(16);return t.length&1?"0"+t:t}function pc(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?$n:BigInt("0x"+e)}function qe(e){return pc(Nn(e))}function ne(e){return pc(Nn(Jr(Rt(e)).reverse()))}function Vn(e,t){if(Te(t),t===0)throw new RangeError("zero length");e=Mn(e);let r=e.toString(16);if(r.length>t*2)throw new RangeError("number too large");return jr(r.padStart(t*2,"0"))}function ki(e,t){return Vn(e,t).reverse()}function mc(e,t){if(e=Y(e),t=Y(t),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 Jr(e){return Uint8Array.from(Y(e))}function qn(e){if(typeof e!="string")throw new TypeError("ascii string expected, got "+typeof e);return Uint8Array.from(e,(t,r)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${e[r]}" with code ${n} at position ${r}`);return n})}var Kn=e=>typeof e=="bigint"&&$n<=e;function Gd(e,t,r){return Kn(e)&&Kn(t)&&Kn(r)&&t<=e&&e<r}function yr(e,t,r,n){if(!Gd(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function gr(e){if(e<$n)throw new Error("expected non-negative bigint, got "+e);let t;for(t=0;e>$n;e>>=Ni,t+=1);return t}var Qr=e=>(Ni<<BigInt(e))-Ni;function yc(e,t,r){if(Te(e,"hashLen"),Te(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=y=>new Uint8Array(y),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),f=0,l=()=>{c.fill(1),u.fill(0),f=0},h=(...y)=>r(u,ct(c,...y)),m=(y=o)=>{u=h(i,y),c=h(),y.length!==0&&(u=h(s,y),c=h())},E=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,S=[];for(;y<t;){c=h();let A=c.slice();S.push(A),y+=c.length}return ct(...S)};return(y,S)=>{l(),m(y);let A;for(;(A=S(E()))===void 0;)m();return l(),A}}function jt(e,t={},r={}){if(Object.prototype.toString.call(e)!=="[object Object]")throw new TypeError("expected valid options object");function n(i,s,a){if(!a&&s!=="function"&&!Object.hasOwn(e,i))throw new TypeError(`param "${i}" is invalid: expected own property`);let c=e[i];if(a&&c===void 0)return;let u=typeof c;if(u!==s||c===null)throw new TypeError(`param "${i}" is invalid: expected ${s}, got ${u}`)}let o=(i,s)=>Object.entries(i).forEach(([a,c])=>n(a,c,s));o(t,!1),o(r,!0)}var Ki=()=>{throw new Error("not implemented")};var yt=BigInt(0),nt=BigInt(1),ze=BigInt(2),wc=BigInt(3),Ec=BigInt(4),Sc=BigInt(5),Wd=BigInt(7),vc=BigInt(8),Xd=BigInt(9),Tc=BigInt(16);function it(e,t){if(t<=yt)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=yt?r:t+r}function J(e,t,r){if(t<yt)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >yt;)n*=n,n%=r;return n}function gc(e,t){if(e===yt)throw new Error("invert: expected non-zero number");if(t<=yt)throw new Error("invert: expected positive modulus, got "+t);let r=it(e,t),n=t,o=yt,i=nt,s=nt,a=yt;for(;r!==yt;){let u=n/r,f=n-r*u,l=o-s*u,h=i-a*u;n=r,r=f,o=s,i=a,s=l,a=h}if(n!==nt)throw new Error("invert: does not exist");return it(o,t)}function $i(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function Ac(e,t){let r=e,n=(r.ORDER+nt)/Ec,o=r.pow(t,n);return $i(r,o,t),o}function Jd(e,t){let r=e,n=(r.ORDER-Sc)/vc,o=r.mul(t,ze),i=r.pow(o,n),s=r.mul(t,i),a=r.mul(r.mul(s,ze),i),c=r.mul(s,r.sub(a,r.ONE));return $i(r,c,t),c}function Qd(e){let t=br(e),r=Ic(e),n=r(t,t.neg(t.ONE)),o=r(t,n),i=r(t,t.neg(n)),s=(e+Wd)/Tc;return((a,c)=>{let u=a,f=u.pow(c,s),l=u.mul(f,n),h=u.mul(f,o),m=u.mul(f,i),E=u.eql(u.sqr(l),c),v=u.eql(u.sqr(h),c);f=u.cmov(f,l,E),l=u.cmov(m,h,v);let y=u.eql(u.sqr(l),c),S=u.cmov(f,l,y);return $i(u,S,c),S})}function Ic(e){if(e<wc)throw new Error("sqrt is not defined for small field");let t=e-nt,r=0;for(;t%ze===yt;)t/=ze,r++;let n=ze,o=br(e);for(;bc(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ac;let i=o.pow(n,t),s=(t+nt)/ze;return function(c,u){let f=c;if(f.is0(u))return u;if(bc(f,u)!==1)throw new Error("Cannot find square root");let l=r,h=f.mul(f.ONE,i),m=f.pow(u,t),E=f.pow(u,s);for(;!f.eql(m,f.ONE);){if(f.is0(m))return f.ZERO;let v=1,y=f.sqr(m);for(;!f.eql(y,f.ONE);)if(v++,y=f.sqr(y),v===l)throw new Error("Cannot find square root");let S=nt<<BigInt(l-v-1),A=f.pow(h,S);l=v,h=f.sqr(A),m=f.mul(m,h),E=f.mul(E,A)}return E}}function th(e){return e%Ec===wc?Ac:e%vc===Sc?Jd:e%Tc===Xd?Qd(e):Ic(e)}var me=(e,t)=>(it(e,t)&nt)===nt,eh=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Mi(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=eh.reduce((n,o)=>(n[o]="function",n),t);if(jt(e,r),Ht(e.BYTES,"BYTES"),Ht(e.BITS,"BITS"),e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=nt)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function rh(e,t,r){let n=e;if(r<yt)throw new Error("invalid exponent, negatives unsupported");if(r===yt)return n.ONE;if(r===nt)return t;let o=n.ONE,i=t;for(;r>yt;)r&nt&&(o=n.mul(o,i)),i=n.sqr(i),r>>=nt;return o}function tn(e,t,r=!1){let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),i=t.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),s=n.inv(i);return t.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),s),o}function bc(e,t){let r=e,n=(r.ORDER-nt)/ze,o=r.pow(t,n),i=r.eql(o,r.ONE),s=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!i&&!s&&!a)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function nh(e,t){if(t!==void 0&&Ui(t),e<=yt)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=gr(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${t})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var xc=new WeakMap,zn=class{ORDER;BITS;BYTES;isLE;ZERO=yt;ONE=nt;_lengths;_mod;constructor(t,r={}){if(t<=nt)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:i}=nh(t,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=i,Object.freeze(this)}create(t){return it(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return yt<=t&&t<this.ORDER}is0(t){return t===yt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&nt)===nt}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 rh(this,t,r)}div(t,r){return it(t*gc(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 gc(t,this.ORDER)}sqrt(t){let r=xc.get(this);return r||xc.set(this,r=th(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?ki(t,this.BYTES):Vn(t,this.BYTES)}fromBytes(t,r=!1){Y(t);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:a}=this;if(n){if(t.length<1||!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 c=i?ne(t):qe(t);if(a&&(c=it(c,s)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return tn(this,t)}cmov(t,r,n){return zt(n,"condition"),n?r:t}};Object.freeze(zn.prototype);function br(e,t={}){return new zn(e,t)}function Cc(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=nt)throw new Error("field order must be greater than 1");let t=gr(e-nt);return Math.ceil(t/8)}function Vi(e){let t=Cc(e);return t+Math.ceil(t/2)}function qi(e,t,r=!1){Y(e);let n=e.length,o=Cc(t),i=Math.max(Vi(t),16);if(n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?ne(e):qe(e),a=it(s,t-nt)+nt;return r?ki(a,o):Vn(a,o)}var xr=BigInt(0),He=BigInt(1);function en(e,t){let r=t.negate();return e?r:t}function je(e,t){let r=tn(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Dc(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function zi(e,t){Dc(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,i=Qr(e),s=BigInt(e);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function _c(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+=He);let u=t*n,f=u+Math.abs(a)-1,l=a===0,h=a<0,m=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:h,isNegF:m,offsetF:u}}var Hi=new WeakMap,Pc=new WeakMap;function ji(e){return Pc.get(e)||1}function Bc(e){if(e!==xr)throw new Error("invalid wNAF")}var wr=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>xr;)r&He&&(n=n.add(o)),o=o.double(),r>>=He;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=zi(r,this.bits),i=[],s=t,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let u=1;u<o;u++)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=zi(t,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:h,offsetF:m}=_c(n,a,s);n=c,f?i=i.add(en(h,r[m])):o=o.add(en(l,r[u]))}return Bc(n),{p:o,f:i}}wNAFUnsafe(t,r,n,o=this.ZERO){let i=zi(t,this.bits);for(let s=0;s<i.windows&&n!==xr;s++){let{nextN:a,offset:c,isZero:u,isNeg:f}=_c(n,s,i);if(n=a,!u){let l=r[c];o=o.add(f?l.negate():l)}}return Bc(n),o}getPrecomputes(t,r,n){let o=Hi.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Hi.set(r,o))),o}cached(t,r,n){let o=ji(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let i=ji(t);return i===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,t,n),r,o)}createCache(t,r){Dc(r,this.bits),Pc.set(t,r),Hi.delete(t)}hasCache(t){return ji(t)!==1}};function Oc(e,t,r,n){let o=t,i=e.ZERO,s=e.ZERO;for(;r>xr||n>xr;)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 Rc(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Mi(t),t}else return br(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 c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>xr))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Rc(t.p,r.Fp,n),i=Rc(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}}function jn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var _e=BigInt(0),lt=BigInt(1),Yi=BigInt(2),oh=BigInt(8);function ih(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 Fc(e,t={}){let r=t,n=Hn("edwards",e,r,r.FpFnLE),{Fp:o,Fn:i}=n,s=n.CURVE,{h:a}=s;jt(r,{},{uvRatio:"function"});let c=Yi<<BigInt(i.BYTES*8)-lt,u=v=>o.create(v),f=r.uvRatio===void 0?(v,y)=>{try{return{isValid:!0,value:o.sqrt(o.div(v,y))}}catch{return{isValid:!1,value:_e}}}:r.uvRatio;if(!ih(o,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function l(v,y,S=!1){let A=S?lt:_e;return yr("coordinate "+v,y,A,c),y}function h(v){if(!(v instanceof m))throw new Error("EdwardsPoint expected")}class m{static BASE=new m(s.Gx,s.Gy,lt,u(s.Gx*s.Gy));static ZERO=new m(_e,lt,lt,_e);static Fp=o;static Fn=i;X;Y;Z;T;constructor(y,S,A,_){this.X=l("x",y),this.Y=l("y",S),this.Z=l("z",A,!0),this.T=l("t",_),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){if(y instanceof m)throw new Error("extended point not allowed");let{x:S,y:A}=y||{};return l("x",S),l("y",A),new m(S,A,lt,u(S*A))}static fromBytes(y,S=!1){let A=o.BYTES,{a:_,d:U}=s;y=Jr(Y(y,A,"point")),zt(S,"zip215");let F=Jr(y),M=y[A-1];F[A-1]=M&-129;let L=ne(F),w=S?c:o.ORDER;yr("point.y",L,_e,w);let C=u(L*L),N=u(C-lt),P=u(U*C-_),{isValid:d,value:g}=f(N,P);if(!d)throw new Error("bad point: invalid y coordinate");let T=(g&lt)===lt,b=(M&128)!==0;if(!S&&g===_e&&b)throw new Error("bad point: x=0 and x_0=1");return b!==T&&(g=u(-g)),m.fromAffine({x:g,y:L})}static fromHex(y,S=!1){return m.fromBytes(mr(y),S)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,S=!0){return E.createCache(this,y),S||this.multiply(Yi),this}assertValidity(){let y=this,{a:S,d:A}=s;if(y.is0())throw new Error("bad point: ZERO");let{X:_,Y:U,Z:F,T:M}=y,L=u(_*_),w=u(U*U),C=u(F*F),N=u(C*C),P=u(L*S),d=u(C*u(P+w)),g=u(N+u(A*u(L*w)));if(d!==g)throw new Error("bad point: equation left != right (1)");let T=u(_*U),b=u(F*M);if(T!==b)throw new Error("bad point: equation left != right (2)")}equals(y){h(y);let{X:S,Y:A,Z:_}=this,{X:U,Y:F,Z:M}=y,L=u(S*M),w=u(U*_),C=u(A*M),N=u(F*_);return L===w&&C===N}is0(){return this.equals(m.ZERO)}negate(){return new m(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:y}=s,{X:S,Y:A,Z:_}=this,U=u(S*S),F=u(A*A),M=u(Yi*u(_*_)),L=u(y*U),w=S+A,C=u(u(w*w)-U-F),N=L+F,P=N-M,d=L-F,g=u(C*P),T=u(N*d),b=u(C*d),x=u(P*N);return new m(g,T,x,b)}add(y){h(y);let{a:S,d:A}=s,{X:_,Y:U,Z:F,T:M}=this,{X:L,Y:w,Z:C,T:N}=y,P=u(_*L),d=u(U*w),g=u(M*A*N),T=u(F*C),b=u((_+U)*(L+w)-P-d),x=T-g,I=T+g,R=u(d-S*P),D=u(b*x),k=u(I*R),$=u(b*R),j=u(x*I);return new m(D,k,j,$)}subtract(y){return h(y),this.add(y.negate())}multiply(y){if(!i.isValidNot0(y))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:S,f:A}=E.cached(this,y,_=>je(m,_));return je(m,[S,A])[0]}multiplyUnsafe(y){if(!i.isValid(y))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return y===_e?m.ZERO:this.is0()||y===lt?this:E.unsafe(this,y,S=>je(m,S))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(y){let S=this,A=y,{X:_,Y:U,Z:F}=S,M=S.is0();A==null&&(A=M?oh:o.inv(F));let L=u(_*A),w=u(U*A),C=o.mul(F,A);if(M)return{x:_e,y:lt};if(C!==lt)throw new Error("invZ was invalid");return{x:L,y:w}}clearCofactor(){return a===lt?this:this.multiplyUnsafe(a)}toBytes(){let{x:y,y:S}=this.toAffine(),A=o.toBytes(S);return A[A.length-1]|=y&lt?128:0,A}toHex(){return pr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let E=new wr(m,i.BITS);return i.BITS>=8&&m.BASE.precompute(8),Object.freeze(m.prototype),Object.freeze(m),m}var Yn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){Ki()}static fromHex(t){Ki()}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 pr(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.ep.precompute(t,r),this}};function Lc(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;jt(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:i}=o,{BASE:s,Fp:a,Fn:c}=e,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(Ht(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?Wr:o.randomBytes,h=o.adjustScalarBytes===void 0?d=>d:o.adjustScalarBytes,m=o.domain===void 0?(d,g,T)=>{if(zt(T,"phflag"),g.length||T)throw new Error("Contexts/pre-hash are not supported");return d}:o.domain;function E(d){return c.create(ne(d))}function v(d){let g=L.secretKey;Y(d,L.secretKey,"secretKey");let T=Y(n(d),2*g,"hashedSecretKey"),b=h(T.slice(0,g)),x=T.slice(g,2*g),I=E(b);return{head:b,prefix:x,scalar:I}}function y(d){let{head:g,prefix:T,scalar:b}=v(d),x=s.multiply(b),I=x.toBytes();return{head:g,prefix:T,scalar:b,point:x,pointBytes:I}}function S(d){return y(d).pointBytes}function A(d=Uint8Array.of(),...g){let T=ct(...g);return E(n(m(T,Y(d,void 0,"context"),!!i)))}function _(d,g,T={}){d=Y(d,void 0,"message"),i&&(d=i(d));let{prefix:b,scalar:x,pointBytes:I}=y(g),R=A(T.context,b,d),D=s.multiply(R).toBytes(),k=A(T.context,D,I,d),$=c.create(R+k*x);if(!c.isValid($))throw new Error("sign failed: invalid s");let j=ct(D,c.toBytes($));return Y(j,L.signature,"result")}let U={zip215:o.zip215};function F(d,g,T,b=U){let{context:x}=b,I=b.zip215===void 0?!!U.zip215:b.zip215,R=L.signature;d=Y(d,R,"signature"),g=Y(g,void 0,"message"),T=Y(T,L.publicKey,"publicKey"),I!==void 0&&zt(I,"zip215"),i&&(g=i(g));let D=R/2,k=d.subarray(0,D),$=ne(d.subarray(D,R)),j,G,q;try{j=e.fromBytes(T,I),G=e.fromBytes(k,I),q=s.multiplyUnsafe($)}catch{return!1}if(!I&&j.isSmallOrder())return!1;let at=A(x,k,T,g);return G.add(j.multiplyUnsafe(at)).subtract(q).clearCofactor().is0()}let M=a.BYTES,L={secretKey:M,publicKey:M,signature:2*M,seed:M};function w(d){return d=d===void 0?l(L.seed):d,Y(d,L.seed,"seed")}function C(d){return Ve(d)&&d.length===L.secretKey}function N(d,g){try{return!!e.fromBytes(d,g===void 0?U.zip215:g)}catch{return!1}}let P={getExtendedPublicKey:y,randomSecretKey:w,isValidSecretKey:C,isValidPublicKey:N,toMontgomery(d){let{y:g}=e.fromBytes(d),T=L.publicKey,b=T===32;if(!b&&T!==57)throw new Error("only defined for 25519 and 448");let x=b?a.div(lt+g,lt-g):a.div(g-lt,g+lt);return a.toBytes(x)},toMontgomerySecret(d){let g=L.secretKey;Y(d,g);let T=n(d.subarray(0,g));return h(T).subarray(0,g)}};return Object.freeze(L),Object.freeze(P),Object.freeze({keygen:jn(w,S),getPublicKey:S,sign:_,verify:F,utils:P,Point:e,lengths:L})}function rn(e,t){if(Ht(e),Ht(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(e<0||e>2**(8*t)-1)throw new Error("invalid I2OSP input: "+e);let r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=e&255,e>>>=8;return new Uint8Array(r)}function sh(e,t){let r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}function ah(e){if(!Ve(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof e=="string"?qn(e):e;if(t.length===0)throw new Error("DST must be non-empty");return t}function Zi(e,t,r,n){Y(e),Ht(r),t=ah(t),t.length>255&&(t=n(ct(qn("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:i}=n,s=Math.ceil(r/o);if(r>65535||s>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=ct(t,rn(t.length,1)),c=new Uint8Array(i),u=rn(r,2),f=new Array(s),l=n(ct(c,e,u,rn(0,1),a));f[0]=n(ct(l,rn(1,1),a));for(let m=1;m<s;m++){let E=[sh(l,f[m-1]),rn(m+1,1),a];f[m]=n(ct(...E))}return ct(...f).slice(0,r)}var Nc="HashToScalar-";var ch=BigInt(0),ye=BigInt(1),Uc=BigInt(2);var uh=BigInt(5),fh=BigInt(8),Er=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Ji={p:Er,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:fh,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function lh(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=Er,a=e*e%i*e%i,c=J(a,Uc,i)*a%i,u=J(c,ye,i)*e%i,f=J(u,uh,i)*u%i,l=J(f,t,i)*f%i,h=J(l,r,i)*l%i,m=J(h,n,i)*h%i,E=J(m,o,i)*m%i,v=J(E,o,i)*m%i,y=J(v,t,i)*f%i;return{pow_p_5_8:J(y,Uc,i)*e%i,b2:a}}function dh(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Gi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Qi(e,t){let r=Er,n=it(t*t*t,r),o=it(n*n*t,r),i=lh(e*o).pow_p_5_8,s=it(e*n*i,r),a=it(t*s*s,r),c=s,u=it(s*Gi,r),f=a===e,l=a===it(-e,r),h=a===it(-e*Gi,r);return f&&(s=c),(l||h)&&(s=u),me(s,r)&&(s=it(-s,r)),{isValid:f||l,value:s}}var Re=Fc(Ji,{uvRatio:Qi}),Be=Re.Fp,$c=Re.Fn;function hh(e){return Lc(Re,kn,Object.assign({adjustScalarBytes:dh,zip215:!0},e))}var Mc=hh({});var Wi=Gi,ph=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),mh=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),yh=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),gh=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),kc=e=>Qi(ye,e),bh=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Xi=e=>Be.create(ne(e)&bh);function Kc(e){let{d:t}=Ji,r=Er,n=S=>Be.create(S),o=n(Wi*e*e),i=n((o+ye)*yh),s=BigInt(-1),a=n((s-t*o)*n(o+t)),{isValid:c,value:u}=Qi(i,a),f=n(u*e);me(f,r)||(f=n(-f)),c||(u=f),c||(s=o);let l=n(s*(o-ye)*gh-a),h=u*u,m=n((u+u)*a),E=n(l*ph),v=n(ye-h),y=n(ye+h);return new Re(n(m*y),n(v*E),n(E*y),n(m*v))}var De=class e extends Yn{static BASE=new e(Re.BASE);static ZERO=new e(Re.ZERO);static Fp=Be;static Fn=$c;constructor(t){super(t)}static fromAffine(t){return new e(Re.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static fromBytes(t){Rt(t,32);let{a:r,d:n}=Ji,o=Er,i=U=>Be.create(U),s=Xi(t);if(!mc(Be.toBytes(s),t)||me(s,o))throw new Error("invalid ristretto255 encoding 1");let a=i(s*s),c=i(ye+r*a),u=i(ye-r*a),f=i(c*c),l=i(u*u),h=i(r*n*f-l),{isValid:m,value:E}=kc(i(h*l)),v=i(E*u),y=i(E*v*h),S=i((s+s)*v);me(S,o)&&(S=i(-S));let A=i(c*y),_=i(S*A);if(!m||me(_,o)||A===ch)throw new Error("invalid ristretto255 encoding 2");return new e(new Re(S,A,ye,_))}static fromHex(t){return e.fromBytes(jr(t))}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,i=Er,s=y=>Be.create(y),a=s(s(n+r)*s(n-r)),c=s(t*r),u=s(c*c),{value:f}=kc(s(a*u)),l=s(f*a),h=s(f*c),m=s(l*h*o),E;if(me(o*m,i)){let y=s(r*Wi),S=s(t*Wi);t=y,r=S,E=s(l*mh)}else E=h;me(t*m,i)&&(r=s(-r));let v=s((n-r)*E);return me(v,i)&&(v=s(-v)),Be.toBytes(v)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:i}=t.ep,s=u=>Be.create(u),a=s(r*i)===s(n*o),c=s(n*i)===s(r*o);return a||c}is0(){return this.equals(e.ZERO)}};Object.freeze(De.BASE);Object.freeze(De.ZERO);Object.freeze(De.prototype);Object.freeze(De);var xh=Object.freeze({Point:De,hashToCurve(e,t){let r=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=Zi(e,r,64,kn);return xh.deriveToCurve(n)},hashToScalar(e,t={DST:Nc}){let r=Zi(e,t.DST,64,kn);return $c.create(ne(r))},deriveToCurve(e){Rt(e,64);let t=Xi(e.subarray(0,32)),r=Kc(t),n=Xi(e.subarray(32,64)),o=Kc(n);return new De(r.add(o))}});var nn=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Zn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Vc={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Zn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Ut=Vc;var Gn=32;var ts,wh=(async()=>{try{return await Ut.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Eh(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Ut.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Ut.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Sh(e,t,r){return Mc.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function qc(e,t,r){return ts==null&&(ts=await wh),ts?Eh(e,t,r):Sh(e,t,r)}function Wn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Xn=class{type="Ed25519";raw;constructor(t){this.raw=es(t,Gn)}toMultihash(){return St.digest(lr(this))}toCID(){return H.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=qc(this.raw,r,t);return Wn(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}};function rs(e){return e=es(e,Gn),new Xn(e)}function es(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new et(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Th=Math.pow(2,7),Ah=Math.pow(2,14),Ih=Math.pow(2,21),ns=Math.pow(2,28),os=Math.pow(2,35),is=Math.pow(2,42),ss=Math.pow(2,49),Q=128,bt=127;function oe(e){if(e<Th)return 1;if(e<Ah)return 2;if(e<Ih)return 3;if(e<ns)return 4;if(e<os)return 5;if(e<is)return 6;if(e<ss)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function on(e,t,r=0){switch(oe(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 as(e,t){let r=e[t],n=0;if(n+=r&bt,r<Q||(r=e[t+1],n+=(r&bt)<<7,r<Q)||(r=e[t+2],n+=(r&bt)<<14,r<Q)||(r=e[t+3],n+=(r&bt)<<21,r<Q)||(r=e[t+4],n+=(r&bt)*ns,r<Q)||(r=e[t+5],n+=(r&bt)*os,r<Q)||(r=e[t+6],n+=(r&bt)*is,r<Q)||(r=e[t+7],n+=(r&bt)*ss,r<Q))return n;throw new RangeError("Could not decode varint")}function Ch(e,t){let r=e.get(t),n=0;if(n+=r&bt,r<Q||(r=e.get(t+1),n+=(r&bt)<<7,r<Q)||(r=e.get(t+2),n+=(r&bt)<<14,r<Q)||(r=e.get(t+3),n+=(r&bt)<<21,r<Q)||(r=e.get(t+4),n+=(r&bt)*ns,r<Q)||(r=e.get(t+5),n+=(r&bt)*os,r<Q)||(r=e.get(t+6),n+=(r&bt)*is,r<Q)||(r=e.get(t+7),n+=(r&bt)*ss,r<Q))return n;throw new RangeError("Could not decode varint")}function cs(e,t=0){return e instanceof Uint8Array?as(e,t):Ch(e,t)}var us=new Float32Array([-0]),Pe=new Uint8Array(us.buffer);function Hc(e,t,r){us[0]=e,t[r]=Pe[0],t[r+1]=Pe[1],t[r+2]=Pe[2],t[r+3]=Pe[3]}function jc(e,t){return Pe[0]=e[t],Pe[1]=e[t+1],Pe[2]=e[t+2],Pe[3]=e[t+3],us[0]}var fs=new Float64Array([-0]),xt=new Uint8Array(fs.buffer);function Yc(e,t,r){fs[0]=e,t[r]=xt[0],t[r+1]=xt[1],t[r+2]=xt[2],t[r+3]=xt[3],t[r+4]=xt[4],t[r+5]=xt[5],t[r+6]=xt[6],t[r+7]=xt[7]}function Zc(e,t){return xt[0]=e[t],xt[1]=e[t+1],xt[2]=e[t+2],xt[3]=e[t+3],xt[4]=e[t+4],xt[5]=e[t+5],xt[6]=e[t+6],xt[7]=e[t+7],fs[0]}var Bh=BigInt(Number.MAX_SAFE_INTEGER),Rh=BigInt(Number.MIN_SAFE_INTEGER),Dt=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 Ye;if(t<Bh&&t>Rh)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>Gc&&(o=0n,++n>Gc&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ye;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):Ye}},Ye=new Dt(0,0);Ye.toBigInt=function(){return 0n};Ye.zzEncode=Ye.zzDecode=function(){return this};Ye.length=function(){return 1};var Gc=4294967296n;function Wc(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 Xc(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 ls(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 Yt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Jn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var ds=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,Yt(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 Yt(this,4);return Jn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Yt(this,4);return Jn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Yt(this,4);let t=jc(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Yt(this,4);let t=Zc(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 Yt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Xc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Yt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Yt(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 Dt(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 Yt(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 Yt(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 Yt(this,8);let t=Jn(this.buf,this.pos+=4),r=Jn(this.buf,this.pos+=4);return new Dt(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=as(this.buf,this.pos);return this.pos+=oe(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 sn(e){return new ds(e instanceof Uint8Array?e:e.subarray())}function Sr(e,t,r){let n=sn(e);return t.decode(n,void 0,r)}function hs(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return _t(s);o+s>t&&(n=_t(t),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}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 ps(){}var ys=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Dh=hs();function Ph(e){return globalThis.Buffer!=null?_t(e):Dh(e)}var cn=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ze(ps,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 gs((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(Qn,10,Dt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Dt.fromBigInt(t);return this._push(Qn,r.length(),r)}uint64Number(t){return this._push(on,oe(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=Dt.fromBigInt(t).zzEncode();return this._push(Qn,r.length(),r)}sint64Number(t){let r=Dt.fromNumber(t).zzEncode();return this._push(Qn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ms,1,t?1:0)}fixed32(t){return this._push(an,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Dt.fromBigInt(t);return this._push(an,4,r.lo)._push(an,4,r.hi)}fixed64Number(t){let r=Dt.fromNumber(t);return this._push(an,4,r.lo)._push(an,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(Hc,4,t)}double(t){return this._push(Yc,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(ms,1,0):this.uint32(r)._push(Fh,r,t)}string(t){let r=Wc(t);return r!==0?this.uint32(r)._push(ls,r,t):this._push(ms,1,0)}fork(){return this.states=new ys(this),this.head=this.tail=new Ze(ps,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(ps,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=Ph(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function ms(e,t,r){t[r]=e&255}function Oh(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var gs=class extends Ze{next;constructor(t,r){super(Oh,t,r),this.next=void 0}};function Qn(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 an(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 Fh(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(cn.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Lh,t,e),this},cn.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Nh,t,e),this});function Lh(e,t,r){t.set(e,r)}function Nh(e,t,r){e.length<40?ls(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(V(e),r)}function bs(){return new cn}function vr(e,t){let r=bs();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Tr(e,t,r){let n=sn(e);yield*t.stream(n,void 0,"$",r)}var to={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function eo(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function un(e){function t(i){if(e[i.toString()]==null)throw new Error("Invalid enum value");return e[i]}let r=function(s,a){let c=t(s);a.int32(c)},n=function(s){let a=s.int32();return t(a)},o=function*(s){let a=s.int32();yield t(a)};return eo("enum",to.VARINT,r,n,o)}function Ar(e,t,r){return eo("message",to.LENGTH_DELIMITED,e,t,r)}var tt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(tt||(tt={}));var xs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(xs||(xs={}));(function(e){e.codec=()=>un(xs)})(tt||(tt={}));var ie;(function(e){let t;e.codec=()=>(t==null&&(t=Ar((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),tt.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=tt.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:tt.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(f&7);break}}}})),t);function r(i){return vr(i,e.codec())}e.encode=r;function n(i,s){return Sr(i,e.codec(),s)}e.decode=n;function o(i,s){return Tr(i,e.codec(),s)}e.stream=o})(ie||(ie={}));var ws;(function(e){let t;e.codec=()=>(t==null&&(t=Ar((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),tt.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=tt.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:tt.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(f&7);break}}}})),t);function r(i){return vr(i,e.codec())}e.encode=r;function n(i,s){return Sr(i,e.codec(),s)}e.decode=n;function o(i,s){return Tr(i,e.codec(),s)}e.stream=o})(ws||(ws={}));var ln={};Et(ln,{MAX_RSA_KEY_SIZE:()=>Es,generateRSAKeyPair:()=>nu,jwkToJWKKeyPair:()=>ou,jwkToPkcs1:()=>$h,jwkToPkix:()=>As,jwkToRSAPrivateKey:()=>Bs,pkcs1MessageToJwk:()=>vs,pkcs1MessageToRSAPrivateKey:()=>Is,pkcs1ToJwk:()=>Kh,pkcs1ToRSAPrivateKey:()=>ru,pkixMessageToJwk:()=>Ts,pkixMessageToRSAPublicKey:()=>_s,pkixToJwk:()=>Mh,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=ln.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return H.createV1(114,this._multihash)}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){return eu(this.jwk,r,t,n)}},fn=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=ln.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}sign(t,r){return tu(this.jwk,t,r)}};var Es=8192,Ss=18,Uh=1062,kh=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Kh(e){let t=le(e);return vs(t)}function vs(e){return{n:z(e[1],"base64url"),e:z(e[2],"base64url"),d:z(e[3],"base64url"),p:z(e[4],"base64url"),q:z(e[5],"base64url"),dp:z(e[6],"base64url"),dq:z(e[7],"base64url"),qi:z(e[8],"base64url"),kty:"RSA"}}function $h(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 et("JWK was missing components");return ve([It(Uint8Array.from([0])),It(V(e.n,"base64url")),It(V(e.e,"base64url")),It(V(e.d,"base64url")),It(V(e.p,"base64url")),It(V(e.q,"base64url")),It(V(e.dp,"base64url")),It(V(e.dq,"base64url")),It(V(e.qi,"base64url"))]).subarray()}function Mh(e){let t=le(e,{offset:0});return Ts(t)}function Ts(e){let t=le(e[1],{offset:0});return{kty:"RSA",n:z(t[0],"base64url"),e:z(t[1],"base64url")}}function As(e){if(e.n==null||e.e==null)throw new et("JWK was missing components");return ve([kh,Pn(ve([It(V(e.n,"base64url")),It(V(e.e,"base64url"))]))]).subarray()}function ru(e){let t=le(e);return Is(t)}function Is(e){let t=vs(e);return Bs(t)}function Cs(e,t){if(e.byteLength>=Uh)throw new rr("Key size is too large");let r=le(e,{offset:0});return _s(r,e,t)}function _s(e,t,r){let n=Ts(e);if(r==null){let o=hr(ie.encode({Type:tt.RSA,Data:t}));r=Vt(Ss,o)}return new Ir(n,r)}function Bs(e){if(su(e)>Es)throw new et("Key size is too large");let t=ou(e),r=hr(ie.encode({Type:tt.RSA,Data:As(t.publicKey)})),n=Vt(Ss,r);return new fn(t.privateKey,new Ir(t.publicKey,n))}async function nu(e){if(e>Es)throw new et("Key size is too large");let t=await iu(e),r=hr(ie.encode({Type:tt.RSA,Data:As(t.publicKey)})),n=Vt(Ss,r);return new fn(t.privateKey,new Ir(t.publicKey,n))}function ou(e){if(e==null)throw new et("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function iu(e,t){let r=await Ut.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Vh(r,t);return{privateKey:n[0],publicKey:n[1]}}async function tu(e,t,r){let n=await Ut.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Ut.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function eu(e,t,r,n){let o=await Ut.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Ut.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),i}async function Vh(e,t){if(e.privateKey==null||e.publicKey==null)throw new et("Private and public key are required");let r=await Promise.all([Ut.get().subtle.exportKey("jwk",e.privateKey),Ut.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function su(e){if(e.kty!=="RSA")throw new et("invalid key type");if(e.n==null)throw new et("invalid key modulus");return V(e.n,"base64url").length*8}var ro=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(On(t),Rt(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),he(o)}update(t){return dr(this),this.iHash.update(t),this}digestInto(t){dr(this),Fn(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),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: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()}},au=(()=>{let e=((t,r,n)=>new ro(t,r).update(n).digest());return e.create=(t,r)=>new ro(t,r),e})();var cu=(e,t)=>(e+(e>=0?t:-t)/uu)/t;function qh(e,t,r){yr("scalar",e,se,r);let[[n,o],[i,s]]=t,a=cu(s*e,r),c=cu(-o*e,r),u=e-a*n-c*i,f=-a*o-c*s,l=u<se,h=f<se;l&&(u=-u),h&&(f=-f);let m=Qr(Math.ceil(gr(r)/2))+Oe;if(u<se||u>=m||f<se||f>=m)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:h,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 Rs(e,t){jt(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return zt(r.lowS,"lowS"),zt(r.prehash,"prehash"),r.format!==void 0&&Ds(r.format),r}var Ps=class extends Error{constructor(t=""){super(t)}},Zt={Err:Ps,_tlv:{encode:(e,t)=>{let{Err:r}=Zt;if(Ht(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=Xr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?Xr(o.length/2|128):"";return Xr(e)+i+o+t},decode(e,t){let{Err:r}=Zt;t=Y(t,void 0,"DER data");let n=0;if(e<0||e>255)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 u=t.subarray(n,n+c);if(u.length!==c)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+=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}=Zt;if(Mn(e),e<se)throw new t("integer: negative integers are not allowed");let r=Xr(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}=Zt;if(e.length<1)throw new t("invalid signature integer: empty");if(e[0]&128)throw new t("invalid signature integer: negative");if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return qe(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Zt,o=Y(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:a,l:c}=n.decode(2,i),{v:u,l:f}=n.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Zt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),i=n+o;return t.encode(48,i)}};Object.freeze(Zt._tlv);Object.freeze(Zt._int);Object.freeze(Zt);var se=BigInt(0),Oe=BigInt(1),uu=BigInt(2),no=BigInt(3),zh=BigInt(4);function fu(e,t={}){let r=Hn("weierstrass",e,t),n=r.Fp,o=r.Fn,i=r.CURVE,{h:s,n:a}=i;jt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=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=du(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(P,d,g){if(u&&d.is0())return Uint8Array.of(0);let{x:T,y:b}=d.toAffine(),x=n.toBytes(T);if(zt(g,"isCompressed"),g){l();let I=!n.isOdd(b);return ct(lu(I),x)}else return ct(Uint8Array.of(4),x,n.toBytes(b))}function m(P){Y(P,void 0,"Point");let{publicKey:d,publicKeyUncompressed:g}=f,T=P.length,b=P[0],x=P.subarray(1);if(u&&T===1&&b===0)return{x:n.ZERO,y:n.ZERO};if(T===d&&(b===2||b===3)){let I=n.fromBytes(x);if(!n.isValid(I))throw new Error("bad point: is not on curve, wrong x");let R=y(I),D;try{D=n.sqrt(R)}catch(j){let G=j instanceof Error?": "+j.message:"";throw new Error("bad point: is not on curve, sqrt error"+G)}l();let k=n.isOdd(D);return(b&1)===1!==k&&(D=n.neg(D)),{x:I,y:D}}else if(T===g&&b===4){let I=n.BYTES,R=n.fromBytes(x.subarray(0,I)),D=n.fromBytes(x.subarray(I,I*2));if(!S(R,D))throw new Error("bad point: is not on curve");return{x:R,y:D}}else throw new Error(`bad point: got length ${T}, expected compressed=${d} or uncompressed=${g}`)}let E=t.toBytes===void 0?h:t.toBytes,v=t.fromBytes===void 0?m:t.fromBytes;function y(P){let d=n.sqr(P),g=n.mul(d,P);return n.add(n.add(g,n.mul(P,i.a)),i.b)}function S(P,d){let g=n.sqr(d),T=y(P);return n.eql(g,T)}if(!S(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let A=n.mul(n.pow(i.a,no),zh),_=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(A,_)))throw new Error("bad curve params: a or b");function U(P,d,g=!1){if(!n.isValid(d)||g&&n.is0(d))throw new Error(`bad point coordinate ${P}`);return d}function F(P){if(!(P instanceof w))throw new Error("Weierstrass Point expected")}function M(P){if(!c||!c.basises)throw new Error("no endo");return qh(P,c.basises,o.ORDER)}function L(P,d,g,T,b){return g=new w(n.mul(g.X,P),g.Y,g.Z),d=en(T,d),g=en(b,g),d.add(g)}class w{static BASE=new w(i.Gx,i.Gy,n.ONE);static ZERO=new w(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(d,g,T){this.X=U("x",d),this.Y=U("y",g,!0),this.Z=U("z",T),Object.freeze(this)}static CURVE(){return i}static fromAffine(d){let{x:g,y:T}=d||{};if(!d||!n.isValid(g)||!n.isValid(T))throw new Error("invalid affine point");if(d instanceof w)throw new Error("projective point not allowed");return n.is0(g)&&n.is0(T)?w.ZERO:new w(g,T,n.ONE)}static fromBytes(d){let g=w.fromAffine(v(Y(d,void 0,"point")));return g.assertValidity(),g}static fromHex(d){return w.fromBytes(mr(d))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=8,g=!0){return N.createCache(this,d),g||this.multiply(no),this}assertValidity(){let d=this;if(d.is0()){if(t.allowInfinityPoint&&n.is0(d.X)&&n.eql(d.Y,n.ONE)&&n.is0(d.Z))return;throw new Error("bad point: ZERO")}let{x:g,y:T}=d.toAffine();if(!n.isValid(g)||!n.isValid(T))throw new Error("bad point: x or y not field elements");if(!S(g,T))throw new Error("bad point: equation left != right");if(!d.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:d}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(d)}equals(d){F(d);let{X:g,Y:T,Z:b}=this,{X:x,Y:I,Z:R}=d,D=n.eql(n.mul(g,R),n.mul(x,b)),k=n.eql(n.mul(T,R),n.mul(I,b));return D&&k}negate(){return new w(this.X,n.neg(this.Y),this.Z)}double(){let{a:d,b:g}=i,T=n.mul(g,no),{X:b,Y:x,Z:I}=this,R=n.ZERO,D=n.ZERO,k=n.ZERO,$=n.mul(b,b),j=n.mul(x,x),G=n.mul(I,I),q=n.mul(b,x);return q=n.add(q,q),k=n.mul(b,I),k=n.add(k,k),R=n.mul(d,k),D=n.mul(T,G),D=n.add(R,D),R=n.sub(j,D),D=n.add(j,D),D=n.mul(R,D),R=n.mul(q,R),k=n.mul(T,k),G=n.mul(d,G),q=n.sub($,G),q=n.mul(d,q),q=n.add(q,k),k=n.add($,$),$=n.add(k,$),$=n.add($,G),$=n.mul($,q),D=n.add(D,$),G=n.mul(x,I),G=n.add(G,G),$=n.mul(G,q),R=n.sub(R,$),k=n.mul(G,j),k=n.add(k,k),k=n.add(k,k),new w(R,D,k)}add(d){F(d);let{X:g,Y:T,Z:b}=this,{X:x,Y:I,Z:R}=d,D=n.ZERO,k=n.ZERO,$=n.ZERO,j=i.a,G=n.mul(i.b,no),q=n.mul(g,x),at=n.mul(T,I),ut=n.mul(b,R),ft=n.add(g,T),ot=n.add(x,I);ft=n.mul(ft,ot),ot=n.add(q,at),ft=n.sub(ft,ot),ot=n.add(g,b);let Tt=n.add(x,R);return ot=n.mul(ot,Tt),Tt=n.add(q,ut),ot=n.sub(ot,Tt),Tt=n.add(T,b),D=n.add(I,R),Tt=n.mul(Tt,D),D=n.add(at,ut),Tt=n.sub(Tt,D),$=n.mul(j,ot),D=n.mul(G,ut),$=n.add(D,$),D=n.sub(at,$),$=n.add(at,$),k=n.mul(D,$),at=n.add(q,q),at=n.add(at,q),ut=n.mul(j,ut),ot=n.mul(G,ot),at=n.add(at,ut),ut=n.sub(q,ut),ut=n.mul(j,ut),ot=n.add(ot,ut),q=n.mul(at,ot),k=n.add(k,q),q=n.mul(Tt,ot),D=n.mul(ft,D),D=n.sub(D,q),q=n.mul(ft,at),$=n.mul(Tt,$),$=n.add($,q),new w(D,k,$)}subtract(d){return F(d),this.add(d.negate())}is0(){return this.equals(w.ZERO)}multiply(d){let{endo:g}=t;if(!o.isValidNot0(d))throw new RangeError("invalid scalar: out of range");let T,b,x=I=>N.cached(this,I,R=>je(w,R));if(g){let{k1neg:I,k1:R,k2neg:D,k2:k}=M(d),{p:$,f:j}=x(R),{p:G,f:q}=x(k);b=j.add(q),T=L(g.beta,$,G,I,D)}else{let{p:I,f:R}=x(d);T=I,b=R}return je(w,[T,b])[0]}multiplyUnsafe(d){let{endo:g}=t,T=this,b=d;if(!o.isValid(b))throw new RangeError("invalid scalar: out of range");if(b===se||T.is0())return w.ZERO;if(b===Oe)return T;if(N.hasCache(this))return this.multiply(b);if(g){let{k1neg:x,k1:I,k2neg:R,k2:D}=M(b),{p1:k,p2:$}=Oc(w,T,I,D);return L(g.beta,k,$,x,R)}else return N.unsafe(T,b)}toAffine(d){let g=this,T=d,{X:b,Y:x,Z:I}=g;if(n.eql(I,n.ONE))return{x:b,y:x};let R=g.is0();T==null&&(T=R?n.ONE:n.inv(I));let D=n.mul(b,T),k=n.mul(x,T),$=n.mul(I,T);if(R)return{x:n.ZERO,y:n.ZERO};if(!n.eql($,n.ONE))throw new Error("invZ was invalid");return{x:D,y:k}}isTorsionFree(){let{isTorsionFree:d}=t;return s===Oe?!0:d?d(w,this):N.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:d}=t;return s===Oe?this:d?d(w,this):this.multiplyUnsafe(s)}isSmallOrder(){return s===Oe?this.is0():this.clearCofactor().is0()}toBytes(d=!0){return zt(d,"isCompressed"),this.assertValidity(),E(w,this,d)}toHex(d=!0){return pr(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let C=o.BITS,N=new wr(w,t.endo?Math.ceil(C/2):C);return C>=8&&w.BASE.precompute(8),Object.freeze(w.prototype),Object.freeze(w),w}function lu(e){return Uint8Array.of(e?2:3)}function du(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Hh(e,t={}){let{Fn:r}=e,n=t.randomBytes===void 0?Wr:t.randomBytes,o=Object.assign(du(e.Fp,r),{seed:Math.max(Vi(r.ORDER),16)});function i(m){try{let E=r.fromBytes(m);return r.isValidNot0(E)}catch{return!1}}function s(m,E){let{publicKey:v,publicKeyUncompressed:y}=o;try{let S=m.length;return E===!0&&S!==v||E===!1&&S!==y?!1:!!e.fromBytes(m)}catch{return!1}}function a(m){return m=m===void 0?n(o.seed):m,qi(Y(m,o.seed,"seed"),r.ORDER)}function c(m,E=!0){return e.BASE.multiply(r.fromBytes(m)).toBytes(E)}function u(m){let{secretKey:E,publicKey:v,publicKeyUncompressed:y}=o,S=r._lengths;if(!Ve(m))return;let A=Y(m,void 0,"key").length,_=A===v||A===y,U=A===E||!!S?.includes(A);if(!(_&&U))return _}function f(m,E,v=!0){if(u(m)===!0)throw new Error("first arg must be private key");if(u(E)===!1)throw new Error("second arg must be public key");let y=r.fromBytes(m);return e.fromBytes(E).multiply(y).toBytes(v)}let l={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},h=jn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:h,Point:e,utils:l,lengths:o})}function hu(e,t,r={}){let n=t;On(n),jt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?Wr:r.randomBytes,i=r.hmac===void 0?(b,x)=>au(n,b,x):r.hmac,{Fp:s,Fn:a}=e,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:h,utils:m,lengths:E}=Hh(e,r),v={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},y=c*uu+Oe<s.ORDER;function S(b){let x=c>>Oe;return b>x}function A(b,x){if(!a.isValidNot0(x))throw new Error(`invalid signature ${b}: out of range 1..Point.Fn.ORDER`);return x}function _(){if(y)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function U(b,x){Ds(x);let I=E.signature,R=x==="compact"?I:x==="recovered"?I+1:void 0;return Y(b,R)}class F{r;s;recovery;constructor(x,I,R){if(this.r=A("r",x),this.s=A("s",I),R!=null){if(_(),![0,1,2,3].includes(R))throw new Error("invalid recovery id");this.recovery=R}Object.freeze(this)}static fromBytes(x,I=v.format){U(x,I);let R;if(I==="der"){let{r:j,s:G}=Zt.toSig(Y(x));return new F(j,G)}I==="recovered"&&(R=x[0],I="compact",x=x.subarray(1));let D=E.signature/2,k=x.subarray(0,D),$=x.subarray(D,D*2);return new F(a.fromBytes(k),a.fromBytes($),R)}static fromHex(x,I){return this.fromBytes(mr(x),I)}assertRecovery(){let{recovery:x}=this;if(x==null)throw new Error("invalid recovery id: must be present");return x}addRecoveryBit(x){return new F(this.r,this.s,x)}recoverPublicKey(x){let{r:I,s:R}=this,D=this.assertRecovery(),k=D===2||D===3?I+c:I;if(!s.isValid(k))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let $=s.toBytes(k),j=e.fromBytes(ct(lu((D&1)===0),$)),G=a.inv(k),q=L(Y(x,void 0,"msgHash")),at=a.create(-q*G),ut=a.create(R*G),ft=e.BASE.multiplyUnsafe(at).add(j.multiplyUnsafe(ut));if(ft.is0())throw new Error("invalid recovery: point at infinify");return ft.assertValidity(),ft}hasHighS(){return S(this.s)}toBytes(x=v.format){if(Ds(x),x==="der")return mr(Zt.hexFromSig(this));let{r:I,s:R}=this,D=a.toBytes(I),k=a.toBytes(R);return x==="recovered"?(_(),ct(Uint8Array.of(this.assertRecovery()),D,k)):ct(D,k)}toHex(x){return pr(this.toBytes(x))}}Object.freeze(F.prototype),Object.freeze(F);let M=r.bits2int===void 0?function(x){if(x.length>8192)throw new Error("input is too large");let I=qe(x),R=x.length*8-u;return R>0?I>>BigInt(R):I}:r.bits2int,L=r.bits2int_modN===void 0?function(x){return a.create(M(x))}:r.bits2int_modN,w=Qr(u);function C(b){return yr("num < 2^"+u,b,se,w),a.toBytes(b)}function N(b,x){return Y(b,void 0,"message"),x?Y(n(b),void 0,"prehashed message"):b}function P(b,x,I){let{lowS:R,prehash:D,extraEntropy:k}=Rs(I,v);b=N(b,D);let $=L(b),j=a.fromBytes(x);if(!a.isValidNot0(j))throw new Error("invalid private key");let G=[C(j),C($)];if(k!=null&&k!==!1){let ft=k===!0?o(E.secretKey):k;G.push(Y(ft,void 0,"extraEntropy"))}let q=ct(...G),at=$;function ut(ft){let ot=M(ft);if(!a.isValidNot0(ot))return;let Tt=a.inv(ot),er=e.BASE.multiply(ot).toAffine(),kr=a.create(er.x);if(kr===se)return;let In=a.create(Tt*a.create(at+kr*j));if(In===se)return;let xa=(er.x===kr?0:2)|Number(er.y&Oe),wa=In;return R&&S(In)&&(wa=a.neg(In),xa^=1),new F(kr,wa,y?void 0:xa)}return{seed:q,k2sig:ut}}function d(b,x,I={}){let{seed:R,k2sig:D}=P(b,x,I);return yc(n.outputLen,a.BYTES,i)(R,D).toBytes(I.format)}function g(b,x,I,R={}){let{lowS:D,prehash:k,format:$}=Rs(R,v);if(I=Y(I,void 0,"publicKey"),x=N(x,k),!Ve(b)){let j=b instanceof F?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+j)}U(b,$);try{let j=F.fromBytes(b,$),G=e.fromBytes(I);if(D&&j.hasHighS())return!1;let{r:q,s:at}=j,ut=L(x),ft=a.inv(at),ot=a.create(ut*ft),Tt=a.create(q*ft),er=e.BASE.multiplyUnsafe(ot).add(G.multiplyUnsafe(Tt));return er.is0()?!1:a.create(er.x)===q}catch{return!1}}function T(b,x,I={}){let{prehash:R}=Rs(I,v);return x=N(x,R),F.fromBytes(b,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:h,utils:m,lengths:E,Point:e,sign:d,verify:g,recoverPublicKey:T,Signature:F,hash:n})}var Fs={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},jh={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var pu=BigInt(2);function Yh(e){let t=Fs.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=J(f,r,t)*f%t,h=J(l,r,t)*f%t,m=J(h,pu,t)*u%t,E=J(m,o,t)*m%t,v=J(E,i,t)*E%t,y=J(v,a,t)*v%t,S=J(y,c,t)*y%t,A=J(S,a,t)*v%t,_=J(A,r,t)*f%t,U=J(_,s,t)*E%t,F=J(U,n,t)*u%t,M=J(F,pu,t);if(!Os.eql(Os.sqr(M),e))throw new Error("Cannot find square root");return M}var Os=br(Fs.p,{sqrt:Yh}),Zh=fu(Fs,{Fp:Os,endo:jh}),Cr=hu(Zh,hr);function mu(e,t,r,n){let o=Vr.digest(r instanceof Uint8Array?r:r.subarray());if(Wn(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Cr.verify(t,i,e,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new nn(String(i))});try{return n?.signal?.throwIfAborted(),Cr.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(i){throw new nn(String(i))}}var oo=class{type="secp256k1";raw;_key;constructor(t){this._key=gu(t),this.raw=yu(this._key)}toMultihash(){return St.digest(lr(this))}toCID(){return H.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){return mu(this._key,r,t,n)}};function Ls(e){return new oo(e)}function yu(e){return Cr.Point.fromBytes(e).toBytes()}function gu(e){try{return Cr.Point.fromBytes(e),e}catch(t){throw new rr(String(t))}}function bu(e,t){let{Type:r,Data:n}=ie.decode(e),o=n??new Uint8Array;switch(r){case tt.RSA:return Cs(o,t);case tt.Ed25519:return rs(o);case tt.secp256k1:return Ls(o);case tt.ECDSA:return Ai(o);default:throw new or}}function io(e){let{Type:t,Data:r}=ie.decode(e.digest),n=r??new Uint8Array;switch(t){case tt.Ed25519:return rs(n);case tt.secp256k1:return Ls(n);case tt.ECDSA:return Ai(n);default:throw new or}}function lr(e){return ie.encode({Type:tt[e.type],Data:e.raw})}var xu=Symbol.for("nodejs.util.inspect.custom"),Gh=114,dn=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Bn]=!0;toString(){return this.string==null&&(this.string=X.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return H.createV1(Gh,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return W(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return W(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[xu](){return`PeerId(${this.toString()})`}},so=class extends dn{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},ao=class extends dn{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},co=class extends dn{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Wh=2336,hn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=St.digest(V(this.url))}[xu](){return`PeerId(${this.url})`}[Bn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return H.createV1(Wh,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};var Xh=114,wu=2336;function Eu(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=Se(X.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return Ns(H.parse(e));if(t==null)throw new et('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=Se(t.decode(e))}return uo(r)}function uo(e){if(Qh(e))return new so({multihash:e});if(Jh(e))try{let t=io(e);if(t.type==="Ed25519")return new ao({multihash:e,publicKey:t});if(t.type==="secp256k1")return new co({multihash:e,publicKey:t})}catch{let r=z(e.digest);return new hn(new URL(r))}throw new nr("Supplied PeerID Multihash is invalid")}function Ns(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Xh&&e.code!==wu)throw new _n("Supplied PeerID CID is invalid");if(e.code===wu){let t=z(e.multihash.digest);return new hn(new URL(t))}return uo(e.multihash)}function Jh(e){return e.code===St.code}function Qh(e){return e.code===Vr.code}var gt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},ge=class extends Error{static name="ValidationError";name="ValidationError"},fo=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},lo=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var ho=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",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let h=Number.parseInt(l,t);if(!Number.isNaN(h))return h});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&&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 tp=45,ep=15,po=new ho;function Su(e){if(!(e.length>ep))return po.new(e).parseWith(()=>po.readIPv4Addr())}function vu(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>tp))return po.new(e).parseWith(()=>po.readIPv6Addr())}function mo(e){return!!Su(e)}function Tu(e){return!!vu(e)}function ks(e){return t=>z(t,e)}function Ks(e){return t=>V(t,e)}function _r(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function Ge(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function Au(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=V(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=Ge(n);return Nt([r,o],r.length+o.length)}function Iu(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=te.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=Ge(n);return Nt([r,o],r.length+o.length)}function $s(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=z(t,"base32"),o=_r(r);return`${n}:${o}`}var Ms=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 gt("Invalid byte value in IP address");t[n]=o}),t},Cu=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let i=mo(r[n]),s;i&&(s=Ms(r[n]),r[n]=z(s.subarray(0,2),"base16")),s!=null&&++n<8&&r.splice(n,0,z(s.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let i=[n,1];for(n=9-r.length;n>0;n--)i.push("0");r.splice.apply(r,i)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let i=parseInt(r[n],16);if(isNaN(i)||i<0||i>65535)throw new gt("Invalid byte value in IP address");o[t++]=i>>8&255,o[t++]=i&255}return o},_u=function(e){if(e.byteLength!==4)throw new gt("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Bu=function(e){if(e.byteLength!==16)throw new gt("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 gt(`Invalid IPv6 address "${r}"`)}};function Ru(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new gt(`Invalid IPv6 address "${e}"`)}}var Us=Object.values(qr).map(e=>e.decoder),rp=(function(){let e=Us[0].or(Us[1]);return Us.slice(2).forEach(t=>e=e.or(t)),e})();function Du(e){return rp.decode(e)}function Pu(e){return t=>e.encoder.encode(t)}function np(e){if(parseInt(e).toString()!==e)throw new ge("Value must be an integer")}function op(e){if(e<0)throw new ge("Value must be a positive integer, or zero")}function ip(e){return t=>{if(t>e)throw new ge(`Value must be smaller than or equal to ${e}`)}}function sp(...e){return t=>{for(let r of e)r(t)}}var pn=sp(np,op,ip(65535));var dt=-1,Vs=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 lo(`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)}))}},be=new Vs,Yp=[{code:4,name:"ip4",size:32,valueToBytes:Ms,bytesToValue:_u,validate:e=>{if(!mo(e))throw new ge(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ge,bytesToValue:_r,validate:pn},{code:273,name:"udp",size:16,valueToBytes:Ge,bytesToValue:_r,validate:pn},{code:33,name:"dccp",size:16,valueToBytes:Ge,bytesToValue:_r,validate:pn},{code:41,name:"ip6",size:128,valueToBytes:Cu,bytesToValue:Bu,stringToValue:Ru,validate:e=>{if(!Tu(e))throw new ge(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:dt},{code:43,name:"ipcidr",size:8,bytesToValue:ks("base10"),valueToBytes:Ks("base10")},{code:53,name:"dns",size:dt},{code:54,name:"dns4",size:dt},{code:55,name:"dns6",size:dt},{code:56,name:"dnsaddr",size:dt},{code:132,name:"sctp",size:16,valueToBytes:Ge,bytesToValue:_r,validate:pn},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:dt,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:dt,bytesToValue:ks("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Ks("base58btc")(e):H.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:$s,valueToBytes:Au},{code:445,name:"onion3",size:296,bytesToValue:$s,valueToBytes:Iu},{code:446,name:"garlic64",size:dt},{code:447,name:"garlic32",size:dt},{code:448,name:"tls"},{code:449,name:"sni",size:dt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:dt,bytesToValue:Pu(di),valueToBytes:Du},{code:480,name:"http"},{code:481,name:"http-path",size:dt,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:dt}];Yp.forEach(e=>{be.addProtocol(e)});function Ou(e){let t=[],r=0;for(;r<e.length;){let n=cs(e,r),o=be.getProtocol(n),i=oe(n),s=Zp(o,e,r+i),a=0;s>0&&o.size===dt&&(a=oe(s));let c=i+a+s,u={code:n,name:o.name,bytes:e.subarray(r,r+c)};if(s>0){let f=r+i+a,l=e.subarray(f,f+s);u.value=o.bytesToValue?.(l)??z(l)}t.push(u),r+=c}return t}function Fu(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=be.getProtocol(n.code),i=oe(n.code),s,a=0,c=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??V(n.value),a=s.byteLength,o.size===dt&&(c=oe(a)));let u=new Uint8Array(i+c+a),f=0;on(n.code,u,f),f+=i,s!=null&&(o.size===dt&&(on(a,u,f),f+=c),u.set(s,f)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Nt(r,t)}function Lu(e){if(e.charAt(0)!=="/")throw new gt('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=be.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 gt(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new gt(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new gt("Incomplete multiaddr");return t}function Nu(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=be.getProtocol(t.code);if(r==null)throw new gt(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Zp(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:cs(t,r)}var Gp=Symbol.for("nodejs.util.inspect.custom"),qs=Symbol.for("@multiformats/multiaddr");function Wp(e){if(e==null&&(e="/"),Uu(e))return e.getComponents();if(e instanceof Uint8Array)return Ou(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Lu(e);if(Array.isArray(e))return e;throw new gt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var yo=class e{[qs]=!0;#t;#n;#r;constructor(t="/",r={}){this.#t=Wp(t),r.validate!==!1&&Xp(this)}get bytes(){return this.#r==null&&(this.#r=Fu(this.#t)),this.#r}toString(){return this.#n==null&&(this.#n=Nu(this.#t)),this.#n}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new fo(`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 W(this.bytes,t.bytes)}[Gp](){return`Multiaddr(${this.toString()})`}};function Xp(e){e.getComponents().forEach(t=>{let r=be.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function Uu(e){return!!e?.[qs]}function go(e){return new yo(e)}function Br(e){let t=new globalThis.AbortController;function r(){let i=e.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();t.abort(i);for(let s of e)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let i of e){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=t.signal;return o.clear=n,o}async function*mn(e,t={}){let r=e.getReader();try{for(;;){let n=await r.read();if(n.done)return;yield n.value}}finally{t.preventCancel!==!0&&await r.cancel(),r.releaseLock()}}function Jp(e,t){if(typeof e=="string")return Qp(e);if(typeof e=="number")return r0(e,t);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(e)}`)}var bo=Jp;function Qp(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 t0(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 e0(e){let t=Math.abs(e);return t>=315576e5?We(e,t,315576e5,"year"):t>=26298e5?We(e,t,26298e5,"month"):t>=6048e5?We(e,t,6048e5,"week"):t>=864e5?We(e,t,864e5,"day"):t>=36e5?We(e,t,36e5,"hour"):t>=6e4?We(e,t,6e4,"minute"):t>=1e3?We(e,t,1e3,"second"):`${e} ms`}function r0(e,t){if(typeof e!="number"||!Number.isFinite(e))throw Error("Value provided to ms.format() must be of type number.");return t?.long?e0(e):t0(e)}function We(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function zs(e){r.debug=r,r.default=r,r.coerce=c,r.disable=i,r.enable=o,r.enabled=s,r.humanize=bo,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 h=0;h<f.length;h++)l=(l<<5)-l+f.charCodeAt(h),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=t;function r(f,l){let h,m=null,E,v;function y(...S){if(!y.enabled)return;let A=y,_=Number(new Date),U=_-(h||_);A.diff=U,A.prev=h,A.curr=_,h=_,S[0]=r.coerce(S[0]),typeof S[0]!="string"&&S.unshift("%O");let F=0;S[0]=S[0].replace(/%([a-zA-Z%])/g,(L,w)=>{if(L==="%%")return"%";F++;let C=r.formatters[w];if(typeof C=="function"){let N=S[F];L=C.call(A,N),S.splice(F,1),F--}return L}),r.formatArgs.call(A,S),l?.onLog!=null&&l.onLog(...S),(A.log||r.log).apply(A,S)}return y.namespace=f,y.useColors=r.useColors(),y.color=r.selectColor(f),y.extend=n,y.destroy=r.destroy,Object.defineProperty(y,"enabled",{enumerable:!0,configurable:!1,get:()=>m!==null?m:(E!==r.namespaces&&(E=r.namespaces,v=r.enabled(f)),v),set:S=>{m=S}}),typeof r.init=="function"&&r.init(y),y}function n(f,l){let h=r(this.namespace+(typeof l>"u"?":":l)+f);return h.log=this.log,h}function o(f){r.save(f),r.namespaces=f,r.names=[],r.skips=[];let l,h=(typeof f=="string"?f:"").split(/[\s,]+/),m=h.length;for(l=0;l<m;l++)h[l]&&(f=h[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(a),...r.skips.map(a).map(l=>"-"+l)].join(",");return r.enable(""),f}function s(f){if(f[f.length-1]==="*")return!0;let l,h;for(l=0,h=r.skips.length;l<h;l++)if(r.skips[l].test(f))return!1;for(l=0,h=r.names.length;l<h;l++)if(r.names[l].test(f))return!0;return!1}function a(f){return f.toString().substring(2,f.toString().length-2).replace(/\.\*\?$/,"*")}function c(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 xo=u0(),n0=["#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 o0(){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 i0(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+bo(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 s0=console.debug??console.log??(()=>{});function a0(e){try{e?xo?.setItem("debug",e):xo?.removeItem("debug")}catch{}}function c0(){let e;try{e=xo?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function u0(){try{return localStorage}catch{}}function f0(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var ku=zs({formatArgs:i0,save:a0,load:c0,useColors:o0,setupFormatters:f0,colors:n0,storage:xo,log:s0});var Ct=ku;Ct.formatters.b=e=>e==null?"undefined":X.baseEncode(e);Ct.formatters.t=e=>e==null?"undefined":te.baseEncode(e);Ct.formatters.m=e=>e==null?"undefined":li.baseEncode(e);Ct.formatters.p=e=>e==null?"undefined":e.toString();Ct.formatters.c=e=>e==null?"undefined":e.toString();Ct.formatters.k=e=>e==null?"undefined":e.toString();Ct.formatters.a=e=>e==null?"undefined":e.toString();function Ku(e,t=""){let r=$u(e.message),n=$u(e.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
4
4
  `).join(`
5
5
  ${t}`)}`:`${r}
6
6
  ${t}${n.split(`
7
7
  `).join(`
8
8
  ${t}`)}`:n!=null?`${n.split(`
9
9
  `).join(`
10
- ${t}`)}`:r!=null?`${r}`:`${e.toString()}`}function h0(e){return e instanceof AggregateError||e?.name==="AggregateError"&&Array.isArray(e.errors)}function Fu(e,t=""){if(h0(e)){let r=Ku(e,t);return e.errors.length>0?(t=`${t} `,r+=`
11
- ${t}${e.errors.map(n=>`${Fu(n,`${t}`)}`).join(`
10
+ ${t}`)}`:r!=null?`${r}`:`${e.toString()}`}function l0(e){return e instanceof AggregateError||e?.name==="AggregateError"&&Array.isArray(e.errors)}function Mu(e,t=""){if(l0(e)){let r=Ku(e,t);return e.errors.length>0?(t=`${t} `,r+=`
11
+ ${t}${e.errors.map(n=>`${Mu(n,`${t}`)}`).join(`
12
12
  ${t}`)}`):r+=`
13
- ${t}[Error list was empty]`,r.trim()}return Ku(e,t)}Dt.formatters.e=e=>e==null?"undefined":Fu(e);function p0(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 Ze(e,t){let r=p0(`${e}:trace`);return Dt.enabled(`${e}:trace`)&&Dt.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=Dt(`${e}:trace`,t)),Object.assign(Dt(e,t),{error:Dt(`${e}:error`,t),trace:r,newScope:n=>Ze(`${e}:${n}`,t)})}function Mu(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var rm=Vo(Ps(),1);var Gt=class extends Error{static name="SignatureVerificationError";constructor(t="Record signature verification failed"){super(t),this.name="SignatureVerificationError"}},ao=class extends Error{static name="RecordExpiredError";constructor(t="Record has expired"){super(t),this.name="RecordExpiredError"}},vr=class extends Error{static name="UnsupportedValidityError";constructor(t="The validity type is unsupported"){super(t),this.name="UnsupportedValidityError"}},co=class extends Error{static name="RecordTooLargeError";constructor(t="The record is too large"){super(t),this.name="RecordTooLargeError"}},uo=class extends Error{static name="InvalidValueError";constructor(t="Value must be a valid content path starting with /"){super(t),this.name="InvalidValueError"}},fo=class extends Error{static name="InvalidRecordDataError";constructor(t="Invalid record data"){super(t),this.name="InvalidRecordDataError"}},nn=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(t="Invalid embedded public key"){super(t),this.name="InvalidEmbeddedPublicKeyError"}};var Ls=new Float32Array([-0]),Re=new Uint8Array(Ls.buffer);function Vu(e,t,r){Ls[0]=e,t[r]=Re[0],t[r+1]=Re[1],t[r+2]=Re[2],t[r+3]=Re[3]}function $u(e,t){return Re[0]=e[t],Re[1]=e[t+1],Re[2]=e[t+2],Re[3]=e[t+3],Ls[0]}var Us=new Float64Array([-0]),wt=new Uint8Array(Us.buffer);function qu(e,t,r){Us[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 Hu(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],Us[0]}var m0=BigInt(Number.MAX_SAFE_INTEGER),y0=BigInt(Number.MIN_SAFE_INTEGER),Pt=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 Ye;if(t<m0&&t>y0)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>zu&&(o=0n,++n>zu&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ye;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):Ye}},Ye=new Pt(0,0);Ye.toBigInt=function(){return 0n};Ye.zzEncode=Ye.zzDecode=function(){return this};Ye.length=function(){return 1};var zu=4294967296n;function ju(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 Gu(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 Os(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 lo(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var ks=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 lo(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Zt(this,4);return lo(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Zt(this,4);let t=$u(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Zt(this,4);let t=Hu(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 Gu(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 Pt(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=lo(this.buf,this.pos+=4),r=lo(this.buf,this.pos+=4);return new Pt(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=Gr(this.buf,this.pos);return this.pos+=_t(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 Ks(e){return new ks(e instanceof Uint8Array?e:e.subarray())}function Ms(e,t,r){let n=Ks(e);return t.decode(n,void 0,r)}function Fs(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return ct(s);o+s>t&&(n=ct(t),o=0);let c=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),c}}var We=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Vs(){}var qs=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},g0=Fs();function x0(e){return globalThis.Buffer!=null?ct(e):g0(e)}var sn=class{len;head;tail;states;constructor(){this.len=0,this.head=new We(Vs,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new We(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Hs((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(ho,10,Pt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Pt.fromBigInt(t);return this._push(ho,r.length(),r)}uint64Number(t){return this._push(qe,_t(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=Pt.fromBigInt(t).zzEncode();return this._push(ho,r.length(),r)}sint64Number(t){let r=Pt.fromNumber(t).zzEncode();return this._push(ho,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push($s,1,t?1:0)}fixed32(t){return this._push(on,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Pt.fromBigInt(t);return this._push(on,4,r.lo)._push(on,4,r.hi)}fixed64Number(t){let r=Pt.fromNumber(t);return this._push(on,4,r.lo)._push(on,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(Vu,4,t)}double(t){return this._push(qu,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push($s,1,0):this.uint32(r)._push(w0,r,t)}string(t){let r=ju(t);return r!==0?this.uint32(r)._push(Os,r,t):this._push($s,1,0)}fork(){return this.states=new qs(this),this.head=this.tail=new We(Vs,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 We(Vs,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=x0(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function $s(e,t,r){t[r]=e&255}function b0(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Hs=class extends We{next;constructor(t,r){super(b0,t,r),this.next=void 0}};function ho(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 on(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 w0(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(sn.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(E0,t,e),this},sn.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(S0,t,e),this});function E0(e,t,r){t.set(e,r)}function S0(e,t,r){e.length<40?Os(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(q(e),r)}function zs(){return new sn}function js(e,t){let r=zs();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Ar;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(Ar||(Ar={}));function po(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Gs(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 po("enum",Ar.VARINT,r,n)}function Zs(e,t){return po("message",Ar.LENGTH_DELIMITED,e,t)}var Yt;(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=()=>Gs(r)})(t=e.ValidityType||(e.ValidityType={}));let n;e.codec=()=>(n==null&&(n=Zs((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 f=o.uint32();switch(f>>>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(f&7);break}}}return c})),n),e.encode=o=>js(o,e.codec()),e.decode=(o,i)=>Ms(o,e.codec(),i)})(Yt||(Yt={}));var v0=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Yu(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(t==="string"||t==="number"||t==="bigint"||t==="symbol")return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(e instanceof Uint8Array)return"Uint8Array";if(e.constructor===Object)return"Object";let r=A0(e);return r||"Object"}function A0(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(v0.includes(t))return t}var h=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}static equals(t,r){return t===r||t.major===r.major&&t.name===r.name}};h.uint=new h(0,"uint",!0);h.negint=new h(1,"negint",!0);h.bytes=new h(2,"bytes",!0);h.string=new h(3,"string",!0);h.array=new h(4,"array",!1);h.map=new h(5,"map",!1);h.tag=new h(6,"tag",!1);h.float=new h(7,"float",!0);h.false=new h(7,"false",!0);h.true=new h(7,"true",!0);h.null=new h(7,"null",!0);h.undefined=new h(7,"undefined",!0);h.break=new h(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 an=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",I0=new TextEncoder;function mo(e){return an&&globalThis.Buffer.isBuffer(e)}function cn(e){return e instanceof Uint8Array?mo(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var T0=24,C0=200,Ys=an?e=>e.length>=T0?globalThis.Buffer.from(e):Wu(e):e=>e.length>=C0?I0.encode(e):Wu(e),ie=e=>Uint8Array.from(e),Xu=an?(e,t,r)=>mo(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Ju=an?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),cn(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},Qu=an?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function yo(e,t){if(mo(e)&&mo(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):(o>=55296&&o<=57343&&(o=65533),t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128)}return t}var B0=256,un=class{constructor(t=B0){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=Qu(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=Xu(n,0,this.cursor)}else r=Ju(this.chunks,this.cursor);return t&&this.reset(),r}},go=class{constructor(t){this.dest=t,this.cursor=0,this.chunks=[t]}reset(){this.cursor=0}push(t){if(this.cursor+t.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(t,this.cursor),this.cursor+=t.length}toBytes(t=!1){let r=this.dest.subarray(0,this.cursor);return t&&this.reset(),r}};var V="CBOR decode error:",Ws="CBOR encode error:",fn=[];fn[23]=1;fn[24]=2;fn[25]=3;fn[26]=5;fn[27]=9;function be(e,t,r){if(e.length-t<r)throw new Error(`${V} not enough data for type`)}var dt=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Lt(e,t,r){be(e,t,1);let n=e[t];if(r.strict===!0&&n<dt[0])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function Ut(e,t,r){be(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<dt[1])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function Ot(e,t,r){be(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(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function kt(e,t,r){be(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(`${V} 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(`${V} integers outside of the safe integer range are not supported`)}function tf(e,t,r,n){return new N(h.uint,Lt(e,t+1,n),2)}function ef(e,t,r,n){return new N(h.uint,Ut(e,t+1,n),3)}function rf(e,t,r,n){return new N(h.uint,Ot(e,t+1,n),5)}function nf(e,t,r,n){return new N(h.uint,kt(e,t+1,n),9)}function Ft(e,t){return ht(e,0,t.value)}function ht(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(`${V} encountered BigInt larger than allowable range`)}}Ft.encodedSize=function(t){return ht.encodedSize(t.value)};ht.encodedSize=function(t){return t<dt[0]?1:t<dt[1]?2:t<dt[2]?3:t<dt[3]?5:9};Ft.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function of(e,t,r,n){return new N(h.negint,-1-Lt(e,t+1,n),2)}function sf(e,t,r,n){return new N(h.negint,-1-Ut(e,t+1,n),3)}function af(e,t,r,n){return new N(h.negint,-1-Ot(e,t+1,n),5)}var Xs=BigInt(-1),cf=BigInt(1);function uf(e,t,r,n){let o=kt(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new N(h.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${V} integers outside of the safe integer range are not supported`);return new N(h.negint,Xs-BigInt(o),9)}function xo(e,t){let r=t.value,n=typeof r=="bigint"?r*Xs-cf:r*-1-1;ht(e,t.type.majorEncoded,n)}xo.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*Xs-cf:r*-1-1;return n<dt[0]?1:n<dt[1]?2:n<dt[2]?3:n<dt[3]?5:9};xo.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function ln(e,t,r,n){be(e,t,r+n);let o=e.slice(t+r,t+r+n);return new N(h.bytes,o,r+n)}function ff(e,t,r,n){return ln(e,t,1,r)}function lf(e,t,r,n){return ln(e,t,2,Lt(e,t+1,n))}function df(e,t,r,n){return ln(e,t,3,Ut(e,t+1,n))}function hf(e,t,r,n){return ln(e,t,5,Ot(e,t+1,n))}function pf(e,t,r,n){let o=kt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer bytes lengths not supported`);return ln(e,t,9,o)}function bo(e){return e.encodedBytes===void 0&&(e.encodedBytes=h.equals(e.type,h.string)?Ys(e.value):e.value),e.encodedBytes}function Ir(e,t){let r=bo(t);ht(e,t.type.majorEncoded,r.length),e.push(r)}Ir.encodedSize=function(t){let r=bo(t);return ht.encodedSize(r.length)+r.length};Ir.compareTokens=function(t,r){return D0(bo(t),bo(r))};function D0(e,t){return e.length<t.length?-1:e.length>t.length?1:yo(e,t)}var mf=new TextDecoder,N0=32;function P0(e,t,r){if(r-t<N0){let o="";for(let i=t;i<r;i++){let s=e[i];if(s&128)return mf.decode(e.subarray(t,r));o+=String.fromCharCode(s)}return o}return mf.decode(e.subarray(t,r))}function dn(e,t,r,n,o){let i=r+n;be(e,t,i);let s=new N(h.string,P0(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=e.slice(t+r,t+i)),s}function yf(e,t,r,n){return dn(e,t,1,r,n)}function gf(e,t,r,n){return dn(e,t,2,Lt(e,t+1,n),n)}function xf(e,t,r,n){return dn(e,t,3,Ut(e,t+1,n),n)}function bf(e,t,r,n){return dn(e,t,5,Ot(e,t+1,n),n)}function wf(e,t,r,n){let o=kt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer string lengths not supported`);return dn(e,t,9,o,n)}var Ef=Ir;function Tr(e,t,r,n){return new N(h.array,n,r)}function Sf(e,t,r,n){return Tr(e,t,1,r)}function vf(e,t,r,n){return Tr(e,t,2,Lt(e,t+1,n))}function Af(e,t,r,n){return Tr(e,t,3,Ut(e,t+1,n))}function If(e,t,r,n){return Tr(e,t,5,Ot(e,t+1,n))}function Tf(e,t,r,n){let o=kt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer array lengths not supported`);return Tr(e,t,9,o)}function Cf(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return Tr(e,t,1,1/0)}function wo(e,t){ht(e,h.array.majorEncoded,t.value)}wo.compareTokens=Ft.compareTokens;wo.encodedSize=function(t){return ht.encodedSize(t.value)};function Cr(e,t,r,n){return new N(h.map,n,r)}function Bf(e,t,r,n){return Cr(e,t,1,r)}function _f(e,t,r,n){return Cr(e,t,2,Lt(e,t+1,n))}function Df(e,t,r,n){return Cr(e,t,3,Ut(e,t+1,n))}function Rf(e,t,r,n){return Cr(e,t,5,Ot(e,t+1,n))}function Nf(e,t,r,n){let o=kt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer map lengths not supported`);return Cr(e,t,9,o)}function Pf(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return Cr(e,t,1,1/0)}function Eo(e,t){ht(e,h.map.majorEncoded,t.value)}Eo.compareTokens=Ft.compareTokens;Eo.encodedSize=function(t){return ht.encodedSize(t.value)};function Lf(e,t,r,n){return new N(h.tag,r,1)}function Uf(e,t,r,n){return new N(h.tag,Lt(e,t+1,n),2)}function Of(e,t,r,n){return new N(h.tag,Ut(e,t+1,n),3)}function kf(e,t,r,n){return new N(h.tag,Ot(e,t+1,n),5)}function Kf(e,t,r,n){return new N(h.tag,kt(e,t+1,n),9)}function So(e,t){ht(e,h.tag.majorEncoded,t.value)}So.compareTokens=Ft.compareTokens;So.encodedSize=function(t){return ht.encodedSize(t.value)};var Js=20,Qs=21,ta=22,ea=23;function Mf(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${V} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new N(h.null,null,1):new N(h.undefined,void 0,1)}function Ff(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return new N(h.break,void 0,1)}function ra(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${V} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${V} Infinity values are not supported`)}return new N(h.float,e,t)}function Vf(e,t,r,n){return ra(na(e,t+1),3,n)}function $f(e,t,r,n){return ra(oa(e,t+1),5,n)}function qf(e,t,r,n){return ra(Gf(e,t+1),9,n)}function vo(e,t,r){let n=t.value;if(n===!1)e.push([h.float.majorEncoded|Js]);else if(n===!0)e.push([h.float.majorEncoded|Qs]);else if(n===null)e.push([h.float.majorEncoded|ta]);else if(n===void 0)e.push([h.float.majorEncoded|ea]);else{let o,i=!1;(!r||r.float64!==!0)&&(zf(n),o=na(Wt,1),n===o||Number.isNaN(n)?(Wt[0]=249,e.push(Wt.slice(0,3)),i=!0):(jf(n),o=oa(Wt,1),n===o&&(Wt[0]=250,e.push(Wt.slice(0,5)),i=!0))),i||(K0(n),o=Gf(Wt,1),Wt[0]=251,e.push(Wt.slice(0,9)))}}vo.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=na(Wt,1);if(n===o||Number.isNaN(n))return 3;if(jf(n),o=oa(Wt,1),n===o)return 5}return 9};var Hf=new ArrayBuffer(9),Vt=new DataView(Hf,1),Wt=new Uint8Array(Hf,0);function zf(e){if(e===1/0)Vt.setUint16(0,31744,!1);else if(e===-1/0)Vt.setUint16(0,64512,!1);else if(Number.isNaN(e))Vt.setUint16(0,32256,!1);else{Vt.setFloat32(0,e);let t=Vt.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)Vt.setUint16(0,31744,!1);else if(r===0)Vt.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Vt.setUint16(0,0):o<-14?Vt.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):Vt.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function na(e,t){if(e.length-t<2)throw new Error(`${V} 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 jf(e){Vt.setFloat32(0,e,!1)}function oa(e,t){if(e.length-t<4)throw new Error(`${V} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function K0(e){Vt.setFloat64(0,e,!1)}function Gf(e,t){if(e.length-t<8)throw new Error(`${V} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}vo.compareTokens=Ft.compareTokens;function Z(e,t,r){throw new Error(`${V} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Ao(e){return()=>{throw new Error(`${V} ${e}`)}}var B=[];for(let e=0;e<=23;e++)B[e]=Z;B[24]=tf;B[25]=ef;B[26]=rf;B[27]=nf;B[28]=Z;B[29]=Z;B[30]=Z;B[31]=Z;for(let e=32;e<=55;e++)B[e]=Z;B[56]=of;B[57]=sf;B[58]=af;B[59]=uf;B[60]=Z;B[61]=Z;B[62]=Z;B[63]=Z;for(let e=64;e<=87;e++)B[e]=ff;B[88]=lf;B[89]=df;B[90]=hf;B[91]=pf;B[92]=Z;B[93]=Z;B[94]=Z;B[95]=Ao("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)B[e]=yf;B[120]=gf;B[121]=xf;B[122]=bf;B[123]=wf;B[124]=Z;B[125]=Z;B[126]=Z;B[127]=Ao("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)B[e]=Sf;B[152]=vf;B[153]=Af;B[154]=If;B[155]=Tf;B[156]=Z;B[157]=Z;B[158]=Z;B[159]=Cf;for(let e=160;e<=183;e++)B[e]=Bf;B[184]=_f;B[185]=Df;B[186]=Rf;B[187]=Nf;B[188]=Z;B[189]=Z;B[190]=Z;B[191]=Pf;for(let e=192;e<=215;e++)B[e]=Lf;B[216]=Uf;B[217]=Of;B[218]=kf;B[219]=Kf;B[220]=Z;B[221]=Z;B[222]=Z;B[223]=Z;for(let e=224;e<=243;e++)B[e]=Ao("simple values are not supported");B[244]=Z;B[245]=Z;B[246]=Z;B[247]=Mf;B[248]=Ao("simple values are not supported");B[249]=Vf;B[250]=$f;B[251]=qf;B[252]=Z;B[253]=Z;B[254]=Z;B[255]=Ff;var Xt=[];for(let e=0;e<24;e++)Xt[e]=new N(h.uint,e,1);for(let e=-1;e>=-24;e--)Xt[31-e]=new N(h.negint,e,1);Xt[64]=new N(h.bytes,new Uint8Array(0),1);Xt[96]=new N(h.string,"",1);Xt[128]=new N(h.array,0,1);Xt[160]=new N(h.map,0,1);Xt[244]=new N(h.false,!1,1);Xt[245]=new N(h.true,!0,1);Xt[246]=new N(h.null,null,1);function Zf(e){switch(e.type){case h.false:return ie([244]);case h.true:return ie([245]);case h.null:return ie([246]);case h.bytes:return e.value.length?void 0:ie([64]);case h.string:return e.value===""?ie([96]):void 0;case h.array:return e.value===0?ie([128]):void 0;case h.map:return e.value===0?ie([160]):void 0;case h.uint:return e.value<24?ie([Number(e.value)]):void 0;case h.negint:if(e.value>=-24)return ie([31-Number(e.value)])}}var Wf=Object.freeze({float64:!0,mapSorter:H0,quickEncodeToken:Zf});function F0(){let e=[];return e[h.uint.major]=Ft,e[h.negint.major]=xo,e[h.bytes.major]=Ir,e[h.string.major]=Ef,e[h.array.major]=wo,e[h.map.major]=Eo,e[h.tag.major]=So,e[h.float.major]=vo,e}var V0=F0(),$0=new un,To=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(`${Ws} object contains circular references`);return new e(r,t)}},Ne={null:new N(h.null,null),undefined:new N(h.undefined,void 0),true:new N(h.true,!0),false:new N(h.false,!1),emptyArray:new N(h.array,0),emptyMap:new N(h.map,0)},Pe={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new N(h.float,e):e>=0?new N(h.uint,e):new N(h.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new N(h.uint,e):new N(h.negint,e)},Uint8Array(e,t,r,n){return new N(h.bytes,e)},string(e,t,r,n){return new N(h.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(h.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new N(h.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(h.break)]:Ne.emptyArray;n=To.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=Io(s,r,n);return r.addBreakTokens?[new N(h.array,e.length),o,new N(h.break)]:[new N(h.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,c;if(s){c=new Array(s),n=To.createCheck(n,e);let a=!o&&r.ignoreUndefinedProperties,f=0;for(let u of i){let l=o?e.get(u):e[u];a&&l===void 0||(c[f++]=[Io(u,r,n),Io(l,r,n)])}f<s&&(c.length=f)}return c?.length?(q0(c,r),r.addBreakTokens?[new N(h.map,c.length),c,new N(h.break)]:[new N(h.map,c.length),c]):r.addBreakTokens===!0?[Ne.emptyMap,new N(h.break)]:Ne.emptyMap}};Pe.Map=Pe.Object;Pe.Buffer=Pe.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Pe[`${e}Array`]=Pe.DataView;function Io(e,t={},r){let n=Yu(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||Pe[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=Pe[n];if(!i)throw new Error(`${Ws} unsupported type: ${n}`);return i(e,n,t,r)}function q0(e,t){t.mapSorter&&e.sort(t.mapSorter)}function H0(e,t){if(e[0]instanceof N&&t[0]instanceof N){let r=e[0],n=t[0];return r._keyBytes||(r._keyBytes=Yf(r.value)),n._keyBytes||(n._keyBytes=Yf(n.value)),yo(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Yf(e){return z0(e,V0,Wf)}function Xf(e,t,r,n){if(Array.isArray(t))for(let o of t)Xf(e,o,r,n);else r[t.type.major](e,t,n)}var j2=h.uint.majorEncoded,G2=h.negint.majorEncoded,Z2=h.bytes.majorEncoded,Y2=h.string.majorEncoded,W2=h.array.majorEncoded,X2=h.float.majorEncoded|Js,J2=h.float.majorEncoded|Qs,Q2=h.float.majorEncoded|ta,tE=h.float.majorEncoded|ea,eE=BigInt(-1),rE=BigInt(1);function z0(e,t,r,n){let o=n instanceof Uint8Array,i=o?new go(n):$0,s=Io(e,r);if(!Array.isArray(s)&&r.quickEncodeToken){let c=r.quickEncodeToken(s);if(c)return o?(i.push(c),i.toBytes()):c;let a=t[s.type.major];if(a.encodedSize){let f=a.encodedSize(s,r);if(o||(i=new un(f)),a(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():cn(i.chunks[0])}}return i.reset(),Xf(i,s,t,r),i.toBytes(!0)}var j0={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Co=class{constructor(t,r={}){this._pos=0,this.data=t,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let t=this.data[this._pos],r=Xt[t];if(r===void 0){let n=B[t];if(!n)throw new Error(`${V} 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}},hn=Symbol.for("DONE"),Bo=Symbol.for("BREAK");function G0(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=Br(t,r);if(i===Bo){if(e.value===1/0)break;throw new Error(`${V} got unexpected break to lengthed array`)}if(i===hn)throw new Error(`${V} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function Z0(e,t,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let c=0;c<e.value;c++){let a=Br(t,r);if(a===Bo){if(e.value===1/0)break;throw new Error(`${V} got unexpected break to lengthed map`)}if(a===hn)throw new Error(`${V} found map but not enough entries (got ${c} [no key], expected ${e.value})`);if(!n&&typeof a!="string")throw new Error(`${V} non-string keys not supported (got ${typeof a})`);if(o&&(n&&s.has(a)||!n&&Object.hasOwn(i,a)))throw new Error(`${V} found repeat map key "${a}"`);let f=Br(t,r);if(f===hn)throw new Error(`${V} found map but not enough entries (got ${c} [no value], expected ${e.value})`);n?s.set(a,f):i[a]=f}return n?s:i}function Br(e,t){if(e.done())return hn;let r=e.next();if(h.equals(r.type,h.break))return Bo;if(r.type.terminal)return r.value;if(h.equals(r.type,h.array))return G0(r,e,t);if(h.equals(r.type,h.map))return Z0(r,e,t);if(h.equals(r.type,h.tag)){if(t.tags&&typeof t.tags[r.value]=="function"){let n=Br(e,t);return t.tags[r.value](n)}throw new Error(`${V} tag not supported (${r.value})`)}throw new Error("unsupported")}function Jf(e,t){if(!(e instanceof Uint8Array))throw new Error(`${V} data to decode must be a Uint8Array`);t=Object.assign({},j0,t);let r=cn(e),n=t.tokenizer||new Co(r,t),o=Br(n,t);if(o===hn)throw new Error(`${V} did not find any content to decode`);if(o===Bo)throw new Error(`${V} got unexpected break`);return[o,e.subarray(n.pos())]}function ia(e,t){let[r,n]=Jf(e,t);if(n.length>0)throw new Error(`${V} too many terminals, data makes no sense`);return r}var X0=Ze("ipns:utils"),Qf=q("/ipns/");var J0=0,Q0=18;function tl(e){let t;if(e.pubKey!=null)try{t=gu(e.pubKey)}catch(r){throw X0.error(r),r}if(t!=null)return t}function el(e){let t=q("ipns-signature:");return Kt([t,e])}function Je(e){return"signatureV1"in e?Yt.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}):Yt.encode({pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data})}function se(e){let t=Yt.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 Gt("Missing data or signatureV2");let r=rl(t.data),n=tm(r.Value),o=z(r.Validity);if(t.value!=null&&t.signatureV1!=null)return em(t),{value:n,validityType:Yt.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:Yt.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 pn(e){return Kt([Qf,e.bytes])}function we(e){let t=Se(e.slice(Qf.length));if(!_o(t,J0)&&!_o(t,Q0))throw new er("Multihash in IPNS key was not identity or sha2-256");return t}function rl(e){let t=ia(e);if(t.ValidityType===0)t.ValidityType=Yt.ValidityType.EOL;else throw new vr("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 tm(e){let t=z(e).trim();if(t.startsWith("/"))return t;try{return`/ipfs/${j.decode(e).toV1().toString()}`}catch{}try{return`/ipfs/${j.parse(t).toV1().toString()}`}catch{}throw new uo("Value must be a valid content path starting with /")}function em(e){if(e.data==null)throw new fo("Record data is missing");let t=rl(e.data);if(!Y(t.Value,e.value??new Uint8Array(0)))throw new Gt('Field "value" did not match between protobuf and CBOR');if(!Y(t.Validity,e.validity??new Uint8Array(0)))throw new Gt('Field "validity" did not match between protobuf and CBOR');if(t.ValidityType!==e.validityType)throw new Gt('Field "validityType" did not match between protobuf and CBOR');if(t.Sequence!==e.sequence)throw new Gt('Field "sequence" did not match between protobuf and CBOR');if(t.TTL!==e.ttl)throw new Gt('Field "ttl" did not match between protobuf and CBOR')}function _o(e,t){return e.code===t}var CE=Ze("ipns"),BE=300*1e9,nm="/ipns/",_E=nm.length;var nl=Vo(Ps(),1);var Do=Ze("ipns:validator"),om=1024*10;async function im(e,t){let r=se(t),n;try{let o=el(r.data);n=await e.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw Do.error("record signature verification failed"),new Gt("Record signature verification failed");if(r.validityType===Yt.ValidityType.EOL){if(nl.default.fromString(r.validity).toDate().getTime()<Date.now())throw Do.error("record has expired"),new ao("record has expired")}else if(r.validityType!=null)throw Do.error("the validity type is unsupported"),new vr("The validity type is unsupported");Do("ipns record for %s is valid",r.value)}async function ol(e,t){if(t.byteLength>om)throw new co("The record is too large");let r=we(e),n;_o(r,0)&&(n=Gn(r));let o=se(t),i=tl(o)??n;if(i==null)throw new nn("Could not extract public key from IPNS record or routing key");let s=pn(i.toMultihash());if(!Y(s,e))throw new nn("Embedded public key did not match routing key");await im(i,t)}var Ro=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MESSAGE_LENGTH"};async function*_r(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)),ar(i)&&(i=i.subarray()),o+=n.decode(i,{stream:!0}),o.length>(t?.maxMessageLength??o.length))throw new Ro("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 $t(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var aa=Vo(sl(),1);var ca=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},al=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function ua(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=t,c,a,u=new Promise((l,m)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){m(al(s));return}if(s&&(a=()=>{m(al(s))},s.addEventListener("abort",a,{once:!0})),e.then(l,m),r===Number.POSITIVE_INFINITY)return;let E=new ca;c=i.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(b){m(b)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?l():o instanceof Error?m(o):(E.message=o??`Promise timed out after ${r} milliseconds`,m(E))},r)}).finally(()=>{u.clear(),a&&s&&s.removeEventListener("abort",a)});return u.clear=()=>{i.clearTimeout.call(void 0,c),c=void 0},u}function 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 Dr=class{#t=[];enqueue(t,r){let{priority:n=0,id:o}=r??{},i={priority:n,id:o,run:t};if(this.size===0||this.#t[this.size-1].priority>=n){this.#t.push(i);return}let s=fa(this.#t,i,(c,a)=>a.priority-c.priority);this.#t.splice(s,0,i)}setPriority(t,r){let n=this.#t.findIndex(i=>i.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:r,id:t})}remove(t){let r=this.#t.findIndex(n=>typeof t=="string"?n.id===t:n.run===t);r!==-1&&this.#t.splice(r,1)}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 yn=class extends aa.default{#t;#n;#r=0;#h;#m=!1;#b=!1;#c;#C=0;#w=0;#u;#f;#a;#s=[];#i=0;#e;#B;#o=0;#y;#l;#P=1n;#g=new Map;#E=new Set;timeout;constructor(t){if(super(),t={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Dr,strict:!1,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);if(t.strict&&t.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(t.strict&&t.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#t=t.carryoverIntervalCount??t.carryoverConcurrencyCount??!1,this.#n=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#h=t.intervalCap,this.#c=t.interval,this.#a=t.strict,this.#e=new t.queueClass,this.#B=t.queueClass,this.concurrency=t.concurrency,t.timeout!==void 0&&!(Number.isFinite(t.timeout)&&t.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${t.timeout}\` (${typeof t.timeout})`);this.timeout=t.timeout,this.#l=t.autoStart===!1,this.#V()}#S(t){for(;this.#i<this.#s.length;){let n=this.#s[this.#i];if(n!==void 0&&t-n>=this.#c)this.#i++;else break}(this.#i>100&&this.#i>this.#s.length/2||this.#i===this.#s.length)&&(this.#s=this.#s.slice(this.#i),this.#i=0)}#L(t){this.#a?this.#s.push(t):this.#r++}#U(){this.#a?this.#s.length>this.#i&&this.#s.pop():this.#r>0&&this.#r--}#v(){return this.#s.length-this.#i}get#O(){return this.#n?!0:this.#a?this.#v()<this.#h:this.#r<this.#h}get#k(){return this.#o<this.#y}#K(){this.#o--,this.#o===0&&this.emit("pendingZero"),this.#x(),this.emit("next")}#M(){this.#f=void 0,this.#R(),this.#D()}#F(t){if(this.#a){if(this.#S(t),this.#v()>=this.#h){let n=this.#s[this.#i],o=this.#c-(t-n);return this.#A(o),!0}return!1}if(this.#u===void 0){let r=this.#C-t;if(r<0){if(this.#w>0){let n=t-this.#w;if(n<this.#c)return this.#A(this.#c-n),!0}this.#r=this.#t?this.#o:0}else return this.#A(r),!0}return!1}#A(t){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#M()},t))}#I(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}#_(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#x(){if(this.#e.size===0){if(this.#I(),this.emit("empty"),this.#o===0){if(this.#_(),this.#a&&this.#i>0){let r=Date.now();this.#S(r)}this.emit("idle")}return!1}let t=!1;if(!this.#l){let r=Date.now(),n=!this.#F(r);if(this.#O&&this.#k){let o=this.#e.dequeue();this.#n||(this.#L(r),this.#p()),this.emit("active"),o(),n&&this.#D(),t=!0}}return t}#D(){this.#n||this.#u!==void 0||this.#a||(this.#u=setInterval(()=>{this.#R()},this.#c),this.#C=Date.now()+this.#c)}#R(){this.#a||(this.#r===0&&this.#o===0&&this.#u&&this.#I(),this.#r=this.#t?this.#o:0),this.#T(),this.#p()}#T(){for(;this.#x(););}get concurrency(){return this.#y}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#y=t,this.#T()}setPriority(t,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#e.setPriority(t,r)}async add(t,r={}){return r={timeout:this.timeout,...r,id:r.id??(this.#P++).toString()},new Promise((n,o)=>{let i=Symbol(`task-${r.id}`),s=()=>{},c=async()=>{s(),this.#o++,this.#g.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let f;try{try{r.signal?.throwIfAborted()}catch(m){throw this.#$(),this.#g.delete(i),m}this.#w=Date.now();let u=t({signal:r.signal});if(r.timeout&&(u=ua(Promise.resolve(u),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#o} running, ${this.#e.size} waiting)`})),r.signal){let{signal:m}=r;u=Promise.race([u,new Promise((E,b)=>{f=()=>{b(m.reason)},m.addEventListener("abort",f,{once:!0})})])}let l=await u;n(l),this.emit("completed",l)}catch(u){o(u),this.emit("error",u)}finally{f&&r.signal?.removeEventListener("abort",f),this.#g.delete(i),queueMicrotask(()=>{this.#K()})}};this.#e.enqueue(c,r);let a=()=>{if(this.#e instanceof Dr){this.#e.remove(c);return}this.#e.remove?.(r.id)};if(r.signal){let{signal:f}=r,u=()=>{s(),a(),o(f.reason),this.#x(),this.emit("next")};if(s=()=>{f.removeEventListener("abort",u),this.#E.delete(s)},f.aborted){u();return}f.addEventListener("abort",u,{once:!0}),this.#E.add(s)}this.emit("add"),this.#x()})}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#T(),this):this}pause(){this.#l=!0}clear(){for(let t of this.#E)t();this.#e=new this.#B,this.#I(),this.#N(),this.emit("empty"),this.#o===0&&(this.#_(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#e.size!==0&&await this.#d("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#d("next",()=>this.#e.size<t)}async onIdle(){this.#o===0&&this.#e.size===0||await this.#d("idle")}async onPendingZero(){this.#o!==0&&await this.#d("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#d("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#d("rateLimitCleared")}onError(){return new Promise((t,r)=>{let n=o=>{this.off("error",n),r(o)};this.on("error",n)})}async#d(t,r){return new Promise(n=>{let o=()=>{r&&!r()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#o}get isPaused(){return this.#l}#V(){this.#n||(this.on("add",()=>{this.#e.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#n||this.#b||(this.#b=!0,queueMicrotask(()=>{this.#b=!1,this.#N()}))}#$(){this.#n||(this.#U(),this.#p())}#N(){let t=this.#m;if(this.#n||this.#e.size===0){t&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#a){let o=Date.now();this.#S(o),r=this.#v()}else r=this.#r;let n=r>=this.#h;n!==t&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#o===this.#y&&this.#e.size>0||this.isRateLimited&&this.#e.size>0}get runningTasks(){return[...this.#g.values()].map(t=>({...t}))}};var Qe=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 cm(e){return e[Symbol.asyncIterator]!=null}function um(e){if(cm(e))return(async()=>{for await(let t of e)return t})();for(let t of e)return t}var Po=um;function fm(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=fm;function lm(e){return e[Symbol.asyncIterator]!=null}function dm(e,t){let r=0;if(lm(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 Lo=dm;var ul=q("/ipns/");function fl(e){return Y(e.subarray(0,ul.byteLength),ul)}var Uo=class{client;constructor(t){this.client=t}async*findProviders(t,r={}){try{yield*Lo(this.client.getProviders(t,r),n=>({id:n.ID,multiaddrs:n.Addrs??[],routing:"delegated-http-routing-v1"}))}catch(n){if(n instanceof Tt)return;throw n}}async provide(){}async cancelReprovide(){}async put(t,r,n){if(!fl(t))return;let o=we(t),i=j.createV1(114,o),s=se(r);await this.client.putIPNS(i,s,n)}async get(t,r){if(!fl(t))throw new Tt("Not found");let n=we(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 Tt("Not found"):i}}toString(){return`DelegatedRoutingV1HttpApiClientContentRouting(${this.client.url})`}},Oo=class{client;constructor(t){this.client=t}async findPeer(t,r={}){let n=await Po(this.client.getPeers(t,r));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new Tt("Not found")}async*getClosestPeers(t,r={}){let n;try{n=j.decode(t)}catch{try{n=Xn(ee.decode(t))}catch{n=j.createV1(za,vt.digest(t))}}for await(let o of this.client.getClosestPeers(n,r))yield{id:o.ID,multiaddrs:o.Addrs??[]}}toString(){return`DelegatedRoutingV1HttpApiClientPeerRouting(${this.client.url})`}};var ko={concurrentRequests:4,timeout:3e4,cacheTTL:300*1e3,cacheName:"delegated-routing-v1-cache"},Ko=class{url;started;httpQueue;shutDownController;timeout;contentRouting;peerRouting;filterAddrs;filterProtocols;inFlightRequests;cacheName;cache;cacheTTL;log;constructor(t,r){this.log=t.logger.forComponent("delegated-routing-v1-http-api-client"),this.started=!1,this.shutDownController=new AbortController,this.shutDownController.signal,this.httpQueue=new yn({concurrency:r.concurrentRequests??ko.concurrentRequests}),this.inFlightRequests=new Map,this.url=r.url instanceof URL?r.url:new URL(r.url),this.timeout=r.timeout??ko.timeout,this.filterAddrs=r.filterAddrs,this.filterProtocols=r.filterProtocols,this.contentRouting=new Uo(this),this.peerRouting=new Oo(this),this.cacheName=r.cacheName??ko.cacheName,this.cacheTTL=r.cacheTTL??ko.cacheTTL}get[Ia](){return this.contentRouting}get[Ca](){return this.peerRouting}isStarted(){return this.started}async start(){this.started||(this.started=!0,this.cacheTTL>0&&(this.cache=await globalThis.caches?.open(this.cacheName),this.cache!=null&&this.log("cache enabled with ttl %d",this.cacheTTL)))}async stop(){this.httpQueue.clear(),this.shutDownController.abort(),await globalThis.caches?.delete(this.cacheName),this.started=!1}async*getProviders(t,r={}){this.log("getProviders starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=Sr([this.shutDownController.signal,n,r.signal]);let i=$t(),s=$t(),c=0;this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let a=new URL(`${this.url}routing/v1/providers/${t}`);this.#n(a,r.filterAddrs,r.filterProtocols);let f={headers:{accept:"application/x-ndjson, application/json;q=0.8"},signal:o},u=await this.#r(a.toString(),f);if(!u.ok){if(u.status===404)return;throw u.status===422?new Qe("Request does not conform to schema or semantic constraints"):new qt(`Unexpected status code: ${u.status}`)}let l=u.headers.get("Content-Type");if(l==null)throw new qt("No Content-Type header received");if(u.body==null){if(l!=="application/x-ndjson")throw new qt("Routing response had no body");return}if(l.startsWith("application/json")){let E=(await u.json()).Providers??[];for(let b of E){let T=this.#t(b);T!=null&&(c++,yield T)}}else if(l.includes("application/x-ndjson"))for await(let m of _r(rn(u.body))){let E=this.#t(m);E!=null&&(c++,yield E)}else throw new qt(`Unsupported Content-Type: ${l}`)}finally{o.clear(),s.resolve(),this.log("getProviders finished found %d providers for %c",c,t)}}async*getPeers(t,r={}){this.log("getPeers starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=Sr([this.shutDownController.signal,n,r.signal]);let i=$t(),s=$t();this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let c=new URL(`${this.url}routing/v1/peers/${t.toCID().toString()}`);this.#n(c,r.filterAddrs,r.filterProtocols);let a={headers:{Accept:"application/x-ndjson"},signal:o},f=await this.#r(c.toString(),a);if(f.status===404)return;if(f.status===422)throw new Qe("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")?.startsWith("application/json")){let m=(await f.json()).Peers??[];for(let E of m){let b=this.#t(E);b!=null&&(yield b)}}else for await(let l of _r(rn(f.body))){let m=this.#t(l);m!=null&&(yield m)}}catch(c){this.log.error("getPeers errored - %e",c)}finally{o.clear(),s.resolve(),this.log("getPeers finished: %c",t)}}async*getClosestPeers(t,r={}){let n;if(Ta(t))n=t.toCID().toString();else if(j.asCID(t)===t||t instanceof j)n=t.toV1().toString();else throw new ot("Key must be CID or PeerId");this.log("getClosestPeers starts: %s",n);let o=AbortSignal.timeout(this.timeout),i=Sr([this.shutDownController.signal,o,r.signal]);let s=$t(),c=$t();this.httpQueue.add(async()=>(s.resolve(),c.promise));try{await s.promise;let a=new URL(`${this.url}routing/v1/dht/closest/peers/${n}`);this.#n(a,r.filterAddrs,r.filterProtocols);let f={headers:{Accept:"application/x-ndjson"},signal:i},u=await this.#r(a.toString(),f);if(u.status===404)return;if(u.status===422)throw new Qe("Request does not conform to schema or semantic constraints");if(u.body==null)throw new qt("Routing response had no body");if(u.headers.get("Content-Type")?.startsWith("application/json")){let E=(await u.json()).Peers??[];for(let b of E){let T=this.#t(b);T!=null&&(yield T)}}else for await(let m of _r(rn(u.body))){let E=this.#t(m);E!=null&&(yield E)}}catch(a){this.log.error("getClosestPeers errored - %e",a)}finally{i.clear(),c.resolve(),this.log("getClosestPeers finished: %s",n)}}async getIPNS(t,r={}){this.log("getIPNS starts: %s",t);let n=AbortSignal.timeout(this.timeout),o=Sr([this.shutDownController.signal,n,r.signal]);let i=$t(),s=$t();this.httpQueue.add(async()=>(i.resolve(),s.promise));let c=`${this.url}routing/v1/ipns/${t}`;try{await i.promise;let a={headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:o},f=await this.#r(c,a);if(this.log("getIPNS GET %s %d",c,f.status),f.status===404)throw new Tt("No matching records found");if(f.status===422)throw new Qe("Request does not conform to schema or semantic constraints");if(!f.ok)throw new qt(`Unexpected status code: ${f.status}`);let u=f.headers.get("Content-Type");if(u==null||!u.includes("application/vnd.ipfs.ipns-record"))throw new Tt("No matching records found");if(f.body==null)throw new qt("GET ipns response had no body");let l=await f.arrayBuffer(),m=new Uint8Array(l,0,l.byteLength);return r.validate!==!1&&await ol(pn(t.multihash),m),se(m)}catch(a){throw this.log.error("getIPNS GET %s error - %e",c,a),a}finally{o.clear(),s.resolve(),this.log("getIPNS finished: %s",t)}}async putIPNS(t,r,n={}){this.log("putIPNS starts: %c",t);let o=AbortSignal.timeout(this.timeout),i=Sr([this.shutDownController.signal,o,n.signal]);let s=$t(),c=$t();this.httpQueue.add(async()=>(s.resolve(),c.promise));let a=`${this.url}routing/v1/ipns/${t}`;try{await s.promise;let f=Je(r),u={method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:f,signal:i},l=await this.#r(a,u);if(this.log("putIPNS PUT %s %d",a,l.status),l.status!==200)throw new qt("PUT ipns response had status other than 200")}catch(f){throw this.log.error("putIPNS PUT %s error - %e",a,f.stack),f}finally{i.clear(),c.resolve(),this.log("putIPNS finished: %c",t)}}#t(t){try{let r=[],n=t.Addrs?.map(oo)??[];return t.Protocols!=null&&r.push(...t.Protocols),t.Protocol!=null&&(r.push(t.Protocol),delete t.Protocol),{...t,Schema:"peer",ID:wu(t.ID),Addrs:n,Protocols:r}}catch(r){this.log.error("could not conform record to peer schema - %e",r)}}#n(t,r,n){if(r!=null||this.filterAddrs!=null){let o=r?.join(",")??this.filterAddrs?.join(",")??"";o!==""&&t.searchParams.set("filter-addrs",o)}if(n!=null||this.filterProtocols!=null){let o=n?.join(",")??this.filterProtocols?.join(",")??"";o!==""&&t.searchParams.set("filter-protocols",o)}}async#r(t,r){let n=r.method??"GET",o=`${n}-${t}`;if(n==="GET"){let a=await this.cache?.match(t);if(a!=null){if(parseInt(a.headers.get("x-cache-expires")??"0",10)>Date.now())return this.log("returning cached response for %s",o),this.logResponse(a),a;this.log("evicting cached response for %s",o),await this.cache?.delete(t)}else this.cache!=null&&this.log("cache miss for %s",o)}let i=this.inFlightRequests.get(o);if(i!=null){let a=await i;return this.log("deduplicating outgoing request for %s",o),a.clone()}this.log("outgoing request:"),this.logRequest(t,r);let s=fetch(t,r).then(async a=>{if(this.log("incoming response:"),this.logResponse(a),this.cache!=null&&a.ok&&n==="GET"){let f=Date.now()+this.cacheTTL,u=new Headers(a.headers);u.set("x-cache-expires",f.toString());let l=new Response(a.clone().body,{status:a.status,statusText:a.statusText,headers:u});await this.cache.put(t,l)}return a}).finally(()=>{this.inFlightRequests.delete(o)});return this.inFlightRequests.set(o,s),await s}toString(){return`DefaultDelegatedRoutingV1HttpApiClient(${this.url})`}logRequest(t,r){let n=new Headers(r.headers);this.log("%s %s HTTP/1.1",r.method??"GET",t);for(let[o,i]of n.entries())this.log("%s: %s",o,i)}logResponse(t){this.log("HTTP/1.1 %d %s",t.status,t.statusText);for(let[r,n]of t.headers.entries())this.log("%s: %s",r,n)}};function ll(e){return t=>new Ko(t,e)}function Mo(e){return{url:"https://delegated-ipfs.dev",filterProtocols:["unknown","transport-bitswap","transport-ipfs-gateway-http"],filterAddrs:["https","webtransport","webrtc","webrtc-direct","wss","tls"]}}var dl=q("/ipns/");function hl(e){return Y(e.subarray(0,dl.byteLength),dl)}var la=class{name="delegated-http-router";client;constructor(t,r){this.client=ll(r)(t)}async provide(t,r){}async cancelReprovide(t,r){}async*findProviders(t,r){yield*Lo(this.client.getProviders(t,r),n=>({id:n.ID,multiaddrs:n.Addrs,protocols:n.Protocols,routing:"delegated-http-routing"}))}async put(t,r,n){if(!hl(t))return;let o=we(t),i=j.createV1(114,o),s=se(r);await this.client.putIPNS(i,s,n)}async get(t,r){if(!hl(t))throw new Tt("Not found");let n=we(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 Tt("Not found"):i}}async findPeer(t,r){let n=await Po(this.client.getPeers(t,r));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new Tt("Not found")}async*getClosestPeers(t,r){}toString(){return`DelegatedHTTPRouter(${this.client.url})`}};function pl(e){return t=>new la(t,Mo(e))}var ml="[a-fA-F\\d:]",Le=e=>e&&e.includeBoundaries?`(?:(?<=\\s|^)(?=${ml})|(?<=${ml})(?=\\s|$))`:"",Jt="(?: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}",Fo=`
13
+ ${t}[Error list was empty]`,r.trim()}return Ku(e,t)}Ct.formatters.e=e=>e==null?"undefined":Mu(e);function d0(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 Xe(e,t){let r=d0(`${e}:trace`);return Ct.enabled(`${e}:trace`)&&Ct.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=Ct(`${e}:trace`,t)),Object.assign(Ct(e,t),{error:Ct(`${e}:error`,t),trace:r,newScope:n=>Xe(`${e}:${n}`,t)})}function $u(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var Z0=Go(js(),1);var Gt=class extends Error{static name="SignatureVerificationError";constructor(t="Record signature verification failed"){super(t),this.name="SignatureVerificationError"}},wo=class extends Error{static name="RecordExpiredError";constructor(t="Record has expired"){super(t),this.name="RecordExpiredError"}},Rr=class extends Error{static name="UnsupportedValidityError";constructor(t="The validity type is unsupported"){super(t),this.name="UnsupportedValidityError"}},Eo=class extends Error{static name="RecordTooLargeError";constructor(t="The record is too large"){super(t),this.name="RecordTooLargeError"}},So=class extends Error{static name="InvalidValueError";constructor(t="Value must be a valid content path starting with /"){super(t),this.name="InvalidValueError"}},vo=class extends Error{static name="InvalidRecordDataError";constructor(t="Invalid record data"){super(t),this.name="InvalidRecordDataError"}},yn=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(t="Invalid embedded public key"){super(t),this.name="InvalidEmbeddedPublicKeyError"}};var Wt;(function(e){let t;(function(a){a.EOL="EOL"})(t=e.ValidityType||(e.ValidityType={}));let r;(function(a){a[a.EOL=0]="EOL"})(r||(r={})),(function(a){a.codec=()=>un(r)})(t=e.ValidityType||(e.ValidityType={}));let n;e.codec=()=>(n==null&&(n=Ar((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.value!=null&&(c.uint32(10),c.bytes(a.value)),a.signatureV1!=null&&(c.uint32(18),c.bytes(a.signatureV1)),a.validityType!=null&&(c.uint32(24),e.ValidityType.codec().encode(a.validityType,c)),a.validity!=null&&(c.uint32(34),c.bytes(a.validity)),a.sequence!=null&&(c.uint32(40),c.uint64(a.sequence)),a.ttl!=null&&(c.uint32(48),c.uint64(a.ttl)),a.pubKey!=null&&(c.uint32(58),c.bytes(a.pubKey)),a.signatureV2!=null&&(c.uint32(66),c.bytes(a.signatureV2)),a.data!=null&&(c.uint32(74),c.bytes(a.data)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let h=a.uint32();switch(h>>>3){case 1:{f.value=a.bytes();break}case 2:{f.signatureV1=a.bytes();break}case 3:{f.validityType=e.ValidityType.codec().decode(a);break}case 4:{f.validity=a.bytes();break}case 5:{f.sequence=a.uint64();break}case 6:{f.ttl=a.uint64();break}case 7:{f.pubKey=a.bytes();break}case 8:{f.signatureV2=a.bytes();break}case 9:{f.data=a.bytes();break}default:{a.skipType(h&7);break}}}return f},function*(a,c,u,f={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let h=a.uint32();switch(h>>>3){case 1:{yield{field:`${u}.value`,value:a.bytes()};break}case 2:{yield{field:`${u}.signatureV1`,value:a.bytes()};break}case 3:{yield{field:`${u}.validityType`,value:e.ValidityType.codec().decode(a)};break}case 4:{yield{field:`${u}.validity`,value:a.bytes()};break}case 5:{yield{field:`${u}.sequence`,value:a.uint64()};break}case 6:{yield{field:`${u}.ttl`,value:a.uint64()};break}case 7:{yield{field:`${u}.pubKey`,value:a.bytes()};break}case 8:{yield{field:`${u}.signatureV2`,value:a.bytes()};break}case 9:{yield{field:`${u}.data`,value:a.bytes()};break}default:{a.skipType(h&7);break}}}})),n);function o(a){return vr(a,e.codec())}e.encode=o;function i(a,c){return Sr(a,e.codec(),c)}e.decode=i;function s(a,c){return Tr(a,e.codec(),c)}e.stream=s})(Wt||(Wt={}));var h0=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged"];function Vu(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(t==="string"||t==="number"||t==="bigint"||t==="symbol")return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(e instanceof Uint8Array)return"Uint8Array";if(e.constructor===Object)return"Object";let r=p0(e);return r||"Object"}function p0(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(h0.includes(t))return t}var p=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}static equals(t,r){return t===r||t.major===r.major&&t.name===r.name}};p.uint=new p(0,"uint",!0);p.negint=new p(1,"negint",!0);p.bytes=new p(2,"bytes",!0);p.string=new p(3,"string",!0);p.array=new p(4,"array",!1);p.map=new p(5,"map",!1);p.tag=new p(6,"tag",!1);p.float=new p(7,"float",!0);p.false=new p(7,"false",!0);p.true=new p(7,"true",!0);p.null=new p(7,"null",!0);p.undefined=new p(7,"undefined",!0);p.break=new p(7,"break",!0);var O=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 gn=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",m0=new TextEncoder;function To(e){return gn&&globalThis.Buffer.isBuffer(e)}function bn(e){return e instanceof Uint8Array?To(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var y0=24,g0=200,Ys=gn?e=>e.length>=y0?globalThis.Buffer.from(e):qu(e):e=>e.length>=g0?m0.encode(e):qu(e),ae=e=>Uint8Array.from(e),zu=gn?(e,t,r)=>To(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Hu=gn?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),bn(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},ju=gn?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function Ao(e,t){if(To(e)&&To(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 qu(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):(o>=55296&&o<=57343&&(o=65533),t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128)}return t}var b0=256,xn=class{constructor(t=b0){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=ju(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=zu(n,0,this.cursor)}else r=Hu(this.chunks,this.cursor);return t&&this.reset(),r}},Io=class{constructor(t){this.dest=t,this.cursor=0,this.chunks=[t]}reset(){this.cursor=0}push(t){if(this.cursor+t.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(t,this.cursor),this.cursor+=t.length}toBytes(t=!1){let r=this.dest.subarray(0,this.cursor);return t&&this.reset(),r}};var K="CBOR decode error:",Zs="CBOR encode error:",wn=[];wn[23]=1;wn[24]=2;wn[25]=3;wn[26]=5;wn[27]=9;function xe(e,t,r){if(e.length-t<r)throw new Error(`${K} not enough data for type`)}var ht=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Pt(e,t,r){xe(e,t,1);let n=e[t];if(r.strict===!0&&n<ht[0])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Ot(e,t,r){xe(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<ht[1])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Ft(e,t,r){xe(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<ht[2])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Lt(e,t,r){xe(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<ht[3])throw new Error(`${K} 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(`${K} integers outside of the safe integer range are not supported`)}function Yu(e,t,r,n){return new O(p.uint,Pt(e,t+1,n),2)}function Zu(e,t,r,n){return new O(p.uint,Ot(e,t+1,n),3)}function Gu(e,t,r,n){return new O(p.uint,Ft(e,t+1,n),5)}function Wu(e,t,r,n){return new O(p.uint,Lt(e,t+1,n),9)}function kt(e,t){return pt(e,0,t.value)}function pt(e,t,r){if(r<ht[0]){let n=Number(r);e.push([t|n])}else if(r<ht[1]){let n=Number(r);e.push([t|24,n])}else if(r<ht[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<ht[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<ht[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,e.push(o)}else throw new Error(`${K} encountered BigInt larger than allowable range`)}}kt.encodedSize=function(t){return pt.encodedSize(t.value)};pt.encodedSize=function(t){return t<ht[0]?1:t<ht[1]?2:t<ht[2]?3:t<ht[3]?5:9};kt.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function Xu(e,t,r,n){return new O(p.negint,-1-Pt(e,t+1,n),2)}function Ju(e,t,r,n){return new O(p.negint,-1-Ot(e,t+1,n),3)}function Qu(e,t,r,n){return new O(p.negint,-1-Ft(e,t+1,n),5)}var Gs=BigInt(-1),tf=BigInt(1);function ef(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new O(p.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${K} integers outside of the safe integer range are not supported`);return new O(p.negint,Gs-BigInt(o),9)}function Co(e,t){let r=t.value,n=typeof r=="bigint"?r*Gs-tf:r*-1-1;pt(e,t.type.majorEncoded,n)}Co.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*Gs-tf:r*-1-1;return n<ht[0]?1:n<ht[1]?2:n<ht[2]?3:n<ht[3]?5:9};Co.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function En(e,t,r,n){xe(e,t,r+n);let o=e.slice(t+r,t+r+n);return new O(p.bytes,o,r+n)}function rf(e,t,r,n){return En(e,t,1,r)}function nf(e,t,r,n){return En(e,t,2,Pt(e,t+1,n))}function of(e,t,r,n){return En(e,t,3,Ot(e,t+1,n))}function sf(e,t,r,n){return En(e,t,5,Ft(e,t+1,n))}function af(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer bytes lengths not supported`);return En(e,t,9,o)}function _o(e){return e.encodedBytes===void 0&&(e.encodedBytes=p.equals(e.type,p.string)?Ys(e.value):e.value),e.encodedBytes}function Dr(e,t){let r=_o(t);pt(e,t.type.majorEncoded,r.length),e.push(r)}Dr.encodedSize=function(t){let r=_o(t);return pt.encodedSize(r.length)+r.length};Dr.compareTokens=function(t,r){return w0(_o(t),_o(r))};function w0(e,t){return e.length<t.length?-1:e.length>t.length?1:Ao(e,t)}var cf=new TextDecoder,S0=32;function v0(e,t,r){if(r-t<S0){let o="";for(let i=t;i<r;i++){let s=e[i];if(s&128)return cf.decode(e.subarray(t,r));o+=String.fromCharCode(s)}return o}return cf.decode(e.subarray(t,r))}function Sn(e,t,r,n,o){let i=r+n;xe(e,t,i);let s=new O(p.string,v0(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=e.slice(t+r,t+i)),s}function uf(e,t,r,n){return Sn(e,t,1,r,n)}function ff(e,t,r,n){return Sn(e,t,2,Pt(e,t+1,n),n)}function lf(e,t,r,n){return Sn(e,t,3,Ot(e,t+1,n),n)}function df(e,t,r,n){return Sn(e,t,5,Ft(e,t+1,n),n)}function hf(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer string lengths not supported`);return Sn(e,t,9,o,n)}var pf=Dr;function Pr(e,t,r,n){return new O(p.array,n,r)}function mf(e,t,r,n){return Pr(e,t,1,r)}function yf(e,t,r,n){return Pr(e,t,2,Pt(e,t+1,n))}function gf(e,t,r,n){return Pr(e,t,3,Ot(e,t+1,n))}function bf(e,t,r,n){return Pr(e,t,5,Ft(e,t+1,n))}function xf(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer array lengths not supported`);return Pr(e,t,9,o)}function wf(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return Pr(e,t,1,1/0)}function Bo(e,t){pt(e,p.array.majorEncoded,t.value)}Bo.compareTokens=kt.compareTokens;Bo.encodedSize=function(t){return pt.encodedSize(t.value)};function Or(e,t,r,n){return new O(p.map,n,r)}function Ef(e,t,r,n){return Or(e,t,1,r)}function Sf(e,t,r,n){return Or(e,t,2,Pt(e,t+1,n))}function vf(e,t,r,n){return Or(e,t,3,Ot(e,t+1,n))}function Tf(e,t,r,n){return Or(e,t,5,Ft(e,t+1,n))}function Af(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer map lengths not supported`);return Or(e,t,9,o)}function If(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return Or(e,t,1,1/0)}function Ro(e,t){pt(e,p.map.majorEncoded,t.value)}Ro.compareTokens=kt.compareTokens;Ro.encodedSize=function(t){return pt.encodedSize(t.value)};function Cf(e,t,r,n){return new O(p.tag,r,1)}function _f(e,t,r,n){return new O(p.tag,Pt(e,t+1,n),2)}function Bf(e,t,r,n){return new O(p.tag,Ot(e,t+1,n),3)}function Rf(e,t,r,n){return new O(p.tag,Ft(e,t+1,n),5)}function Df(e,t,r,n){return new O(p.tag,Lt(e,t+1,n),9)}function Do(e,t){pt(e,p.tag.majorEncoded,t.value)}Do.compareTokens=kt.compareTokens;Do.encodedSize=function(t){return pt.encodedSize(t.value)};var Ws=20,Xs=21,Js=22,Qs=23;function Pf(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${K} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new O(p.null,null,1):new O(p.undefined,void 0,1)}function Of(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return new O(p.break,void 0,1)}function ta(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${K} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${K} Infinity values are not supported`)}return new O(p.float,e,t)}function Ff(e,t,r,n){return ta(ea(e,t+1),3,n)}function Lf(e,t,r,n){return ta(ra(e,t+1),5,n)}function Nf(e,t,r,n){return ta($f(e,t+1),9,n)}function Po(e,t,r){let n=t.value;if(n===!1)e.push([p.float.majorEncoded|Ws]);else if(n===!0)e.push([p.float.majorEncoded|Xs]);else if(n===null)e.push([p.float.majorEncoded|Js]);else if(n===void 0)e.push([p.float.majorEncoded|Qs]);else{let o,i=!1;(!r||r.float64!==!0)&&(kf(n),o=ea(Xt,1),n===o||Number.isNaN(n)?(Xt[0]=249,e.push(Xt.slice(0,3)),i=!0):(Kf(n),o=ra(Xt,1),n===o&&(Xt[0]=250,e.push(Xt.slice(0,5)),i=!0))),i||(_0(n),o=$f(Xt,1),Xt[0]=251,e.push(Xt.slice(0,9)))}}Po.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){kf(n);let o=ea(Xt,1);if(n===o||Number.isNaN(n))return 3;if(Kf(n),o=ra(Xt,1),n===o)return 5}return 9};var Uf=new ArrayBuffer(9),Kt=new DataView(Uf,1),Xt=new Uint8Array(Uf,0);function kf(e){if(e===1/0)Kt.setUint16(0,31744,!1);else if(e===-1/0)Kt.setUint16(0,64512,!1);else if(Number.isNaN(e))Kt.setUint16(0,32256,!1);else{Kt.setFloat32(0,e);let t=Kt.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)Kt.setUint16(0,31744,!1);else if(r===0)Kt.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Kt.setUint16(0,0):o<-14?Kt.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):Kt.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function ea(e,t){if(e.length-t<2)throw new Error(`${K} 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 Kf(e){Kt.setFloat32(0,e,!1)}function ra(e,t){if(e.length-t<4)throw new Error(`${K} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function _0(e){Kt.setFloat64(0,e,!1)}function $f(e,t){if(e.length-t<8)throw new Error(`${K} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}Po.compareTokens=kt.compareTokens;function Z(e,t,r){throw new Error(`${K} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Oo(e){return()=>{throw new Error(`${K} ${e}`)}}var B=[];for(let e=0;e<=23;e++)B[e]=Z;B[24]=Yu;B[25]=Zu;B[26]=Gu;B[27]=Wu;B[28]=Z;B[29]=Z;B[30]=Z;B[31]=Z;for(let e=32;e<=55;e++)B[e]=Z;B[56]=Xu;B[57]=Ju;B[58]=Qu;B[59]=ef;B[60]=Z;B[61]=Z;B[62]=Z;B[63]=Z;for(let e=64;e<=87;e++)B[e]=rf;B[88]=nf;B[89]=of;B[90]=sf;B[91]=af;B[92]=Z;B[93]=Z;B[94]=Z;B[95]=Oo("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)B[e]=uf;B[120]=ff;B[121]=lf;B[122]=df;B[123]=hf;B[124]=Z;B[125]=Z;B[126]=Z;B[127]=Oo("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)B[e]=mf;B[152]=yf;B[153]=gf;B[154]=bf;B[155]=xf;B[156]=Z;B[157]=Z;B[158]=Z;B[159]=wf;for(let e=160;e<=183;e++)B[e]=Ef;B[184]=Sf;B[185]=vf;B[186]=Tf;B[187]=Af;B[188]=Z;B[189]=Z;B[190]=Z;B[191]=If;for(let e=192;e<=215;e++)B[e]=Cf;B[216]=_f;B[217]=Bf;B[218]=Rf;B[219]=Df;B[220]=Z;B[221]=Z;B[222]=Z;B[223]=Z;for(let e=224;e<=243;e++)B[e]=Oo("simple values are not supported");B[244]=Z;B[245]=Z;B[246]=Z;B[247]=Pf;B[248]=Oo("simple values are not supported");B[249]=Ff;B[250]=Lf;B[251]=Nf;B[252]=Z;B[253]=Z;B[254]=Z;B[255]=Of;var Jt=[];for(let e=0;e<24;e++)Jt[e]=new O(p.uint,e,1);for(let e=-1;e>=-24;e--)Jt[31-e]=new O(p.negint,e,1);Jt[64]=new O(p.bytes,new Uint8Array(0),1);Jt[96]=new O(p.string,"",1);Jt[128]=new O(p.array,0,1);Jt[160]=new O(p.map,0,1);Jt[244]=new O(p.false,!1,1);Jt[245]=new O(p.true,!0,1);Jt[246]=new O(p.null,null,1);function Mf(e){switch(e.type){case p.false:return ae([244]);case p.true:return ae([245]);case p.null:return ae([246]);case p.bytes:return e.value.length?void 0:ae([64]);case p.string:return e.value===""?ae([96]):void 0;case p.array:return e.value===0?ae([128]):void 0;case p.map:return e.value===0?ae([160]):void 0;case p.uint:return e.value<24?ae([Number(e.value)]):void 0;case p.negint:if(e.value>=-24)return ae([31-Number(e.value)])}}var qf=Object.freeze({float64:!0,mapSorter:F0,quickEncodeToken:Mf});function R0(){let e=[];return e[p.uint.major]=kt,e[p.negint.major]=Co,e[p.bytes.major]=Dr,e[p.string.major]=pf,e[p.array.major]=Bo,e[p.map.major]=Ro,e[p.tag.major]=Do,e[p.float.major]=Po,e}var D0=R0(),P0=new xn,Fo=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)}},Fe={null:new O(p.null,null),undefined:new O(p.undefined,void 0),true:new O(p.true,!0),false:new O(p.false,!1),emptyArray:new O(p.array,0),emptyMap:new O(p.map,0)},Le={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new O(p.float,e):e>=0?new O(p.uint,e):new O(p.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new O(p.uint,e):new O(p.negint,e)},Uint8Array(e,t,r,n){return new O(p.bytes,e)},string(e,t,r,n){return new O(p.string,e)},boolean(e,t,r,n){return e?Fe.true:Fe.false},null(e,t,r,n){return Fe.null},undefined(e,t,r,n){return Fe.undefined},ArrayBuffer(e,t,r,n){return new O(p.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new O(p.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[Fe.emptyArray,new O(p.break)]:Fe.emptyArray;n=Fo.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=Fr(s,r,n);return r.addBreakTokens?[new O(p.array,e.length),o,new O(p.break)]:[new O(p.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,a;if(s){a=new Array(s),n=Fo.createCheck(n,e);let c=!o&&r.ignoreUndefinedProperties,u=0;for(let f of i){let l=o?e.get(f):e[f];c&&l===void 0||(a[u++]=[Fr(f,r,n),Fr(l,r,n)])}u<s&&(a.length=u)}return a?.length?(O0(a,r),r.addBreakTokens?[new O(p.map,a.length),a,new O(p.break)]:[new O(p.map,a.length),a]):r.addBreakTokens===!0?[Fe.emptyMap,new O(p.break)]:Fe.emptyMap},Tagged(e,t,r,n){return[new O(p.tag,e.tag),Fr(e.value,r,n)]}};Le.Map=Le.Object;Le.Buffer=Le.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Le[`${e}Array`]=Le.DataView;function Fr(e,t={},r){let n=Vu(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||Le[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=Le[n];if(!i)throw new Error(`${Zs} unsupported type: ${n}`);return i(e,n,t,r)}function O0(e,t){t.mapSorter&&e.sort(t.mapSorter)}function F0(e,t){if(e[0]instanceof O&&t[0]instanceof O){let r=e[0],n=t[0];return r._keyBytes||(r._keyBytes=Vf(r.value)),n._keyBytes||(n._keyBytes=Vf(n.value)),Ao(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Vf(e){return L0(e,D0,qf)}function zf(e,t,r,n){if(Array.isArray(t))for(let o of t)zf(e,o,r,n);else r[t.type.major](e,t,n)}var l2=p.uint.majorEncoded,d2=p.negint.majorEncoded,h2=p.bytes.majorEncoded,p2=p.string.majorEncoded,m2=p.array.majorEncoded,y2=p.float.majorEncoded|Ws,g2=p.float.majorEncoded|Xs,b2=p.float.majorEncoded|Js,x2=p.float.majorEncoded|Qs,w2=BigInt(-1),E2=BigInt(1);function L0(e,t,r,n){let o=n instanceof Uint8Array,i=o?new Io(n):P0,s=Fr(e,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=t[s.type.major];if(c.encodedSize){let u=c.encodedSize(s,r);if(o||(i=new xn(u)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():bn(i.chunks[0])}}return i.reset(),zf(i,s,t,r),i.toBytes(!0)}var N0={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Lo=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=B[t];if(!n)throw new Error(`${K} 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}},Ne=Symbol.for("DONE"),Lr=Symbol.for("BREAK");function U0(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=Ue(t,r);if(i===Lr){if(e.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed array`)}if(i===Ne)throw new Error(`${K} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function k0(e,t,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<e.value;a++){let c=Ue(t,r);if(c===Lr){if(e.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed map`)}if(c===Ne)throw new Error(`${K} found map but not enough entries (got ${a} [no key], expected ${e.value})`);if(!n&&typeof c!="string")throw new Error(`${K} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${K} found repeat map key "${c}"`);let u=Ue(t,r);if(u===Ne)throw new Error(`${K} found map but not enough entries (got ${a} [no value], expected ${e.value})`);n?s.set(c,u):i[c]=u}return n?s:i}function*K0(e,t,r){for(let n=0;n<e.value;n++){let o=Ue(t,r);if(o===Lr){if(e.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed map`)}if(o===Ne)throw new Error(`${K} found map but not enough entries (got ${n} [no key], expected ${e.value})`);let i=Ue(t,r);if(i===Ne)throw new Error(`${K} found map but not enough entries (got ${n} [no value], expected ${e.value})`);yield[o,i]}}function $0(e,t){let r=!1,n=function(){if(r)throw new Error(`${K} tag decode() may only be called once`);r=!0;let o=Ue(e,t);if(o===Ne)throw new Error(`${K} tag content missing`);if(o===Lr)throw new Error(`${K} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${K} tag decode() may only be called once`);r=!0;let o=e.next();if(!p.equals(o.type,p.map))throw new Error(`${K} entries() requires map content, got ${o.type.name}`);let i=[];for(let s of K0(o,e,t))i.push(s);return i},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function Ue(e,t){if(e.done())return Ne;let r=e.next();if(p.equals(r.type,p.break))return Lr;if(r.type.terminal)return r.value;if(p.equals(r.type,p.array))return U0(r,e,t);if(p.equals(r.type,p.map))return k0(r,e,t);if(p.equals(r.type,p.tag)){if(t.tags&&typeof t.tags[r.value]=="function"){let n=$0(e,t),o=t.tags[r.value](n);if(!n._called)throw new Error(`${K} tag decoder must call decode() or entries()`);return o}throw new Error(`${K} tag not supported (${r.value})`)}throw new Error("unsupported")}function Hf(e,t){if(!(e instanceof Uint8Array))throw new Error(`${K} data to decode must be a Uint8Array`);t=Object.assign({},N0,t);let r=bn(e),n=t.tokenizer||new Lo(r,t),o=Ue(n,t);if(o===Ne)throw new Error(`${K} did not find any content to decode`);if(o===Lr)throw new Error(`${K} got unexpected break`);return[o,e.subarray(n.pos())]}function na(e,t){let[r,n]=Hf(e,t);if(n.length>0)throw new Error(`${K} too many terminals, data makes no sense`);return r}var No=class e{constructor(t,r){if(typeof t!="number"||!Number.isInteger(t)||t<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=t,this.value=r}static decoder(t){return r=>new e(t,r())}static preserve(...t){let r={};for(let n of t)r[n]=e.decoder(n);return r}};Object.defineProperty(No.prototype,Symbol.toStringTag,{value:"Tagged"});var q0=Xe("ipns:utils"),jf=V("/ipns/");var z0=0,H0=18;function Yf(e){let t;if(e.pubKey!=null)try{t=bu(e.pubKey)}catch(r){throw q0.error(r),r}if(t!=null)return t}function Zf(e){let t=V("ipns-signature:");return Nt([t,e])}function Qe(e){return"signatureV1"in e?Wt.encode({value:V(e.value),signatureV1:e.signatureV1,validityType:e.validityType,validity:V(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 ce(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 Gt("Missing data or signatureV2");let r=Gf(t.data),n=j0(r.Value),o=z(r.Validity);if(t.value!=null&&t.signatureV1!=null)return Y0(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 vn(e){return Nt([jf,e.bytes])}function we(e){let t=Se(e.slice(jf.length));if(!Uo(t,z0)&&!Uo(t,H0))throw new nr("Multihash in IPNS key was not identity or sha2-256");return t}function Gf(e){let t=na(e);if(t.ValidityType===0)t.ValidityType=Wt.ValidityType.EOL;else throw new Rr("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 j0(e){let t=z(e).trim();if(t.startsWith("/"))return t;try{return`/ipfs/${H.decode(e).toV1().toString()}`}catch{}try{return`/ipfs/${H.parse(t).toV1().toString()}`}catch{}throw new So("Value must be a valid content path starting with /")}function Y0(e){if(e.data==null)throw new vo("Record data is missing");let t=Gf(e.data);if(!W(t.Value,e.value??new Uint8Array(0)))throw new Gt('Field "value" did not match between protobuf and CBOR');if(!W(t.Validity,e.validity??new Uint8Array(0)))throw new Gt('Field "validity" did not match between protobuf and CBOR');if(t.ValidityType!==e.validityType)throw new Gt('Field "validityType" did not match between protobuf and CBOR');if(t.Sequence!==e.sequence)throw new Gt('Field "sequence" did not match between protobuf and CBOR');if(t.TTL!==e.ttl)throw new Gt('Field "ttl" did not match between protobuf and CBOR')}function Uo(e,t){return e.code===t}var Z2=Xe("ipns"),G2=300*1e9,G0="/ipns/",W2=G0.length;var Wf=Go(js(),1);var ko=Xe("ipns:validator"),W0=1024*10;async function X0(e,t){let r=ce(t),n;try{let o=Zf(r.data);n=await e.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw ko.error("record signature verification failed"),new Gt("Record signature verification failed");if(r.validityType===Wt.ValidityType.EOL){if(Wf.default.fromString(r.validity).toDate().getTime()<Date.now())throw ko.error("record has expired"),new wo("record has expired")}else if(r.validityType!=null)throw ko.error("the validity type is unsupported"),new Rr("The validity type is unsupported");ko("ipns record for %s is valid",r.value)}async function Xf(e,t){if(t.byteLength>W0)throw new Eo("The record is too large");let r=we(e),n;Uo(r,0)&&(n=io(r));let o=ce(t),i=Yf(o)??n;if(i==null)throw new yn("Could not extract public key from IPNS record or routing key");let s=vn(i.toMultihash());if(!W(s,e))throw new yn("Embedded public key did not match routing key");await X0(i,t)}var Ko=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MESSAGE_LENGTH"};async function*Nr(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)),ur(i)&&(i=i.subarray()),o+=n.decode(i,{stream:!0}),o.length>(t?.maxMessageLength??o.length))throw new Ko("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 $t(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var ia=Go(Qf(),1);var sa=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},tl=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function aa(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=t,a,c,f=new Promise((l,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){h(tl(s));return}if(s&&(c=()=>{h(tl(s))},s.addEventListener("abort",c,{once:!0})),e.then(l,h),r===Number.POSITIVE_INFINITY)return;let m=new sa;a=i.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(E){h(E)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?l():o instanceof Error?h(o):(m.message=o??`Promise timed out after ${r} milliseconds`,h(m))},r)}).finally(()=>{f.clear(),c&&s&&s.removeEventListener("abort",c)});return f.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},f}function ca(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 Ur=class{#t=[];enqueue(t,r){let{priority:n=0,id:o}=r??{},i={priority:n,id:o,run:t};if(this.size===0||this.#t[this.size-1].priority>=n){this.#t.push(i);return}let s=ca(this.#t,i,(a,c)=>c.priority-a.priority);this.#t.splice(s,0,i)}setPriority(t,r){let n=this.#t.findIndex(i=>i.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:r,id:t})}remove(t){let r=this.#t.findIndex(n=>typeof t=="string"?n.id===t:n.run===t);r!==-1&&this.#t.splice(r,1)}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 ia.default{#t;#n;#r=0;#h;#m=!1;#x=!1;#c;#C=0;#w=0;#u;#f;#a;#s=[];#i=0;#e;#_;#o=0;#y;#l;#O=1n;#g=new Map;#E=new Set;timeout;constructor(t){if(super(),t={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Ur,strict:!1,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);if(t.strict&&t.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(t.strict&&t.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#t=t.carryoverIntervalCount??t.carryoverConcurrencyCount??!1,this.#n=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#h=t.intervalCap,this.#c=t.interval,this.#a=t.strict,this.#e=new t.queueClass,this.#_=t.queueClass,this.concurrency=t.concurrency,t.timeout!==void 0&&!(Number.isFinite(t.timeout)&&t.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${t.timeout}\` (${typeof t.timeout})`);this.timeout=t.timeout,this.#l=t.autoStart===!1,this.#M()}#S(t){for(;this.#i<this.#s.length;){let n=this.#s[this.#i];if(n!==void 0&&t-n>=this.#c)this.#i++;else break}(this.#i>100&&this.#i>this.#s.length/2||this.#i===this.#s.length)&&(this.#s=this.#s.slice(this.#i),this.#i=0)}#F(t){this.#a?this.#s.push(t):this.#r++}#L(){this.#a?this.#s.length>this.#i&&this.#s.pop():this.#r>0&&this.#r--}#v(){return this.#s.length-this.#i}get#N(){return this.#n?!0:this.#a?this.#v()<this.#h:this.#r<this.#h}get#U(){return this.#o<this.#y}#k(){this.#o--,this.#o===0&&this.emit("pendingZero"),this.#b(),this.emit("next")}#K(){this.#f=void 0,this.#D(),this.#R()}#$(t){if(this.#a){if(this.#S(t),this.#v()>=this.#h){let n=this.#s[this.#i],o=this.#c-(t-n);return this.#T(o),!0}return!1}if(this.#u===void 0){let r=this.#C-t;if(r<0){if(this.#w>0){let n=t-this.#w;if(n<this.#c)return this.#T(this.#c-n),!0}this.#r=this.#t?this.#o:0}else return this.#T(r),!0}return!1}#T(t){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#K()},t))}#A(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}#B(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#b(){if(this.#e.size===0){if(this.#A(),this.emit("empty"),this.#o===0){if(this.#B(),this.#a&&this.#i>0){let r=Date.now();this.#S(r)}this.emit("idle")}return!1}let t=!1;if(!this.#l){let r=Date.now(),n=!this.#$(r);if(this.#N&&this.#U){let o=this.#e.dequeue();this.#n||(this.#F(r),this.#p()),this.emit("active"),o(),n&&this.#R(),t=!0}}return t}#R(){this.#n||this.#u!==void 0||this.#a||(this.#u=setInterval(()=>{this.#D()},this.#c),this.#C=Date.now()+this.#c)}#D(){this.#a||(this.#r===0&&this.#o===0&&this.#u&&this.#A(),this.#r=this.#t?this.#o:0),this.#I(),this.#p()}#I(){for(;this.#b(););}get concurrency(){return this.#y}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#y=t,this.#I()}setPriority(t,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#e.setPriority(t,r)}async add(t,r={}){return r={timeout:this.timeout,...r,id:r.id??(this.#O++).toString()},new Promise((n,o)=>{let i=Symbol(`task-${r.id}`),s=()=>{},a=async()=>{s(),this.#o++,this.#g.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let u;try{try{r.signal?.throwIfAborted()}catch(h){throw this.#V(),this.#g.delete(i),h}this.#w=Date.now();let f=t({signal:r.signal});if(r.timeout&&(f=aa(Promise.resolve(f),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#o} running, ${this.#e.size} waiting)`})),r.signal){let{signal:h}=r;f=Promise.race([f,new Promise((m,E)=>{u=()=>{E(h.reason)},h.addEventListener("abort",u,{once:!0})})])}let l=await f;n(l),this.emit("completed",l)}catch(f){o(f),this.emit("error",f)}finally{u&&r.signal?.removeEventListener("abort",u),this.#g.delete(i),queueMicrotask(()=>{this.#k()})}};this.#e.enqueue(a,r);let c=()=>{if(this.#e instanceof Ur){this.#e.remove(a);return}this.#e.remove?.(r.id)};if(r.signal){let{signal:u}=r,f=()=>{s(),c(),o(u.reason),this.#b(),this.emit("next")};if(s=()=>{u.removeEventListener("abort",f),this.#E.delete(s)},u.aborted){f();return}u.addEventListener("abort",f,{once:!0}),this.#E.add(s)}this.emit("add"),this.#b()})}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#I(),this):this}pause(){this.#l=!0}clear(){for(let t of this.#E)t();this.#e=new this.#_,this.#A(),this.#P(),this.emit("empty"),this.#o===0&&(this.#B(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#e.size!==0&&await this.#d("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#d("next",()=>this.#e.size<t)}async onIdle(){this.#o===0&&this.#e.size===0||await this.#d("idle")}async onPendingZero(){this.#o!==0&&await this.#d("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#d("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#d("rateLimitCleared")}onError(){return new Promise((t,r)=>{let n=o=>{this.off("error",n),r(o)};this.on("error",n)})}async#d(t,r){return new Promise(n=>{let o=()=>{r&&!r()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#o}get isPaused(){return this.#l}#M(){this.#n||(this.on("add",()=>{this.#e.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#n||this.#x||(this.#x=!0,queueMicrotask(()=>{this.#x=!1,this.#P()}))}#V(){this.#n||(this.#L(),this.#p())}#P(){let t=this.#m;if(this.#n||this.#e.size===0){t&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#a){let o=Date.now();this.#S(o),r=this.#v()}else r=this.#r;let n=r>=this.#h;n!==t&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#o===this.#y&&this.#e.size>0||this.isRateLimited&&this.#e.size>0}get runningTasks(){return[...this.#g.values()].map(t=>({...t}))}};var tr=class extends Error{static name="InvalidRequestError";constructor(t="Invalid request"){super(t),this.name="InvalidRequestError"}},Mt=class extends Error{static name="BadResponseError";constructor(t="Bad response"){super(t),this.name="BadResponseError"}};function tm(e){return e[Symbol.asyncIterator]!=null}function em(e){if(tm(e))return(async()=>{for await(let t of e)return t})();for(let t of e)return t}var Mo=em;function rm(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 el=rm;function nm(e){return e[Symbol.asyncIterator]!=null}function om(e,t){let r=0;if(nm(e))return(async function*(){for await(let c of e)yield t(c,r++)})();let n=el(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 Vo=om;var rl=V("/ipns/");function nl(e){return W(e.subarray(0,rl.byteLength),rl)}var qo=class{client;constructor(t){this.client=t}async*findProviders(t,r={}){try{yield*Vo(this.client.getProviders(t,r),n=>({id:n.ID,multiaddrs:n.Addrs??[],routing:"delegated-http-routing-v1"}))}catch(n){if(n instanceof At)return;throw n}}async provide(){}async cancelReprovide(){}async put(t,r,n){if(!nl(t))return;let o=we(t),i=H.createV1(114,o),s=ce(r);await this.client.putIPNS(i,s,n)}async get(t,r){if(!nl(t))throw new At("Not found");let n=we(t),o=H.createV1(114,n);try{let i=await this.client.getIPNS(o,r);return Qe(i)}catch(i){throw i.name==="BadResponseError"?new At("Not found"):i}}toString(){return`DelegatedRoutingV1HttpApiClientContentRouting(${this.client.url})`}},zo=class{client;constructor(t){this.client=t}async findPeer(t,r={}){let n=await Mo(this.client.getPeers(t,r));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new At("Not found")}async*getClosestPeers(t,r={}){let n;try{n=H.decode(t)}catch{try{n=uo(ee.decode(t))}catch{n=H.createV1(qa,St.digest(t))}}for await(let o of this.client.getClosestPeers(n,r))yield{id:o.ID,multiaddrs:o.Addrs??[]}}toString(){return`DelegatedRoutingV1HttpApiClientPeerRouting(${this.client.url})`}};var Ho={concurrentRequests:4,timeout:3e4,cacheTTL:300*1e3,cacheName:"delegated-routing-v1-cache"},jo=class{url;started;httpQueue;shutDownController;timeout;contentRouting;peerRouting;filterAddrs;filterProtocols;inFlightRequests;cacheName;cache;cacheTTL;log;constructor(t,r){this.log=t.logger.forComponent("delegated-routing-v1-http-api-client"),this.started=!1,this.shutDownController=new AbortController,this.shutDownController.signal,this.httpQueue=new An({concurrency:r.concurrentRequests??Ho.concurrentRequests}),this.inFlightRequests=new Map,this.url=r.url instanceof URL?r.url:new URL(r.url),this.timeout=r.timeout??Ho.timeout,this.filterAddrs=r.filterAddrs,this.filterProtocols=r.filterProtocols,this.contentRouting=new qo(this),this.peerRouting=new zo(this),this.cacheName=r.cacheName??Ho.cacheName,this.cacheTTL=r.cacheTTL??Ho.cacheTTL}get[va](){return this.contentRouting}get[Aa](){return this.peerRouting}isStarted(){return this.started}async start(){this.started||(this.started=!0,this.cacheTTL>0&&(this.cache=await globalThis.caches?.open(this.cacheName),this.cache!=null&&this.log("cache enabled with ttl %d",this.cacheTTL)))}async stop(){this.httpQueue.clear(),this.shutDownController.abort(),await globalThis.caches?.delete(this.cacheName),this.started=!1}async*getProviders(t,r={}){this.log("getProviders starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=Br([this.shutDownController.signal,n,r.signal]);let i=$t(),s=$t(),a=0;this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let c=new URL(`${this.url}routing/v1/providers/${t}`);this.#n(c,r.filterAddrs,r.filterProtocols);let u={headers:{accept:"application/x-ndjson, application/json;q=0.8"},signal:o},f=await this.#r(c.toString(),u);if(!f.ok){if(f.status===404)return;throw f.status===422?new tr("Request does not conform to schema or semantic constraints"):new Mt(`Unexpected status code: ${f.status}`)}let l=f.headers.get("Content-Type");if(l==null)throw new Mt("No Content-Type header received");if(f.body==null){if(l!=="application/x-ndjson")throw new Mt("Routing response had no body");return}if(l.startsWith("application/json")){let m=(await f.json()).Providers??[];for(let E of m){let v=this.#t(E);v!=null&&(a++,yield v)}}else if(l.includes("application/x-ndjson"))for await(let h of Nr(mn(f.body))){let m=this.#t(h);m!=null&&(a++,yield m)}else throw new Mt(`Unsupported Content-Type: ${l}`)}finally{o.clear(),s.resolve(),this.log("getProviders finished found %d providers for %c",a,t)}}async*getPeers(t,r={}){this.log("getPeers starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=Br([this.shutDownController.signal,n,r.signal]);let i=$t(),s=$t();this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let a=new URL(`${this.url}routing/v1/peers/${t.toCID().toString()}`);this.#n(a,r.filterAddrs,r.filterProtocols);let c={headers:{Accept:"application/x-ndjson"},signal:o},u=await this.#r(a.toString(),c);if(u.status===404)return;if(u.status===422)throw new tr("Request does not conform to schema or semantic constraints");if(u.body==null)throw new Mt("Routing response had no body");if(u.headers.get("Content-Type")?.startsWith("application/json")){let h=(await u.json()).Peers??[];for(let m of h){let E=this.#t(m);E!=null&&(yield E)}}else for await(let l of Nr(mn(u.body))){let h=this.#t(l);h!=null&&(yield h)}}catch(a){this.log.error("getPeers errored - %e",a)}finally{o.clear(),s.resolve(),this.log("getPeers finished: %c",t)}}async*getClosestPeers(t,r={}){let n;if(Ta(t))n=t.toCID().toString();else if(H.asCID(t)===t||t instanceof H)n=t.toV1().toString();else throw new et("Key must be CID or PeerId");this.log("getClosestPeers starts: %s",n);let o=AbortSignal.timeout(this.timeout),i=Br([this.shutDownController.signal,o,r.signal]);let s=$t(),a=$t();this.httpQueue.add(async()=>(s.resolve(),a.promise));try{await s.promise;let c=new URL(`${this.url}routing/v1/dht/closest/peers/${n}`);this.#n(c,r.filterAddrs,r.filterProtocols);let u={headers:{Accept:"application/x-ndjson"},signal:i},f=await this.#r(c.toString(),u);if(f.status===404)return;if(f.status===422)throw new tr("Request does not conform to schema or semantic constraints");if(f.body==null)throw new Mt("Routing response had no body");if(f.headers.get("Content-Type")?.startsWith("application/json")){let m=(await f.json()).Peers??[];for(let E of m){let v=this.#t(E);v!=null&&(yield v)}}else for await(let h of Nr(mn(f.body))){let m=this.#t(h);m!=null&&(yield m)}}catch(c){this.log.error("getClosestPeers errored - %e",c)}finally{i.clear(),a.resolve(),this.log("getClosestPeers finished: %s",n)}}async getIPNS(t,r={}){this.log("getIPNS starts: %s",t);let n=AbortSignal.timeout(this.timeout),o=Br([this.shutDownController.signal,n,r.signal]);let i=$t(),s=$t();this.httpQueue.add(async()=>(i.resolve(),s.promise));let a=`${this.url}routing/v1/ipns/${t}`;try{await i.promise;let c={headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:o},u=await this.#r(a,c);if(this.log("getIPNS GET %s %d",a,u.status),u.status===404)throw new At("No matching records found");if(u.status===422)throw new tr("Request does not conform to schema or semantic constraints");if(!u.ok)throw new Mt(`Unexpected status code: ${u.status}`);let f=u.headers.get("Content-Type");if(f==null||!f.includes("application/vnd.ipfs.ipns-record"))throw new At("No matching records found");if(u.body==null)throw new Mt("GET ipns response had no body");let l=await u.arrayBuffer(),h=new Uint8Array(l,0,l.byteLength);return r.validate!==!1&&await Xf(vn(t.multihash),h),ce(h)}catch(c){throw this.log.error("getIPNS GET %s error - %e",a,c),c}finally{o.clear(),s.resolve(),this.log("getIPNS finished: %s",t)}}async putIPNS(t,r,n={}){this.log("putIPNS starts: %c",t);let o=AbortSignal.timeout(this.timeout),i=Br([this.shutDownController.signal,o,n.signal]);let s=$t(),a=$t();this.httpQueue.add(async()=>(s.resolve(),a.promise));let c=`${this.url}routing/v1/ipns/${t}`;try{await s.promise;let u=Qe(r),f={method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:u,signal:i},l=await this.#r(c,f);if(this.log("putIPNS PUT %s %d",c,l.status),l.status!==200)throw new Mt("PUT ipns response had status other than 200")}catch(u){throw this.log.error("putIPNS PUT %s error - %e",c,u.stack),u}finally{i.clear(),a.resolve(),this.log("putIPNS finished: %c",t)}}#t(t){try{let r=[],n=t.Addrs?.map(go)??[];return t.Protocols!=null&&r.push(...t.Protocols),t.Protocol!=null&&(r.push(t.Protocol),delete t.Protocol),{...t,Schema:"peer",ID:Eu(t.ID),Addrs:n,Protocols:r}}catch(r){this.log.error("could not conform record to peer schema - %e",r)}}#n(t,r,n){if(r!=null||this.filterAddrs!=null){let o=r?.join(",")??this.filterAddrs?.join(",")??"";o!==""&&t.searchParams.set("filter-addrs",o)}if(n!=null||this.filterProtocols!=null){let o=n?.join(",")??this.filterProtocols?.join(",")??"";o!==""&&t.searchParams.set("filter-protocols",o)}}async#r(t,r){let n=r.method??"GET",o=`${n}-${t}`;if(n==="GET"){let c=await this.cache?.match(t);if(c!=null){if(parseInt(c.headers.get("x-cache-expires")??"0",10)>Date.now())return this.log("returning cached response for %s",o),this.logResponse(c),c;this.log("evicting cached response for %s",o),await this.cache?.delete(t)}else this.cache!=null&&this.log("cache miss for %s",o)}let i=this.inFlightRequests.get(o);if(i!=null){let c=await i;return this.log("deduplicating outgoing request for %s",o),c.clone()}this.log("outgoing request:"),this.logRequest(t,r);let s=fetch(t,r).then(async c=>{if(this.log("incoming response:"),this.logResponse(c),this.cache!=null&&c.ok&&n==="GET"){let u=Date.now()+this.cacheTTL,f=new Headers(c.headers);f.set("x-cache-expires",u.toString());let l=new Response(c.clone().body,{status:c.status,statusText:c.statusText,headers:f});await this.cache.put(t,l)}return c}).finally(()=>{this.inFlightRequests.delete(o)});return this.inFlightRequests.set(o,s),await s}toString(){return`DefaultDelegatedRoutingV1HttpApiClient(${this.url})`}logRequest(t,r){let n=new Headers(r.headers);this.log("%s %s HTTP/1.1",r.method??"GET",t);for(let[o,i]of n.entries())this.log("%s: %s",o,i)}logResponse(t){this.log("HTTP/1.1 %d %s",t.status,t.statusText);for(let[r,n]of t.headers.entries())this.log("%s: %s",r,n)}};function ol(e){return t=>new jo(t,e)}function Yo(e){return{url:"https://delegated-ipfs.dev",filterProtocols:["unknown","transport-bitswap","transport-ipfs-gateway-http"],filterAddrs:["https","webtransport","webrtc","webrtc-direct","wss","tls"]}}var il=V("/ipns/");function sl(e){return W(e.subarray(0,il.byteLength),il)}var ua=class{name="delegated-http-router";client;constructor(t,r){this.client=ol(r)(t)}async provide(t,r){}async cancelReprovide(t,r){}async*findProviders(t,r){yield*Vo(this.client.getProviders(t,r),n=>({id:n.ID,multiaddrs:n.Addrs,protocols:n.Protocols,routing:"delegated-http-routing"}))}async put(t,r,n){if(!sl(t))return;let o=we(t),i=H.createV1(114,o),s=ce(r);await this.client.putIPNS(i,s,n)}async get(t,r){if(!sl(t))throw new At("Not found");let n=we(t),o=H.createV1(114,n);try{let i=await this.client.getIPNS(o,r);return Qe(i)}catch(i){throw i.name==="BadResponseError"?new At("Not found"):i}}async findPeer(t,r){let n=await Mo(this.client.getPeers(t,r));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new At("Not found")}async*getClosestPeers(t,r){}toString(){return`DelegatedHTTPRouter(${this.client.url})`}};function al(e){return t=>new ua(t,Yo(e))}var cl="[a-fA-F\\d:]",ke=e=>e&&e.includeBoundaries?`(?:(?<=\\s|^)(?=${cl})|(?<=${cl})(?=\\s|$))`:"",Qt="(?: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}",st="[a-fA-F\\d]{1,4}",Zo=`
14
14
  (?:
15
- (?:${at}:){7}(?:${at}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
16
- (?:${at}:){6}(?:${Jt}|:${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
17
- (?:${at}:){5}(?::${Jt}|(?::${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
18
- (?:${at}:){4}(?:(?::${at}){0,1}:${Jt}|(?::${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
19
- (?:${at}:){3}(?:(?::${at}){0,2}:${Jt}|(?::${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
20
- (?:${at}:){2}(?:(?::${at}){0,3}:${Jt}|(?::${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
21
- (?:${at}:){1}(?:(?::${at}){0,4}:${Jt}|(?::${at}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
22
- (?::(?:(?::${at}){0,5}:${Jt}|(?::${at}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
15
+ (?:${st}:){7}(?:${st}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
16
+ (?:${st}:){6}(?:${Qt}|:${st}|:)| // 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
17
+ (?:${st}:){5}(?::${Qt}|(?::${st}){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
18
+ (?:${st}:){4}(?:(?::${st}){0,1}:${Qt}|(?::${st}){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
19
+ (?:${st}:){3}(?:(?::${st}){0,2}:${Qt}|(?::${st}){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
20
+ (?:${st}:){2}(?:(?::${st}){0,3}:${Qt}|(?::${st}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
21
+ (?:${st}:){1}(?:(?::${st}){0,4}:${Qt}|(?::${st}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
22
+ (?::(?:(?::${st}){0,5}:${Qt}|(?::${st}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
23
23
  )(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
24
- `.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),hm=new RegExp(`(?:^${Jt}$)|(?:^${Fo}$)`),pm=new RegExp(`^${Jt}$`),mm=new RegExp(`^${Fo}$`),da=e=>e&&e.exact?hm:new RegExp(`(?:${Le(e)}${Jt}${Le(e)})|(?:${Le(e)}${Fo}${Le(e)})`,"g");da.v4=e=>e&&e.exact?pm:new RegExp(`${Le(e)}${Jt}${Le(e)}`,"g");da.v6=e=>e&&e.exact?mm:new RegExp(`${Le(e)}${Fo}${Le(e)}`,"g");var ha=da;function pa(e){let t=(...r)=>e(...r);return Object.defineProperty(t,"name",{value:`functionTimeout(${e.name||"<anonymous>"})`,configurable:!0}),t}function yl(){return!1}var{toString:ym}=Object.prototype;function ma(e){return ym.call(e)==="[object RegExp]"}var gl={global:"g",ignoreCase:"i",multiline:"m",dotAll:"s",sticky:"y",unicode:"u"};function ya(e,t={}){if(!ma(e))throw new TypeError("Expected a RegExp instance");let r=Object.keys(gl).map(o=>(typeof t[o]=="boolean"?t[o]:e[o])?gl[o]:"").join(""),n=new RegExp(t.source||e.source,r);return n.lastIndex=typeof t.lastIndex=="number"?t.lastIndex:e.lastIndex,n}function ga(e,t,{timeout:r}={}){try{return pa(()=>ya(e).test(t),{timeout:r})()}catch(n){if(yl(n))return!1;throw n}}var gm=15,xm=45,xl={timeout:400};function xa(e){return e.length>xm?!1:ga(ha.v6({exact:!0}),e,xl)}function bl(e){return e.length>gm?!1:ga(ha.v4({exact:!0}),e,xl)}var wl={http:"80",https:"443",ws:"80",wss:"443"},bm=["http","https","ws","wss"];function El(e,t){t=t??{};let r=t.defaultDnsType??"dns",{scheme:n,hostname:o,port:i,path:s}=wm(e),c=[Em(o,r),Sm(i,n),vm(n)];s!=null&&c.push(Am(s));let a="/"+c.filter(f=>!!f).reduce((f,u)=>f.concat(u),[]).join("/");return oo(a)}function wm(e){let[t]=e.split(":");bm.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=Im(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 Em(e,t){if(!(e==null||e==="")){if(bl(e))return["ip4",e];if(xa(e))return["ip6",e];if(e[0]==="["){let r=e.substring(1,e.length-1);if(xa(r))return["ip6",r]}return[t,e]}}function Sm(e,t){if(!(e==null||e===""))return t==="udp"?["udp",e]:["tcp",e]}function vm(e){if(e.match(/^tcp$|^udp$/)==null)return e==="https"?["/tls/http"]:e==="wss"?["/tls/ws"]:[e]}function Am(e){if(!(e==null||e===""))return["http-path",encodeURIComponent(e)]}function Im(e){if(!(e==null||e===""||wl[e]==null))return wl[e]}var Tm=["https://trustless-gateway.link","https://4everland.io"],Cm=2336;function Bm(e){return e=e.toString(),{id:vs(j.createV1(Cm,vt.digest(q(e)))),multiaddrs:[El(e)]}}function _m(e){return new URL(z(e.id.toMultihash().digest))}var ba=class{name="http-gateway-router";gateways;shuffle;constructor(t={}){this.gateways=(t.gateways??Tm).map(r=>Bm(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"],routing:"http-gateway-routing"}))}toString(){return`HTTPGatewayRouter([${this.gateways.map(t=>_m(t)).join(", ")}])`}};function Sl(e={}){return new ba(e)}var wa=class{name="libp2p-router";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)}toString(){return"Libp2pRouter()"}};function vl(e){return new wa(e)}return _l(Dm);})();
24
+ `.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),im=new RegExp(`(?:^${Qt}$)|(?:^${Zo}$)`),sm=new RegExp(`^${Qt}$`),am=new RegExp(`^${Zo}$`),fa=e=>e&&e.exact?im:new RegExp(`(?:${ke(e)}${Qt}${ke(e)})|(?:${ke(e)}${Zo}${ke(e)})`,"g");fa.v4=e=>e&&e.exact?sm:new RegExp(`${ke(e)}${Qt}${ke(e)}`,"g");fa.v6=e=>e&&e.exact?am:new RegExp(`${ke(e)}${Zo}${ke(e)}`,"g");var la=fa;function da(e){let t=(...r)=>e(...r);return Object.defineProperty(t,"name",{value:`functionTimeout(${e.name||"<anonymous>"})`,configurable:!0}),t}function ul(){return!1}var{toString:cm}=Object.prototype;function ha(e){return cm.call(e)==="[object RegExp]"}var fl={global:"g",ignoreCase:"i",multiline:"m",dotAll:"s",sticky:"y",unicode:"u"};function pa(e,t={}){if(!ha(e))throw new TypeError("Expected a RegExp instance");let r=Object.keys(fl).map(o=>(typeof t[o]=="boolean"?t[o]:e[o])?fl[o]:"").join(""),n=new RegExp(t.source||e.source,r);return n.lastIndex=typeof t.lastIndex=="number"?t.lastIndex:e.lastIndex,n}function ma(e,t,{timeout:r}={}){try{return da(()=>pa(e).test(t),{timeout:r})()}catch(n){if(ul(n))return!1;throw n}}var um=15,fm=45,ll={timeout:400};function ya(e){return e.length>fm?!1:ma(la.v6({exact:!0}),e,ll)}function dl(e){return e.length>um?!1:ma(la.v4({exact:!0}),e,ll)}var hl={http:"80",https:"443",ws:"80",wss:"443"},lm=["http","https","ws","wss"];function pl(e,t){t=t??{};let r=t.defaultDnsType??"dns",{scheme:n,hostname:o,port:i,path:s}=dm(e),a=[hm(o,r),pm(i,n),mm(n)];s!=null&&a.push(ym(s));let c="/"+a.filter(u=>!!u).reduce((u,f)=>u.concat(f),[]).join("/");return go(c)}function dm(e){let[t]=e.split(":");lm.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 c=gm(t);c!=null&&(o=c),c==null&&r==="http:"&&(o="80")}let a;return i!=null&&i!==""&&i!=="/"&&(i.startsWith("/")&&(i=i.substring(1)),a=i),s!=null&&s!==""&&(a=a??"",a+=s),{scheme:t,hostname:n,port:o,path:a}}function hm(e,t){if(!(e==null||e==="")){if(dl(e))return["ip4",e];if(ya(e))return["ip6",e];if(e[0]==="["){let r=e.substring(1,e.length-1);if(ya(r))return["ip6",r]}return[t,e]}}function pm(e,t){if(!(e==null||e===""))return t==="udp"?["udp",e]:["tcp",e]}function mm(e){if(e.match(/^tcp$|^udp$/)==null)return e==="https"?["/tls/http"]:e==="wss"?["/tls/ws"]:[e]}function ym(e){if(!(e==null||e===""))return["http-path",encodeURIComponent(e)]}function gm(e){if(!(e==null||e===""||hl[e]==null))return hl[e]}var bm=["https://trustless-gateway.link","https://4everland.io"],xm=2336;function wm(e){return e=e.toString(),{id:Ns(H.createV1(xm,St.digest(V(e)))),multiaddrs:[pl(e)]}}function Em(e){return new URL(z(e.id.toMultihash().digest))}var ga=class{name="http-gateway-router";gateways;shuffle;constructor(t={}){this.gateways=(t.gateways??bm).map(r=>wm(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"],routing:"http-gateway-routing"}))}toString(){return`HTTPGatewayRouter([${this.gateways.map(t=>Em(t)).join(", ")}])`}};function ml(e={}){return new ga(e)}var ba=class{name="libp2p-router";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)}toString(){return"Libp2pRouter()"}};function yl(e){return new ba(e)}return Sl(Sm);})();
25
25
  /*! Bundled license information:
26
26
 
27
- @noble/hashes/utils.js:
28
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
29
-
30
27
  @noble/curves/utils.js:
31
28
  @noble/curves/abstract/modular.js:
32
29
  @noble/curves/abstract/curve.js: