@helia/ipns 8.2.4-f3a99597 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,6 +1,6 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaIpns = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var HeliaIpns=(()=>{var cf=Object.create;var nn=Object.defineProperty;var uf=Object.getOwnPropertyDescriptor;var ff=Object.getOwnPropertyNames;var lf=Object.getPrototypeOf,df=Object.prototype.hasOwnProperty;var hf=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),bt=(e,t)=>{for(var r in t)nn(e,r,{get:t[r],enumerable:!0})},ps=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ff(t))!df.call(e,o)&&o!==r&&nn(e,o,{get:()=>t[o],enumerable:!(n=uf(t,o))||n.enumerable});return e};var xo=(e,t,r)=>(r=e!=null?cf(lf(e)):{},ps(t||!e||!e.__esModule?nn(r,"default",{value:e,enumerable:!0}):r,e)),pf=e=>ps(nn({},"__esModule",{value:!0}),e);var Rn=hf((Ig,Gi)=>{var Ag=(function(){typeof Gi<"u"&&(Gi.exports=A);var e=86400,t=3200,r=146097*t/400,n=e*r,o=1e3*n,i=864e13,s=4294967296,a=1e6,c="000000000",f=Math.trunc||function(h){var p=h-h%1;return p==0&&(h<0||h===0&&1/h!=1/0)?-0:p},u=A.prototype,l=(A.fromDate=function(h){return new A(+h)},A.fromInt64BE=U(0,1,2,3,0,4),A.fromInt64LE=U(3,2,1,0,4,0),A.fromString=function(L){var p,_=new A,L=(L+="").replace(/^\s*[+\-]?\d+/,function(m){var m=+m,y=1970+(m-1970)%400;return _.year=m-y,y}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(T,m,y){return m<0&&(y*=-1),p=6e4*(60*+m+ +y),""}).replace(/\.\d+$/,function(T){return _.nano=+(T+c).substr(1,9),""}).split(/\D+/);if(1<L.length?L[1]--:L[1]=0,_.time=p=Date.UTC.apply(Date,L)-(p||0),isNaN(p))throw new TypeError("Invalid Date");return w(_)},A.fromTimeT=function(h){return B(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=w(this);return(h.time%1e3*a+ +h.nano+1e9)%1e9},u.getTimeT=function(){var p=w(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 S(w(this).time)},u.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},u.toString=function(h){var p=this,_=p.toDate(),L={H:function(){return M(_.getUTCHours())},L:function(){return F(_.getUTCMilliseconds(),3)},M:function(){return M(_.getUTCMinutes())},N:function(){return F(p.getNano(),9)},S:function(){return M(_.getUTCSeconds())},Y:function(){var T=p.getYear();return 999999<T?"+"+T:9999<T?"+"+F(T,6):0<=T?F(T,4):-999999<=T?"-"+F(-T,6):T},a:function(){return E[_.getUTCDay()]},b:function(){return x[_.getUTCMonth()]},d:function(){return M(_.getUTCDate())},e:function(){return(function(T){return(9<T?"":" ")+(0|T)})(_.getUTCDate())},m:function(){return M(_.getUTCMonth()+1)}};return(function T(m){return m.replace(/%./g,function(y){var I=y[1],d=b[I],I=L[I];return d?T(d):I?I():y})})(h||l)},u.writeInt64BE=v(0,1,2,3,0,4),u.writeInt64LE=v(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),x=["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 A;function A(h,p,_){var L=this;if(!(L instanceof A))return new A(h,p,_);L.time=+h||0,L.nano=+p||0,L.year=+_||0,w(L)}function w(h){var p,_,L,T=h.year,m=h.time,y=h.nano,d=((y<0||a<=y)&&(y-=(_=Math.floor(y/a))*a,m+=_,_=1),T%t);return(m<-i||i<m||d)&&((p=f(m/o))&&(T+=p*t,m-=p*o),(L=S(m)).setUTCFullYear(d+L.getUTCFullYear()),L=(m=+L)+(p=f((T-=d)/t))*o,p&&-i<=L&&L<=i&&(T-=p*t,m=L),_=1),_&&(h.year=T,h.time=m,h.nano=y),h}function S(h){var p=new Date(0);return p.setTime(h),p}function B(T,L){T=+T||0;var _=f((L=(L|0)*s)/n)+f(T/n),L=L%n+T%n,T=f(L/n);return T&&(_+=T,L-=T*n),new A(1e3*L,0,_*t)}function v(h,p,_,L,T,m){return function(d,I){var R=w(this);d=d||new Array(8),P(d,I|=0);var k=Math.floor(R.time/1e3),R=R.year*(r*e/t),D=f(R/s)+f(k/s),R=R%s+k%s,k=Math.floor(R/s);return k&&(D+=k,R-=k*s),y(d,I+T,D),y(d,I+m,R),d};function y(d,I,D){d[I+h]=D>>24&255,d[I+p]=D>>16&255,d[I+_]=D>>8&255,d[I+L]=255&D}}function U(h,p,_,L,T,m){return function(d,I){P(d,I|=0);var D=y(d,I+T);return B(y(d,I+m),D)};function y(d,I){return 16777216*d[I+h]+(d[I+p]<<16|d[I+_]<<8|d[I+L])}}function P(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 F(h,p){return(c+(0|h)).substr(-p)}})()});var n0={};bt(n0,{ipns:()=>r0,ipnsSelector:()=>ao,ipnsValidator:()=>Wr});var Wt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var it=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Fe=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},yr=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var gr=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var on=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var qe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};function ms(e){return e==null?!1:(e.type==="RSA"||e.type==="Ed25519"||e.type==="secp256k1"||e.type==="ECDSA")&&e.raw instanceof Uint8Array&&typeof e.equals=="function"&&typeof e.toMultihash=="function"&&typeof e.toCID=="function"&&typeof e.verify=="function"}var sn=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){super.addEventListener(t,r,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:i})=>i!==r),this.#t.set(t,o))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var vo={};bt(vo,{base58btc:()=>j,base58flickr:()=>Ef});var c0=new Uint8Array(0);function ys(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 Jt(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 gs(e){return new TextEncoder().encode(e)}function xs(e){return new TextDecoder().decode(e)}function mf(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=e.length,c=e.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var A=0,w=0,S=0,B=b.length;S!==B&&b[S]===0;)S++,A++;for(var v=(B-S)*u+1>>>0,U=new Uint8Array(v);S!==B;){for(var P=b[S],M=0,F=v-1;(P!==0||M<w)&&F!==-1;F--,M++)P+=256*U[F]>>>0,U[F]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");w=M,S++}for(var h=v-w;h!==v&&U[h]===0;)h++;for(var p=c.repeat(A);h<v;++h)p+=e.charAt(U[h]);return p}function x(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var A=0;if(b[A]!==" "){for(var w=0,S=0;b[A]===c;)w++,A++;for(var B=(b.length-A)*f+1>>>0,v=new Uint8Array(B);b[A];){var U=r[b.charCodeAt(A)];if(U===255)return;for(var P=0,M=B-1;(U!==0||P<S)&&M!==-1;M--,P++)U+=a*v[M]>>>0,v[M]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");S=P,A++}if(b[A]!==" "){for(var F=B-S;F!==B&&v[F]===0;)F++;for(var h=new Uint8Array(w+(B-F)),p=w;F!==B;)h[p++]=v[F++];return h}}}function E(b){var A=x(b);if(A)return A;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:x,decode:E}}var yf=mf,gf=yf,ws=gf;var bo=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},wo=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Es(this,t)}},Eo=class{decoders;constructor(t){this.decoders=t}or(t){return Es(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 Es(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 He({name:e,prefix:t,encode:r,decode:n}){return new So(e,t,r,n)}function ue({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=ws(r,e);return He({prefix:t,name:e,encode:n,decode:i=>Jt(o(i))})}function xf(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let f=0;f<o;++f){let u=t[e[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function bf(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],s+=8;s>r;)s-=r,i+=t[o&a>>s];if(s!==0&&(i+=t[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function wf(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function tt({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=wf(n);return He({prefix:t,name:e,encode(i){return bf(i,n,r)},decode(i){return xf(i,o,r,e)}})}var j=ue({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ef=ue({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ao={};bt(Ao,{base32:()=>fe,base32hex:()=>If,base32hexpad:()=>Bf,base32hexpadupper:()=>Cf,base32hexupper:()=>Tf,base32pad:()=>vf,base32padupper:()=>Af,base32upper:()=>Sf,base32z:()=>_f});var fe=tt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Sf=tt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),vf=tt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Af=tt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),If=tt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Tf=tt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Bf=tt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Cf=tt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),_f=tt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Io={};bt(Io,{base36:()=>Rt,base36upper:()=>Lf});var Rt=ue({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Lf=ue({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Uf=As,Ss=128,Df=127,Rf=~Df,Nf=Math.pow(2,31);function As(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Nf;)t[r++]=e&255|Ss,e/=128;for(;e&Rf;)t[r++]=e&255|Ss,e>>>=7;return t[r]=e|0,As.bytes=r-n+1,t}var kf=To,Kf=128,vs=127;function To(e,n){var r=0,n=n||0,o=0,i=n,s,a=e.length;do{if(i>=a)throw To.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&vs)<<o:(s&vs)*Math.pow(2,o),o+=7}while(s>=Kf);return To.bytes=i-n,r}var Pf=Math.pow(2,7),Of=Math.pow(2,14),Mf=Math.pow(2,21),Vf=Math.pow(2,28),Ff=Math.pow(2,35),qf=Math.pow(2,42),Hf=Math.pow(2,49),$f=Math.pow(2,56),zf=Math.pow(2,63),Zf=function(e){return e<Pf?1:e<Of?2:e<Mf?3:e<Vf?4:e<Ff?5:e<qf?6:e<Hf?7:e<$f?8:e<zf?9:10},Yf={encode:Uf,decode:kf,encodingLength:Zf},Gf=Yf,xr=Gf;function br(e,t=0){return[xr.decode(e,t),xr.decode.bytes]}function $e(e,t,r=0){return xr.encode(e,t,r),t}function ze(e){return xr.encodingLength(e)}function Ht(e,t){let r=t.byteLength,n=ze(e),o=n+ze(r),i=new Uint8Array(o+r);return $e(e,i,0),$e(r,i,n),i.set(t,o),new Ze(e,r,t,i)}function Ye(e){let t=Jt(e),[r,n]=br(t),[o,i]=br(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Ze(r,o,s,t)}function Is(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&ys(e.bytes,r.bytes)}}var Ze=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Ts(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Xf(r,Bo(e),t??j.encoder);default:return Wf(r,Bo(e),t??fe.encoder)}}var Bs=new WeakMap;function Bo(e){let t=Bs.get(e);if(t==null){let r=new Map;return Bs.set(e,r),r}return t}var ot=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!==wr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Jf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Ht(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Is(t.multihash,n.multihash)}toString(t){return Ts(this,t)}toJSON(){return{"/":Ts(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??Cs(n,o,i.bytes))}else if(r[Qf]===!0){let{version:n,multihash:o,code:i}=r,s=Ye(o);return e.create(n,i,s)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==wr)throw new Error(`Version 0 CID must use dag-pb (code: ${wr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Cs(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,wr,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=Jt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new Ze(r.multihashCode,r.digestSize,i,o);return[r.version===0?e.createV0(s):e.createV1(r.codec,s),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,x]=br(t.subarray(r));return r+=x,l},o=n(),i=wr;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),f=r+c,u=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(t,r){let[n,o]=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??j;return[j.prefix,r.decode(`${j.prefix}${e}`)]}case j.prefix:{let r=t??j;return[j.prefix,r.decode(e)]}case fe.prefix:{let r=t??fe;return[fe.prefix,r.decode(e)]}case Rt.prefix:{let r=t??Rt;return[Rt.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function Xf(e,t,r){let{prefix:n}=r;if(n!==j.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 Wf(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 wr=112,Jf=18;function Cs(e,t,r){let n=ze(e),o=n+ze(t),i=new Uint8Array(o+r.byteLength);return $e(e,i,0),$e(t,i,n),i.set(r,o),i}var Qf=Symbol.for("@ipld/js-cid/CID");var Co={};bt(Co,{identity:()=>Ie});var _s=0,tl="identity",Ls=Jt;function el(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Ht(_s,Ls(e))}var Ie={code:_s,name:tl,encode:Ls,digest:el};function et(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 Lt(e=0){return new Uint8Array(e)}function At(e=0){return new Uint8Array(e)}function le(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=At(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Ds=Symbol.for("@achingbrain/uint8arraylist");function Us(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 cn(e){return!!e?.[Ds]}var mt=class e{bufs;length;[Ds]=!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(cn(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(cn(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=Us(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Us(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(cn(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 le(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:le(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),i=new e;return i.length=o,i.bufs=[...n],i}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,u=r>a&&r<=c;if(f&&u){if(t===a&&r===c){n.push(s);break}let l=t-a;n.push(s.subarray(l,l+(r-t)));break}if(f){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(u){if(r===c){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!cn(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=r;l<=c;l+=u){u=0;for(let x=f;x>=0;x--){let E=this.get(l+x);if(n[x]!==E){u=Math.max(1,x-a[E]);break}}if(u===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=At(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=Lt(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=Lt(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=Lt(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=At(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=Lt(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=Lt(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=Lt(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=Lt(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=Lt(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(!et(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 _o={};bt(_o,{base10:()=>rl});var rl=ue({prefix:"9",name:"base10",alphabet:"0123456789"});var Lo={};bt(Lo,{base16:()=>nl,base16upper:()=>ol});var nl=tt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ol=tt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Uo={};bt(Uo,{base2:()=>il});var il=tt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Do={};bt(Do,{base256emoji:()=>fl});var Rs=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}"),sl=Rs.reduce((e,t,r)=>(e[r]=t,e),[]),al=Rs.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function cl(e){return e.reduce((t,r)=>(t+=sl[r],t),"")}function ul(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=al[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var fl=He({prefix:"\u{1F680}",name:"base256emoji",encode:cl,decode:ul});var No={};bt(No,{base64:()=>Ro,base64pad:()=>ll,base64url:()=>dl,base64urlpad:()=>hl});var Ro=tt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ll=tt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),dl=tt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),hl=tt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ko={};bt(ko,{base8:()=>pl});var pl=tt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ko={};bt(Ko,{identity:()=>ml});var ml=He({prefix:"\0",name:"identity",encode:e=>xs(e),decode:e=>gs(e)});var z0=new TextEncoder,Z0=new TextDecoder;var Mo={};bt(Mo,{sha256:()=>un,sha512:()=>bl});var xl=20;function Oo({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Po(e,t,r,n,o)}var Po=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??xl,this.maxDigestLength=i}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Ns(n,this.code,r?.truncate):n.then(o=>Ns(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ns(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Ht(t,e)}function Ks(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var un=Oo({name:"sha2-256",code:18,encode:Ks("SHA-256")}),bl=Oo({name:"sha2-512",code:19,encode:Ks("SHA-512")});var Vo={...Ko,...Uo,...ko,..._o,...Lo,...Ao,...Io,...vo,...No,...Do},op={...Mo,...Co};function Os(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Ps=Os("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Fo=Os("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=At(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),wl={utf8:Ps,"utf-8":Ps,hex:Vo.base16,latin1:Fo,ascii:Fo,binary:Fo,...Vo},fn=wl;function $(e,t="utf8"){let r=fn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function Y(e,t="utf8"){let r=fn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var El=parseInt("11111",2),qo=parseInt("10000000",2),Sl=parseInt("01111111",2),Ms={0:Er,1:Er,2:vl,3:Tl,4:Bl,5:Il,6:Al,16:Er,22:Er,48:Er};function Qt(e,t={offset:0}){let r=e[t.offset]&El;if(t.offset++,Ms[r]!=null)return Ms[r](e,t);throw new Error("No decoder for tag "+r)}function Sr(e,t){let r=0;if((e[t.offset]&qo)===qo){let n=e[t.offset]&Sl,o="0x";t.offset++;for(let i=0;i<n;i++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Er(e,t){Sr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Qt(e,t);if(n===null)break;r.push(n)}return r}function vl(e,t){let r=Sr(e,t),n=t.offset,o=t.offset+r,i=[];for(let s=n;s<o;s++)s===n&&e[s]===0||i.push(e[s]);return t.offset+=r,Uint8Array.from(i)}function Al(e,t){let r=Sr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;t.offset<n;){let f=e[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let l=0;l<c.length;l++)u+=c[l]<<l*7;a+=`.${u}`,c=[]}}return a}function Il(e,t){return t.offset++,null}function Tl(e,t){let r=Sr(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=Sr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Cl(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new mt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function ln(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Cl(e.byteLength);return new mt(Uint8Array.from([t.byteLength|qo]),t)}function yt(e){let t=new mt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new mt(Uint8Array.from([2]),ln(t),t)}function vr(e){let t=Uint8Array.from([0]),r=new mt(t,e);return new mt(Uint8Array.from([3]),ln(r),r)}function Vs(e){return new mt(Uint8Array.from([4]),ln(e),e)}function Nt(e,t=48){let r=new mt;for(let n of e)r.append(n);return new mt(Uint8Array.from([t]),ln(r),r)}async function Fs(e="P-256"){let t=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:e},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",t.publicKey),privateKey:await crypto.subtle.exportKey("jwk",t.privateKey)}}async function qs(e,t,r){let n=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["sign"]);r?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Hs(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),i}var _l=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Ll=Uint8Array.from([6,5,43,129,4,0,34]),Ul=Uint8Array.from([6,5,43,129,4,0,35]),Dl={ext:!0,kty:"EC",crv:"P-256"},Rl={ext:!0,kty:"EC",crv:"P-384"},Nl={ext:!0,kty:"EC",crv:"P-521"},Ho=32,$o=48,zo=66;function Zo(e){let t=Qt(e);return $s(t)}function $s(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Ho*2+1)return n=Y(t.subarray(r,r+Ho),"base64url"),o=Y(t.subarray(r+Ho),"base64url"),new Te({...Dl,key_ops:["verify"],x:n,y:o});if(t.byteLength===$o*2+1)return n=Y(t.subarray(r,r+$o),"base64url"),o=Y(t.subarray(r+$o),"base64url"),new Te({...Rl,key_ops:["verify"],x:n,y:o});if(t.byteLength===zo*2+1)return n=Y(t.subarray(r,r+zo),"base64url"),o=Y(t.subarray(r+zo),"base64url"),new Te({...Nl,key_ops:["verify"],x:n,y:o});throw new it(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function zs(e){return Nt([yt(Uint8Array.from([1])),Vs($(e.d??"","base64url")),Nt([Ys(e.crv)],160),Nt([vr(new mt(Uint8Array.from([4]),$(e.x??"","base64url"),$(e.y??"","base64url")))],161)]).subarray()}function Zs(e){return Nt([yt(Uint8Array.from([1])),Nt([Ys(e.crv)],160),Nt([vr(new mt(Uint8Array.from([4]),$(e.x??"","base64url"),$(e.y??"","base64url")))],161)]).subarray()}function Ys(e){if(e==="P-256")return _l;if(e==="P-384")return Ll;if(e==="P-521")return Ul;throw new it(`Invalid curve ${e}`)}async function Gs(e="P-256"){let t=await Fs(e);return new dn(t.privateKey)}var Te=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Zs(this.jwk)),this._raw}toMultihash(){return Ie.digest(de(this))}toCID(){return ot.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:et(this.raw,t.raw)}async verify(t,r,n){return Hs(this.jwk,r,t,n)}},dn=class{type="ECDSA";jwk;publicKey;_raw;constructor(t){this.jwk=t,this.publicKey=new Te({crv:t.crv,ext:t.ext,key_ops:["verify"],kty:"EC",x:t.x,y:t.y})}get raw(){return this._raw==null&&(this._raw=zs(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:et(this.raw,t.raw)}async sign(t,r){return qs(this.jwk,t,r)}};function Be(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function $t(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function H(e,t,r=""){let n=Be(e),o=e?.length,i=t!==void 0;if(!n||i&&o!==t){let s=r&&`"${r}" `,a=i?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`;throw new Error(s+"expected Uint8Array"+a+", got "+c)}return e}function hn(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");$t(e.outputLen),$t(e.blockLen)}function Ge(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 Xs(e,t){H(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function ee(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function pn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function kt(e,t){return e<<32-t|e>>>t}var Ws=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",kl=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function re(e){if(H(e),Ws)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=kl[e[r]];return t}var te={_0:48,_9:57,A:65,F:70,a:97,f:102};function js(e){if(e>=te._0&&e<=te._9)return e-te._0;if(e>=te.A&&e<=te.F)return e-(te.A-10);if(e>=te.a&&e<=te.f)return e-(te.a-10)}function ne(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Ws)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=js(e.charCodeAt(i)),a=js(e.charCodeAt(i+1));if(s===void 0||a===void 0){let c=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function wt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];H(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let i=e[n];r.set(i,o),o+=i.length}return r}function 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 je(e=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}var Go=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Js(e,t,r){return e&t^~e&r}function Qs(e,t,r){return e&t^e&r^t&r}var Ar=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=pn(this.buffer)}update(t){Ge(this),H(t);let{view:r,buffer:n,blockLen:o}=this,i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=pn(t);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ge(this),Xs(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,ee(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),i),this.process(n,0);let a=pn(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],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return t.destroyed=s,t.finished=i,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},oe=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ft=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var mn=BigInt(4294967295),ta=BigInt(32);function Kl(e,t=!1){return t?{h:Number(e&mn),l:Number(e>>ta&mn)}:{h:Number(e>>ta&mn)|0,l:Number(e&mn)|0}}function ea(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let i=0;i<r;i++){let{h:s,l:a}=Kl(e[i],t);[n[i],o[i]]=[s,a]}return[n,o]}var jo=(e,t,r)=>e>>>r,Xo=(e,t,r)=>e<<32-r|t>>>r,Ce=(e,t,r)=>e>>>r|t<<32-r,_e=(e,t,r)=>e<<32-r|t>>>r,Ir=(e,t,r)=>e<<64-r|t>>>r-32,Tr=(e,t,r)=>e>>>r-32|t<<64-r;function zt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ra=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),na=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,oa=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ia=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,sa=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),aa=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;var Ol=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]),he=new Uint32Array(64),Wo=class extends Ar{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[t,r,n,o,i,s,a,c]}set(t,r,n,o,i,s,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)he[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let x=he[l-15],E=he[l-2],b=kt(x,7)^kt(x,18)^x>>>3,A=kt(E,17)^kt(E,19)^E>>>10;he[l]=A+he[l-7]+b+he[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let x=kt(a,6)^kt(a,11)^kt(a,25),E=u+x+Js(a,c,f)+Ol[l]+he[l]|0,A=(kt(n,2)^kt(n,13)^kt(n,22))+Qs(n,o,i)|0;u=f,f=c,c=a,a=s+E|0,s=i,i=o,o=n,n=E+A|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,i,s,a,c,f,u)}roundClean(){ee(he)}destroy(){this.set(0,0,0,0,0,0,0,0),ee(this.buffer)}},Jo=class extends Wo{A=oe[0]|0;B=oe[1]|0;C=oe[2]|0;D=oe[3]|0;E=oe[4]|0;F=oe[5]|0;G=oe[6]|0;H=oe[7]|0;constructor(){super(32)}};var ca=ea(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Ml=ca[0],Vl=ca[1],pe=new Uint32Array(80),me=new Uint32Array(80),Qo=class extends Ar{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:x,Gh:E,Gl:b,Hh:A,Hl:w}=this;return[t,r,n,o,i,s,a,c,f,u,l,x,E,b,A,w]}set(t,r,n,o,i,s,a,c,f,u,l,x,E,b,A,w){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=x|0,this.Gh=E|0,this.Gl=b|0,this.Hh=A|0,this.Hl=w|0}process(t,r){for(let v=0;v<16;v++,r+=4)pe[v]=t.getUint32(r),me[v]=t.getUint32(r+=4);for(let v=16;v<80;v++){let U=pe[v-15]|0,P=me[v-15]|0,M=Ce(U,P,1)^Ce(U,P,8)^jo(U,P,7),F=_e(U,P,1)^_e(U,P,8)^Xo(U,P,7),h=pe[v-2]|0,p=me[v-2]|0,_=Ce(h,p,19)^Ir(h,p,61)^jo(h,p,6),L=_e(h,p,19)^Tr(h,p,61)^Xo(h,p,6),T=oa(F,L,me[v-7],me[v-16]),m=ia(T,M,_,pe[v-7],pe[v-16]);pe[v]=m|0,me[v]=T|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:x,Fh:E,Fl:b,Gh:A,Gl:w,Hh:S,Hl:B}=this;for(let v=0;v<80;v++){let U=Ce(l,x,14)^Ce(l,x,18)^Ir(l,x,41),P=_e(l,x,14)^_e(l,x,18)^Tr(l,x,41),M=l&E^~l&A,F=x&b^~x&w,h=sa(B,P,F,Vl[v],me[v]),p=aa(h,S,U,M,Ml[v],pe[v]),_=h|0,L=Ce(n,o,28)^Ir(n,o,34)^Ir(n,o,39),T=_e(n,o,28)^Tr(n,o,34)^Tr(n,o,39),m=n&i^n&a^i&a,y=o&s^o&c^s&c;S=A|0,B=w|0,A=E|0,w=b|0,E=l|0,b=x|0,{h:l,l:x}=zt(f|0,u|0,p|0,_|0),f=a|0,u=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let d=ra(_,T,y);n=na(d,p,L,m),o=d|0}({h:n,l:o}=zt(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=zt(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=zt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=zt(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:x}=zt(this.Eh|0,this.El|0,l|0,x|0),{h:E,l:b}=zt(this.Fh|0,this.Fl|0,E|0,b|0),{h:A,l:w}=zt(this.Gh|0,this.Gl|0,A|0,w|0),{h:S,l:B}=zt(this.Hh|0,this.Hl|0,S|0,B|0),this.set(n,o,i,s,a,c,f,u,l,x,E,b,A,w,S,B)}roundClean(){ee(pe,me)}destroy(){ee(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ti=class extends Qo{Ah=ft[0]|0;Al=ft[1]|0;Bh=ft[2]|0;Bl=ft[3]|0;Ch=ft[4]|0;Cl=ft[5]|0;Dh=ft[6]|0;Dl=ft[7]|0;Eh=ft[8]|0;El=ft[9]|0;Fh=ft[10]|0;Fl=ft[11]|0;Gh=ft[12]|0;Gl=ft[13]|0;Hh=ft[14]|0;Hl=ft[15]|0;constructor(){super(64)}};var Xe=Yo(()=>new Jo,Go(1));var ua=Yo(()=>new ti,Go(3));var ri=BigInt(0),ei=BigInt(1);function ie(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function fa(e){if(typeof e=="bigint"){if(!yn(e))throw new Error("positive bigint expected, got "+e)}else $t(e);return e}function Br(e){let t=fa(e).toString(16);return t.length&1?"0"+t:t}function la(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?ri:BigInt("0x"+e)}function We(e){return la(re(e))}function Le(e){return la(re(xn(H(e)).reverse()))}function gn(e,t){$t(t),e=fa(e);let r=ne(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function ni(e,t){return gn(e,t).reverse()}function xn(e){return Uint8Array.from(e)}var yn=e=>typeof e=="bigint"&&ri<=e;function Fl(e,t,r){return yn(e)&&yn(t)&&yn(r)&&t<=e&&e<r}function Cr(e,t,r,n){if(!Fl(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function oi(e){let t;for(t=0;e>ri;e>>=ei,t+=1);return t}var _r=e=>(ei<<BigInt(e))-ei;function da(e,t,r){if($t(e,"hashLen"),$t(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=w=>new Uint8Array(w),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=n(e),f=n(e),u=0,l=()=>{c.fill(1),f.fill(0),u=0},x=(...w)=>r(f,wt(c,...w)),E=(w=o)=>{f=x(i,w),c=x(),w.length!==0&&(f=x(s,w),c=x())},b=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let w=0,S=[];for(;w<t;){c=x();let B=c.slice();S.push(B),w+=c.length}return wt(...S)};return(w,S)=>{l(),E(w);let B;for(;!(B=S(b()));)E();return l(),B}}function ye(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(i,s,a){let c=e[i];if(a&&c===void 0)return;let f=typeof c;if(f!==s||c===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${f}`)}let o=(i,s)=>Object.entries(i).forEach(([a,c])=>n(a,c,s));o(t,!1),o(r,!0)}function Je(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 gt=BigInt(0),st=BigInt(1),Ue=BigInt(2),ma=BigInt(3),ya=BigInt(4),ga=BigInt(5),ql=BigInt(7),xa=BigInt(8),Hl=BigInt(9),ba=BigInt(16);function rt(e,t){let r=e%t;return r>=gt?r:t+r}function X(e,t,r){let n=e;for(;t-- >gt;)n*=n,n%=r;return n}function ha(e,t){if(e===gt)throw new Error("invert: expected non-zero number");if(t<=gt)throw new Error("invert: expected positive modulus, got "+t);let r=rt(e,t),n=t,o=gt,i=st,s=st,a=gt;for(;r!==gt;){let f=n/r,u=n%r,l=o-s*f,x=i-a*f;n=r,r=u,o=s,i=a,s=l,a=x}if(n!==st)throw new Error("invert: does not exist");return rt(o,t)}function si(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function wa(e,t){let r=(e.ORDER+st)/ya,n=e.pow(t,r);return si(e,n,t),n}function $l(e,t){let r=(e.ORDER-ga)/xa,n=e.mul(t,Ue),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,Ue),o),a=e.mul(i,e.sub(s,e.ONE));return si(e,a,t),a}function zl(e){let t=Qe(e),r=Ea(e),n=r(t,t.neg(t.ONE)),o=r(t,n),i=r(t,t.neg(n)),s=(e+ql)/ba;return(a,c)=>{let f=a.pow(c,s),u=a.mul(f,n),l=a.mul(f,o),x=a.mul(f,i),E=a.eql(a.sqr(u),c),b=a.eql(a.sqr(l),c);f=a.cmov(f,u,E),u=a.cmov(x,l,b);let A=a.eql(a.sqr(u),c),w=a.cmov(f,u,A);return si(a,w,c),w}}function Ea(e){if(e<ma)throw new Error("sqrt is not defined for small field");let t=e-st,r=0;for(;t%Ue===gt;)t/=Ue,r++;let n=Ue,o=Qe(e);for(;pa(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return wa;let i=o.pow(n,t),s=(t+st)/Ue;return function(c,f){if(c.is0(f))return f;if(pa(c,f)!==1)throw new Error("Cannot find square root");let u=r,l=c.mul(c.ONE,i),x=c.pow(f,t),E=c.pow(f,s);for(;!c.eql(x,c.ONE);){if(c.is0(x))return c.ZERO;let b=1,A=c.sqr(x);for(;!c.eql(A,c.ONE);)if(b++,A=c.sqr(A),b===u)throw new Error("Cannot find square root");let w=st<<BigInt(u-b-1),S=c.pow(l,w);u=b,l=c.sqr(S),x=c.mul(x,l),E=c.mul(E,S)}return E}}function Zl(e){return e%ya===ma?wa:e%xa===ga?$l:e%ba===Hl?zl(e):Ea(e)}var Sa=(e,t)=>(rt(e,t)&st)===st,Yl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ai(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Yl.reduce((n,o)=>(n[o]="function",n),t);return ye(e,r),e}function Gl(e,t,r){if(r<gt)throw new Error("invalid exponent, negatives unsupported");if(r===gt)return e.ONE;if(r===st)return t;let n=e.ONE,o=t;for(;r>gt;)r&st&&(n=e.mul(n,o)),o=e.sqr(o),r>>=st;return n}function Lr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((s,a,c)=>e.is0(a)?s:(n[c]=s,e.mul(s,a)),e.ONE),i=e.inv(o);return t.reduceRight((s,a,c)=>e.is0(a)?s:(n[c]=e.mul(s,n[c]),e.mul(s,a)),i),n}function pa(e,t){let r=(e.ORDER-st)/Ue,n=e.pow(t,r),o=e.eql(n,e.ONE),i=e.eql(n,e.ZERO),s=e.eql(n,e.neg(e.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function jl(e,t){t!==void 0&&$t(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var ii=class{ORDER;BITS;BYTES;isLE;ZERO=gt;ONE=st;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=gt)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}=jl(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 rt(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return gt<=t&&t<this.ORDER}is0(t){return t===gt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&st)===st}neg(t){return rt(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return rt(t*t,this.ORDER)}add(t,r){return rt(t+r,this.ORDER)}sub(t,r){return rt(t-r,this.ORDER)}mul(t,r){return rt(t*r,this.ORDER)}pow(t,r){return Gl(this,t,r)}div(t,r){return rt(t*ha(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 ha(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=Zl(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?ni(t,this.BYTES):gn(t,this.BYTES)}fromBytes(t,r=!1){H(t);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=new Uint8Array(o);f.set(t,i?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=i?Le(t):We(t);if(a&&(c=rt(c,s)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Lr(this,t)}cmov(t,r,n){return n?r:t}};function Qe(e,t={}){return new ii(e,t)}function va(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 ci(e){let t=va(e);return t+Math.ceil(t/2)}function ui(e,t,r=!1){H(e);let n=e.length,o=va(t),i=ci(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Le(e):We(e),a=rt(s,t-st)+st;return r?ni(a,o):gn(a,o)}var tr=BigInt(0),De=BigInt(1);function Ur(e,t){let r=t.negate();return e?r:t}function Re(e,t){let r=Lr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Ba(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function fi(e,t){Ba(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,i=_r(e),s=BigInt(e);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function Aa(e,t,r){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r,a=Number(e&o),c=e>>s;a>n&&(a-=i,c+=De);let f=t*n,u=f+Math.abs(a)-1,l=a===0,x=a<0,E=t%2!==0;return{nextN:c,offset:u,isZero:l,isNeg:x,isNegF:E,offsetF:f}}var li=new WeakMap,Ca=new WeakMap;function di(e){return Ca.get(e)||1}function Ia(e){if(e!==tr)throw new Error("invalid wNAF")}var er=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>tr;)r&De&&(n=n.add(o)),o=o.double(),r>>=De;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=fi(r,this.bits),i=[],s=t,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let f=1;f<o;f++)a=a.add(s),i.push(a);s=a.double()}return i}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=fi(t,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:f,isZero:u,isNeg:l,isNegF:x,offsetF:E}=Aa(n,a,s);n=c,u?i=i.add(Ur(x,r[E])):o=o.add(Ur(l,r[f]))}return Ia(n),{p:o,f:i}}wNAFUnsafe(t,r,n,o=this.ZERO){let i=fi(t,this.bits);for(let s=0;s<i.windows&&n!==tr;s++){let{nextN:a,offset:c,isZero:f,isNeg:u}=Aa(n,s,i);if(n=a,!f){let l=r[c];o=o.add(u?l.negate():l)}}return Ia(n),o}getPrecomputes(t,r,n){let o=li.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),li.set(r,o))),o}cached(t,r,n){let o=di(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let i=di(t);return i===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,t,n),r,o)}createCache(t,r){Ba(r,this.bits),Ca.set(t,r),li.delete(t)}hasCache(t){return di(t)!==1}};function _a(e,t,r,n){let o=t,i=e.ZERO,s=e.ZERO;for(;r>tr||n>tr;)r&De&&(i=i.add(o)),n&De&&(s=s.add(o)),o=o.double(),r>>=De,n>>=De;return{p1:i,p2:s}}function Ta(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ai(t),t}else return Qe(e,{isLE:r})}function bn(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let f=t[c];if(!(typeof f=="bigint"&&f>tr))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Ta(t.p,r.Fp,n),i=Ta(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:i}}function wn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var ge=BigInt(0),at=BigInt(1),hi=BigInt(2),Xl=BigInt(8);function Wl(e,t,r,n){let o=e.sqr(r),i=e.sqr(n),s=e.add(e.mul(t.a,o),i),a=e.add(e.ONE,e.mul(t.d,e.mul(o,i)));return e.eql(s,a)}function La(e,t={}){let r=bn("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s}=i;ye(t,{},{uvRatio:"function"});let a=hi<<BigInt(o.BYTES*8)-at,c=w=>n.create(w),f=t.uvRatio||((w,S)=>{try{return{isValid:!0,value:n.sqrt(n.div(w,S))}}catch{return{isValid:!1,value:ge}}});if(!Wl(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function u(w,S,B=!1){let v=B?at:ge;return Cr("coordinate "+w,S,v,a),S}function l(w){if(!(w instanceof b))throw new Error("EdwardsPoint expected")}let x=Je((w,S)=>{let{X:B,Y:v,Z:U}=w,P=w.is0();S==null&&(S=P?Xl:n.inv(U));let M=c(B*S),F=c(v*S),h=n.mul(U,S);if(P)return{x:ge,y:at};if(h!==at)throw new Error("invZ was invalid");return{x:M,y:F}}),E=Je(w=>{let{a:S,d:B}=i;if(w.is0())throw new Error("bad point: ZERO");let{X:v,Y:U,Z:P,T:M}=w,F=c(v*v),h=c(U*U),p=c(P*P),_=c(p*p),L=c(F*S),T=c(p*c(L+h)),m=c(_+c(B*c(F*h)));if(T!==m)throw new Error("bad point: equation left != right (1)");let y=c(v*U),d=c(P*M);if(y!==d)throw new Error("bad point: equation left != right (2)");return!0});class b{static BASE=new b(i.Gx,i.Gy,at,c(i.Gx*i.Gy));static ZERO=new b(ge,at,at,ge);static Fp=n;static Fn=o;X;Y;Z;T;constructor(S,B,v,U){this.X=u("x",S),this.Y=u("y",B),this.Z=u("z",v,!0),this.T=u("t",U),Object.freeze(this)}static CURVE(){return i}static fromAffine(S){if(S instanceof b)throw new Error("extended point not allowed");let{x:B,y:v}=S||{};return u("x",B),u("y",v),new b(B,v,at,c(B*v))}static fromBytes(S,B=!1){let v=n.BYTES,{a:U,d:P}=i;S=xn(H(S,v,"point")),ie(B,"zip215");let M=xn(S),F=S[v-1];M[v-1]=F&-129;let h=Le(M),p=B?a:n.ORDER;Cr("point.y",h,ge,p);let _=c(h*h),L=c(_-at),T=c(P*_-U),{isValid:m,value:y}=f(L,T);if(!m)throw new Error("bad point: invalid y coordinate");let d=(y&at)===at,I=(F&128)!==0;if(!B&&y===ge&&I)throw new Error("bad point: x=0 and x_0=1");return I!==d&&(y=c(-y)),b.fromAffine({x:y,y:h})}static fromHex(S,B=!1){return b.fromBytes(ne(S),B)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(S=8,B=!0){return A.createCache(this,S),B||this.multiply(hi),this}assertValidity(){E(this)}equals(S){l(S);let{X:B,Y:v,Z:U}=this,{X:P,Y:M,Z:F}=S,h=c(B*F),p=c(P*U),_=c(v*F),L=c(M*U);return h===p&&_===L}is0(){return this.equals(b.ZERO)}negate(){return new b(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:S}=i,{X:B,Y:v,Z:U}=this,P=c(B*B),M=c(v*v),F=c(hi*c(U*U)),h=c(S*P),p=B+v,_=c(c(p*p)-P-M),L=h+M,T=L-F,m=h-M,y=c(_*T),d=c(L*m),I=c(_*m),D=c(T*L);return new b(y,d,D,I)}add(S){l(S);let{a:B,d:v}=i,{X:U,Y:P,Z:M,T:F}=this,{X:h,Y:p,Z:_,T:L}=S,T=c(U*h),m=c(P*p),y=c(F*v*L),d=c(M*_),I=c((U+P)*(h+p)-T-m),D=d-y,R=d+y,k=c(m-B*T),K=c(I*D),O=c(R*k),q=c(I*k),W=c(D*R);return new b(K,O,W,q)}subtract(S){return this.add(S.negate())}multiply(S){if(!o.isValidNot0(S))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:B,f:v}=A.cached(this,S,U=>Re(b,U));return Re(b,[B,v])[0]}multiplyUnsafe(S,B=b.ZERO){if(!o.isValid(S))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return S===ge?b.ZERO:this.is0()||S===at?this:A.unsafe(this,S,v=>Re(b,v),B)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return A.unsafe(this,i.n).is0()}toAffine(S){return x(this,S)}clearCofactor(){return s===at?this:this.multiplyUnsafe(s)}toBytes(){let{x:S,y:B}=this.toAffine(),v=n.toBytes(B);return v[v.length-1]|=S&at?128:0,v}toHex(){return re(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let A=new er(b,o.BITS);return b.BASE.precompute(8),b}function Ua(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');ye(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:i,Fn:s}=e,a=r.randomBytes||je,c=r.adjustScalarBytes||(h=>h),f=r.domain||((h,p,_)=>{if(ie(_,"phflag"),p.length||_)throw new Error("Contexts/pre-hash are not supported");return h});function u(h){return s.create(Le(h))}function l(h){let p=v.secretKey;H(h,v.secretKey,"secretKey");let _=H(t(h),2*p,"hashedSecretKey"),L=c(_.slice(0,p)),T=_.slice(p,2*p),m=u(L);return{head:L,prefix:T,scalar:m}}function x(h){let{head:p,prefix:_,scalar:L}=l(h),T=o.multiply(L),m=T.toBytes();return{head:p,prefix:_,scalar:L,point:T,pointBytes:m}}function E(h){return x(h).pointBytes}function b(h=Uint8Array.of(),...p){let _=wt(...p);return u(t(f(_,H(h,void 0,"context"),!!n)))}function A(h,p,_={}){h=H(h,void 0,"message"),n&&(h=n(h));let{prefix:L,scalar:T,pointBytes:m}=x(p),y=b(_.context,L,h),d=o.multiply(y).toBytes(),I=b(_.context,d,m,h),D=s.create(y+I*T);if(!s.isValid(D))throw new Error("sign failed: invalid s");let R=wt(d,s.toBytes(D));return H(R,v.signature,"result")}let w={zip215:!0};function S(h,p,_,L=w){let{context:T,zip215:m}=L,y=v.signature;h=H(h,y,"signature"),p=H(p,void 0,"message"),_=H(_,v.publicKey,"publicKey"),m!==void 0&&ie(m,"zip215"),n&&(p=n(p));let d=y/2,I=h.subarray(0,d),D=Le(h.subarray(d,y)),R,k,K;try{R=e.fromBytes(_,m),k=e.fromBytes(I,m),K=o.multiplyUnsafe(D)}catch{return!1}if(!m&&R.isSmallOrder())return!1;let O=b(T,k.toBytes(),R.toBytes(),p);return k.add(R.multiplyUnsafe(O)).subtract(K).clearCofactor().is0()}let B=i.BYTES,v={secretKey:B,publicKey:B,signature:2*B,seed:B};function U(h=a(v.seed)){return H(h,v.seed,"seed")}function P(h){return Be(h)&&h.length===s.BYTES}function M(h,p){try{return!!e.fromBytes(h,p)}catch{return!1}}let F={getExtendedPublicKey:x,randomSecretKey:U,isValidSecretKey:P,isValidPublicKey:M,toMontgomery(h){let{y:p}=e.fromBytes(h),_=v.publicKey,L=_===32;if(!L&&_!==57)throw new Error("only defined for 25519 and 448");let T=L?i.div(at+p,at-p):i.div(p-at,p+at);return i.toBytes(T)},toMontgomerySecret(h){let p=v.secretKey;H(h,p);let _=t(h.subarray(0,p));return c(_).subarray(0,p)}};return Object.freeze({keygen:wn(U,E),getPublicKey:E,sign:A,verify:S,utils:F,Point:e,lengths:v})}var Jl=BigInt(1),Da=BigInt(2);var Ql=BigInt(5),td=BigInt(8),pi=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ed={p:pi,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:td,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function rd(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=pi,a=e*e%i*e%i,c=X(a,Da,i)*a%i,f=X(c,Jl,i)*e%i,u=X(f,Ql,i)*f%i,l=X(u,t,i)*u%i,x=X(l,r,i)*l%i,E=X(x,n,i)*x%i,b=X(E,o,i)*E%i,A=X(b,o,i)*E%i,w=X(A,t,i)*u%i;return{pow_p_5_8:X(w,Da,i)*e%i,b2:a}}function nd(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ra=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function od(e,t){let r=pi,n=rt(t*t*t,r),o=rt(n*n*t,r),i=rd(e*o).pow_p_5_8,s=rt(e*n*i,r),a=rt(t*s*s,r),c=s,f=rt(s*Ra,r),u=a===e,l=a===rt(-e,r),x=a===rt(-e*Ra,r);return u&&(s=c),(l||x)&&(s=f),Sa(s,r)&&(s=rt(-s,r)),{isValid:u||l,value:s}}var id=La(ed,{uvRatio:od});function sd(e){return Ua(id,ua,Object.assign({adjustScalarBytes:nd},e))}var Dr=sd({});var Rr=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},Nr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},En=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Na={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new En("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 Et=Na;var Sn=32,kr=64,mi=32;var rr,ka=(async()=>{try{return await Et.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function Ka(){let e=Dr.utils.randomSecretKey(),t=Dr.getPublicKey(e);return{privateKey:ld(e,t),publicKey:t}}async function ad(e,t){let r;e.length===kr?r=e.subarray(0,32):r=e;let n={crv:"Ed25519",kty:"OKP",x:Y(e.subarray(32),"base64url"),d:Y(r,"base64url"),ext:!0,key_ops:["sign"]},o=await Et.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),i=await Et.get().subtle.sign({name:"Ed25519"},o,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(i,0,i.byteLength)}function cd(e,t){let r=e.subarray(0,mi);return Dr.sign(t instanceof Uint8Array?t:t.subarray(),r)}async function Pa(e,t){return rr==null&&(rr=await ka),rr?ad(e,t):cd(e,t)}async function ud(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Et.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Et.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function fd(e,t,r){return Dr.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Oa(e,t,r){return rr==null&&(rr=await ka),rr?ud(e,t,r):fd(e,t,r)}function ld(e,t){let r=new Uint8Array(kr);for(let n=0;n<mi;n++)r[n]=e[n],r[mi+n]=t[n];return r}function nr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Kr=class{type="Ed25519";raw;constructor(t){this.raw=An(t,Sn)}toMultihash(){return Ie.digest(de(this))}toCID(){return ot.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:et(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Oa(this.raw,r,t);return nr(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}},vn=class{type="Ed25519";raw;publicKey;constructor(t,r){this.raw=An(t,kr),this.publicKey=new Kr(r)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:et(this.raw,t.raw)}sign(t,r){r?.signal?.throwIfAborted();let n=Pa(this.raw,t);return nr(n)?n.then(o=>(r?.signal?.throwIfAborted(),o)):(r?.signal?.throwIfAborted(),n)}};function yi(e){return e=An(e,Sn),new Kr(e)}async function Va(){let{privateKey:e,publicKey:t}=Ka();return new vn(e,t)}function An(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new it(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var dd=Math.pow(2,7),hd=Math.pow(2,14),pd=Math.pow(2,21),Fa=Math.pow(2,28),qa=Math.pow(2,35),Ha=Math.pow(2,42),$a=Math.pow(2,49),xt=128,xe=127;function Pr(e){if(e<dd)return 1;if(e<hd)return 2;if(e<pd)return 3;if(e<Fa)return 4;if(e<qa)return 5;if(e<Ha)return 6;if(e<$a)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function za(e,t,r=0){switch(Pr(e)){case 8:t[r++]=e&255|xt,e/=128;case 7:t[r++]=e&255|xt,e/=128;case 6:t[r++]=e&255|xt,e/=128;case 5:t[r++]=e&255|xt,e/=128;case 4:t[r++]=e&255|xt,e>>>=7;case 3:t[r++]=e&255|xt,e>>>=7;case 2:t[r++]=e&255|xt,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Za(e,t){let r=e[t],n=0;if(n+=r&xe,r<xt||(r=e[t+1],n+=(r&xe)<<7,r<xt)||(r=e[t+2],n+=(r&xe)<<14,r<xt)||(r=e[t+3],n+=(r&xe)<<21,r<xt)||(r=e[t+4],n+=(r&xe)*Fa,r<xt)||(r=e[t+5],n+=(r&xe)*qa,r<xt)||(r=e[t+6],n+=(r&xe)*Ha,r<xt)||(r=e[t+7],n+=(r&xe)*$a,r<xt))return n;throw new RangeError("Could not decode varint")}var gi=new Float32Array([-0]),be=new Uint8Array(gi.buffer);function Ya(e,t,r){gi[0]=e,t[r]=be[0],t[r+1]=be[1],t[r+2]=be[2],t[r+3]=be[3]}function Ga(e,t){return be[0]=e[t],be[1]=e[t+1],be[2]=e[t+2],be[3]=e[t+3],gi[0]}var xi=new Float64Array([-0]),pt=new Uint8Array(xi.buffer);function ja(e,t,r){xi[0]=e,t[r]=pt[0],t[r+1]=pt[1],t[r+2]=pt[2],t[r+3]=pt[3],t[r+4]=pt[4],t[r+5]=pt[5],t[r+6]=pt[6],t[r+7]=pt[7]}function Xa(e,t){return pt[0]=e[t],pt[1]=e[t+1],pt[2]=e[t+2],pt[3]=e[t+3],pt[4]=e[t+4],pt[5]=e[t+5],pt[6]=e[t+6],pt[7]=e[t+7],xi[0]}var md=BigInt(Number.MAX_SAFE_INTEGER),yd=BigInt(Number.MIN_SAFE_INTEGER),It=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Ne;if(t<md&&t>yd)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Wa&&(o=0n,++n>Wa&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ne;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):Ne}},Ne=new It(0,0);Ne.toBigInt=function(){return 0n};Ne.zzEncode=Ne.zzDecode=function(){return this};Ne.length=function(){return 1};var Wa=4294967296n;function Ja(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 Qa(e,t,r){if(r-t<1)return"";let o,i=[],s=0,a;for(;t<r;)a=e[t++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function 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 Kt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function In(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var wi=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Kt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Kt(this,4);return In(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Kt(this,4);return In(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Kt(this,4);let t=Ga(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Kt(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 Kt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Qa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Kt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Kt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new It(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Kt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Kt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Kt(this,8);let t=In(this.buf,this.pos+=4),r=In(this.buf,this.pos+=4);return new It(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Za(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 Ei(e){return new wi(e instanceof Uint8Array?e:e.subarray())}function Zt(e,t,r){let n=Ei(e);return t.decode(n,void 0,r)}function Si(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return At(s);o+s>t&&(n=At(t),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var ke=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function vi(){}var Ii=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},gd=Si();function xd(e){return globalThis.Buffer!=null?At(e):gd(e)}var Mr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ke(vi,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ke(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ti((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(Tn,10,It.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=It.fromBigInt(t);return this._push(Tn,r.length(),r)}uint64Number(t){return this._push(za,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 r=It.fromBigInt(t).zzEncode();return this._push(Tn,r.length(),r)}sint64Number(t){let r=It.fromNumber(t).zzEncode();return this._push(Tn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ai,1,t?1:0)}fixed32(t){return this._push(Or,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=It.fromBigInt(t);return this._push(Or,4,r.lo)._push(Or,4,r.hi)}fixed64Number(t){let r=It.fromNumber(t);return this._push(Or,4,r.lo)._push(Or,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Ya,4,t)}double(t){return this._push(ja,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Ai,1,0):this.uint32(r)._push(wd,r,t)}string(t){let r=Ja(t);return r!==0?this.uint32(r)._push(bi,r,t):this._push(Ai,1,0)}fork(){return this.states=new Ii(this),this.head=this.tail=new ke(vi,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new ke(vi,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=xd(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Ai(e,t,r){t[r]=e&255}function bd(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Ti=class extends ke{next;constructor(t,r){super(bd,t,r),this.next=void 0}};function Tn(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 Or(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 wd(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Mr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Ed,t,e),this},Mr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Sd,t,e),this});function Ed(e,t,r){t.set(e,r)}function Sd(e,t,r){e.length<40?bi(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set($(e),r)}function Bi(){return new Mr}function Yt(e,t){let r=Bi();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var or;(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"})(or||(or={}));function Bn(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Vr(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(i,s){let a=t(i);s.int32(a)},n=function(i){let s=i.int32();return t(s)};return Bn("enum",or.VARINT,r,n)}function Gt(e,t){return Bn("message",or.LENGTH_DELIMITED,e,t)}var nt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(nt||(nt={}));var Ci;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Ci||(Ci={}));(function(e){e.codec=()=>Vr(Ci)})(nt||(nt={}));var jt;(function(e){let t;e.codec=()=>(t==null&&(t=Gt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),nt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let a=r.uint32();switch(a>>>3){case 1:{i.Type=nt.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>Yt(r,e.codec()),e.decode=(r,n)=>Zt(r,e.codec(),n)})(jt||(jt={}));var _i;(function(e){let t;e.codec=()=>(t==null&&(t=Gt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),nt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let a=r.uint32();switch(a>>>3){case 1:{i.Type=nt.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>Yt(r,e.codec()),e.decode=(r,n)=>Zt(r,e.codec(),n)})(_i||(_i={}));var qr={};bt(qr,{MAX_RSA_KEY_SIZE:()=>Li,generateRSAKeyPair:()=>Mi,jwkToJWKKeyPair:()=>ic,jwkToPkcs1:()=>Td,jwkToPkix:()=>Ni,jwkToRSAPrivateKey:()=>Oi,pkcs1MessageToJwk:()=>Di,pkcs1MessageToRSAPrivateKey:()=>ki,pkcs1ToJwk:()=>Id,pkcs1ToRSAPrivateKey:()=>oc,pkixMessageToJwk:()=>Ri,pkixMessageToRSAPublicKey:()=>Pi,pkixToJwk:()=>Bd,pkixToRSAPublicKey:()=>Ki});var ir=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=qr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ot.createV1(114,this._multihash)}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:et(this.raw,t.raw)}verify(t,r,n){return nc(this.jwk,r,t,n)}},Fr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=qr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:et(this.raw,t.raw)}sign(t,r){return rc(this.jwk,t,r)}};var Li=8192,Ui=18,vd=1062,Ad=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Id(e){let t=Qt(e);return Di(t)}function Di(e){return{n:Y(e[1],"base64url"),e:Y(e[2],"base64url"),d:Y(e[3],"base64url"),p:Y(e[4],"base64url"),q:Y(e[5],"base64url"),dp:Y(e[6],"base64url"),dq:Y(e[7],"base64url"),qi:Y(e[8],"base64url"),kty:"RSA"}}function Td(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 it("JWK was missing components");return Nt([yt(Uint8Array.from([0])),yt($(e.n,"base64url")),yt($(e.e,"base64url")),yt($(e.d,"base64url")),yt($(e.p,"base64url")),yt($(e.q,"base64url")),yt($(e.dp,"base64url")),yt($(e.dq,"base64url")),yt($(e.qi,"base64url"))]).subarray()}function Bd(e){let t=Qt(e,{offset:0});return Ri(t)}function Ri(e){let t=Qt(e[1],{offset:0});return{kty:"RSA",n:Y(t[0],"base64url"),e:Y(t[1],"base64url")}}function Ni(e){if(e.n==null||e.e==null)throw new it("JWK was missing components");return Nt([Ad,vr(Nt([yt($(e.n,"base64url")),yt($(e.e,"base64url"))]))]).subarray()}function oc(e){let t=Qt(e);return ki(t)}function ki(e){let t=Di(e);return Oi(t)}function Ki(e,t){if(e.byteLength>=vd)throw new Fe("Key size is too large");let r=Qt(e,{offset:0});return Pi(r,e,t)}function Pi(e,t,r){let n=Ri(e);if(r==null){let o=Xe(jt.encode({Type:nt.RSA,Data:t}));r=Ht(Ui,o)}return new ir(n,r)}function Oi(e){if(ac(e)>Li)throw new it("Key size is too large");let t=ic(e),r=Xe(jt.encode({Type:nt.RSA,Data:Ni(t.publicKey)})),n=Ht(Ui,r);return new Fr(t.privateKey,new ir(t.publicKey,n))}async function Mi(e){if(e>Li)throw new it("Key size is too large");let t=await sc(e),r=Xe(jt.encode({Type:nt.RSA,Data:Ni(t.publicKey)})),n=Ht(Ui,r);return new Fr(t.privateKey,new ir(t.publicKey,n))}function ic(e){if(e==null)throw new it("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function sc(e,t){let r=await Et.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 Cd(r,t);return{privateKey:n[0],publicKey:n[1]}}async function rc(e,t,r){let n=await Et.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Et.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 nc(e,t,r,n){let o=await Et.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Et.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),i}async function Cd(e,t){if(e.privateKey==null||e.publicKey==null)throw new it("Private and public key are required");let r=await Promise.all([Et.get().subtle.exportKey("jwk",e.privateKey),Et.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function ac(e){if(e.kty!=="RSA")throw new it("invalid key type");if(e.n==null)throw new it("invalid key modulus");return $(e.n,"base64url").length*8}var Cn=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(hn(t),H(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),ee(o)}update(t){return Ge(this),this.iHash.update(t),this}digestInto(t){Ge(this),H(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=i,t.blockLen=s,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Vi=(e,t,r)=>new Cn(e,t).update(r).digest();Vi.create=(e,t)=>new Cn(e,t);var cc=(e,t)=>(e+(e>=0?t:-t)/uc)/t;function _d(e,t,r){let[[n,o],[i,s]]=t,a=cc(s*e,r),c=cc(-o*e,r),f=e-a*n-c*i,u=-a*o-c*s,l=f<se,x=u<se;l&&(f=-f),x&&(u=-u);let E=_r(Math.ceil(oi(r)/2))+sr;if(f<se||f>=E||u<se||u>=E)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:f,k2neg:x,k2:u}}function qi(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Fi(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return ie(r.lowS,"lowS"),ie(r.prehash,"prehash"),r.format!==void 0&&qi(r.format),r}var Hi=class extends Error{constructor(t=""){super(t)}},we={Err:Hi,_tlv:{encode:(e,t)=>{let{Err:r}=we;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=Br(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?Br(o.length/2|128):"";return Br(e)+i+o+t},decode(e,t){let{Err:r}=we,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)s=s<<8|u;if(n+=c,s<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+s)}}},_int:{encode(e){let{Err:t}=we;if(e<se)throw new t("integer: negative integers are not allowed");let r=Br(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}=we;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 We(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=we,o=H(e,void 0,"signature"),{v:i,l:s}=n.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:f,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=we,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),i=n+o;return t.encode(48,i)}},se=BigInt(0),sr=BigInt(1),uc=BigInt(2),_n=BigInt(3),Ld=BigInt(4);function fc(e,t={}){let r=bn("weierstrass",e,t),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s,n:a}=i;ye(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=t;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=dc(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(T,m,y){let{x:d,y:I}=m.toAffine(),D=n.toBytes(d);if(ie(y,"isCompressed"),y){u();let R=!n.isOdd(I);return wt(lc(R),D)}else return wt(Uint8Array.of(4),D,n.toBytes(I))}function x(T){H(T,void 0,"Point");let{publicKey:m,publicKeyUncompressed:y}=f,d=T.length,I=T[0],D=T.subarray(1);if(d===m&&(I===2||I===3)){let R=n.fromBytes(D);if(!n.isValid(R))throw new Error("bad point: is not on curve, wrong x");let k=A(R),K;try{K=n.sqrt(k)}catch(W){let G=W instanceof Error?": "+W.message:"";throw new Error("bad point: is not on curve, sqrt error"+G)}u();let O=n.isOdd(K);return(I&1)===1!==O&&(K=n.neg(K)),{x:R,y:K}}else if(d===y&&I===4){let R=n.BYTES,k=n.fromBytes(D.subarray(0,R)),K=n.fromBytes(D.subarray(R,R*2));if(!w(k,K))throw new Error("bad point: is not on curve");return{x:k,y:K}}else throw new Error(`bad point: got length ${d}, expected compressed=${m} or uncompressed=${y}`)}let E=t.toBytes||l,b=t.fromBytes||x;function A(T){let m=n.sqr(T),y=n.mul(m,T);return n.add(n.add(y,n.mul(T,i.a)),i.b)}function w(T,m){let y=n.sqr(m),d=A(T);return n.eql(y,d)}if(!w(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(i.a,_n),Ld),B=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(S,B)))throw new Error("bad curve params: a or b");function v(T,m,y=!1){if(!n.isValid(m)||y&&n.is0(m))throw new Error(`bad point coordinate ${T}`);return m}function U(T){if(!(T instanceof p))throw new Error("Weierstrass Point expected")}function P(T){if(!c||!c.basises)throw new Error("no endo");return _d(T,c.basises,o.ORDER)}let M=Je((T,m)=>{let{X:y,Y:d,Z:I}=T;if(n.eql(I,n.ONE))return{x:y,y:d};let D=T.is0();m==null&&(m=D?n.ONE:n.inv(I));let R=n.mul(y,m),k=n.mul(d,m),K=n.mul(I,m);if(D)return{x:n.ZERO,y:n.ZERO};if(!n.eql(K,n.ONE))throw new Error("invZ was invalid");return{x:R,y:k}}),F=Je(T=>{if(T.is0()){if(t.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:m,y}=T.toAffine();if(!n.isValid(m)||!n.isValid(y))throw new Error("bad point: x or y not field elements");if(!w(m,y))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function h(T,m,y,d,I){return y=new p(n.mul(y.X,T),y.Y,y.Z),m=Ur(d,m),y=Ur(I,y),m.add(y)}class p{static BASE=new p(i.Gx,i.Gy,n.ONE);static ZERO=new p(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,y,d){this.X=v("x",m),this.Y=v("y",y,!0),this.Z=v("z",d),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){let{x:y,y:d}=m||{};if(!m||!n.isValid(y)||!n.isValid(d))throw new Error("invalid affine point");if(m instanceof p)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(d)?p.ZERO:new p(y,d,n.ONE)}static fromBytes(m){let y=p.fromAffine(b(H(m,void 0,"point")));return y.assertValidity(),y}static fromHex(m){return p.fromBytes(ne(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,y=!0){return L.createCache(this,m),y||this.multiply(_n),this}assertValidity(){F(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:y,Y:d,Z:I}=this,{X:D,Y:R,Z:k}=m,K=n.eql(n.mul(y,k),n.mul(D,I)),O=n.eql(n.mul(d,k),n.mul(R,I));return K&&O}negate(){return new p(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:y}=i,d=n.mul(y,_n),{X:I,Y:D,Z:R}=this,k=n.ZERO,K=n.ZERO,O=n.ZERO,q=n.mul(I,I),W=n.mul(D,D),G=n.mul(R,R),z=n.mul(I,D);return z=n.add(z,z),O=n.mul(I,R),O=n.add(O,O),k=n.mul(m,O),K=n.mul(d,G),K=n.add(k,K),k=n.sub(W,K),K=n.add(W,K),K=n.mul(k,K),k=n.mul(z,k),O=n.mul(d,O),G=n.mul(m,G),z=n.sub(q,G),z=n.mul(m,z),z=n.add(z,O),O=n.add(q,q),q=n.add(O,q),q=n.add(q,G),q=n.mul(q,z),K=n.add(K,q),G=n.mul(D,R),G=n.add(G,G),q=n.mul(G,z),k=n.sub(k,q),O=n.mul(G,W),O=n.add(O,O),O=n.add(O,O),new p(k,K,O)}add(m){U(m);let{X:y,Y:d,Z:I}=this,{X:D,Y:R,Z:k}=m,K=n.ZERO,O=n.ZERO,q=n.ZERO,W=i.a,G=n.mul(i.b,_n),z=n.mul(y,D),J=n.mul(d,R),ut=n.mul(I,k),qt=n.add(y,d),Q=n.add(D,R);qt=n.mul(qt,Q),Q=n.add(z,J),qt=n.sub(qt,Q),Q=n.add(y,I);let ht=n.add(D,k);return Q=n.mul(Q,ht),ht=n.add(z,ut),Q=n.sub(Q,ht),ht=n.add(d,I),K=n.add(R,k),ht=n.mul(ht,K),K=n.add(J,ut),ht=n.sub(ht,K),q=n.mul(W,Q),K=n.mul(G,ut),q=n.add(K,q),K=n.sub(J,q),q=n.add(J,q),O=n.mul(K,q),J=n.add(z,z),J=n.add(J,z),ut=n.mul(W,ut),Q=n.mul(G,Q),J=n.add(J,ut),ut=n.sub(z,ut),ut=n.mul(W,ut),Q=n.add(Q,ut),z=n.mul(J,Q),O=n.add(O,z),z=n.mul(ht,Q),K=n.mul(qt,K),K=n.sub(K,z),z=n.mul(qt,J),q=n.mul(ht,q),q=n.add(q,z),new p(K,O,q)}subtract(m){return this.add(m.negate())}is0(){return this.equals(p.ZERO)}multiply(m){let{endo:y}=t;if(!o.isValidNot0(m))throw new Error("invalid scalar: out of range");let d,I,D=R=>L.cached(this,R,k=>Re(p,k));if(y){let{k1neg:R,k1:k,k2neg:K,k2:O}=P(m),{p:q,f:W}=D(k),{p:G,f:z}=D(O);I=W.add(z),d=h(y.beta,q,G,R,K)}else{let{p:R,f:k}=D(m);d=R,I=k}return Re(p,[d,I])[0]}multiplyUnsafe(m){let{endo:y}=t,d=this;if(!o.isValid(m))throw new Error("invalid scalar: out of range");if(m===se||d.is0())return p.ZERO;if(m===sr)return d;if(L.hasCache(this))return this.multiply(m);if(y){let{k1neg:I,k1:D,k2neg:R,k2:k}=P(m),{p1:K,p2:O}=_a(p,d,D,k);return h(y.beta,K,O,I,R)}else return L.unsafe(d,m)}toAffine(m){return M(this,m)}isTorsionFree(){let{isTorsionFree:m}=t;return s===sr?!0:m?m(p,this):L.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=t;return s===sr?this:m?m(p,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(m=!0){return ie(m,"isCompressed"),this.assertValidity(),E(p,this,m)}toHex(m=!0){return re(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let _=o.BITS,L=new er(p,t.endo?Math.ceil(_/2):_);return p.BASE.precompute(8),p}function lc(e){return Uint8Array.of(e?2:3)}function dc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Ud(e,t={}){let{Fn:r}=e,n=t.randomBytes||je,o=Object.assign(dc(e.Fp,r),{seed:ci(r.ORDER)});function i(E){try{let b=r.fromBytes(E);return r.isValidNot0(b)}catch{return!1}}function s(E,b){let{publicKey:A,publicKeyUncompressed:w}=o;try{let S=E.length;return b===!0&&S!==A||b===!1&&S!==w?!1:!!e.fromBytes(E)}catch{return!1}}function a(E=n(o.seed)){return ui(H(E,o.seed,"seed"),r.ORDER)}function c(E,b=!0){return e.BASE.multiply(r.fromBytes(E)).toBytes(b)}function f(E){let{secretKey:b,publicKey:A,publicKeyUncompressed:w}=o;if(!Be(E)||"_lengths"in r&&r._lengths||b===A)return;let S=H(E,void 0,"key").length;return S===A||S===w}function u(E,b,A=!0){if(f(E)===!0)throw new Error("first arg must be private key");if(f(b)===!1)throw new Error("second arg must be public key");let w=r.fromBytes(E);return e.fromBytes(b).multiply(w).toBytes(A)}let l={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},x=wn(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:x,Point:e,utils:l,lengths:o})}function hc(e,t,r={}){hn(t),ye(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||je,o=r.hmac||((y,d)=>Vi(t,y,d)),{Fp:i,Fn:s}=e,{ORDER:a,BITS:c}=s,{keygen:f,getPublicKey:u,getSharedSecret:l,utils:x,lengths:E}=Ud(e,r),b={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},A=a*uc<i.ORDER;function w(y){let d=a>>sr;return y>d}function S(y,d){if(!s.isValidNot0(d))throw new Error(`invalid signature ${y}: out of range 1..Point.Fn.ORDER`);return d}function B(){if(A)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function v(y,d){qi(d);let I=E.signature,D=d==="compact"?I:d==="recovered"?I+1:void 0;return H(y,D)}class U{r;s;recovery;constructor(d,I,D){if(this.r=S("r",d),this.s=S("s",I),D!=null){if(B(),![0,1,2,3].includes(D))throw new Error("invalid recovery id");this.recovery=D}Object.freeze(this)}static fromBytes(d,I=b.format){v(d,I);let D;if(I==="der"){let{r:O,s:q}=we.toSig(H(d));return new U(O,q)}I==="recovered"&&(D=d[0],I="compact",d=d.subarray(1));let R=E.signature/2,k=d.subarray(0,R),K=d.subarray(R,R*2);return new U(s.fromBytes(k),s.fromBytes(K),D)}static fromHex(d,I){return this.fromBytes(ne(d),I)}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:I,s:D}=this,R=this.assertRecovery(),k=R===2||R===3?I+a:I;if(!i.isValid(k))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let K=i.toBytes(k),O=e.fromBytes(wt(lc((R&1)===0),K)),q=s.inv(k),W=M(H(d,void 0,"msgHash")),G=s.create(-W*q),z=s.create(D*q),J=e.BASE.multiplyUnsafe(G).add(O.multiplyUnsafe(z));if(J.is0())throw new Error("invalid recovery: point at infinify");return J.assertValidity(),J}hasHighS(){return w(this.s)}toBytes(d=b.format){if(qi(d),d==="der")return ne(we.hexFromSig(this));let{r:I,s:D}=this,R=s.toBytes(I),k=s.toBytes(D);return d==="recovered"?(B(),wt(Uint8Array.of(this.assertRecovery()),R,k)):wt(R,k)}toHex(d){return re(this.toBytes(d))}}let P=r.bits2int||function(d){if(d.length>8192)throw new Error("input is too large");let I=We(d),D=d.length*8-c;return D>0?I>>BigInt(D):I},M=r.bits2int_modN||function(d){return s.create(P(d))},F=_r(c);function h(y){return Cr("num < 2^"+c,y,se,F),s.toBytes(y)}function p(y,d){return H(y,void 0,"message"),d?H(t(y),void 0,"prehashed message"):y}function _(y,d,I){let{lowS:D,prehash:R,extraEntropy:k}=Fi(I,b);y=p(y,R);let K=M(y),O=s.fromBytes(d);if(!s.isValidNot0(O))throw new Error("invalid private key");let q=[h(O),h(K)];if(k!=null&&k!==!1){let J=k===!0?n(E.secretKey):k;q.push(H(J,void 0,"extraEntropy"))}let W=wt(...q),G=K;function z(J){let ut=P(J);if(!s.isValidNot0(ut))return;let qt=s.inv(ut),Q=e.BASE.multiply(ut).toAffine(),ht=s.create(Q.x);if(ht===se)return;let rn=s.create(qt*s.create(G+ht*O));if(rn===se)return;let ds=(Q.x===ht?0:2)|Number(Q.y&sr),hs=rn;return D&&w(rn)&&(hs=s.neg(rn),ds^=1),new U(ht,hs,A?void 0:ds)}return{seed:W,k2sig:z}}function L(y,d,I={}){let{seed:D,k2sig:R}=_(y,d,I);return da(t.outputLen,s.BYTES,o)(D,R).toBytes(I.format)}function T(y,d,I,D={}){let{lowS:R,prehash:k,format:K}=Fi(D,b);if(I=H(I,void 0,"publicKey"),d=p(d,k),!Be(y)){let O=y instanceof U?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+O)}v(y,K);try{let O=U.fromBytes(y,K),q=e.fromBytes(I);if(R&&O.hasHighS())return!1;let{r:W,s:G}=O,z=M(d),J=s.inv(G),ut=s.create(z*J),qt=s.create(W*J),Q=e.BASE.multiplyUnsafe(ut).add(q.multiplyUnsafe(qt));return Q.is0()?!1:s.create(Q.x)===W}catch{return!1}}function m(y,d,I={}){let{prehash:D}=Fi(I,b);return d=p(d,D),U.fromBytes(y,"recovered").recoverPublicKey(d).toBytes()}return Object.freeze({keygen:f,getPublicKey:u,getSharedSecret:l,utils:x,lengths:E,Point:e,sign:L,verify:T,recoverPublicKey:m,Signature:U,hash:t})}var zi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Dd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var pc=BigInt(2);function Rd(e){let t=zi.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=e*e*e%t,u=f*f*e%t,l=X(u,r,t)*u%t,x=X(l,r,t)*u%t,E=X(x,pc,t)*f%t,b=X(E,o,t)*E%t,A=X(b,i,t)*b%t,w=X(A,a,t)*A%t,S=X(w,c,t)*w%t,B=X(S,a,t)*A%t,v=X(B,r,t)*u%t,U=X(v,s,t)*b%t,P=X(U,n,t)*f%t,M=X(P,pc,t);if(!$i.eql($i.sqr(M),e))throw new Error("Cannot find square root");return M}var $i=Qe(zi.p,{sqrt:Rd}),Nd=fc(zi,{Fp:$i,endo:Dd}),Pt=hc(Nd,Xe);function mc(e,t,r){let n=un.digest(t instanceof Uint8Array?t:t.subarray());if(nr(n))return n.then(({digest:o})=>(r?.signal?.throwIfAborted(),Pt.sign(o,e,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new Rr(String(o))});try{return Pt.sign(n.digest,e,{prehash:!1,format:"der"})}catch(o){throw new Rr(String(o))}}function yc(e,t,r,n){let o=un.digest(r instanceof Uint8Array?r:r.subarray());if(nr(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Pt.verify(t,i,e,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new Nr(String(i))});try{return n?.signal?.throwIfAborted(),Pt.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(i){throw new Nr(String(i))}}var Hr=class{type="secp256k1";raw;_key;constructor(t){this._key=bc(t),this.raw=gc(this._key)}toMultihash(){return Ie.digest(de(this))}toCID(){return ot.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:et(this.raw,t.raw)}verify(t,r,n){return yc(this._key,r,t,n)}},Ln=class{type="secp256k1";raw;publicKey;constructor(t,r){this.raw=xc(t),this.publicKey=new Hr(r??wc(t))}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:et(this.raw,t.raw)}sign(t,r){return mc(this.raw,t,r)}};function Zi(e){return new Hr(e)}async function Ec(){let e=kd();return new Ln(e)}function gc(e){return Pt.Point.fromBytes(e).toBytes()}function xc(e){try{return Pt.getPublicKey(e,!0),e}catch(t){throw new yr(String(t))}}function bc(e){try{return Pt.Point.fromBytes(e),e}catch(t){throw new Fe(String(t))}}function wc(e){try{return Pt.getPublicKey(e,!0)}catch(t){throw new yr(String(t))}}function kd(){return Pt.utils.randomSecretKey()}async function Sc(e,t){if(e==="Ed25519")return Va();if(e==="secp256k1")return Ec();if(e==="RSA")return Mi(Kd(t));if(e==="ECDSA")return Gs(Pd(t));throw new qe}function vc(e,t){let{Type:r,Data:n}=jt.decode(e),o=n??new Uint8Array;switch(r){case nt.RSA:return Ki(o,t);case nt.Ed25519:return yi(o);case nt.secp256k1:return Zi(o);case nt.ECDSA:return Zo(o);default:throw new qe}}function Ac(e){let{Type:t,Data:r}=jt.decode(e.digest),n=r??new Uint8Array;switch(t){case nt.Ed25519:return yi(n);case nt.secp256k1:return Zi(n);case nt.ECDSA:return Zo(n);default:throw new qe}}function de(e){return jt.encode({Type:nt[e.type],Data:e.raw})}function Kd(e){return e==null?2048:parseInt(e,10)}function Pd(e){if(e==="P-256"||e==null)return"P-256";if(e==="P-384")return"P-384";if(e==="P-521")return"P-521";throw new it("Unsupported curve, should be P-256, P-384 or P-521")}function Od(e,t){if(typeof e=="string")return Md(e);if(typeof e=="number")return qd(e,t);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(e)}`)}var Un=Od;function Md(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 Vd(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 Fd(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 qd(e,t){if(typeof e!="number"||!Number.isFinite(e))throw Error("Value provided to ms.format() must be of type number.");return t?.long?Fd(e):Vd(e)}function Ke(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function Yi(e){r.debug=r,r.default=r,r.coerce=c,r.disable=i,r.enable=o,r.enabled=s,r.humanize=Un,r.destroy=f,Object.keys(e).forEach(u=>{r[u]=e[u]}),r.names=[],r.skips=[],r.formatters={};function t(u){let l=0;for(let x=0;x<u.length;x++)l=(l<<5)-l+u.charCodeAt(x),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=t;function r(u){let l,x=null,E,b;function A(...w){if(!A.enabled)return;let S=A,B=Number(new Date),v=B-(l||B);S.diff=v,S.prev=l,S.curr=B,l=B,w[0]=r.coerce(w[0]),typeof w[0]!="string"&&w.unshift("%O");let U=0;w[0]=w[0].replace(/%([a-zA-Z%])/g,(M,F)=>{if(M==="%%")return"%";U++;let h=r.formatters[F];if(typeof h=="function"){let p=w[U];M=h.call(S,p),w.splice(U,1),U--}return M}),r.formatArgs.call(S,w),(S.log||r.log).apply(S,w)}return A.namespace=u,A.useColors=r.useColors(),A.color=r.selectColor(u),A.extend=n,A.destroy=r.destroy,Object.defineProperty(A,"enabled",{enumerable:!0,configurable:!1,get:()=>x!==null?x:(E!==r.namespaces&&(E=r.namespaces,b=r.enabled(u)),b),set:w=>{x=w}}),typeof r.init=="function"&&r.init(A),A}function n(u,l){let x=r(this.namespace+(typeof l>"u"?":":l)+u);return x.log=this.log,x}function o(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];let l,x=(typeof u=="string"?u:"").split(/[\s,]+/),E=x.length;for(l=0;l<E;l++)x[l]&&(u=x[l].replace(/\*/g,".*?"),u[0]==="-"?r.skips.push(new RegExp("^"+u.substr(1)+"$")):r.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...r.names.map(a),...r.skips.map(a).map(l=>"-"+l)].join(",");return r.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let l,x;for(l=0,x=r.skips.length;l<x;l++)if(r.skips[l].test(u))return!1;for(l=0,x=r.names.length;l<x;l++)if(r.names[l].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function c(u){return u instanceof Error?u.stack??u.message:u}function f(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var Dn=jd(),Hd=["#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 $d(){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 zd(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+Un(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 Zd=console.debug??console.log??(()=>{});function Yd(e){try{e?Dn?.setItem("debug",e):Dn?.removeItem("debug")}catch{}}function Gd(){let e;try{e=Dn?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function jd(){try{return localStorage}catch{}}function Xd(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Ic=Yi({formatArgs:zd,save:Yd,load:Gd,useColors:$d,setupFormatters:Xd,colors:Hd,storage:Dn,log:Zd});var St=Ic;St.formatters.b=e=>e==null?"undefined":j.baseEncode(e);St.formatters.t=e=>e==null?"undefined":fe.baseEncode(e);St.formatters.m=e=>e==null?"undefined":Ro.baseEncode(e);St.formatters.p=e=>e==null?"undefined":e.toString();St.formatters.c=e=>e==null?"undefined":e.toString();St.formatters.k=e=>e==null?"undefined":e.toString();St.formatters.a=e=>e==null?"undefined":e.toString();St.formatters.e=e=>e==null?"undefined":Tc(e.stack)??Tc(e.message)??e.toString();function Wd(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 Pe(e){let t=Wd(`${e}:trace`);return St.enabled(`${e}:trace`)&&St.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(t=St(`${e}:trace`)),Object.assign(St(e),{error:St(`${e}:error`),trace:t,newScope:r=>Pe(`${e}:${r}`)})}function Tc(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var Mu=xo(Rn(),1);var Nn=class extends Error{static name="SignatureCreationError";constructor(t="Record signature creation failed"){super(t),this.name="SignatureCreationError"}},Ot=class extends Error{static name="SignatureVerificationError";constructor(t="Record signature verification failed"){super(t),this.name="SignatureVerificationError"}},kn=class extends Error{static name="RecordExpiredError";constructor(t="Record has expired"){super(t),this.name="RecordExpiredError"}},Oe=class extends Error{static name="UnsupportedValidityError";constructor(t="The validity type is unsupported"){super(t),this.name="UnsupportedValidityError"}},Kn=class extends Error{static name="RecordTooLargeError";constructor(t="The record is too large"){super(t),this.name="RecordTooLargeError"}},$r=class extends Error{static name="InvalidValueError";constructor(t="Value must be a valid content path starting with /"){super(t),this.name="InvalidValueError"}},Pn=class extends Error{static name="InvalidRecordDataError";constructor(t="Invalid record data"){super(t),this.name="InvalidRecordDataError"}},zr=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(t="Invalid embedded public key"){super(t),this.name="InvalidEmbeddedPublicKeyError"}};var lt;(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=()=>Vr(r)})(t=e.ValidityType||(e.ValidityType={}));let n;e.codec=()=>(n==null&&(n=Gt((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.value!=null&&(i.uint32(10),i.bytes(o.value)),o.signatureV1!=null&&(i.uint32(18),i.bytes(o.signatureV1)),o.validityType!=null&&(i.uint32(24),e.ValidityType.codec().encode(o.validityType,i)),o.validity!=null&&(i.uint32(34),i.bytes(o.validity)),o.sequence!=null&&(i.uint32(40),i.uint64(o.sequence)),o.ttl!=null&&(i.uint32(48),i.uint64(o.ttl)),o.pubKey!=null&&(i.uint32(58),i.bytes(o.pubKey)),o.signatureV2!=null&&(i.uint32(66),i.bytes(o.signatureV2)),o.data!=null&&(i.uint32(74),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let f=o.uint32();switch(f>>>3){case 1:{a.value=o.bytes();break}case 2:{a.signatureV1=o.bytes();break}case 3:{a.validityType=e.ValidityType.codec().decode(o);break}case 4:{a.validity=o.bytes();break}case 5:{a.sequence=o.uint64();break}case 6:{a.ttl=o.uint64();break}case 7:{a.pubKey=o.bytes();break}case 8:{a.signatureV2=o.bytes();break}case 9:{a.data=o.bytes();break}default:{o.skipType(f&7);break}}}return a})),n),e.encode=o=>Yt(o,e.codec()),e.decode=(o,i)=>Zt(o,e.codec(),i)})(lt||(lt={}));var On=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Jd=["string","number","bigint","symbol"],Qd=["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 Bc(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(Jd.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(th(e))return"Buffer";let r=eh(e);return r||"Object"}function th(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function eh(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(Qd.includes(t))return t}var g=class{constructor(t,r,n){this.major=t,this.majorEncoded=t<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}};g.uint=new g(0,"uint",!0);g.negint=new g(1,"negint",!0);g.bytes=new g(2,"bytes",!0);g.string=new g(3,"string",!0);g.array=new g(4,"array",!1);g.map=new g(5,"map",!1);g.tag=new g(6,"tag",!1);g.float=new g(7,"float",!0);g.false=new g(7,"false",!0);g.true=new g(7,"true",!0);g.null=new g(7,"null",!0);g.undefined=new g(7,"undefined",!0);g.break=new g(7,"break",!0);var N=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var ar=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",rh=new TextDecoder,nh=new TextEncoder;function Mn(e){return ar&&globalThis.Buffer.isBuffer(e)}function ji(e){return e instanceof Uint8Array?Mn(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Uc=ar?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):_c(e,t,r):(e,t,r)=>r-t>64?rh.decode(e.subarray(t,r)):_c(e,t,r),Dc=ar?e=>e.length>64?globalThis.Buffer.from(e):Cc(e):e=>e.length>64?nh.encode(e):Cc(e),Xt=e=>Uint8Array.from(e),cr=ar?(e,t,r)=>Mn(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Rc=ar?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),ji(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},Nc=ar?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function kc(e,t){if(Mn(e)&&Mn(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 Cc(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 _c(e,t,r){let n=[];for(;t<r;){let o=e[t],i=null,s=o>239?4:o>223?3:o>191?2:1;if(t+s<=r){let a,c,f,u;switch(s){case 1:o<128&&(i=o);break;case 2:a=e[t+1],(a&192)===128&&(u=(o&31)<<6|a&63,u>127&&(i=u));break;case 3:a=e[t+1],c=e[t+2],(a&192)===128&&(c&192)===128&&(u=(o&15)<<12|(a&63)<<6|c&63,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:a=e[t+1],c=e[t+2],f=e[t+3],(a&192)===128&&(c&192)===128&&(f&192)===128&&(u=(o&15)<<18|(a&63)<<12|(c&63)<<6|f&63,u>65535&&u<1114112&&(i=u))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=s}return oh(n)}var Lc=4096;function oh(e){let t=e.length;if(t<=Lc)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Lc));return r}var ih=256,Zr=class{constructor(t=ih){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=Nc(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=cr(n,0,this.cursor)}else r=Rc(this.chunks,this.cursor);return t&&this.reset(),r}};var V="CBOR decode error:",Xi="CBOR encode error:",Yr=[];Yr[23]=1;Yr[24]=2;Yr[25]=3;Yr[26]=5;Yr[27]=9;function ae(e,t,r){if(e.length-t<r)throw new Error(`${V} not enough data for type`)}var ct=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Tt(e,t,r){ae(e,t,1);let n=e[t];if(r.strict===!0&&n<ct[0])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function Bt(e,t,r){ae(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<ct[1])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function Ct(e,t,r){ae(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<ct[2])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function _t(e,t,r){ae(e,t,8);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<ct[3])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${V} integers outside of the safe integer range are not supported`)}function Kc(e,t,r,n){return new N(g.uint,Tt(e,t+1,n),2)}function Pc(e,t,r,n){return new N(g.uint,Bt(e,t+1,n),3)}function Oc(e,t,r,n){return new N(g.uint,Ct(e,t+1,n),5)}function Mc(e,t,r,n){return new N(g.uint,_t(e,t+1,n),9)}function Ut(e,t){return dt(e,0,t.value)}function dt(e,t,r){if(r<ct[0]){let n=Number(r);e.push([t|n])}else if(r<ct[1]){let n=Number(r);e.push([t|24,n])}else if(r<ct[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<ct[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<ct[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,e.push(o)}else throw new Error(`${V} encountered BigInt larger than allowable range`)}}Ut.encodedSize=function(t){return dt.encodedSize(t.value)};dt.encodedSize=function(t){return t<ct[0]?1:t<ct[1]?2:t<ct[2]?3:t<ct[3]?5:9};Ut.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function Vc(e,t,r,n){return new N(g.negint,-1-Tt(e,t+1,n),2)}function Fc(e,t,r,n){return new N(g.negint,-1-Bt(e,t+1,n),3)}function qc(e,t,r,n){return new N(g.negint,-1-Ct(e,t+1,n),5)}var Wi=BigInt(-1),Hc=BigInt(1);function $c(e,t,r,n){let o=_t(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new N(g.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${V} integers outside of the safe integer range are not supported`);return new N(g.negint,Wi-BigInt(o),9)}function Vn(e,t){let r=t.value,n=typeof r=="bigint"?r*Wi-Hc:r*-1-1;dt(e,t.type.majorEncoded,n)}Vn.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*Wi-Hc:r*-1-1;return n<ct[0]?1:n<ct[1]?2:n<ct[2]?3:n<ct[3]?5:9};Vn.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function Gr(e,t,r,n){ae(e,t,r+n);let o=cr(e,t+r,t+r+n);return new N(g.bytes,o,r+n)}function zc(e,t,r,n){return Gr(e,t,1,r)}function Zc(e,t,r,n){return Gr(e,t,2,Tt(e,t+1,n))}function Yc(e,t,r,n){return Gr(e,t,3,Bt(e,t+1,n))}function Gc(e,t,r,n){return Gr(e,t,5,Ct(e,t+1,n))}function jc(e,t,r,n){let o=_t(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer bytes lengths not supported`);return Gr(e,t,9,o)}function Fn(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===g.string?Dc(e.value):e.value),e.encodedBytes}function ur(e,t){let r=Fn(t);dt(e,t.type.majorEncoded,r.length),e.push(r)}ur.encodedSize=function(t){let r=Fn(t);return dt.encodedSize(r.length)+r.length};ur.compareTokens=function(t,r){return ah(Fn(t),Fn(r))};function ah(e,t){return e.length<t.length?-1:e.length>t.length?1:kc(e,t)}function jr(e,t,r,n,o){let i=r+n;ae(e,t,i);let s=new N(g.string,Uc(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=cr(e,t+r,t+i)),s}function Xc(e,t,r,n){return jr(e,t,1,r,n)}function Wc(e,t,r,n){return jr(e,t,2,Tt(e,t+1,n),n)}function Jc(e,t,r,n){return jr(e,t,3,Bt(e,t+1,n),n)}function Qc(e,t,r,n){return jr(e,t,5,Ct(e,t+1,n),n)}function tu(e,t,r,n){let o=_t(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer string lengths not supported`);return jr(e,t,9,o,n)}var eu=ur;function fr(e,t,r,n){return new N(g.array,n,r)}function ru(e,t,r,n){return fr(e,t,1,r)}function nu(e,t,r,n){return fr(e,t,2,Tt(e,t+1,n))}function ou(e,t,r,n){return fr(e,t,3,Bt(e,t+1,n))}function iu(e,t,r,n){return fr(e,t,5,Ct(e,t+1,n))}function su(e,t,r,n){let o=_t(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer array lengths not supported`);return fr(e,t,9,o)}function au(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return fr(e,t,1,1/0)}function qn(e,t){dt(e,g.array.majorEncoded,t.value)}qn.compareTokens=Ut.compareTokens;qn.encodedSize=function(t){return dt.encodedSize(t.value)};function lr(e,t,r,n){return new N(g.map,n,r)}function cu(e,t,r,n){return lr(e,t,1,r)}function uu(e,t,r,n){return lr(e,t,2,Tt(e,t+1,n))}function fu(e,t,r,n){return lr(e,t,3,Bt(e,t+1,n))}function lu(e,t,r,n){return lr(e,t,5,Ct(e,t+1,n))}function du(e,t,r,n){let o=_t(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer map lengths not supported`);return lr(e,t,9,o)}function hu(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return lr(e,t,1,1/0)}function Hn(e,t){dt(e,g.map.majorEncoded,t.value)}Hn.compareTokens=Ut.compareTokens;Hn.encodedSize=function(t){return dt.encodedSize(t.value)};function pu(e,t,r,n){return new N(g.tag,r,1)}function mu(e,t,r,n){return new N(g.tag,Tt(e,t+1,n),2)}function yu(e,t,r,n){return new N(g.tag,Bt(e,t+1,n),3)}function gu(e,t,r,n){return new N(g.tag,Ct(e,t+1,n),5)}function xu(e,t,r,n){return new N(g.tag,_t(e,t+1,n),9)}function $n(e,t){dt(e,g.tag.majorEncoded,t.value)}$n.compareTokens=Ut.compareTokens;$n.encodedSize=function(t){return dt.encodedSize(t.value)};var hh=20,ph=21,mh=22,yh=23;function bu(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${V} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new N(g.null,null,1):new N(g.undefined,void 0,1)}function wu(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return new N(g.break,void 0,1)}function Ji(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${V} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${V} Infinity values are not supported`)}return new N(g.float,e,t)}function Eu(e,t,r,n){return Ji(Qi(e,t+1),3,n)}function Su(e,t,r,n){return Ji(ts(e,t+1),5,n)}function vu(e,t,r,n){return Ji(Bu(e,t+1),9,n)}function zn(e,t,r){let n=t.value;if(n===!1)e.push([g.float.majorEncoded|hh]);else if(n===!0)e.push([g.float.majorEncoded|ph]);else if(n===null)e.push([g.float.majorEncoded|mh]);else if(n===void 0)e.push([g.float.majorEncoded|yh]);else{let o,i=!1;(!r||r.float64!==!0)&&(Iu(n),o=Qi(Mt,1),n===o||Number.isNaN(n)?(Mt[0]=249,e.push(Mt.slice(0,3)),i=!0):(Tu(n),o=ts(Mt,1),n===o&&(Mt[0]=250,e.push(Mt.slice(0,5)),i=!0))),i||(gh(n),o=Bu(Mt,1),Mt[0]=251,e.push(Mt.slice(0,9)))}}zn.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){Iu(n);let o=Qi(Mt,1);if(n===o||Number.isNaN(n))return 3;if(Tu(n),o=ts(Mt,1),n===o)return 5}return 9};var Au=new ArrayBuffer(9),Dt=new DataView(Au,1),Mt=new Uint8Array(Au,0);function Iu(e){if(e===1/0)Dt.setUint16(0,31744,!1);else if(e===-1/0)Dt.setUint16(0,64512,!1);else if(Number.isNaN(e))Dt.setUint16(0,32256,!1);else{Dt.setFloat32(0,e);let t=Dt.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)Dt.setUint16(0,31744,!1);else if(r===0)Dt.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Dt.setUint16(0,0):o<-14?Dt.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):Dt.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Qi(e,t){if(e.length-t<2)throw new Error(`${V} not enough data for float16`);let r=(e[t]<<8)+e[t+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Tu(e){Dt.setFloat32(0,e,!1)}function ts(e,t){if(e.length-t<4)throw new Error(`${V} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function gh(e){Dt.setFloat64(0,e,!1)}function Bu(e,t){if(e.length-t<8)throw new Error(`${V} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}zn.compareTokens=Ut.compareTokens;function Z(e,t,r){throw new Error(`${V} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Zn(e){return()=>{throw new Error(`${V} ${e}`)}}var C=[];for(let e=0;e<=23;e++)C[e]=Z;C[24]=Kc;C[25]=Pc;C[26]=Oc;C[27]=Mc;C[28]=Z;C[29]=Z;C[30]=Z;C[31]=Z;for(let e=32;e<=55;e++)C[e]=Z;C[56]=Vc;C[57]=Fc;C[58]=qc;C[59]=$c;C[60]=Z;C[61]=Z;C[62]=Z;C[63]=Z;for(let e=64;e<=87;e++)C[e]=zc;C[88]=Zc;C[89]=Yc;C[90]=Gc;C[91]=jc;C[92]=Z;C[93]=Z;C[94]=Z;C[95]=Zn("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)C[e]=Xc;C[120]=Wc;C[121]=Jc;C[122]=Qc;C[123]=tu;C[124]=Z;C[125]=Z;C[126]=Z;C[127]=Zn("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)C[e]=ru;C[152]=nu;C[153]=ou;C[154]=iu;C[155]=su;C[156]=Z;C[157]=Z;C[158]=Z;C[159]=au;for(let e=160;e<=183;e++)C[e]=cu;C[184]=uu;C[185]=fu;C[186]=lu;C[187]=du;C[188]=Z;C[189]=Z;C[190]=Z;C[191]=hu;for(let e=192;e<=215;e++)C[e]=pu;C[216]=mu;C[217]=yu;C[218]=gu;C[219]=xu;C[220]=Z;C[221]=Z;C[222]=Z;C[223]=Z;for(let e=224;e<=243;e++)C[e]=Zn("simple values are not supported");C[244]=Z;C[245]=Z;C[246]=Z;C[247]=bu;C[248]=Zn("simple values are not supported");C[249]=Eu;C[250]=Su;C[251]=vu;C[252]=Z;C[253]=Z;C[254]=Z;C[255]=wu;var Vt=[];for(let e=0;e<24;e++)Vt[e]=new N(g.uint,e,1);for(let e=-1;e>=-24;e--)Vt[31-e]=new N(g.negint,e,1);Vt[64]=new N(g.bytes,new Uint8Array(0),1);Vt[96]=new N(g.string,"",1);Vt[128]=new N(g.array,0,1);Vt[160]=new N(g.map,0,1);Vt[244]=new N(g.false,!1,1);Vt[245]=new N(g.true,!0,1);Vt[246]=new N(g.null,null,1);function Cu(e){switch(e.type){case g.false:return Xt([244]);case g.true:return Xt([245]);case g.null:return Xt([246]);case g.bytes:return e.value.length?void 0:Xt([64]);case g.string:return e.value===""?Xt([96]):void 0;case g.array:return e.value===0?Xt([128]):void 0;case g.map:return e.value===0?Xt([160]):void 0;case g.uint:return e.value<24?Xt([Number(e.value)]):void 0;case g.negint:if(e.value>=-24)return Xt([31-Number(e.value)])}}var bh={float64:!1,mapSorter:Sh,quickEncodeToken:Cu};function wh(){let e=[];return e[g.uint.major]=Ut,e[g.negint.major]=Vn,e[g.bytes.major]=ur,e[g.string.major]=eu,e[g.array.major]=qn,e[g.map.major]=Hn,e[g.tag.major]=$n,e[g.float.major]=zn,e}var _u=wh(),es=new Zr,Gn=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(`${Xi} object contains circular references`);return new e(r,t)}},Ee={null:new N(g.null,null),undefined:new N(g.undefined,void 0),true:new N(g.true,!0),false:new N(g.false,!1),emptyArray:new N(g.array,0),emptyMap:new N(g.map,0)},Se={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new N(g.float,e):e>=0?new N(g.uint,e):new N(g.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new N(g.uint,e):new N(g.negint,e)},Uint8Array(e,t,r,n){return new N(g.bytes,e)},string(e,t,r,n){return new N(g.string,e)},boolean(e,t,r,n){return e?Ee.true:Ee.false},null(e,t,r,n){return Ee.null},undefined(e,t,r,n){return Ee.undefined},ArrayBuffer(e,t,r,n){return new N(g.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new N(g.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[Ee.emptyArray,new N(g.break)]:Ee.emptyArray;n=Gn.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=Yn(s,r,n);return r.addBreakTokens?[new N(g.array,e.length),o,new N(g.break)]:[new N(g.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),s=o?e.size:i.length;if(!s)return r.addBreakTokens===!0?[Ee.emptyMap,new N(g.break)]:Ee.emptyMap;n=Gn.createCheck(n,e);let a=[],c=0;for(let f of i)a[c++]=[Yn(f,r,n),Yn(o?e.get(f):e[f],r,n)];return Eh(a,r),r.addBreakTokens?[new N(g.map,s),a,new N(g.break)]:[new N(g.map,s),a]}};Se.Map=Se.Object;Se.Buffer=Se.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Se[`${e}Array`]=Se.DataView;function Yn(e,t={},r){let n=Bc(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||Se[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=Se[n];if(!i)throw new Error(`${Xi} unsupported type: ${n}`);return i(e,n,t,r)}function Eh(e,t){t.mapSorter&&e.sort(t.mapSorter)}function Sh(e,t){let r=Array.isArray(e[0])?e[0][0]:e[0],n=Array.isArray(t[0])?t[0][0]:t[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=_u[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Lu(e,t,r,n){if(Array.isArray(t))for(let o of t)Lu(e,o,r,n);else r[t.type.major](e,t,n)}function vh(e,t,r){let n=Yn(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),a=new Zr(s);if(i(a,n,r),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return ji(a.chunks[0])}}return es.reset(),Lu(es,n,t,r),es.toBytes(!0)}function rs(e,t){return t=Object.assign({},bh,t),vh(e,_u,t)}var Ah={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},jn=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=Vt[t];if(r===void 0){let n=C[t];if(!n)throw new Error(`${V} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},Xr=Symbol.for("DONE"),Xn=Symbol.for("BREAK");function Ih(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=dr(t,r);if(i===Xn){if(e.value===1/0)break;throw new Error(`${V} got unexpected break to lengthed array`)}if(i===Xr)throw new Error(`${V} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function Th(e,t,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<e.value;s++){let a=dr(t,r);if(a===Xn){if(e.value===1/0)break;throw new Error(`${V} got unexpected break to lengthed map`)}if(a===Xr)throw new Error(`${V} found map but not enough entries (got ${s} [no key], expected ${e.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${V} non-string keys not supported (got ${typeof a})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${V} found repeat map key "${a}"`);let c=dr(t,r);if(c===Xr)throw new Error(`${V} found map but not enough entries (got ${s} [no value], expected ${e.value})`);n?i.set(a,c):o[a]=c}return n?i:o}function dr(e,t){if(e.done())return Xr;let r=e.next();if(r.type===g.break)return Xn;if(r.type.terminal)return r.value;if(r.type===g.array)return Ih(r,e,t);if(r.type===g.map)return Th(r,e,t);if(r.type===g.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=dr(e,t);return t.tags[r.value](n)}throw new Error(`${V} tag not supported (${r.value})`)}throw new Error("unsupported")}function Uu(e,t){if(!(e instanceof Uint8Array))throw new Error(`${V} data to decode must be a Uint8Array`);t=Object.assign({},Ah,t);let r=t.tokenizer||new jn(e,t),n=dr(r,t);if(n===Xr)throw new Error(`${V} did not find any content to decode`);if(n===Xn)throw new Error(`${V} got unexpected break`);return[n,e.subarray(r.pos())]}function ns(e,t){let[r,n]=Uu(e,t);if(n.length>0)throw new Error(`${V} too many terminals, data makes no sense`);return r}var Ch=Pe("ipns:utils"),Du=$("/ipns/"),_h=114,Lh=0,Uh=18;function Ru(e){let t;if(e.pubKey!=null)try{t=vc(e.pubKey)}catch(r){throw Ch.error(r),r}if(t!=null)return t}function Nu(e,t,r){let n=$(t);return le([e,r,n])}function Jn(e){let t=$("ipns-signature:");return le([t,e])}function Qn(e){return"signatureV1"in e?lt.encode({value:$(e.value),signatureV1:e.signatureV1,validityType:e.validityType,validity:$(e.validity),sequence:e.sequence,ttl:e.ttl,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data}):lt.encode({pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data})}function Ft(e){let t=lt.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 Ot("Missing data or signatureV2");let r=Pu(t.data),n=Dh(r.Value),o=Y(r.Validity);if(t.value!=null&&t.signatureV1!=null)return Rh(t),{value:n,validityType:lt.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:lt.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 Ve(e){return le([Du,e.bytes])}function ku(e){let t=Ye(e.slice(Du.length));if(!Wn(t,Lh)&&!Wn(t,Uh))throw new On("Multihash in IPNS key was not identity or sha2-256");return t}function Ku(e,t,r,n,o){let i;if(t===lt.ValidityType.EOL)i=0;else throw new Oe("The validity type is unsupported");return rs({Value:e,Validity:r,ValidityType:i,Sequence:n,TTL:o})}function Pu(e){let t=ns(e);if(t.ValidityType===0)t.ValidityType=lt.ValidityType.EOL;else throw new Oe("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 Dh(e){let t=Y(e).trim();if(t.startsWith("/"))return t;try{return`/ipfs/${ot.decode(e).toV1().toString()}`}catch{}try{return`/ipfs/${ot.parse(t).toV1().toString()}`}catch{}throw new $r("Value must be a valid content path starting with /")}function Ou(e){if(e!=null){let t=Kh(e);if(t!=null)return t.code===_h?`/ipns/${t.toString(Rt)}`:`/ipfs/${t.toV1().toString()}`;if(Nh(e))return`/ipns/${Rt.encode(e.bytes)}`;let r=e.toString().trim();if(r.startsWith("/")&&r.length>1)return r}throw new $r("Value must be a valid content path starting with /")}function Rh(e){if(e.data==null)throw new Pn("Record data is missing");let t=Pu(e.data);if(!et(t.Value,e.value??new Uint8Array(0)))throw new Ot('Field "value" did not match between protobuf and CBOR');if(!et(t.Validity,e.validity??new Uint8Array(0)))throw new Ot('Field "validity" did not match between protobuf and CBOR');if(t.ValidityType!==e.validityType)throw new Ot('Field "validityType" did not match between protobuf and CBOR');if(t.Sequence!==e.sequence)throw new Ot('Field "sequence" did not match between protobuf and CBOR');if(t.TTL!==e.ttl)throw new Ot('Field "ttl" did not match between protobuf and CBOR')}function Nh(e){return e.bytes instanceof Uint8Array}function kh(e){return typeof e?.toCID=="function"}function Kh(e){if(kh(e))return e.toCID();try{return ot.parse(e)}catch{}return ot.asCID(e)}function Wn(e,t){return e.code===t}var to=Pe("ipns:validator"),Ph=1024*10;async function Oh(e,t){let r=Ft(t),n;try{let o=Jn(r.data);n=await e.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw to.error("record signature verification failed"),new Ot("Record signature verification failed");if(r.validityType===lt.ValidityType.EOL){if(Mu.default.fromString(r.validity).toDate().getTime()<Date.now())throw to.error("record has expired"),new kn("record has expired")}else if(r.validityType!=null)throw to.error("the validity type is unsupported"),new Oe("The validity type is unsupported");to("ipns record for %s is valid",r.value)}async function Wr(e,t){if(t.byteLength>Ph)throw new Kn("The record is too large");let r=ku(e),n;Wn(r,0)&&(n=Ac(r));let o=Ft(t),i=Ru(o)??n;if(i==null)throw new zr("Could not extract public key from IPNS record or routing key");let s=Ve(i.toMultihash());if(!et(s,e))throw new zr("Embedded public key did not match routing key");await Oh(i,t)}function hr(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var eo=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},pr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new eo(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new eo(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var os=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Vu(e={}){return Mh(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function Mh(e,t){t=t??{};let r=t.onEnd,n=new pr,o,i,s,a=hr(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((w,S)=>{i=B=>{i=null,n.push(B);try{w(e(n))}catch(v){S(v)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=hr()})}},f=w=>i!=null?i(w):(n.push(w),o),u=w=>(n=new pr,i!=null?i({error:w}):(n.push({error:w}),o)),l=w=>{if(s)return o;if(t?.objectMode!==!0&&w?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:w})},x=w=>s?o:(s=!0,w!=null?u(w):f({done:!0})),E=()=>(n=new pr,x(),{done:!0}),b=w=>(x(w),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:E,throw:b,push:l,end:x,get readableLength(){return n.size},onEmpty:async w=>{let S=w?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let B,v;S!=null&&(B=new Promise((U,P)=>{v=()=>{P(new os)},S.addEventListener("abort",v)}));try{await Promise.race([a.promise,B])}finally{v!=null&&S!=null&&S?.removeEventListener("abort",v)}}},r==null)return o;let A=o;return o={[Symbol.asyncIterator](){return this},next(){return A.next()},throw(w){return A.throw(w),r!=null&&(r(w),r=void 0),{done:!0}},return(){return A.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(w){return A.end(w),r!=null&&(r(w),r=void 0),o},get readableLength(){return A.readableLength},onEmpty:w=>A.onEmpty(w)},o}var is=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},ss=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},Fu=e=>globalThis.DOMException===void 0?new ss(e):new DOMException(e),qu=e=>{let t=e.reason===void 0?Fu("This operation was aborted."):e.reason;return t instanceof Error?t:Fu(t)};function as(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=t,s,a,f=new Promise((u,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:E}=t;E.aborted&&l(qu(E)),a=()=>{l(qu(E))},E.addEventListener("abort",a,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(u,l);return}let x=new is;s=i.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(E){l(E)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?u():o instanceof Error?l(o):(x.message=o??`Promise timed out after ${r} milliseconds`,l(x))},r),(async()=>{try{u(await e)}catch(E){l(E)}})()}).finally(()=>{f.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return f.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},f}var Vh=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function Fh(e,t,r){let n,o=new Promise((i,s)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:f,removeListener:u}=Vh(e),l=async(...E)=>{let b=r.multiArgs?E:E[0];if(r.filter)try{if(!await r.filter(b))return}catch(A){n(),s(A);return}c.push(b),r.count===c.length&&(n(),i(c))},x=(...E)=>{n(),s(r.rejectionMultiArgs?E:E[0])};n=()=>{for(let E of a)u(E,l);for(let E of r.rejectionEvents)a.includes(E)||u(E,x)};for(let E of a)f(E,l);for(let E of r.rejectionEvents)a.includes(E)||f(E,x);r.signal&&r.signal.addEventListener("abort",()=>{x(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(o.cancel=n,typeof r.timeout=="number"){let i=as(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function ro(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Fh(e,t,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function Jr(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var no=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};function qh(e){return e.reason}async function Hu(e,t,r){if(t==null)return e;let n=r?.translateError??qh;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((i,s)=>{o=()=>{s(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var oo=class{deferred;signal;constructor(t){this.signal=t,this.deferred=hr(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Wt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Hh(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var io=class{id;fn;options;recipients;status;timeline;controller;constructor(t,r){this.id=Hh(),this.status="queued",this.fn=t,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Wt),this.cleanup())}async join(t={}){let r=new oo(t.signal);return this.recipients.push(r),t.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await Hu(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(r=>{r.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};var so=class extends sn{concurrency;maxSize;queue;pending;sort;paused;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,t.metricName!=null&&t.metrics?.registerMetricGroup(t.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=t.sort,this.queue=[],this.emitEmpty=Jr(this.emitEmpty.bind(this),1),this.emitIdle=Jr(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let r of this.queue)if(r.status==="queued"){t=r;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===t){this.queue.splice(r,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new no;let n=new io(t,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new Wt)}),this.clear()}async onEmpty(t){this.size!==0&&await ro(this,"empty",t)}async onSizeLessThan(t,r){this.size<t||await ro(this,"next",{...r,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await ro(this,"idle",t)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let r=Vu({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail)},i=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new Wt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",i),this.addEventListener("idle",s),t?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),t?.signal?.removeEventListener("abort",a),n()}}};function $u(e){let t=new globalThis.AbortController;function r(){t.abort();for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}for(let i of e){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=t.signal;return o.clear=n,o}function zu(e,t,r){let n,o,i=!1;function s(){let f={signal:o.signal};if(r?.timeout!=null){let u=$u([o.signal,AbortSignal.timeout(r.timeout)]);f.signal=u}i=!0,Promise.resolve().then(async()=>{await e(f)}).catch(()=>{}).finally(()=>{i=!1,!o.signal.aborted&&(n=setTimeout(s,t))})}let a=Jr(s,r?.debounce??100),c=!1;return{setInterval:f=>{t!==f&&(t=f,n!=null&&(clearTimeout(n),n=setTimeout(s,t)))},setTimeout:f=>{r??={},r.timeout=f},run:()=>{i||(clearTimeout(n),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,t))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var Zu=xo(Rn(),1);var $h=Pe("ipns"),Yu=300*1e9,zh="/ipns/",Cb=zh.length,Gu={v1Compatible:!0,ttlNs:Yu};async function cs(e,t,r,n,o=Gu){let i=new Zu.default(Date.now()+Number(n)),s=lt.ValidityType.EOL,a=BigInt(o.ttlNs??Yu);return Zh(e,t,r,s,i.toString(),a,o)}var Zh=async(e,t,r,n,o,i,s=Gu)=>{r=BigInt(r);let a=$(o),c=Ou(t),f=$(c),u=Ku(f,n,a,r,i),l=Jn(u),x=await e.sign(l),E;if(e.type==="RSA"&&(E=de(e.publicKey)),s.v1Compatible===!0){let b=await Yh(e,f,n,a),A={value:c,signatureV1:b,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:x,data:u};return E!=null&&(A.pubKey=E),A}else{let b={value:c,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:x,data:u};return E!=null&&(b.pubKey=E),b}},Yh=async(e,t,r,n)=>{try{let o=Nu(t,r,n);return await e.sign(o)}catch(o){throw $h.error("record signature creation failed",o),new Nn("Record signature creation failed")}};var us=xo(Rn(),1);function ao(e,t){let r=t.map((n,o)=>({record:Ft(n),index:o}));return r.sort((n,o)=>{let i=n.record.sequence,s=o.record.sequence;if(i>s)return-1;if(i<s)return 1;if(n.record.validityType===lt.ValidityType.EOL&&o.record.validityType===lt.ValidityType.EOL){let a=us.default.fromString(n.record.validity).toDate(),c=us.default.fromString(o.record.validity).toDate();if(a.getTime()>c.getTime())return-1;if(a.getTime()<c.getTime())return 1}return 0}),r[0].index}var vt=class extends Event{type;detail;constructor(t,r){super(t),this.type=t,this.detail=r}};var co=BigInt(6e4)*5000000n,ju=5;var uo=class extends Error{static name="RecordsFailedValidationError";constructor(t="Records failed validation"){super(t),this.name="RecordsFailedValidationError"}},fo=class extends Error{static name="UnsupportedMultibasePrefixError";constructor(t="Unsupported multibase prefix"){super(t),this.name="UnsupportedMultibasePrefixError"}},lo=class extends Error{static name="UnsupportedMultihashCodecError";constructor(t="Unsupported multihash codec"){super(t),this.name="UnsupportedMultihashCodecError"}},ho=class extends Error{static name="InvalidValueError";constructor(t="Invalid value"){super(t),this.name="InvalidValueError"}};var Qr;(function(e){let t;e.codec=()=>(t==null&&(t=Gt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.key!=null&&r.key.byteLength>0&&(n.uint32(10),n.bytes(r.key)),r.value!=null&&r.value.byteLength>0&&(n.uint32(18),n.bytes(r.value)),r.timeReceived!=null&&r.timeReceived!==""&&(n.uint32(42),n.string(r.timeReceived)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={key:Lt(0),value:Lt(0),timeReceived:""},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let a=r.uint32();switch(a>>>3){case 1:{i.key=r.bytes();break}case 2:{i.value=r.bytes();break}case 5:{i.timeReceived=r.string();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>Yt(r,e.codec()),e.decode=(r,n)=>Zt(r,e.codec(),n)})(Qr||(Qr={}));function Xu(e){let t=e.getUTCFullYear(),r=String(e.getUTCMonth()+1).padStart(2,"0"),n=String(e.getUTCDate()).padStart(2,"0"),o=String(e.getUTCHours()).padStart(2,"0"),i=String(e.getUTCMinutes()).padStart(2,"0"),s=String(e.getUTCSeconds()).padStart(2,"0"),a=e.getUTCMilliseconds(),c=String(a*1e3*1e3).padStart(9,"0");return`${t}-${r}-${n}T${o}:${i}:${s}.${c}Z`}function Wu(e){let t=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),r=String(e).trim().match(t);if(r==null)throw new Error("Invalid format");let n=parseInt(r[1],10),o=parseInt(r[2],10)-1,i=parseInt(r[3],10),s=parseInt(r[4],10),a=parseInt(r[5],10),c=parseInt(r[6],10),f=parseInt(r[7].slice(0,-6),10);return new Date(Date.UTC(n,o,i,s,a,c,f))}var ve=class e{key;value;timeReceived;constructor(t,r,n){if(!(t instanceof Uint8Array))throw new Error("key must be a Uint8Array");if(!(r instanceof Uint8Array))throw new Error("value must be a Uint8Array");this.key=t,this.value=r,this.timeReceived=n}serialize(){return Qr.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:Xu(this.timeReceived)}}static deserialize(t){let r=Qr.decode(t);return new e(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(t){let r=Wu(t.timeReceived);if(t.key==null)throw new Error("key missing from deserialized object");if(t.value==null)throw new Error("value missing from deserialized object");return new e(t.key,t.value,r)}};var ce="/",Ju=new TextEncoder().encode(ce),po=Ju[0],mr=class e{_buf;constructor(t,r){if(typeof t=="string")this._buf=$(t);else if(t instanceof Uint8Array)this._buf=t;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==po)throw new Error("Invalid key")}toString(t="utf8"){return Y(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new e(t.join(ce))}static random(){return new e(Math.random().toString().substring(2))}static asKey(t){return t instanceof Uint8Array||typeof t=="string"?new e(t):typeof t.uint8Array=="function"?new e(t.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Ju),this._buf[0]!==po){let t=new Uint8Array(this._buf.byteLength+1);t.fill(po,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===po;)this._buf=this._buf.subarray(0,-1)}less(t){let r=this.list(),n=t.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let i=r[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return r.length<n.length}reverse(){return e.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(ce).slice(1)}type(){return jh(this.baseNamespace())}name(){return Xh(this.baseNamespace())}instance(t){return new e(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(ce)||(t+=ce),t+=this.type(),new e(t)}parent(){let t=this.list();return t.length===1?new e(ce):new e(t.slice(0,-1).join(ce))}child(t){return this.toString()===ce?t:t.toString()===ce?this:new e(this.toString()+t.toString(),!1)}isAncestorOf(t){return t.toString()===this.toString()?!1:t.toString().startsWith(this.toString())}isDecendantOf(t){return t.toString()===this.toString()?!1:this.toString().startsWith(t.toString())}isTopLevel(){return this.list().length===1}concat(...t){return e.withNamespaces([...this.namespaces(),...Wh(t.map(r=>r.namespaces()))])}};function jh(e){let t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Xh(e){let t=e.split(":");return t[t.length-1]}function Wh(e){return[].concat(...e)}var Qu;(function(e){e[e.SEND_QUERY=0]="SEND_QUERY",e[e.PEER_RESPONSE=1]="PEER_RESPONSE",e[e.FINAL_PEER=2]="FINAL_PEER",e[e.QUERY_ERROR=3]="QUERY_ERROR",e[e.PROVIDER=4]="PROVIDER",e[e.VALUE=5]="VALUE",e[e.ADD_PEER=6]="ADD_PEER",e[e.DIAL_PEER=7]="DIAL_PEER",e[e.PATH_ENDED=8]="PATH_ENDED"})(Qu||(Qu={}));var tn;(function(e){let t;e.codec=()=>(t==null&&(t=Gt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.keyName!=null&&r.keyName!==""&&(n.uint32(10),n.string(r.keyName)),r.lifetime!=null&&r.lifetime!==0&&(n.uint32(16),n.uint32(r.lifetime)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={keyName:"",lifetime:0},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let a=r.uint32();switch(a>>>3){case 1:{i.keyName=r.string();break}case 2:{i.lifetime=r.uint32();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>Yt(r,e.codec()),e.decode=(r,n)=>Zt(r,e.codec(),n)})(tn||(tn={}));var tf=0,ef=18;function fs(e,t){return e.code===t}var mo="/dht/record/",Qh="/ipns/metadata/";function en(e){return new mr(mo+Y(e,"base32"),!1)}function yo(e){return new mr(Qh+Y(e,"base32"),!1)}function rf(e,t){let r=Date.now(),n=t.getTime()+1728e5,o=new Date(e.validity).getTime();return n-r<864e5||o-r<864e5}function nf(e,t){return{async put(r,n,o={}){try{let i=en(r);try{let c=await e.get(i),f=ve.deserialize(c);if(et(f.value,n))return}catch(c){if(c.name!=="NotFoundError")throw c}let s=new ve(r,n,new Date);o.onProgress?.(new vt("ipns:routing:datastore:put"));let a=e.batch();a.put(i,s.serialize()),o.metadata!=null&&a.put(yo(r),tn.encode(o.metadata)),await a.commit(o)}catch(i){throw o.onProgress?.(new vt("ipns:routing:datastore:error",i)),i}},async get(r,n={}){try{let o=en(r);n.onProgress?.(new vt("ipns:routing:datastore:get"));let i=await e.get(o,n),s=ve.deserialize(i);return{record:s.value,created:s.timeReceived}}catch(o){throw n.onProgress?.(new vt("ipns:routing:datastore:error",o)),o}},async has(r,n={}){let o=en(r);return e.has(o,n)},async delete(r,n){let o=en(r),i=e.batch();i.delete(o),i.delete(yo(r)),await i.commit(n)},async*list(r={}){try{r.onProgress?.(new vt("ipns:routing:datastore:list"));for await(let{key:n,value:o}of e.query({prefix:mo},r))try{let i=ve.deserialize(o),a=n.toString().substring(mo.length),c=$(a,"base32"),f=yo(c),u;try{let l=await e.get(f,r);u=tn.decode(l)}catch(l){t.error("Error deserializing metadata for %s - %e",a,l)}yield{routingKey:c,metadata:u,record:i.value,created:i.timeReceived}}catch(i){t.error("Error deserializing record - %e",i)}}catch(n){throw r.onProgress?.(new vt("ipns:routing:datastore:error",n)),n}}}}var ls=class{routing;constructor(t){this.routing=t}async put(t,r,n={}){try{await this.routing.put(t,r,n)}catch(o){throw n.onProgress?.(new vt("ipns:routing:helia:error",o)),o}}async get(t,r={}){try{return await this.routing.get(t,r)}catch(n){throw r.onProgress?.(new vt("ipns:routing:helia:error",n)),n}}};function of(e){return new ls(e)}function sf(e){return{async put(t,r,n){await e.put(t,r,n)},async get(t,r){let{record:n}=await e.get(t,r);return n}}}var af={[Rt.prefix]:Rt,[j.prefix]:j},go=class{routers;localStore;republishTask;log;keychain;started=!1;republishConcurrency;constructor(t,r={}){this.log=t.logger.forComponent("helia:ipns"),this.localStore=nf(t.datastore,t.logger.forComponent("helia:ipns:local-store")),this.keychain=t.libp2p.services.keychain,this.republishConcurrency=r.republishConcurrency||ju,this.started=t.libp2p.status==="started",this.routers=[sf(this.localStore),of(t.routing),...r.routers??[]],t.events.addEventListener("start",this.start.bind(this)),t.events.addEventListener("stop",this.stop.bind(this)),this.republishTask=zu(this.#r.bind(this),r.republishInterval??36e5,{runImmediately:!0}),this.started&&this.republishTask.start()}start(){this.started||(this.started=!0,this.republishTask.start())}stop(){this.started&&(this.started=!1,this.republishTask.stop())}#t(){if(!this.started)throw new on("Helia is stopped, cannot perform IPNS operations")}async publish(t,r,n={}){this.#t();try{let o=await this.#e(t),i=1n,s=Ve(o.publicKey.toMultihash());if(await this.localStore.has(s,n)){let{record:l}=await this.localStore.get(s,n);i=Ft(l).sequence+1n}let a=n.ttl!=null?BigInt(n.ttl)*1000000n:co,c=n.lifetime??1728e5,f=await cs(o,r,i,c,{...n,ttlNs:a}),u=Qn(f);return n.offline===!0?await this.localStore.put(s,u,{...n,metadata:{keyName:t,lifetime:c}}):await Promise.all(this.routers.map(async l=>{await l.put(s,u,{...n,metadata:{keyName:t,lifetime:c}})})),{record:f,publicKey:o.publicKey}}catch(o){throw n.onProgress?.(new vt("ipns:publish:error",o)),o}}async resolve(t,r={}){this.#t();let n=ms(t)?t.toMultihash():t,o=Ve(n),i=await this.#o(o,r);return{...await this.#n(i.value,r),record:i}}async#e(t){try{return await this.keychain.exportKey(t)}catch{let n=await Sc("Ed25519");return await this.keychain.importKey(t,n),n}}async#r(t={}){if(!this.started)return;this.log("starting ipns republish records loop");let r=new so({concurrency:this.republishConcurrency});try{let n=[];for await(let{routingKey:o,record:i,metadata:s,created:a}of this.localStore.list(t)){if(s==null){this.log(`no metadata found for record ${o.toString()}, skipping`);continue}let c;try{c=Ft(i)}catch(x){this.log.error("error unmarshaling record - %e",x);continue}if(!rf(c,a)){this.log.trace(`skipping record ${o.toString()}within republish threshold`);continue}let f=c.sequence+1n,u=c.ttl??co,l;try{l=await this.keychain.exportKey(s.keyName)}catch(x){this.log.error(`missing key ${s.keyName}, skipping republishing record`,x);continue}try{let x=await cs(l,c.value,f,s.lifetime,{...t,ttlNs:u});n.push({routingKey:o,record:x})}catch(x){this.log.error(`error creating updated IPNS record for ${o.toString()}`,x);continue}}this.log(`found ${n.length} records to republish`);for(let{routingKey:o,record:i}of n)r.add(async()=>{try{let s=Qn(i);await Promise.all(this.routers.map(a=>a.put(o,s,t)))}catch(s){this.log.error("error republishing record - %e",s)}},t)}catch(n){this.log.error("error during republish - %e",n)}await r.onIdle(t)}async unpublish(t,r){let{publicKey:n}=await this.keychain.exportKey(t),o=n.toMultihash(),i=Ve(o);await this.localStore.delete(i,r)}async#n(t,r={}){let n=t.split("/");try{let o=n[1];if(o==="ipns"){let i=n[2],s=i.substring(0,1),a;if(s==="1"||s==="Q")a=j.decode(`z${i}`);else if(af[s]!=null)a=af[s].decode(i);else throw new fo(`Unsupported multibase prefix "${s}"`);let c;try{c=Ye(a)}catch{c=ot.decode(a).multihash}if(!fs(c,tf)&&!fs(c,ef))throw new lo(`Unsupported multihash codec "${c.code}"`);let{cid:f}=await this.resolve(c,r),u=n.slice(3).join("/");return{cid:f,path:u}}else if(o==="ipfs"){let i=ot.parse(n[2]),s=n.slice(3).join("/");return{cid:i,path:s}}}catch(o){this.log.error("error parsing ipfs path - %e",o)}throw this.log.error("invalid ipfs path %s",t),new ho("Invalid value")}async#o(t,r={}){let n=[];if(await this.localStore.has(t,r))if(this.log("record is present in the cache"),r.nocache!==!0)try{let{record:a,created:c}=await this.localStore.get(t,r);this.log("record retrieved from cache"),await Wr(t,a),this.log("record was valid");let f=Ft(a),u=Number((f.ttl??co)/1000000n);if(c.getTime()+u>Date.now())return this.log("record TTL was valid"),f;if(r.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),f;this.log("record TTL has been reached, searching routing for updates"),n.push(a)}catch(a){this.log("cached record was invalid - %e",a),await this.localStore.delete(t,r)}else this.log("ignoring local cache due to nocache=true option");if(r.offline===!0)throw new gr("Record was not present in the cache or has expired");this.log("did not have record locally");let i=0;if(await Promise.all(this.routers.map(async a=>{let c;try{c=await a.get(t,{...r,validate:!1})}catch(f){this.log.error("error finding IPNS record - %e",f);return}try{await Wr(t,c),n.push(c)}catch(f){i++,this.log.error("error finding IPNS record - %e",f)}})),n.length===0)throw i>0?new uo(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`):new gr("Could not find record for routing key");let s=n[ao(t,n)];return await this.localStore.put(t,s,r),Ft(s)}};function r0(e,t={}){return new go(e,t)}return pf(n0);})();
2
+ "use strict";var HeliaIpns=(()=>{var ff=Object.create;var nn=Object.defineProperty;var lf=Object.getOwnPropertyDescriptor;var df=Object.getOwnPropertyNames;var hf=Object.getPrototypeOf,pf=Object.prototype.hasOwnProperty;var mf=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),bt=(e,t)=>{for(var r in t)nn(e,r,{get:t[r],enumerable:!0})},gs=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of df(t))!pf.call(e,o)&&o!==r&&nn(e,o,{get:()=>t[o],enumerable:!(n=lf(t,o))||n.enumerable});return e};var xo=(e,t,r)=>(r=e!=null?ff(hf(e)):{},gs(t||!e||!e.__esModule?nn(r,"default",{value:e,enumerable:!0}):r,e)),yf=e=>gs(nn({},"__esModule",{value:!0}),e);var Rn=mf((Dg,ji)=>{var Lg=(function(){typeof ji<"u"&&(ji.exports=A);var e=86400,t=3200,r=146097*t/400,n=e*r,o=1e3*n,i=864e13,s=4294967296,a=1e6,c="000000000",f=Math.trunc||function(h){var p=h-h%1;return p==0&&(h<0||h===0&&1/h!=1/0)?-0:p},u=A.prototype,l=(A.fromDate=function(h){return new A(+h)},A.fromInt64BE=D(0,1,2,3,0,4),A.fromInt64LE=D(3,2,1,0,4,0),A.fromString=function(L){var p,_=new A,L=(L+="").replace(/^\s*[+\-]?\d+/,function(m){var m=+m,y=1970+(m-1970)%400;return _.year=m-y,y}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(T,m,y){return m<0&&(y*=-1),p=6e4*(60*+m+ +y),""}).replace(/\.\d+$/,function(T){return _.nano=+(T+c).substr(1,9),""}).split(/\D+/);if(1<L.length?L[1]--:L[1]=0,_.time=p=Date.UTC.apply(Date,L)-(p||0),isNaN(p))throw new TypeError("Invalid Date");return w(_)},A.fromTimeT=function(h){return B(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=w(this);return(h.time%1e3*a+ +h.nano+1e9)%1e9},u.getTimeT=function(){var p=w(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 S(w(this).time)},u.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},u.toString=function(h){var p=this,_=p.toDate(),L={H:function(){return M(_.getUTCHours())},L:function(){return F(_.getUTCMilliseconds(),3)},M:function(){return M(_.getUTCMinutes())},N:function(){return F(p.getNano(),9)},S:function(){return M(_.getUTCSeconds())},Y:function(){var T=p.getYear();return 999999<T?"+"+T:9999<T?"+"+F(T,6):0<=T?F(T,4):-999999<=T?"-"+F(-T,6):T},a:function(){return E[_.getUTCDay()]},b:function(){return x[_.getUTCMonth()]},d:function(){return M(_.getUTCDate())},e:function(){return(function(T){return(9<T?"":" ")+(0|T)})(_.getUTCDate())},m:function(){return M(_.getUTCMonth()+1)}};return(function T(m){return m.replace(/%./g,function(y){var I=y[1],d=b[I],I=L[I];return d?T(d):I?I():y})})(h||l)},u.writeInt64BE=v(0,1,2,3,0,4),u.writeInt64LE=v(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),x=["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 A;function A(h,p,_){var L=this;if(!(L instanceof A))return new A(h,p,_);L.time=+h||0,L.nano=+p||0,L.year=+_||0,w(L)}function w(h){var p,_,L,T=h.year,m=h.time,y=h.nano,d=((y<0||a<=y)&&(y-=(_=Math.floor(y/a))*a,m+=_,_=1),T%t);return(m<-i||i<m||d)&&((p=f(m/o))&&(T+=p*t,m-=p*o),(L=S(m)).setUTCFullYear(d+L.getUTCFullYear()),L=(m=+L)+(p=f((T-=d)/t))*o,p&&-i<=L&&L<=i&&(T-=p*t,m=L),_=1),_&&(h.year=T,h.time=m,h.nano=y),h}function S(h){var p=new Date(0);return p.setTime(h),p}function B(T,L){T=+T||0;var _=f((L=(L|0)*s)/n)+f(T/n),L=L%n+T%n,T=f(L/n);return T&&(_+=T,L-=T*n),new A(1e3*L,0,_*t)}function v(h,p,_,L,T,m){return function(d,I){var R=w(this);d=d||new Array(8),P(d,I|=0);var k=Math.floor(R.time/1e3),R=R.year*(r*e/t),U=f(R/s)+f(k/s),R=R%s+k%s,k=Math.floor(R/s);return k&&(U+=k,R-=k*s),y(d,I+T,U),y(d,I+m,R),d};function y(d,I,U){d[I+h]=U>>24&255,d[I+p]=U>>16&255,d[I+_]=U>>8&255,d[I+L]=255&U}}function D(h,p,_,L,T,m){return function(d,I){P(d,I|=0);var U=y(d,I+T);return B(y(d,I+m),U)};function y(d,I){return 16777216*d[I+h]+(d[I+p]<<16|d[I+_]<<8|d[I+L])}}function P(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 F(h,p){return(c+(0|h)).substr(-p)}})()});var c0={};bt(c0,{ipns:()=>a0,ipnsSelector:()=>ao,ipnsValidator:()=>Wr});var Wt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var tt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Fe=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},yr=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var gr=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var on=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var qe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};function xs(e){return e==null?!1:(e.type==="RSA"||e.type==="Ed25519"||e.type==="secp256k1"||e.type==="ECDSA")&&e.raw instanceof Uint8Array&&typeof e.equals=="function"&&typeof e.toMultihash=="function"&&typeof e.toCID=="function"&&typeof e.verify=="function"}var gf=Symbol.for("@libp2p/peer-id");function bo(e){return!!e?.[gf]}var sn=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){super.addEventListener(t,r,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:i})=>i!==r),this.#t.set(t,o))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var Ao={};bt(Ao,{base58btc:()=>j,base58flickr:()=>Af});var p0=new Uint8Array(0);function bs(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Jt(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 ws(e){return new TextEncoder().encode(e)}function Es(e){return new TextDecoder().decode(e)}function xf(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=e.length,c=e.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(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 A=0,w=0,S=0,B=b.length;S!==B&&b[S]===0;)S++,A++;for(var v=(B-S)*u+1>>>0,D=new Uint8Array(v);S!==B;){for(var P=b[S],M=0,F=v-1;(P!==0||M<w)&&F!==-1;F--,M++)P+=256*D[F]>>>0,D[F]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");w=M,S++}for(var h=v-w;h!==v&&D[h]===0;)h++;for(var p=c.repeat(A);h<v;++h)p+=e.charAt(D[h]);return p}function x(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var A=0;if(b[A]!==" "){for(var w=0,S=0;b[A]===c;)w++,A++;for(var B=(b.length-A)*f+1>>>0,v=new Uint8Array(B);b[A];){var D=r[b.charCodeAt(A)];if(D===255)return;for(var P=0,M=B-1;(D!==0||P<S)&&M!==-1;M--,P++)D+=a*v[M]>>>0,v[M]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");S=P,A++}if(b[A]!==" "){for(var F=B-S;F!==B&&v[F]===0;)F++;for(var h=new Uint8Array(w+(B-F)),p=w;F!==B;)h[p++]=v[F++];return h}}}function E(b){var A=x(b);if(A)return A;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:x,decode:E}}var bf=xf,wf=bf,vs=wf;var wo=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Eo=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 As(this,t)}},So=class{decoders;constructor(t){this.decoders=t}or(t){return As(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 As(e,t){return new So({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var vo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new wo(t,r,n),this.decoder=new Eo(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function He({name:e,prefix:t,encode:r,decode:n}){return new vo(e,t,r,n)}function ue({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=vs(r,e);return He({prefix:t,name:e,encode:n,decode:i=>Jt(o(i))})}function Ef(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let f=0;f<o;++f){let u=t[e[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Sf(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],s+=8;s>r;)s-=r,i+=t[o&a>>s];if(s!==0&&(i+=t[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function vf(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function et({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=vf(n);return He({prefix:t,name:e,encode(i){return Sf(i,n,r)},decode(i){return Ef(i,o,r,e)}})}var j=ue({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Af=ue({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Io={};bt(Io,{base32:()=>fe,base32hex:()=>Cf,base32hexpad:()=>Lf,base32hexpadupper:()=>Df,base32hexupper:()=>_f,base32pad:()=>Tf,base32padupper:()=>Bf,base32upper:()=>If,base32z:()=>Uf});var fe=et({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),If=et({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Tf=et({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Bf=et({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Cf=et({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),_f=et({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Lf=et({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Df=et({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Uf=et({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var To={};bt(To,{base36:()=>Rt,base36upper:()=>Rf});var Rt=ue({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Rf=ue({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Nf=Bs,Is=128,kf=127,Kf=~kf,Pf=Math.pow(2,31);function Bs(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Pf;)t[r++]=e&255|Is,e/=128;for(;e&Kf;)t[r++]=e&255|Is,e>>>=7;return t[r]=e|0,Bs.bytes=r-n+1,t}var Of=Bo,Mf=128,Ts=127;function Bo(e,n){var r=0,n=n||0,o=0,i=n,s,a=e.length;do{if(i>=a)throw Bo.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&Ts)<<o:(s&Ts)*Math.pow(2,o),o+=7}while(s>=Mf);return Bo.bytes=i-n,r}var Vf=Math.pow(2,7),Ff=Math.pow(2,14),qf=Math.pow(2,21),Hf=Math.pow(2,28),$f=Math.pow(2,35),zf=Math.pow(2,42),Zf=Math.pow(2,49),Yf=Math.pow(2,56),Gf=Math.pow(2,63),jf=function(e){return e<Vf?1:e<Ff?2:e<qf?3:e<Hf?4:e<$f?5:e<zf?6:e<Zf?7:e<Yf?8:e<Gf?9:10},Xf={encode:Nf,decode:Of,encodingLength:jf},Wf=Xf,xr=Wf;function br(e,t=0){return[xr.decode(e,t),xr.decode.bytes]}function $e(e,t,r=0){return xr.encode(e,t,r),t}function ze(e){return xr.encodingLength(e)}function Ht(e,t){let r=t.byteLength,n=ze(e),o=n+ze(r),i=new Uint8Array(o+r);return $e(e,i,0),$e(r,i,n),i.set(t,o),new Ze(e,r,t,i)}function Ye(e){let t=Jt(e),[r,n]=br(t),[o,i]=br(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Ze(r,o,s,t)}function Cs(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&bs(e.bytes,r.bytes)}}var Ze=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function _s(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Qf(r,Co(e),t??j.encoder);default:return tl(r,Co(e),t??fe.encoder)}}var Ls=new WeakMap;function Co(e){let t=Ls.get(e);if(t==null){let r=new Map;return Ls.set(e,r),r}return t}var it=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!==wr)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=Ht(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Cs(t.multihash,n.multihash)}toString(t){return _s(this,t)}toJSON(){return{"/":_s(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new e(n,o,i,s??Ds(n,o,i.bytes))}else if(r[rl]===!0){let{version:n,multihash:o,code:i}=r,s=Ye(o);return e.create(n,i,s)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==wr)throw new Error(`Version 0 CID must use dag-pb (code: ${wr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Ds(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,wr,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=Jt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new Ze(r.multihashCode,r.digestSize,i,o);return[r.version===0?e.createV0(s):e.createV1(r.codec,s),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,x]=br(t.subarray(r));return r+=x,l},o=n(),i=wr;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),f=r+c,u=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(t,r){let[n,o]=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 Co(i).set(n,t),i}};function Jf(e,t){switch(e[0]){case"Q":{let r=t??j;return[j.prefix,r.decode(`${j.prefix}${e}`)]}case j.prefix:{let r=t??j;return[j.prefix,r.decode(e)]}case fe.prefix:{let r=t??fe;return[fe.prefix,r.decode(e)]}case Rt.prefix:{let r=t??Rt;return[Rt.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!==j.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 wr=112,el=18;function Ds(e,t,r){let n=ze(e),o=n+ze(t),i=new Uint8Array(o+r.byteLength);return $e(e,i,0),$e(t,i,n),i.set(r,o),i}var rl=Symbol.for("@ipld/js-cid/CID");var _o={};bt(_o,{identity:()=>Ie});var Us=0,nl="identity",Rs=Jt;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 Ht(Us,Rs(e))}var Ie={code:Us,name:nl,encode:Rs,digest:ol};function rt(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 Lt(e=0){return new Uint8Array(e)}function At(e=0){return new Uint8Array(e)}function le(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=At(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var ks=Symbol.for("@achingbrain/uint8arraylist");function Ns(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 cn(e){return!!e?.[ks]}var mt=class e{bufs;length;[ks]=!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(cn(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(cn(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=Ns(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Ns(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(cn(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 le(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:le(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),i=new e;return i.length=o,i.bufs=[...n],i}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,u=r>a&&r<=c;if(f&&u){if(t===a&&r===c){n.push(s);break}let l=t-a;n.push(s.subarray(l,l+(r-t)));break}if(f){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(u){if(r===c){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!cn(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=r;l<=c;l+=u){u=0;for(let x=f;x>=0;x--){let E=this.get(l+x);if(n[x]!==E){u=Math.max(1,x-a[E]);break}}if(u===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=At(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=Lt(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=Lt(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=Lt(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=At(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=Lt(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=Lt(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=Lt(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=Lt(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=Lt(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(!rt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};var Lo={};bt(Lo,{base10:()=>il});var il=ue({prefix:"9",name:"base10",alphabet:"0123456789"});var Do={};bt(Do,{base16:()=>sl,base16upper:()=>al});var sl=et({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),al=et({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Uo={};bt(Uo,{base2:()=>cl});var cl=et({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ro={};bt(Ro,{base256emoji:()=>hl});var Ks=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=Ks.reduce((e,t,r)=>(e[r]=t,e),[]),fl=Ks.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=He({prefix:"\u{1F680}",name:"base256emoji",encode:ll,decode:dl});var ko={};bt(ko,{base64:()=>No,base64pad:()=>pl,base64url:()=>ml,base64urlpad:()=>yl});var No=et({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),pl=et({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ml=et({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),yl=et({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ko={};bt(Ko,{base8:()=>gl});var gl=et({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Po={};bt(Po,{identity:()=>xl});var xl=He({prefix:"\0",name:"identity",encode:e=>Es(e),decode:e=>ws(e)});var W0=new TextEncoder,J0=new TextDecoder;var Vo={};bt(Vo,{sha256:()=>un,sha512:()=>Sl});var El=20;function Mo({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Oo(e,t,r,n,o)}var Oo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??El,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?Ps(n,this.code,r?.truncate):n.then(o=>Ps(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ps(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Ht(t,e)}function Ms(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var un=Mo({name:"sha2-256",code:18,encode:Ms("SHA-256")}),Sl=Mo({name:"sha2-512",code:19,encode:Ms("SHA-512")});var Fo={...Po,...Uo,...Ko,...Lo,...Do,...Io,...To,...Ao,...ko,...Ro},fp={...Vo,..._o};function Fs(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Vs=Fs("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),qo=Fs("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=At(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),vl={utf8:Vs,"utf-8":Vs,hex:Fo.base16,latin1:qo,ascii:qo,binary:qo,...Fo},fn=vl;function $(e,t="utf8"){let r=fn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function Y(e,t="utf8"){let r=fn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Al=parseInt("11111",2),Ho=parseInt("10000000",2),Il=parseInt("01111111",2),qs={0:Er,1:Er,2:Tl,3:_l,4:Ll,5:Cl,6:Bl,16:Er,22:Er,48:Er};function Qt(e,t={offset:0}){let r=e[t.offset]&Al;if(t.offset++,qs[r]!=null)return qs[r](e,t);throw new Error("No decoder for tag "+r)}function Sr(e,t){let r=0;if((e[t.offset]&Ho)===Ho){let n=e[t.offset]&Il,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 Er(e,t){Sr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Qt(e,t);if(n===null)break;r.push(n)}return r}function Tl(e,t){let r=Sr(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 Bl(e,t){let r=Sr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;t.offset<n;){let f=e[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let l=0;l<c.length;l++)u+=c[l]<<l*7;a+=`.${u}`,c=[]}}return a}function Cl(e,t){return t.offset++,null}function _l(e,t){let r=Sr(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 Ll(e,t){let r=Sr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Dl(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new mt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function ln(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Dl(e.byteLength);return new mt(Uint8Array.from([t.byteLength|Ho]),t)}function yt(e){let t=new mt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new mt(Uint8Array.from([2]),ln(t),t)}function vr(e){let t=Uint8Array.from([0]),r=new mt(t,e);return new mt(Uint8Array.from([3]),ln(r),r)}function Hs(e){return new mt(Uint8Array.from([4]),ln(e),e)}function Nt(e,t=48){let r=new mt;for(let n of e)r.append(n);return new mt(Uint8Array.from([t]),ln(r),r)}async function $s(e="P-256"){let t=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:e},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",t.publicKey),privateKey:await crypto.subtle.exportKey("jwk",t.privateKey)}}async function zs(e,t,r){let n=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["sign"]);r?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Zs(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 Ul=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Rl=Uint8Array.from([6,5,43,129,4,0,34]),Nl=Uint8Array.from([6,5,43,129,4,0,35]),kl={ext:!0,kty:"EC",crv:"P-256"},Kl={ext:!0,kty:"EC",crv:"P-384"},Pl={ext:!0,kty:"EC",crv:"P-521"},$o=32,zo=48,Zo=66;function Yo(e){let t=Qt(e);return Ys(t)}function Ys(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===$o*2+1)return n=Y(t.subarray(r,r+$o),"base64url"),o=Y(t.subarray(r+$o),"base64url"),new Te({...kl,key_ops:["verify"],x:n,y:o});if(t.byteLength===zo*2+1)return n=Y(t.subarray(r,r+zo),"base64url"),o=Y(t.subarray(r+zo),"base64url"),new Te({...Kl,key_ops:["verify"],x:n,y:o});if(t.byteLength===Zo*2+1)return n=Y(t.subarray(r,r+Zo),"base64url"),o=Y(t.subarray(r+Zo),"base64url"),new Te({...Pl,key_ops:["verify"],x:n,y:o});throw new tt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Gs(e){return Nt([yt(Uint8Array.from([1])),Hs($(e.d??"","base64url")),Nt([Xs(e.crv)],160),Nt([vr(new mt(Uint8Array.from([4]),$(e.x??"","base64url"),$(e.y??"","base64url")))],161)]).subarray()}function js(e){return Nt([yt(Uint8Array.from([1])),Nt([Xs(e.crv)],160),Nt([vr(new mt(Uint8Array.from([4]),$(e.x??"","base64url"),$(e.y??"","base64url")))],161)]).subarray()}function Xs(e){if(e==="P-256")return Ul;if(e==="P-384")return Rl;if(e==="P-521")return Nl;throw new tt(`Invalid curve ${e}`)}async function Ws(e="P-256"){let t=await $s(e);return new dn(t.privateKey)}var Te=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=js(this.jwk)),this._raw}toMultihash(){return Ie.digest(de(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:rt(this.raw,t.raw)}async verify(t,r,n){return Zs(this.jwk,r,t,n)}},dn=class{type="ECDSA";jwk;publicKey;_raw;constructor(t){this.jwk=t,this.publicKey=new Te({crv:t.crv,ext:t.ext,key_ops:["verify"],kty:"EC",x:t.x,y:t.y})}get raw(){return this._raw==null&&(this._raw=Gs(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:rt(this.raw,t.raw)}async sign(t,r){return zs(this.jwk,t,r)}};function Be(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function $t(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function H(e,t,r=""){let n=Be(e),o=e?.length,i=t!==void 0;if(!n||i&&o!==t){let s=r&&`"${r}" `,a=i?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`;throw new Error(s+"expected Uint8Array"+a+", got "+c)}return e}function hn(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");$t(e.outputLen),$t(e.blockLen)}function Ge(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 Qs(e,t){H(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function ee(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function pn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function kt(e,t){return e<<32-t|e>>>t}var ta=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Ol=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function re(e){if(H(e),ta)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Ol[e[r]];return t}var te={_0:48,_9:57,A:65,F:70,a:97,f:102};function Js(e){if(e>=te._0&&e<=te._9)return e-te._0;if(e>=te.A&&e<=te.F)return e-(te.A-10);if(e>=te.a&&e<=te.f)return e-(te.a-10)}function ne(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(ta)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=Js(e.charCodeAt(i)),a=Js(e.charCodeAt(i+1));if(s===void 0||a===void 0){let c=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function wt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];H(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let i=e[n];r.set(i,o),o+=i.length}return r}function Go(e,t={}){let r=(o,i)=>e(i).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function je(e=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}var jo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ea(e,t,r){return e&t^~e&r}function ra(e,t,r){return e&t^e&r^t&r}var Ar=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=pn(this.buffer)}update(t){Ge(this),H(t);let{view:r,buffer:n,blockLen:o}=this,i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=pn(t);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ge(this),Qs(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,ee(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),i),this.process(n,0);let a=pn(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],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return t.destroyed=s,t.finished=i,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},oe=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ft=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var mn=BigInt(4294967295),na=BigInt(32);function Ml(e,t=!1){return t?{h:Number(e&mn),l:Number(e>>na&mn)}:{h:Number(e>>na&mn)|0,l:Number(e&mn)|0}}function oa(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let i=0;i<r;i++){let{h:s,l:a}=Ml(e[i],t);[n[i],o[i]]=[s,a]}return[n,o]}var Xo=(e,t,r)=>e>>>r,Wo=(e,t,r)=>e<<32-r|t>>>r,Ce=(e,t,r)=>e>>>r|t<<32-r,_e=(e,t,r)=>e<<32-r|t>>>r,Ir=(e,t,r)=>e<<64-r|t>>>r-32,Tr=(e,t,r)=>e>>>r-32|t<<64-r;function zt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ia=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),sa=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,aa=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ca=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,ua=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),fa=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;var Fl=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]),he=new Uint32Array(64),Jo=class extends Ar{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[t,r,n,o,i,s,a,c]}set(t,r,n,o,i,s,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)he[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let x=he[l-15],E=he[l-2],b=kt(x,7)^kt(x,18)^x>>>3,A=kt(E,17)^kt(E,19)^E>>>10;he[l]=A+he[l-7]+b+he[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let x=kt(a,6)^kt(a,11)^kt(a,25),E=u+x+ea(a,c,f)+Fl[l]+he[l]|0,A=(kt(n,2)^kt(n,13)^kt(n,22))+ra(n,o,i)|0;u=f,f=c,c=a,a=s+E|0,s=i,i=o,o=n,n=E+A|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,i,s,a,c,f,u)}roundClean(){ee(he)}destroy(){this.set(0,0,0,0,0,0,0,0),ee(this.buffer)}},Qo=class extends Jo{A=oe[0]|0;B=oe[1]|0;C=oe[2]|0;D=oe[3]|0;E=oe[4]|0;F=oe[5]|0;G=oe[6]|0;H=oe[7]|0;constructor(){super(32)}};var la=oa(["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))),ql=la[0],Hl=la[1],pe=new Uint32Array(80),me=new Uint32Array(80),ti=class extends Ar{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:x,Gh:E,Gl:b,Hh:A,Hl:w}=this;return[t,r,n,o,i,s,a,c,f,u,l,x,E,b,A,w]}set(t,r,n,o,i,s,a,c,f,u,l,x,E,b,A,w){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=x|0,this.Gh=E|0,this.Gl=b|0,this.Hh=A|0,this.Hl=w|0}process(t,r){for(let v=0;v<16;v++,r+=4)pe[v]=t.getUint32(r),me[v]=t.getUint32(r+=4);for(let v=16;v<80;v++){let D=pe[v-15]|0,P=me[v-15]|0,M=Ce(D,P,1)^Ce(D,P,8)^Xo(D,P,7),F=_e(D,P,1)^_e(D,P,8)^Wo(D,P,7),h=pe[v-2]|0,p=me[v-2]|0,_=Ce(h,p,19)^Ir(h,p,61)^Xo(h,p,6),L=_e(h,p,19)^Tr(h,p,61)^Wo(h,p,6),T=aa(F,L,me[v-7],me[v-16]),m=ca(T,M,_,pe[v-7],pe[v-16]);pe[v]=m|0,me[v]=T|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:x,Fh:E,Fl:b,Gh:A,Gl:w,Hh:S,Hl:B}=this;for(let v=0;v<80;v++){let D=Ce(l,x,14)^Ce(l,x,18)^Ir(l,x,41),P=_e(l,x,14)^_e(l,x,18)^Tr(l,x,41),M=l&E^~l&A,F=x&b^~x&w,h=ua(B,P,F,Hl[v],me[v]),p=fa(h,S,D,M,ql[v],pe[v]),_=h|0,L=Ce(n,o,28)^Ir(n,o,34)^Ir(n,o,39),T=_e(n,o,28)^Tr(n,o,34)^Tr(n,o,39),m=n&i^n&a^i&a,y=o&s^o&c^s&c;S=A|0,B=w|0,A=E|0,w=b|0,E=l|0,b=x|0,{h:l,l:x}=zt(f|0,u|0,p|0,_|0),f=a|0,u=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let d=ia(_,T,y);n=sa(d,p,L,m),o=d|0}({h:n,l:o}=zt(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=zt(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=zt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=zt(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:x}=zt(this.Eh|0,this.El|0,l|0,x|0),{h:E,l:b}=zt(this.Fh|0,this.Fl|0,E|0,b|0),{h:A,l:w}=zt(this.Gh|0,this.Gl|0,A|0,w|0),{h:S,l:B}=zt(this.Hh|0,this.Hl|0,S|0,B|0),this.set(n,o,i,s,a,c,f,u,l,x,E,b,A,w,S,B)}roundClean(){ee(pe,me)}destroy(){ee(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ei=class extends ti{Ah=ft[0]|0;Al=ft[1]|0;Bh=ft[2]|0;Bl=ft[3]|0;Ch=ft[4]|0;Cl=ft[5]|0;Dh=ft[6]|0;Dl=ft[7]|0;Eh=ft[8]|0;El=ft[9]|0;Fh=ft[10]|0;Fl=ft[11]|0;Gh=ft[12]|0;Gl=ft[13]|0;Hh=ft[14]|0;Hl=ft[15]|0;constructor(){super(64)}};var Xe=Go(()=>new Qo,jo(1));var da=Go(()=>new ei,jo(3));var ni=BigInt(0),ri=BigInt(1);function ie(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function ha(e){if(typeof e=="bigint"){if(!yn(e))throw new Error("positive bigint expected, got "+e)}else $t(e);return e}function Br(e){let t=ha(e).toString(16);return t.length&1?"0"+t:t}function pa(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?ni:BigInt("0x"+e)}function We(e){return pa(re(e))}function Le(e){return pa(re(xn(H(e)).reverse()))}function gn(e,t){$t(t),e=ha(e);let r=ne(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function oi(e,t){return gn(e,t).reverse()}function xn(e){return Uint8Array.from(e)}var yn=e=>typeof e=="bigint"&&ni<=e;function $l(e,t,r){return yn(e)&&yn(t)&&yn(r)&&t<=e&&e<r}function Cr(e,t,r,n){if(!$l(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function ii(e){let t;for(t=0;e>ni;e>>=ri,t+=1);return t}var _r=e=>(ri<<BigInt(e))-ri;function ma(e,t,r){if($t(e,"hashLen"),$t(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=w=>new Uint8Array(w),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=n(e),f=n(e),u=0,l=()=>{c.fill(1),f.fill(0),u=0},x=(...w)=>r(f,wt(c,...w)),E=(w=o)=>{f=x(i,w),c=x(),w.length!==0&&(f=x(s,w),c=x())},b=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let w=0,S=[];for(;w<t;){c=x();let B=c.slice();S.push(B),w+=c.length}return wt(...S)};return(w,S)=>{l(),E(w);let B;for(;!(B=S(b()));)E();return l(),B}}function ye(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(i,s,a){let c=e[i];if(a&&c===void 0)return;let f=typeof c;if(f!==s||c===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${f}`)}let o=(i,s)=>Object.entries(i).forEach(([a,c])=>n(a,c,s));o(t,!1),o(r,!0)}function Je(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 gt=BigInt(0),st=BigInt(1),De=BigInt(2),xa=BigInt(3),ba=BigInt(4),wa=BigInt(5),zl=BigInt(7),Ea=BigInt(8),Zl=BigInt(9),Sa=BigInt(16);function nt(e,t){let r=e%t;return r>=gt?r:t+r}function X(e,t,r){let n=e;for(;t-- >gt;)n*=n,n%=r;return n}function ya(e,t){if(e===gt)throw new Error("invert: expected non-zero number");if(t<=gt)throw new Error("invert: expected positive modulus, got "+t);let r=nt(e,t),n=t,o=gt,i=st,s=st,a=gt;for(;r!==gt;){let f=n/r,u=n%r,l=o-s*f,x=i-a*f;n=r,r=u,o=s,i=a,s=l,a=x}if(n!==st)throw new Error("invert: does not exist");return nt(o,t)}function ai(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function va(e,t){let r=(e.ORDER+st)/ba,n=e.pow(t,r);return ai(e,n,t),n}function Yl(e,t){let r=(e.ORDER-wa)/Ea,n=e.mul(t,De),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,De),o),a=e.mul(i,e.sub(s,e.ONE));return ai(e,a,t),a}function Gl(e){let t=Qe(e),r=Aa(e),n=r(t,t.neg(t.ONE)),o=r(t,n),i=r(t,t.neg(n)),s=(e+zl)/Sa;return(a,c)=>{let f=a.pow(c,s),u=a.mul(f,n),l=a.mul(f,o),x=a.mul(f,i),E=a.eql(a.sqr(u),c),b=a.eql(a.sqr(l),c);f=a.cmov(f,u,E),u=a.cmov(x,l,b);let A=a.eql(a.sqr(u),c),w=a.cmov(f,u,A);return ai(a,w,c),w}}function Aa(e){if(e<xa)throw new Error("sqrt is not defined for small field");let t=e-st,r=0;for(;t%De===gt;)t/=De,r++;let n=De,o=Qe(e);for(;ga(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return va;let i=o.pow(n,t),s=(t+st)/De;return function(c,f){if(c.is0(f))return f;if(ga(c,f)!==1)throw new Error("Cannot find square root");let u=r,l=c.mul(c.ONE,i),x=c.pow(f,t),E=c.pow(f,s);for(;!c.eql(x,c.ONE);){if(c.is0(x))return c.ZERO;let b=1,A=c.sqr(x);for(;!c.eql(A,c.ONE);)if(b++,A=c.sqr(A),b===u)throw new Error("Cannot find square root");let w=st<<BigInt(u-b-1),S=c.pow(l,w);u=b,l=c.sqr(S),x=c.mul(x,l),E=c.mul(E,S)}return E}}function jl(e){return e%ba===xa?va:e%Ea===wa?Yl:e%Sa===Zl?Gl(e):Aa(e)}var Ia=(e,t)=>(nt(e,t)&st)===st,Xl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ci(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Xl.reduce((n,o)=>(n[o]="function",n),t);return ye(e,r),e}function Wl(e,t,r){if(r<gt)throw new Error("invalid exponent, negatives unsupported");if(r===gt)return e.ONE;if(r===st)return t;let n=e.ONE,o=t;for(;r>gt;)r&st&&(n=e.mul(n,o)),o=e.sqr(o),r>>=st;return n}function Lr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((s,a,c)=>e.is0(a)?s:(n[c]=s,e.mul(s,a)),e.ONE),i=e.inv(o);return t.reduceRight((s,a,c)=>e.is0(a)?s:(n[c]=e.mul(s,n[c]),e.mul(s,a)),i),n}function ga(e,t){let r=(e.ORDER-st)/De,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 Jl(e,t){t!==void 0&&$t(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var si=class{ORDER;BITS;BYTES;isLE;ZERO=gt;ONE=st;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=gt)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}=Jl(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 nt(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return gt<=t&&t<this.ORDER}is0(t){return t===gt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&st)===st}neg(t){return nt(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return nt(t*t,this.ORDER)}add(t,r){return nt(t+r,this.ORDER)}sub(t,r){return nt(t-r,this.ORDER)}mul(t,r){return nt(t*r,this.ORDER)}pow(t,r){return Wl(this,t,r)}div(t,r){return nt(t*ya(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 ya(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=jl(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?oi(t,this.BYTES):gn(t,this.BYTES)}fromBytes(t,r=!1){H(t);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=new Uint8Array(o);f.set(t,i?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=i?Le(t):We(t);if(a&&(c=nt(c,s)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Lr(this,t)}cmov(t,r,n){return n?r:t}};function Qe(e,t={}){return new si(e,t)}function Ta(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function ui(e){let t=Ta(e);return t+Math.ceil(t/2)}function fi(e,t,r=!1){H(e);let n=e.length,o=Ta(t),i=ui(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Le(e):We(e),a=nt(s,t-st)+st;return r?oi(a,o):gn(a,o)}var tr=BigInt(0),Ue=BigInt(1);function Dr(e,t){let r=t.negate();return e?r:t}function Re(e,t){let r=Lr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function La(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function li(e,t){La(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,i=_r(e),s=BigInt(e);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function Ba(e,t,r){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r,a=Number(e&o),c=e>>s;a>n&&(a-=i,c+=Ue);let f=t*n,u=f+Math.abs(a)-1,l=a===0,x=a<0,E=t%2!==0;return{nextN:c,offset:u,isZero:l,isNeg:x,isNegF:E,offsetF:f}}var di=new WeakMap,Da=new WeakMap;function hi(e){return Da.get(e)||1}function Ca(e){if(e!==tr)throw new Error("invalid wNAF")}var er=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>tr;)r&Ue&&(n=n.add(o)),o=o.double(),r>>=Ue;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=li(r,this.bits),i=[],s=t,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let f=1;f<o;f++)a=a.add(s),i.push(a);s=a.double()}return i}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=li(t,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:f,isZero:u,isNeg:l,isNegF:x,offsetF:E}=Ba(n,a,s);n=c,u?i=i.add(Dr(x,r[E])):o=o.add(Dr(l,r[f]))}return Ca(n),{p:o,f:i}}wNAFUnsafe(t,r,n,o=this.ZERO){let i=li(t,this.bits);for(let s=0;s<i.windows&&n!==tr;s++){let{nextN:a,offset:c,isZero:f,isNeg:u}=Ba(n,s,i);if(n=a,!f){let l=r[c];o=o.add(u?l.negate():l)}}return Ca(n),o}getPrecomputes(t,r,n){let o=di.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),di.set(r,o))),o}cached(t,r,n){let o=hi(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let i=hi(t);return i===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,t,n),r,o)}createCache(t,r){La(r,this.bits),Da.set(t,r),di.delete(t)}hasCache(t){return hi(t)!==1}};function Ua(e,t,r,n){let o=t,i=e.ZERO,s=e.ZERO;for(;r>tr||n>tr;)r&Ue&&(i=i.add(o)),n&Ue&&(s=s.add(o)),o=o.double(),r>>=Ue,n>>=Ue;return{p1:i,p2:s}}function _a(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ci(t),t}else return Qe(e,{isLE:r})}function bn(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let f=t[c];if(!(typeof f=="bigint"&&f>tr))throw new Error(`CURVE.${c} must be positive bigint`)}let o=_a(t.p,r.Fp,n),i=_a(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:i}}function wn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var ge=BigInt(0),at=BigInt(1),pi=BigInt(2),Ql=BigInt(8);function td(e,t,r,n){let o=e.sqr(r),i=e.sqr(n),s=e.add(e.mul(t.a,o),i),a=e.add(e.ONE,e.mul(t.d,e.mul(o,i)));return e.eql(s,a)}function Ra(e,t={}){let r=bn("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s}=i;ye(t,{},{uvRatio:"function"});let a=pi<<BigInt(o.BYTES*8)-at,c=w=>n.create(w),f=t.uvRatio||((w,S)=>{try{return{isValid:!0,value:n.sqrt(n.div(w,S))}}catch{return{isValid:!1,value:ge}}});if(!td(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function u(w,S,B=!1){let v=B?at:ge;return Cr("coordinate "+w,S,v,a),S}function l(w){if(!(w instanceof b))throw new Error("EdwardsPoint expected")}let x=Je((w,S)=>{let{X:B,Y:v,Z:D}=w,P=w.is0();S==null&&(S=P?Ql:n.inv(D));let M=c(B*S),F=c(v*S),h=n.mul(D,S);if(P)return{x:ge,y:at};if(h!==at)throw new Error("invZ was invalid");return{x:M,y:F}}),E=Je(w=>{let{a:S,d:B}=i;if(w.is0())throw new Error("bad point: ZERO");let{X:v,Y:D,Z:P,T:M}=w,F=c(v*v),h=c(D*D),p=c(P*P),_=c(p*p),L=c(F*S),T=c(p*c(L+h)),m=c(_+c(B*c(F*h)));if(T!==m)throw new Error("bad point: equation left != right (1)");let y=c(v*D),d=c(P*M);if(y!==d)throw new Error("bad point: equation left != right (2)");return!0});class b{static BASE=new b(i.Gx,i.Gy,at,c(i.Gx*i.Gy));static ZERO=new b(ge,at,at,ge);static Fp=n;static Fn=o;X;Y;Z;T;constructor(S,B,v,D){this.X=u("x",S),this.Y=u("y",B),this.Z=u("z",v,!0),this.T=u("t",D),Object.freeze(this)}static CURVE(){return i}static fromAffine(S){if(S instanceof b)throw new Error("extended point not allowed");let{x:B,y:v}=S||{};return u("x",B),u("y",v),new b(B,v,at,c(B*v))}static fromBytes(S,B=!1){let v=n.BYTES,{a:D,d:P}=i;S=xn(H(S,v,"point")),ie(B,"zip215");let M=xn(S),F=S[v-1];M[v-1]=F&-129;let h=Le(M),p=B?a:n.ORDER;Cr("point.y",h,ge,p);let _=c(h*h),L=c(_-at),T=c(P*_-D),{isValid:m,value:y}=f(L,T);if(!m)throw new Error("bad point: invalid y coordinate");let d=(y&at)===at,I=(F&128)!==0;if(!B&&y===ge&&I)throw new Error("bad point: x=0 and x_0=1");return I!==d&&(y=c(-y)),b.fromAffine({x:y,y:h})}static fromHex(S,B=!1){return b.fromBytes(ne(S),B)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(S=8,B=!0){return A.createCache(this,S),B||this.multiply(pi),this}assertValidity(){E(this)}equals(S){l(S);let{X:B,Y:v,Z:D}=this,{X:P,Y:M,Z:F}=S,h=c(B*F),p=c(P*D),_=c(v*F),L=c(M*D);return h===p&&_===L}is0(){return this.equals(b.ZERO)}negate(){return new b(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:S}=i,{X:B,Y:v,Z:D}=this,P=c(B*B),M=c(v*v),F=c(pi*c(D*D)),h=c(S*P),p=B+v,_=c(c(p*p)-P-M),L=h+M,T=L-F,m=h-M,y=c(_*T),d=c(L*m),I=c(_*m),U=c(T*L);return new b(y,d,U,I)}add(S){l(S);let{a:B,d:v}=i,{X:D,Y:P,Z:M,T:F}=this,{X:h,Y:p,Z:_,T:L}=S,T=c(D*h),m=c(P*p),y=c(F*v*L),d=c(M*_),I=c((D+P)*(h+p)-T-m),U=d-y,R=d+y,k=c(m-B*T),K=c(I*U),O=c(R*k),q=c(I*k),W=c(U*R);return new b(K,O,W,q)}subtract(S){return this.add(S.negate())}multiply(S){if(!o.isValidNot0(S))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:B,f:v}=A.cached(this,S,D=>Re(b,D));return Re(b,[B,v])[0]}multiplyUnsafe(S,B=b.ZERO){if(!o.isValid(S))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return S===ge?b.ZERO:this.is0()||S===at?this:A.unsafe(this,S,v=>Re(b,v),B)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return A.unsafe(this,i.n).is0()}toAffine(S){return x(this,S)}clearCofactor(){return s===at?this:this.multiplyUnsafe(s)}toBytes(){let{x:S,y:B}=this.toAffine(),v=n.toBytes(B);return v[v.length-1]|=S&at?128:0,v}toHex(){return re(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let A=new er(b,o.BITS);return b.BASE.precompute(8),b}function Na(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');ye(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:i,Fn:s}=e,a=r.randomBytes||je,c=r.adjustScalarBytes||(h=>h),f=r.domain||((h,p,_)=>{if(ie(_,"phflag"),p.length||_)throw new Error("Contexts/pre-hash are not supported");return h});function u(h){return s.create(Le(h))}function l(h){let p=v.secretKey;H(h,v.secretKey,"secretKey");let _=H(t(h),2*p,"hashedSecretKey"),L=c(_.slice(0,p)),T=_.slice(p,2*p),m=u(L);return{head:L,prefix:T,scalar:m}}function x(h){let{head:p,prefix:_,scalar:L}=l(h),T=o.multiply(L),m=T.toBytes();return{head:p,prefix:_,scalar:L,point:T,pointBytes:m}}function E(h){return x(h).pointBytes}function b(h=Uint8Array.of(),...p){let _=wt(...p);return u(t(f(_,H(h,void 0,"context"),!!n)))}function A(h,p,_={}){h=H(h,void 0,"message"),n&&(h=n(h));let{prefix:L,scalar:T,pointBytes:m}=x(p),y=b(_.context,L,h),d=o.multiply(y).toBytes(),I=b(_.context,d,m,h),U=s.create(y+I*T);if(!s.isValid(U))throw new Error("sign failed: invalid s");let R=wt(d,s.toBytes(U));return H(R,v.signature,"result")}let w={zip215:!0};function S(h,p,_,L=w){let{context:T,zip215:m}=L,y=v.signature;h=H(h,y,"signature"),p=H(p,void 0,"message"),_=H(_,v.publicKey,"publicKey"),m!==void 0&&ie(m,"zip215"),n&&(p=n(p));let d=y/2,I=h.subarray(0,d),U=Le(h.subarray(d,y)),R,k,K;try{R=e.fromBytes(_,m),k=e.fromBytes(I,m),K=o.multiplyUnsafe(U)}catch{return!1}if(!m&&R.isSmallOrder())return!1;let O=b(T,k.toBytes(),R.toBytes(),p);return k.add(R.multiplyUnsafe(O)).subtract(K).clearCofactor().is0()}let B=i.BYTES,v={secretKey:B,publicKey:B,signature:2*B,seed:B};function D(h=a(v.seed)){return H(h,v.seed,"seed")}function P(h){return Be(h)&&h.length===s.BYTES}function M(h,p){try{return!!e.fromBytes(h,p)}catch{return!1}}let F={getExtendedPublicKey:x,randomSecretKey:D,isValidSecretKey:P,isValidPublicKey:M,toMontgomery(h){let{y:p}=e.fromBytes(h),_=v.publicKey,L=_===32;if(!L&&_!==57)throw new Error("only defined for 25519 and 448");let T=L?i.div(at+p,at-p):i.div(p-at,p+at);return i.toBytes(T)},toMontgomerySecret(h){let p=v.secretKey;H(h,p);let _=t(h.subarray(0,p));return c(_).subarray(0,p)}};return Object.freeze({keygen:wn(D,E),getPublicKey:E,sign:A,verify:S,utils:F,Point:e,lengths:v})}var ed=BigInt(1),ka=BigInt(2);var rd=BigInt(5),nd=BigInt(8),mi=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),od={p:mi,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:nd,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function id(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=mi,a=e*e%i*e%i,c=X(a,ka,i)*a%i,f=X(c,ed,i)*e%i,u=X(f,rd,i)*f%i,l=X(u,t,i)*u%i,x=X(l,r,i)*l%i,E=X(x,n,i)*x%i,b=X(E,o,i)*E%i,A=X(b,o,i)*E%i,w=X(A,t,i)*u%i;return{pow_p_5_8:X(w,ka,i)*e%i,b2:a}}function sd(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ka=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ad(e,t){let r=mi,n=nt(t*t*t,r),o=nt(n*n*t,r),i=id(e*o).pow_p_5_8,s=nt(e*n*i,r),a=nt(t*s*s,r),c=s,f=nt(s*Ka,r),u=a===e,l=a===nt(-e,r),x=a===nt(-e*Ka,r);return u&&(s=c),(l||x)&&(s=f),Ia(s,r)&&(s=nt(-s,r)),{isValid:u||l,value:s}}var cd=Ra(od,{uvRatio:ad});function ud(e){return Na(cd,da,Object.assign({adjustScalarBytes:sd},e))}var Ur=ud({});var Rr=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},Nr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},En=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Pa={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new En("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 Et=Pa;var Sn=32,kr=64,yi=32;var rr,Oa=(async()=>{try{return await Et.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function Ma(){let e=Ur.utils.randomSecretKey(),t=Ur.getPublicKey(e);return{privateKey:pd(e,t),publicKey:t}}async function fd(e,t){let r;e.length===kr?r=e.subarray(0,32):r=e;let n={crv:"Ed25519",kty:"OKP",x:Y(e.subarray(32),"base64url"),d:Y(r,"base64url"),ext:!0,key_ops:["sign"]},o=await Et.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),i=await Et.get().subtle.sign({name:"Ed25519"},o,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(i,0,i.byteLength)}function ld(e,t){let r=e.subarray(0,yi);return Ur.sign(t instanceof Uint8Array?t:t.subarray(),r)}async function Va(e,t){return rr==null&&(rr=await Oa),rr?fd(e,t):ld(e,t)}async function dd(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Et.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Et.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 hd(e,t,r){return Ur.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Fa(e,t,r){return rr==null&&(rr=await Oa),rr?dd(e,t,r):hd(e,t,r)}function pd(e,t){let r=new Uint8Array(kr);for(let n=0;n<yi;n++)r[n]=e[n],r[yi+n]=t[n];return r}function nr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Kr=class{type="Ed25519";raw;constructor(t){this.raw=An(t,Sn)}toMultihash(){return Ie.digest(de(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:rt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Fa(this.raw,r,t);return nr(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}},vn=class{type="Ed25519";raw;publicKey;constructor(t,r){this.raw=An(t,kr),this.publicKey=new Kr(r)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:rt(this.raw,t.raw)}sign(t,r){r?.signal?.throwIfAborted();let n=Va(this.raw,t);return nr(n)?n.then(o=>(r?.signal?.throwIfAborted(),o)):(r?.signal?.throwIfAborted(),n)}};function gi(e){return e=An(e,Sn),new Kr(e)}async function Ha(){let{privateKey:e,publicKey:t}=Ma();return new vn(e,t)}function An(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new tt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var md=Math.pow(2,7),yd=Math.pow(2,14),gd=Math.pow(2,21),$a=Math.pow(2,28),za=Math.pow(2,35),Za=Math.pow(2,42),Ya=Math.pow(2,49),xt=128,xe=127;function Pr(e){if(e<md)return 1;if(e<yd)return 2;if(e<gd)return 3;if(e<$a)return 4;if(e<za)return 5;if(e<Za)return 6;if(e<Ya)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ga(e,t,r=0){switch(Pr(e)){case 8:t[r++]=e&255|xt,e/=128;case 7:t[r++]=e&255|xt,e/=128;case 6:t[r++]=e&255|xt,e/=128;case 5:t[r++]=e&255|xt,e/=128;case 4:t[r++]=e&255|xt,e>>>=7;case 3:t[r++]=e&255|xt,e>>>=7;case 2:t[r++]=e&255|xt,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function ja(e,t){let r=e[t],n=0;if(n+=r&xe,r<xt||(r=e[t+1],n+=(r&xe)<<7,r<xt)||(r=e[t+2],n+=(r&xe)<<14,r<xt)||(r=e[t+3],n+=(r&xe)<<21,r<xt)||(r=e[t+4],n+=(r&xe)*$a,r<xt)||(r=e[t+5],n+=(r&xe)*za,r<xt)||(r=e[t+6],n+=(r&xe)*Za,r<xt)||(r=e[t+7],n+=(r&xe)*Ya,r<xt))return n;throw new RangeError("Could not decode varint")}var xi=new Float32Array([-0]),be=new Uint8Array(xi.buffer);function Xa(e,t,r){xi[0]=e,t[r]=be[0],t[r+1]=be[1],t[r+2]=be[2],t[r+3]=be[3]}function Wa(e,t){return be[0]=e[t],be[1]=e[t+1],be[2]=e[t+2],be[3]=e[t+3],xi[0]}var bi=new Float64Array([-0]),pt=new Uint8Array(bi.buffer);function Ja(e,t,r){bi[0]=e,t[r]=pt[0],t[r+1]=pt[1],t[r+2]=pt[2],t[r+3]=pt[3],t[r+4]=pt[4],t[r+5]=pt[5],t[r+6]=pt[6],t[r+7]=pt[7]}function Qa(e,t){return pt[0]=e[t],pt[1]=e[t+1],pt[2]=e[t+2],pt[3]=e[t+3],pt[4]=e[t+4],pt[5]=e[t+5],pt[6]=e[t+6],pt[7]=e[t+7],bi[0]}var xd=BigInt(Number.MAX_SAFE_INTEGER),bd=BigInt(Number.MIN_SAFE_INTEGER),It=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return 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>tc&&(o=0n,++n>tc&&(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 It(0,0);Ne.toBigInt=function(){return 0n};Ne.zzEncode=Ne.zzDecode=function(){return this};Ne.length=function(){return 1};var tc=4294967296n;function ec(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 rc(e,t,r){if(r-t<1)return"";let o,i=[],s=0,a;for(;t<r;)a=e[t++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function wi(e,t,r){let n=r,o,i;for(let s=0;s<e.length;++s)o=e.charCodeAt(s),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((i=e.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Kt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function In(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Ei=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Kt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Kt(this,4);return In(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Kt(this,4);return In(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Kt(this,4);let t=Wa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Kt(this,4);let t=Qa(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Kt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return rc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Kt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Kt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new It(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Kt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Kt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Kt(this,8);let t=In(this.buf,this.pos+=4),r=In(this.buf,this.pos+=4);return new It(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=ja(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 Si(e){return new Ei(e instanceof Uint8Array?e:e.subarray())}function Zt(e,t,r){let n=Si(e);return t.decode(n,void 0,r)}function vi(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return At(s);o+s>t&&(n=At(t),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var ke=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Ai(){}var Ti=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},wd=vi();function Ed(e){return globalThis.Buffer!=null?At(e):wd(e)}var Mr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ke(Ai,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ke(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Bi((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(Tn,10,It.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=It.fromBigInt(t);return this._push(Tn,r.length(),r)}uint64Number(t){return this._push(Ga,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 r=It.fromBigInt(t).zzEncode();return this._push(Tn,r.length(),r)}sint64Number(t){let r=It.fromNumber(t).zzEncode();return this._push(Tn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ii,1,t?1:0)}fixed32(t){return this._push(Or,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=It.fromBigInt(t);return this._push(Or,4,r.lo)._push(Or,4,r.hi)}fixed64Number(t){let r=It.fromNumber(t);return this._push(Or,4,r.lo)._push(Or,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Xa,4,t)}double(t){return this._push(Ja,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Ii,1,0):this.uint32(r)._push(vd,r,t)}string(t){let r=ec(t);return r!==0?this.uint32(r)._push(wi,r,t):this._push(Ii,1,0)}fork(){return this.states=new Ti(this),this.head=this.tail=new ke(Ai,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new ke(Ai,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 Ii(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 Bi=class extends ke{next;constructor(t,r){super(Sd,t,r),this.next=void 0}};function Tn(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 Or(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&&(Mr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Ad,t,e),this},Mr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Id,t,e),this});function Ad(e,t,r){t.set(e,r)}function Id(e,t,r){e.length<40?wi(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set($(e),r)}function Ci(){return new Mr}function Yt(e,t){let r=Ci();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var or;(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"})(or||(or={}));function Bn(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Vr(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(i,s){let a=t(i);s.int32(a)},n=function(i){let s=i.int32();return t(s)};return Bn("enum",or.VARINT,r,n)}function Gt(e,t){return Bn("message",or.LENGTH_DELIMITED,e,t)}var ot;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(ot||(ot={}));var _i;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(_i||(_i={}));(function(e){e.codec=()=>Vr(_i)})(ot||(ot={}));var jt;(function(e){let t;e.codec=()=>(t==null&&(t=Gt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),ot.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let a=r.uint32();switch(a>>>3){case 1:{i.Type=ot.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>Yt(r,e.codec()),e.decode=(r,n)=>Zt(r,e.codec(),n)})(jt||(jt={}));var Li;(function(e){let t;e.codec=()=>(t==null&&(t=Gt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),ot.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let a=r.uint32();switch(a>>>3){case 1:{i.Type=ot.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>Yt(r,e.codec()),e.decode=(r,n)=>Zt(r,e.codec(),n)})(Li||(Li={}));var qr={};bt(qr,{MAX_RSA_KEY_SIZE:()=>Di,generateRSAKeyPair:()=>Vi,jwkToJWKKeyPair:()=>cc,jwkToPkcs1:()=>_d,jwkToPkix:()=>ki,jwkToRSAPrivateKey:()=>Mi,pkcs1MessageToJwk:()=>Ri,pkcs1MessageToRSAPrivateKey:()=>Ki,pkcs1ToJwk:()=>Cd,pkcs1ToRSAPrivateKey:()=>ac,pkixMessageToJwk:()=>Ni,pkixMessageToRSAPublicKey:()=>Oi,pkixToJwk:()=>Ld,pkixToRSAPublicKey:()=>Pi});var ir=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=qr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return it.createV1(114,this._multihash)}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:rt(this.raw,t.raw)}verify(t,r,n){return sc(this.jwk,r,t,n)}},Fr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=qr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:rt(this.raw,t.raw)}sign(t,r){return ic(this.jwk,t,r)}};var Di=8192,Ui=18,Td=1062,Bd=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Cd(e){let t=Qt(e);return Ri(t)}function Ri(e){return{n:Y(e[1],"base64url"),e:Y(e[2],"base64url"),d:Y(e[3],"base64url"),p:Y(e[4],"base64url"),q:Y(e[5],"base64url"),dp:Y(e[6],"base64url"),dq:Y(e[7],"base64url"),qi:Y(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 tt("JWK was missing components");return Nt([yt(Uint8Array.from([0])),yt($(e.n,"base64url")),yt($(e.e,"base64url")),yt($(e.d,"base64url")),yt($(e.p,"base64url")),yt($(e.q,"base64url")),yt($(e.dp,"base64url")),yt($(e.dq,"base64url")),yt($(e.qi,"base64url"))]).subarray()}function Ld(e){let t=Qt(e,{offset:0});return Ni(t)}function Ni(e){let t=Qt(e[1],{offset:0});return{kty:"RSA",n:Y(t[0],"base64url"),e:Y(t[1],"base64url")}}function ki(e){if(e.n==null||e.e==null)throw new tt("JWK was missing components");return Nt([Bd,vr(Nt([yt($(e.n,"base64url")),yt($(e.e,"base64url"))]))]).subarray()}function ac(e){let t=Qt(e);return Ki(t)}function Ki(e){let t=Ri(e);return Mi(t)}function Pi(e,t){if(e.byteLength>=Td)throw new Fe("Key size is too large");let r=Qt(e,{offset:0});return Oi(r,e,t)}function Oi(e,t,r){let n=Ni(e);if(r==null){let o=Xe(jt.encode({Type:ot.RSA,Data:t}));r=Ht(Ui,o)}return new ir(n,r)}function Mi(e){if(fc(e)>Di)throw new tt("Key size is too large");let t=cc(e),r=Xe(jt.encode({Type:ot.RSA,Data:ki(t.publicKey)})),n=Ht(Ui,r);return new Fr(t.privateKey,new ir(t.publicKey,n))}async function Vi(e){if(e>Di)throw new tt("Key size is too large");let t=await uc(e),r=Xe(jt.encode({Type:ot.RSA,Data:ki(t.publicKey)})),n=Ht(Ui,r);return new Fr(t.privateKey,new ir(t.publicKey,n))}function cc(e){if(e==null)throw new tt("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function uc(e,t){let r=await Et.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Dd(r,t);return{privateKey:n[0],publicKey:n[1]}}async function ic(e,t,r){let n=await Et.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Et.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 sc(e,t,r,n){let o=await Et.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Et.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),i}async function Dd(e,t){if(e.privateKey==null||e.publicKey==null)throw new tt("Private and public key are required");let r=await Promise.all([Et.get().subtle.exportKey("jwk",e.privateKey),Et.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function fc(e){if(e.kty!=="RSA")throw new tt("invalid key type");if(e.n==null)throw new tt("invalid key modulus");return $(e.n,"base64url").length*8}var Cn=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(hn(t),H(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),ee(o)}update(t){return Ge(this),this.iHash.update(t),this}digestInto(t){Ge(this),H(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=i,t.blockLen=s,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Fi=(e,t,r)=>new Cn(e,t).update(r).digest();Fi.create=(e,t)=>new Cn(e,t);var lc=(e,t)=>(e+(e>=0?t:-t)/dc)/t;function Ud(e,t,r){let[[n,o],[i,s]]=t,a=lc(s*e,r),c=lc(-o*e,r),f=e-a*n-c*i,u=-a*o-c*s,l=f<se,x=u<se;l&&(f=-f),x&&(u=-u);let E=_r(Math.ceil(ii(r)/2))+sr;if(f<se||f>=E||u<se||u>=E)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:f,k2neg:x,k2:u}}function Hi(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function qi(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return ie(r.lowS,"lowS"),ie(r.prehash,"prehash"),r.format!==void 0&&Hi(r.format),r}var $i=class extends Error{constructor(t=""){super(t)}},we={Err:$i,_tlv:{encode:(e,t)=>{let{Err:r}=we;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=Br(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?Br(o.length/2|128):"";return Br(e)+i+o+t},decode(e,t){let{Err:r}=we,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)s=s<<8|u;if(n+=c,s<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+s)}}},_int:{encode(e){let{Err:t}=we;if(e<se)throw new t("integer: negative integers are not allowed");let r=Br(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}=we;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 We(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=we,o=H(e,void 0,"signature"),{v:i,l:s}=n.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:f,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=we,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),i=n+o;return t.encode(48,i)}},se=BigInt(0),sr=BigInt(1),dc=BigInt(2),_n=BigInt(3),Rd=BigInt(4);function hc(e,t={}){let r=bn("weierstrass",e,t),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s,n:a}=i;ye(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=t;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=mc(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(T,m,y){let{x:d,y:I}=m.toAffine(),U=n.toBytes(d);if(ie(y,"isCompressed"),y){u();let R=!n.isOdd(I);return wt(pc(R),U)}else return wt(Uint8Array.of(4),U,n.toBytes(I))}function x(T){H(T,void 0,"Point");let{publicKey:m,publicKeyUncompressed:y}=f,d=T.length,I=T[0],U=T.subarray(1);if(d===m&&(I===2||I===3)){let R=n.fromBytes(U);if(!n.isValid(R))throw new Error("bad point: is not on curve, wrong x");let k=A(R),K;try{K=n.sqrt(k)}catch(W){let G=W instanceof Error?": "+W.message:"";throw new Error("bad point: is not on curve, sqrt error"+G)}u();let O=n.isOdd(K);return(I&1)===1!==O&&(K=n.neg(K)),{x:R,y:K}}else if(d===y&&I===4){let R=n.BYTES,k=n.fromBytes(U.subarray(0,R)),K=n.fromBytes(U.subarray(R,R*2));if(!w(k,K))throw new Error("bad point: is not on curve");return{x:k,y:K}}else throw new Error(`bad point: got length ${d}, expected compressed=${m} or uncompressed=${y}`)}let E=t.toBytes||l,b=t.fromBytes||x;function A(T){let m=n.sqr(T),y=n.mul(m,T);return n.add(n.add(y,n.mul(T,i.a)),i.b)}function w(T,m){let y=n.sqr(m),d=A(T);return n.eql(y,d)}if(!w(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(i.a,_n),Rd),B=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(S,B)))throw new Error("bad curve params: a or b");function v(T,m,y=!1){if(!n.isValid(m)||y&&n.is0(m))throw new Error(`bad point coordinate ${T}`);return m}function D(T){if(!(T instanceof p))throw new Error("Weierstrass Point expected")}function P(T){if(!c||!c.basises)throw new Error("no endo");return Ud(T,c.basises,o.ORDER)}let M=Je((T,m)=>{let{X:y,Y:d,Z:I}=T;if(n.eql(I,n.ONE))return{x:y,y:d};let U=T.is0();m==null&&(m=U?n.ONE:n.inv(I));let R=n.mul(y,m),k=n.mul(d,m),K=n.mul(I,m);if(U)return{x:n.ZERO,y:n.ZERO};if(!n.eql(K,n.ONE))throw new Error("invZ was invalid");return{x:R,y:k}}),F=Je(T=>{if(T.is0()){if(t.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:m,y}=T.toAffine();if(!n.isValid(m)||!n.isValid(y))throw new Error("bad point: x or y not field elements");if(!w(m,y))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function h(T,m,y,d,I){return y=new p(n.mul(y.X,T),y.Y,y.Z),m=Dr(d,m),y=Dr(I,y),m.add(y)}class p{static BASE=new p(i.Gx,i.Gy,n.ONE);static ZERO=new p(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,y,d){this.X=v("x",m),this.Y=v("y",y,!0),this.Z=v("z",d),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){let{x:y,y:d}=m||{};if(!m||!n.isValid(y)||!n.isValid(d))throw new Error("invalid affine point");if(m instanceof p)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(d)?p.ZERO:new p(y,d,n.ONE)}static fromBytes(m){let y=p.fromAffine(b(H(m,void 0,"point")));return y.assertValidity(),y}static fromHex(m){return p.fromBytes(ne(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,y=!0){return L.createCache(this,m),y||this.multiply(_n),this}assertValidity(){F(this)}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){D(m);let{X:y,Y:d,Z:I}=this,{X:U,Y:R,Z:k}=m,K=n.eql(n.mul(y,k),n.mul(U,I)),O=n.eql(n.mul(d,k),n.mul(R,I));return K&&O}negate(){return new p(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:y}=i,d=n.mul(y,_n),{X:I,Y:U,Z:R}=this,k=n.ZERO,K=n.ZERO,O=n.ZERO,q=n.mul(I,I),W=n.mul(U,U),G=n.mul(R,R),z=n.mul(I,U);return z=n.add(z,z),O=n.mul(I,R),O=n.add(O,O),k=n.mul(m,O),K=n.mul(d,G),K=n.add(k,K),k=n.sub(W,K),K=n.add(W,K),K=n.mul(k,K),k=n.mul(z,k),O=n.mul(d,O),G=n.mul(m,G),z=n.sub(q,G),z=n.mul(m,z),z=n.add(z,O),O=n.add(q,q),q=n.add(O,q),q=n.add(q,G),q=n.mul(q,z),K=n.add(K,q),G=n.mul(U,R),G=n.add(G,G),q=n.mul(G,z),k=n.sub(k,q),O=n.mul(G,W),O=n.add(O,O),O=n.add(O,O),new p(k,K,O)}add(m){D(m);let{X:y,Y:d,Z:I}=this,{X:U,Y:R,Z:k}=m,K=n.ZERO,O=n.ZERO,q=n.ZERO,W=i.a,G=n.mul(i.b,_n),z=n.mul(y,U),J=n.mul(d,R),ut=n.mul(I,k),qt=n.add(y,d),Q=n.add(U,R);qt=n.mul(qt,Q),Q=n.add(z,J),qt=n.sub(qt,Q),Q=n.add(y,I);let ht=n.add(U,k);return Q=n.mul(Q,ht),ht=n.add(z,ut),Q=n.sub(Q,ht),ht=n.add(d,I),K=n.add(R,k),ht=n.mul(ht,K),K=n.add(J,ut),ht=n.sub(ht,K),q=n.mul(W,Q),K=n.mul(G,ut),q=n.add(K,q),K=n.sub(J,q),q=n.add(J,q),O=n.mul(K,q),J=n.add(z,z),J=n.add(J,z),ut=n.mul(W,ut),Q=n.mul(G,Q),J=n.add(J,ut),ut=n.sub(z,ut),ut=n.mul(W,ut),Q=n.add(Q,ut),z=n.mul(J,Q),O=n.add(O,z),z=n.mul(ht,Q),K=n.mul(qt,K),K=n.sub(K,z),z=n.mul(qt,J),q=n.mul(ht,q),q=n.add(q,z),new p(K,O,q)}subtract(m){return this.add(m.negate())}is0(){return this.equals(p.ZERO)}multiply(m){let{endo:y}=t;if(!o.isValidNot0(m))throw new Error("invalid scalar: out of range");let d,I,U=R=>L.cached(this,R,k=>Re(p,k));if(y){let{k1neg:R,k1:k,k2neg:K,k2:O}=P(m),{p:q,f:W}=U(k),{p:G,f:z}=U(O);I=W.add(z),d=h(y.beta,q,G,R,K)}else{let{p:R,f:k}=U(m);d=R,I=k}return Re(p,[d,I])[0]}multiplyUnsafe(m){let{endo:y}=t,d=this;if(!o.isValid(m))throw new Error("invalid scalar: out of range");if(m===se||d.is0())return p.ZERO;if(m===sr)return d;if(L.hasCache(this))return this.multiply(m);if(y){let{k1neg:I,k1:U,k2neg:R,k2:k}=P(m),{p1:K,p2:O}=Ua(p,d,U,k);return h(y.beta,K,O,I,R)}else return L.unsafe(d,m)}toAffine(m){return M(this,m)}isTorsionFree(){let{isTorsionFree:m}=t;return s===sr?!0:m?m(p,this):L.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=t;return s===sr?this:m?m(p,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(m=!0){return ie(m,"isCompressed"),this.assertValidity(),E(p,this,m)}toHex(m=!0){return re(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let _=o.BITS,L=new er(p,t.endo?Math.ceil(_/2):_);return p.BASE.precompute(8),p}function pc(e){return Uint8Array.of(e?2:3)}function mc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Nd(e,t={}){let{Fn:r}=e,n=t.randomBytes||je,o=Object.assign(mc(e.Fp,r),{seed:ui(r.ORDER)});function i(E){try{let b=r.fromBytes(E);return r.isValidNot0(b)}catch{return!1}}function s(E,b){let{publicKey:A,publicKeyUncompressed:w}=o;try{let S=E.length;return b===!0&&S!==A||b===!1&&S!==w?!1:!!e.fromBytes(E)}catch{return!1}}function a(E=n(o.seed)){return fi(H(E,o.seed,"seed"),r.ORDER)}function c(E,b=!0){return e.BASE.multiply(r.fromBytes(E)).toBytes(b)}function f(E){let{secretKey:b,publicKey:A,publicKeyUncompressed:w}=o;if(!Be(E)||"_lengths"in r&&r._lengths||b===A)return;let S=H(E,void 0,"key").length;return S===A||S===w}function u(E,b,A=!0){if(f(E)===!0)throw new Error("first arg must be private key");if(f(b)===!1)throw new Error("second arg must be public key");let w=r.fromBytes(E);return e.fromBytes(b).multiply(w).toBytes(A)}let l={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},x=wn(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:x,Point:e,utils:l,lengths:o})}function yc(e,t,r={}){hn(t),ye(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||je,o=r.hmac||((y,d)=>Fi(t,y,d)),{Fp:i,Fn:s}=e,{ORDER:a,BITS:c}=s,{keygen:f,getPublicKey:u,getSharedSecret:l,utils:x,lengths:E}=Nd(e,r),b={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},A=a*dc<i.ORDER;function w(y){let d=a>>sr;return y>d}function S(y,d){if(!s.isValidNot0(d))throw new Error(`invalid signature ${y}: out of range 1..Point.Fn.ORDER`);return d}function B(){if(A)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function v(y,d){Hi(d);let I=E.signature,U=d==="compact"?I:d==="recovered"?I+1:void 0;return H(y,U)}class D{r;s;recovery;constructor(d,I,U){if(this.r=S("r",d),this.s=S("s",I),U!=null){if(B(),![0,1,2,3].includes(U))throw new Error("invalid recovery id");this.recovery=U}Object.freeze(this)}static fromBytes(d,I=b.format){v(d,I);let U;if(I==="der"){let{r:O,s:q}=we.toSig(H(d));return new D(O,q)}I==="recovered"&&(U=d[0],I="compact",d=d.subarray(1));let R=E.signature/2,k=d.subarray(0,R),K=d.subarray(R,R*2);return new D(s.fromBytes(k),s.fromBytes(K),U)}static fromHex(d,I){return this.fromBytes(ne(d),I)}assertRecovery(){let{recovery:d}=this;if(d==null)throw new Error("invalid recovery id: must be present");return d}addRecoveryBit(d){return new D(this.r,this.s,d)}recoverPublicKey(d){let{r:I,s:U}=this,R=this.assertRecovery(),k=R===2||R===3?I+a:I;if(!i.isValid(k))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let K=i.toBytes(k),O=e.fromBytes(wt(pc((R&1)===0),K)),q=s.inv(k),W=M(H(d,void 0,"msgHash")),G=s.create(-W*q),z=s.create(U*q),J=e.BASE.multiplyUnsafe(G).add(O.multiplyUnsafe(z));if(J.is0())throw new Error("invalid recovery: point at infinify");return J.assertValidity(),J}hasHighS(){return w(this.s)}toBytes(d=b.format){if(Hi(d),d==="der")return ne(we.hexFromSig(this));let{r:I,s:U}=this,R=s.toBytes(I),k=s.toBytes(U);return d==="recovered"?(B(),wt(Uint8Array.of(this.assertRecovery()),R,k)):wt(R,k)}toHex(d){return re(this.toBytes(d))}}let P=r.bits2int||function(d){if(d.length>8192)throw new Error("input is too large");let I=We(d),U=d.length*8-c;return U>0?I>>BigInt(U):I},M=r.bits2int_modN||function(d){return s.create(P(d))},F=_r(c);function h(y){return Cr("num < 2^"+c,y,se,F),s.toBytes(y)}function p(y,d){return H(y,void 0,"message"),d?H(t(y),void 0,"prehashed message"):y}function _(y,d,I){let{lowS:U,prehash:R,extraEntropy:k}=qi(I,b);y=p(y,R);let K=M(y),O=s.fromBytes(d);if(!s.isValidNot0(O))throw new Error("invalid private key");let q=[h(O),h(K)];if(k!=null&&k!==!1){let J=k===!0?n(E.secretKey):k;q.push(H(J,void 0,"extraEntropy"))}let W=wt(...q),G=K;function z(J){let ut=P(J);if(!s.isValidNot0(ut))return;let qt=s.inv(ut),Q=e.BASE.multiply(ut).toAffine(),ht=s.create(Q.x);if(ht===se)return;let rn=s.create(qt*s.create(G+ht*O));if(rn===se)return;let ms=(Q.x===ht?0:2)|Number(Q.y&sr),ys=rn;return U&&w(rn)&&(ys=s.neg(rn),ms^=1),new D(ht,ys,A?void 0:ms)}return{seed:W,k2sig:z}}function L(y,d,I={}){let{seed:U,k2sig:R}=_(y,d,I);return ma(t.outputLen,s.BYTES,o)(U,R).toBytes(I.format)}function T(y,d,I,U={}){let{lowS:R,prehash:k,format:K}=qi(U,b);if(I=H(I,void 0,"publicKey"),d=p(d,k),!Be(y)){let O=y instanceof D?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+O)}v(y,K);try{let O=D.fromBytes(y,K),q=e.fromBytes(I);if(R&&O.hasHighS())return!1;let{r:W,s:G}=O,z=M(d),J=s.inv(G),ut=s.create(z*J),qt=s.create(W*J),Q=e.BASE.multiplyUnsafe(ut).add(q.multiplyUnsafe(qt));return Q.is0()?!1:s.create(Q.x)===W}catch{return!1}}function m(y,d,I={}){let{prehash:U}=qi(I,b);return d=p(d,U),D.fromBytes(y,"recovered").recoverPublicKey(d).toBytes()}return Object.freeze({keygen:f,getPublicKey:u,getSharedSecret:l,utils:x,lengths:E,Point:e,sign:L,verify:T,recoverPublicKey:m,Signature:D,hash:t})}var Zi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},kd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var gc=BigInt(2);function Kd(e){let t=Zi.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=e*e*e%t,u=f*f*e%t,l=X(u,r,t)*u%t,x=X(l,r,t)*u%t,E=X(x,gc,t)*f%t,b=X(E,o,t)*E%t,A=X(b,i,t)*b%t,w=X(A,a,t)*A%t,S=X(w,c,t)*w%t,B=X(S,a,t)*A%t,v=X(B,r,t)*u%t,D=X(v,s,t)*b%t,P=X(D,n,t)*f%t,M=X(P,gc,t);if(!zi.eql(zi.sqr(M),e))throw new Error("Cannot find square root");return M}var zi=Qe(Zi.p,{sqrt:Kd}),Pd=hc(Zi,{Fp:zi,endo:kd}),Pt=yc(Pd,Xe);function xc(e,t,r){let n=un.digest(t instanceof Uint8Array?t:t.subarray());if(nr(n))return n.then(({digest:o})=>(r?.signal?.throwIfAborted(),Pt.sign(o,e,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new Rr(String(o))});try{return Pt.sign(n.digest,e,{prehash:!1,format:"der"})}catch(o){throw new Rr(String(o))}}function bc(e,t,r,n){let o=un.digest(r instanceof Uint8Array?r:r.subarray());if(nr(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Pt.verify(t,i,e,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new Nr(String(i))});try{return n?.signal?.throwIfAborted(),Pt.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(i){throw new Nr(String(i))}}var Hr=class{type="secp256k1";raw;_key;constructor(t){this._key=Sc(t),this.raw=wc(this._key)}toMultihash(){return Ie.digest(de(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:rt(this.raw,t.raw)}verify(t,r,n){return bc(this._key,r,t,n)}},Ln=class{type="secp256k1";raw;publicKey;constructor(t,r){this.raw=Ec(t),this.publicKey=new Hr(r??vc(t))}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:rt(this.raw,t.raw)}sign(t,r){return xc(this.raw,t,r)}};function Yi(e){return new Hr(e)}async function Ac(){let e=Od();return new Ln(e)}function wc(e){return Pt.Point.fromBytes(e).toBytes()}function Ec(e){try{return Pt.getPublicKey(e,!0),e}catch(t){throw new yr(String(t))}}function Sc(e){try{return Pt.Point.fromBytes(e),e}catch(t){throw new Fe(String(t))}}function vc(e){try{return Pt.getPublicKey(e,!0)}catch(t){throw new yr(String(t))}}function Od(){return Pt.utils.randomSecretKey()}async function Ic(e,t){if(e==="Ed25519")return Ha();if(e==="secp256k1")return Ac();if(e==="RSA")return Vi(Md(t));if(e==="ECDSA")return Ws(Vd(t));throw new qe}function Tc(e,t){let{Type:r,Data:n}=jt.decode(e),o=n??new Uint8Array;switch(r){case ot.RSA:return Pi(o,t);case ot.Ed25519:return gi(o);case ot.secp256k1:return Yi(o);case ot.ECDSA:return Yo(o);default:throw new qe}}function Bc(e){let{Type:t,Data:r}=jt.decode(e.digest),n=r??new Uint8Array;switch(t){case ot.Ed25519:return gi(n);case ot.secp256k1:return Yi(n);case ot.ECDSA:return Yo(n);default:throw new qe}}function de(e){return jt.encode({Type:ot[e.type],Data:e.raw})}function Md(e){return e==null?2048:parseInt(e,10)}function Vd(e){if(e==="P-256"||e==null)return"P-256";if(e==="P-384")return"P-384";if(e==="P-521")return"P-521";throw new tt("Unsupported curve, should be P-256, P-384 or P-521")}function Fd(e,t){if(typeof e=="string")return qd(e);if(typeof e=="number")return zd(e,t);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(e)}`)}var Dn=Fd;function qd(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 Hd(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 $d(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 zd(e,t){if(typeof e!="number"||!Number.isFinite(e))throw Error("Value provided to ms.format() must be of type number.");return t?.long?$d(e):Hd(e)}function Ke(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function Gi(e){r.debug=r,r.default=r,r.coerce=c,r.disable=i,r.enable=o,r.enabled=s,r.humanize=Dn,r.destroy=f,Object.keys(e).forEach(u=>{r[u]=e[u]}),r.names=[],r.skips=[],r.formatters={};function t(u){let l=0;for(let x=0;x<u.length;x++)l=(l<<5)-l+u.charCodeAt(x),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=t;function r(u){let l,x=null,E,b;function A(...w){if(!A.enabled)return;let S=A,B=Number(new Date),v=B-(l||B);S.diff=v,S.prev=l,S.curr=B,l=B,w[0]=r.coerce(w[0]),typeof w[0]!="string"&&w.unshift("%O");let D=0;w[0]=w[0].replace(/%([a-zA-Z%])/g,(M,F)=>{if(M==="%%")return"%";D++;let h=r.formatters[F];if(typeof h=="function"){let p=w[D];M=h.call(S,p),w.splice(D,1),D--}return M}),r.formatArgs.call(S,w),(S.log||r.log).apply(S,w)}return A.namespace=u,A.useColors=r.useColors(),A.color=r.selectColor(u),A.extend=n,A.destroy=r.destroy,Object.defineProperty(A,"enabled",{enumerable:!0,configurable:!1,get:()=>x!==null?x:(E!==r.namespaces&&(E=r.namespaces,b=r.enabled(u)),b),set:w=>{x=w}}),typeof r.init=="function"&&r.init(A),A}function n(u,l){let x=r(this.namespace+(typeof l>"u"?":":l)+u);return x.log=this.log,x}function o(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];let l,x=(typeof u=="string"?u:"").split(/[\s,]+/),E=x.length;for(l=0;l<E;l++)x[l]&&(u=x[l].replace(/\*/g,".*?"),u[0]==="-"?r.skips.push(new RegExp("^"+u.substr(1)+"$")):r.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...r.names.map(a),...r.skips.map(a).map(l=>"-"+l)].join(",");return r.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let l,x;for(l=0,x=r.skips.length;l<x;l++)if(r.skips[l].test(u))return!1;for(l=0,x=r.names.length;l<x;l++)if(r.names[l].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function c(u){return u instanceof Error?u.stack??u.message:u}function f(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var Un=Jd(),Zd=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Yd(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function Gd(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+Dn(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 jd=console.debug??console.log??(()=>{});function Xd(e){try{e?Un?.setItem("debug",e):Un?.removeItem("debug")}catch{}}function Wd(){let e;try{e=Un?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function Jd(){try{return localStorage}catch{}}function Qd(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Cc=Gi({formatArgs:Gd,save:Xd,load:Wd,useColors:Yd,setupFormatters:Qd,colors:Zd,storage:Un,log:jd});var St=Cc;St.formatters.b=e=>e==null?"undefined":j.baseEncode(e);St.formatters.t=e=>e==null?"undefined":fe.baseEncode(e);St.formatters.m=e=>e==null?"undefined":No.baseEncode(e);St.formatters.p=e=>e==null?"undefined":e.toString();St.formatters.c=e=>e==null?"undefined":e.toString();St.formatters.k=e=>e==null?"undefined":e.toString();St.formatters.a=e=>e==null?"undefined":e.toString();St.formatters.e=e=>e==null?"undefined":_c(e.stack)??_c(e.message)??e.toString();function th(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 Pe(e){let t=th(`${e}:trace`);return St.enabled(`${e}:trace`)&&St.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(t=St(`${e}:trace`)),Object.assign(St(e),{error:St(`${e}:error`),trace:t,newScope:r=>Pe(`${e}:${r}`)})}function _c(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var qu=xo(Rn(),1);var Nn=class extends Error{static name="SignatureCreationError";constructor(t="Record signature creation failed"){super(t),this.name="SignatureCreationError"}},Ot=class extends Error{static name="SignatureVerificationError";constructor(t="Record signature verification failed"){super(t),this.name="SignatureVerificationError"}},kn=class extends Error{static name="RecordExpiredError";constructor(t="Record has expired"){super(t),this.name="RecordExpiredError"}},Oe=class extends Error{static name="UnsupportedValidityError";constructor(t="The validity type is unsupported"){super(t),this.name="UnsupportedValidityError"}},Kn=class extends Error{static name="RecordTooLargeError";constructor(t="The record is too large"){super(t),this.name="RecordTooLargeError"}},$r=class extends Error{static name="InvalidValueError";constructor(t="Value must be a valid content path starting with /"){super(t),this.name="InvalidValueError"}},Pn=class extends Error{static name="InvalidRecordDataError";constructor(t="Invalid record data"){super(t),this.name="InvalidRecordDataError"}},zr=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(t="Invalid embedded public key"){super(t),this.name="InvalidEmbeddedPublicKeyError"}};var lt;(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=()=>Vr(r)})(t=e.ValidityType||(e.ValidityType={}));let n;e.codec=()=>(n==null&&(n=Gt((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.value!=null&&(i.uint32(10),i.bytes(o.value)),o.signatureV1!=null&&(i.uint32(18),i.bytes(o.signatureV1)),o.validityType!=null&&(i.uint32(24),e.ValidityType.codec().encode(o.validityType,i)),o.validity!=null&&(i.uint32(34),i.bytes(o.validity)),o.sequence!=null&&(i.uint32(40),i.uint64(o.sequence)),o.ttl!=null&&(i.uint32(48),i.uint64(o.ttl)),o.pubKey!=null&&(i.uint32(58),i.bytes(o.pubKey)),o.signatureV2!=null&&(i.uint32(66),i.bytes(o.signatureV2)),o.data!=null&&(i.uint32(74),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let f=o.uint32();switch(f>>>3){case 1:{a.value=o.bytes();break}case 2:{a.signatureV1=o.bytes();break}case 3:{a.validityType=e.ValidityType.codec().decode(o);break}case 4:{a.validity=o.bytes();break}case 5:{a.sequence=o.uint64();break}case 6:{a.ttl=o.uint64();break}case 7:{a.pubKey=o.bytes();break}case 8:{a.signatureV2=o.bytes();break}case 9:{a.data=o.bytes();break}default:{o.skipType(f&7);break}}}return a})),n),e.encode=o=>Yt(o,e.codec()),e.decode=(o,i)=>Zt(o,e.codec(),i)})(lt||(lt={}));var On=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var eh=["string","number","bigint","symbol"],rh=["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 Lc(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(eh.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(nh(e))return"Buffer";let r=oh(e);return r||"Object"}function nh(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function oh(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(rh.includes(t))return t}var g=class{constructor(t,r,n){this.major=t,this.majorEncoded=t<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}};g.uint=new g(0,"uint",!0);g.negint=new g(1,"negint",!0);g.bytes=new g(2,"bytes",!0);g.string=new g(3,"string",!0);g.array=new g(4,"array",!1);g.map=new g(5,"map",!1);g.tag=new g(6,"tag",!1);g.float=new g(7,"float",!0);g.false=new g(7,"false",!0);g.true=new g(7,"true",!0);g.null=new g(7,"null",!0);g.undefined=new g(7,"undefined",!0);g.break=new g(7,"break",!0);var N=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var ar=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",ih=new TextDecoder,sh=new TextEncoder;function Mn(e){return ar&&globalThis.Buffer.isBuffer(e)}function Xi(e){return e instanceof Uint8Array?Mn(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Nc=ar?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):Uc(e,t,r):(e,t,r)=>r-t>64?ih.decode(e.subarray(t,r)):Uc(e,t,r),kc=ar?e=>e.length>64?globalThis.Buffer.from(e):Dc(e):e=>e.length>64?sh.encode(e):Dc(e),Xt=e=>Uint8Array.from(e),cr=ar?(e,t,r)=>Mn(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Kc=ar?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Xi(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},Pc=ar?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function Oc(e,t){if(Mn(e)&&Mn(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 Dc(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 Uc(e,t,r){let n=[];for(;t<r;){let o=e[t],i=null,s=o>239?4:o>223?3:o>191?2:1;if(t+s<=r){let a,c,f,u;switch(s){case 1:o<128&&(i=o);break;case 2:a=e[t+1],(a&192)===128&&(u=(o&31)<<6|a&63,u>127&&(i=u));break;case 3:a=e[t+1],c=e[t+2],(a&192)===128&&(c&192)===128&&(u=(o&15)<<12|(a&63)<<6|c&63,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:a=e[t+1],c=e[t+2],f=e[t+3],(a&192)===128&&(c&192)===128&&(f&192)===128&&(u=(o&15)<<18|(a&63)<<12|(c&63)<<6|f&63,u>65535&&u<1114112&&(i=u))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=s}return ah(n)}var Rc=4096;function ah(e){let t=e.length;if(t<=Rc)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Rc));return r}var ch=256,Zr=class{constructor(t=ch){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=Pc(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=cr(n,0,this.cursor)}else r=Kc(this.chunks,this.cursor);return t&&this.reset(),r}};var V="CBOR decode error:",Wi="CBOR encode error:",Yr=[];Yr[23]=1;Yr[24]=2;Yr[25]=3;Yr[26]=5;Yr[27]=9;function ae(e,t,r){if(e.length-t<r)throw new Error(`${V} not enough data for type`)}var ct=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Tt(e,t,r){ae(e,t,1);let n=e[t];if(r.strict===!0&&n<ct[0])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function Bt(e,t,r){ae(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<ct[1])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function Ct(e,t,r){ae(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<ct[2])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function _t(e,t,r){ae(e,t,8);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<ct[3])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${V} integers outside of the safe integer range are not supported`)}function Mc(e,t,r,n){return new N(g.uint,Tt(e,t+1,n),2)}function Vc(e,t,r,n){return new N(g.uint,Bt(e,t+1,n),3)}function Fc(e,t,r,n){return new N(g.uint,Ct(e,t+1,n),5)}function qc(e,t,r,n){return new N(g.uint,_t(e,t+1,n),9)}function Dt(e,t){return dt(e,0,t.value)}function dt(e,t,r){if(r<ct[0]){let n=Number(r);e.push([t|n])}else if(r<ct[1]){let n=Number(r);e.push([t|24,n])}else if(r<ct[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<ct[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<ct[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,e.push(o)}else throw new Error(`${V} encountered BigInt larger than allowable range`)}}Dt.encodedSize=function(t){return dt.encodedSize(t.value)};dt.encodedSize=function(t){return t<ct[0]?1:t<ct[1]?2:t<ct[2]?3:t<ct[3]?5:9};Dt.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function Hc(e,t,r,n){return new N(g.negint,-1-Tt(e,t+1,n),2)}function $c(e,t,r,n){return new N(g.negint,-1-Bt(e,t+1,n),3)}function zc(e,t,r,n){return new N(g.negint,-1-Ct(e,t+1,n),5)}var Ji=BigInt(-1),Zc=BigInt(1);function Yc(e,t,r,n){let o=_t(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new N(g.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${V} integers outside of the safe integer range are not supported`);return new N(g.negint,Ji-BigInt(o),9)}function Vn(e,t){let r=t.value,n=typeof r=="bigint"?r*Ji-Zc:r*-1-1;dt(e,t.type.majorEncoded,n)}Vn.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*Ji-Zc:r*-1-1;return n<ct[0]?1:n<ct[1]?2:n<ct[2]?3:n<ct[3]?5:9};Vn.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function Gr(e,t,r,n){ae(e,t,r+n);let o=cr(e,t+r,t+r+n);return new N(g.bytes,o,r+n)}function Gc(e,t,r,n){return Gr(e,t,1,r)}function jc(e,t,r,n){return Gr(e,t,2,Tt(e,t+1,n))}function Xc(e,t,r,n){return Gr(e,t,3,Bt(e,t+1,n))}function Wc(e,t,r,n){return Gr(e,t,5,Ct(e,t+1,n))}function Jc(e,t,r,n){let o=_t(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer bytes lengths not supported`);return Gr(e,t,9,o)}function Fn(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===g.string?kc(e.value):e.value),e.encodedBytes}function ur(e,t){let r=Fn(t);dt(e,t.type.majorEncoded,r.length),e.push(r)}ur.encodedSize=function(t){let r=Fn(t);return dt.encodedSize(r.length)+r.length};ur.compareTokens=function(t,r){return fh(Fn(t),Fn(r))};function fh(e,t){return e.length<t.length?-1:e.length>t.length?1:Oc(e,t)}function jr(e,t,r,n,o){let i=r+n;ae(e,t,i);let s=new N(g.string,Nc(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=cr(e,t+r,t+i)),s}function Qc(e,t,r,n){return jr(e,t,1,r,n)}function tu(e,t,r,n){return jr(e,t,2,Tt(e,t+1,n),n)}function eu(e,t,r,n){return jr(e,t,3,Bt(e,t+1,n),n)}function ru(e,t,r,n){return jr(e,t,5,Ct(e,t+1,n),n)}function nu(e,t,r,n){let o=_t(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer string lengths not supported`);return jr(e,t,9,o,n)}var ou=ur;function fr(e,t,r,n){return new N(g.array,n,r)}function iu(e,t,r,n){return fr(e,t,1,r)}function su(e,t,r,n){return fr(e,t,2,Tt(e,t+1,n))}function au(e,t,r,n){return fr(e,t,3,Bt(e,t+1,n))}function cu(e,t,r,n){return fr(e,t,5,Ct(e,t+1,n))}function uu(e,t,r,n){let o=_t(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer array lengths not supported`);return fr(e,t,9,o)}function fu(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return fr(e,t,1,1/0)}function qn(e,t){dt(e,g.array.majorEncoded,t.value)}qn.compareTokens=Dt.compareTokens;qn.encodedSize=function(t){return dt.encodedSize(t.value)};function lr(e,t,r,n){return new N(g.map,n,r)}function lu(e,t,r,n){return lr(e,t,1,r)}function du(e,t,r,n){return lr(e,t,2,Tt(e,t+1,n))}function hu(e,t,r,n){return lr(e,t,3,Bt(e,t+1,n))}function pu(e,t,r,n){return lr(e,t,5,Ct(e,t+1,n))}function mu(e,t,r,n){let o=_t(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer map lengths not supported`);return lr(e,t,9,o)}function yu(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return lr(e,t,1,1/0)}function Hn(e,t){dt(e,g.map.majorEncoded,t.value)}Hn.compareTokens=Dt.compareTokens;Hn.encodedSize=function(t){return dt.encodedSize(t.value)};function gu(e,t,r,n){return new N(g.tag,r,1)}function xu(e,t,r,n){return new N(g.tag,Tt(e,t+1,n),2)}function bu(e,t,r,n){return new N(g.tag,Bt(e,t+1,n),3)}function wu(e,t,r,n){return new N(g.tag,Ct(e,t+1,n),5)}function Eu(e,t,r,n){return new N(g.tag,_t(e,t+1,n),9)}function $n(e,t){dt(e,g.tag.majorEncoded,t.value)}$n.compareTokens=Dt.compareTokens;$n.encodedSize=function(t){return dt.encodedSize(t.value)};var yh=20,gh=21,xh=22,bh=23;function Su(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${V} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new N(g.null,null,1):new N(g.undefined,void 0,1)}function vu(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return new N(g.break,void 0,1)}function Qi(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${V} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${V} Infinity values are not supported`)}return new N(g.float,e,t)}function Au(e,t,r,n){return Qi(ts(e,t+1),3,n)}function Iu(e,t,r,n){return Qi(es(e,t+1),5,n)}function Tu(e,t,r,n){return Qi(Lu(e,t+1),9,n)}function zn(e,t,r){let n=t.value;if(n===!1)e.push([g.float.majorEncoded|yh]);else if(n===!0)e.push([g.float.majorEncoded|gh]);else if(n===null)e.push([g.float.majorEncoded|xh]);else if(n===void 0)e.push([g.float.majorEncoded|bh]);else{let o,i=!1;(!r||r.float64!==!0)&&(Cu(n),o=ts(Mt,1),n===o||Number.isNaN(n)?(Mt[0]=249,e.push(Mt.slice(0,3)),i=!0):(_u(n),o=es(Mt,1),n===o&&(Mt[0]=250,e.push(Mt.slice(0,5)),i=!0))),i||(wh(n),o=Lu(Mt,1),Mt[0]=251,e.push(Mt.slice(0,9)))}}zn.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){Cu(n);let o=ts(Mt,1);if(n===o||Number.isNaN(n))return 3;if(_u(n),o=es(Mt,1),n===o)return 5}return 9};var Bu=new ArrayBuffer(9),Ut=new DataView(Bu,1),Mt=new Uint8Array(Bu,0);function Cu(e){if(e===1/0)Ut.setUint16(0,31744,!1);else if(e===-1/0)Ut.setUint16(0,64512,!1);else if(Number.isNaN(e))Ut.setUint16(0,32256,!1);else{Ut.setFloat32(0,e);let t=Ut.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)Ut.setUint16(0,31744,!1);else if(r===0)Ut.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Ut.setUint16(0,0):o<-14?Ut.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):Ut.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function ts(e,t){if(e.length-t<2)throw new Error(`${V} not enough data for float16`);let r=(e[t]<<8)+e[t+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function _u(e){Ut.setFloat32(0,e,!1)}function es(e,t){if(e.length-t<4)throw new Error(`${V} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function wh(e){Ut.setFloat64(0,e,!1)}function Lu(e,t){if(e.length-t<8)throw new Error(`${V} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}zn.compareTokens=Dt.compareTokens;function Z(e,t,r){throw new Error(`${V} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Zn(e){return()=>{throw new Error(`${V} ${e}`)}}var C=[];for(let e=0;e<=23;e++)C[e]=Z;C[24]=Mc;C[25]=Vc;C[26]=Fc;C[27]=qc;C[28]=Z;C[29]=Z;C[30]=Z;C[31]=Z;for(let e=32;e<=55;e++)C[e]=Z;C[56]=Hc;C[57]=$c;C[58]=zc;C[59]=Yc;C[60]=Z;C[61]=Z;C[62]=Z;C[63]=Z;for(let e=64;e<=87;e++)C[e]=Gc;C[88]=jc;C[89]=Xc;C[90]=Wc;C[91]=Jc;C[92]=Z;C[93]=Z;C[94]=Z;C[95]=Zn("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)C[e]=Qc;C[120]=tu;C[121]=eu;C[122]=ru;C[123]=nu;C[124]=Z;C[125]=Z;C[126]=Z;C[127]=Zn("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)C[e]=iu;C[152]=su;C[153]=au;C[154]=cu;C[155]=uu;C[156]=Z;C[157]=Z;C[158]=Z;C[159]=fu;for(let e=160;e<=183;e++)C[e]=lu;C[184]=du;C[185]=hu;C[186]=pu;C[187]=mu;C[188]=Z;C[189]=Z;C[190]=Z;C[191]=yu;for(let e=192;e<=215;e++)C[e]=gu;C[216]=xu;C[217]=bu;C[218]=wu;C[219]=Eu;C[220]=Z;C[221]=Z;C[222]=Z;C[223]=Z;for(let e=224;e<=243;e++)C[e]=Zn("simple values are not supported");C[244]=Z;C[245]=Z;C[246]=Z;C[247]=Su;C[248]=Zn("simple values are not supported");C[249]=Au;C[250]=Iu;C[251]=Tu;C[252]=Z;C[253]=Z;C[254]=Z;C[255]=vu;var Vt=[];for(let e=0;e<24;e++)Vt[e]=new N(g.uint,e,1);for(let e=-1;e>=-24;e--)Vt[31-e]=new N(g.negint,e,1);Vt[64]=new N(g.bytes,new Uint8Array(0),1);Vt[96]=new N(g.string,"",1);Vt[128]=new N(g.array,0,1);Vt[160]=new N(g.map,0,1);Vt[244]=new N(g.false,!1,1);Vt[245]=new N(g.true,!0,1);Vt[246]=new N(g.null,null,1);function Du(e){switch(e.type){case g.false:return Xt([244]);case g.true:return Xt([245]);case g.null:return Xt([246]);case g.bytes:return e.value.length?void 0:Xt([64]);case g.string:return e.value===""?Xt([96]):void 0;case g.array:return e.value===0?Xt([128]):void 0;case g.map:return e.value===0?Xt([160]):void 0;case g.uint:return e.value<24?Xt([Number(e.value)]):void 0;case g.negint:if(e.value>=-24)return Xt([31-Number(e.value)])}}var Sh={float64:!1,mapSorter:Ih,quickEncodeToken:Du};function vh(){let e=[];return e[g.uint.major]=Dt,e[g.negint.major]=Vn,e[g.bytes.major]=ur,e[g.string.major]=ou,e[g.array.major]=qn,e[g.map.major]=Hn,e[g.tag.major]=$n,e[g.float.major]=zn,e}var Uu=vh(),rs=new Zr,Gn=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(`${Wi} object contains circular references`);return new e(r,t)}},Ee={null:new N(g.null,null),undefined:new N(g.undefined,void 0),true:new N(g.true,!0),false:new N(g.false,!1),emptyArray:new N(g.array,0),emptyMap:new N(g.map,0)},Se={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new N(g.float,e):e>=0?new N(g.uint,e):new N(g.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new N(g.uint,e):new N(g.negint,e)},Uint8Array(e,t,r,n){return new N(g.bytes,e)},string(e,t,r,n){return new N(g.string,e)},boolean(e,t,r,n){return e?Ee.true:Ee.false},null(e,t,r,n){return Ee.null},undefined(e,t,r,n){return Ee.undefined},ArrayBuffer(e,t,r,n){return new N(g.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new N(g.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[Ee.emptyArray,new N(g.break)]:Ee.emptyArray;n=Gn.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=Yn(s,r,n);return r.addBreakTokens?[new N(g.array,e.length),o,new N(g.break)]:[new N(g.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),s=o?e.size:i.length;if(!s)return r.addBreakTokens===!0?[Ee.emptyMap,new N(g.break)]:Ee.emptyMap;n=Gn.createCheck(n,e);let a=[],c=0;for(let f of i)a[c++]=[Yn(f,r,n),Yn(o?e.get(f):e[f],r,n)];return Ah(a,r),r.addBreakTokens?[new N(g.map,s),a,new N(g.break)]:[new N(g.map,s),a]}};Se.Map=Se.Object;Se.Buffer=Se.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Se[`${e}Array`]=Se.DataView;function Yn(e,t={},r){let n=Lc(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||Se[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=Se[n];if(!i)throw new Error(`${Wi} unsupported type: ${n}`);return i(e,n,t,r)}function Ah(e,t){t.mapSorter&&e.sort(t.mapSorter)}function Ih(e,t){let r=Array.isArray(e[0])?e[0][0]:e[0],n=Array.isArray(t[0])?t[0][0]:t[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=Uu[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Ru(e,t,r,n){if(Array.isArray(t))for(let o of t)Ru(e,o,r,n);else r[t.type.major](e,t,n)}function Th(e,t,r){let n=Yn(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),a=new Zr(s);if(i(a,n,r),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return Xi(a.chunks[0])}}return rs.reset(),Ru(rs,n,t,r),rs.toBytes(!0)}function ns(e,t){return t=Object.assign({},Sh,t),Th(e,Uu,t)}var Bh={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},jn=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=Vt[t];if(r===void 0){let n=C[t];if(!n)throw new Error(`${V} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},Xr=Symbol.for("DONE"),Xn=Symbol.for("BREAK");function Ch(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=dr(t,r);if(i===Xn){if(e.value===1/0)break;throw new Error(`${V} got unexpected break to lengthed array`)}if(i===Xr)throw new Error(`${V} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function _h(e,t,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<e.value;s++){let a=dr(t,r);if(a===Xn){if(e.value===1/0)break;throw new Error(`${V} got unexpected break to lengthed map`)}if(a===Xr)throw new Error(`${V} found map but not enough entries (got ${s} [no key], expected ${e.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${V} non-string keys not supported (got ${typeof a})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${V} found repeat map key "${a}"`);let c=dr(t,r);if(c===Xr)throw new Error(`${V} found map but not enough entries (got ${s} [no value], expected ${e.value})`);n?i.set(a,c):o[a]=c}return n?i:o}function dr(e,t){if(e.done())return Xr;let r=e.next();if(r.type===g.break)return Xn;if(r.type.terminal)return r.value;if(r.type===g.array)return Ch(r,e,t);if(r.type===g.map)return _h(r,e,t);if(r.type===g.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=dr(e,t);return t.tags[r.value](n)}throw new Error(`${V} tag not supported (${r.value})`)}throw new Error("unsupported")}function Nu(e,t){if(!(e instanceof Uint8Array))throw new Error(`${V} data to decode must be a Uint8Array`);t=Object.assign({},Bh,t);let r=t.tokenizer||new jn(e,t),n=dr(r,t);if(n===Xr)throw new Error(`${V} did not find any content to decode`);if(n===Xn)throw new Error(`${V} got unexpected break`);return[n,e.subarray(r.pos())]}function os(e,t){let[r,n]=Nu(e,t);if(n.length>0)throw new Error(`${V} too many terminals, data makes no sense`);return r}var Dh=Pe("ipns:utils"),ku=$("/ipns/"),Uh=114,Rh=0,Nh=18;function Ku(e){let t;if(e.pubKey!=null)try{t=Tc(e.pubKey)}catch(r){throw Dh.error(r),r}if(t!=null)return t}function Pu(e,t,r){let n=$(t);return le([e,r,n])}function Jn(e){let t=$("ipns-signature:");return le([t,e])}function Qn(e){return"signatureV1"in e?lt.encode({value:$(e.value),signatureV1:e.signatureV1,validityType:e.validityType,validity:$(e.validity),sequence:e.sequence,ttl:e.ttl,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data}):lt.encode({pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data})}function Ft(e){let t=lt.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 Ot("Missing data or signatureV2");let r=Vu(t.data),n=kh(r.Value),o=Y(r.Validity);if(t.value!=null&&t.signatureV1!=null)return Kh(t),{value:n,validityType:lt.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:lt.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 Ve(e){return le([ku,e.bytes])}function Ou(e){let t=Ye(e.slice(ku.length));if(!Wn(t,Rh)&&!Wn(t,Nh))throw new On("Multihash in IPNS key was not identity or sha2-256");return t}function Mu(e,t,r,n,o){let i;if(t===lt.ValidityType.EOL)i=0;else throw new Oe("The validity type is unsupported");return ns({Value:e,Validity:r,ValidityType:i,Sequence:n,TTL:o})}function Vu(e){let t=os(e);if(t.ValidityType===0)t.ValidityType=lt.ValidityType.EOL;else throw new Oe("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 kh(e){let t=Y(e).trim();if(t.startsWith("/"))return t;try{return`/ipfs/${it.decode(e).toV1().toString()}`}catch{}try{return`/ipfs/${it.parse(t).toV1().toString()}`}catch{}throw new $r("Value must be a valid content path starting with /")}function Fu(e){if(e!=null){let t=Mh(e);if(t!=null)return t.code===Uh?`/ipns/${t.toString(Rt)}`:`/ipfs/${t.toV1().toString()}`;if(Ph(e))return`/ipns/${Rt.encode(e.bytes)}`;let r=e.toString().trim();if(r.startsWith("/")&&r.length>1)return r}throw new $r("Value must be a valid content path starting with /")}function Kh(e){if(e.data==null)throw new Pn("Record data is missing");let t=Vu(e.data);if(!rt(t.Value,e.value??new Uint8Array(0)))throw new Ot('Field "value" did not match between protobuf and CBOR');if(!rt(t.Validity,e.validity??new Uint8Array(0)))throw new Ot('Field "validity" did not match between protobuf and CBOR');if(t.ValidityType!==e.validityType)throw new Ot('Field "validityType" did not match between protobuf and CBOR');if(t.Sequence!==e.sequence)throw new Ot('Field "sequence" did not match between protobuf and CBOR');if(t.TTL!==e.ttl)throw new Ot('Field "ttl" did not match between protobuf and CBOR')}function Ph(e){return e.bytes instanceof Uint8Array}function Oh(e){return typeof e?.toCID=="function"}function Mh(e){if(Oh(e))return e.toCID();try{return it.parse(e)}catch{}return it.asCID(e)}function Wn(e,t){return e.code===t}var to=Pe("ipns:validator"),Vh=1024*10;async function Fh(e,t){let r=Ft(t),n;try{let o=Jn(r.data);n=await e.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw to.error("record signature verification failed"),new Ot("Record signature verification failed");if(r.validityType===lt.ValidityType.EOL){if(qu.default.fromString(r.validity).toDate().getTime()<Date.now())throw to.error("record has expired"),new kn("record has expired")}else if(r.validityType!=null)throw to.error("the validity type is unsupported"),new Oe("The validity type is unsupported");to("ipns record for %s is valid",r.value)}async function Wr(e,t){if(t.byteLength>Vh)throw new Kn("The record is too large");let r=Ou(e),n;Wn(r,0)&&(n=Bc(r));let o=Ft(t),i=Ku(o)??n;if(i==null)throw new zr("Could not extract public key from IPNS record or routing key");let s=Ve(i.toMultihash());if(!rt(s,e))throw new zr("Embedded public key did not match routing key");await Fh(i,t)}function hr(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var eo=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},pr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new eo(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new eo(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var is=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Hu(e={}){return qh(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function qh(e,t){t=t??{};let r=t.onEnd,n=new pr,o,i,s,a=hr(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((w,S)=>{i=B=>{i=null,n.push(B);try{w(e(n))}catch(v){S(v)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=hr()})}},f=w=>i!=null?i(w):(n.push(w),o),u=w=>(n=new pr,i!=null?i({error:w}):(n.push({error:w}),o)),l=w=>{if(s)return o;if(t?.objectMode!==!0&&w?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:w})},x=w=>s?o:(s=!0,w!=null?u(w):f({done:!0})),E=()=>(n=new pr,x(),{done:!0}),b=w=>(x(w),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:E,throw:b,push:l,end:x,get readableLength(){return n.size},onEmpty:async w=>{let S=w?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let B,v;S!=null&&(B=new Promise((D,P)=>{v=()=>{P(new is)},S.addEventListener("abort",v)}));try{await Promise.race([a.promise,B])}finally{v!=null&&S!=null&&S?.removeEventListener("abort",v)}}},r==null)return o;let A=o;return o={[Symbol.asyncIterator](){return this},next(){return A.next()},throw(w){return A.throw(w),r!=null&&(r(w),r=void 0),{done:!0}},return(){return A.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(w){return A.end(w),r!=null&&(r(w),r=void 0),o},get readableLength(){return A.readableLength},onEmpty:w=>A.onEmpty(w)},o}var ss=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},as=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},$u=e=>globalThis.DOMException===void 0?new as(e):new DOMException(e),zu=e=>{let t=e.reason===void 0?$u("This operation was aborted."):e.reason;return t instanceof Error?t:$u(t)};function cs(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=t,s,a,f=new Promise((u,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:E}=t;E.aborted&&l(zu(E)),a=()=>{l(zu(E))},E.addEventListener("abort",a,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(u,l);return}let x=new ss;s=i.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(E){l(E)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?u():o instanceof Error?l(o):(x.message=o??`Promise timed out after ${r} milliseconds`,l(x))},r),(async()=>{try{u(await e)}catch(E){l(E)}})()}).finally(()=>{f.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return f.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},f}var Hh=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function $h(e,t,r){let n,o=new Promise((i,s)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:f,removeListener:u}=Hh(e),l=async(...E)=>{let b=r.multiArgs?E:E[0];if(r.filter)try{if(!await r.filter(b))return}catch(A){n(),s(A);return}c.push(b),r.count===c.length&&(n(),i(c))},x=(...E)=>{n(),s(r.rejectionMultiArgs?E:E[0])};n=()=>{for(let E of a)u(E,l);for(let E of r.rejectionEvents)a.includes(E)||u(E,x)};for(let E of a)f(E,l);for(let E of r.rejectionEvents)a.includes(E)||f(E,x);r.signal&&r.signal.addEventListener("abort",()=>{x(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(o.cancel=n,typeof r.timeout=="number"){let i=cs(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function ro(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=$h(e,t,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function Jr(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var no=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};function zh(e){return e.reason}async function Zu(e,t,r){if(t==null)return e;let n=r?.translateError??zh;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((i,s)=>{o=()=>{s(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var oo=class{deferred;signal;constructor(t){this.signal=t,this.deferred=hr(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Wt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Zh(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var io=class{id;fn;options;recipients;status;timeline;controller;constructor(t,r){this.id=Zh(),this.status="queued",this.fn=t,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Wt),this.cleanup())}async join(t={}){let r=new oo(t.signal);return this.recipients.push(r),t.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await Zu(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(r=>{r.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};var so=class extends sn{concurrency;maxSize;queue;pending;sort;paused;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,t.metricName!=null&&t.metrics?.registerMetricGroup(t.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=t.sort,this.queue=[],this.emitEmpty=Jr(this.emitEmpty.bind(this),1),this.emitIdle=Jr(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let r of this.queue)if(r.status==="queued"){t=r;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===t){this.queue.splice(r,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new no;let n=new io(t,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new Wt)}),this.clear()}async onEmpty(t){this.size!==0&&await ro(this,"empty",t)}async onSizeLessThan(t,r){this.size<t||await ro(this,"next",{...r,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await ro(this,"idle",t)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let r=Hu({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail)},i=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new Wt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",i),this.addEventListener("idle",s),t?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),t?.signal?.removeEventListener("abort",a),n()}}};function Yu(e){let t=new globalThis.AbortController;function r(){t.abort();for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}for(let i of e){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=t.signal;return o.clear=n,o}function Gu(e,t,r){let n,o,i=!1;function s(){let f={signal:o.signal};if(r?.timeout!=null){let u=Yu([o.signal,AbortSignal.timeout(r.timeout)]);f.signal=u}i=!0,Promise.resolve().then(async()=>{await e(f)}).catch(()=>{}).finally(()=>{i=!1,!o.signal.aborted&&(n=setTimeout(s,t))})}let a=Jr(s,r?.debounce??100),c=!1;return{setInterval:f=>{t!==f&&(t=f,n!=null&&(clearTimeout(n),n=setTimeout(s,t)))},setTimeout:f=>{r??={},r.timeout=f},run:()=>{i||(clearTimeout(n),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,t))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var ju=xo(Rn(),1);var Yh=Pe("ipns"),Xu=300*1e9,Gh="/ipns/",Nb=Gh.length,Wu={v1Compatible:!0,ttlNs:Xu};async function us(e,t,r,n,o=Wu){let i=new ju.default(Date.now()+Number(n)),s=lt.ValidityType.EOL,a=BigInt(o.ttlNs??Xu);return jh(e,t,r,s,i.toString(),a,o)}var jh=async(e,t,r,n,o,i,s=Wu)=>{r=BigInt(r);let a=$(o),c=Fu(t),f=$(c),u=Mu(f,n,a,r,i),l=Jn(u),x=await e.sign(l),E;if(e.type==="RSA"&&(E=de(e.publicKey)),s.v1Compatible===!0){let b=await Xh(e,f,n,a),A={value:c,signatureV1:b,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:x,data:u};return E!=null&&(A.pubKey=E),A}else{let b={value:c,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:x,data:u};return E!=null&&(b.pubKey=E),b}},Xh=async(e,t,r,n)=>{try{let o=Pu(t,r,n);return await e.sign(o)}catch(o){throw Yh.error("record signature creation failed",o),new Nn("Record signature creation failed")}};var fs=xo(Rn(),1);function ao(e,t){let r=t.map((n,o)=>({record:Ft(n),index:o}));return r.sort((n,o)=>{let i=n.record.sequence,s=o.record.sequence;if(i>s)return-1;if(i<s)return 1;if(n.record.validityType===lt.ValidityType.EOL&&o.record.validityType===lt.ValidityType.EOL){let a=fs.default.fromString(n.record.validity).toDate(),c=fs.default.fromString(o.record.validity).toDate();if(a.getTime()>c.getTime())return-1;if(a.getTime()<c.getTime())return 1}return 0}),r[0].index}var vt=class extends Event{type;detail;constructor(t,r){super(t),this.type=t,this.detail=r}};var co=BigInt(6e4)*5000000n,Ju=5;var uo=class extends Error{static name="RecordsFailedValidationError";constructor(t="Records failed validation"){super(t),this.name="RecordsFailedValidationError"}},fo=class extends Error{static name="UnsupportedMultibasePrefixError";constructor(t="Unsupported multibase prefix"){super(t),this.name="UnsupportedMultibasePrefixError"}},lo=class extends Error{static name="UnsupportedMultihashCodecError";constructor(t="Unsupported multihash codec"){super(t),this.name="UnsupportedMultihashCodecError"}},ho=class extends Error{static name="InvalidValueError";constructor(t="Invalid value"){super(t),this.name="InvalidValueError"}};var Qr;(function(e){let t;e.codec=()=>(t==null&&(t=Gt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.key!=null&&r.key.byteLength>0&&(n.uint32(10),n.bytes(r.key)),r.value!=null&&r.value.byteLength>0&&(n.uint32(18),n.bytes(r.value)),r.timeReceived!=null&&r.timeReceived!==""&&(n.uint32(42),n.string(r.timeReceived)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={key:Lt(0),value:Lt(0),timeReceived:""},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let a=r.uint32();switch(a>>>3){case 1:{i.key=r.bytes();break}case 2:{i.value=r.bytes();break}case 5:{i.timeReceived=r.string();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>Yt(r,e.codec()),e.decode=(r,n)=>Zt(r,e.codec(),n)})(Qr||(Qr={}));function Qu(e){let t=e.getUTCFullYear(),r=String(e.getUTCMonth()+1).padStart(2,"0"),n=String(e.getUTCDate()).padStart(2,"0"),o=String(e.getUTCHours()).padStart(2,"0"),i=String(e.getUTCMinutes()).padStart(2,"0"),s=String(e.getUTCSeconds()).padStart(2,"0"),a=e.getUTCMilliseconds(),c=String(a*1e3*1e3).padStart(9,"0");return`${t}-${r}-${n}T${o}:${i}:${s}.${c}Z`}function tf(e){let t=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),r=String(e).trim().match(t);if(r==null)throw new Error("Invalid format");let n=parseInt(r[1],10),o=parseInt(r[2],10)-1,i=parseInt(r[3],10),s=parseInt(r[4],10),a=parseInt(r[5],10),c=parseInt(r[6],10),f=parseInt(r[7].slice(0,-6),10);return new Date(Date.UTC(n,o,i,s,a,c,f))}var ve=class e{key;value;timeReceived;constructor(t,r,n){if(!(t instanceof Uint8Array))throw new Error("key must be a Uint8Array");if(!(r instanceof Uint8Array))throw new Error("value must be a Uint8Array");this.key=t,this.value=r,this.timeReceived=n}serialize(){return Qr.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:Qu(this.timeReceived)}}static deserialize(t){let r=Qr.decode(t);return new e(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(t){let r=tf(t.timeReceived);if(t.key==null)throw new Error("key missing from deserialized object");if(t.value==null)throw new Error("value missing from deserialized object");return new e(t.key,t.value,r)}};var ce="/",ef=new TextEncoder().encode(ce),po=ef[0],mr=class e{_buf;constructor(t,r){if(typeof t=="string")this._buf=$(t);else if(t instanceof Uint8Array)this._buf=t;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==po)throw new Error("Invalid key")}toString(t="utf8"){return Y(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new e(t.join(ce))}static random(){return new e(Math.random().toString().substring(2))}static asKey(t){return t instanceof Uint8Array||typeof t=="string"?new e(t):typeof t.uint8Array=="function"?new e(t.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=ef),this._buf[0]!==po){let t=new Uint8Array(this._buf.byteLength+1);t.fill(po,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===po;)this._buf=this._buf.subarray(0,-1)}less(t){let r=this.list(),n=t.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let i=r[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return r.length<n.length}reverse(){return e.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(ce).slice(1)}type(){return Jh(this.baseNamespace())}name(){return Qh(this.baseNamespace())}instance(t){return new e(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(ce)||(t+=ce),t+=this.type(),new e(t)}parent(){let t=this.list();return t.length===1?new e(ce):new e(t.slice(0,-1).join(ce))}child(t){return this.toString()===ce?t:t.toString()===ce?this:new e(this.toString()+t.toString(),!1)}isAncestorOf(t){return t.toString()===this.toString()?!1:t.toString().startsWith(this.toString())}isDecendantOf(t){return t.toString()===this.toString()?!1:this.toString().startsWith(t.toString())}isTopLevel(){return this.list().length===1}concat(...t){return e.withNamespaces([...this.namespaces(),...t0(t.map(r=>r.namespaces()))])}};function Jh(e){let t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Qh(e){let t=e.split(":");return t[t.length-1]}function t0(e){return[].concat(...e)}var rf;(function(e){e[e.SEND_QUERY=0]="SEND_QUERY",e[e.PEER_RESPONSE=1]="PEER_RESPONSE",e[e.FINAL_PEER=2]="FINAL_PEER",e[e.QUERY_ERROR=3]="QUERY_ERROR",e[e.PROVIDER=4]="PROVIDER",e[e.VALUE=5]="VALUE",e[e.ADD_PEER=6]="ADD_PEER",e[e.DIAL_PEER=7]="DIAL_PEER",e[e.PATH_ENDED=8]="PATH_ENDED"})(rf||(rf={}));var tn;(function(e){let t;e.codec=()=>(t==null&&(t=Gt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.keyName!=null&&r.keyName!==""&&(n.uint32(10),n.string(r.keyName)),r.lifetime!=null&&r.lifetime!==0&&(n.uint32(16),n.uint32(r.lifetime)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={keyName:"",lifetime:0},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let a=r.uint32();switch(a>>>3){case 1:{i.keyName=r.string();break}case 2:{i.lifetime=r.uint32();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>Yt(r,e.codec()),e.decode=(r,n)=>Zt(r,e.codec(),n)})(tn||(tn={}));var r0=114,ls=0,ds=18;function hs(e,t){return e.code===t}var mo="/dht/record/",n0="/ipns/metadata/";function en(e){return new mr(mo+Y(e,"base32"),!1)}function yo(e){return new mr(n0+Y(e,"base32"),!1)}function nf(e,t){let r=Date.now(),n=t.getTime()+1728e5,o=new Date(e.validity).getTime();return n-r<864e5||o-r<864e5}function o0(e){return e?.asCID===e}function of(e){if(!o0(e))return!1;if(e.code!==r0)throw new tt(`CID codec ${e.code} was not libp2p-key`);if(e.multihash.code!==ls&&e.multihash.code!==ds)throw new tt(`Multihash algorithm codec ${e.multihash.code} was not Identity or SHA256 hash`);return!0}function sf(e,t){return{async put(r,n,o={}){try{let i=en(r);try{let c=await e.get(i),f=ve.deserialize(c);if(rt(f.value,n))return}catch(c){if(c.name!=="NotFoundError")throw c}let s=new ve(r,n,new Date);o.onProgress?.(new vt("ipns:routing:datastore:put"));let a=e.batch();a.put(i,s.serialize()),o.metadata!=null&&a.put(yo(r),tn.encode(o.metadata)),await a.commit(o)}catch(i){throw o.onProgress?.(new vt("ipns:routing:datastore:error",i)),i}},async get(r,n={}){try{let o=en(r);n.onProgress?.(new vt("ipns:routing:datastore:get"));let i=await e.get(o,n),s=ve.deserialize(i);return{record:s.value,created:s.timeReceived}}catch(o){throw n.onProgress?.(new vt("ipns:routing:datastore:error",o)),o}},async has(r,n={}){let o=en(r);return e.has(o,n)},async delete(r,n){let o=en(r),i=e.batch();i.delete(o),i.delete(yo(r)),await i.commit(n)},async*list(r={}){try{r.onProgress?.(new vt("ipns:routing:datastore:list"));for await(let{key:n,value:o}of e.query({prefix:mo},r))try{let i=ve.deserialize(o),a=n.toString().substring(mo.length),c=$(a,"base32"),f=yo(c),u;try{let l=await e.get(f,r);u=tn.decode(l)}catch(l){t.error("Error deserializing metadata for %s - %e",a,l)}yield{routingKey:c,metadata:u,record:i.value,created:i.timeReceived}}catch(i){t.error("Error deserializing record - %e",i)}}catch(n){throw r.onProgress?.(new vt("ipns:routing:datastore:error",n)),n}}}}var ps=class{routing;constructor(t){this.routing=t}async put(t,r,n={}){try{await this.routing.put(t,r,n)}catch(o){throw n.onProgress?.(new vt("ipns:routing:helia:error",o)),o}}async get(t,r={}){try{return await this.routing.get(t,r)}catch(n){throw r.onProgress?.(new vt("ipns:routing:helia:error",n)),n}}};function af(e){return new ps(e)}function cf(e){return{async put(t,r,n){await e.put(t,r,n)},async get(t,r){let{record:n}=await e.get(t,r);return n}}}var uf={[Rt.prefix]:Rt,[j.prefix]:j},go=class{routers;localStore;republishTask;log;keychain;started=!1;republishConcurrency;constructor(t,r={}){this.log=t.logger.forComponent("helia:ipns"),this.localStore=sf(t.datastore,t.logger.forComponent("helia:ipns:local-store")),this.keychain=t.libp2p.services.keychain,this.republishConcurrency=r.republishConcurrency||Ju,this.started=t.libp2p.status==="started",this.routers=[cf(this.localStore),af(t.routing),...r.routers??[]],t.events.addEventListener("start",this.start.bind(this)),t.events.addEventListener("stop",this.stop.bind(this)),this.republishTask=Gu(this.#r.bind(this),r.republishInterval??36e5,{runImmediately:!0}),this.started&&this.republishTask.start()}start(){this.started||(this.started=!0,this.republishTask.start())}stop(){this.started&&(this.started=!1,this.republishTask.stop())}#t(){if(!this.started)throw new on("Helia is stopped, cannot perform IPNS operations")}async publish(t,r,n={}){this.#t();try{let o=await this.#e(t),i=1n,s=Ve(o.publicKey.toMultihash());if(await this.localStore.has(s,n)){let{record:l}=await this.localStore.get(s,n);i=Ft(l).sequence+1n}bo(r)&&(r=r.toCID());let a=n.ttl!=null?BigInt(n.ttl)*1000000n:co,c=n.lifetime??1728e5,f=await us(o,r,i,c,{...n,ttlNs:a}),u=Qn(f);return n.offline===!0?await this.localStore.put(s,u,{...n,metadata:{keyName:t,lifetime:c}}):await Promise.all(this.routers.map(async l=>{await l.put(s,u,{...n,metadata:{keyName:t,lifetime:c}})})),{record:f,publicKey:o.publicKey}}catch(o){throw n.onProgress?.(new vt("ipns:publish:error",o)),o}}async resolve(t,r={}){this.#t();let n=xs(t)||bo(t)?t.toMultihash():of(t)?t.multihash:t,o=Ve(n),i=await this.#o(o,r);return{...await this.#n(i.value,r),record:i}}async#e(t){try{return await this.keychain.exportKey(t)}catch{let n=await Ic("Ed25519");return await this.keychain.importKey(t,n),n}}async#r(t={}){if(!this.started)return;this.log("starting ipns republish records loop");let r=new so({concurrency:this.republishConcurrency});try{let n=[];for await(let{routingKey:o,record:i,metadata:s,created:a}of this.localStore.list(t)){if(s==null){this.log(`no metadata found for record ${o.toString()}, skipping`);continue}let c;try{c=Ft(i)}catch(x){this.log.error("error unmarshaling record - %e",x);continue}if(!nf(c,a)){this.log.trace(`skipping record ${o.toString()}within republish threshold`);continue}let f=c.sequence+1n,u=c.ttl??co,l;try{l=await this.keychain.exportKey(s.keyName)}catch(x){this.log.error(`missing key ${s.keyName}, skipping republishing record`,x);continue}try{let x=await us(l,c.value,f,s.lifetime,{...t,ttlNs:u});n.push({routingKey:o,record:x})}catch(x){this.log.error(`error creating updated IPNS record for ${o.toString()}`,x);continue}}this.log(`found ${n.length} records to republish`);for(let{routingKey:o,record:i}of n)r.add(async()=>{try{let s=Qn(i);await Promise.all(this.routers.map(a=>a.put(o,s,t)))}catch(s){this.log.error("error republishing record - %e",s)}},t)}catch(n){this.log.error("error during republish - %e",n)}await r.onIdle(t)}async unpublish(t,r){let{publicKey:n}=await this.keychain.exportKey(t),o=n.toMultihash(),i=Ve(o);await this.localStore.delete(i,r)}async#n(t,r={}){let n=t.split("/");try{let o=n[1];if(o==="ipns"){let i=n[2],s=i.substring(0,1),a;if(s==="1"||s==="Q")a=j.decode(`z${i}`);else if(uf[s]!=null)a=uf[s].decode(i);else throw new fo(`Unsupported multibase prefix "${s}"`);let c;try{c=Ye(a)}catch{c=it.decode(a).multihash}if(!hs(c,ls)&&!hs(c,ds))throw new lo(`Unsupported multihash codec "${c.code}"`);let{cid:f}=await this.resolve(c,r),u=n.slice(3).join("/");return{cid:f,path:u}}else if(o==="ipfs"){let i=it.parse(n[2]),s=n.slice(3).join("/");return{cid:i,path:s}}}catch(o){this.log.error("error parsing ipfs path - %e",o)}throw this.log.error("invalid ipfs path %s",t),new ho("Invalid value")}async#o(t,r={}){let n=[];if(await this.localStore.has(t,r))if(this.log("record is present in the cache"),r.nocache!==!0)try{let{record:a,created:c}=await this.localStore.get(t,r);this.log("record retrieved from cache"),await Wr(t,a),this.log("record was valid");let f=Ft(a),u=Number((f.ttl??co)/1000000n);if(c.getTime()+u>Date.now())return this.log("record TTL was valid"),f;if(r.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),f;this.log("record TTL has been reached, searching routing for updates"),n.push(a)}catch(a){this.log("cached record was invalid - %e",a),await this.localStore.delete(t,r)}else this.log("ignoring local cache due to nocache=true option");if(r.offline===!0)throw new gr("Record was not present in the cache or has expired");this.log("did not have record locally");let i=0;if(await Promise.all(this.routers.map(async a=>{let c;try{c=await a.get(t,{...r,validate:!1})}catch(f){this.log.error("error finding IPNS record - %e",f);return}try{await Wr(t,c),n.push(c)}catch(f){i++,this.log.error("error finding IPNS record - %e",f)}})),n.length===0)throw i>0?new uo(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`):new gr("Could not find record for routing key");let s=n[ao(t,n)];return await this.localStore.put(t,s,r),Ft(s)}};function a0(e,t={}){return new go(e,t)}return yf(c0);})();
4
4
  /*! Bundled license information:
5
5
 
6
6
  @noble/hashes/utils.js: