@helia/delegated-routing-v1-http-api-client 6.0.1 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,21 +1,7 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaDelegatedRoutingV1HttpApiClient = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var HeliaDelegatedRoutingV1HttpApiClient=(()=>{var lf=Object.create;var un=Object.defineProperty;var df=Object.getOwnPropertyDescriptor;var hf=Object.getOwnPropertyNames;var pf=Object.getPrototypeOf,mf=Object.prototype.hasOwnProperty;var Is=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),bt=(e,t)=>{for(var r in t)un(e,r,{get:t[r],enumerable:!0})},Ts=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of hf(t))!mf.call(e,o)&&o!==r&&un(e,o,{get:()=>t[o],enumerable:!(n=df(t,o))||n.enumerable});return e};var xo=(e,t,r)=>(r=e!=null?lf(pf(e)):{},Ts(t||!e||!e.__esModule?un(r,"default",{value:e,enumerable:!0}):r,e)),yf=e=>Ts(un({},"__esModule",{value:!0}),e);var fs=Is((Fb,us)=>{var Mb=(function(){typeof us<"u"&&(us.exports=I);var e=86400,t=3200,r=146097*t/400,n=e*r,o=1e3*n,i=864e13,s=4294967296,c=1e6,a="000000000",l=Math.trunc||function(h){var p=h-h%1;return p==0&&(h<0||h===0&&1/h!=1/0)?-0:p},u=I.prototype,f=(I.fromDate=function(h){return new I(+h)},I.fromInt64BE=U(0,1,2,3,0,4),I.fromInt64LE=U(3,2,1,0,4,0),I.fromString=function(D){var p,_=new I,D=(D+="").replace(/^\s*[+\-]?\d+/,function(m){var m=+m,g=1970+(m-1970)%400;return _.year=m-g,g}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(A,m,g){return m<0&&(g*=-1),p=6e4*(60*+m+ +g),""}).replace(/\.\d+$/,function(A){return _.nano=+(A+a).substr(1,9),""}).split(/\D+/);if(1<D.length?D[1]--:D[1]=0,_.time=p=Date.UTC.apply(Date,D)-(p||0),isNaN(p))throw new TypeError("Invalid Date");return C(_)},I.fromTimeT=function(h){return T(h,0)},u.year=0,u.time=0,u.nano=0,u.addNano=function(h){return this.nano+=+h||0,this},u.getNano=function(){var h=C(this);return(h.time%1e3*c+ +h.nano+1e9)%1e9},u.getTimeT=function(){var p=C(this),h=Math.floor(p.time/1e3),p=p.year;return p&&(h+=p*r*e/t),h},u.getYear=function(){return this.toDate().getUTCFullYear()+this.year},u.toDate=function(){return w(C(this).time)},u.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},u.toString=function(h){var p=this,_=p.toDate(),D={H:function(){return M(_.getUTCHours())},L:function(){return V(_.getUTCMilliseconds(),3)},M:function(){return M(_.getUTCMinutes())},N:function(){return V(p.getNano(),9)},S:function(){return M(_.getUTCSeconds())},Y:function(){var A=p.getYear();return 999999<A?"+"+A:9999<A?"+"+V(A,6):0<=A?V(A,4):-999999<=A?"-"+V(-A,6):A},a:function(){return E[_.getUTCDay()]},b:function(){return y[_.getUTCMonth()]},d:function(){return M(_.getUTCDate())},e:function(){return(function(A){return(9<A?"":" ")+(0|A)})(_.getUTCDate())},m:function(){return M(_.getUTCMonth()+1)}};return(function A(m){return m.replace(/%./g,function(g){var S=g[1],d=b[S],S=D[S];return d?A(d):S?S():g})})(h||f)},u.writeInt64BE=v(0,1,2,3,0,4),u.writeInt64LE=v(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),y=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],E=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],b={"%":"%",F:"%Y-%m-%d",n:`
3
- `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return I;function I(h,p,_){var D=this;if(!(D instanceof I))return new I(h,p,_);D.time=+h||0,D.nano=+p||0,D.year=+_||0,C(D)}function C(h){var p,_,D,A=h.year,m=h.time,g=h.nano,d=((g<0||c<=g)&&(g-=(_=Math.floor(g/c))*c,m+=_,_=1),A%t);return(m<-i||i<m||d)&&((p=l(m/o))&&(A+=p*t,m-=p*o),(D=w(m)).setUTCFullYear(d+D.getUTCFullYear()),D=(m=+D)+(p=l((A-=d)/t))*o,p&&-i<=D&&D<=i&&(A-=p*t,m=D),_=1),_&&(h.year=A,h.time=m,h.nano=g),h}function w(h){var p=new Date(0);return p.setTime(h),p}function T(A,D){A=+A||0;var _=l((D=(D|0)*s)/n)+l(A/n),D=D%n+A%n,A=l(D/n);return A&&(_+=A,D-=A*n),new I(1e3*D,0,_*t)}function v(h,p,_,D,A,m){return function(d,S){var P=C(this);d=d||new Array(8),k(d,S|=0);var N=Math.floor(P.time/1e3),P=P.year*(r*e/t),R=l(P/s)+l(N/s),P=P%s+N%s,N=Math.floor(P/s);return N&&(R+=N,P-=N*s),g(d,S+A,R),g(d,S+m,P),d};function g(d,S,R){d[S+h]=R>>24&255,d[S+p]=R>>16&255,d[S+_]=R>>8&255,d[S+D]=255&R}}function U(h,p,_,D,A,m){return function(d,S){k(d,S|=0);var R=g(d,S+A);return T(g(d,S+m),R)};function g(d,S){return 16777216*d[S+h]+(d[S+p]<<16|d[S+_]<<8|d[S+D])}}function k(h,p){if(h=h&&h.length,h==null)throw new TypeError("Invalid Buffer");if(h<p+8)throw new RangeError("Out of range")}function M(h){return(9<h?"":"0")+(0|h)}function V(h,p){return(a+(0|h)).substr(-p)}})()});var nf=Is((T1,bs)=>{"use strict";var $p=Object.prototype.hasOwnProperty,Et="~";function on(){}Object.create&&(on.prototype=Object.create(null),new on().__proto__||(Et=!1));function Hp(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function rf(e,t,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new Hp(r,n||e,o),s=Et?Et+t:t;return e._events[s]?e._events[s].fn?e._events[s]=[e._events[s],i]:e._events[s].push(i):(e._events[s]=i,e._eventsCount++),e}function ho(e,t){--e._eventsCount===0?e._events=new on:delete e._events[t]}function xt(){this._events=new on,this._eventsCount=0}xt.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)$p.call(r,n)&&t.push(Et?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};xt.prototype.listeners=function(t){var r=Et?Et+t:t,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};xt.prototype.listenerCount=function(t){var r=Et?Et+t:t,n=this._events[r];return n?n.fn?1:n.length:0};xt.prototype.emit=function(t,r,n,o,i,s){var c=Et?Et+t:t;if(!this._events[c])return!1;var a=this._events[c],l=arguments.length,u,f;if(a.fn){switch(a.once&&this.removeListener(t,a.fn,void 0,!0),l){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,r),!0;case 3:return a.fn.call(a.context,r,n),!0;case 4:return a.fn.call(a.context,r,n,o),!0;case 5:return a.fn.call(a.context,r,n,o,i),!0;case 6:return a.fn.call(a.context,r,n,o,i,s),!0}for(f=1,u=new Array(l-1);f<l;f++)u[f-1]=arguments[f];a.fn.apply(a.context,u)}else{var y=a.length,E;for(f=0;f<y;f++)switch(a[f].once&&this.removeListener(t,a[f].fn,void 0,!0),l){case 1:a[f].fn.call(a[f].context);break;case 2:a[f].fn.call(a[f].context,r);break;case 3:a[f].fn.call(a[f].context,r,n);break;case 4:a[f].fn.call(a[f].context,r,n,o);break;default:if(!u)for(E=1,u=new Array(l-1);E<l;E++)u[E-1]=arguments[E];a[f].fn.apply(a[f].context,u)}}return!0};xt.prototype.on=function(t,r,n){return rf(this,t,r,n,!1)};xt.prototype.once=function(t,r,n){return rf(this,t,r,n,!0)};xt.prototype.removeListener=function(t,r,n,o){var i=Et?Et+t:t;if(!this._events[i])return this;if(!r)return ho(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&ho(this,i);else{for(var c=0,a=[],l=s.length;c<l;c++)(s[c].fn!==r||o&&!s[c].once||n&&s[c].context!==n)&&a.push(s[c]);a.length?this._events[i]=a.length===1?a[0]:a:ho(this,i)}return this};xt.prototype.removeAllListeners=function(t){var r;return t?(r=Et?Et+t:t,this._events[r]&&ho(this,r)):(this._events=new on,this._eventsCount=0),this};xt.prototype.off=xt.prototype.removeListener;xt.prototype.addListener=xt.prototype.on;xt.prefixed=Et;xt.EventEmitter=xt;typeof bs<"u"&&(bs.exports=xt)});var Xp={};bt(Xp,{delegatedRoutingV1HttpApiClient:()=>Wp});var Bs=Symbol.for("@libp2p/content-routing");var nt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},qe=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Zt=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var fn=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},$e=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var He=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var ln=Symbol.for("@libp2p/peer-id");function _s(e){return!!e?.[ln]}var Ds=Symbol.for("@libp2p/peer-routing");var vo={};bt(vo,{base58btc:()=>W,base58flickr:()=>vf});var n0=new Uint8Array(0);function Rs(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function ee(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Ls(e){return new TextEncoder().encode(e)}function Ps(e){return new TextDecoder().decode(e)}function gf(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var c=e.length,a=e.charAt(0),l=Math.log(c)/Math.log(256),u=Math.log(256)/Math.log(c);function f(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var I=0,C=0,w=0,T=b.length;w!==T&&b[w]===0;)w++,I++;for(var v=(T-w)*u+1>>>0,U=new Uint8Array(v);w!==T;){for(var k=b[w],M=0,V=v-1;(k!==0||M<C)&&V!==-1;V--,M++)k+=256*U[V]>>>0,U[V]=k%c>>>0,k=k/c>>>0;if(k!==0)throw new Error("Non-zero carry");C=M,w++}for(var h=v-C;h!==v&&U[h]===0;)h++;for(var p=a.repeat(I);h<v;++h)p+=e.charAt(U[h]);return p}function y(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var I=0;if(b[I]!==" "){for(var C=0,w=0;b[I]===a;)C++,I++;for(var T=(b.length-I)*l+1>>>0,v=new Uint8Array(T);b[I];){var U=r[b.charCodeAt(I)];if(U===255)return;for(var k=0,M=T-1;(U!==0||k<w)&&M!==-1;M--,k++)U+=c*v[M]>>>0,v[M]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");w=k,I++}if(b[I]!==" "){for(var V=T-w;V!==T&&v[V]===0;)V++;for(var h=new Uint8Array(C+(T-V)),p=C;V!==T;)h[p++]=v[V++];return h}}}function E(b){var I=y(b);if(I)return I;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:y,decode:E}}var xf=gf,bf=xf,Ns=bf;var bo=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},wo=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Os(this,t)}},Eo=class{decoders;constructor(t){this.decoders=t}or(t){return Os(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Os(e,t){return new Eo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var So=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new bo(t,r,n),this.decoder=new wo(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ze({name:e,prefix:t,encode:r,decode:n}){return new So(e,t,r,n)}function pe({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ns(r,e);return ze({prefix:t,name:e,encode:n,decode:i=>ee(o(i))})}function wf(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,c=0,a=0;for(let l=0;l<o;++l){let u=t[e[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|u,s+=r,s>=8&&(s-=8,i[a++]=255&c>>s)}if(s>=r||(255&c<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Ef(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 Sf(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function ot({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Sf(n);return ze({prefix:t,name:e,encode(i){return Ef(i,n,r)},decode(i){return wf(i,o,r,e)}})}var W=pe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),vf=pe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ao={};bt(Ao,{base32:()=>jt,base32hex:()=>Tf,base32hexpad:()=>_f,base32hexpadupper:()=>Df,base32hexupper:()=>Bf,base32pad:()=>Cf,base32padupper:()=>If,base32upper:()=>Af,base32z:()=>Rf});var jt=ot({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Af=ot({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Cf=ot({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),If=ot({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Tf=ot({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Bf=ot({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),_f=ot({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Df=ot({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Rf=ot({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Co={};bt(Co,{base36:()=>Ge,base36upper:()=>Lf});var Ge=pe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Lf=pe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Yt={};bt(Yt,{Digest:()=>Te,create:()=>Vt,decode:()=>me,equals:()=>To,hasCode:()=>Xf});var Pf=Vs,ks=128,Uf=127,Nf=~Uf,Of=Math.pow(2,31);function Vs(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Of;)t[r++]=e&255|ks,e/=128;for(;e&Nf;)t[r++]=e&255|ks,e>>>=7;return t[r]=e|0,Vs.bytes=r-n+1,t}var kf=Io,Kf=128,Ks=127;function Io(e,n){var r=0,n=n||0,o=0,i=n,s,c=e.length;do{if(i>=c)throw Io.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&Ks)<<o:(s&Ks)*Math.pow(2,o),o+=7}while(s>=Kf);return Io.bytes=i-n,r}var Vf=Math.pow(2,7),Mf=Math.pow(2,14),Ff=Math.pow(2,21),qf=Math.pow(2,28),$f=Math.pow(2,35),Hf=Math.pow(2,42),zf=Math.pow(2,49),Gf=Math.pow(2,56),Zf=Math.pow(2,63),jf=function(e){return e<Vf?1:e<Mf?2:e<Ff?3:e<qf?4:e<$f?5:e<Hf?6:e<zf?7:e<Gf?8:e<Zf?9:10},Yf={encode:Pf,decode:kf,encodingLength:jf},Wf=Yf,Ar=Wf;function Cr(e,t=0){return[Ar.decode(e,t),Ar.decode.bytes]}function Ze(e,t,r=0){return Ar.encode(e,t,r),t}function je(e){return Ar.encodingLength(e)}function Vt(e,t){let r=t.byteLength,n=je(e),o=n+je(r),i=new Uint8Array(o+r);return Ze(e,i,0),Ze(r,i,n),i.set(t,o),new Te(e,r,t,i)}function me(e){let t=ee(e),[r,n]=Cr(t),[o,i]=Cr(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Te(r,o,s,t)}function To(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Rs(e.bytes,r.bytes)}}var Te=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Xf(e,t){return e.code===t}function Ms(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Qf(r,Bo(e),t??W.encoder);default:return tl(r,Bo(e),t??jt.encoder)}}var Fs=new WeakMap;function Bo(e){let t=Fs.get(e);if(t==null){let r=new Map;return Fs.set(e,r),r}return t}var j=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Ir)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==el)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&&To(t.multihash,n.multihash)}toString(t){return Ms(this,t)}toJSON(){return{"/":Ms(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new e(n,o,i,s??qs(n,o,i.bytes))}else if(r[rl]===!0){let{version:n,multihash:o,code:i}=r,s=me(o);return e.create(n,i,s)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Ir)throw new Error(`Version 0 CID must use dag-pb (code: ${Ir}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=qs(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Ir,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=ee(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new Te(r.multihashCode,r.digestSize,i,o);return[r.version===0?e.createV0(s):e.createV1(r.codec,s),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[f,y]=Cr(t.subarray(r));return r+=y,f},o=n(),i=Ir;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,c=n(),a=n(),l=r+a,u=l-s;return{version:o,codec:i,multihashCode:c,digestSize:a,multihashSize:u,size:l}}static parse(t,r){let[n,o]=Jf(t,r),i=e.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Bo(i).set(n,t),i}};function Jf(e,t){switch(e[0]){case"Q":{let r=t??W;return[W.prefix,r.decode(`${W.prefix}${e}`)]}case W.prefix:{let r=t??W;return[W.prefix,r.decode(e)]}case jt.prefix:{let r=t??jt;return[jt.prefix,r.decode(e)]}case Ge.prefix:{let r=t??Ge;return[Ge.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function Qf(e,t,r){let{prefix:n}=r;if(n!==W.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return o}function tl(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o}var Ir=112,el=18;function qs(e,t,r){let n=je(e),o=n+je(t),i=new Uint8Array(o+r.byteLength);return Ze(e,i,0),Ze(t,i,n),i.set(r,o),i}var rl=Symbol.for("@ipld/js-cid/CID");var _o={};bt(_o,{identity:()=>Ct});var $s=0,nl="identity",Hs=ee;function ol(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($s,Hs(e))}var Ct={code:$s,name:nl,encode:Hs,digest:ol};function J(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function re(e=0){return new Uint8Array(e)}function It(e=0){return new Uint8Array(e)}function Pt(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=It(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Gs=Symbol.for("@achingbrain/uint8arraylist");function zs(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Ye(e){return!!e?.[Gs]}var Tt=class e{bufs;length;[Gs]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Ye(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Ye(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=zs(this.bufs,t);return r.buf[r.index]}set(t,r){let n=zs(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Ye(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Pt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Pt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),i=new e;return i.length=o,i.bufs=[...n],i}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],c=o,a=c+s.byteLength;if(o=a,t>=a)continue;let l=t>=c&&t<a,u=r>c&&r<=a;if(l&&u){if(t===c&&r===a){n.push(s);break}let f=t-c;n.push(s.subarray(f,f+(r-t)));break}if(l){if(t===0){n.push(s);continue}n.push(s.subarray(t-c));continue}if(u){if(r===a){n.push(s);break}n.push(s.subarray(0,r-c));break}n.push(s)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Ye(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let f=0;f<i;f++)s[f]=-1;for(let f=0;f<o;f++)s[n[f]]=f;let c=s,a=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=r;f<=a;f+=u){u=0;for(let y=l;y>=0;y--){let E=this.get(f+y);if(n[y]!==E){u=Math.max(1,y-c[E]);break}}if(u===0)return f}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=It(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=re(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=re(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=re(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=It(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=re(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=re(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=re(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=re(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=re(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!J(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};var Do={};bt(Do,{base10:()=>il});var il=pe({prefix:"9",name:"base10",alphabet:"0123456789"});var Ro={};bt(Ro,{base16:()=>sl,base16upper:()=>al});var sl=ot({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),al=ot({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Lo={};bt(Lo,{base2:()=>cl});var cl=ot({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Po={};bt(Po,{base256emoji:()=>hl});var Zs=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),ul=Zs.reduce((e,t,r)=>(e[r]=t,e),[]),fl=Zs.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function ll(e){return e.reduce((t,r)=>(t+=ul[r],t),"")}function dl(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=fl[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var hl=ze({prefix:"\u{1F680}",name:"base256emoji",encode:ll,decode:dl});var Oo={};bt(Oo,{base64:()=>Uo,base64pad:()=>pl,base64url:()=>No,base64urlpad:()=>ml});var Uo=ot({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),pl=ot({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),No=ot({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ml=ot({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ko={};bt(ko,{base8:()=>yl});var yl=ot({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ko={};bt(Ko,{identity:()=>gl});var gl=ze({prefix:"\0",name:"identity",encode:e=>Ps(e),decode:e=>Ls(e)});var M0=new TextEncoder,F0=new TextDecoder;var js=85;var Fo={};bt(Fo,{sha256:()=>Tr,sha512:()=>wl});var bl=20;function Mo({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Vo(e,t,r,n,o)}var Vo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??bl,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?Ws(n,this.code,r?.truncate):n.then(o=>Ws(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ws(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 Js(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Tr=Mo({name:"sha2-256",code:18,encode:Js("SHA-256")}),wl=Mo({name:"sha2-512",code:19,encode:Js("SHA-512")});var Br={...Ko,...Lo,...ko,...Do,...Ro,...Ao,...Co,...vo,...Oo,...Po},Q0={...Fo,..._o};function ta(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Qs=ta("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),qo=ta("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=It(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),El={utf8:Qs,"utf-8":Qs,hex:Br.base16,latin1:qo,ascii:qo,binary:qo,...Br},hn=El;function H(e,t="utf8"){let r=hn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function z(e,t="utf8"){let r=hn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Sl=parseInt("11111",2),$o=parseInt("10000000",2),vl=parseInt("01111111",2),ea={0:_r,1:_r,2:Al,3:Tl,4:Bl,5:Il,6:Cl,16:_r,22:_r,48:_r};function ne(e,t={offset:0}){let r=e[t.offset]&Sl;if(t.offset++,ea[r]!=null)return ea[r](e,t);throw new Error("No decoder for tag "+r)}function Dr(e,t){let r=0;if((e[t.offset]&$o)===$o){let n=e[t.offset]&vl,o="0x";t.offset++;for(let i=0;i<n;i++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function _r(e,t){Dr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=ne(e,t);if(n===null)break;r.push(n)}return r}function Al(e,t){let r=Dr(e,t),n=t.offset,o=t.offset+r,i=[];for(let s=n;s<o;s++)s===n&&e[s]===0||i.push(e[s]);return t.offset+=r,Uint8Array.from(i)}function Cl(e,t){let r=Dr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let c=`${i}.${s}`,a=[];for(;t.offset<n;){let l=e[t.offset];if(t.offset++,a.push(l&127),l<128){a.reverse();let u=0;for(let f=0;f<a.length;f++)u+=a[f]<<f*7;c+=`.${u}`,a=[]}}return c}function Il(e,t){return t.offset++,null}function Tl(e,t){let r=Dr(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Bl(e,t){let r=Dr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function _l(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new Tt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Ho(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=_l(e.byteLength);return new Tt(Uint8Array.from([t.byteLength|$o]),t)}function St(e){let t=new Tt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new Tt(Uint8Array.from([2]),Ho(t),t)}function pn(e){let t=Uint8Array.from([0]),r=new Tt(t,e);return new Tt(Uint8Array.from([3]),Ho(r),r)}function ye(e,t=48){let r=new Tt;for(let n of e)r.append(n);return new Tt(Uint8Array.from([t]),Ho(r),r)}async function ra(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 Dl=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Rl=Uint8Array.from([6,5,43,129,4,0,34]),Ll=Uint8Array.from([6,5,43,129,4,0,35]),Pl={ext:!0,kty:"EC",crv:"P-256"},Ul={ext:!0,kty:"EC",crv:"P-384"},Nl={ext:!0,kty:"EC",crv:"P-521"},zo=32,Go=48,Zo=66;function jo(e){let t=ne(e);return na(t)}function na(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===zo*2+1)return n=z(t.subarray(r,r+zo),"base64url"),o=z(t.subarray(r+zo),"base64url"),new We({...Pl,key_ops:["verify"],x:n,y:o});if(t.byteLength===Go*2+1)return n=z(t.subarray(r,r+Go),"base64url"),o=z(t.subarray(r+Go),"base64url"),new We({...Ul,key_ops:["verify"],x:n,y:o});if(t.byteLength===Zo*2+1)return n=z(t.subarray(r,r+Zo),"base64url"),o=z(t.subarray(r+Zo),"base64url"),new We({...Nl,key_ops:["verify"],x:n,y:o});throw new nt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function oa(e){return ye([St(Uint8Array.from([1])),ye([Ol(e.crv)],160),ye([pn(new Tt(Uint8Array.from([4]),H(e.x??"","base64url"),H(e.y??"","base64url")))],161)]).subarray()}function Ol(e){if(e==="P-256")return Dl;if(e==="P-384")return Rl;if(e==="P-521")return Ll;throw new nt(`Invalid curve ${e}`)}var We=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=oa(this.jwk)),this._raw}toMultihash(){return Ct.digest(Xe(this))}toCID(){return j.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:J(this.raw,t.raw)}async verify(t,r,n){return ra(this.jwk,r,t,n)}};function Be(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Wt(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function $(e,t,r=""){let n=Be(e),o=e?.length,i=t!==void 0;if(!n||i&&o!==t){let s=r&&`"${r}" `,c=i?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(s+"expected Uint8Array"+c+", got "+a)}return e}function mn(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Wt(e.outputLen),Wt(e.blockLen)}function Je(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function sa(e,t){$(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function ie(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function yn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Mt(e,t){return e<<32-t|e>>>t}var aa=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",kl=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function se(e){if($(e),aa)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=kl[e[r]];return t}var oe={_0:48,_9:57,A:65,F:70,a:97,f:102};function ia(e){if(e>=oe._0&&e<=oe._9)return e-oe._0;if(e>=oe.A&&e<=oe.F)return e-(oe.A-10);if(e>=oe.a&&e<=oe.f)return e-(oe.a-10)}function ae(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(aa)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=ia(e.charCodeAt(i)),c=ia(e.charCodeAt(i+1));if(s===void 0||c===void 0){let a=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+i)}n[o]=s*16+c}return n}function vt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];$(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let i=e[n];r.set(i,o),o+=i.length}return r}function Yo(e,t={}){let r=(o,i)=>e(i).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function Qe(e=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}var Wo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ca(e,t,r){return e&t^~e&r}function ua(e,t,r){return e&t^e&r^t&r}var Rr=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=yn(this.buffer)}update(t){Je(this),$(t);let{view:r,buffer:n,blockLen:o}=this,i=t.length;for(let s=0;s<i;){let c=Math.min(o-this.pos,i-s);if(c===o){let a=yn(t);for(;o<=i-s;s+=o)this.process(a,s);continue}n.set(t.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Je(this),sa(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,ie(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let f=s;f<o;f++)r[f]=0;n.setBigUint64(o-8,BigInt(this.length*8),i),this.process(n,0);let c=yn(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let l=a/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)c.setUint32(4*f,u[f],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:c}=this;return t.destroyed=s,t.finished=i,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},ce=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var dt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var gn=BigInt(4294967295),fa=BigInt(32);function Kl(e,t=!1){return t?{h:Number(e&gn),l:Number(e>>fa&gn)}:{h:Number(e>>fa&gn)|0,l:Number(e&gn)|0}}function la(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let i=0;i<r;i++){let{h:s,l:c}=Kl(e[i],t);[n[i],o[i]]=[s,c]}return[n,o]}var Xo=(e,t,r)=>e>>>r,Jo=(e,t,r)=>e<<32-r|t>>>r,_e=(e,t,r)=>e>>>r|t<<32-r,De=(e,t,r)=>e<<32-r|t>>>r,Lr=(e,t,r)=>e<<64-r|t>>>r-32,Pr=(e,t,r)=>e>>>r-32|t<<64-r;function Xt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var da=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),ha=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,pa=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ma=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,ya=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ga=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;var Ml=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ge=new Uint32Array(64),Qo=class extends Rr{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:i,F:s,G:c,H:a}=this;return[t,r,n,o,i,s,c,a]}set(t,r,n,o,i,s,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=c|0,this.H=a|0}process(t,r){for(let f=0;f<16;f++,r+=4)ge[f]=t.getUint32(r,!1);for(let f=16;f<64;f++){let y=ge[f-15],E=ge[f-2],b=Mt(y,7)^Mt(y,18)^y>>>3,I=Mt(E,17)^Mt(E,19)^E>>>10;ge[f]=I+ge[f-7]+b+ge[f-16]|0}let{A:n,B:o,C:i,D:s,E:c,F:a,G:l,H:u}=this;for(let f=0;f<64;f++){let y=Mt(c,6)^Mt(c,11)^Mt(c,25),E=u+y+ca(c,a,l)+Ml[f]+ge[f]|0,I=(Mt(n,2)^Mt(n,13)^Mt(n,22))+ua(n,o,i)|0;u=l,l=a,a=c,c=s+E|0,s=i,i=o,o=n,n=E+I|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,o,i,s,c,a,l,u)}roundClean(){ie(ge)}destroy(){this.set(0,0,0,0,0,0,0,0),ie(this.buffer)}},ti=class extends Qo{A=ce[0]|0;B=ce[1]|0;C=ce[2]|0;D=ce[3]|0;E=ce[4]|0;F=ce[5]|0;G=ce[6]|0;H=ce[7]|0;constructor(){super(32)}};var xa=la(["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))),Fl=xa[0],ql=xa[1],xe=new Uint32Array(80),be=new Uint32Array(80),ei=class extends Rr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:c,Dl:a,Eh:l,El:u,Fh:f,Fl:y,Gh:E,Gl:b,Hh:I,Hl:C}=this;return[t,r,n,o,i,s,c,a,l,u,f,y,E,b,I,C]}set(t,r,n,o,i,s,c,a,l,u,f,y,E,b,I,C){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=c|0,this.Dl=a|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=y|0,this.Gh=E|0,this.Gl=b|0,this.Hh=I|0,this.Hl=C|0}process(t,r){for(let v=0;v<16;v++,r+=4)xe[v]=t.getUint32(r),be[v]=t.getUint32(r+=4);for(let v=16;v<80;v++){let U=xe[v-15]|0,k=be[v-15]|0,M=_e(U,k,1)^_e(U,k,8)^Xo(U,k,7),V=De(U,k,1)^De(U,k,8)^Jo(U,k,7),h=xe[v-2]|0,p=be[v-2]|0,_=_e(h,p,19)^Lr(h,p,61)^Xo(h,p,6),D=De(h,p,19)^Pr(h,p,61)^Jo(h,p,6),A=pa(V,D,be[v-7],be[v-16]),m=ma(A,M,_,xe[v-7],xe[v-16]);xe[v]=m|0,be[v]=A|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:c,Cl:a,Dh:l,Dl:u,Eh:f,El:y,Fh:E,Fl:b,Gh:I,Gl:C,Hh:w,Hl:T}=this;for(let v=0;v<80;v++){let U=_e(f,y,14)^_e(f,y,18)^Lr(f,y,41),k=De(f,y,14)^De(f,y,18)^Pr(f,y,41),M=f&E^~f&I,V=y&b^~y&C,h=ya(T,k,V,ql[v],be[v]),p=ga(h,w,U,M,Fl[v],xe[v]),_=h|0,D=_e(n,o,28)^Lr(n,o,34)^Lr(n,o,39),A=De(n,o,28)^Pr(n,o,34)^Pr(n,o,39),m=n&i^n&c^i&c,g=o&s^o&a^s&a;w=I|0,T=C|0,I=E|0,C=b|0,E=f|0,b=y|0,{h:f,l:y}=Xt(l|0,u|0,p|0,_|0),l=c|0,u=a|0,c=i|0,a=s|0,i=n|0,s=o|0;let d=da(_,A,g);n=ha(d,p,D,m),o=d|0}({h:n,l:o}=Xt(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Xt(this.Bh|0,this.Bl|0,i|0,s|0),{h:c,l:a}=Xt(this.Ch|0,this.Cl|0,c|0,a|0),{h:l,l:u}=Xt(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:y}=Xt(this.Eh|0,this.El|0,f|0,y|0),{h:E,l:b}=Xt(this.Fh|0,this.Fl|0,E|0,b|0),{h:I,l:C}=Xt(this.Gh|0,this.Gl|0,I|0,C|0),{h:w,l:T}=Xt(this.Hh|0,this.Hl|0,w|0,T|0),this.set(n,o,i,s,c,a,l,u,f,y,E,b,I,C,w,T)}roundClean(){ie(xe,be)}destroy(){ie(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ri=class extends ei{Ah=dt[0]|0;Al=dt[1]|0;Bh=dt[2]|0;Bl=dt[3]|0;Ch=dt[4]|0;Cl=dt[5]|0;Dh=dt[6]|0;Dl=dt[7]|0;Eh=dt[8]|0;El=dt[9]|0;Fh=dt[10]|0;Fl=dt[11]|0;Gh=dt[12]|0;Gl=dt[13]|0;Hh=dt[14]|0;Hl=dt[15]|0;constructor(){super(64)}};var tr=Yo(()=>new ti,Wo(1));var ba=Yo(()=>new ri,Wo(3));var oi=BigInt(0),ni=BigInt(1);function ue(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function wa(e){if(typeof e=="bigint"){if(!xn(e))throw new Error("positive bigint expected, got "+e)}else Wt(e);return e}function Ur(e){let t=wa(e).toString(16);return t.length&1?"0"+t:t}function Ea(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?oi:BigInt("0x"+e)}function er(e){return Ea(se(e))}function Re(e){return Ea(se(wn($(e)).reverse()))}function bn(e,t){Wt(t),e=wa(e);let r=ae(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function ii(e,t){return bn(e,t).reverse()}function wn(e){return Uint8Array.from(e)}var xn=e=>typeof e=="bigint"&&oi<=e;function $l(e,t,r){return xn(e)&&xn(t)&&xn(r)&&t<=e&&e<r}function Nr(e,t,r,n){if(!$l(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function si(e){let t;for(t=0;e>oi;e>>=ni,t+=1);return t}var Or=e=>(ni<<BigInt(e))-ni;function Sa(e,t,r){if(Wt(e,"hashLen"),Wt(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=C=>new Uint8Array(C),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),c=1e3,a=n(e),l=n(e),u=0,f=()=>{a.fill(1),l.fill(0),u=0},y=(...C)=>r(l,vt(a,...C)),E=(C=o)=>{l=y(i,C),a=y(),C.length!==0&&(l=y(s,C),a=y())},b=()=>{if(u++>=c)throw new Error("drbg: tried max amount of iterations");let C=0,w=[];for(;C<t;){a=y();let T=a.slice();w.push(T),C+=a.length}return vt(...w)};return(C,w)=>{f(),E(C);let T;for(;!(T=w(b()));)E();return f(),T}}function we(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(i,s,c){let a=e[i];if(c&&a===void 0)return;let l=typeof a;if(l!==s||a===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${l}`)}let o=(i,s)=>Object.entries(i).forEach(([c,a])=>n(c,a,s));o(t,!1),o(r,!0)}function rr(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let i=e(r,...n);return t.set(r,i),i}}var wt=BigInt(0),at=BigInt(1),Le=BigInt(2),Ca=BigInt(3),Ia=BigInt(4),Ta=BigInt(5),Hl=BigInt(7),Ba=BigInt(8),zl=BigInt(9),_a=BigInt(16);function it(e,t){let r=e%t;return r>=wt?r:t+r}function X(e,t,r){let n=e;for(;t-- >wt;)n*=n,n%=r;return n}function va(e,t){if(e===wt)throw new Error("invert: expected non-zero number");if(t<=wt)throw new Error("invert: expected positive modulus, got "+t);let r=it(e,t),n=t,o=wt,i=at,s=at,c=wt;for(;r!==wt;){let l=n/r,u=n%r,f=o-s*l,y=i-c*l;n=r,r=u,o=s,i=c,s=f,c=y}if(n!==at)throw new Error("invert: does not exist");return it(o,t)}function ci(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Da(e,t){let r=(e.ORDER+at)/Ia,n=e.pow(t,r);return ci(e,n,t),n}function Gl(e,t){let r=(e.ORDER-Ta)/Ba,n=e.mul(t,Le),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,Le),o),c=e.mul(i,e.sub(s,e.ONE));return ci(e,c,t),c}function Zl(e){let t=nr(e),r=Ra(e),n=r(t,t.neg(t.ONE)),o=r(t,n),i=r(t,t.neg(n)),s=(e+Hl)/_a;return(c,a)=>{let l=c.pow(a,s),u=c.mul(l,n),f=c.mul(l,o),y=c.mul(l,i),E=c.eql(c.sqr(u),a),b=c.eql(c.sqr(f),a);l=c.cmov(l,u,E),u=c.cmov(y,f,b);let I=c.eql(c.sqr(u),a),C=c.cmov(l,u,I);return ci(c,C,a),C}}function Ra(e){if(e<Ca)throw new Error("sqrt is not defined for small field");let t=e-at,r=0;for(;t%Le===wt;)t/=Le,r++;let n=Le,o=nr(e);for(;Aa(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Da;let i=o.pow(n,t),s=(t+at)/Le;return function(a,l){if(a.is0(l))return l;if(Aa(a,l)!==1)throw new Error("Cannot find square root");let u=r,f=a.mul(a.ONE,i),y=a.pow(l,t),E=a.pow(l,s);for(;!a.eql(y,a.ONE);){if(a.is0(y))return a.ZERO;let b=1,I=a.sqr(y);for(;!a.eql(I,a.ONE);)if(b++,I=a.sqr(I),b===u)throw new Error("Cannot find square root");let C=at<<BigInt(u-b-1),w=a.pow(f,C);u=b,f=a.sqr(w),y=a.mul(y,f),E=a.mul(E,w)}return E}}function jl(e){return e%Ia===Ca?Da:e%Ba===Ta?Gl:e%_a===zl?Zl(e):Ra(e)}var La=(e,t)=>(it(e,t)&at)===at,Yl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ui(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Yl.reduce((n,o)=>(n[o]="function",n),t);return we(e,r),e}function Wl(e,t,r){if(r<wt)throw new Error("invalid exponent, negatives unsupported");if(r===wt)return e.ONE;if(r===at)return t;let n=e.ONE,o=t;for(;r>wt;)r&at&&(n=e.mul(n,o)),o=e.sqr(o),r>>=at;return n}function kr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((s,c,a)=>e.is0(c)?s:(n[a]=s,e.mul(s,c)),e.ONE),i=e.inv(o);return t.reduceRight((s,c,a)=>e.is0(c)?s:(n[a]=e.mul(s,n[a]),e.mul(s,c)),i),n}function Aa(e,t){let r=(e.ORDER-at)/Le,n=e.pow(t,r),o=e.eql(n,e.ONE),i=e.eql(n,e.ZERO),s=e.eql(n,e.neg(e.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function Xl(e,t){t!==void 0&&Wt(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var ai=class{ORDER;BITS;BYTES;isLE;ZERO=wt;ONE=at;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=wt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:i}=Xl(t,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=i,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return it(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return wt<=t&&t<this.ORDER}is0(t){return t===wt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&at)===at}neg(t){return it(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return it(t*t,this.ORDER)}add(t,r){return it(t+r,this.ORDER)}sub(t,r){return it(t-r,this.ORDER)}mul(t,r){return it(t*r,this.ORDER)}pow(t,r){return Wl(this,t,r)}div(t,r){return it(t*va(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 va(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=jl(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?ii(t,this.BYTES):bn(t,this.BYTES)}fromBytes(t,r=!1){$(t);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:c}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let l=new Uint8Array(o);l.set(t,i?0:l.length-t.length),t=l}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let a=i?Re(t):er(t);if(c&&(a=it(a,s)),!r&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(t){return kr(this,t)}cmov(t,r,n){return n?r:t}};function nr(e,t={}){return new ai(e,t)}function Pa(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function fi(e){let t=Pa(e);return t+Math.ceil(t/2)}function li(e,t,r=!1){$(e);let n=e.length,o=Pa(t),i=fi(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Re(e):er(e),c=it(s,t-at)+at;return r?ii(c,o):bn(c,o)}var or=BigInt(0),Pe=BigInt(1);function Kr(e,t){let r=t.negate();return e?r:t}function Ue(e,t){let r=kr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function ka(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function di(e,t){ka(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,i=Or(e),s=BigInt(e);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function Ua(e,t,r){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r,c=Number(e&o),a=e>>s;c>n&&(c-=i,a+=Pe);let l=t*n,u=l+Math.abs(c)-1,f=c===0,y=c<0,E=t%2!==0;return{nextN:a,offset:u,isZero:f,isNeg:y,isNegF:E,offsetF:l}}var hi=new WeakMap,Ka=new WeakMap;function pi(e){return Ka.get(e)||1}function Na(e){if(e!==or)throw new Error("invalid wNAF")}var ir=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>or;)r&Pe&&(n=n.add(o)),o=o.double(),r>>=Pe;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=di(r,this.bits),i=[],s=t,c=s;for(let a=0;a<n;a++){c=s,i.push(c);for(let l=1;l<o;l++)c=c.add(s),i.push(c);s=c.double()}return i}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=di(t,this.bits);for(let c=0;c<s.windows;c++){let{nextN:a,offset:l,isZero:u,isNeg:f,isNegF:y,offsetF:E}=Ua(n,c,s);n=a,u?i=i.add(Kr(y,r[E])):o=o.add(Kr(f,r[l]))}return Na(n),{p:o,f:i}}wNAFUnsafe(t,r,n,o=this.ZERO){let i=di(t,this.bits);for(let s=0;s<i.windows&&n!==or;s++){let{nextN:c,offset:a,isZero:l,isNeg:u}=Ua(n,s,i);if(n=c,!l){let f=r[a];o=o.add(u?f.negate():f)}}return Na(n),o}getPrecomputes(t,r,n){let o=hi.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),hi.set(r,o))),o}cached(t,r,n){let o=pi(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let i=pi(t);return i===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,t,n),r,o)}createCache(t,r){ka(r,this.bits),Ka.set(t,r),hi.delete(t)}hasCache(t){return pi(t)!==1}};function Va(e,t,r,n){let o=t,i=e.ZERO,s=e.ZERO;for(;r>or||n>or;)r&Pe&&(i=i.add(o)),n&Pe&&(s=s.add(o)),o=o.double(),r>>=Pe,n>>=Pe;return{p1:i,p2:s}}function Oa(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ui(t),t}else return nr(e,{isLE:r})}function En(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let l=t[a];if(!(typeof l=="bigint"&&l>or))throw new Error(`CURVE.${a} must be positive bigint`)}let o=Oa(t.p,r.Fp,n),i=Oa(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:i}}function Sn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var Ee=BigInt(0),ct=BigInt(1),mi=BigInt(2),Jl=BigInt(8);function Ql(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 Ma(e,t={}){let r=En("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s}=i;we(t,{},{uvRatio:"function"});let c=mi<<BigInt(o.BYTES*8)-ct,a=C=>n.create(C),l=t.uvRatio||((C,w)=>{try{return{isValid:!0,value:n.sqrt(n.div(C,w))}}catch{return{isValid:!1,value:Ee}}});if(!Ql(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function u(C,w,T=!1){let v=T?ct:Ee;return Nr("coordinate "+C,w,v,c),w}function f(C){if(!(C instanceof b))throw new Error("EdwardsPoint expected")}let y=rr((C,w)=>{let{X:T,Y:v,Z:U}=C,k=C.is0();w==null&&(w=k?Jl:n.inv(U));let M=a(T*w),V=a(v*w),h=n.mul(U,w);if(k)return{x:Ee,y:ct};if(h!==ct)throw new Error("invZ was invalid");return{x:M,y:V}}),E=rr(C=>{let{a:w,d:T}=i;if(C.is0())throw new Error("bad point: ZERO");let{X:v,Y:U,Z:k,T:M}=C,V=a(v*v),h=a(U*U),p=a(k*k),_=a(p*p),D=a(V*w),A=a(p*a(D+h)),m=a(_+a(T*a(V*h)));if(A!==m)throw new Error("bad point: equation left != right (1)");let g=a(v*U),d=a(k*M);if(g!==d)throw new Error("bad point: equation left != right (2)");return!0});class b{static BASE=new b(i.Gx,i.Gy,ct,a(i.Gx*i.Gy));static ZERO=new b(Ee,ct,ct,Ee);static Fp=n;static Fn=o;X;Y;Z;T;constructor(w,T,v,U){this.X=u("x",w),this.Y=u("y",T),this.Z=u("z",v,!0),this.T=u("t",U),Object.freeze(this)}static CURVE(){return i}static fromAffine(w){if(w instanceof b)throw new Error("extended point not allowed");let{x:T,y:v}=w||{};return u("x",T),u("y",v),new b(T,v,ct,a(T*v))}static fromBytes(w,T=!1){let v=n.BYTES,{a:U,d:k}=i;w=wn($(w,v,"point")),ue(T,"zip215");let M=wn(w),V=w[v-1];M[v-1]=V&-129;let h=Re(M),p=T?c:n.ORDER;Nr("point.y",h,Ee,p);let _=a(h*h),D=a(_-ct),A=a(k*_-U),{isValid:m,value:g}=l(D,A);if(!m)throw new Error("bad point: invalid y coordinate");let d=(g&ct)===ct,S=(V&128)!==0;if(!T&&g===Ee&&S)throw new Error("bad point: x=0 and x_0=1");return S!==d&&(g=a(-g)),b.fromAffine({x:g,y:h})}static fromHex(w,T=!1){return b.fromBytes(ae(w),T)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(w=8,T=!0){return I.createCache(this,w),T||this.multiply(mi),this}assertValidity(){E(this)}equals(w){f(w);let{X:T,Y:v,Z:U}=this,{X:k,Y:M,Z:V}=w,h=a(T*V),p=a(k*U),_=a(v*V),D=a(M*U);return h===p&&_===D}is0(){return this.equals(b.ZERO)}negate(){return new b(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:w}=i,{X:T,Y:v,Z:U}=this,k=a(T*T),M=a(v*v),V=a(mi*a(U*U)),h=a(w*k),p=T+v,_=a(a(p*p)-k-M),D=h+M,A=D-V,m=h-M,g=a(_*A),d=a(D*m),S=a(_*m),R=a(A*D);return new b(g,d,R,S)}add(w){f(w);let{a:T,d:v}=i,{X:U,Y:k,Z:M,T:V}=this,{X:h,Y:p,Z:_,T:D}=w,A=a(U*h),m=a(k*p),g=a(V*v*D),d=a(M*_),S=a((U+k)*(h+p)-A-m),R=d-g,P=d+g,N=a(m-T*A),O=a(S*R),K=a(P*N),q=a(S*N),tt=a(R*P);return new b(O,K,tt,q)}subtract(w){return this.add(w.negate())}multiply(w){if(!o.isValidNot0(w))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:T,f:v}=I.cached(this,w,U=>Ue(b,U));return Ue(b,[T,v])[0]}multiplyUnsafe(w,T=b.ZERO){if(!o.isValid(w))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return w===Ee?b.ZERO:this.is0()||w===ct?this:I.unsafe(this,w,v=>Ue(b,v),T)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return I.unsafe(this,i.n).is0()}toAffine(w){return y(this,w)}clearCofactor(){return s===ct?this:this.multiplyUnsafe(s)}toBytes(){let{x:w,y:T}=this.toAffine(),v=n.toBytes(T);return v[v.length-1]|=w&ct?128:0,v}toHex(){return se(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let I=new ir(b,o.BITS);return b.BASE.precompute(8),b}function Fa(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');we(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:i,Fn:s}=e,c=r.randomBytes||Qe,a=r.adjustScalarBytes||(h=>h),l=r.domain||((h,p,_)=>{if(ue(_,"phflag"),p.length||_)throw new Error("Contexts/pre-hash are not supported");return h});function u(h){return s.create(Re(h))}function f(h){let p=v.secretKey;$(h,v.secretKey,"secretKey");let _=$(t(h),2*p,"hashedSecretKey"),D=a(_.slice(0,p)),A=_.slice(p,2*p),m=u(D);return{head:D,prefix:A,scalar:m}}function y(h){let{head:p,prefix:_,scalar:D}=f(h),A=o.multiply(D),m=A.toBytes();return{head:p,prefix:_,scalar:D,point:A,pointBytes:m}}function E(h){return y(h).pointBytes}function b(h=Uint8Array.of(),...p){let _=vt(...p);return u(t(l(_,$(h,void 0,"context"),!!n)))}function I(h,p,_={}){h=$(h,void 0,"message"),n&&(h=n(h));let{prefix:D,scalar:A,pointBytes:m}=y(p),g=b(_.context,D,h),d=o.multiply(g).toBytes(),S=b(_.context,d,m,h),R=s.create(g+S*A);if(!s.isValid(R))throw new Error("sign failed: invalid s");let P=vt(d,s.toBytes(R));return $(P,v.signature,"result")}let C={zip215:!0};function w(h,p,_,D=C){let{context:A,zip215:m}=D,g=v.signature;h=$(h,g,"signature"),p=$(p,void 0,"message"),_=$(_,v.publicKey,"publicKey"),m!==void 0&&ue(m,"zip215"),n&&(p=n(p));let d=g/2,S=h.subarray(0,d),R=Re(h.subarray(d,g)),P,N,O;try{P=e.fromBytes(_,m),N=e.fromBytes(S,m),O=o.multiplyUnsafe(R)}catch{return!1}if(!m&&P.isSmallOrder())return!1;let K=b(A,N.toBytes(),P.toBytes(),p);return N.add(P.multiplyUnsafe(K)).subtract(O).clearCofactor().is0()}let T=i.BYTES,v={secretKey:T,publicKey:T,signature:2*T,seed:T};function U(h=c(v.seed)){return $(h,v.seed,"seed")}function k(h){return Be(h)&&h.length===s.BYTES}function M(h,p){try{return!!e.fromBytes(h,p)}catch{return!1}}let V={getExtendedPublicKey:y,randomSecretKey:U,isValidSecretKey:k,isValidPublicKey:M,toMontgomery(h){let{y:p}=e.fromBytes(h),_=v.publicKey,D=_===32;if(!D&&_!==57)throw new Error("only defined for 25519 and 448");let A=D?i.div(ct+p,ct-p):i.div(p-ct,p+ct);return i.toBytes(A)},toMontgomerySecret(h){let p=v.secretKey;$(h,p);let _=t(h.subarray(0,p));return a(_).subarray(0,p)}};return Object.freeze({keygen:Sn(U,E),getPublicKey:E,sign:I,verify:w,utils:V,Point:e,lengths:v})}var td=BigInt(1),qa=BigInt(2);var ed=BigInt(5),rd=BigInt(8),yi=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),nd={p:yi,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:rd,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function od(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=yi,c=e*e%i*e%i,a=X(c,qa,i)*c%i,l=X(a,td,i)*e%i,u=X(l,ed,i)*l%i,f=X(u,t,i)*u%i,y=X(f,r,i)*f%i,E=X(y,n,i)*y%i,b=X(E,o,i)*E%i,I=X(b,o,i)*E%i,C=X(I,t,i)*u%i;return{pow_p_5_8:X(C,qa,i)*e%i,b2:c}}function id(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var $a=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function sd(e,t){let r=yi,n=it(t*t*t,r),o=it(n*n*t,r),i=od(e*o).pow_p_5_8,s=it(e*n*i,r),c=it(t*s*s,r),a=s,l=it(s*$a,r),u=c===e,f=c===it(-e,r),y=c===it(-e*$a,r);return u&&(s=a),(f||y)&&(s=l),La(s,r)&&(s=it(-s,r)),{isValid:u||f,value:s}}var ad=Ma(nd,{uvRatio:sd});function cd(e){return Fa(ad,ba,Object.assign({adjustScalarBytes:id},e))}var Ha=cd({});var Vr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},vn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var za={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new vn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Ut=za;var An=32;var gi,ud=(async()=>{try{return await Ut.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function fd(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 ld(e,t,r){return Ha.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Ga(e,t,r){return gi==null&&(gi=await ud),gi?fd(e,t,r):ld(e,t,r)}function Cn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var In=class{type="Ed25519";raw;constructor(t){this.raw=xi(t,An)}toMultihash(){return Ct.digest(Xe(this))}toCID(){return j.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:J(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Ga(this.raw,r,t);return Cn(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}};function bi(e){return e=xi(e,An),new In(e)}function xi(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new nt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var hd=Math.pow(2,7),pd=Math.pow(2,14),md=Math.pow(2,21),wi=Math.pow(2,28),Ei=Math.pow(2,35),Si=Math.pow(2,42),vi=Math.pow(2,49),Q=128,yt=127;function Jt(e){if(e<hd)return 1;if(e<pd)return 2;if(e<md)return 3;if(e<wi)return 4;if(e<Ei)return 5;if(e<Si)return 6;if(e<vi)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Mr(e,t,r=0){switch(Jt(e)){case 8:t[r++]=e&255|Q,e/=128;case 7:t[r++]=e&255|Q,e/=128;case 6:t[r++]=e&255|Q,e/=128;case 5:t[r++]=e&255|Q,e/=128;case 4:t[r++]=e&255|Q,e>>>=7;case 3:t[r++]=e&255|Q,e>>>=7;case 2:t[r++]=e&255|Q,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Ai(e,t){let r=e[t],n=0;if(n+=r&yt,r<Q||(r=e[t+1],n+=(r&yt)<<7,r<Q)||(r=e[t+2],n+=(r&yt)<<14,r<Q)||(r=e[t+3],n+=(r&yt)<<21,r<Q)||(r=e[t+4],n+=(r&yt)*wi,r<Q)||(r=e[t+5],n+=(r&yt)*Ei,r<Q)||(r=e[t+6],n+=(r&yt)*Si,r<Q)||(r=e[t+7],n+=(r&yt)*vi,r<Q))return n;throw new RangeError("Could not decode varint")}function yd(e,t){let r=e.get(t),n=0;if(n+=r&yt,r<Q||(r=e.get(t+1),n+=(r&yt)<<7,r<Q)||(r=e.get(t+2),n+=(r&yt)<<14,r<Q)||(r=e.get(t+3),n+=(r&yt)<<21,r<Q)||(r=e.get(t+4),n+=(r&yt)*wi,r<Q)||(r=e.get(t+5),n+=(r&yt)*Ei,r<Q)||(r=e.get(t+6),n+=(r&yt)*Si,r<Q)||(r=e.get(t+7),n+=(r&yt)*vi,r<Q))return n;throw new RangeError("Could not decode varint")}function Ci(e,t=0){return e instanceof Uint8Array?Ai(e,t):yd(e,t)}var Ii=new Float32Array([-0]),Se=new Uint8Array(Ii.buffer);function ja(e,t,r){Ii[0]=e,t[r]=Se[0],t[r+1]=Se[1],t[r+2]=Se[2],t[r+3]=Se[3]}function Ya(e,t){return Se[0]=e[t],Se[1]=e[t+1],Se[2]=e[t+2],Se[3]=e[t+3],Ii[0]}var Ti=new Float64Array([-0]),gt=new Uint8Array(Ti.buffer);function Wa(e,t,r){Ti[0]=e,t[r]=gt[0],t[r+1]=gt[1],t[r+2]=gt[2],t[r+3]=gt[3],t[r+4]=gt[4],t[r+5]=gt[5],t[r+6]=gt[6],t[r+7]=gt[7]}function Xa(e,t){return gt[0]=e[t],gt[1]=e[t+1],gt[2]=e[t+2],gt[3]=e[t+3],gt[4]=e[t+4],gt[5]=e[t+5],gt[6]=e[t+6],gt[7]=e[t+7],Ti[0]}var xd=BigInt(Number.MAX_SAFE_INTEGER),bd=BigInt(Number.MIN_SAFE_INTEGER),Bt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Ne;if(t<xd&&t>bd)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>Ja&&(o=0n,++n>Ja&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ne;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):Ne}},Ne=new Bt(0,0);Ne.toBigInt=function(){return 0n};Ne.zzEncode=Ne.zzDecode=function(){return this};Ne.length=function(){return 1};var Ja=4294967296n;function Qa(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 tc(e,t,r){if(r-t<1)return"";let o,i=[],s=0,c;for(;t<r;)c=e[t++],c<128?i[s++]=c:c>191&&c<224?i[s++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,i[s++]=55296+(c>>10),i[s++]=56320+(c&1023)):i[s++]=(c&15)<<12|(e[t++]&63)<<6|e[t++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Bi(e,t,r){let n=r,o,i;for(let s=0;s<e.length;++s)o=e.charCodeAt(s),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((i=e.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Ft(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Tn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var _i=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Ft(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ft(this,4);return Tn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ft(this,4);return Tn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ft(this,4);let t=Ya(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ft(this,4);let t=Xa(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Ft(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return tc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ft(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ft(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Bt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ft(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Ft(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ft(this,8);let t=Tn(this.buf,this.pos+=4),r=Tn(this.buf,this.pos+=4);return new Bt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Ai(this.buf,this.pos);return this.pos+=Jt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Di(e){return new _i(e instanceof Uint8Array?e:e.subarray())}function sr(e,t,r){let n=Di(e);return t.decode(n,void 0,r)}function Ri(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return It(s);o+s>t&&(n=It(t),o=0);let c=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),c}}var Oe=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Li(){}var Ui=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},wd=Ri();function Ed(e){return globalThis.Buffer!=null?It(e):wd(e)}var qr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Oe(Li,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Oe(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ni((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Bn,10,Bt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Bt.fromBigInt(t);return this._push(Bn,r.length(),r)}uint64Number(t){return this._push(Mr,Jt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=Bt.fromBigInt(t).zzEncode();return this._push(Bn,r.length(),r)}sint64Number(t){let r=Bt.fromNumber(t).zzEncode();return this._push(Bn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Pi,1,t?1:0)}fixed32(t){return this._push(Fr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Bt.fromBigInt(t);return this._push(Fr,4,r.lo)._push(Fr,4,r.hi)}fixed64Number(t){let r=Bt.fromNumber(t);return this._push(Fr,4,r.lo)._push(Fr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ja,4,t)}double(t){return this._push(Wa,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Pi,1,0):this.uint32(r)._push(vd,r,t)}string(t){let r=Qa(t);return r!==0?this.uint32(r)._push(Bi,r,t):this._push(Pi,1,0)}fork(){return this.states=new Ui(this),this.head=this.tail=new Oe(Li,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Oe(Li,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Ed(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Pi(e,t,r){t[r]=e&255}function Sd(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Ni=class extends Oe{next;constructor(t,r){super(Sd,t,r),this.next=void 0}};function Bn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Fr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function vd(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(qr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Ad,t,e),this},qr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Cd,t,e),this});function Ad(e,t,r){t.set(e,r)}function Cd(e,t,r){e.length<40?Bi(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(H(e),r)}function Oi(){return new qr}function ar(e,t){let r=Oi();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var cr;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(cr||(cr={}));function _n(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function $r(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(i,s){let c=t(i);s.int32(c)},n=function(i){let s=i.int32();return t(s)};return _n("enum",cr.VARINT,r,n)}function ur(e,t){return _n("message",cr.LENGTH_DELIMITED,e,t)}var st;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(st||(st={}));var ki;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(ki||(ki={}));(function(e){e.codec=()=>$r(ki)})(st||(st={}));var Qt;(function(e){let t;e.codec=()=>(t==null&&(t=ur((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),st.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let c=r.uint32();switch(c>>>3){case 1:{i.Type=st.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return i})),t),e.encode=r=>ar(r,e.codec()),e.decode=(r,n)=>sr(r,e.codec(),n)})(Qt||(Qt={}));var Ki;(function(e){let t;e.codec=()=>(t==null&&(t=ur((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),st.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let c=r.uint32();switch(c>>>3){case 1:{i.Type=st.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return i})),t),e.encode=r=>ar(r,e.codec()),e.decode=(r,n)=>sr(r,e.codec(),n)})(Ki||(Ki={}));var zr={};bt(zr,{MAX_RSA_KEY_SIZE:()=>Vi,generateRSAKeyPair:()=>sc,jwkToJWKKeyPair:()=>ac,jwkToPkcs1:()=>_d,jwkToPkix:()=>$i,jwkToRSAPrivateKey:()=>Zi,pkcs1MessageToJwk:()=>Fi,pkcs1MessageToRSAPrivateKey:()=>Hi,pkcs1ToJwk:()=>Bd,pkcs1ToRSAPrivateKey:()=>ic,pkixMessageToJwk:()=>qi,pkixMessageToRSAPublicKey:()=>Gi,pkixToJwk:()=>Dd,pkixToRSAPublicKey:()=>zi});var fr=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=zr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return j.createV1(114,this._multihash)}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:J(this.raw,t.raw)}verify(t,r,n){return oc(this.jwk,r,t,n)}},Hr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=zr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:J(this.raw,t.raw)}sign(t,r){return nc(this.jwk,t,r)}};var Vi=8192,Mi=18,Id=1062,Td=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Bd(e){let t=ne(e);return Fi(t)}function Fi(e){return{n:z(e[1],"base64url"),e:z(e[2],"base64url"),d:z(e[3],"base64url"),p:z(e[4],"base64url"),q:z(e[5],"base64url"),dp:z(e[6],"base64url"),dq:z(e[7],"base64url"),qi:z(e[8],"base64url"),kty:"RSA"}}function _d(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new nt("JWK was missing components");return ye([St(Uint8Array.from([0])),St(H(e.n,"base64url")),St(H(e.e,"base64url")),St(H(e.d,"base64url")),St(H(e.p,"base64url")),St(H(e.q,"base64url")),St(H(e.dp,"base64url")),St(H(e.dq,"base64url")),St(H(e.qi,"base64url"))]).subarray()}function Dd(e){let t=ne(e,{offset:0});return qi(t)}function qi(e){let t=ne(e[1],{offset:0});return{kty:"RSA",n:z(t[0],"base64url"),e:z(t[1],"base64url")}}function $i(e){if(e.n==null||e.e==null)throw new nt("JWK was missing components");return ye([Td,pn(ye([St(H(e.n,"base64url")),St(H(e.e,"base64url"))]))]).subarray()}function ic(e){let t=ne(e);return Hi(t)}function Hi(e){let t=Fi(e);return Zi(t)}function zi(e,t){if(e.byteLength>=Id)throw new qe("Key size is too large");let r=ne(e,{offset:0});return Gi(r,e,t)}function Gi(e,t,r){let n=qi(e);if(r==null){let o=tr(Qt.encode({Type:st.RSA,Data:t}));r=Vt(Mi,o)}return new fr(n,r)}function Zi(e){if(uc(e)>Vi)throw new nt("Key size is too large");let t=ac(e),r=tr(Qt.encode({Type:st.RSA,Data:$i(t.publicKey)})),n=Vt(Mi,r);return new Hr(t.privateKey,new fr(t.publicKey,n))}async function sc(e){if(e>Vi)throw new nt("Key size is too large");let t=await cc(e),r=tr(Qt.encode({Type:st.RSA,Data:$i(t.publicKey)})),n=Vt(Mi,r);return new Hr(t.privateKey,new fr(t.publicKey,n))}function ac(e){if(e==null)throw new nt("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function cc(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 Rd(r,t);return{privateKey:n[0],publicKey:n[1]}}async function nc(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 oc(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 Rd(e,t){if(e.privateKey==null||e.publicKey==null)throw new nt("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 uc(e){if(e.kty!=="RSA")throw new nt("invalid key type");if(e.n==null)throw new nt("invalid key modulus");return H(e.n,"base64url").length*8}var Dn=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(mn(t),$(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),ie(o)}update(t){return Je(this),this.iHash.update(t),this}digestInto(t){Je(this),$(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=i,t.blockLen=s,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ji=(e,t,r)=>new Dn(e,t).update(r).digest();ji.create=(e,t)=>new Dn(e,t);var fc=(e,t)=>(e+(e>=0?t:-t)/lc)/t;function Ld(e,t,r){let[[n,o],[i,s]]=t,c=fc(s*e,r),a=fc(-o*e,r),l=e-c*n-a*i,u=-c*o-a*s,f=l<fe,y=u<fe;f&&(l=-l),y&&(u=-u);let E=Or(Math.ceil(si(r)/2))+lr;if(l<fe||l>=E||u<fe||u>=E)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:f,k1:l,k2neg:y,k2:u}}function Wi(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Yi(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return ue(r.lowS,"lowS"),ue(r.prehash,"prehash"),r.format!==void 0&&Wi(r.format),r}var Xi=class extends Error{constructor(t=""){super(t)}},ve={Err:Xi,_tlv:{encode:(e,t)=>{let{Err:r}=ve;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=Ur(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?Ur(o.length/2|128):"";return Ur(e)+i+o+t},decode(e,t){let{Err:r}=ve,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],i=!!(o&128),s=0;if(!i)s=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+a);if(l.length!==a)throw new r("tlv.decode: length bytes not complete");if(l[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of l)s=s<<8|u;if(n+=a,s<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+s);if(c.length!==s)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+s)}}},_int:{encode(e){let{Err:t}=ve;if(e<fe)throw new t("integer: negative integers are not allowed");let r=Ur(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=ve;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return er(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=ve,o=$(e,void 0,"signature"),{v:i,l:s}=n.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,i),{v:l,l:u}=n.decode(2,a);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(l)}},hexFromSig(e){let{_tlv:t,_int:r}=ve,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),i=n+o;return t.encode(48,i)}},fe=BigInt(0),lr=BigInt(1),lc=BigInt(2),Rn=BigInt(3),Pd=BigInt(4);function dc(e,t={}){let r=En("weierstrass",e,t),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s,n:c}=i;we(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:a}=t;if(a&&(!n.is0(i.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let l=pc(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(A,m,g){let{x:d,y:S}=m.toAffine(),R=n.toBytes(d);if(ue(g,"isCompressed"),g){u();let P=!n.isOdd(S);return vt(hc(P),R)}else return vt(Uint8Array.of(4),R,n.toBytes(S))}function y(A){$(A,void 0,"Point");let{publicKey:m,publicKeyUncompressed:g}=l,d=A.length,S=A[0],R=A.subarray(1);if(d===m&&(S===2||S===3)){let P=n.fromBytes(R);if(!n.isValid(P))throw new Error("bad point: is not on curve, wrong x");let N=I(P),O;try{O=n.sqrt(N)}catch(tt){let Y=tt instanceof Error?": "+tt.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}u();let K=n.isOdd(O);return(S&1)===1!==K&&(O=n.neg(O)),{x:P,y:O}}else if(d===g&&S===4){let P=n.BYTES,N=n.fromBytes(R.subarray(0,P)),O=n.fromBytes(R.subarray(P,P*2));if(!C(N,O))throw new Error("bad point: is not on curve");return{x:N,y:O}}else throw new Error(`bad point: got length ${d}, expected compressed=${m} or uncompressed=${g}`)}let E=t.toBytes||f,b=t.fromBytes||y;function I(A){let m=n.sqr(A),g=n.mul(m,A);return n.add(n.add(g,n.mul(A,i.a)),i.b)}function C(A,m){let g=n.sqr(m),d=I(A);return n.eql(g,d)}if(!C(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let w=n.mul(n.pow(i.a,Rn),Pd),T=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(w,T)))throw new Error("bad curve params: a or b");function v(A,m,g=!1){if(!n.isValid(m)||g&&n.is0(m))throw new Error(`bad point coordinate ${A}`);return m}function U(A){if(!(A instanceof p))throw new Error("Weierstrass Point expected")}function k(A){if(!a||!a.basises)throw new Error("no endo");return Ld(A,a.basises,o.ORDER)}let M=rr((A,m)=>{let{X:g,Y:d,Z:S}=A;if(n.eql(S,n.ONE))return{x:g,y:d};let R=A.is0();m==null&&(m=R?n.ONE:n.inv(S));let P=n.mul(g,m),N=n.mul(d,m),O=n.mul(S,m);if(R)return{x:n.ZERO,y:n.ZERO};if(!n.eql(O,n.ONE))throw new Error("invZ was invalid");return{x:P,y:N}}),V=rr(A=>{if(A.is0()){if(t.allowInfinityPoint&&!n.is0(A.Y))return;throw new Error("bad point: ZERO")}let{x:m,y:g}=A.toAffine();if(!n.isValid(m)||!n.isValid(g))throw new Error("bad point: x or y not field elements");if(!C(m,g))throw new Error("bad point: equation left != right");if(!A.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function h(A,m,g,d,S){return g=new p(n.mul(g.X,A),g.Y,g.Z),m=Kr(d,m),g=Kr(S,g),m.add(g)}class p{static BASE=new p(i.Gx,i.Gy,n.ONE);static ZERO=new p(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,g,d){this.X=v("x",m),this.Y=v("y",g,!0),this.Z=v("z",d),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){let{x:g,y:d}=m||{};if(!m||!n.isValid(g)||!n.isValid(d))throw new Error("invalid affine point");if(m instanceof p)throw new Error("projective point not allowed");return n.is0(g)&&n.is0(d)?p.ZERO:new p(g,d,n.ONE)}static fromBytes(m){let g=p.fromAffine(b($(m,void 0,"point")));return g.assertValidity(),g}static fromHex(m){return p.fromBytes(ae(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,g=!0){return D.createCache(this,m),g||this.multiply(Rn),this}assertValidity(){V(this)}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){U(m);let{X:g,Y:d,Z:S}=this,{X:R,Y:P,Z:N}=m,O=n.eql(n.mul(g,N),n.mul(R,S)),K=n.eql(n.mul(d,N),n.mul(P,S));return O&&K}negate(){return new p(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:g}=i,d=n.mul(g,Rn),{X:S,Y:R,Z:P}=this,N=n.ZERO,O=n.ZERO,K=n.ZERO,q=n.mul(S,S),tt=n.mul(R,R),Y=n.mul(P,P),G=n.mul(S,R);return G=n.add(G,G),K=n.mul(S,P),K=n.add(K,K),N=n.mul(m,K),O=n.mul(d,Y),O=n.add(N,O),N=n.sub(tt,O),O=n.add(tt,O),O=n.mul(N,O),N=n.mul(G,N),K=n.mul(d,K),Y=n.mul(m,Y),G=n.sub(q,Y),G=n.mul(m,G),G=n.add(G,K),K=n.add(q,q),q=n.add(K,q),q=n.add(q,Y),q=n.mul(q,G),O=n.add(O,q),Y=n.mul(R,P),Y=n.add(Y,Y),q=n.mul(Y,G),N=n.sub(N,q),K=n.mul(Y,tt),K=n.add(K,K),K=n.add(K,K),new p(N,O,K)}add(m){U(m);let{X:g,Y:d,Z:S}=this,{X:R,Y:P,Z:N}=m,O=n.ZERO,K=n.ZERO,q=n.ZERO,tt=i.a,Y=n.mul(i.b,Rn),G=n.mul(g,R),et=n.mul(d,P),lt=n.mul(S,N),Gt=n.add(g,d),rt=n.add(R,P);Gt=n.mul(Gt,rt),rt=n.add(G,et),Gt=n.sub(Gt,rt),rt=n.add(g,S);let mt=n.add(R,N);return rt=n.mul(rt,mt),mt=n.add(G,lt),rt=n.sub(rt,mt),mt=n.add(d,S),O=n.add(P,N),mt=n.mul(mt,O),O=n.add(et,lt),mt=n.sub(mt,O),q=n.mul(tt,rt),O=n.mul(Y,lt),q=n.add(O,q),O=n.sub(et,q),q=n.add(et,q),K=n.mul(O,q),et=n.add(G,G),et=n.add(et,G),lt=n.mul(tt,lt),rt=n.mul(Y,rt),et=n.add(et,lt),lt=n.sub(G,lt),lt=n.mul(tt,lt),rt=n.add(rt,lt),G=n.mul(et,rt),K=n.add(K,G),G=n.mul(mt,rt),O=n.mul(Gt,O),O=n.sub(O,G),G=n.mul(Gt,et),q=n.mul(mt,q),q=n.add(q,G),new p(O,K,q)}subtract(m){return this.add(m.negate())}is0(){return this.equals(p.ZERO)}multiply(m){let{endo:g}=t;if(!o.isValidNot0(m))throw new Error("invalid scalar: out of range");let d,S,R=P=>D.cached(this,P,N=>Ue(p,N));if(g){let{k1neg:P,k1:N,k2neg:O,k2:K}=k(m),{p:q,f:tt}=R(N),{p:Y,f:G}=R(K);S=tt.add(G),d=h(g.beta,q,Y,P,O)}else{let{p:P,f:N}=R(m);d=P,S=N}return Ue(p,[d,S])[0]}multiplyUnsafe(m){let{endo:g}=t,d=this;if(!o.isValid(m))throw new Error("invalid scalar: out of range");if(m===fe||d.is0())return p.ZERO;if(m===lr)return d;if(D.hasCache(this))return this.multiply(m);if(g){let{k1neg:S,k1:R,k2neg:P,k2:N}=k(m),{p1:O,p2:K}=Va(p,d,R,N);return h(g.beta,O,K,S,P)}else return D.unsafe(d,m)}toAffine(m){return M(this,m)}isTorsionFree(){let{isTorsionFree:m}=t;return s===lr?!0:m?m(p,this):D.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:m}=t;return s===lr?this:m?m(p,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(m=!0){return ue(m,"isCompressed"),this.assertValidity(),E(p,this,m)}toHex(m=!0){return se(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let _=o.BITS,D=new ir(p,t.endo?Math.ceil(_/2):_);return p.BASE.precompute(8),p}function hc(e){return Uint8Array.of(e?2:3)}function pc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Ud(e,t={}){let{Fn:r}=e,n=t.randomBytes||Qe,o=Object.assign(pc(e.Fp,r),{seed:fi(r.ORDER)});function i(E){try{let b=r.fromBytes(E);return r.isValidNot0(b)}catch{return!1}}function s(E,b){let{publicKey:I,publicKeyUncompressed:C}=o;try{let w=E.length;return b===!0&&w!==I||b===!1&&w!==C?!1:!!e.fromBytes(E)}catch{return!1}}function c(E=n(o.seed)){return li($(E,o.seed,"seed"),r.ORDER)}function a(E,b=!0){return e.BASE.multiply(r.fromBytes(E)).toBytes(b)}function l(E){let{secretKey:b,publicKey:I,publicKeyUncompressed:C}=o;if(!Be(E)||"_lengths"in r&&r._lengths||b===I)return;let w=$(E,void 0,"key").length;return w===I||w===C}function u(E,b,I=!0){if(l(E)===!0)throw new Error("first arg must be private key");if(l(b)===!1)throw new Error("second arg must be public key");let C=r.fromBytes(E);return e.fromBytes(b).multiply(C).toBytes(I)}let f={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:c},y=Sn(c,a);return Object.freeze({getPublicKey:a,getSharedSecret:u,keygen:y,Point:e,utils:f,lengths:o})}function mc(e,t,r={}){mn(t),we(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||Qe,o=r.hmac||((g,d)=>ji(t,g,d)),{Fp:i,Fn:s}=e,{ORDER:c,BITS:a}=s,{keygen:l,getPublicKey:u,getSharedSecret:f,utils:y,lengths:E}=Ud(e,r),b={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},I=c*lc<i.ORDER;function C(g){let d=c>>lr;return g>d}function w(g,d){if(!s.isValidNot0(d))throw new Error(`invalid signature ${g}: out of range 1..Point.Fn.ORDER`);return d}function T(){if(I)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function v(g,d){Wi(d);let S=E.signature,R=d==="compact"?S:d==="recovered"?S+1:void 0;return $(g,R)}class U{r;s;recovery;constructor(d,S,R){if(this.r=w("r",d),this.s=w("s",S),R!=null){if(T(),![0,1,2,3].includes(R))throw new Error("invalid recovery id");this.recovery=R}Object.freeze(this)}static fromBytes(d,S=b.format){v(d,S);let R;if(S==="der"){let{r:K,s:q}=ve.toSig($(d));return new U(K,q)}S==="recovered"&&(R=d[0],S="compact",d=d.subarray(1));let P=E.signature/2,N=d.subarray(0,P),O=d.subarray(P,P*2);return new U(s.fromBytes(N),s.fromBytes(O),R)}static fromHex(d,S){return this.fromBytes(ae(d),S)}assertRecovery(){let{recovery:d}=this;if(d==null)throw new Error("invalid recovery id: must be present");return d}addRecoveryBit(d){return new U(this.r,this.s,d)}recoverPublicKey(d){let{r:S,s:R}=this,P=this.assertRecovery(),N=P===2||P===3?S+c:S;if(!i.isValid(N))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let O=i.toBytes(N),K=e.fromBytes(vt(hc((P&1)===0),O)),q=s.inv(N),tt=M($(d,void 0,"msgHash")),Y=s.create(-tt*q),G=s.create(R*q),et=e.BASE.multiplyUnsafe(Y).add(K.multiplyUnsafe(G));if(et.is0())throw new Error("invalid recovery: point at infinify");return et.assertValidity(),et}hasHighS(){return C(this.s)}toBytes(d=b.format){if(Wi(d),d==="der")return ae(ve.hexFromSig(this));let{r:S,s:R}=this,P=s.toBytes(S),N=s.toBytes(R);return d==="recovered"?(T(),vt(Uint8Array.of(this.assertRecovery()),P,N)):vt(P,N)}toHex(d){return se(this.toBytes(d))}}let k=r.bits2int||function(d){if(d.length>8192)throw new Error("input is too large");let S=er(d),R=d.length*8-a;return R>0?S>>BigInt(R):S},M=r.bits2int_modN||function(d){return s.create(k(d))},V=Or(a);function h(g){return Nr("num < 2^"+a,g,fe,V),s.toBytes(g)}function p(g,d){return $(g,void 0,"message"),d?$(t(g),void 0,"prehashed message"):g}function _(g,d,S){let{lowS:R,prehash:P,extraEntropy:N}=Yi(S,b);g=p(g,P);let O=M(g),K=s.fromBytes(d);if(!s.isValidNot0(K))throw new Error("invalid private key");let q=[h(K),h(O)];if(N!=null&&N!==!1){let et=N===!0?n(E.secretKey):N;q.push($(et,void 0,"extraEntropy"))}let tt=vt(...q),Y=O;function G(et){let lt=k(et);if(!s.isValidNot0(lt))return;let Gt=s.inv(lt),rt=e.BASE.multiply(lt).toAffine(),mt=s.create(rt.x);if(mt===fe)return;let cn=s.create(Gt*s.create(Y+mt*K));if(cn===fe)return;let As=(rt.x===mt?0:2)|Number(rt.y&lr),Cs=cn;return R&&C(cn)&&(Cs=s.neg(cn),As^=1),new U(mt,Cs,I?void 0:As)}return{seed:tt,k2sig:G}}function D(g,d,S={}){let{seed:R,k2sig:P}=_(g,d,S);return Sa(t.outputLen,s.BYTES,o)(R,P).toBytes(S.format)}function A(g,d,S,R={}){let{lowS:P,prehash:N,format:O}=Yi(R,b);if(S=$(S,void 0,"publicKey"),d=p(d,N),!Be(g)){let K=g instanceof U?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+K)}v(g,O);try{let K=U.fromBytes(g,O),q=e.fromBytes(S);if(P&&K.hasHighS())return!1;let{r:tt,s:Y}=K,G=M(d),et=s.inv(Y),lt=s.create(G*et),Gt=s.create(tt*et),rt=e.BASE.multiplyUnsafe(lt).add(q.multiplyUnsafe(Gt));return rt.is0()?!1:s.create(rt.x)===tt}catch{return!1}}function m(g,d,S={}){let{prehash:R}=Yi(S,b);return d=p(d,R),U.fromBytes(g,"recovered").recoverPublicKey(d).toBytes()}return Object.freeze({keygen:l,getPublicKey:u,getSharedSecret:f,utils:y,lengths:E,Point:e,sign:D,verify:A,recoverPublicKey:m,Signature:U,hash:t})}var Qi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Nd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var yc=BigInt(2);function Od(e){let t=Qi.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),l=e*e*e%t,u=l*l*e%t,f=X(u,r,t)*u%t,y=X(f,r,t)*u%t,E=X(y,yc,t)*l%t,b=X(E,o,t)*E%t,I=X(b,i,t)*b%t,C=X(I,c,t)*I%t,w=X(C,a,t)*C%t,T=X(w,c,t)*I%t,v=X(T,r,t)*u%t,U=X(v,s,t)*b%t,k=X(U,n,t)*l%t,M=X(k,yc,t);if(!Ji.eql(Ji.sqr(M),e))throw new Error("Cannot find square root");return M}var Ji=nr(Qi.p,{sqrt:Od}),kd=dc(Qi,{Fp:Ji,endo:Nd}),dr=mc(kd,tr);function gc(e,t,r,n){let o=Tr.digest(r instanceof Uint8Array?r:r.subarray());if(Cn(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),dr.verify(t,i,e,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new Vr(String(i))});try{return n?.signal?.throwIfAborted(),dr.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(i){throw new Vr(String(i))}}var Ln=class{type="secp256k1";raw;_key;constructor(t){this._key=bc(t),this.raw=xc(this._key)}toMultihash(){return Ct.digest(Xe(this))}toCID(){return j.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:J(this.raw,t.raw)}verify(t,r,n){return gc(this._key,r,t,n)}};function ts(e){return new Ln(e)}function xc(e){return dr.Point.fromBytes(e).toBytes()}function bc(e){try{return dr.Point.fromBytes(e),e}catch(t){throw new qe(String(t))}}function wc(e,t){let{Type:r,Data:n}=Qt.decode(e),o=n??new Uint8Array;switch(r){case st.RSA:return zi(o,t);case st.Ed25519:return bi(o);case st.secp256k1:return ts(o);case st.ECDSA:return jo(o);default:throw new He}}function Pn(e){let{Type:t,Data:r}=Qt.decode(e.digest),n=r??new Uint8Array;switch(t){case st.Ed25519:return bi(n);case st.secp256k1:return ts(n);case st.ECDSA:return jo(n);default:throw new He}}function Xe(e){return Qt.encode({Type:st[e.type],Data:e.raw})}var Ec=Symbol.for("nodejs.util.inspect.custom"),Kd=114,Gr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[ln]=!0;toString(){return this.string==null&&(this.string=W.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return j.createV1(Kd,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return J(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return J(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ec](){return`PeerId(${this.toString()})`}},Un=class extends Gr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Nn=class extends Gr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},On=class extends Gr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Vd=2336,Zr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Ct.digest(H(this.url))}[Ec](){return`PeerId(${this.url})`}[ln]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return j.createV1(Vd,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};var Md=114,Sc=2336;function vc(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=me(W.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return Fd(j.parse(e));if(t==null)throw new nt('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=me(t.decode(e))}return kn(r)}function kn(e){if($d(e))return new Un({multihash:e});if(qd(e))try{let t=Pn(e);if(t.type==="Ed25519")return new Nn({multihash:e,publicKey:t});if(t.type==="secp256k1")return new On({multihash:e,publicKey:t})}catch{let r=z(e.digest);return new Zr(new URL(r))}throw new $e("Supplied PeerID Multihash is invalid")}function Fd(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Md&&e.code!==Sc)throw new fn("Supplied PeerID CID is invalid");if(e.code===Sc){let t=z(e.multihash.digest);return new Zr(new URL(t))}return kn(e.multihash)}function qd(e){return e.code===Ct.code}function $d(e){return e.code===Tr.code}var ht=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},le=class extends Error{static name="ValidationError";name="ValidationError"},Kn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Vn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Mn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let i=0,s=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",l=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let y=Number.parseInt(f,t);if(!Number.isNaN(y))return y});if(u===void 0)break;if(i*=t,i+=u,i>l||(s+=1,r!==void 0&&s>r))return}if(s!==0)return!n&&a&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return r[o]=s[0],r[o+1]=s[1],r[o+2]=s[2],r[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];r[o]=i>>8,r[o+1]=i&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[c]=t(i.subarray(0,s));return r.set(i.subarray(0,c),16-c),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Hd=45,zd=15,Fn=new Mn;function Ac(e){if(!(e.length>zd))return Fn.new(e).parseWith(()=>Fn.readIPv4Addr())}function Cc(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Hd))return Fn.new(e).parseWith(()=>Fn.readIPv6Addr())}function qn(e){return!!Ac(e)}function Ic(e){return!!Cc(e)}function rs(e){return t=>z(t,e)}function ns(e){return t=>H(t,e)}function hr(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function ke(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function Tc(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=H(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ke(n);return Pt([r,o],r.length+o.length)}function Bc(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=jt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ke(n);return Pt([r,o],r.length+o.length)}function os(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=z(t,"base32"),o=hr(r);return`${n}:${o}`}var is=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new ht("Invalid byte value in IP address");t[n]=o}),t},_c=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let i=qn(r[n]),s;i&&(s=is(r[n]),r[n]=z(s.subarray(0,2),"base16")),s!=null&&++n<8&&r.splice(n,0,z(s.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let i=[n,1];for(n=9-r.length;n>0;n--)i.push("0");r.splice.apply(r,i)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let i=parseInt(r[n],16);if(isNaN(i)||i<0||i>65535)throw new ht("Invalid byte value in IP address");o[t++]=i>>8&255,o[t++]=i&255}return o},Dc=function(e){if(e.byteLength!==4)throw new ht("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Rc=function(e){if(e.byteLength!==16)throw new ht("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],i=e[n+1],s=`${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`;t.push(s)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ht(`Invalid IPv6 address "${r}"`)}};function Lc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ht(`Invalid IPv6 address "${e}"`)}}var es=Object.values(Br).map(e=>e.decoder),Gd=(function(){let e=es[0].or(es[1]);return es.slice(2).forEach(t=>e=e.or(t)),e})();function Pc(e){return Gd.decode(e)}function Uc(e){return t=>e.encoder.encode(t)}function Zd(e){if(parseInt(e).toString()!==e)throw new le("Value must be an integer")}function jd(e){if(e<0)throw new le("Value must be a positive integer, or zero")}function Yd(e){return t=>{if(t>e)throw new le(`Value must be smaller than or equal to ${e}`)}}function Wd(...e){return t=>{for(let r of e)r(t)}}var jr=Wd(Zd,jd,Yd(65535));var ut=-1,ss=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new Vn(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},de=new ss,kh=[{code:4,name:"ip4",size:32,valueToBytes:is,bytesToValue:Dc,validate:e=>{if(!qn(e))throw new le(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ke,bytesToValue:hr,validate:jr},{code:273,name:"udp",size:16,valueToBytes:ke,bytesToValue:hr,validate:jr},{code:33,name:"dccp",size:16,valueToBytes:ke,bytesToValue:hr,validate:jr},{code:41,name:"ip6",size:128,valueToBytes:_c,bytesToValue:Rc,stringToValue:Lc,validate:e=>{if(!Ic(e))throw new le(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:ut},{code:43,name:"ipcidr",size:8,bytesToValue:rs("base10"),valueToBytes:ns("base10")},{code:53,name:"dns",size:ut},{code:54,name:"dns4",size:ut},{code:55,name:"dns6",size:ut},{code:56,name:"dnsaddr",size:ut},{code:132,name:"sctp",size:16,valueToBytes:ke,bytesToValue:hr,validate:jr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ut,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:ut,bytesToValue:rs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?ns("base58btc")(e):j.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:os,valueToBytes:Tc},{code:445,name:"onion3",size:296,bytesToValue:os,valueToBytes:Bc},{code:446,name:"garlic64",size:ut},{code:447,name:"garlic32",size:ut},{code:448,name:"tls"},{code:449,name:"sni",size:ut},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ut,bytesToValue:Uc(No),valueToBytes:Pc},{code:480,name:"http"},{code:481,name:"http-path",size:ut,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ut}];kh.forEach(e=>{de.addProtocol(e)});function Nc(e){let t=[],r=0;for(;r<e.length;){let n=Ci(e,r),o=de.getProtocol(n),i=Jt(n),s=Kh(o,e,r+i),c=0;s>0&&o.size===ut&&(c=Jt(s));let a=i+c+s,l={code:n,name:o.name,bytes:e.subarray(r,r+a)};if(s>0){let u=r+i+c,f=e.subarray(u,u+s);l.value=o.bytesToValue?.(f)??z(f)}t.push(l),r+=a}return t}function Oc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=de.getProtocol(n.code),i=Jt(n.code),s,c=0,a=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??H(n.value),c=s.byteLength,o.size===ut&&(a=Jt(c)));let l=new Uint8Array(i+a+c),u=0;Mr(n.code,l,u),u+=i,s!=null&&(o.size===ut&&(Mr(c,l,u),u+=a),l.set(s,u)),n.bytes=l}r.push(n.bytes),t+=n.bytes.byteLength}return Pt(r,t)}function kc(e){if(e.charAt(0)!=="/")throw new ht('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let i=1;i<e.length;i++){let s=e.charAt(i);s!=="/"&&(r==="protocol"?o+=e.charAt(i):n+=e.charAt(i));let c=i===e.length-1;if(s==="/"||c){let a=de.getProtocol(o);if(r==="protocol"){if(a.size==null||a.size===0){t.push({code:a.code,name:a.name}),n="",o="",r="protocol";continue}else if(c)throw new ht(`Component ${o} was missing value`);r="value"}else if(r==="value"){let l={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new ht(`Component ${o} was missing value`);l.value=a.stringToValue?.(n)??n}t.push(l),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ht("Incomplete multiaddr");return t}function Kc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=de.getProtocol(t.code);if(r==null)throw new ht(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Kh(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Ci(t,r)}var Vh=Symbol.for("nodejs.util.inspect.custom"),as=Symbol.for("@multiformats/multiaddr");function Mh(e){if(e==null&&(e="/"),Vc(e))return e.getComponents();if(e instanceof Uint8Array)return Nc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),kc(e);if(Array.isArray(e))return e;throw new ht("Must be a string, Uint8Array, Component[], or another Multiaddr")}var $n=class e{[as]=!0;#t;#n;#e;constructor(t="/",r={}){this.#t=Mh(t),r.validate!==!1&&Fh(this)}get bytes(){return this.#e==null&&(this.#e=Oc(this.#t)),this.#e}toString(){return this.#n==null&&(this.#n=Kc(this.#t)),this.#n}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Kn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}equals(t){return J(this.bytes,t.bytes)}[Vh](){return`Multiaddr(${this.toString()})`}};function Fh(e){e.getComponents().forEach(t=>{let r=de.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function Vc(e){return!!e?.[as]}function Mc(e){return new $n(e)}function pr(e){let t=new globalThis.AbortController;function r(){let i=e.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();t.abort(i);for(let s of e)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let i of e){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=t.signal;return o.clear=n,o}async function*Yr(e,t={}){let r=e.getReader();try{for(;;){let n=await r.read();if(n.done)return;yield n.value}}finally{t.preventCancel!==!0&&await r.cancel(),r.releaseLock()}}function qh(e,t){if(typeof e=="string")return $h(e);if(typeof e=="number")return Gh(e,t);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(e)}`)}var Hn=qh;function $h(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 Hh(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 zh(e){let t=Math.abs(e);return t>=315576e5?Ke(e,t,315576e5,"year"):t>=26298e5?Ke(e,t,26298e5,"month"):t>=6048e5?Ke(e,t,6048e5,"week"):t>=864e5?Ke(e,t,864e5,"day"):t>=36e5?Ke(e,t,36e5,"hour"):t>=6e4?Ke(e,t,6e4,"minute"):t>=1e3?Ke(e,t,1e3,"second"):`${e} ms`}function Gh(e,t){if(typeof e!="number"||!Number.isFinite(e))throw Error("Value provided to ms.format() must be of type number.");return t?.long?zh(e):Hh(e)}function Ke(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function cs(e){r.debug=r,r.default=r,r.coerce=a,r.disable=i,r.enable=o,r.enabled=s,r.humanize=Hn,r.destroy=l,Object.keys(e).forEach(u=>{r[u]=e[u]}),r.names=[],r.skips=[],r.formatters={};function t(u){let f=0;for(let y=0;y<u.length;y++)f=(f<<5)-f+u.charCodeAt(y),f|=0;return r.colors[Math.abs(f)%r.colors.length]}r.selectColor=t;function r(u,f){let y,E=null,b,I;function C(...w){if(!C.enabled)return;let T=C,v=Number(new Date),U=v-(y||v);T.diff=U,T.prev=y,T.curr=v,y=v,w[0]=r.coerce(w[0]),typeof w[0]!="string"&&w.unshift("%O");let k=0;w[0]=w[0].replace(/%([a-zA-Z%])/g,(V,h)=>{if(V==="%%")return"%";k++;let p=r.formatters[h];if(typeof p=="function"){let _=w[k];V=p.call(T,_),w.splice(k,1),k--}return V}),r.formatArgs.call(T,w),f?.onLog!=null&&f.onLog(...w),(T.log||r.log).apply(T,w)}return C.namespace=u,C.useColors=r.useColors(),C.color=r.selectColor(u),C.extend=n,C.destroy=r.destroy,Object.defineProperty(C,"enabled",{enumerable:!0,configurable:!1,get:()=>E!==null?E:(b!==r.namespaces&&(b=r.namespaces,I=r.enabled(u)),I),set:w=>{E=w}}),typeof r.init=="function"&&r.init(C),C}function n(u,f){let y=r(this.namespace+(typeof f>"u"?":":f)+u);return y.log=this.log,y}function o(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];let f,y=(typeof u=="string"?u:"").split(/[\s,]+/),E=y.length;for(f=0;f<E;f++)y[f]&&(u=y[f].replace(/\*/g,".*?"),u[0]==="-"?r.skips.push(new RegExp("^"+u.substr(1)+"$")):r.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...r.names.map(c),...r.skips.map(c).map(f=>"-"+f)].join(",");return r.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let f,y;for(f=0,y=r.skips.length;f<y;f++)if(r.skips[f].test(u))return!1;for(f=0,y=r.names.length;f<y;f++)if(r.names[f].test(u))return!0;return!1}function c(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function a(u){return u instanceof Error?u.stack??u.message:u}function l(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var zn=Qh(),Zh=["#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 jh(){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 Yh(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+Hn(this.diff),!this.useColors)return;let t="color: "+this.color;e.splice(1,0,t,"color: inherit");let r=0,n=0;e[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(r++,o==="%c"&&(n=r))}),e.splice(n,0,t)}var Wh=console.debug??console.log??(()=>{});function Xh(e){try{e?zn?.setItem("debug",e):zn?.removeItem("debug")}catch{}}function Jh(){let e;try{e=zn?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function Qh(){try{return localStorage}catch{}}function tp(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Fc=cs({formatArgs:Yh,save:Xh,load:Jh,useColors:jh,setupFormatters:tp,colors:Zh,storage:zn,log:Wh});var At=Fc;At.formatters.b=e=>e==null?"undefined":W.baseEncode(e);At.formatters.t=e=>e==null?"undefined":jt.baseEncode(e);At.formatters.m=e=>e==null?"undefined":Uo.baseEncode(e);At.formatters.p=e=>e==null?"undefined":e.toString();At.formatters.c=e=>e==null?"undefined":e.toString();At.formatters.k=e=>e==null?"undefined":e.toString();At.formatters.a=e=>e==null?"undefined":e.toString();function qc(e,t=""){let r=$c(e.message),n=$c(e.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
4
- `).join(`
5
- ${t}`)}`:`${r}
6
- ${t}${n.split(`
7
- `).join(`
8
- ${t}`)}`:n!=null?`${n.split(`
9
- `).join(`
10
- ${t}`)}`:r!=null?`${r}`:`${e.toString()}`}function ep(e){return e instanceof AggregateError||e?.name==="AggregateError"&&Array.isArray(e.errors)}function Hc(e,t=""){if(ep(e)){let r=qc(e,t);return e.errors.length>0?(t=`${t} `,r+=`
11
- ${t}${e.errors.map(n=>`${Hc(n,`${t}`)}`).join(`
12
- ${t}`)}`):r+=`
13
- ${t}[Error list was empty]`,r.trim()}return qc(e,t)}At.formatters.e=e=>e==null?"undefined":Hc(e);function rp(e){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=e,t.destroy=()=>!0,t.extend=()=>t,t}function Ve(e,t){let r=rp(`${e}:trace`);return At.enabled(`${e}:trace`)&&At.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=At(`${e}:trace`,t)),Object.assign(At(e,t),{error:At(`${e}:error`,t),trace:r,newScope:n=>Ve(`${e}:${n}`,t)})}function $c(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var Vp=xo(fs(),1);var qt=class extends Error{static name="SignatureVerificationError";constructor(t="Record signature verification failed"){super(t),this.name="SignatureVerificationError"}},Gn=class extends Error{static name="RecordExpiredError";constructor(t="Record has expired"){super(t),this.name="RecordExpiredError"}},mr=class extends Error{static name="UnsupportedValidityError";constructor(t="The validity type is unsupported"){super(t),this.name="UnsupportedValidityError"}},Zn=class extends Error{static name="RecordTooLargeError";constructor(t="The record is too large"){super(t),this.name="RecordTooLargeError"}},jn=class extends Error{static name="InvalidValueError";constructor(t="Value must be a valid content path starting with /"){super(t),this.name="InvalidValueError"}},Yn=class extends Error{static name="InvalidRecordDataError";constructor(t="Invalid record data"){super(t),this.name="InvalidRecordDataError"}},Wr=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(t="Invalid embedded public key"){super(t),this.name="InvalidEmbeddedPublicKeyError"}};var $t;(function(e){let t;(function(o){o.EOL="EOL"})(t=e.ValidityType||(e.ValidityType={}));let r;(function(o){o[o.EOL=0]="EOL"})(r||(r={})),(function(o){o.codec=()=>$r(r)})(t=e.ValidityType||(e.ValidityType={}));let n;e.codec=()=>(n==null&&(n=ur((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.value!=null&&(i.uint32(10),i.bytes(o.value)),o.signatureV1!=null&&(i.uint32(18),i.bytes(o.signatureV1)),o.validityType!=null&&(i.uint32(24),e.ValidityType.codec().encode(o.validityType,i)),o.validity!=null&&(i.uint32(34),i.bytes(o.validity)),o.sequence!=null&&(i.uint32(40),i.uint64(o.sequence)),o.ttl!=null&&(i.uint32(48),i.uint64(o.ttl)),o.pubKey!=null&&(i.uint32(58),i.bytes(o.pubKey)),o.signatureV2!=null&&(i.uint32(66),i.bytes(o.signatureV2)),o.data!=null&&(i.uint32(74),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let c={},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let l=o.uint32();switch(l>>>3){case 1:{c.value=o.bytes();break}case 2:{c.signatureV1=o.bytes();break}case 3:{c.validityType=e.ValidityType.codec().decode(o);break}case 4:{c.validity=o.bytes();break}case 5:{c.sequence=o.uint64();break}case 6:{c.ttl=o.uint64();break}case 7:{c.pubKey=o.bytes();break}case 8:{c.signatureV2=o.bytes();break}case 9:{c.data=o.bytes();break}default:{o.skipType(l&7);break}}}return c})),n),e.encode=o=>ar(o,e.codec()),e.decode=(o,i)=>sr(o,e.codec(),i)})($t||($t={}));var np=["string","number","bigint","symbol"],op=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function zc(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(np.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(ip(e))return"Buffer";let r=sp(e);return r||"Object"}function ip(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function sp(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(op.includes(t))return t}var x=class{constructor(t,r,n){this.major=t,this.majorEncoded=t<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}};x.uint=new x(0,"uint",!0);x.negint=new x(1,"negint",!0);x.bytes=new x(2,"bytes",!0);x.string=new x(3,"string",!0);x.array=new x(4,"array",!1);x.map=new x(5,"map",!1);x.tag=new x(6,"tag",!1);x.float=new x(7,"float",!0);x.false=new x(7,"false",!0);x.true=new x(7,"true",!0);x.null=new x(7,"null",!0);x.undefined=new x(7,"undefined",!0);x.break=new x(7,"break",!0);var L=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var yr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",ap=new TextDecoder,cp=new TextEncoder;function Wn(e){return yr&&globalThis.Buffer.isBuffer(e)}function ls(e){return e instanceof Uint8Array?Wn(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Yc=yr?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):Zc(e,t,r):(e,t,r)=>r-t>64?ap.decode(e.subarray(t,r)):Zc(e,t,r),Wc=yr?e=>e.length>64?globalThis.Buffer.from(e):Gc(e):e=>e.length>64?cp.encode(e):Gc(e),te=e=>Uint8Array.from(e),gr=yr?(e,t,r)=>Wn(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Xc=yr?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),ls(globalThis.Buffer.concat(e,t))):(e,t)=>{let r=new Uint8Array(t),n=0;for(let o of e)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},Jc=yr?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function Xn(e,t){if(Wn(e)&&Wn(t))return e.compare(t);for(let r=0;r<e.length;r++)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return 0}function Gc(e){let t=[],r=0;for(let n=0;n<e.length;n++){let o=e.charCodeAt(n);o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&n+1<e.length&&(e.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(e.charCodeAt(++n)&1023),t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128)}return t}function Zc(e,t,r){let n=[];for(;t<r;){let o=e[t],i=null,s=o>239?4:o>223?3:o>191?2:1;if(t+s<=r){let c,a,l,u;switch(s){case 1:o<128&&(i=o);break;case 2:c=e[t+1],(c&192)===128&&(u=(o&31)<<6|c&63,u>127&&(i=u));break;case 3:c=e[t+1],a=e[t+2],(c&192)===128&&(a&192)===128&&(u=(o&15)<<12|(c&63)<<6|a&63,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:c=e[t+1],a=e[t+2],l=e[t+3],(c&192)===128&&(a&192)===128&&(l&192)===128&&(u=(o&15)<<18|(c&63)<<12|(a&63)<<6|l&63,u>65535&&u<1114112&&(i=u))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=s}return up(n)}var jc=4096;function up(e){let t=e.length;if(t<=jc)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=jc));return r}var fp=256,Xr=class{constructor(t=fp){this.chunkSize=t,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(t){let r=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(t,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(r=Jc(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(t,0)):(this.chunks.push(t),this.maxCursor+=t.length)}this.cursor+=t.length}toBytes(t=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];t&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=gr(n,0,this.cursor)}else r=Xc(this.chunks,this.cursor);return t&&this.reset(),r}};var F="CBOR decode error:",ds="CBOR encode error:",Jr=[];Jr[23]=1;Jr[24]=2;Jr[25]=3;Jr[26]=5;Jr[27]=9;function he(e,t,r){if(e.length-t<r)throw new Error(`${F} not enough data for type`)}var ft=[24,256,65536,4294967296,BigInt("18446744073709551616")];function _t(e,t,r){he(e,t,1);let n=e[t];if(r.strict===!0&&n<ft[0])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function Dt(e,t,r){he(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<ft[1])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function Rt(e,t,r){he(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<ft[2])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function Lt(e,t,r){he(e,t,8);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<ft[3])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${F} integers outside of the safe integer range are not supported`)}function Qc(e,t,r,n){return new L(x.uint,_t(e,t+1,n),2)}function tu(e,t,r,n){return new L(x.uint,Dt(e,t+1,n),3)}function eu(e,t,r,n){return new L(x.uint,Rt(e,t+1,n),5)}function ru(e,t,r,n){return new L(x.uint,Lt(e,t+1,n),9)}function Nt(e,t){return pt(e,0,t.value)}function pt(e,t,r){if(r<ft[0]){let n=Number(r);e.push([t|n])}else if(r<ft[1]){let n=Number(r);e.push([t|24,n])}else if(r<ft[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<ft[3]){let n=Number(r);e.push([t|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<ft[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,e.push(o)}else throw new Error(`${F} encountered BigInt larger than allowable range`)}}Nt.encodedSize=function(t){return pt.encodedSize(t.value)};pt.encodedSize=function(t){return t<ft[0]?1:t<ft[1]?2:t<ft[2]?3:t<ft[3]?5:9};Nt.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function nu(e,t,r,n){return new L(x.negint,-1-_t(e,t+1,n),2)}function ou(e,t,r,n){return new L(x.negint,-1-Dt(e,t+1,n),3)}function iu(e,t,r,n){return new L(x.negint,-1-Rt(e,t+1,n),5)}var hs=BigInt(-1),su=BigInt(1);function au(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 L(x.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${F} integers outside of the safe integer range are not supported`);return new L(x.negint,hs-BigInt(o),9)}function Jn(e,t){let r=t.value,n=typeof r=="bigint"?r*hs-su:r*-1-1;pt(e,t.type.majorEncoded,n)}Jn.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*hs-su:r*-1-1;return n<ft[0]?1:n<ft[1]?2:n<ft[2]?3:n<ft[3]?5:9};Jn.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function Qr(e,t,r,n){he(e,t,r+n);let o=gr(e,t+r,t+r+n);return new L(x.bytes,o,r+n)}function cu(e,t,r,n){return Qr(e,t,1,r)}function uu(e,t,r,n){return Qr(e,t,2,_t(e,t+1,n))}function fu(e,t,r,n){return Qr(e,t,3,Dt(e,t+1,n))}function lu(e,t,r,n){return Qr(e,t,5,Rt(e,t+1,n))}function du(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer bytes lengths not supported`);return Qr(e,t,9,o)}function Qn(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===x.string?Wc(e.value):e.value),e.encodedBytes}function xr(e,t){let r=Qn(t);pt(e,t.type.majorEncoded,r.length),e.push(r)}xr.encodedSize=function(t){let r=Qn(t);return pt.encodedSize(r.length)+r.length};xr.compareTokens=function(t,r){return dp(Qn(t),Qn(r))};function dp(e,t){return e.length<t.length?-1:e.length>t.length?1:Xn(e,t)}function tn(e,t,r,n,o){let i=r+n;he(e,t,i);let s=new L(x.string,Yc(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=gr(e,t+r,t+i)),s}function hu(e,t,r,n){return tn(e,t,1,r,n)}function pu(e,t,r,n){return tn(e,t,2,_t(e,t+1,n),n)}function mu(e,t,r,n){return tn(e,t,3,Dt(e,t+1,n),n)}function yu(e,t,r,n){return tn(e,t,5,Rt(e,t+1,n),n)}function gu(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer string lengths not supported`);return tn(e,t,9,o,n)}var xu=xr;function br(e,t,r,n){return new L(x.array,n,r)}function bu(e,t,r,n){return br(e,t,1,r)}function wu(e,t,r,n){return br(e,t,2,_t(e,t+1,n))}function Eu(e,t,r,n){return br(e,t,3,Dt(e,t+1,n))}function Su(e,t,r,n){return br(e,t,5,Rt(e,t+1,n))}function vu(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer array lengths not supported`);return br(e,t,9,o)}function Au(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return br(e,t,1,1/0)}function to(e,t){pt(e,x.array.majorEncoded,t.value)}to.compareTokens=Nt.compareTokens;to.encodedSize=function(t){return pt.encodedSize(t.value)};function wr(e,t,r,n){return new L(x.map,n,r)}function Cu(e,t,r,n){return wr(e,t,1,r)}function Iu(e,t,r,n){return wr(e,t,2,_t(e,t+1,n))}function Tu(e,t,r,n){return wr(e,t,3,Dt(e,t+1,n))}function Bu(e,t,r,n){return wr(e,t,5,Rt(e,t+1,n))}function _u(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer map lengths not supported`);return wr(e,t,9,o)}function Du(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return wr(e,t,1,1/0)}function eo(e,t){pt(e,x.map.majorEncoded,t.value)}eo.compareTokens=Nt.compareTokens;eo.encodedSize=function(t){return pt.encodedSize(t.value)};function Ru(e,t,r,n){return new L(x.tag,r,1)}function Lu(e,t,r,n){return new L(x.tag,_t(e,t+1,n),2)}function Pu(e,t,r,n){return new L(x.tag,Dt(e,t+1,n),3)}function Uu(e,t,r,n){return new L(x.tag,Rt(e,t+1,n),5)}function Nu(e,t,r,n){return new L(x.tag,Lt(e,t+1,n),9)}function ro(e,t){pt(e,x.tag.majorEncoded,t.value)}ro.compareTokens=Nt.compareTokens;ro.encodedSize=function(t){return pt.encodedSize(t.value)};var xp=20,bp=21,wp=22,Ep=23;function Ou(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${F} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new L(x.null,null,1):new L(x.undefined,void 0,1)}function ku(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return new L(x.break,void 0,1)}function ps(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${F} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${F} Infinity values are not supported`)}return new L(x.float,e,t)}function Ku(e,t,r,n){return ps(ms(e,t+1),3,n)}function Vu(e,t,r,n){return ps(ys(e,t+1),5,n)}function Mu(e,t,r,n){return ps(Hu(e,t+1),9,n)}function no(e,t,r){let n=t.value;if(n===!1)e.push([x.float.majorEncoded|xp]);else if(n===!0)e.push([x.float.majorEncoded|bp]);else if(n===null)e.push([x.float.majorEncoded|wp]);else if(n===void 0)e.push([x.float.majorEncoded|Ep]);else{let o,i=!1;(!r||r.float64!==!0)&&(qu(n),o=ms(Ht,1),n===o||Number.isNaN(n)?(Ht[0]=249,e.push(Ht.slice(0,3)),i=!0):($u(n),o=ys(Ht,1),n===o&&(Ht[0]=250,e.push(Ht.slice(0,5)),i=!0))),i||(Sp(n),o=Hu(Ht,1),Ht[0]=251,e.push(Ht.slice(0,9)))}}no.encodedSize=function(t,r){let n=t.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){qu(n);let o=ms(Ht,1);if(n===o||Number.isNaN(n))return 3;if($u(n),o=ys(Ht,1),n===o)return 5}return 9};var Fu=new ArrayBuffer(9),Ot=new DataView(Fu,1),Ht=new Uint8Array(Fu,0);function qu(e){if(e===1/0)Ot.setUint16(0,31744,!1);else if(e===-1/0)Ot.setUint16(0,64512,!1);else if(Number.isNaN(e))Ot.setUint16(0,32256,!1);else{Ot.setFloat32(0,e);let t=Ot.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)Ot.setUint16(0,31744,!1);else if(r===0)Ot.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Ot.setUint16(0,0):o<-14?Ot.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):Ot.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function ms(e,t){if(e.length-t<2)throw new Error(`${F} not enough data for float16`);let r=(e[t]<<8)+e[t+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function $u(e){Ot.setFloat32(0,e,!1)}function ys(e,t){if(e.length-t<4)throw new Error(`${F} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function Sp(e){Ot.setFloat64(0,e,!1)}function Hu(e,t){if(e.length-t<8)throw new Error(`${F} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}no.compareTokens=Nt.compareTokens;function Z(e,t,r){throw new Error(`${F} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function oo(e){return()=>{throw new Error(`${F} ${e}`)}}var B=[];for(let e=0;e<=23;e++)B[e]=Z;B[24]=Qc;B[25]=tu;B[26]=eu;B[27]=ru;B[28]=Z;B[29]=Z;B[30]=Z;B[31]=Z;for(let e=32;e<=55;e++)B[e]=Z;B[56]=nu;B[57]=ou;B[58]=iu;B[59]=au;B[60]=Z;B[61]=Z;B[62]=Z;B[63]=Z;for(let e=64;e<=87;e++)B[e]=cu;B[88]=uu;B[89]=fu;B[90]=lu;B[91]=du;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]=hu;B[120]=pu;B[121]=mu;B[122]=yu;B[123]=gu;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]=bu;B[152]=wu;B[153]=Eu;B[154]=Su;B[155]=vu;B[156]=Z;B[157]=Z;B[158]=Z;B[159]=Au;for(let e=160;e<=183;e++)B[e]=Cu;B[184]=Iu;B[185]=Tu;B[186]=Bu;B[187]=_u;B[188]=Z;B[189]=Z;B[190]=Z;B[191]=Du;for(let e=192;e<=215;e++)B[e]=Ru;B[216]=Lu;B[217]=Pu;B[218]=Uu;B[219]=Nu;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]=Ou;B[248]=oo("simple values are not supported");B[249]=Ku;B[250]=Vu;B[251]=Mu;B[252]=Z;B[253]=Z;B[254]=Z;B[255]=ku;var zt=[];for(let e=0;e<24;e++)zt[e]=new L(x.uint,e,1);for(let e=-1;e>=-24;e--)zt[31-e]=new L(x.negint,e,1);zt[64]=new L(x.bytes,new Uint8Array(0),1);zt[96]=new L(x.string,"",1);zt[128]=new L(x.array,0,1);zt[160]=new L(x.map,0,1);zt[244]=new L(x.false,!1,1);zt[245]=new L(x.true,!0,1);zt[246]=new L(x.null,null,1);function zu(e){switch(e.type){case x.false:return te([244]);case x.true:return te([245]);case x.null:return te([246]);case x.bytes:return e.value.length?void 0:te([64]);case x.string:return e.value===""?te([96]):void 0;case x.array:return e.value===0?te([128]):void 0;case x.map:return e.value===0?te([160]):void 0;case x.uint:return e.value<24?te([Number(e.value)]):void 0;case x.negint:if(e.value>=-24)return te([31-Number(e.value)])}}var Zu=Object.freeze({float64:!0,mapSorter:Tp,quickEncodeToken:zu});function Ap(){let e=[];return e[x.uint.major]=Nt,e[x.negint.major]=Jn,e[x.bytes.major]=xr,e[x.string.major]=xu,e[x.array.major]=to,e[x.map.major]=eo,e[x.tag.major]=ro,e[x.float.major]=no,e}var Cp=Ap(),gs=new Xr,so=class e{constructor(t,r){this.obj=t,this.parent=r}includes(t){let r=this;do if(r.obj===t)return!0;while(r=r.parent);return!1}static createCheck(t,r){if(t&&t.includes(r))throw new Error(`${ds} object contains circular references`);return new e(r,t)}},Ae={null:new L(x.null,null),undefined:new L(x.undefined,void 0),true:new L(x.true,!0),false:new L(x.false,!1),emptyArray:new L(x.array,0),emptyMap:new L(x.map,0)},Ce={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new L(x.float,e):e>=0?new L(x.uint,e):new L(x.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new L(x.uint,e):new L(x.negint,e)},Uint8Array(e,t,r,n){return new L(x.bytes,e)},string(e,t,r,n){return new L(x.string,e)},boolean(e,t,r,n){return e?Ae.true:Ae.false},null(e,t,r,n){return Ae.null},undefined(e,t,r,n){return Ae.undefined},ArrayBuffer(e,t,r,n){return new L(x.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new L(x.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[Ae.emptyArray,new L(x.break)]:Ae.emptyArray;n=so.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=io(s,r,n);return r.addBreakTokens?[new L(x.array,e.length),o,new L(x.break)]:[new L(x.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),s=o?e.size:i.length;if(!s)return r.addBreakTokens===!0?[Ae.emptyMap,new L(x.break)]:Ae.emptyMap;n=so.createCheck(n,e);let c=[],a=0;for(let l of i)c[a++]=[io(l,r,n),io(o?e.get(l):e[l],r,n)];return Ip(c,r),r.addBreakTokens?[new L(x.map,s),c,new L(x.break)]:[new L(x.map,s),c]}};Ce.Map=Ce.Object;Ce.Buffer=Ce.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Ce[`${e}Array`]=Ce.DataView;function io(e,t={},r){let n=zc(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||Ce[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=Ce[n];if(!i)throw new Error(`${ds} unsupported type: ${n}`);return i(e,n,t,r)}function Ip(e,t){t.mapSorter&&e.sort(t.mapSorter)}function Tp(e,t){if(e[0]instanceof L&&t[0]instanceof L){let r=e[0],n=t[0];return r._keyBytes||(r._keyBytes=Gu(r.value)),n._keyBytes||(n._keyBytes=Gu(n.value)),Xn(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Gu(e){return Bp(e,Cp,Zu)}function ju(e,t,r,n){if(Array.isArray(t))for(let o of t)ju(e,o,r,n);else r[t.type.major](e,t,n)}function Bp(e,t,r){let n=io(e,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=t[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,r),c=new Xr(s);if(i(c,n,r),c.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return ls(c.chunks[0])}}return gs.reset(),ju(gs,n,t,r),gs.toBytes(!0)}var _p={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},ao=class{constructor(t,r={}){this._pos=0,this.data=t,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let t=this.data[this._pos],r=zt[t];if(r===void 0){let n=B[t];if(!n)throw new Error(`${F} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},en=Symbol.for("DONE"),co=Symbol.for("BREAK");function Dp(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=Er(t,r);if(i===co){if(e.value===1/0)break;throw new Error(`${F} got unexpected break to lengthed array`)}if(i===en)throw new Error(`${F} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function Rp(e,t,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<e.value;s++){let c=Er(t,r);if(c===co){if(e.value===1/0)break;throw new Error(`${F} got unexpected break to lengthed map`)}if(c===en)throw new Error(`${F} found map but not enough entries (got ${s} [no key], expected ${e.value})`);if(n!==!0&&typeof c!="string")throw new Error(`${F} non-string keys not supported (got ${typeof c})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(c)||!n&&c in o))throw new Error(`${F} found repeat map key "${c}"`);let a=Er(t,r);if(a===en)throw new Error(`${F} found map but not enough entries (got ${s} [no value], expected ${e.value})`);n?i.set(c,a):o[c]=a}return n?i:o}function Er(e,t){if(e.done())return en;let r=e.next();if(r.type===x.break)return co;if(r.type.terminal)return r.value;if(r.type===x.array)return Dp(r,e,t);if(r.type===x.map)return Rp(r,e,t);if(r.type===x.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=Er(e,t);return t.tags[r.value](n)}throw new Error(`${F} tag not supported (${r.value})`)}throw new Error("unsupported")}function Yu(e,t){if(!(e instanceof Uint8Array))throw new Error(`${F} data to decode must be a Uint8Array`);t=Object.assign({},_p,t);let r=t.tokenizer||new ao(e,t),n=Er(r,t);if(n===en)throw new Error(`${F} did not find any content to decode`);if(n===co)throw new Error(`${F} got unexpected break`);return[n,e.subarray(r.pos())]}function xs(e,t){let[r,n]=Yu(e,t);if(n.length>0)throw new Error(`${F} too many terminals, data makes no sense`);return r}var Up=Ve("ipns:utils"),Wu=H("/ipns/");var Np=0,Op=18;function Xu(e){let t;if(e.pubKey!=null)try{t=wc(e.pubKey)}catch(r){throw Up.error(r),r}if(t!=null)return t}function Ju(e){let t=H("ipns-signature:");return Pt([t,e])}function rn(e){return"signatureV1"in e?$t.encode({value:H(e.value),signatureV1:e.signatureV1,validityType:e.validityType,validity:H(e.validity),sequence:e.sequence,ttl:e.ttl,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data}):$t.encode({pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data})}function Ie(e){let t=$t.decode(e);if(t.sequence!=null&&(t.sequence=BigInt(t.sequence)),t.ttl!=null&&(t.ttl=BigInt(t.ttl)),t.signatureV2==null||t.data==null)throw new qt("Missing data or signatureV2");let r=Qu(t.data),n=kp(r.Value),o=z(r.Validity);if(t.value!=null&&t.signatureV1!=null)return Kp(t),{value:n,validityType:$t.ValidityType.EOL,validity:o,sequence:r.Sequence,ttl:r.TTL,pubKey:t.pubKey,signatureV1:t.signatureV1,signatureV2:t.signatureV2,data:t.data};if(t.signatureV2!=null)return{value:n,validityType:$t.ValidityType.EOL,validity:o,sequence:r.Sequence,ttl:r.TTL,pubKey:t.pubKey,signatureV2:t.signatureV2,data:t.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}function nn(e){return Pt([Wu,e.bytes])}function Sr(e){let t=me(e.slice(Wu.length));if(!uo(t,Np)&&!uo(t,Op))throw new $e("Multihash in IPNS key was not identity or sha2-256");return t}function Qu(e){let t=xs(e);if(t.ValidityType===0)t.ValidityType=$t.ValidityType.EOL;else throw new mr("The validity type is unsupported");return Number.isInteger(t.Sequence)&&(t.Sequence=BigInt(t.Sequence)),Number.isInteger(t.TTL)&&(t.TTL=BigInt(t.TTL)),t}function kp(e){let t=z(e).trim();if(t.startsWith("/"))return t;try{return`/ipfs/${j.decode(e).toV1().toString()}`}catch{}try{return`/ipfs/${j.parse(t).toV1().toString()}`}catch{}throw new jn("Value must be a valid content path starting with /")}function Kp(e){if(e.data==null)throw new Yn("Record data is missing");let t=Qu(e.data);if(!J(t.Value,e.value??new Uint8Array(0)))throw new qt('Field "value" did not match between protobuf and CBOR');if(!J(t.Validity,e.validity??new Uint8Array(0)))throw new qt('Field "validity" did not match between protobuf and CBOR');if(t.ValidityType!==e.validityType)throw new qt('Field "validityType" did not match between protobuf and CBOR');if(t.Sequence!==e.sequence)throw new qt('Field "sequence" did not match between protobuf and CBOR');if(t.TTL!==e.ttl)throw new qt('Field "ttl" did not match between protobuf and CBOR')}function uo(e,t){return e.code===t}var r1=Ve("ipns"),n1=300*1e9,Mp="/ipns/",o1=Mp.length;var tf=xo(fs(),1);var fo=Ve("ipns:validator"),Fp=1024*10;async function qp(e,t){let r=Ie(t),n;try{let o=Ju(r.data);n=await e.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw fo.error("record signature verification failed"),new qt("Record signature verification failed");if(r.validityType===$t.ValidityType.EOL){if(tf.default.fromString(r.validity).toDate().getTime()<Date.now())throw fo.error("record has expired"),new Gn("record has expired")}else if(r.validityType!=null)throw fo.error("the validity type is unsupported"),new mr("The validity type is unsupported");fo("ipns record for %s is valid",r.value)}async function ef(e,t){if(t.byteLength>Fp)throw new Zn("The record is too large");let r=Sr(e),n;uo(r,0)&&(n=Pn(r));let o=Ie(t),i=Xu(o)??n;if(i==null)throw new Wr("Could not extract public key from IPNS record or routing key");let s=nn(i.toMultihash());if(!J(s,e))throw new Wr("Embedded public key did not match routing key");await qp(i,t)}var lo=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MESSAGE_LENGTH"};async function*vr(e,t={}){let r=/\r?\n/,n=new TextDecoder("utf8"),o="";for await(let i of e){if(typeof i=="string"&&(i=new TextEncoder().encode(i)),Ye(i)&&(i=i.subarray()),o+=n.decode(i,{stream:!0}),o.length>(t?.maxMessageLength??o.length))throw new lo("Incoming message too long");let s=o.split(r);o=s.pop()??"";for(let c=0;c<s.length;c++)yield JSON.parse(s[c])}o+=n.decode(),o!==""&&(yield JSON.parse(o))}function kt(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var ws=xo(nf(),1);var Es=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},of=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function Ss(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=t,c,a,u=new Promise((f,y)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){y(of(s));return}if(s&&(a=()=>{y(of(s))},s.addEventListener("abort",a,{once:!0})),e.then(f,y),r===Number.POSITIVE_INFINITY)return;let E=new Es;c=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(b){y(b)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?f():o instanceof Error?y(o):(E.message=o??`Promise timed out after ${r} milliseconds`,y(E))},r)}).finally(()=>{u.clear(),a&&s&&s.removeEventListener("abort",a)});return u.clear=()=>{i.clearTimeout.call(void 0,c),c=void 0},u}function vs(e,t,r){let n=0,o=e.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(e[s],t)<=0?(n=++s,o-=i+1):o=i}return n}var sn=class{#t=[];enqueue(t,r){let{priority:n=0,id:o}=r??{},i={priority:n,id:o,run:t};if(this.size===0||this.#t[this.size-1].priority>=n){this.#t.push(i);return}let s=vs(this.#t,i,(c,a)=>a.priority-c.priority);this.#t.splice(s,0,i)}setPriority(t,r){let n=this.#t.findIndex(i=>i.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:r,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return this.#t.length}};var an=class extends ws.default{#t;#n;#e=0;#h;#m=!1;#x=!1;#c;#I=0;#b=0;#u;#f;#a;#s=[];#i=0;#r;#T;#o=0;#y;#l;#L=1n;#g=new Map;timeout;constructor(t){if(super(),t={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:sn,strict:!1,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);if(t.strict&&t.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(t.strict&&t.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#t=t.carryoverIntervalCount??t.carryoverConcurrencyCount??!1,this.#n=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#h=t.intervalCap,this.#c=t.interval,this.#a=t.strict,this.#r=new t.queueClass,this.#T=t.queueClass,this.concurrency=t.concurrency,t.timeout!==void 0&&!(Number.isFinite(t.timeout)&&t.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${t.timeout}\` (${typeof t.timeout})`);this.timeout=t.timeout,this.#l=t.autoStart===!1,this.#M()}#w(t){for(;this.#i<this.#s.length;){let n=this.#s[this.#i];if(n!==void 0&&t-n>=this.#c)this.#i++;else break}(this.#i>100&&this.#i>this.#s.length/2||this.#i===this.#s.length)&&(this.#s=this.#s.slice(this.#i),this.#i=0)}#P(t){this.#a?this.#s.push(t):this.#e++}#U(){this.#a?this.#s.length>this.#i&&this.#s.pop():this.#e>0&&this.#e--}#E(){return this.#s.length-this.#i}get#N(){return this.#n?!0:this.#a?this.#E()<this.#h:this.#e<this.#h}get#O(){return this.#o<this.#y}#k(){this.#o--,this.#o===0&&this.emit("pendingZero"),this.#A(),this.emit("next")}#K(){this.#f=void 0,this.#D(),this.#_()}#V(t){if(this.#a){if(this.#w(t),this.#E()>=this.#h){let n=this.#s[this.#i],o=this.#c-(t-n);return this.#S(o),!0}return!1}if(this.#u===void 0){let r=this.#I-t;if(r<0){if(this.#b>0){let n=t-this.#b;if(n<this.#c)return this.#S(this.#c-n),!0}this.#e=this.#t?this.#o:0}else return this.#S(r),!0}return!1}#S(t){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#K()},t))}#v(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}#B(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#A(){if(this.#r.size===0){if(this.#v(),this.emit("empty"),this.#o===0){if(this.#B(),this.#a&&this.#i>0){let r=Date.now();this.#w(r)}this.emit("idle")}return!1}let t=!1;if(!this.#l){let r=Date.now(),n=!this.#V(r);if(this.#N&&this.#O){let o=this.#r.dequeue();this.#n||(this.#P(r),this.#p()),this.emit("active"),o(),n&&this.#_(),t=!0}}return t}#_(){this.#n||this.#u!==void 0||this.#a||(this.#u=setInterval(()=>{this.#D()},this.#c),this.#I=Date.now()+this.#c)}#D(){this.#a||(this.#e===0&&this.#o===0&&this.#u&&this.#v(),this.#e=this.#t?this.#o:0),this.#C(),this.#p()}#C(){for(;this.#A(););}get concurrency(){return this.#y}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#y=t,this.#C()}setPriority(t,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#r.setPriority(t,r)}async add(t,r={}){return r={timeout:this.timeout,...r,id:r.id??(this.#L++).toString()},new Promise((n,o)=>{let i=Symbol(`task-${r.id}`);this.#r.enqueue(async()=>{this.#o++,this.#g.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let s;try{try{r.signal?.throwIfAborted()}catch(l){throw this.#F(),this.#g.delete(i),l}this.#b=Date.now();let c=t({signal:r.signal});if(r.timeout&&(c=Ss(Promise.resolve(c),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#o} running, ${this.#r.size} waiting)`})),r.signal){let{signal:l}=r;c=Promise.race([c,new Promise((u,f)=>{s=()=>{f(l.reason)},l.addEventListener("abort",s,{once:!0})})])}let a=await c;n(a),this.emit("completed",a)}catch(c){o(c),this.emit("error",c)}finally{s&&r.signal?.removeEventListener("abort",s),this.#g.delete(i),queueMicrotask(()=>{this.#k()})}},r),this.emit("add"),this.#A()})}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#C(),this):this}pause(){this.#l=!0}clear(){this.#r=new this.#T,this.#v(),this.#R(),this.emit("empty"),this.#o===0&&(this.#B(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#r.size!==0&&await this.#d("empty")}async onSizeLessThan(t){this.#r.size<t||await this.#d("next",()=>this.#r.size<t)}async onIdle(){this.#o===0&&this.#r.size===0||await this.#d("idle")}async onPendingZero(){this.#o!==0&&await this.#d("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#d("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#d("rateLimitCleared")}onError(){return new Promise((t,r)=>{let n=o=>{this.off("error",n),r(o)};this.on("error",n)})}async#d(t,r){return new Promise(n=>{let o=()=>{r&&!r()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#r.size}sizeBy(t){return this.#r.filter(t).length}get pending(){return this.#o}get isPaused(){return this.#l}#M(){this.#n||(this.on("add",()=>{this.#r.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#n||this.#x||(this.#x=!0,queueMicrotask(()=>{this.#x=!1,this.#R()}))}#F(){this.#n||(this.#U(),this.#p())}#R(){let t=this.#m;if(this.#n||this.#r.size===0){t&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#a){let o=Date.now();this.#w(o),r=this.#E()}else r=this.#e;let n=r>=this.#h;n!==t&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#o===this.#y&&this.#r.size>0||this.isRateLimited&&this.#r.size>0}get runningTasks(){return[...this.#g.values()].map(t=>({...t}))}};var Fe=class extends Error{static name="InvalidRequestError";constructor(t="Invalid request"){super(t),this.name="InvalidRequestError"}},Kt=class extends Error{static name="BadResponseError";constructor(t="Bad response"){super(t),this.name="BadResponseError"}};function zp(e){return e[Symbol.asyncIterator]!=null}function Gp(e){if(zp(e))return(async()=>{for await(let t of e)return t})();for(let t of e)return t}var sf=Gp;function Zp(e){let[t,r]=e[Symbol.asyncIterator]!=null?[e[Symbol.asyncIterator](),Symbol.asyncIterator]:[e[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[r](){return this}}}var af=Zp;function jp(e){return e[Symbol.asyncIterator]!=null}function Yp(e,t){let r=0;if(jp(e))return(async function*(){for await(let a of e)yield t(a,r++)})();let n=af(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 cf=Yp;var uf=H("/ipns/");function ff(e){return J(e.subarray(0,uf.byteLength),uf)}var po=class{client;constructor(t){this.client=t}async*findProviders(t,r={}){try{yield*cf(this.client.getProviders(t,r),n=>({id:n.ID,multiaddrs:n.Addrs??[],routing:"delegated-http-routing-v1"}))}catch(n){if(n instanceof Zt)return;throw n}}async provide(){}async cancelReprovide(){}async put(t,r,n){if(!ff(t))return;let o=Sr(t),i=j.createV1(114,o),s=Ie(r);await this.client.putIPNS(i,s,n)}async get(t,r){if(!ff(t))throw new Zt("Not found");let n=Sr(t),o=j.createV1(114,n);try{let i=await this.client.getIPNS(o,r);return rn(i)}catch(i){throw i.name==="BadResponseError"?new Zt("Not found"):i}}toString(){return`DelegatedRoutingV1HttpApiClientContentRouting(${this.client.url})`}},mo=class{client;constructor(t){this.client=t}async findPeer(t,r={}){let n=await sf(this.client.getPeers(t,r));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new Zt("Not found")}async*getClosestPeers(t,r={}){let n;try{n=j.decode(t)}catch{try{n=kn(Yt.decode(t))}catch{n=j.createV1(js,Ct.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 yo={concurrentRequests:4,timeout:3e4,cacheTTL:300*1e3,cacheName:"delegated-routing-v1-cache"},go=class{url;started;httpQueue;shutDownController;timeout;contentRouting;peerRouting;filterAddrs;filterProtocols;inFlightRequests;cacheName;cache;cacheTTL;log;constructor(t,r){this.log=t.logger.forComponent("delegated-routing-v1-http-api-client"),this.started=!1,this.shutDownController=new AbortController,this.shutDownController.signal,this.httpQueue=new an({concurrency:r.concurrentRequests??yo.concurrentRequests}),this.inFlightRequests=new Map,this.url=r.url instanceof URL?r.url:new URL(r.url),this.timeout=r.timeout??yo.timeout,this.filterAddrs=r.filterAddrs,this.filterProtocols=r.filterProtocols,this.contentRouting=new po(this),this.peerRouting=new mo(this),this.cacheName=r.cacheName??yo.cacheName,this.cacheTTL=r.cacheTTL??yo.cacheTTL}get[Bs](){return this.contentRouting}get[Ds](){return this.peerRouting}isStarted(){return this.started}async start(){this.started||(this.started=!0,this.cacheTTL>0&&(this.cache=await globalThis.caches?.open(this.cacheName),this.cache!=null&&this.log("cache enabled with ttl %d",this.cacheTTL)))}async stop(){this.httpQueue.clear(),this.shutDownController.abort(),await globalThis.caches?.delete(this.cacheName),this.started=!1}async*getProviders(t,r={}){this.log("getProviders starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=pr([this.shutDownController.signal,n,r.signal]);let i=kt(),s=kt(),c=0;this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let a=new URL(`${this.url}routing/v1/providers/${t}`);this.#n(a,r.filterAddrs,r.filterProtocols);let l={headers:{accept:"application/x-ndjson, application/json;q=0.8"},signal:o},u=await this.#e(a.toString(),l);if(!u.ok){if(u.status===404)return;throw u.status===422?new Fe("Request does not conform to schema or semantic constraints"):new Kt(`Unexpected status code: ${u.status}`)}let f=u.headers.get("Content-Type");if(f==null)throw new Kt("No Content-Type header received");if(u.body==null){if(f!=="application/x-ndjson")throw new Kt("Routing response had no body");return}if(f.startsWith("application/json")){let E=(await u.json()).Providers??[];for(let b of E){let I=this.#t(b);I!=null&&(c++,yield I)}}else if(f.includes("application/x-ndjson"))for await(let y of vr(Yr(u.body))){let E=this.#t(y);E!=null&&(c++,yield E)}else throw new Kt(`Unsupported Content-Type: ${f}`)}finally{o.clear(),s.resolve(),this.log("getProviders finished found %d providers for %c",c,t)}}async*getPeers(t,r={}){this.log("getPeers starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=pr([this.shutDownController.signal,n,r.signal]);let i=kt(),s=kt();this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let c=new URL(`${this.url}routing/v1/peers/${t.toCID().toString()}`);this.#n(c,r.filterAddrs,r.filterProtocols);let a={headers:{Accept:"application/x-ndjson"},signal:o},l=await this.#e(c.toString(),a);if(l.status===404)return;if(l.status===422)throw new Fe("Request does not conform to schema or semantic constraints");if(l.body==null)throw new Kt("Routing response had no body");if(l.headers.get("Content-Type")?.startsWith("application/json")){let y=(await l.json()).Peers??[];for(let E of y){let b=this.#t(E);b!=null&&(yield b)}}else for await(let f of vr(Yr(l.body))){let y=this.#t(f);y!=null&&(yield y)}}catch(c){this.log.error("getPeers errored - %e",c)}finally{o.clear(),s.resolve(),this.log("getPeers finished: %c",t)}}async*getClosestPeers(t,r={}){let n;if(_s(t))n=t.toCID().toString();else if(j.asCID(t)===t||t instanceof j)n=t.toV1().toString();else throw new nt("Key must be CID or PeerId");this.log("getClosestPeers starts: %s",n);let o=AbortSignal.timeout(this.timeout),i=pr([this.shutDownController.signal,o,r.signal]);let s=kt(),c=kt();this.httpQueue.add(async()=>(s.resolve(),c.promise));try{await s.promise;let a=new URL(`${this.url}routing/v1/dht/closest/peers/${n}`);this.#n(a,r.filterAddrs,r.filterProtocols);let l={headers:{Accept:"application/x-ndjson"},signal:i},u=await this.#e(a.toString(),l);if(u.status===404)return;if(u.status===422)throw new Fe("Request does not conform to schema or semantic constraints");if(u.body==null)throw new Kt("Routing response had no body");if(u.headers.get("Content-Type")?.startsWith("application/json")){let E=(await u.json()).Peers??[];for(let b of E){let I=this.#t(b);I!=null&&(yield I)}}else for await(let y of vr(Yr(u.body))){let E=this.#t(y);E!=null&&(yield E)}}catch(a){this.log.error("getClosestPeers errored - %e",a)}finally{i.clear(),c.resolve(),this.log("getClosestPeers finished: %s",n)}}async getIPNS(t,r={}){this.log("getIPNS starts: %s",t);let n=AbortSignal.timeout(this.timeout),o=pr([this.shutDownController.signal,n,r.signal]);let i=kt(),s=kt();this.httpQueue.add(async()=>(i.resolve(),s.promise));let c=`${this.url}routing/v1/ipns/${t}`;try{await i.promise;let a={headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:o},l=await this.#e(c,a);if(this.log("getIPNS GET %s %d",c,l.status),l.status===404)throw new Zt("No matching records found");if(l.status===422)throw new Fe("Request does not conform to schema or semantic constraints");if(!l.ok)throw new Kt(`Unexpected status code: ${l.status}`);let u=l.headers.get("Content-Type");if(u==null||!u.includes("application/vnd.ipfs.ipns-record"))throw new Zt("No matching records found");if(l.body==null)throw new Kt("GET ipns response had no body");let f=await l.arrayBuffer(),y=new Uint8Array(f,0,f.byteLength);return r.validate!==!1&&await ef(nn(t.multihash),y),Ie(y)}catch(a){throw this.log.error("getIPNS GET %s error - %e",c,a),a}finally{o.clear(),s.resolve(),this.log("getIPNS finished: %s",t)}}async putIPNS(t,r,n={}){this.log("putIPNS starts: %c",t);let o=AbortSignal.timeout(this.timeout),i=pr([this.shutDownController.signal,o,n.signal]);let s=kt(),c=kt();this.httpQueue.add(async()=>(s.resolve(),c.promise));let a=`${this.url}routing/v1/ipns/${t}`;try{await s.promise;let l=rn(r),u={method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:l,signal:i},f=await this.#e(a,u);if(this.log("putIPNS PUT %s %d",a,f.status),f.status!==200)throw new Kt("PUT ipns response had status other than 200")}catch(l){throw this.log.error("putIPNS PUT %s error - %e",a,l.stack),l}finally{i.clear(),c.resolve(),this.log("putIPNS finished: %c",t)}}#t(t){try{let r=[],n=t.Addrs?.map(Mc)??[];return t.Protocols!=null&&r.push(...t.Protocols),t.Protocol!=null&&(r.push(t.Protocol),delete t.Protocol),{...t,Schema:"peer",ID:vc(t.ID),Addrs:n,Protocols:r}}catch(r){this.log.error("could not conform record to peer schema - %e",r)}}#n(t,r,n){if(r!=null||this.filterAddrs!=null){let o=r?.join(",")??this.filterAddrs?.join(",")??"";o!==""&&t.searchParams.set("filter-addrs",o)}if(n!=null||this.filterProtocols!=null){let o=n?.join(",")??this.filterProtocols?.join(",")??"";o!==""&&t.searchParams.set("filter-protocols",o)}}async#e(t,r){let n=r.method??"GET",o=`${n}-${t}`;if(n==="GET"){let a=await this.cache?.match(t);if(a!=null){if(parseInt(a.headers.get("x-cache-expires")??"0",10)>Date.now())return this.log("returning cached response for %s",o),this.logResponse(a),a;this.log("evicting cached response for %s",o),await this.cache?.delete(t)}else this.cache!=null&&this.log("cache miss for %s",o)}let i=this.inFlightRequests.get(o);if(i!=null){let a=await i;return this.log("deduplicating outgoing request for %s",o),a.clone()}this.log("outgoing request:"),this.logRequest(t,r);let s=fetch(t,r).then(async a=>{if(this.log("incoming response:"),this.logResponse(a),this.cache!=null&&a.ok&&n==="GET"){let l=Date.now()+this.cacheTTL,u=new Headers(a.headers);u.set("x-cache-expires",l.toString());let f=new Response(a.clone().body,{status:a.status,statusText:a.statusText,headers:u});await this.cache.put(t,f)}return a}).finally(()=>{this.inFlightRequests.delete(o)});return this.inFlightRequests.set(o,s),await s}toString(){return`DefaultDelegatedRoutingV1HttpApiClient(${this.url})`}logRequest(t,r){let n=new Headers(r.headers);this.log("%s %s HTTP/1.1",r.method??"GET",t);for(let[o,i]of n.entries())this.log("%s: %s",o,i)}logResponse(t){this.log("HTTP/1.1 %d %s",t.status,t.statusText);for(let[r,n]of t.headers.entries())this.log("%s: %s",r,n)}};function Wp(e){return t=>new go(t,e)}return yf(Xp);})();
2
+ "use strict";var HeliaDelegatedRoutingV1HttpApiClient=(()=>{var xc=Object.create;var Cr=Object.defineProperty;var Ec=Object.getOwnPropertyDescriptor;var Sc=Object.getOwnPropertyNames;var vc=Object.getPrototypeOf,Ac=Object.prototype.hasOwnProperty;var Bc=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ht=(r,t)=>{for(var e in t)Cr(r,e,{get:t[e],enumerable:!0})},Rs=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Sc(t))!Ac.call(r,o)&&o!==e&&Cr(r,o,{get:()=>t[o],enumerable:!(n=Ec(t,o))||n.enumerable});return r};var Tc=(r,t,e)=>(e=r!=null?xc(vc(r)):{},Rs(t||!r||!r.__esModule?Cr(e,"default",{value:r,enumerable:!0}):e,r)),Ic=r=>Rs(Cr({},"__esModule",{value:!0}),r);var pc=Bc((ib,As)=>{"use strict";var lh=Object.prototype.hasOwnProperty,ut="~";function Br(){}Object.create&&(Br.prototype=Object.create(null),new Br().__proto__||(ut=!1));function hh(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function dc(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new hh(e,n||r,o),i=ut?ut+t:t;return r._events[i]?r._events[i].fn?r._events[i]=[r._events[i],s]:r._events[i].push(s):(r._events[i]=s,r._eventsCount++),r}function In(r,t){--r._eventsCount===0?r._events=new Br:delete r._events[t]}function at(){this._events=new Br,this._eventsCount=0}at.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)lh.call(e,n)&&t.push(ut?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};at.prototype.listeners=function(t){var e=ut?ut+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,s=n.length,i=new Array(s);o<s;o++)i[o]=n[o].fn;return i};at.prototype.listenerCount=function(t){var e=ut?ut+t:t,n=this._events[e];return n?n.fn?1:n.length:0};at.prototype.emit=function(t,e,n,o,s,i){var a=ut?ut+t:t;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,u,l;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,o),!0;case 5:return c.fn.call(c.context,e,n,o,s),!0;case 6:return c.fn.call(c.context,e,n,o,s,i),!0}for(l=1,u=new Array(f-1);l<f;l++)u[l-1]=arguments[l];c.fn.apply(c.context,u)}else{var p=c.length,d;for(l=0;l<p;l++)switch(c[l].once&&this.removeListener(t,c[l].fn,void 0,!0),f){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,e);break;case 3:c[l].fn.call(c[l].context,e,n);break;case 4:c[l].fn.call(c[l].context,e,n,o);break;default:if(!u)for(d=1,u=new Array(f-1);d<f;d++)u[d-1]=arguments[d];c[l].fn.apply(c[l].context,u)}}return!0};at.prototype.on=function(t,e,n){return dc(this,t,e,n,!1)};at.prototype.once=function(t,e,n){return dc(this,t,e,n,!0)};at.prototype.removeListener=function(t,e,n,o){var s=ut?ut+t:t;if(!this._events[s])return this;if(!e)return In(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&In(this,s);else{for(var a=0,c=[],f=i.length;a<f;a++)(i[a].fn!==e||o&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);c.length?this._events[s]=c.length===1?c[0]:c:In(this,s)}return this};at.prototype.removeAllListeners=function(t){var e;return t?(e=ut?ut+t:t,this._events[e]&&In(this,e)):(this._events=new Br,this._eventsCount=0),this};at.prototype.off=at.prototype.removeListener;at.prototype.addListener=at.prototype.on;at.prefixed=ut;at.EventEmitter=at;typeof As<"u"&&(As.exports=at)});var Eh={};ht(Eh,{delegatedRoutingV1HttpApiClient:()=>_s,delegatedRoutingV1HttpApiClientContentRouting:()=>wh,delegatedRoutingV1HttpApiClientPeerRouting:()=>xh});var Os=Symbol.for("@libp2p/content-routing");var bt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},_r=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var It=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Dr=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Lr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Ze=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var On=Symbol.for("@libp2p/peer-id");var Ps=Symbol.for("@libp2p/peer-routing");var kn={};ht(kn,{base58btc:()=>G,base58flickr:()=>Uc});var Ih=new Uint8Array(0);function Us(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Pt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return ae(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return ae(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function Fs(r){return new TextEncoder().encode(r)}function Ns(r){return new TextDecoder().decode(r)}function Cc(r){return r?.buffer instanceof ArrayBuffer}function ae(r){return Cc(r)?r:r.slice()}function _c(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var S=0,m=0,x=0,v=y.length;x!==v&&y[x]===0;)x++,S++;for(var B=(v-x)*u+1>>>0,L=new Uint8Array(B);x!==v;){for(var _=y[x],P=0,R=B-1;(_!==0||P<m)&&R!==-1;R--,P++)_+=256*L[R]>>>0,L[R]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");m=P,x++}for(var I=B-m;I!==B&&L[I]===0;)I++;for(var U=c.repeat(S);I<B;++I)U+=r.charAt(L[I]);return U}function p(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var S=0;if(y[S]!==" "){for(var m=0,x=0;y[S]===c;)m++,S++;for(var v=(y.length-S)*f+1>>>0,B=new Uint8Array(v);y[S];){var L=e[y.charCodeAt(S)];if(L===255)return;for(var _=0,P=v-1;(L!==0||_<x)&&P!==-1;P--,_++)L+=a*B[P]>>>0,B[P]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");x=_,S++}if(y[S]!==" "){for(var R=v-x;R!==v&&B[R]===0;)R++;for(var I=new Uint8Array(m+(v-R)),U=m;R!==v;)I[U++]=B[R++];return I}}}function d(y){var S=p(y);if(S)return S;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:p,decode:d}}var Dc=_c,Lc=Dc,Ks=Lc;var Pn=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Un=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Vs(this,t)}},Fn=class{decoders;constructor(t){this.decoders=t}or(t){return Vs(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Vs(r,t){return new Fn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Nn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Pn(t,e,n),this.decoder=new Un(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ae({name:r,prefix:t,encode:e,decode:n}){return new Nn(r,t,e,n)}function jt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Ks(e,r);return Ae({prefix:t,name:r,encode:n,decode:s=>Pt(o(s))})}function Rc(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let u=t[r[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|u,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Oc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Pc(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function j({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Pc(n);return Ae({prefix:t,name:r,encode(s){return Oc(s,n,e)},decode(s){return Rc(s,o,e,r)}})}var G=jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Uc=jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Kn={};ht(Kn,{base32:()=>$t,base32hex:()=>Kc,base32hexpad:()=>Mc,base32hexpadupper:()=>qc,base32hexupper:()=>Vc,base32pad:()=>Nc,base32padupper:()=>kc,base32upper:()=>Fc,base32z:()=>Hc});var $t=j({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Fc=j({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Nc=j({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),kc=j({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Kc=j({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Vc=j({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Mc=j({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),qc=j({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Hc=j({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Vn={};ht(Vn,{base36:()=>Ye,base36upper:()=>zc});var Ye=jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),zc=jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ct={};ht(Ct,{Digest:()=>ce,create:()=>fe,decode:()=>Ut,equals:()=>qn,hasCode:()=>uf});var jc=Hs,Ms=128,$c=127,Zc=~$c,Yc=Math.pow(2,31);function Hs(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Yc;)t[e++]=r&255|Ms,r/=128;for(;r&Zc;)t[e++]=r&255|Ms,r>>>=7;return t[e]=r|0,Hs.bytes=e-n+1,t}var Gc=Mn,Xc=128,qs=127;function Mn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Mn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&qs)<<o:(i&qs)*Math.pow(2,o),o+=7}while(i>=Xc);return Mn.bytes=s-n,e}var Wc=Math.pow(2,7),Qc=Math.pow(2,14),Jc=Math.pow(2,21),tf=Math.pow(2,28),ef=Math.pow(2,35),rf=Math.pow(2,42),nf=Math.pow(2,49),of=Math.pow(2,56),sf=Math.pow(2,63),af=function(r){return r<Wc?1:r<Qc?2:r<Jc?3:r<tf?4:r<ef?5:r<rf?6:r<nf?7:r<of?8:r<sf?9:10},cf={encode:jc,decode:Gc,encodingLength:af},ff=cf,Ge=ff;function Xe(r,t=0){return[Ge.decode(r,t),Ge.decode.bytes]}function Be(r,t,e=0){return Ge.encode(r,t,e),t}function Te(r){return Ge.encodingLength(r)}function fe(r,t){let e=t.byteLength,n=Te(r),o=n+Te(e),s=new Uint8Array(o+e);return Be(r,s,0),Be(e,s,n),s.set(t,o),new ce(r,e,t,s)}function Ut(r){let t=Pt(r),[e,n]=Xe(t),[o,s]=Xe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ce(e,o,i,t)}function qn(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Us(r.bytes,e.bytes)}}var ce=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=ae(n),this.bytes=ae(o)}};function uf(r,t){return r.code===t}function zs(r,t){let{bytes:e,version:n}=r;return n===0?hf(e,Hn(r),t??G.encoder):df(e,Hn(r),t??$t.encoder)}var js=new WeakMap;function Hn(r){let t=js.get(r);if(t==null){let e=new Map;return js.set(r,e),e}return t}var q=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=ae(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==We)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==pf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=fe(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&qn(t.multihash,n.multihash)}toString(t){return zs(this,t)}toJSON(){return{"/":zs(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??$s(n,o,s.bytes))}else if(e[mf]===!0){let{version:n,multihash:o,code:s}=e,i=Ut(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==We)throw new Error(`Version 0 CID must use dag-pb (code: ${We}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=$s(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,We,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Pt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new ce(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,p]=Xe(t.subarray(e));return e+=p,l},o=n(),s=We;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),f=e+c,u=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(t,e){let[n,o]=lf(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Hn(s).set(n,t),s}};function lf(r,t){switch(r[0]){case"Q":{let e=t??G;return[G.prefix,e.decode(`${G.prefix}${r}`)]}case G.prefix:{let e=t??G;return[G.prefix,e.decode(r)]}case $t.prefix:{let e=t??$t;return[$t.prefix,e.decode(r)]}case Ye.prefix:{let e=t??Ye;return[Ye.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function hf(r,t,e){let{prefix:n}=e;if(n!==G.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function df(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var We=112,pf=18;function $s(r,t,e){let n=Te(r),o=n+Te(t),s=new Uint8Array(o+e.byteLength);return Be(r,s,0),Be(t,s,n),s.set(e,o),s}var mf=Symbol.for("@ipld/js-cid/CID");var zn={};ht(zn,{identity:()=>pt});var Zs=0,yf="identity",Ys=Pt;function gf(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return fe(Zs,Ys(r))}var pt={code:Zs,name:yf,encode:Ys,digest:gf};function Ie(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}async function Gs(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}function Ft(r=0){return new Uint8Array(r)}function Qe(r=0){return new Uint8Array(r)}function jn(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=Qe(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}function Xs(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var Qs=Symbol.for("@achingbrain/uint8arraylist");function Ws(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Or(r){return!!r?.[Qs]}var mt=class r{bufs;length;[Qs]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Or(n)){e+=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+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Or(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Ws(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Ws(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Or(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return jn(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:jn(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=n,s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,u=e>a&&e<=c;if(f&&u){if(t===a&&e===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Or(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=e;l<=c;l+=u){u=0;for(let p=f;p>=0;p--){let d=this.get(l+p);if(n[p]!==d){u=Math.max(1,p-a[d]);break}}if(u===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=Qe(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=Ft(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=Ft(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=Ft(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=Qe(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=Ft(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=Ft(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=Ft(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=Ft(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=Ft(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!Xs(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var $n={};ht($n,{base10:()=>bf});var bf=jt({prefix:"9",name:"base10",alphabet:"0123456789"});var Zn={};ht(Zn,{base16:()=>wf,base16upper:()=>xf});var wf=j({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),xf=j({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Yn={};ht(Yn,{base2:()=>Ef});var Ef=j({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Gn={};ht(Gn,{base256emoji:()=>Tf});var Js=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Sf=Js.reduce((r,t,e)=>(r[e]=t,r),[]),vf=Js.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Af(r){return r.reduce((t,e)=>(t+=Sf[e],t),"")}function Bf(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=vf[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Tf=Ae({prefix:"\u{1F680}",name:"base256emoji",encode:Af,decode:Bf});var Wn={};ht(Wn,{base64:()=>If,base64pad:()=>Cf,base64url:()=>Xn,base64urlpad:()=>_f});var If=j({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Cf=j({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xn=j({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),_f=j({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Qn={};ht(Qn,{base8:()=>Df});var Df=j({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Jn={};ht(Jn,{identity:()=>Lf});var Lf=Ae({prefix:"\0",name:"identity",encode:r=>Ns(r),decode:r=>Fs(r)});var hd=new TextEncoder,dd=new TextDecoder;var ti=85;var ro={};ht(ro,{sha256:()=>Je,sha512:()=>Pf});var Of=20;function eo({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new to(r,t,e,n,o)}var to=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??Of,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.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?ri(n,this.code,e?.truncate):n.then(o=>ri(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function ri(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return fe(t,r)}function oi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Je=eo({name:"sha2-256",code:18,encode:oi("SHA-256")}),Pf=eo({name:"sha2-512",code:19,encode:oi("SHA-512")});var dt={...Jn,...Yn,...Qn,...$n,...Zn,...Kn,...Vn,...kn,...Wn,...Gn},Bd={...ro,...zn};function no(r=0){return new Uint8Array(r)}function ii(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var si=ii("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),oo=ii("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=no(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Uf={utf8:si,"utf-8":si,hex:dt.base16,latin1:oo,ascii:oo,binary:oo,...dt},Pr=Uf;function Ur(r,t="utf8"){let e=Pr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function Zt(r,t="utf8"){let e=Pr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Ff=parseInt("11111",2),so=parseInt("10000000",2),Nf=parseInt("01111111",2),ai={0:tr,1:tr,2:kf,3:Mf,4:qf,5:Vf,6:Kf,16:tr,22:tr,48:tr};function io(r,t={offset:0}){let e=r[t.offset]&Ff;if(t.offset++,ai[e]!=null)return ai[e](r,t);throw new Error("No decoder for tag "+e)}function er(r,t){let e=0;if((r[t.offset]&so)===so){let n=r[t.offset]&Nf,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function tr(r,t){er(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=io(r,t);if(n===null)break;e.push(n)}return e}function kf(r,t){let e=er(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function Kf(r,t){let e=er(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let f=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let l=0;l<c.length;l++)u+=c[l]<<l*7;a+=`.${u}`,c=[]}}return a}function Vf(r,t){return t.offset++,null}function Mf(r,t){let e=er(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function qf(r,t){let e=er(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Hf(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new mt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function ao(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Hf(r.byteLength);return new mt(Uint8Array.from([t.byteLength|so]),t)}function ci(r){let t=new mt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new mt(Uint8Array.from([2]),ao(t),t)}function fi(r){let t=Uint8Array.from([0]),e=new mt(t,r);return new mt(Uint8Array.from([3]),ao(e),e)}function Fr(r,t=48){let e=new mt;for(let n of r)e.append(n);return new mt(Uint8Array.from([t]),ao(e),e)}var zf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),jf=Uint8Array.from([6,5,43,129,4,0,34]),$f=Uint8Array.from([6,5,43,129,4,0,35]),Zf={ext:!0,kty:"EC",crv:"P-256"},Yf={ext:!0,kty:"EC",crv:"P-384"},Gf={ext:!0,kty:"EC",crv:"P-521"},co=32,fo=48,uo=66;function ui(r){let t=io(r);return li(t)}function li(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===co*2+1)return n=Zt(t.subarray(e,e+co),"base64url"),o=Zt(t.subarray(e+co),"base64url"),new Ce({...Zf,key_ops:["verify"],x:n,y:o});if(t.byteLength===fo*2+1)return n=Zt(t.subarray(e,e+fo),"base64url"),o=Zt(t.subarray(e+fo),"base64url"),new Ce({...Yf,key_ops:["verify"],x:n,y:o});if(t.byteLength===uo*2+1)return n=Zt(t.subarray(e,e+uo),"base64url"),o=Zt(t.subarray(e+uo),"base64url"),new Ce({...Gf,key_ops:["verify"],x:n,y:o});throw new bt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function hi(r){return Fr([ci(Uint8Array.from([1])),Fr([Xf(r.crv)],160),Fr([fi(new mt(Uint8Array.from([4]),Ur(r.x??"","base64url"),Ur(r.y??"","base64url")))],161)]).subarray()}function Xf(r){if(r==="P-256")return zf;if(r==="P-384")return jf;if(r==="P-521")return $f;throw new bt(`Invalid curve ${r}`)}var Ce=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=hi(this.jwk)),this._raw}toMultihash(){return pt.digest(_e(this))}toCID(){return q.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Ie(this.raw,t.raw)}async verify(t,e,n){return Gs(this.jwk,e,t,n)}};function lo(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in r&&r.BYTES_PER_ELEMENT===1}function Yt(r,t=""){if(typeof r!="number"){let e=t&&`"${t}" `;throw new TypeError(`${e}expected number, got ${typeof r}`)}if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new RangeError(`${e}expected integer >= 0, got ${r}`)}}function yt(r,t,e=""){let n=lo(r),o=r?.length,s=t!==void 0;if(!n||s&&o!==t){let i=e&&`"${e}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof r}`,f=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(f):new TypeError(f)}return r}function Nr(r){if(typeof r!="function"||typeof r.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Yt(r.outputLen),Yt(r.blockLen),r.outputLen<1)throw new Error('"outputLen" must be >= 1');if(r.blockLen<1)throw new Error('"blockLen" must be >= 1')}function De(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function kr(r,t){yt(r,void 0,"digestInto() output");let e=t.outputLen;if(r.length<e)throw new RangeError('"digestInto() output" expected to be of length >='+e)}function kt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Kr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Et(r,t){return r<<32-t|r>>>t}var pi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Wf=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Vr(r){if(yt(r),pi)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Wf[r[e]];return t}var Nt={_0:48,_9:57,A:65,F:70,a:97,f:102};function di(r){if(r>=Nt._0&&r<=Nt._9)return r-Nt._0;if(r>=Nt.A&&r<=Nt.F)return r-(Nt.A-10);if(r>=Nt.a&&r<=Nt.f)return r-(Nt.a-10)}function rr(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);if(pi)try{return Uint8Array.fromHex(r)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=r.length,e=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=di(r.charCodeAt(s)),a=di(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function ho(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];yt(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function po(r,t={}){let e=(o,s)=>r(s).update(o).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.canXOF=n.canXOF,e.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function mi(r=32){Yt(r,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(r>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${r}`);return t.getRandomValues(new Uint8Array(r))}var mo=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function yi(r,t,e){return r&t^~r&e}function gi(r,t,e){return r&t^r&e^t&e}var nr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,o){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Kr(this.buffer)}update(t){De(this),yt(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Kr(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){De(this),kr(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,kt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Kr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Kt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var rt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Mr=BigInt(4294967295),bi=BigInt(32);function Qf(r,t=!1){return t?{h:Number(r&Mr),l:Number(r>>bi&Mr)}:{h:Number(r>>bi&Mr)|0,l:Number(r&Mr)|0}}function wi(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=Qf(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var yo=(r,t,e)=>r>>>e,go=(r,t,e)=>r<<32-e|t>>>e,ue=(r,t,e)=>r>>>e|t<<32-e,le=(r,t,e)=>r<<32-e|t>>>e,or=(r,t,e)=>r<<64-e|t>>>e-32,sr=(r,t,e)=>r>>>e-32|t<<64-e;function _t(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var xi=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Ei=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Si=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),vi=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Ai=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Bi=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var tu=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]),Gt=new Uint32Array(64),bo=class extends nr{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let l=0;l<16;l++,e+=4)Gt[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let p=Gt[l-15],d=Gt[l-2],y=Et(p,7)^Et(p,18)^p>>>3,S=Et(d,17)^Et(d,19)^d>>>10;Gt[l]=S+Gt[l-7]+y+Gt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let p=Et(a,6)^Et(a,11)^Et(a,25),d=u+p+yi(a,c,f)+tu[l]+Gt[l]|0,S=(Et(n,2)^Et(n,13)^Et(n,22))+gi(n,o,s)|0;u=f,f=c,c=a,a=i+d|0,i=s,s=o,o=n,n=d+S|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,f,u)}roundClean(){kt(Gt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),kt(this.buffer)}},wo=class extends bo{A=Kt[0]|0;B=Kt[1]|0;C=Kt[2]|0;D=Kt[3]|0;E=Kt[4]|0;F=Kt[5]|0;G=Kt[6]|0;H=Kt[7]|0;constructor(){super(32)}};var Ti=wi(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),eu=Ti[0],ru=Ti[1],Xt=new Uint32Array(80),Wt=new Uint32Array(80),xo=class extends nr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:p,Gh:d,Gl:y,Hh:S,Hl:m}=this;return[t,e,n,o,s,i,a,c,f,u,l,p,d,y,S,m]}set(t,e,n,o,s,i,a,c,f,u,l,p,d,y,S,m){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=p|0,this.Gh=d|0,this.Gl=y|0,this.Hh=S|0,this.Hl=m|0}process(t,e){for(let B=0;B<16;B++,e+=4)Xt[B]=t.getUint32(e),Wt[B]=t.getUint32(e+=4);for(let B=16;B<80;B++){let L=Xt[B-15]|0,_=Wt[B-15]|0,P=ue(L,_,1)^ue(L,_,8)^yo(L,_,7),R=le(L,_,1)^le(L,_,8)^go(L,_,7),I=Xt[B-2]|0,U=Wt[B-2]|0,M=ue(I,U,19)^or(I,U,61)^yo(I,U,6),F=le(I,U,19)^sr(I,U,61)^go(I,U,6),h=Si(R,F,Wt[B-7],Wt[B-16]),g=vi(h,P,M,Xt[B-7],Xt[B-16]);Xt[B]=g|0,Wt[B]=h|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:p,Fh:d,Fl:y,Gh:S,Gl:m,Hh:x,Hl:v}=this;for(let B=0;B<80;B++){let L=ue(l,p,14)^ue(l,p,18)^or(l,p,41),_=le(l,p,14)^le(l,p,18)^sr(l,p,41),P=l&d^~l&S,R=p&y^~p&m,I=Ai(v,_,R,ru[B],Wt[B]),U=Bi(I,x,L,P,eu[B],Xt[B]),M=I|0,F=ue(n,o,28)^or(n,o,34)^or(n,o,39),h=le(n,o,28)^sr(n,o,34)^sr(n,o,39),g=n&s^n&a^s&a,E=o&i^o&c^i&c;x=S|0,v=m|0,S=d|0,m=y|0,d=l|0,y=p|0,{h:l,l:p}=_t(f|0,u|0,U|0,M|0),f=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let w=xi(M,h,E);n=Ei(w,U,F,g),o=w|0}({h:n,l:o}=_t(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=_t(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=_t(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=_t(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:p}=_t(this.Eh|0,this.El|0,l|0,p|0),{h:d,l:y}=_t(this.Fh|0,this.Fl|0,d|0,y|0),{h:S,l:m}=_t(this.Gh|0,this.Gl|0,S|0,m|0),{h:x,l:v}=_t(this.Hh|0,this.Hl|0,x|0,v|0),this.set(n,o,s,i,a,c,f,u,l,p,d,y,S,m,x,v)}roundClean(){kt(Xt,Wt)}destroy(){this.destroyed=!0,kt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Eo=class extends xo{Ah=rt[0]|0;Al=rt[1]|0;Bh=rt[2]|0;Bl=rt[3]|0;Ch=rt[4]|0;Cl=rt[5]|0;Dh=rt[6]|0;Dl=rt[7]|0;Eh=rt[8]|0;El=rt[9]|0;Fh=rt[10]|0;Fl=rt[11]|0;Gh=rt[12]|0;Gl=rt[13]|0;Hh=rt[14]|0;Hl=rt[15]|0;constructor(){super(64)}};var Ii=po(()=>new wo,mo(1));var qr=po(()=>new Eo,mo(3));var K=(r,t,e)=>yt(r,t,e),vo=Yt,Le=Vr,W=(...r)=>ho(...r),Re=r=>rr(r),he=lo,ir=r=>mi(r),zr=BigInt(0),So=BigInt(1);function St(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new TypeError(e+"expected boolean, got type="+typeof r)}return r}function jr(r){if(typeof r=="bigint"){if(!Hr(r))throw new RangeError("positive bigint expected, got "+r)}else vo(r);return r}function vt(r,t=""){if(typeof r!="number"){let e=t&&`"${t}" `;throw new TypeError(e+"expected number, got type="+typeof r)}if(!Number.isSafeInteger(r)){let e=t&&`"${t}" `;throw new RangeError(e+"expected safe integer, got "+r)}}function ar(r){let t=jr(r).toString(16);return t.length&1?"0"+t:t}function Ci(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);return r===""?zr:BigInt("0x"+r)}function de(r){return Ci(Vr(r))}function Dt(r){return Ci(Vr(cr(yt(r)).reverse()))}function $r(r,t){if(Yt(t),t===0)throw new RangeError("zero length");r=jr(r);let e=r.toString(16);if(e.length>t*2)throw new RangeError("number too large");return rr(e.padStart(t*2,"0"))}function Ao(r,t){return $r(r,t).reverse()}function _i(r,t){if(r=K(r),t=K(t),r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function cr(r){return Uint8Array.from(K(r))}function Zr(r){if(typeof r!="string")throw new TypeError("ascii string expected, got "+typeof r);return Uint8Array.from(r,(t,e)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${r[e]}" with code ${n} at position ${e}`);return n})}var Hr=r=>typeof r=="bigint"&&zr<=r;function nu(r,t,e){return Hr(r)&&Hr(t)&&Hr(e)&&t<=r&&r<e}function Oe(r,t,e,n){if(!nu(t,e,n))throw new RangeError("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Pe(r){if(r<zr)throw new Error("expected non-negative bigint, got "+r);let t;for(t=0;r>zr;r>>=So,t+=1);return t}var fr=r=>(So<<BigInt(r))-So;function Di(r,t,e){if(Yt(r,"hashLen"),Yt(t,"qByteLen"),typeof e!="function")throw new TypeError("hmacFn must be a function");let n=m=>new Uint8Array(m),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),f=n(r),u=0,l=()=>{c.fill(1),f.fill(0),u=0},p=(...m)=>e(f,W(c,...m)),d=(m=o)=>{f=p(s,m),c=p(),m.length!==0&&(f=p(i,m),c=p())},y=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let m=0,x=[];for(;m<t;){c=p();let v=c.slice();x.push(v),m+=c.length}return W(...x)};return(m,x)=>{l(),d(m);let v;for(;(v=x(y()))===void 0;)d();return l(),v}}function At(r,t={},e={}){if(Object.prototype.toString.call(r)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(r,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=r[s];if(a&&c===void 0)return;let f=typeof c;if(f!==i||c===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${f}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(e,!0)}var Bo=()=>{throw new Error("not implemented")};var nt=BigInt(0),$=BigInt(1),pe=BigInt(2),Pi=BigInt(3),Ui=BigInt(4),Fi=BigInt(5),ou=BigInt(7),Ni=BigInt(8),su=BigInt(9),ki=BigInt(16);function Y(r,t){if(t<=nt)throw new Error("mod: expected positive modulus, got "+t);let e=r%t;return e>=nt?e:t+e}function H(r,t,e){if(t<nt)throw new Error("pow2: expected non-negative exponent, got "+t);let n=r;for(;t-- >nt;)n*=n,n%=e;return n}function Li(r,t){if(r===nt)throw new Error("invert: expected non-zero number");if(t<=nt)throw new Error("invert: expected positive modulus, got "+t);let e=Y(r,t),n=t,o=nt,s=$,i=$,a=nt;for(;e!==nt;){let f=n/e,u=n-e*f,l=o-i*f,p=s-a*f;n=e,e=u,o=i,s=a,i=l,a=p}if(n!==$)throw new Error("invert: does not exist");return Y(o,t)}function To(r,t,e){let n=r;if(!n.eql(n.sqr(t),e))throw new Error("Cannot find square root")}function Ki(r,t){let e=r,n=(e.ORDER+$)/Ui,o=e.pow(t,n);return To(e,o,t),o}function iu(r,t){let e=r,n=(e.ORDER-Fi)/Ni,o=e.mul(t,pe),s=e.pow(o,n),i=e.mul(t,s),a=e.mul(e.mul(i,pe),s),c=e.mul(i,e.sub(a,e.ONE));return To(e,c,t),c}function au(r){let t=Ue(r),e=Vi(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+ou)/ki;return((a,c)=>{let f=a,u=f.pow(c,i),l=f.mul(u,n),p=f.mul(u,o),d=f.mul(u,s),y=f.eql(f.sqr(l),c),S=f.eql(f.sqr(p),c);u=f.cmov(u,l,y),l=f.cmov(d,p,S);let m=f.eql(f.sqr(l),c),x=f.cmov(u,l,m);return To(f,x,c),x})}function Vi(r){if(r<Pi)throw new Error("sqrt is not defined for small field");let t=r-$,e=0;for(;t%pe===nt;)t/=pe,e++;let n=pe,o=Ue(r);for(;Ri(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Ki;let s=o.pow(n,t),i=(t+$)/pe;return function(c,f){let u=c;if(u.is0(f))return f;if(Ri(u,f)!==1)throw new Error("Cannot find square root");let l=e,p=u.mul(u.ONE,s),d=u.pow(f,t),y=u.pow(f,i);for(;!u.eql(d,u.ONE);){if(u.is0(d))return u.ZERO;let S=1,m=u.sqr(d);for(;!u.eql(m,u.ONE);)if(S++,m=u.sqr(m),S===l)throw new Error("Cannot find square root");let x=$<<BigInt(l-S-1),v=u.pow(p,x);l=S,p=u.sqr(v),d=u.mul(d,p),y=u.mul(y,v)}return y}}function cu(r){return r%Ui===Pi?Ki:r%Ni===Fi?iu:r%ki===su?au(r):Vi(r)}var Vt=(r,t)=>(Y(r,t)&$)===$,fu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Io(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=fu.reduce((n,o)=>(n[o]="function",n),t);if(At(r,e),vt(r.BYTES,"BYTES"),vt(r.BITS,"BITS"),r.BYTES<1||r.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(r.ORDER<=$)throw new Error("invalid field: expected ORDER > 1, got "+r.ORDER);return r}function uu(r,t,e){let n=r;if(e<nt)throw new Error("invalid exponent, negatives unsupported");if(e===nt)return n.ONE;if(e===$)return t;let o=n.ONE,s=t;for(;e>nt;)e&$&&(o=n.mul(o,s)),s=n.sqr(s),e>>=$;return o}function ur(r,t,e=!1){let n=r,o=new Array(t.length).fill(e?n.ZERO:void 0),s=t.reduce((a,c,f)=>n.is0(c)?a:(o[f]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,f)=>n.is0(c)?a:(o[f]=n.mul(a,o[f]),n.mul(a,c)),i),o}function Ri(r,t){let e=r,n=(e.ORDER-$)/pe,o=e.pow(t,n),s=e.eql(o,e.ONE),i=e.eql(o,e.ZERO),a=e.eql(o,e.neg(e.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function lu(r,t){if(t!==void 0&&vo(t),r<=nt)throw new Error("invalid n length: expected positive n, got "+r);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let e=Pe(r);if(t!==void 0&&t<e)throw new Error(`invalid n length: expected bit length (${e}) >= n.length (${t})`);let n=t!==void 0?t:e,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Oi=new WeakMap,Yr=class{ORDER;BITS;BYTES;isLE;ZERO=nt;ONE=$;_lengths;_mod;constructor(t,e={}){if(t<=$)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:e.sqrt,enumerable:!0}),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=Object.freeze(e.allowedLengths.slice())),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:o,nByteLength:s}=lu(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return Y(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return nt<=t&&t<this.ORDER}is0(t){return t===nt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&$)===$}neg(t){return Y(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return Y(t*t,this.ORDER)}add(t,e){return Y(t+e,this.ORDER)}sub(t,e){return Y(t-e,this.ORDER)}mul(t,e){return Y(t*e,this.ORDER)}pow(t,e){return uu(this,t,e)}div(t,e){return Y(t*Li(e,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,e){return t+e}subN(t,e){return t-e}mulN(t,e){return t*e}inv(t){return Li(t,this.ORDER)}sqrt(t){let e=Oi.get(this);return e||Oi.set(this,e=cu(this.ORDER)),e(this,t)}toBytes(t){return this.isLE?Ao(t,this.BYTES):$r(t,this.BYTES)}fromBytes(t,e=!1){K(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_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 f=new Uint8Array(o);f.set(t,s?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?Dt(t):de(t);if(a&&(c=Y(c,i)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return ur(this,t)}cmov(t,e,n){return St(n,"condition"),n?e:t}};Object.freeze(Yr.prototype);function Ue(r,t={}){return new Yr(r,t)}function Mi(r){if(typeof r!="bigint")throw new Error("field order must be bigint");if(r<=$)throw new Error("field order must be greater than 1");let t=Pe(r-$);return Math.ceil(t/8)}function Co(r){let t=Mi(r);return t+Math.ceil(t/2)}function _o(r,t,e=!1){K(r);let n=r.length,o=Mi(t),s=Math.max(Co(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Dt(r):de(r),a=Y(i,t-$)+$;return e?Ao(a,o):$r(a,o)}var Fe=BigInt(0),me=BigInt(1);function lr(r,t){let e=t.negate();return r?e:t}function ye(r,t){let e=ur(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function ji(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Do(r,t){ji(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=fr(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function qi(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=me);let f=t*n,u=f+Math.abs(a)-1,l=a===0,p=a<0,d=t%2!==0;return{nextN:c,offset:u,isZero:l,isNeg:p,isNegF:d,offsetF:f}}var Lo=new WeakMap,$i=new WeakMap;function Ro(r){return $i.get(r)||1}function Hi(r){if(r!==Fe)throw new Error("invalid wNAF")}var Ne=class{BASE;ZERO;Fn;bits;constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let o=t;for(;e>Fe;)e&me&&(n=n.add(o)),o=o.double(),e>>=me;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=Do(e,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let f=1;f<o;f++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Do(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:u,isNeg:l,isNegF:p,offsetF:d}=qi(n,a,i);n=c,u?s=s.add(lr(p,e[d])):o=o.add(lr(l,e[f]))}return Hi(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=Do(t,this.bits);for(let i=0;i<s.windows&&n!==Fe;i++){let{nextN:a,offset:c,isZero:f,isNeg:u}=qi(n,i,s);if(n=a,!f){let l=e[c];o=o.add(u?l.negate():l)}}return Hi(n),o}getPrecomputes(t,e,n){let o=Lo.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),Lo.set(e,o))),o}cached(t,e,n){let o=Ro(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=Ro(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){ji(e,this.bits),$i.set(t,e),Lo.delete(t)}hasCache(t){return Ro(t)!==1}};function Zi(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Fe||n>Fe;)e&me&&(s=s.add(o)),n&me&&(i=i.add(o)),o=o.double(),e>>=me,n>>=me;return{p1:s,p2:i}}function zi(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Io(t),t}else return Ue(r,{isLE:e})}function Gr(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let f=t[c];if(!(typeof f=="bigint"&&f>Fe))throw new Error(`CURVE.${c} must be positive bigint`)}let o=zi(t.p,e.Fp,n),s=zi(t.n,e.Fn,n),a=["Gx","Gy","a",r==="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:s}}function Xr(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var Qt=BigInt(0),tt=BigInt(1),Oo=BigInt(2),hu=BigInt(8);function du(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function Yi(r,t={}){let e=t,n=Gr("edwards",r,e,e.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;At(e,{},{uvRatio:"function"});let c=Oo<<BigInt(s.BYTES*8)-tt,f=S=>o.create(S),u=e.uvRatio===void 0?(S,m)=>{try{return{isValid:!0,value:o.sqrt(o.div(S,m))}}catch{return{isValid:!1,value:Qt}}}:e.uvRatio;if(!du(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(S,m,x=!1){let v=x?tt:Qt;return Oe("coordinate "+S,m,v,c),m}function p(S){if(!(S instanceof d))throw new Error("EdwardsPoint expected")}class d{static BASE=new d(i.Gx,i.Gy,tt,f(i.Gx*i.Gy));static ZERO=new d(Qt,tt,tt,Qt);static Fp=o;static Fn=s;X;Y;Z;T;constructor(m,x,v,B){this.X=l("x",m),this.Y=l("y",x),this.Z=l("z",v,!0),this.T=l("t",B),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){if(m instanceof d)throw new Error("extended point not allowed");let{x,y:v}=m||{};return l("x",x),l("y",v),new d(x,v,tt,f(x*v))}static fromBytes(m,x=!1){let v=o.BYTES,{a:B,d:L}=i;m=cr(K(m,v,"point")),St(x,"zip215");let _=cr(m),P=m[v-1];_[v-1]=P&-129;let R=Dt(_),I=x?c:o.ORDER;Oe("point.y",R,Qt,I);let U=f(R*R),M=f(U-tt),F=f(L*U-B),{isValid:h,value:g}=u(M,F);if(!h)throw new Error("bad point: invalid y coordinate");let E=(g&tt)===tt,w=(P&128)!==0;if(!x&&g===Qt&&w)throw new Error("bad point: x=0 and x_0=1");return w!==E&&(g=f(-g)),d.fromAffine({x:g,y:R})}static fromHex(m,x=!1){return d.fromBytes(Re(m),x)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,x=!0){return y.createCache(this,m),x||this.multiply(Oo),this}assertValidity(){let m=this,{a:x,d:v}=i;if(m.is0())throw new Error("bad point: ZERO");let{X:B,Y:L,Z:_,T:P}=m,R=f(B*B),I=f(L*L),U=f(_*_),M=f(U*U),F=f(R*x),h=f(U*f(F+I)),g=f(M+f(v*f(R*I)));if(h!==g)throw new Error("bad point: equation left != right (1)");let E=f(B*L),w=f(_*P);if(E!==w)throw new Error("bad point: equation left != right (2)")}equals(m){p(m);let{X:x,Y:v,Z:B}=this,{X:L,Y:_,Z:P}=m,R=f(x*P),I=f(L*B),U=f(v*P),M=f(_*B);return R===I&&U===M}is0(){return this.equals(d.ZERO)}negate(){return new d(f(-this.X),this.Y,this.Z,f(-this.T))}double(){let{a:m}=i,{X:x,Y:v,Z:B}=this,L=f(x*x),_=f(v*v),P=f(Oo*f(B*B)),R=f(m*L),I=x+v,U=f(f(I*I)-L-_),M=R+_,F=M-P,h=R-_,g=f(U*F),E=f(M*h),w=f(U*h),b=f(F*M);return new d(g,E,b,w)}add(m){p(m);let{a:x,d:v}=i,{X:B,Y:L,Z:_,T:P}=this,{X:R,Y:I,Z:U,T:M}=m,F=f(B*R),h=f(L*I),g=f(P*v*M),E=f(_*U),w=f((B+L)*(R+I)-F-h),b=E-g,A=E+g,C=f(h-x*F),T=f(w*b),D=f(A*C),O=f(w*C),k=f(b*A);return new d(T,D,k,O)}subtract(m){return p(m),this.add(m.negate())}multiply(m){if(!s.isValidNot0(m))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:x,f:v}=y.cached(this,m,B=>ye(d,B));return ye(d,[x,v])[0]}multiplyUnsafe(m){if(!s.isValid(m))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return m===Qt?d.ZERO:this.is0()||m===tt?this:y.unsafe(this,m,x=>ye(d,x))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return y.unsafe(this,i.n).is0()}toAffine(m){let x=this,v=m,{X:B,Y:L,Z:_}=x,P=x.is0();v==null&&(v=P?hu:o.inv(_));let R=f(B*v),I=f(L*v),U=o.mul(_,v);if(P)return{x:Qt,y:tt};if(U!==tt)throw new Error("invZ was invalid");return{x:R,y:I}}clearCofactor(){return a===tt?this:this.multiplyUnsafe(a)}toBytes(){let{x:m,y:x}=this.toAffine(),v=o.toBytes(x);return v[v.length-1]|=m&tt?128:0,v}toHex(){return Le(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=new Ne(d,s.BITS);return s.BITS>=8&&d.BASE.precompute(8),Object.freeze(d.prototype),Object.freeze(d),d}var Wr=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){Bo()}static fromHex(t){Bo()}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 Le(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,e){return this.ep.precompute(t,e),this}};function Gi(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=e;At(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=r,f=n.outputLen,u=2*a.BYTES;if(f!==void 0&&(vt(f,"hash.outputLen"),f!==u))throw new Error(`hash.outputLen must be ${u}, got ${f}`);let l=o.randomBytes===void 0?ir:o.randomBytes,p=o.adjustScalarBytes===void 0?h=>h:o.adjustScalarBytes,d=o.domain===void 0?(h,g,E)=>{if(St(E,"phflag"),g.length||E)throw new Error("Contexts/pre-hash are not supported");return h}:o.domain;function y(h){return c.create(Dt(h))}function S(h){let g=R.secretKey;K(h,R.secretKey,"secretKey");let E=K(n(h),2*g,"hashedSecretKey"),w=p(E.slice(0,g)),b=E.slice(g,2*g),A=y(w);return{head:w,prefix:b,scalar:A}}function m(h){let{head:g,prefix:E,scalar:w}=S(h),b=i.multiply(w),A=b.toBytes();return{head:g,prefix:E,scalar:w,point:b,pointBytes:A}}function x(h){return m(h).pointBytes}function v(h=Uint8Array.of(),...g){let E=W(...g);return y(n(d(E,K(h,void 0,"context"),!!s)))}function B(h,g,E={}){h=K(h,void 0,"message"),s&&(h=s(h));let{prefix:w,scalar:b,pointBytes:A}=m(g),C=v(E.context,w,h),T=i.multiply(C).toBytes(),D=v(E.context,T,A,h),O=c.create(C+D*b);if(!c.isValid(O))throw new Error("sign failed: invalid s");let k=W(T,c.toBytes(O));return K(k,R.signature,"result")}let L={zip215:o.zip215};function _(h,g,E,w=L){let{context:b}=w,A=w.zip215===void 0?!!L.zip215:w.zip215,C=R.signature;h=K(h,C,"signature"),g=K(g,void 0,"message"),E=K(E,R.publicKey,"publicKey"),A!==void 0&&St(A,"zip215"),s&&(g=s(g));let T=C/2,D=h.subarray(0,T),O=Dt(h.subarray(T,C)),k,V,N;try{k=r.fromBytes(E,A),V=r.fromBytes(D,A),N=i.multiplyUnsafe(O)}catch{return!1}if(!A&&k.isSmallOrder())return!1;let X=v(b,D,E,g);return V.add(k.multiplyUnsafe(X)).subtract(N).clearCofactor().is0()}let P=a.BYTES,R={secretKey:P,publicKey:P,signature:2*P,seed:P};function I(h){return h=h===void 0?l(R.seed):h,K(h,R.seed,"seed")}function U(h){return he(h)&&h.length===R.secretKey}function M(h,g){try{return!!r.fromBytes(h,g===void 0?L.zip215:g)}catch{return!1}}let F={getExtendedPublicKey:m,randomSecretKey:I,isValidSecretKey:U,isValidPublicKey:M,toMontgomery(h){let{y:g}=r.fromBytes(h),E=R.publicKey,w=E===32;if(!w&&E!==57)throw new Error("only defined for 25519 and 448");let b=w?a.div(tt+g,tt-g):a.div(g-tt,g+tt);return a.toBytes(b)},toMontgomerySecret(h){let g=R.secretKey;K(h,g);let E=n(h.subarray(0,g));return p(E).subarray(0,g)}};return Object.freeze(R),Object.freeze(F),Object.freeze({keygen:Xr(I,x),getPublicKey:x,sign:B,verify:_,utils:F,Point:r,lengths:R})}function hr(r,t){if(vt(r),vt(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(r<0||r>2**(8*t)-1)throw new Error("invalid I2OSP input: "+r);let e=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)e[n]=r&255,r>>>=8;return new Uint8Array(e)}function pu(r,t){let e=new Uint8Array(r.length);for(let n=0;n<r.length;n++)e[n]=r[n]^t[n];return e}function mu(r){if(!he(r)&&typeof r!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof r=="string"?Zr(r):r;if(t.length===0)throw new Error("DST must be non-empty");return t}function Po(r,t,e,n){K(r),vt(e),t=mu(t),t.length>255&&(t=n(W(Zr("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(e/o);if(e>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=W(t,hr(t.length,1)),c=new Uint8Array(s),f=hr(e,2),u=new Array(i),l=n(W(c,r,f,hr(0,1),a));u[0]=n(W(l,hr(1,1),a));for(let d=1;d<i;d++){let y=[pu(l,u[d-1]),hr(d+1,1),a];u[d]=n(W(...y))}return W(...u).slice(0,e)}var Xi="HashToScalar-";var yu=BigInt(0),Mt=BigInt(1),Wi=BigInt(2);var gu=BigInt(5),bu=BigInt(8),ke=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ko={p:ke,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:bu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function wu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=ke,a=r*r%s*r%s,c=H(a,Wi,s)*a%s,f=H(c,Mt,s)*r%s,u=H(f,gu,s)*f%s,l=H(u,t,s)*u%s,p=H(l,e,s)*l%s,d=H(p,n,s)*p%s,y=H(d,o,s)*d%s,S=H(y,o,s)*d%s,m=H(S,t,s)*u%s;return{pow_p_5_8:H(m,Wi,s)*r%s,b2:a}}function xu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Uo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Ko(r,t){let e=ke,n=Y(t*t*t,e),o=Y(n*n*t,e),s=wu(r*o).pow_p_5_8,i=Y(r*n*s,e),a=Y(t*i*i,e),c=i,f=Y(i*Uo,e),u=a===r,l=a===Y(-r,e),p=a===Y(-r*Uo,e);return u&&(i=c),(l||p)&&(i=f),Vt(i,e)&&(i=Y(-i,e)),{isValid:u||l,value:i}}var te=Yi(ko,{uvRatio:Ko}),Jt=te.Fp,ta=te.Fn;function Eu(r){return Gi(te,qr,Object.assign({adjustScalarBytes:xu,zip215:!0},r))}var ea=Eu({});var Fo=Uo,Su=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),vu=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Au=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Bu=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Qi=r=>Ko(Mt,r),Tu=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),No=r=>Jt.create(Dt(r)&Tu);function Ji(r){let{d:t}=ko,e=ke,n=x=>Jt.create(x),o=n(Fo*r*r),s=n((o+Mt)*Au),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:f}=Ko(s,a),u=n(f*r);Vt(u,e)||(u=n(-u)),c||(f=u),c||(i=o);let l=n(i*(o-Mt)*Bu-a),p=f*f,d=n((f+f)*a),y=n(l*Su),S=n(Mt-p),m=n(Mt+p);return new te(n(d*m),n(S*y),n(y*m),n(d*S))}var ee=class r extends Wr{static BASE=new r(te.BASE);static ZERO=new r(te.ZERO);static Fp=Jt;static Fn=ta;constructor(t){super(t)}static fromAffine(t){return new r(te.fromAffine(t))}assertSame(t){if(!(t instanceof r))throw new Error("RistrettoPoint expected")}init(t){return new r(t)}static fromBytes(t){yt(t,32);let{a:e,d:n}=ko,o=ke,s=L=>Jt.create(L),i=No(t);if(!_i(Jt.toBytes(i),t)||Vt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Mt+e*a),f=s(Mt-e*a),u=s(c*c),l=s(f*f),p=s(e*n*u-l),{isValid:d,value:y}=Qi(s(p*l)),S=s(y*f),m=s(y*S*p),x=s((i+i)*S);Vt(x,o)&&(x=s(-x));let v=s(c*m),B=s(x*v);if(!d||Vt(B,o)||v===yu)throw new Error("invalid ristretto255 encoding 2");return new r(new te(x,v,Mt,B))}static fromHex(t){return r.fromBytes(rr(t))}toBytes(){let{X:t,Y:e,Z:n,T:o}=this.ep,s=ke,i=m=>Jt.create(m),a=i(i(n+e)*i(n-e)),c=i(t*e),f=i(c*c),{value:u}=Qi(i(a*f)),l=i(u*a),p=i(u*c),d=i(l*p*o),y;if(Vt(o*d,s)){let m=i(e*Fo),x=i(t*Fo);t=m,e=x,y=i(l*vu)}else y=p;Vt(t*d,s)&&(e=i(-e));let S=i((n-e)*y);return Vt(S,s)&&(S=i(-S)),Jt.toBytes(S)}equals(t){this.assertSame(t);let{X:e,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=f=>Jt.create(f),a=i(e*s)===i(n*o),c=i(n*s)===i(e*o);return a||c}is0(){return this.equals(r.ZERO)}};Object.freeze(ee.BASE);Object.freeze(ee.ZERO);Object.freeze(ee.prototype);Object.freeze(ee);var Iu=Object.freeze({Point:ee,hashToCurve(r,t){let e=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=Po(r,e,64,qr);return Iu.deriveToCurve(n)},hashToScalar(r,t={DST:Xi}){let e=Po(r,t.DST,64,qr);return ta.create(Dt(e))},deriveToCurve(r){yt(r,64);let t=No(r.subarray(0,32)),e=Ji(t),n=No(r.subarray(32,64)),o=Ji(n);return new ee(e.add(o))}});var dr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Qr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ra={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Qr("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 Jr=ra;var tn=32;var Vo,Cu=(async()=>{try{return await Jr.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function _u(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await Jr.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Jr.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Du(r,t,e){return ea.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function na(r,t,e){return Vo==null&&(Vo=await Cu),Vo?_u(r,t,e):Du(r,t,e)}function en(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var rn=class{type="Ed25519";raw;constructor(t){this.raw=Mo(t,tn)}toMultihash(){return pt.digest(_e(this))}toCID(){return q.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Ie(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=na(this.raw,e,t);return en(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function sa(r){return r=Mo(r,tn),new rn(r)}function Mo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new bt(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Ru=Math.pow(2,7),Ou=Math.pow(2,14),Pu=Math.pow(2,21),ia=Math.pow(2,28),aa=Math.pow(2,35),ca=Math.pow(2,42),fa=Math.pow(2,49),ct=128,re=127;function pr(r){if(r<Ru)return 1;if(r<Ou)return 2;if(r<Pu)return 3;if(r<ia)return 4;if(r<aa)return 5;if(r<ca)return 6;if(r<fa)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ua(r,t,e=0){switch(pr(r)){case 8:t[e++]=r&255|ct,r/=128;case 7:t[e++]=r&255|ct,r/=128;case 6:t[e++]=r&255|ct,r/=128;case 5:t[e++]=r&255|ct,r/=128;case 4:t[e++]=r&255|ct,r>>>=7;case 3:t[e++]=r&255|ct,r>>>=7;case 2:t[e++]=r&255|ct,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function la(r,t){let e=r[t],n=0;if(n+=e&re,e<ct||(e=r[t+1],n+=(e&re)<<7,e<ct)||(e=r[t+2],n+=(e&re)<<14,e<ct)||(e=r[t+3],n+=(e&re)<<21,e<ct)||(e=r[t+4],n+=(e&re)*ia,e<ct)||(e=r[t+5],n+=(e&re)*aa,e<ct)||(e=r[t+6],n+=(e&re)*ca,e<ct)||(e=r[t+7],n+=(e&re)*fa,e<ct))return n;throw new RangeError("Could not decode varint")}var qo=new Float32Array([-0]),ne=new Uint8Array(qo.buffer);function ha(r,t,e){qo[0]=r,t[e]=ne[0],t[e+1]=ne[1],t[e+2]=ne[2],t[e+3]=ne[3]}function da(r,t){return ne[0]=r[t],ne[1]=r[t+1],ne[2]=r[t+2],ne[3]=r[t+3],qo[0]}var Ho=new Float64Array([-0]),st=new Uint8Array(Ho.buffer);function pa(r,t,e){Ho[0]=r,t[e]=st[0],t[e+1]=st[1],t[e+2]=st[2],t[e+3]=st[3],t[e+4]=st[4],t[e+5]=st[5],t[e+6]=st[6],t[e+7]=st[7]}function ma(r,t){return st[0]=r[t],st[1]=r[t+1],st[2]=r[t+2],st[3]=r[t+3],st[4]=r[t+4],st[5]=r[t+5],st[6]=r[t+6],st[7]=r[t+7],Ho[0]}var Uu=BigInt(Number.MAX_SAFE_INTEGER),Fu=BigInt(Number.MIN_SAFE_INTEGER),gt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ge;if(t<Uu&&t>Fu)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>ya&&(o=0n,++n>ya&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ge;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):ge}},ge=new gt(0,0);ge.toBigInt=function(){return 0n};ge.zzEncode=ge.zzDecode=function(){return this};ge.length=function(){return 1};var ya=4294967296n;function ga(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function ba(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function zo(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Bt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function nn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var jo=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,Bt(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 Bt(this,4);return nn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Bt(this,4);return nn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Bt(this,4);let t=da(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Bt(this,4);let t=ma(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Bt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return ba(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Bt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Bt(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 gt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Bt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Bt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Bt(this,8);let t=nn(this.buf,this.pos+=4),e=nn(this.buf,this.pos+=4);return new gt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=la(this.buf,this.pos);return this.pos+=pr(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 mr(r){return new jo(r instanceof Uint8Array?r:r.subarray())}function on(r,t,e){let n=mr(r);return t.decode(n,void 0,e)}function be(r=0){return new Uint8Array(r)}function Ea(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var xa=Ea("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),$o=Ea("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=be(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Nu={utf8:xa,"utf-8":xa,hex:dt.base16,latin1:$o,ascii:$o,binary:$o,...dt},Sa=Nu;function va(r,t="utf8"){let e=Sa[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function Zo(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return be(i);o+i>t&&(n=be(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var we=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Yo(){}var Xo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},ku=Zo();function Ku(r){return globalThis.Buffer!=null?be(r):ku(r)}var gr=class{len;head;tail;states;constructor(){this.len=0,this.head=new we(Yo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new we(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Wo((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(sn,10,gt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=gt.fromBigInt(t);return this._push(sn,e.length(),e)}uint64Number(t){return this._push(ua,pr(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=gt.fromBigInt(t).zzEncode();return this._push(sn,e.length(),e)}sint64Number(t){let e=gt.fromNumber(t).zzEncode();return this._push(sn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Go,1,t?1:0)}fixed32(t){return this._push(yr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=gt.fromBigInt(t);return this._push(yr,4,e.lo)._push(yr,4,e.hi)}fixed64Number(t){let e=gt.fromNumber(t);return this._push(yr,4,e.lo)._push(yr,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ha,4,t)}double(t){return this._push(pa,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Go,1,0):this.uint32(e)._push(Mu,e,t)}string(t){let e=ga(t);return e!==0?this.uint32(e)._push(zo,e,t):this._push(Go,1,0)}fork(){return this.states=new Xo(this),this.head=this.tail=new we(Yo,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(Yo,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Ku(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Go(r,t,e){t[e]=r&255}function Vu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Wo=class extends we{next;constructor(t,e){super(Vu,t,e),this.next=void 0}};function sn(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function yr(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Mu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(gr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(qu,t,r),this},gr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Hu,t,r),this});function qu(r,t,e){t.set(r,e)}function Hu(r,t,e){r.length<40?zo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(va(r),e)}function Qo(){return new gr}function an(r,t){let e=Qo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}function*cn(r,t,e){let n=mr(r);yield*t.stream(n,void 0,"$",e)}var fn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function un(r,t,e,n,o){return{name:r,type:t,encode:e,decode:n,stream:o}}function Jo(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return un("enum",fn.VARINT,e,n,o)}function ln(r,t,e){return un("message",fn.LENGTH_DELIMITED,r,t,e)}var ft;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(ft||(ft={}));var ts;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(ts||(ts={}));(function(r){r.codec=()=>Jo(ts)})(ft||(ft={}));var br;(function(r){let t;r.codec=()=>(t==null&&(t=ln((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ft.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{c.Type=ft.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:ft.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function e(s){return an(s,r.codec())}r.encode=e;function n(s,i){return on(s,r.codec(),i)}r.decode=n;function o(s,i){return cn(s,r.codec(),i)}r.stream=o})(br||(br={}));var es;(function(r){let t;r.codec=()=>(t==null&&(t=ln((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ft.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{c.Type=ft.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:ft.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function e(s){return an(s,r.codec())}r.encode=e;function n(s,i){return on(s,r.codec(),i)}r.decode=n;function o(s,i){return cn(s,r.codec(),i)}r.stream=o})(es||(es={}));var hn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,e){if(Nr(t),yt(e,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(e.length>n?t.create().update(e).digest():e);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),kt(o)}update(t){return De(this),this.iHash.update(t),this}digestInto(t){De(this),kr(t,this),this.finished=!0;let e=t.subarray(0,this.outputLen);this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),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:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Aa=(()=>{let r=((t,e,n)=>new hn(t,e).update(n).digest());return r.create=(t,e)=>new hn(t,e),r})();var Ba=(r,t)=>(r+(r>=0?t:-t)/Ta)/t;function ju(r,t,e){Oe("scalar",r,Lt,e);let[[n,o],[s,i]]=t,a=Ba(i*r,e),c=Ba(-o*r,e),f=r-a*n-c*s,u=-a*o-c*i,l=f<Lt,p=u<Lt;l&&(f=-f),p&&(u=-u);let d=fr(Math.ceil(Pe(e)/2))+oe;if(f<Lt||f>=d||u<Lt||u>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:f,k2neg:p,k2:u}}function ns(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function rs(r,t){At(r);let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return St(e.lowS,"lowS"),St(e.prehash,"prehash"),e.format!==void 0&&ns(e.format),e}var os=class extends Error{constructor(t=""){super(t)}},Tt={Err:os,_tlv:{encode:(r,t)=>{let{Err:e}=Tt;if(vt(r,"tag"),r<0||r>255)throw new e("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=ar(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?ar(o.length/2|128):"";return ar(r)+s+o+t},decode(r,t){let{Err:e}=Tt;t=K(t,void 0,"DER data");let n=0;if(r<0||r>255)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Tt;if(jr(r),r<Lt)throw new t("integer: negative integers are not allowed");let e=ar(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=Tt;if(r.length<1)throw new t("invalid signature integer: empty");if(r[0]&128)throw new t("invalid signature integer: negative");if(r.length>1&&r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return de(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Tt,o=K(r,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(f)}},hexFromSig(r){let{_tlv:t,_int:e}=Tt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}};Object.freeze(Tt._tlv);Object.freeze(Tt._int);Object.freeze(Tt);var Lt=BigInt(0),oe=BigInt(1),Ta=BigInt(2),dn=BigInt(3),$u=BigInt(4);function Ia(r,t={}){let e=Gr("weierstrass",r,t),n=e.Fp,o=e.Fn,s=e.CURVE,{h:i,n:a}=s;At(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:f}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=_a(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function p(F,h,g){if(f&&h.is0())return Uint8Array.of(0);let{x:E,y:w}=h.toAffine(),b=n.toBytes(E);if(St(g,"isCompressed"),g){l();let A=!n.isOdd(w);return W(Ca(A),b)}else return W(Uint8Array.of(4),b,n.toBytes(w))}function d(F){K(F,void 0,"Point");let{publicKey:h,publicKeyUncompressed:g}=u,E=F.length,w=F[0],b=F.subarray(1);if(f&&E===1&&w===0)return{x:n.ZERO,y:n.ZERO};if(E===h&&(w===2||w===3)){let A=n.fromBytes(b);if(!n.isValid(A))throw new Error("bad point: is not on curve, wrong x");let C=m(A),T;try{T=n.sqrt(C)}catch(k){let V=k instanceof Error?": "+k.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}l();let D=n.isOdd(T);return(w&1)===1!==D&&(T=n.neg(T)),{x:A,y:T}}else if(E===g&&w===4){let A=n.BYTES,C=n.fromBytes(b.subarray(0,A)),T=n.fromBytes(b.subarray(A,A*2));if(!x(C,T))throw new Error("bad point: is not on curve");return{x:C,y:T}}else throw new Error(`bad point: got length ${E}, expected compressed=${h} or uncompressed=${g}`)}let y=t.toBytes===void 0?p:t.toBytes,S=t.fromBytes===void 0?d:t.fromBytes;function m(F){let h=n.sqr(F),g=n.mul(h,F);return n.add(n.add(g,n.mul(F,s.a)),s.b)}function x(F,h){let g=n.sqr(h),E=m(F);return n.eql(g,E)}if(!x(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(s.a,dn),$u),B=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(v,B)))throw new Error("bad curve params: a or b");function L(F,h,g=!1){if(!n.isValid(h)||g&&n.is0(h))throw new Error(`bad point coordinate ${F}`);return h}function _(F){if(!(F instanceof I))throw new Error("Weierstrass Point expected")}function P(F){if(!c||!c.basises)throw new Error("no endo");return ju(F,c.basises,o.ORDER)}function R(F,h,g,E,w){return g=new I(n.mul(g.X,F),g.Y,g.Z),h=lr(E,h),g=lr(w,g),h.add(g)}class I{static BASE=new I(s.Gx,s.Gy,n.ONE);static ZERO=new I(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(h,g,E){this.X=L("x",h),this.Y=L("y",g,!0),this.Z=L("z",E),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){let{x:g,y:E}=h||{};if(!h||!n.isValid(g)||!n.isValid(E))throw new Error("invalid affine point");if(h instanceof I)throw new Error("projective point not allowed");return n.is0(g)&&n.is0(E)?I.ZERO:new I(g,E,n.ONE)}static fromBytes(h){let g=I.fromAffine(S(K(h,void 0,"point")));return g.assertValidity(),g}static fromHex(h){return I.fromBytes(Re(h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,g=!0){return M.createCache(this,h),g||this.multiply(dn),this}assertValidity(){let h=this;if(h.is0()){if(t.allowInfinityPoint&&n.is0(h.X)&&n.eql(h.Y,n.ONE)&&n.is0(h.Z))return;throw new Error("bad point: ZERO")}let{x:g,y:E}=h.toAffine();if(!n.isValid(g)||!n.isValid(E))throw new Error("bad point: x or y not field elements");if(!x(g,E))throw new Error("bad point: equation left != right");if(!h.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(h)}equals(h){_(h);let{X:g,Y:E,Z:w}=this,{X:b,Y:A,Z:C}=h,T=n.eql(n.mul(g,C),n.mul(b,w)),D=n.eql(n.mul(E,C),n.mul(A,w));return T&&D}negate(){return new I(this.X,n.neg(this.Y),this.Z)}double(){let{a:h,b:g}=s,E=n.mul(g,dn),{X:w,Y:b,Z:A}=this,C=n.ZERO,T=n.ZERO,D=n.ZERO,O=n.mul(w,w),k=n.mul(b,b),V=n.mul(A,A),N=n.mul(w,b);return N=n.add(N,N),D=n.mul(w,A),D=n.add(D,D),C=n.mul(h,D),T=n.mul(E,V),T=n.add(C,T),C=n.sub(k,T),T=n.add(k,T),T=n.mul(C,T),C=n.mul(N,C),D=n.mul(E,D),V=n.mul(h,V),N=n.sub(O,V),N=n.mul(h,N),N=n.add(N,D),D=n.add(O,O),O=n.add(D,O),O=n.add(O,V),O=n.mul(O,N),T=n.add(T,O),V=n.mul(b,A),V=n.add(V,V),O=n.mul(V,N),C=n.sub(C,O),D=n.mul(V,k),D=n.add(D,D),D=n.add(D,D),new I(C,T,D)}add(h){_(h);let{X:g,Y:E,Z:w}=this,{X:b,Y:A,Z:C}=h,T=n.ZERO,D=n.ZERO,O=n.ZERO,k=s.a,V=n.mul(s.b,dn),N=n.mul(g,b),X=n.mul(E,A),Q=n.mul(w,C),J=n.add(g,E),Z=n.add(b,A);J=n.mul(J,Z),Z=n.add(N,X),J=n.sub(J,Z),Z=n.add(g,w);let lt=n.add(b,C);return Z=n.mul(Z,lt),lt=n.add(N,Q),Z=n.sub(Z,lt),lt=n.add(E,w),T=n.add(A,C),lt=n.mul(lt,T),T=n.add(X,Q),lt=n.sub(lt,T),O=n.mul(k,Z),T=n.mul(V,Q),O=n.add(T,O),T=n.sub(X,O),O=n.add(X,O),D=n.mul(T,O),X=n.add(N,N),X=n.add(X,N),Q=n.mul(k,Q),Z=n.mul(V,Z),X=n.add(X,Q),Q=n.sub(N,Q),Q=n.mul(k,Q),Z=n.add(Z,Q),N=n.mul(X,Z),D=n.add(D,N),N=n.mul(lt,Z),T=n.mul(J,T),T=n.sub(T,N),N=n.mul(J,X),O=n.mul(lt,O),O=n.add(O,N),new I(T,D,O)}subtract(h){return _(h),this.add(h.negate())}is0(){return this.equals(I.ZERO)}multiply(h){let{endo:g}=t;if(!o.isValidNot0(h))throw new RangeError("invalid scalar: out of range");let E,w,b=A=>M.cached(this,A,C=>ye(I,C));if(g){let{k1neg:A,k1:C,k2neg:T,k2:D}=P(h),{p:O,f:k}=b(C),{p:V,f:N}=b(D);w=k.add(N),E=R(g.beta,O,V,A,T)}else{let{p:A,f:C}=b(h);E=A,w=C}return ye(I,[E,w])[0]}multiplyUnsafe(h){let{endo:g}=t,E=this,w=h;if(!o.isValid(w))throw new RangeError("invalid scalar: out of range");if(w===Lt||E.is0())return I.ZERO;if(w===oe)return E;if(M.hasCache(this))return this.multiply(w);if(g){let{k1neg:b,k1:A,k2neg:C,k2:T}=P(w),{p1:D,p2:O}=Zi(I,E,A,T);return R(g.beta,D,O,b,C)}else return M.unsafe(E,w)}toAffine(h){let g=this,E=h,{X:w,Y:b,Z:A}=g;if(n.eql(A,n.ONE))return{x:w,y:b};let C=g.is0();E==null&&(E=C?n.ONE:n.inv(A));let T=n.mul(w,E),D=n.mul(b,E),O=n.mul(A,E);if(C)return{x:n.ZERO,y:n.ZERO};if(!n.eql(O,n.ONE))throw new Error("invZ was invalid");return{x:T,y:D}}isTorsionFree(){let{isTorsionFree:h}=t;return i===oe?!0:h?h(I,this):M.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:h}=t;return i===oe?this:h?h(I,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===oe?this.is0():this.clearCofactor().is0()}toBytes(h=!0){return St(h,"isCompressed"),this.assertValidity(),y(I,this,h)}toHex(h=!0){return Le(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let U=o.BITS,M=new Ne(I,t.endo?Math.ceil(U/2):U);return U>=8&&I.BASE.precompute(8),Object.freeze(I.prototype),Object.freeze(I),I}function Ca(r){return Uint8Array.of(r?2:3)}function _a(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Zu(r,t={}){let{Fn:e}=r,n=t.randomBytes===void 0?ir:t.randomBytes,o=Object.assign(_a(r.Fp,e),{seed:Math.max(Co(e.ORDER),16)});function s(d){try{let y=e.fromBytes(d);return e.isValidNot0(y)}catch{return!1}}function i(d,y){let{publicKey:S,publicKeyUncompressed:m}=o;try{let x=d.length;return y===!0&&x!==S||y===!1&&x!==m?!1:!!r.fromBytes(d)}catch{return!1}}function a(d){return d=d===void 0?n(o.seed):d,_o(K(d,o.seed,"seed"),e.ORDER)}function c(d,y=!0){return r.BASE.multiply(e.fromBytes(d)).toBytes(y)}function f(d){let{secretKey:y,publicKey:S,publicKeyUncompressed:m}=o,x=e._lengths;if(!he(d))return;let v=K(d,void 0,"key").length,B=v===S||v===m,L=v===y||!!x?.includes(v);if(!(B&&L))return B}function u(d,y,S=!0){if(f(d)===!0)throw new Error("first arg must be private key");if(f(y)===!1)throw new Error("second arg must be public key");let m=e.fromBytes(d);return r.fromBytes(y).multiply(m).toBytes(S)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},p=Xr(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:p,Point:r,utils:l,lengths:o})}function Da(r,t,e={}){let n=t;Nr(n),At(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let o=e.randomBytes===void 0?ir:e.randomBytes,s=e.hmac===void 0?(w,b)=>Aa(n,w,b):e.hmac,{Fp:i,Fn:a}=r,{ORDER:c,BITS:f}=a,{keygen:u,getPublicKey:l,getSharedSecret:p,utils:d,lengths:y}=Zu(r,e),S={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},m=c*Ta+oe<i.ORDER;function x(w){let b=c>>oe;return w>b}function v(w,b){if(!a.isValidNot0(b))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return b}function B(){if(m)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function L(w,b){ns(b);let A=y.signature,C=b==="compact"?A:b==="recovered"?A+1:void 0;return K(w,C)}class _{r;s;recovery;constructor(b,A,C){if(this.r=v("r",b),this.s=v("s",A),C!=null){if(B(),![0,1,2,3].includes(C))throw new Error("invalid recovery id");this.recovery=C}Object.freeze(this)}static fromBytes(b,A=S.format){L(b,A);let C;if(A==="der"){let{r:k,s:V}=Tt.toSig(K(b));return new _(k,V)}A==="recovered"&&(C=b[0],A="compact",b=b.subarray(1));let T=y.signature/2,D=b.subarray(0,T),O=b.subarray(T,T*2);return new _(a.fromBytes(D),a.fromBytes(O),C)}static fromHex(b,A){return this.fromBytes(Re(b),A)}assertRecovery(){let{recovery:b}=this;if(b==null)throw new Error("invalid recovery id: must be present");return b}addRecoveryBit(b){return new _(this.r,this.s,b)}recoverPublicKey(b){let{r:A,s:C}=this,T=this.assertRecovery(),D=T===2||T===3?A+c:A;if(!i.isValid(D))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let O=i.toBytes(D),k=r.fromBytes(W(Ca((T&1)===0),O)),V=a.inv(D),N=R(K(b,void 0,"msgHash")),X=a.create(-N*V),Q=a.create(C*V),J=r.BASE.multiplyUnsafe(X).add(k.multiplyUnsafe(Q));if(J.is0())throw new Error("invalid recovery: point at infinify");return J.assertValidity(),J}hasHighS(){return x(this.s)}toBytes(b=S.format){if(ns(b),b==="der")return Re(Tt.hexFromSig(this));let{r:A,s:C}=this,T=a.toBytes(A),D=a.toBytes(C);return b==="recovered"?(B(),W(Uint8Array.of(this.assertRecovery()),T,D)):W(T,D)}toHex(b){return Le(this.toBytes(b))}}Object.freeze(_.prototype),Object.freeze(_);let P=e.bits2int===void 0?function(b){if(b.length>8192)throw new Error("input is too large");let A=de(b),C=b.length*8-f;return C>0?A>>BigInt(C):A}:e.bits2int,R=e.bits2int_modN===void 0?function(b){return a.create(P(b))}:e.bits2int_modN,I=fr(f);function U(w){return Oe("num < 2^"+f,w,Lt,I),a.toBytes(w)}function M(w,b){return K(w,void 0,"message"),b?K(n(w),void 0,"prehashed message"):w}function F(w,b,A){let{lowS:C,prehash:T,extraEntropy:D}=rs(A,S);w=M(w,T);let O=R(w),k=a.fromBytes(b);if(!a.isValidNot0(k))throw new Error("invalid private key");let V=[U(k),U(O)];if(D!=null&&D!==!1){let J=D===!0?o(y.secretKey):D;V.push(K(J,void 0,"extraEntropy"))}let N=W(...V),X=O;function Q(J){let Z=P(J);if(!a.isValidNot0(Z))return;let lt=a.inv(Z),ve=r.BASE.multiply(Z).toAffine(),$e=a.create(ve.x);if($e===Lt)return;let Ir=a.create(lt*a.create(X+$e*k));if(Ir===Lt)return;let Ds=(ve.x===$e?0:2)|Number(ve.y&oe),Ls=Ir;return C&&x(Ir)&&(Ls=a.neg(Ir),Ds^=1),new _($e,Ls,m?void 0:Ds)}return{seed:N,k2sig:Q}}function h(w,b,A={}){let{seed:C,k2sig:T}=F(w,b,A);return Di(n.outputLen,a.BYTES,s)(C,T).toBytes(A.format)}function g(w,b,A,C={}){let{lowS:T,prehash:D,format:O}=rs(C,S);if(A=K(A,void 0,"publicKey"),b=M(b,D),!he(w)){let k=w instanceof _?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+k)}L(w,O);try{let k=_.fromBytes(w,O),V=r.fromBytes(A);if(T&&k.hasHighS())return!1;let{r:N,s:X}=k,Q=R(b),J=a.inv(X),Z=a.create(Q*J),lt=a.create(N*J),ve=r.BASE.multiplyUnsafe(Z).add(V.multiplyUnsafe(lt));return ve.is0()?!1:a.create(ve.x)===N}catch{return!1}}function E(w,b,A={}){let{prehash:C}=rs(A,S);return b=M(b,C),_.fromBytes(w,"recovered").recoverPublicKey(b).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:p,utils:d,lengths:y,Point:r,sign:h,verify:g,recoverPublicKey:E,Signature:_,hash:n})}var is={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Yu={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var La=BigInt(2);function Gu(r){let t=is.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,u=f*f*r%t,l=H(u,e,t)*u%t,p=H(l,e,t)*u%t,d=H(p,La,t)*f%t,y=H(d,o,t)*d%t,S=H(y,s,t)*y%t,m=H(S,a,t)*S%t,x=H(m,c,t)*m%t,v=H(x,a,t)*S%t,B=H(v,e,t)*u%t,L=H(B,i,t)*y%t,_=H(L,n,t)*f%t,P=H(_,La,t);if(!ss.eql(ss.sqr(P),r))throw new Error("Cannot find square root");return P}var ss=Ue(is.p,{sqrt:Gu}),Xu=Ia(is,{Fp:ss,endo:Yu}),Ke=Da(Xu,Ii);function Ra(r,t,e,n){let o=Je.digest(e instanceof Uint8Array?e:e.subarray());if(en(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ke.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new dr(String(s))});try{return n?.signal?.throwIfAborted(),Ke.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new dr(String(s))}}var pn=class{type="secp256k1";raw;_key;constructor(t){this._key=Pa(t),this.raw=Oa(this._key)}toMultihash(){return pt.digest(_e(this))}toCID(){return q.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Ie(this.raw,t.raw)}verify(t,e,n){return Ra(this._key,e,t,n)}};function Ua(r){return new pn(r)}function Oa(r){return Ke.Point.fromBytes(r).toBytes()}function Pa(r){try{return Ke.Point.fromBytes(r),r}catch(t){throw new _r(String(t))}}function Fa(r){let{Type:t,Data:e}=br.decode(r.digest),n=e??new Uint8Array;switch(t){case ft.Ed25519:return sa(n);case ft.secp256k1:return Ua(n);case ft.ECDSA:return ui(n);default:throw new Ze}}function _e(r){return br.encode({Type:ft[r.type],Data:r.raw})}function Na(r=0){return new Uint8Array(r)}function Ka(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var ka=Ka("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),as=Ka("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=Na(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Wu={utf8:ka,"utf-8":ka,hex:dt.base16,latin1:as,ascii:as,binary:as,...dt},mn=Wu;function wr(r,t="utf8"){let e=mn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}function cs(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Va(r,t="utf8"){let e=mn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}var Ma=Symbol.for("nodejs.util.inspect.custom"),Qu=114,xr=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()})`}[On]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return q.createV1(Qu,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return cs(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return cs(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ma](){return`PeerId(${this.toString()})`}},yn=class extends xr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},gn=class extends xr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},bn=class extends xr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Ju=2336,Er=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=pt.digest(Va(this.url))}[Ma](){return`PeerId(${this.url})`}[On]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return q.createV1(Ju,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=wr(t)),t.toString()===this.toString())}};var tl=114,qa=2336;function Ha(r,t){let e;if(r.charAt(0)==="1"||r.charAt(0)==="Q")e=Ut(G.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return el(q.parse(r));if(t==null)throw new bt('Please pass a multibase decoder for strings that do not start with "1" or "Q"');e=Ut(t.decode(r))}return za(e)}function za(r){if(nl(r))return new yn({multihash:r});if(rl(r))try{let t=Fa(r);if(t.type==="Ed25519")return new gn({multihash:r,publicKey:t});if(t.type==="secp256k1")return new bn({multihash:r,publicKey:t})}catch{let e=wr(r.digest);return new Er(new URL(e))}throw new Lr("Supplied PeerID Multihash is invalid")}function el(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==tl&&r.code!==qa)throw new Dr("Supplied PeerID CID is invalid");if(r.code===qa){let t=wr(r.multihash.digest);return new Er(new URL(t))}return za(r.multihash)}function rl(r){return r.code===pt.code}function nl(r){return r.code===Je.code}function xe(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Rt(r=0){return new Uint8Array(r)}function Ot(r=0){return new Uint8Array(r)}var ol=Math.pow(2,7),sl=Math.pow(2,14),il=Math.pow(2,21),fs=Math.pow(2,28),us=Math.pow(2,35),ls=Math.pow(2,42),hs=Math.pow(2,49),z=128,it=127;function Ve(r){if(r<ol)return 1;if(r<sl)return 2;if(r<il)return 3;if(r<fs)return 4;if(r<us)return 5;if(r<ls)return 6;if(r<hs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ds(r,t,e=0){switch(Ve(r)){case 8:t[e++]=r&255|z,r/=128;case 7:t[e++]=r&255|z,r/=128;case 6:t[e++]=r&255|z,r/=128;case 5:t[e++]=r&255|z,r/=128;case 4:t[e++]=r&255|z,r>>>=7;case 3:t[e++]=r&255|z,r>>>=7;case 2:t[e++]=r&255|z,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function al(r,t){let e=r[t],n=0;if(n+=e&it,e<z||(e=r[t+1],n+=(e&it)<<7,e<z)||(e=r[t+2],n+=(e&it)<<14,e<z)||(e=r[t+3],n+=(e&it)<<21,e<z)||(e=r[t+4],n+=(e&it)*fs,e<z)||(e=r[t+5],n+=(e&it)*us,e<z)||(e=r[t+6],n+=(e&it)*ls,e<z)||(e=r[t+7],n+=(e&it)*hs,e<z))return n;throw new RangeError("Could not decode varint")}function cl(r,t){let e=r.get(t),n=0;if(n+=e&it,e<z||(e=r.get(t+1),n+=(e&it)<<7,e<z)||(e=r.get(t+2),n+=(e&it)<<14,e<z)||(e=r.get(t+3),n+=(e&it)<<21,e<z)||(e=r.get(t+4),n+=(e&it)*fs,e<z)||(e=r.get(t+5),n+=(e&it)*us,e<z)||(e=r.get(t+6),n+=(e&it)*ls,e<z)||(e=r.get(t+7),n+=(e&it)*hs,e<z))return n;throw new RangeError("Could not decode varint")}function ps(r,t=0){return r instanceof Uint8Array?al(r,t):cl(r,t)}function ul(r){return r.buffer instanceof ArrayBuffer}function Sr(r){return ul(r)?r:r.slice()}function ll(r){return r?.buffer instanceof ArrayBuffer}function ms(r){if(ll(r))return r;let t=r.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function qt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=Ot(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return ms(e)}function $a(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var ja=$a("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ys=$a("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=Ot(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),hl={utf8:ja,"utf-8":ja,hex:dt.base16,latin1:ys,ascii:ys,binary:ys,...dt},wn=hl;function se(r,t="utf8"){let e=wn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function ie(r,t="utf8"){let e=wn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var ot=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Ht=class extends Error{static name="ValidationError";name="ValidationError"},xn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},En=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Sn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let p=Number.parseInt(l,t);if(!Number.isNaN(p))return p});if(u===void 0)break;if(s*=t,s+=u,s>f||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var dl=45,pl=15,vn=new Sn;function Za(r){if(!(r.length>pl))return vn.new(r).parseWith(()=>vn.readIPv4Addr())}function Ya(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>dl))return vn.new(r).parseWith(()=>vn.readIPv6Addr())}function An(r){return!!Za(r)}function Ga(r){return!!Ya(r)}function bs(r){return t=>ie(t,r)}function ws(r){return t=>se(t,r)}function Me(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function Ee(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function Xa(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=se(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=Ee(n);return qt([e,o],e.length+o.length)}function Wa(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=$t.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=Ee(n);return qt([e,o],e.length+o.length)}function xs(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=ie(t,"base32"),o=Me(e);return`${n}:${o}`}var Es=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new ot("Invalid byte value in IP address");t[n]=o}),t},Qa=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=An(e[n]),i;s&&(i=Es(e[n]),e[n]=ie(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,ie(i.subarray(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new ot("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Ja=function(r){if(r.byteLength!==4)throw new ot("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},tc=function(r){if(r.byteLength!==16)throw new ot("IPv6 address was incorrect length");let t=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ot(`Invalid IPv6 address "${e}"`)}};function ec(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ot(`Invalid IPv6 address "${r}"`)}}var gs=Object.values(dt).map(r=>r.decoder),ml=(function(){let r=gs[0].or(gs[1]);return gs.slice(2).forEach(t=>r=r.or(t)),r})();function rc(r){return ml.decode(r)}function nc(r){return t=>r.encoder.encode(t)}function yl(r){if(parseInt(r).toString()!==r)throw new Ht("Value must be an integer")}function gl(r){if(r<0)throw new Ht("Value must be a positive integer, or zero")}function bl(r){return t=>{if(t>r)throw new Ht(`Value must be smaller than or equal to ${r}`)}}function wl(...r){return t=>{for(let e of r)e(t)}}var vr=wl(yl,gl,bl(65535));var et=-1,Ss=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new En(`Protocol ${t} was unknown`);return e}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(e=>{this.protocolsByName.set(e,t)})}removeProtocol(t){let e=this.protocolsByCode.get(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},zt=new Ss,ih=[{code:4,name:"ip4",size:32,valueToBytes:Es,bytesToValue:Ja,validate:r=>{if(!An(r))throw new Ht(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ee,bytesToValue:Me,validate:vr},{code:273,name:"udp",size:16,valueToBytes:Ee,bytesToValue:Me,validate:vr},{code:33,name:"dccp",size:16,valueToBytes:Ee,bytesToValue:Me,validate:vr},{code:41,name:"ip6",size:128,valueToBytes:Qa,bytesToValue:tc,stringToValue:ec,validate:r=>{if(!Ga(r))throw new Ht(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:et},{code:43,name:"ipcidr",size:8,bytesToValue:bs("base10"),valueToBytes:ws("base10")},{code:53,name:"dns",size:et},{code:54,name:"dns4",size:et},{code:55,name:"dns6",size:et},{code:56,name:"dnsaddr",size:et},{code:132,name:"sctp",size:16,valueToBytes:Ee,bytesToValue:Me,validate:vr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:et,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:et,bytesToValue:bs("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?ws("base58btc")(r):q.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:xs,valueToBytes:Xa},{code:445,name:"onion3",size:296,bytesToValue:xs,valueToBytes:Wa},{code:446,name:"garlic64",size:et},{code:447,name:"garlic32",size:et},{code:448,name:"tls"},{code:449,name:"sni",size:et},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:et,bytesToValue:nc(Xn),valueToBytes:rc},{code:480,name:"http"},{code:481,name:"http-path",size:et,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.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:et}];ih.forEach(r=>{zt.addProtocol(r)});function oc(r){let t=[],e=0;for(;e<r.length;){let n=ps(r,e),o=zt.getProtocol(n),s=Ve(n),i=ah(o,r,e+s),a=0;i>0&&o.size===et&&(a=Ve(i));let c=s+a+i,f={code:n,name:o.name,bytes:Sr(r.subarray(e,e+c))};if(i>0){let u=e+s+a,l=r.subarray(u,u+i);f.value=o.bytesToValue?.(l)??ie(l)}t.push(f),e+=c}return t}function sc(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=zt.getProtocol(n.code),s=Ve(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??se(n.value),a=i.byteLength,o.size===et&&(c=Ve(a)));let f=new Uint8Array(s+c+a),u=0;ds(n.code,f,u),u+=s,i!=null&&(o.size===et&&(ds(a,f,u),u+=c),f.set(i,u)),n.bytes=f}e.push(n.bytes),t+=n.bytes.byteLength}return qt(e,t)}function ic(r){if(r.charAt(0)!=="/")throw new ot('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=zt.getProtocol(o);if(e==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",e="protocol";continue}else if(a)throw new ot(`Component ${o} was missing value`);e="value"}else if(e==="value"){let f={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ot(`Component ${o} was missing value`);f.value=c.stringToValue?.(n)??n}t.push(f),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new ot("Incomplete multiaddr");return t}function ac(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=zt.getProtocol(t.code);if(e==null)throw new ot(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function ah(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:ps(t,e)}var ch=Symbol.for("nodejs.util.inspect.custom"),vs=Symbol.for("@multiformats/multiaddr");function fh(r){if(r==null&&(r="/"),cc(r))return r.getComponents();if(r instanceof Uint8Array)return oc(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),ic(r);if(Array.isArray(r))return r;throw new ot("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Bn=class r{[vs]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=fh(t),e.validate!==!1&&uh(this)}get bytes(){return this.#r==null&&(this.#r=sc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=ac(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new xn(`Address ${this.toString()} does not contain subaddress: ${e}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}equals(t){return xe(this.bytes,t.bytes)}[ch](){return`Multiaddr(${this.toString()})`}};function uh(r){r.getComponents().forEach(t=>{let e=zt.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function cc(r){return!!r?.[vs]}function fc(r){return new Bn(r)}function qe(r){let t=new globalThis.AbortController;function e(){let s=r.filter(i=>i?.aborted===!0).map(i=>i?.reason).pop();t.abort(s);for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",e)}for(let s of r){if(s?.aborted===!0){e();break}s?.addEventListener!=null&&s.addEventListener("abort",e)}function n(){for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",e)}let o=t.signal;return o.clear=n,o}async function*Ar(r,t={}){let e=r.getReader();try{for(;;){let n=await e.read();if(n.done)return;yield n.value}}finally{t.preventCancel!==!0&&await e.cancel(),e.releaseLock()}}var hc=Symbol.for("@achingbrain/uint8arraylist");function uc(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function He(r){return!!r?.[hc]}var lc=class r{bufs;length;[hc]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(He(n)){e+=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+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(He(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=uc(this.bufs,t);return e.buf[e.index]}set(t,e){let n=uc(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(He(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return qt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:qt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=n,s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,u=e>a&&e<=c;if(f&&u){if(t===a&&e===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!He(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=e;l<=c;l+=u){u=0;for(let p=f;p>=0;p--){let d=this.get(l+p);if(n[p]!==d){u=Math.max(1,p-a[d]);break}}if(u===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=Ot(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=Rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=Rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=Rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=Ot(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=Rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=Rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=Rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=Rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=Rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!xe(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Tn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MESSAGE_LENGTH"};async function*ze(r,t={}){let e=/\r?\n/,n=new TextDecoder("utf8"),o="";for await(let s of r){if(typeof s=="string"&&(s=new TextEncoder().encode(s)),He(s)&&(s=s.subarray()),o+=n.decode(s,{stream:!0}),o.length>(t?.maxMessageLength??o.length))throw new Tn("Incoming message too long");let i=o.split(e);o=i.pop()??"";for(let a=0;a<i.length;a++)yield JSON.parse(i[a])}o+=n.decode(),o!==""&&(yield JSON.parse(o))}function wt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Bs=Tc(pc(),1);var Ts=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},mc=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Is(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,u=new Promise((l,p)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(i?.aborted){p(mc(i));return}if(i&&(c=()=>{p(mc(i))},i.addEventListener("abort",c,{once:!0})),r.then(l,p),e===Number.POSITIVE_INFINITY)return;let d=new Ts;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(y){p(y)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?l():o instanceof Error?p(o):(d.message=o??`Promise timed out after ${e} milliseconds`,p(d))},e)}).finally(()=>{u.clear(),c&&i&&i.removeEventListener("abort",c)});return u.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},u}function Cs(r,t,e){let n=0,o=r.length;for(;o>0;){let s=Math.trunc(o/2),i=n+s;e(r[i],t)<=0?(n=++i,o-=s+1):o=s}return n}var dh=100,je=class{#t=[];#e=0;enqueue(t,e){let{priority:n=0,id:o}=e??{},{size:s}=this,i={priority:n,id:o,run:t};if(s===0){this.#t.length=0,this.#e=0,this.#t.push(i);return}if(this.#t.at(-1).priority>=n){this.#t.push(i);return}this.#r();let a=Cs(this.#t,i,(c,f)=>f.priority-c.priority);this.#t.splice(a,0,i)}setPriority(t,e){let n=this.#t.findIndex((s,i)=>i>=this.#e&&s.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:e,id:t})}remove(t){let e=this.#t.findIndex((n,o)=>o<this.#e?!1:typeof t=="string"?n.id===t:n.run===t);e!==-1&&this.#t.splice(e,1)}dequeue(){if(this.#e===this.#t.length)return;let t=this.#t[this.#e];return this.#e++,this.#e===this.#t.length?(this.#t.length=0,this.#e=0):this.#e>dh&&this.#e>this.#t.length/2&&this.#r(),t?.run}filter(t){let e=[];for(let n=this.#e;n<this.#t.length;n++){let o=this.#t[n];o.priority===t.priority&&e.push(o.run)}return e}get size(){return this.#t.length-this.#e}#r(){this.#e!==0&&(this.#t.splice(0,this.#e),this.#e=0)}};var Tr=class extends Bs.default{#t;#e;#r=0;#d;#m=!1;#w=!1;#c;#I=0;#x=0;#f;#u;#a;#i=[];#s=0;#n;#C;#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:je,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.#e=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#c=t.interval,this.#a=t.strict,this.#n=new t.queueClass,this.#C=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.#s<this.#i.length;){let n=this.#i[this.#s];if(n!==void 0&&t-n>=this.#c)this.#s++;else break}(this.#s>100&&this.#s>this.#i.length/2||this.#s===this.#i.length)&&(this.#i=this.#i.slice(this.#s),this.#s=0)}#P(t){this.#a?this.#i.push(t):this.#r++}#U(){this.#a?this.#i.length>this.#s&&this.#i.pop():this.#r>0&&this.#r--}#v(){return this.#i.length-this.#s}get#F(){return this.#e?!0:this.#a?this.#v()<this.#d:this.#r<this.#d}get#N(){return this.#o<this.#y}#k(){this.#o--,this.#o===0&&this.emit("pendingZero"),this.#b(),this.emit("next")}#K(){this.#u=void 0,this.#L(),this.#D()}#V(t){if(this.#a){if(this.#S(t),this.#v()>=this.#d){let n=this.#i[this.#s],o=this.#c-(t-n);return this.#A(o),!0}return!1}if(this.#f===void 0){let e=this.#I-t;if(e<0){if(this.#x>0){let n=t-this.#x;if(n<this.#c)return this.#A(this.#c-n),!0}this.#r=this.#t?this.#o:0}else return this.#A(e),!0}return!1}#A(t){this.#u===void 0&&(this.#u=setTimeout(()=>{this.#K()},t))}#B(){this.#f&&(clearInterval(this.#f),this.#f=void 0)}#_(){this.#u&&(clearTimeout(this.#u),this.#u=void 0)}#b(){if(this.#n.size===0){if(this.#B(),this.emit("empty"),this.#o===0){if(this.#_(),this.#a&&this.#s>0){let e=Date.now();this.#S(e)}this.emit("idle")}return!1}let t=!1;if(!this.#l){let e=Date.now(),n=!this.#V(e);if(this.#F&&this.#N){let o=this.#n.dequeue();this.#e||(this.#P(e),this.#p()),this.emit("active"),o(),n&&this.#D(),t=!0}}return t}#D(){this.#e||this.#f!==void 0||this.#a||(this.#f=setInterval(()=>{this.#L()},this.#c),this.#I=Date.now()+this.#c)}#L(){this.#a||(this.#r===0&&this.#o===0&&this.#f&&this.#B(),this.#r=this.#t?this.#o:0),this.#T(),this.#p()}#T(){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.#T()}setPriority(t,e){if(typeof e!="number"||!Number.isFinite(e))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${e}\` (${typeof e})`);this.#n.setPriority(t,e)}async add(t,e={}){return e={timeout:this.timeout,...e,id:e.id??(this.#O++).toString()},new Promise((n,o)=>{let s=Symbol(`task-${e.id}`),i=()=>{},a=async()=>{i(),this.#o++,this.#g.set(s,{id:e.id,priority:e.priority??0,startTime:Date.now(),timeout:e.timeout});let f;try{try{e.signal?.throwIfAborted()}catch(p){throw this.#q(),this.#g.delete(s),p}this.#x=Date.now();let u=t({signal:e.signal});if(e.timeout&&(u=Is(Promise.resolve(u),{milliseconds:e.timeout,message:`Task timed out after ${e.timeout}ms (queue has ${this.#o} running, ${this.#n.size} waiting)`})),e.signal){let{signal:p}=e;u=Promise.race([u,new Promise((d,y)=>{f=()=>{y(p.reason)},p.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&&e.signal?.removeEventListener("abort",f),this.#g.delete(s),queueMicrotask(()=>{this.#k()})}};this.#n.enqueue(a,e);let c=()=>{if(this.#n instanceof je){this.#n.remove(a);return}this.#n.remove?.(e.id)};if(e.signal){let{signal:f}=e,u=()=>{i(),c(),o(f.reason),this.#b(),this.emit("next")};if(i=()=>{f.removeEventListener("abort",u),this.#E.delete(i)},f.aborted){u();return}f.addEventListener("abort",u,{once:!0}),this.#E.add(i)}this.emit("add"),this.#b()})}async addAll(t,e){return Promise.all(t.map(async n=>this.add(n,e)))}start(){return this.#l?(this.#l=!1,this.#T(),this):this}pause(){this.#l=!0}clear(){for(let t of this.#E)t();this.#n=new this.#C,this.#B(),this.#R(),this.emit("empty"),this.#o===0&&(this.#_(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#n.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#n.size<t||await this.#h("next",()=>this.#n.size<t)}async onIdle(){this.#o===0&&this.#n.size===0||await this.#h("idle")}async onPendingZero(){this.#o!==0&&await this.#h("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#h("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#h("rateLimitCleared")}onError(){return new Promise((t,e)=>{let n=o=>{this.off("error",n),e(o)};this.on("error",n)})}async#h(t,e){return new Promise(n=>{let o=()=>{e&&!e()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#n.size}sizeBy(t){return this.#n.filter(t).length}get pending(){return this.#o}get isPaused(){return this.#l}#M(){this.#e||(this.on("add",()=>{this.#n.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#e||this.#w||(this.#w=!0,queueMicrotask(()=>{this.#w=!1,this.#R()}))}#q(){this.#e||(this.#U(),this.#p())}#R(){let t=this.#m;if(this.#e||this.#n.size===0){t&&(this.#m=!1,this.emit("rateLimitCleared"));return}let e;if(this.#a){let o=Date.now();this.#S(o),e=this.#v()}else e=this.#r;let n=e>=this.#d;n!==t&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#o===this.#y&&this.#n.size>0||this.isRateLimited&&this.#n.size>0}get runningTasks(){return[...this.#g.values()].map(t=>({...t,timeoutRemaining:t.timeout?Math.max(0,t.startTime+t.timeout-Date.now()):void 0}))}};var Se=class extends Error{static name="InvalidRequestError";constructor(t="Invalid request"){super(t),this.name="InvalidRequestError"}},xt=class extends Error{static name="BadResponseError";constructor(t="Bad response"){super(t),this.name="BadResponseError"}};var Cn={concurrentRequests:4,timeout:3e4,cacheTTL:300*1e3,cacheName:"delegated-routing-v1-cache"},_n=class{url;started;httpQueue;shutDownController;timeout;filterAddrs;filterProtocols;inFlightRequests;cacheName;cache;cacheTTL;log;constructor(t,e){this.log=t.logger.forComponent("delegated-routing-v1-http-api-client"),this.started=!1,this.shutDownController=new AbortController,this.shutDownController.signal,this.httpQueue=new Tr({concurrency:e.concurrentRequests??Cn.concurrentRequests}),this.inFlightRequests=new Map,this.url=e.url instanceof URL?e.url:new URL(e.url),this.timeout=e.timeout??Cn.timeout,this.filterAddrs=e.filterAddrs,this.filterProtocols=e.filterProtocols,this.cacheName=e.cacheName??Cn.cacheName,this.cacheTTL=e.cacheTTL??Cn.cacheTTL}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,e={}){this.log("getProviders starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=qe([this.shutDownController.signal,n,e.signal]);let s=wt(),i=wt(),a=0;this.httpQueue.add(async()=>(s.resolve(),i.promise));try{await s.promise;let c=new URL(`${this.url}routing/v1/providers/${t}`);this.#e(c,e.filterAddrs,e.filterProtocols);let f=await this.#r(c.toString(),{headers:{accept:"application/x-ndjson, application/json;q=0.8"},signal:o});if(!f.ok){if(f.status===404)return;throw f.status===422?new Se("Request does not conform to schema or semantic constraints"):new xt(`Unexpected status code: ${f.status}`)}let u=f.headers.get("Content-Type");if(u==null)throw new xt("No Content-Type header received");if(f.body==null){if(u!=="application/x-ndjson")throw new xt("Routing response had no body");return}if(u.startsWith("application/json")){let p=(await f.json()).Providers??[];for(let d of p){let y=this.#t(d);y!=null&&(a++,yield y)}}else if(u.includes("application/x-ndjson"))for await(let l of ze(Ar(f.body))){let p=this.#t(l);p!=null&&(a++,yield p)}else throw new xt(`Unsupported Content-Type: ${u}`)}finally{o.clear(),i.resolve(),this.log("getProviders finished found %d providers for %c",a,t)}}async*getPeers(t,e={}){this.log("getPeers starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=qe([this.shutDownController.signal,n,e.signal]);let s=wt(),i=wt();this.httpQueue.add(async()=>(s.resolve(),i.promise));try{await s.promise;let a=new URL(`${this.url}routing/v1/peers/${t}`);this.#e(a,e.filterAddrs,e.filterProtocols);let c=await this.#r(a.toString(),{headers:{Accept:"application/x-ndjson"},signal:o});if(c.status===404)return;if(c.status===422)throw new Se("Request does not conform to schema or semantic constraints");if(c.body==null)throw new xt("Routing response had no body");if(c.headers.get("Content-Type")?.startsWith("application/json")){let l=(await c.json()).Peers??[];for(let p of l){let d=this.#t(p);d!=null&&(yield d)}}else for await(let u of ze(Ar(c.body))){let l=this.#t(u);l!=null&&(yield l)}}catch(a){this.log.error("getPeers errored - %e",a)}finally{o.clear(),i.resolve(),this.log("getPeers finished: %c",t)}}async*getClosestPeers(t,e={}){let n;if(q.asCID(t)===t||t instanceof q)n=t.toV1().toString();else throw new bt("Key must be CID");this.log("getClosestPeers starts: %s",n);let o=AbortSignal.timeout(this.timeout),s=qe([this.shutDownController.signal,o,e.signal]);let i=wt(),a=wt();this.httpQueue.add(async()=>(i.resolve(),a.promise));try{await i.promise;let c=new URL(`${this.url}routing/v1/dht/closest/peers/${n}`);this.#e(c,e.filterAddrs,e.filterProtocols);let f=await this.#r(c.toString(),{headers:{Accept:"application/x-ndjson"},signal:s});if(f.status===404)return;if(f.status===422)throw new Se("Request does not conform to schema or semantic constraints");if(f.body==null)throw new xt("Routing response had no body");if(f.headers.get("Content-Type")?.startsWith("application/json")){let p=(await f.json()).Peers??[];for(let d of p){let y=this.#t(d);y!=null&&(yield y)}}else for await(let l of ze(Ar(f.body))){let p=this.#t(l);p!=null&&(yield p)}}catch(c){this.log.error("getClosestPeers errored - %e",c)}finally{s.clear(),a.resolve(),this.log("getClosestPeers finished: %s",n)}}async getIPNS(t,e={}){this.log("getIPNS starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=qe([this.shutDownController.signal,n,e.signal]);let s=wt(),i=wt();this.httpQueue.add(async()=>(s.resolve(),i.promise));let a=`${this.url}routing/v1/ipns/${t}`;try{await s.promise;let c=await this.#r(a,{headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:o});if(this.log("getIPNS GET %s %d",a,c.status),c.status===404)throw new It("No matching records found");if(c.status===422)throw new Se("Request does not conform to schema or semantic constraints");if(!c.ok)throw new xt(`Unexpected status code: ${c.status}`);let f=c.headers.get("Content-Type");if(f==null||!f.includes("application/vnd.ipfs.ipns-record"))throw new It("No matching records found");if(c.body==null)throw new xt("GET ipns response had no body");let u=await c.arrayBuffer();return new Uint8Array(u,0,u.byteLength)}catch(c){throw this.log.error("getIPNS GET %s error - %e",a,c),c}finally{o.clear(),i.resolve(),this.log("getIPNS finished: %c",t)}}async putIPNS(t,e,n={}){this.log("putIPNS starts: %c",t);let o=AbortSignal.timeout(this.timeout),s=qe([this.shutDownController.signal,o,n.signal]);let i=wt(),a=wt();this.httpQueue.add(async()=>(i.resolve(),a.promise));let c=`${this.url}routing/v1/ipns/${t}`;try{await i.promise;let f=await this.#r(c,{method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:Sr(e),signal:s});if(this.log("putIPNS PUT %s %d",c,f.status),f.status!==200)throw new xt("PUT ipns response had status other than 200")}catch(f){throw this.log.error("putIPNS PUT %s error - %e",c,f.stack),f}finally{s.clear(),a.resolve(),this.log("putIPNS finished: %c",t)}}#t(t){try{let e=[],n=t.Addrs?.map(fc)??[];return t.Protocols!=null&&e.push(...t.Protocols),t.Protocol!=null&&(e.push(t.Protocol),delete t.Protocol),{...t,Schema:"peer",ID:Ha(t.ID),Addrs:n,Protocols:e}}catch(e){this.log.error("could not conform record to peer schema - %e",e)}}#e(t,e,n){if(e!=null||this.filterAddrs!=null){let o=e?.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,e){let n=e.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 s=this.inFlightRequests.get(o);if(s!=null){let c=await s;return this.log("deduplicating outgoing request for %s",o),c.clone()}this.log("outgoing request:"),this.logRequest(t,e);let i=fetch(t,e).then(async c=>{if(this.log("incoming response:"),this.logResponse(c),this.cache!=null&&c.ok&&n==="GET"){let f=Date.now()+this.cacheTTL,u=new Headers(c.headers);u.set("x-cache-expires",f.toString());let l=new Response(c.clone().body,{status:c.status,statusText:c.statusText,headers:u});await this.cache.put(t,l)}return c}).finally(()=>{this.inFlightRequests.delete(o)});return this.inFlightRequests.set(o,i),await i}toString(){return`DefaultDelegatedRoutingV1HttpApiClient(${this.url})`}logRequest(t,e){let n=new Headers(e.headers);this.log("%s %s HTTP/1.1",e.method??"GET",t);for(let[o,s]of n.entries())this.log("%s: %s",o,s)}logResponse(t){this.log("HTTP/1.1 %d %s",t.status,t.statusText);for(let[e,n]of t.headers.entries())this.log("%s: %s",e,n)}};function ph(r){return r[Symbol.asyncIterator]!=null}function mh(r){if(ph(r))return(async()=>{for await(let t of r)return t})();for(let t of r)return t}var yc=mh;function yh(r){let[t,e]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[e](){return this}}}var gc=yh;function gh(r){return r[Symbol.asyncIterator]!=null}function bh(r,t){let e=0;if(gh(r))return(async function*(){for await(let c of r)yield t(c,e++)})();let n=gc(r),{value:o,done:s}=n.next();if(s===!0)return(function*(){})();let i=t(o,e++);if(typeof i.then=="function")return(async function*(){yield await i;for(let c of n)yield t(c,e++)})();let a=t;return(function*(){yield i;for(let c of n)yield a(c,e++)})()}var bc=bh;var Dn=se("/ipns/");function wc(r){return xe(r.subarray(0,Dn.byteLength),Dn)}var Ln=class{client;constructor(t){this.client=t}get[Os](){return this}async start(){await this.client.start()}async stop(){await this.client.stop()}async*findProviders(t,e={}){try{yield*bc(this.client.getProviders(t,e),n=>({id:n.ID,multiaddrs:n.Addrs??[],routing:"delegated-http-routing-v1"}))}catch(n){if(n instanceof It)return;throw n}}async provide(){}async cancelReprovide(){}async put(t,e,n){if(!wc(t))return;let o=Ut(t.slice(Dn.length)),s=q.createV1(114,o);await this.client.putIPNS(s,e,n)}async get(t,e){if(!wc(t))throw new It("Not found");let n=Ut(t.slice(Dn.length)),o=q.createV1(114,n);try{return await this.client.getIPNS(o,e)}catch(s){throw s.name==="BadResponseError"?new It("Not found"):s}}toString(){return`DelegatedRoutingV1HttpApiClientContentRouting(${this.client.url})`}},Rn=class{client;constructor(t){this.client=t}get[Ps](){return this}async start(){await this.client.start()}async stop(){await this.client.stop()}async findPeer(t,e={}){let n=await yc(this.client.getPeers(t.toCID(),e));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new It("Not found")}async*getClosestPeers(t,e={}){let n;try{n=q.decode(t)}catch{try{n=q.createV1(114,Ct.decode(t))}catch{n=q.createV1(ti,pt.digest(t))}}for await(let o of this.client.getClosestPeers(n,e))yield{id:o.ID,multiaddrs:o.Addrs??[]}}toString(){return`DelegatedRoutingV1HttpApiClientPeerRouting(${this.client.url})`}};function _s(r){return t=>new _n(t,r)}function wh(r){return t=>new Ln(_s(r)(t))}function xh(r){return t=>new Rn(_s(r)(t))}return Ic(Eh);})();
14
3
  /*! Bundled license information:
15
4
 
16
- @noble/hashes/utils.js:
17
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
18
-
19
5
  @noble/curves/utils.js:
20
6
  @noble/curves/abstract/modular.js:
21
7
  @noble/curves/abstract/curve.js: