@helia/ipns 9.2.1-73a28eda → 9.2.1-a464d83a

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,15 +1,15 @@
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 Fs=Object.create;var Vt=Object.defineProperty;var ks=Object.getOwnPropertyDescriptor;var Ds=Object.getOwnPropertyNames;var Us=Object.getPrototypeOf,_s=Object.prototype.hasOwnProperty;var Ls=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),W=(t,e)=>{for(var r in e)Vt(t,r,{get:e[r],enumerable:!0})},oi=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ds(e))!_s.call(t,i)&&i!==r&&Vt(t,i,{get:()=>e[i],enumerable:!(n=ks(e,i))||n.enumerable});return t};var $r=(t,e,r)=>(r=t!=null?Fs(Us(t)):{},oi(e||!t||!t.__esModule?Vt(r,"default",{value:t,enumerable:!0}):r,t)),Rs=t=>oi(Vt({},"__esModule",{value:!0}),t);var jt=Ls((cl,Xr)=>{var al=(function(){typeof Xr<"u"&&(Xr.exports=E);var t=86400,e=3200,r=146097*e/400,n=t*r,i=1e3*n,o=864e13,s=4294967296,a=1e6,u="000000000",f=Math.trunc||function(g){var w=g-g%1;return w==0&&(g<0||g===0&&1/g!=1/0)?-0:w},l=E.prototype,p=(E.fromDate=function(g){return new E(+g)},E.fromInt64BE=P(0,1,2,3,0,4),E.fromInt64LE=P(3,2,1,0,4,0),E.fromString=function(C){var w,A=new E,C=(C+="").replace(/^\s*[+\-]?\d+/,function(U){var U=+U,M=1970+(U-1970)%400;return A.year=U-M,M}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(I,U,M){return U<0&&(M*=-1),w=6e4*(60*+U+ +M),""}).replace(/\.\d+$/,function(I){return A.nano=+(I+u).substr(1,9),""}).split(/\D+/);if(1<C.length?C[1]--:C[1]=0,A.time=w=Date.UTC.apply(Date,C)-(w||0),isNaN(w))throw new TypeError("Invalid Date");return x(A)},E.fromTimeT=function(g){return F(g,0)},l.year=0,l.time=0,l.nano=0,l.addNano=function(g){return this.nano+=+g||0,this},l.getNano=function(){var g=x(this);return(g.time%1e3*a+ +g.nano+1e9)%1e9},l.getTimeT=function(){var w=x(this),g=Math.floor(w.time/1e3),w=w.year;return w&&(g+=w*r*t/e),g},l.getYear=function(){return this.toDate().getUTCFullYear()+this.year},l.toDate=function(){return T(x(this).time)},l.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},l.toString=function(g){var w=this,A=w.toDate(),C={H:function(){return K(A.getUTCHours())},L:function(){return R(A.getUTCMilliseconds(),3)},M:function(){return K(A.getUTCMinutes())},N:function(){return R(w.getNano(),9)},S:function(){return K(A.getUTCSeconds())},Y:function(){var I=w.getYear();return 999999<I?"+"+I:9999<I?"+"+R(I,6):0<=I?R(I,4):-999999<=I?"-"+R(-I,6):I},a:function(){return b[A.getUTCDay()]},b:function(){return m[A.getUTCMonth()]},d:function(){return K(A.getUTCDate())},e:function(){return(function(I){return(9<I?"":" ")+(0|I)})(A.getUTCDate())},m:function(){return K(A.getUTCMonth()+1)}};return(function I(U){return U.replace(/%./g,function(M){var _=M[1],N=S[_],_=C[_];return N?I(N):_?_():M})})(g||p)},l.writeInt64BE=k(0,1,2,3,0,4),l.writeInt64LE=k(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),m=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],b=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],S={"%":"%",F:"%Y-%m-%d",n:`
3
- `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return E;function E(g,w,A){var C=this;if(!(C instanceof E))return new E(g,w,A);C.time=+g||0,C.nano=+w||0,C.year=+A||0,x(C)}function x(g){var w,A,C,I=g.year,U=g.time,M=g.nano,N=((M<0||a<=M)&&(M-=(A=Math.floor(M/a))*a,U+=A,A=1),I%e);return(U<-o||o<U||N)&&((w=f(U/i))&&(I+=w*e,U-=w*i),(C=T(U)).setUTCFullYear(N+C.getUTCFullYear()),C=(U=+C)+(w=f((I-=N)/e))*i,w&&-o<=C&&C<=o&&(I-=w*e,U=C),A=1),A&&(g.year=I,g.time=U,g.nano=M),g}function T(g){var w=new Date(0);return w.setTime(g),w}function F(I,C){I=+I||0;var A=f((C=(C|0)*s)/n)+f(I/n),C=C%n+I%n,I=f(C/n);return I&&(A+=I,C-=I*n),new E(1e3*C,0,A*e)}function k(g,w,A,C,I,U){return function(N,_){var ge=x(this);N=N||new Array(8),B(N,_|=0);var Ve=Math.floor(ge.time/1e3),ge=ge.year*(r*t/e),me=f(ge/s)+f(Ve/s),ge=ge%s+Ve%s,Ve=Math.floor(ge/s);return Ve&&(me+=Ve,ge-=Ve*s),M(N,_+I,me),M(N,_+U,ge),N};function M(N,_,me){N[_+g]=me>>24&255,N[_+w]=me>>16&255,N[_+A]=me>>8&255,N[_+C]=255&me}}function P(g,w,A,C,I,U){return function(N,_){B(N,_|=0);var me=M(N,_+I);return F(M(N,_+U),me)};function M(N,_){return 16777216*N[_+g]+(N[_+w]<<16|N[_+A]<<8|N[_+C])}}function B(g,w){if(g=g&&g.length,g==null)throw new TypeError("Invalid Buffer");if(g<w+8)throw new RangeError("Out of range")}function K(g){return(9<g?"":"0")+(0|g)}function R(g,w){return(u+(0|g)).substr(-w)}})()});var Vu={};W(Vu,{ipns:()=>Pu,ipnsResolver:()=>$u});var Kr={};W(Kr,{base32:()=>Te,base32hex:()=>Gs,base32hexpad:()=>Ys,base32hexpadupper:()=>Xs,base32hexupper:()=>js,base32pad:()=>Ks,base32padupper:()=>Hs,base32upper:()=>qs,base32z:()=>Ws});var zu=new Uint8Array(0);function si(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function ye(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return De(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return De(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function ai(t){return new TextEncoder().encode(t)}function ci(t){return new TextDecoder().decode(t)}function Bs(t){return t?.buffer instanceof ArrayBuffer}function De(t){return Bs(t)?t:t.slice()}function Ms(t,e){if(t.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 i=0;i<t.length;i++){var o=t.charAt(i),s=o.charCodeAt(0);if(r[s]!==255)throw new TypeError(o+" is ambiguous");r[s]=i}var a=t.length,u=t.charAt(0),f=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function p(S){if(S instanceof Uint8Array||(ArrayBuffer.isView(S)?S=new Uint8Array(S.buffer,S.byteOffset,S.byteLength):Array.isArray(S)&&(S=Uint8Array.from(S))),!(S instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(S.length===0)return"";for(var E=0,x=0,T=0,F=S.length;T!==F&&S[T]===0;)T++,E++;for(var k=(F-T)*l+1>>>0,P=new Uint8Array(k);T!==F;){for(var B=S[T],K=0,R=k-1;(B!==0||K<x)&&R!==-1;R--,K++)B+=256*P[R]>>>0,P[R]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");x=K,T++}for(var g=k-x;g!==k&&P[g]===0;)g++;for(var w=u.repeat(E);g<k;++g)w+=t.charAt(P[g]);return w}function m(S){if(typeof S!="string")throw new TypeError("Expected String");if(S.length===0)return new Uint8Array;var E=0;if(S[E]!==" "){for(var x=0,T=0;S[E]===u;)x++,E++;for(var F=(S.length-E)*f+1>>>0,k=new Uint8Array(F);S[E];){var P=r[S.charCodeAt(E)];if(P===255)return;for(var B=0,K=F-1;(P!==0||B<T)&&K!==-1;K--,B++)P+=a*k[K]>>>0,k[K]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");T=B,E++}if(S[E]!==" "){for(var R=F-T;R!==F&&k[R]===0;)R++;for(var g=new Uint8Array(x+(F-R)),w=x;R!==F;)g[w++]=k[R++];return g}}}function b(S){var E=m(S);if(E)return E;throw new Error(`Non-${e} character`)}return{encode:p,decodeUnsafe:m,decode:b}}var Ps=Ms,$s=Ps,li=$s;var Vr=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Or=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let i=r.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return fi(this,e)}},zr=class{decoders;constructor(e){this.decoders=e}or(e){return fi(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function fi(t,e){return new zr({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var qr=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new Vr(e,r,n),this.decoder=new Or(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Oe({name:t,prefix:e,encode:r,decode:n}){return new qr(t,e,r,n)}function Se({name:t,prefix:e,alphabet:r}){let{encode:n,decode:i}=li(r,t);return Oe({prefix:e,name:t,encode:n,decode:o=>ye(i(o))})}function Vs(t,e,r,n){let i=t.length;for(;t[i-1]==="=";)--i;let o=new Uint8Array(i*r/8|0),s=0,a=0,u=0;for(let f=0;f<i;++f){let l=e[t[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|l,s+=r,s>=8&&(s-=8,o[u++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return o}function Os(t,e,r){let n=e[e.length-1]==="=",i=(1<<r)-1,o="",s=0,a=0;for(let u=0;u<t.length;++u)for(a=a<<8|t[u],s+=8;s>r;)s-=r,o+=e[i&a>>s];if(s!==0&&(o+=e[i&a<<r-s]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function zs(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function L({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let i=zs(n);return Oe({prefix:e,name:t,encode(o){return Os(o,n,r)},decode(o){return Vs(o,i,r,t)}})}var Te=L({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),qs=L({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ks=L({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Hs=L({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Gs=L({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),js=L({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ys=L({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Xs=L({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ws=L({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Hr={};W(Hr,{base36:()=>ne,base36upper:()=>Js});var ne=Se({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Js=Se({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Gr={};W(Gr,{base58btc:()=>j,base58flickr:()=>Qs});var j=Se({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Qs=Se({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Zs=pi,hi=128,ea=127,ta=~ea,ra=Math.pow(2,31);function pi(t,e,r){e=e||[],r=r||0;for(var n=r;t>=ra;)e[r++]=t&255|hi,t/=128;for(;t&ta;)e[r++]=t&255|hi,t>>>=7;return e[r]=t|0,pi.bytes=r-n+1,e}var na=jr,ia=128,di=127;function jr(t,n){var r=0,n=n||0,i=0,o=n,s,a=t.length;do{if(o>=a)throw jr.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&di)<<i:(s&di)*Math.pow(2,i),i+=7}while(s>=ia);return jr.bytes=o-n,r}var oa=Math.pow(2,7),sa=Math.pow(2,14),aa=Math.pow(2,21),ca=Math.pow(2,28),ua=Math.pow(2,35),la=Math.pow(2,42),fa=Math.pow(2,49),ha=Math.pow(2,56),da=Math.pow(2,63),pa=function(t){return t<oa?1:t<sa?2:t<aa?3:t<ca?4:t<ua?5:t<la?6:t<fa?7:t<ha?8:t<da?9:10},ma={encode:Zs,decode:na,encodingLength:pa},ga=ma,at=ga;function ct(t,e=0){return[at.decode(t,e),at.decode.bytes]}function ze(t,e,r=0){return at.encode(t,e,r),e}function qe(t){return at.encodingLength(t)}function He(t,e){let r=e.byteLength,n=qe(t),i=n+qe(r),o=new Uint8Array(i+r);return ze(t,o,0),ze(r,o,n),o.set(e,i),new Ke(t,r,e,o)}function ut(t){let e=ye(t),[r,n]=ct(e),[i,o]=ct(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new Ke(r,i,s,e)}function mi(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&si(t.bytes,r.bytes)}}var Ke=class{code;size;digest;bytes;constructor(e,r,n,i){this.code=e,this.size=r,this.digest=De(n),this.bytes=De(i)}};function gi(t,e){let{bytes:r,version:n}=t;return n===0?xa(r,Yr(t),e??j.encoder):wa(r,Yr(t),e??Te.encoder)}var yi=new WeakMap;function Yr(t){let e=yi.get(t);if(e==null){let r=new Map;return yi.set(t,r),r}return e}var fe=class t{code;version;multihash;bytes;"/";constructor(e,r,n,i){this.code=r,this.version=e,this.multihash=n,this.bytes=De(i),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==lt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==ba)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.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:e,digest:r}=this.multihash,n=He(e,r);return t.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(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&mi(e.multihash,n.multihash)}toString(e){return gi(this,e)}toJSON(){return{"/":gi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:i,multihash:o,bytes:s}=r;return new t(n,i,o,s??xi(n,i,o.bytes))}else if(r[Ea]===!0){let{version:n,multihash:i,code:o}=r,s=ut(i);return t.create(n,o,s)}else return null}static create(e,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(e){case 0:{if(r!==lt)throw new Error(`Version 0 CID must use dag-pb (code: ${lt}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let i=xi(e,r,n.bytes);return new t(e,r,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,lt,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,i=ye(e.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=i.subarray(r.multihashSize-r.digestSize),s=new Ke(r.multihashCode,r.digestSize,o,i);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[p,m]=ct(e.subarray(r));return r+=m,p},i=n(),o=lt;if(i===18?(i=0,r=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=r,a=n(),u=n(),f=r+u,l=f-s;return{version:i,codec:o,multihashCode:a,digestSize:u,multihashSize:l,size:f}}static parse(e,r){let[n,i]=ya(e,r),o=t.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Yr(o).set(n,e),o}};function ya(t,e){switch(t[0]){case"Q":{let r=e??j;return[j.prefix,r.decode(`${j.prefix}${t}`)]}case j.prefix:{let r=e??j;return[j.prefix,r.decode(t)]}case Te.prefix:{let r=e??Te;return[Te.prefix,r.decode(t)]}case ne.prefix:{let r=e??ne;return[ne.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function xa(t,e,r){let{prefix:n}=r;if(n!==j.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=e.get(n);if(i==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return i}function wa(t,e,r){let{prefix:n}=r,i=e.get(n);if(i==null){let o=r.encode(t);return e.set(n,o),o}else return i}var lt=112,ba=18;function xi(t,e,r){let n=qe(t),i=n+qe(e),o=new Uint8Array(i+r.byteLength);return ze(t,o,0),ze(e,o,n),o.set(r,i),o}var Ea=Symbol.for("@ipld/js-cid/CID");var je=BigInt(6e4)*5000000n,wi=5;var zt=class extends Error{static name="RecordsFailedValidationError";name="RecordsFailedValidationError"};var Ye=class extends Error{static name="InvalidValueError";name="InvalidValueError"};var ft=class extends Error{static name="RecordNotFoundError";name="RecordNotFoundError"},qt=class extends Error{static name="SignatureCreationError";name="SignatureCreationError"},se=class extends Error{static name="SignatureVerificationError";name="SignatureVerificationError"},Kt=class extends Error{static name="RecordExpiredError";name="RecordExpiredError"},Ue=class extends Error{static name="UnsupportedValidityError";name="UnsupportedValidityError"},Ht=class extends Error{static name="RecordTooLargeError";name="RecordTooLargeError"},Gt=class extends Error{static name="InvalidRecordDataError";name="InvalidRecordDataError"},Xe=class extends Error{static name="InvalidEmbeddedPublicKeyError";name="InvalidEmbeddedPublicKeyError"};var Tn=$r(jt(),1);function Wr(t=0){return new Uint8Array(t)}function H(t=0){return new Uint8Array(t)}var Sa=Math.pow(2,7),Ta=Math.pow(2,14),Ia=Math.pow(2,21),bi=Math.pow(2,28),Ei=Math.pow(2,35),Si=Math.pow(2,42),Ti=Math.pow(2,49),G=128,Ie=127;function xe(t){if(t<Sa)return 1;if(t<Ta)return 2;if(t<Ia)return 3;if(t<bi)return 4;if(t<Ei)return 5;if(t<Si)return 6;if(t<Ti)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Yt(t,e,r=0){switch(xe(t)){case 8:e[r++]=t&255|G,t/=128;case 7:e[r++]=t&255|G,t/=128;case 6:e[r++]=t&255|G,t/=128;case 5:e[r++]=t&255|G,t/=128;case 4:e[r++]=t&255|G,t>>>=7;case 3:e[r++]=t&255|G,t>>>=7;case 2:e[r++]=t&255|G,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Xt(t,e){let r=t[e],n=0;if(n+=r&Ie,r<G||(r=t[e+1],n+=(r&Ie)<<7,r<G)||(r=t[e+2],n+=(r&Ie)<<14,r<G)||(r=t[e+3],n+=(r&Ie)<<21,r<G)||(r=t[e+4],n+=(r&Ie)*bi,r<G)||(r=t[e+5],n+=(r&Ie)*Ei,r<G)||(r=t[e+6],n+=(r&Ie)*Si,r<G)||(r=t[e+7],n+=(r&Ie)*Ti,r<G))return n;throw new RangeError("Could not decode varint")}function Ca(t){return t.buffer instanceof ArrayBuffer}function Ii(t){return Ca(t)?t:t.slice()}var Jr=new Float32Array([-0]),Ce=new Uint8Array(Jr.buffer);function Ci(t,e,r){Jr[0]=t,e[r]=Ce[0],e[r+1]=Ce[1],e[r+2]=Ce[2],e[r+3]=Ce[3]}function Ai(t,e){return Ce[0]=t[e],Ce[1]=t[e+1],Ce[2]=t[e+2],Ce[3]=t[e+3],Jr[0]}var Qr=new Float64Array([-0]),z=new Uint8Array(Qr.buffer);function vi(t,e,r){Qr[0]=t,e[r]=z[0],e[r+1]=z[1],e[r+2]=z[2],e[r+3]=z[3],e[r+4]=z[4],e[r+5]=z[5],e[r+6]=z[6],e[r+7]=z[7]}function Ni(t,e){return z[0]=t[e],z[1]=t[e+1],z[2]=t[e+2],z[3]=t[e+3],z[4]=t[e+4],z[5]=t[e+5],z[6]=t[e+6],z[7]=t[e+7],Qr[0]}var Aa=BigInt(Number.MAX_SAFE_INTEGER),va=BigInt(Number.MIN_SAFE_INTEGER),J=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&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(e=!1){if(e)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(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return _e;if(e<Aa&&e>va)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,i=e-(n<<32n);return r&&(n=~n|0n,i=~i|0n,++i>Fi&&(i=0n,++n>Fi&&(n=0n))),new t(Number(i),Number(n))}static fromNumber(e){if(e===0)return _e;let r=e<0;r&&(e=-e);let n=e>>>0,i=(e-n)/4294967296>>>0;return r&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new t(n,i)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):_e}},_e=new J(0,0);_e.toBigInt=function(){return 0n};_e.zzEncode=_e.zzDecode=function(){return this};_e.length=function(){return 1};var Fi=4294967296n;function ki(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Di(t,e,r){if(r-e<1)return"";let i,o=[],s=0,a;for(;e<r;)a=t[e++],a<128?o[s++]=a:a>191&&a<224?o[s++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function Zr(t,e,r){let n=r,i,o;for(let s=0;s<t.length;++s)i=t.charCodeAt(s),i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&((o=t.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128);return r-n}function ae(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Wt(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var en=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Ii(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,ae(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw ae(this,4);return Wt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ae(this,4);return Wt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ae(this,4);let e=Ai(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw ae(this,4);let e=Ni(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw ae(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Di(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw ae(this,e);this.pos+=e}else do if(this.pos>=this.len)throw ae(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new J(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw ae(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw ae(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw ae(this,8);let e=Wt(this.buf,this.pos+=4),r=Wt(this.buf,this.pos+=4);return new J(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Xt(this.buf,this.pos);return this.pos+=xe(e),e}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 ht(t){return new en(t instanceof Uint8Array?t:t.subarray())}function dt(t,e,r){let n=ht(t);return e.decode(n,void 0,r)}var tn={};W(tn,{base10:()=>Na});var Na=Se({prefix:"9",name:"base10",alphabet:"0123456789"});var rn={};W(rn,{base16:()=>Fa,base16upper:()=>ka});var Fa=L({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ka=L({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var nn={};W(nn,{base2:()=>Da});var Da=L({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var on={};W(on,{base256emoji:()=>Ba});var _i=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}"),Ua=_i.reduce((t,e,r)=>(t[r]=e,t),[]),_a=_i.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function La(t){return t.reduce((e,r)=>(e+=Ua[r],e),"")}function Ra(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let i=_a[n];if(i==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(i)}return new Uint8Array(e)}var Ba=Oe({prefix:"\u{1F680}",name:"base256emoji",encode:La,decode:Ra});var an={};W(an,{base64:()=>sn,base64pad:()=>Ma,base64url:()=>Pa,base64urlpad:()=>$a});var sn=L({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ma=L({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Pa=L({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),$a=L({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var cn={};W(cn,{base8:()=>Va});var Va=L({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var un={};W(un,{identity:()=>Oa});var Oa=Oe({prefix:"\0",name:"identity",encode:t=>ci(t),decode:t=>ai(t)});var kl=new TextEncoder,Dl=new TextDecoder;var ln={};W(ln,{identity:()=>Ga});var Li=0,Ka="identity",Ri=ye;function Ha(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return He(Li,Ri(t))}var Ga={code:Li,name:Ka,encode:Ri,digest:Ha};var dn={};W(dn,{sha256:()=>Ya,sha512:()=>Xa});var ja=20;function hn({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:i}){return new fn(t,e,r,n,i)}var fn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,i,o){this.name=e,this.code=r,this.encode=n,this.minDigestLength=i??ja,this.maxDigestLength=o}digest(e,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(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Bi(n,this.code,r?.truncate):n.then(i=>Bi(i,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Bi(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return He(e,t)}function Pi(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Ya=hn({name:"sha2-256",code:18,encode:Pi("SHA-256")}),Xa=hn({name:"sha2-512",code:19,encode:Pi("SHA-512")});var pn={...un,...nn,...cn,...tn,...rn,...Kr,...Hr,...Gr,...an,...on},Kl={...dn,...ln};function Vi(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var $i=Vi("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),mn=Vi("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=H(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Wa={utf8:$i,"utf-8":$i,hex:pn.base16,latin1:mn,ascii:mn,binary:mn,...pn},Jt=Wa;function $(t,e="utf8"){let r=Jt[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function gn(t){let e=t??8192,r=e>>>1,n,i=e;return function(s){if(s<1||s>r)return H(s);i+s>e&&(n=H(e),i=0);let a=n.subarray(i,i+=s);return(i&7)!==0&&(i=(i|7)+1),a}}var Le=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function yn(){}var wn=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Ja=gn();function Qa(t){return globalThis.Buffer!=null?H(t):Ja(t)}var mt=class{len;head;tail;states;constructor(){this.len=0,this.head=new Le(yn,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Le(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new bn((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Qt,10,J.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=J.fromBigInt(e);return this._push(Qt,r.length(),r)}uint64Number(e){return this._push(Yt,xe(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=J.fromBigInt(e).zzEncode();return this._push(Qt,r.length(),r)}sint64Number(e){let r=J.fromNumber(e).zzEncode();return this._push(Qt,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(xn,1,e?1:0)}fixed32(e){return this._push(pt,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=J.fromBigInt(e);return this._push(pt,4,r.lo)._push(pt,4,r.hi)}fixed64Number(e){let r=J.fromNumber(e);return this._push(pt,4,r.lo)._push(pt,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Ci,4,e)}double(e){return this._push(vi,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(xn,1,0):this.uint32(r)._push(ec,r,e)}string(e){let r=ki(e);return r!==0?this.uint32(r)._push(Zr,r,e):this._push(xn,1,0)}fork(){return this.states=new wn(this),this.head=this.tail=new Le(yn,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 Le(yn,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=Qa(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function xn(t,e,r){e[r]=t&255}function Za(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var bn=class extends Le{next;constructor(e,r){super(Za,e,r),this.next=void 0}};function Qt(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function pt(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function ec(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(mt.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(tc,e,t),this},mt.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(rc,e,t),this});function tc(t,e,r){e.set(t,r)}function rc(t,e,r){t.length<40?Zr(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set($(t),r)}function En(){return new mt}function gt(t,e){let r=En();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*yt(t,e,r){let n=ht(t);yield*e.stream(n,void 0,"$",r)}var Zt={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function er(t,e,r,n,i){return{name:t,type:e,encode:r,decode:n,stream:i}}function Sn(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(s,a){let u=e(s);a.int32(u)},n=function(s){let a=s.int32();return e(a)},i=function*(s){let a=s.int32();yield e(a)};return er("enum",Zt.VARINT,r,n,i)}function xt(t,e,r){return er("message",Zt.LENGTH_DELIMITED,t,e,r)}var O;(function(t){let e;(function(a){a.EOL="EOL"})(e=t.ValidityType||(t.ValidityType={}));let r;(function(a){a[a.EOL=0]="EOL"})(r||(r={})),(function(a){a.codec=()=>Sn(r)})(e=t.ValidityType||(t.ValidityType={}));let n;t.codec=()=>(n==null&&(n=xt((a,u,f={})=>{f.lengthDelimited!==!1&&u.fork(),a.value!=null&&(u.uint32(10),u.bytes(a.value)),a.signatureV1!=null&&(u.uint32(18),u.bytes(a.signatureV1)),a.validityType!=null&&(u.uint32(24),t.ValidityType.codec().encode(a.validityType,u)),a.validity!=null&&(u.uint32(34),u.bytes(a.validity)),a.sequence!=null&&(u.uint32(40),u.uint64(a.sequence)),a.ttl!=null&&(u.uint32(48),u.uint64(a.ttl)),a.publicKey!=null&&(u.uint32(58),u.bytes(a.publicKey)),a.signatureV2!=null&&(u.uint32(66),u.bytes(a.signatureV2)),a.data!=null&&(u.uint32(74),u.bytes(a.data)),f.lengthDelimited!==!1&&u.ldelim()},(a,u,f={})=>{let l={},p=u==null?a.len:a.pos+u;for(;a.pos<p;){let m=a.uint32();switch(m>>>3){case 1:{l.value=a.bytes();break}case 2:{l.signatureV1=a.bytes();break}case 3:{l.validityType=t.ValidityType.codec().decode(a);break}case 4:{l.validity=a.bytes();break}case 5:{l.sequence=a.uint64();break}case 6:{l.ttl=a.uint64();break}case 7:{l.publicKey=a.bytes();break}case 8:{l.signatureV2=a.bytes();break}case 9:{l.data=a.bytes();break}default:{a.skipType(m&7);break}}}return l},function*(a,u,f,l={}){let p=u==null?a.len:a.pos+u;for(;a.pos<p;){let m=a.uint32();switch(m>>>3){case 1:{yield{field:`${f}.value`,value:a.bytes()};break}case 2:{yield{field:`${f}.signatureV1`,value:a.bytes()};break}case 3:{yield{field:`${f}.validityType`,value:t.ValidityType.codec().decode(a)};break}case 4:{yield{field:`${f}.validity`,value:a.bytes()};break}case 5:{yield{field:`${f}.sequence`,value:a.uint64()};break}case 6:{yield{field:`${f}.ttl`,value:a.uint64()};break}case 7:{yield{field:`${f}.publicKey`,value:a.bytes()};break}case 8:{yield{field:`${f}.signatureV2`,value:a.bytes()};break}case 9:{yield{field:`${f}.data`,value:a.bytes()};break}default:{a.skipType(m&7);break}}}})),n);function i(a){return gt(a,t.codec())}t.encode=i;function o(a,u){return dt(a,t.codec(),u)}t.decode=o;function s(a,u){return yt(a,t.codec(),u)}t.stream=s})(O||(O={}));function tr(t,e){let r=e.map((n,i)=>({record:n,index:i}));return r.sort((n,i)=>{let o=n.record.sequence,s=i.record.sequence;if(o>s)return-1;if(o<s)return 1;if(n.record.validityType===O.ValidityType.EOL&&i.record.validityType===O.ValidityType.EOL){let a=Tn.default.fromString(n.record.validity).toDate(),u=Tn.default.fromString(i.record.validity).toDate();if(a.getTime()>u.getTime())return-1;if(a.getTime()<u.getTime())return 1}return 0}),r[0].index}function nc(t){return t?.buffer instanceof ArrayBuffer}function Oi(t){if(nc(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function rr(t,e){e==null&&(e=t.reduce((i,o)=>i+o.length,0));let r=H(e),n=0;for(let i of t)r.set(i,n),n+=i.length;return Oi(r)}function wt(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function nr(t){return t==null?!1:typeof t.type=="string"&&typeof t.code=="number"&&typeof t.verify=="function"}var we=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};function ic(t){return typeof t?.handleEvent=="function"}function oc(t){return(t!==!0&&t!==!1&&t?.once)??!1}var ir=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let i=oc(n);super.addEventListener(e,s=>{if(i){let a=this.#e.get(s.type);a!=null&&(a=a.filter(({callback:u})=>u!==r),this.#e.set(s.type,a))}ic(r)?r.handleEvent(s):r(s)},n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:r,once:i})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let i=this.#e.get(e);i!=null&&(i=i.filter(({callback:o})=>o!==r),this.#e.set(e,i))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var sc=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged"];function In(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=ac(t);return r||"Object"}function ac(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(sc.includes(e))return e}var c=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};c.uint=new c(0,"uint",!0);c.negint=new c(1,"negint",!0);c.bytes=new c(2,"bytes",!0);c.string=new c(3,"string",!0);c.array=new c(4,"array",!1);c.map=new c(5,"map",!1);c.tag=new c(6,"tag",!1);c.float=new c(7,"float",!0);c.false=new c(7,"false",!0);c.true=new c(7,"true",!0);c.null=new c(7,"null",!0);c.undefined=new c(7,"undefined",!0);c.break=new c(7,"break",!0);var d=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var bt=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",cc=new TextEncoder;function or(t){return bt&&globalThis.Buffer.isBuffer(t)}function Et(t){return t instanceof Uint8Array?or(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var uc=24,lc=200,sr=bt?t=>t.length>=uc?globalThis.Buffer.from(t):zi(t):t=>t.length>=lc?cc.encode(t):zi(t),he=t=>Uint8Array.from(t),qi=bt?(t,e,r)=>or(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),Ki=bt?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Et(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let i of t)n+i.length>r.length&&(i=i.subarray(0,r.length-n)),r.set(i,n),n+=i.length;return r},Hi=bt?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function ar(t,e){if(or(t)&&or(e))return t.compare(e);for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function zi(t){let e=[],r=0;for(let n=0;n<t.length;n++){let i=t.charCodeAt(n);i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(i=65536+((i&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(i>=55296&&i<=57343&&(i=65533),e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128)}return e}var fc=256,St=class{constructor(e=fc){this.chunkSize=e,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(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let i=r.length-(this.maxCursor-this.cursor)-1;r.set(e,i)}else{if(r){let i=r.length-(this.maxCursor-this.cursor)-1;i<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,i),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=Hi(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=qi(n,0,this.cursor)}else r=Ki(this.chunks,this.cursor);return e&&this.reset(),r}},cr=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var y="CBOR decode error:",ur="CBOR encode error:",Tt=[];Tt[23]=1;Tt[24]=2;Tt[25]=3;Tt[26]=5;Tt[27]=9;function be(t,e,r){if(t.length-e<r)throw new Error(`${y} not enough data for type`)}var V=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Q(t,e,r){be(t,e,1);let n=t[e];if(r.strict===!0&&n<V[0])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function Z(t,e,r){be(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<V[1])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function ee(t,e,r){be(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<V[2])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function te(t,e,r){be(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],i=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],o=(BigInt(n)<<BigInt(32))+BigInt(i);if(r.strict===!0&&o<V[3])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);if(o<=Number.MAX_SAFE_INTEGER)return Number(o);if(r.allowBigInt===!0)return o;throw new Error(`${y} integers outside of the safe integer range are not supported`)}function Gi(t,e,r,n){return new d(c.uint,Q(t,e+1,n),2)}function ji(t,e,r,n){return new d(c.uint,Z(t,e+1,n),3)}function Yi(t,e,r,n){return new d(c.uint,ee(t,e+1,n),5)}function Xi(t,e,r,n){return new d(c.uint,te(t,e+1,n),9)}function ie(t,e){return D(t,0,e.value)}function D(t,e,r){if(r<V[0]){let n=Number(r);t.push([e|n])}else if(r<V[1]){let n=Number(r);t.push([e|24,n])}else if(r<V[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<V[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<V[4]){let i=[e|27,0,0,0,0,0,0,0],o=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));i[8]=o&255,o=o>>8,i[7]=o&255,o=o>>8,i[6]=o&255,o=o>>8,i[5]=o&255,i[4]=s&255,s=s>>8,i[3]=s&255,s=s>>8,i[2]=s&255,s=s>>8,i[1]=s&255,t.push(i)}else throw new Error(`${y} encountered BigInt larger than allowable range`)}}ie.encodedSize=function(e){return D.encodedSize(e.value)};D.encodedSize=function(e){return e<V[0]?1:e<V[1]?2:e<V[2]?3:e<V[3]?5:9};ie.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Wi(t,e,r,n){return new d(c.negint,-1-Q(t,e+1,n),2)}function Ji(t,e,r,n){return new d(c.negint,-1-Z(t,e+1,n),3)}function Qi(t,e,r,n){return new d(c.negint,-1-ee(t,e+1,n),5)}var Cn=BigInt(-1),Zi=BigInt(1);function eo(t,e,r,n){let i=te(t,e+1,n);if(typeof i!="bigint"){let o=-1-i;if(o>=Number.MIN_SAFE_INTEGER)return new d(c.negint,o,9)}if(n.allowBigInt!==!0)throw new Error(`${y} integers outside of the safe integer range are not supported`);return new d(c.negint,Cn-BigInt(i),9)}function lr(t,e){let r=e.value,n=typeof r=="bigint"?r*Cn-Zi:r*-1-1;D(t,e.type.majorEncoded,n)}lr.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Cn-Zi:r*-1-1;return n<V[0]?1:n<V[1]?2:n<V[2]?3:n<V[3]?5:9};lr.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function It(t,e,r,n){be(t,e,r+n);let i=t.slice(e+r,e+r+n);return new d(c.bytes,i,r+n)}function to(t,e,r,n){return It(t,e,1,r)}function ro(t,e,r,n){return It(t,e,2,Q(t,e+1,n))}function no(t,e,r,n){return It(t,e,3,Z(t,e+1,n))}function io(t,e,r,n){return It(t,e,5,ee(t,e+1,n))}function oo(t,e,r,n){let i=te(t,e+1,n);if(typeof i=="bigint")throw new Error(`${y} 64-bit integer bytes lengths not supported`);return It(t,e,9,i)}function fr(t){return t.encodedBytes===void 0&&(t.encodedBytes=c.equals(t.type,c.string)?sr(t.value):t.value),t.encodedBytes}function We(t,e){let r=fr(e);D(t,e.type.majorEncoded,r.length),t.push(r)}We.encodedSize=function(e){let r=fr(e);return D.encodedSize(r.length)+r.length};We.compareTokens=function(e,r){return dc(fr(e),fr(r))};function dc(t,e){return t.length<e.length?-1:t.length>e.length?1:ar(t,e)}var so=new TextDecoder,mc=32;function gc(t,e,r){if(r-e<mc){let i="";for(let o=e;o<r;o++){let s=t[o];if(s&128)return so.decode(t.subarray(e,r));i+=String.fromCharCode(s)}return i}return so.decode(t.subarray(e,r))}function Ct(t,e,r,n,i){let o=r+n;be(t,e,o);let s=new d(c.string,gc(t,e+r,e+o),o);return i.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+o)),s}function ao(t,e,r,n){return Ct(t,e,1,r,n)}function co(t,e,r,n){return Ct(t,e,2,Q(t,e+1,n),n)}function uo(t,e,r,n){return Ct(t,e,3,Z(t,e+1,n),n)}function lo(t,e,r,n){return Ct(t,e,5,ee(t,e+1,n),n)}function fo(t,e,r,n){let i=te(t,e+1,n);if(typeof i=="bigint")throw new Error(`${y} 64-bit integer string lengths not supported`);return Ct(t,e,9,i,n)}var ho=We;function Je(t,e,r,n){return new d(c.array,n,r)}function po(t,e,r,n){return Je(t,e,1,r)}function mo(t,e,r,n){return Je(t,e,2,Q(t,e+1,n))}function go(t,e,r,n){return Je(t,e,3,Z(t,e+1,n))}function yo(t,e,r,n){return Je(t,e,5,ee(t,e+1,n))}function xo(t,e,r,n){let i=te(t,e+1,n);if(typeof i=="bigint")throw new Error(`${y} 64-bit integer array lengths not supported`);return Je(t,e,9,i)}function wo(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return Je(t,e,1,1/0)}function hr(t,e){D(t,c.array.majorEncoded,e.value)}hr.compareTokens=ie.compareTokens;hr.encodedSize=function(e){return D.encodedSize(e.value)};function Qe(t,e,r,n){return new d(c.map,n,r)}function bo(t,e,r,n){return Qe(t,e,1,r)}function Eo(t,e,r,n){return Qe(t,e,2,Q(t,e+1,n))}function So(t,e,r,n){return Qe(t,e,3,Z(t,e+1,n))}function To(t,e,r,n){return Qe(t,e,5,ee(t,e+1,n))}function Io(t,e,r,n){let i=te(t,e+1,n);if(typeof i=="bigint")throw new Error(`${y} 64-bit integer map lengths not supported`);return Qe(t,e,9,i)}function Co(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return Qe(t,e,1,1/0)}function dr(t,e){D(t,c.map.majorEncoded,e.value)}dr.compareTokens=ie.compareTokens;dr.encodedSize=function(e){return D.encodedSize(e.value)};function Ao(t,e,r,n){return new d(c.tag,r,1)}function vo(t,e,r,n){return new d(c.tag,Q(t,e+1,n),2)}function No(t,e,r,n){return new d(c.tag,Z(t,e+1,n),3)}function Fo(t,e,r,n){return new d(c.tag,ee(t,e+1,n),5)}function ko(t,e,r,n){return new d(c.tag,te(t,e+1,n),9)}function pr(t,e){D(t,c.tag.majorEncoded,e.value)}pr.compareTokens=ie.compareTokens;pr.encodedSize=function(e){return D.encodedSize(e.value)};var An=20,vn=21,Nn=22,Fn=23;function Do(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${y} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new d(c.null,null,1):new d(c.undefined,void 0,1)}function Uo(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return new d(c.break,void 0,1)}function kn(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${y} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${y} Infinity values are not supported`)}return new d(c.float,t,e)}function _o(t,e,r,n){return kn(Dn(t,e+1),3,n)}function Lo(t,e,r,n){return kn(Un(t,e+1),5,n)}function Ro(t,e,r,n){return kn($o(t,e+1),9,n)}function At(t,e,r){let n=e.value;if(n===!1)t.push([c.float.majorEncoded|An]);else if(n===!0)t.push([c.float.majorEncoded|vn]);else if(n===null)t.push([c.float.majorEncoded|Nn]);else if(n===void 0)t.push([c.float.majorEncoded|Fn]);else{let i,o=!1;(!r||r.float64!==!0)&&(Mo(n),i=Dn(ce,1),n===i||Number.isNaN(n)?(ce[0]=249,t.push(ce.slice(0,3)),o=!0):(Po(n),i=Un(ce,1),n===i&&(ce[0]=250,t.push(ce.slice(0,5)),o=!0))),o||(Ec(n),i=$o(ce,1),ce[0]=251,t.push(ce.slice(0,9)))}}At.encodedSize=function(e,r){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){Mo(n);let i=Dn(ce,1);if(n===i||Number.isNaN(n))return 3;if(Po(n),i=Un(ce,1),n===i)return 5}return 9};var Bo=new ArrayBuffer(9),oe=new DataView(Bo,1),ce=new Uint8Array(Bo,0);function Mo(t){if(t===1/0)oe.setUint16(0,31744,!1);else if(t===-1/0)oe.setUint16(0,64512,!1);else if(Number.isNaN(t))oe.setUint16(0,32256,!1);else{oe.setFloat32(0,t);let e=oe.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)oe.setUint16(0,31744,!1);else if(r===0)oe.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let i=r-127;i<-24?oe.setUint16(0,0):i<-14?oe.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):oe.setUint16(0,(e&2147483648)>>16|i+15<<10|n>>13,!1)}}}function Dn(t,e){if(t.length-e<2)throw new Error(`${y} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,i=r&1023,o;return n===0?o=i*2**-24:n!==31?o=(i+1024)*2**(n-25):o=i===0?1/0:NaN,r&32768?-o:o}function Po(t){oe.setFloat32(0,t,!1)}function Un(t,e){if(t.length-e<4)throw new Error(`${y} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Ec(t){oe.setFloat64(0,t,!1)}function $o(t,e){if(t.length-e<8)throw new Error(`${y} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}At.compareTokens=ie.compareTokens;function v(t,e,r){throw new Error(`${y} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function mr(t){return()=>{throw new Error(`${y} ${t}`)}}var h=[];for(let t=0;t<=23;t++)h[t]=v;h[24]=Gi;h[25]=ji;h[26]=Yi;h[27]=Xi;h[28]=v;h[29]=v;h[30]=v;h[31]=v;for(let t=32;t<=55;t++)h[t]=v;h[56]=Wi;h[57]=Ji;h[58]=Qi;h[59]=eo;h[60]=v;h[61]=v;h[62]=v;h[63]=v;for(let t=64;t<=87;t++)h[t]=to;h[88]=ro;h[89]=no;h[90]=io;h[91]=oo;h[92]=v;h[93]=v;h[94]=v;h[95]=mr("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)h[t]=ao;h[120]=co;h[121]=uo;h[122]=lo;h[123]=fo;h[124]=v;h[125]=v;h[126]=v;h[127]=mr("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)h[t]=po;h[152]=mo;h[153]=go;h[154]=yo;h[155]=xo;h[156]=v;h[157]=v;h[158]=v;h[159]=wo;for(let t=160;t<=183;t++)h[t]=bo;h[184]=Eo;h[185]=So;h[186]=To;h[187]=Io;h[188]=v;h[189]=v;h[190]=v;h[191]=Co;for(let t=192;t<=215;t++)h[t]=Ao;h[216]=vo;h[217]=No;h[218]=Fo;h[219]=ko;h[220]=v;h[221]=v;h[222]=v;h[223]=v;for(let t=224;t<=243;t++)h[t]=mr("simple values are not supported");h[244]=v;h[245]=v;h[246]=v;h[247]=Do;h[248]=mr("simple values are not supported");h[249]=_o;h[250]=Lo;h[251]=Ro;h[252]=v;h[253]=v;h[254]=v;h[255]=Uo;var ue=[];for(let t=0;t<24;t++)ue[t]=new d(c.uint,t,1);for(let t=-1;t>=-24;t--)ue[31-t]=new d(c.negint,t,1);ue[64]=new d(c.bytes,new Uint8Array(0),1);ue[96]=new d(c.string,"",1);ue[128]=new d(c.array,0,1);ue[160]=new d(c.map,0,1);ue[244]=new d(c.false,!1,1);ue[245]=new d(c.true,!0,1);ue[246]=new d(c.null,null,1);function _n(t){switch(t.type){case c.false:return he([244]);case c.true:return he([245]);case c.null:return he([246]);case c.bytes:return t.value.length?void 0:he([64]);case c.string:return t.value===""?he([96]):void 0;case c.array:return t.value===0?he([128]):void 0;case c.map:return t.value===0?he([160]):void 0;case c.uint:return t.value<24?he([Number(t.value)]):void 0;case c.negint:if(t.value>=-24)return he([31-Number(t.value)])}}var Tc={float64:!1,mapSorter:Ac,quickEncodeToken:_n},Ko=Object.freeze({float64:!0,mapSorter:vc,quickEncodeToken:_n});function Ic(){let t=[];return t[c.uint.major]=ie,t[c.negint.major]=lr,t[c.bytes.major]=We,t[c.string.major]=ho,t[c.array.major]=hr,t[c.map.major]=dr,t[c.tag.major]=pr,t[c.float.major]=At,t}var et=Ic(),gr=new St,Nt=class t{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${ur} object contains circular references`);return new t(r,e)}},Ae={null:new d(c.null,null),undefined:new d(c.undefined,void 0),true:new d(c.true,!0),false:new d(c.false,!1),emptyArray:new d(c.array,0),emptyMap:new d(c.map,0)},de={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new d(c.float,t):t>=0?new d(c.uint,t):new d(c.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new d(c.uint,t):new d(c.negint,t)},Uint8Array(t,e,r,n){return new d(c.bytes,t)},string(t,e,r,n){return new d(c.string,t)},boolean(t,e,r,n){return t?Ae.true:Ae.false},null(t,e,r,n){return Ae.null},undefined(t,e,r,n){return Ae.undefined},ArrayBuffer(t,e,r,n){return new d(c.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new d(c.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Ae.emptyArray,new d(c.break)]:Ae.emptyArray;n=Nt.createCheck(n,t);let i=[],o=0;for(let s of t)i[o++]=Ze(s,r,n);return r.addBreakTokens?[new d(c.array,t.length),i,new d(c.break)]:[new d(c.array,t.length),i]},Object(t,e,r,n){let i=e!=="Object",o=i?t.keys():Object.keys(t),s=i?t.size:o.length,a;if(s){a=new Array(s),n=Nt.createCheck(n,t);let u=!i&&r.ignoreUndefinedProperties,f=0;for(let l of o){let p=i?t.get(l):t[l];u&&p===void 0||(a[f++]=[Ze(l,r,n),Ze(p,r,n)])}f<s&&(a.length=f)}return a?.length?(Cc(a,r),r.addBreakTokens?[new d(c.map,a.length),a,new d(c.break)]:[new d(c.map,a.length),a]):r.addBreakTokens===!0?[Ae.emptyMap,new d(c.break)]:Ae.emptyMap},Tagged(t,e,r,n){return[new d(c.tag,t.tag),Ze(t.value,r,n)]}};de.Map=de.Object;de.Buffer=de.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))de[`${t}Array`]=de.DataView;function Ze(t,e={},r){let n=In(t),i=e&&e.typeEncoders&&e.typeEncoders[n]||de[n];if(typeof i=="function"){let s=i(t,n,e,r);if(s!=null)return s}let o=de[n];if(!o)throw new Error(`${ur} unsupported type: ${n}`);return o(t,n,e,r)}function Cc(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Ac(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let i=r.type.major,o=et[i].compareTokens(r,n);return o===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),o}function vc(t,e){if(t[0]instanceof d&&e[0]instanceof d){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=Vo(r.value)),n._keyBytes||(n._keyBytes=Vo(n.value)),ar(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Vo(t){return Go(t,et,Ko)}function vt(t,e,r,n){if(Array.isArray(e))for(let i of e)vt(t,i,r,n);else r[e.type.major](t,e,n)}var Oo=c.uint.majorEncoded,zo=c.negint.majorEncoded,Nc=c.bytes.majorEncoded,Fc=c.string.majorEncoded,qo=c.array.majorEncoded,kc=c.float.majorEncoded|An,Dc=c.float.majorEncoded|vn,Uc=c.float.majorEncoded|Nn,_c=c.float.majorEncoded|Fn,Lc=BigInt(-1),Rc=BigInt(1);function Bc(t){return t.addBreakTokens!==!0}function Ho(t,e,r,n){let i=In(e),o=r.typeEncoders&&r.typeEncoders[i];if(o){let s=o(e,i,r,n);if(s!=null){vt(t,s,et,r);return}}switch(i){case"null":t.push([Uc]);return;case"undefined":t.push([_c]);return;case"boolean":t.push([e?Dc:kc]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?At(t,new d(c.float,e),r):e>=0?D(t,Oo,e):D(t,zo,e*-1-1);return;case"bigint":e>=BigInt(0)?D(t,Oo,e):D(t,zo,e*Lc-Rc);return;case"string":{let s=sr(e);D(t,Fc,s.length),t.push(s);return}case"Uint8Array":D(t,Nc,e.length),t.push(e);return;case"Array":if(!e.length){t.push([qo]);return}n=Nt.createCheck(n,e),D(t,qo,e.length);for(let s of e)Ho(t,s,r,n);return;case"Object":case"Map":{let s=de.Object(e,i,r,n);vt(t,s,et,r)}return;default:{let s=de[i];if(!s)throw new Error(`${ur} unsupported type: ${i}`);let a=s(e,i,r,n);vt(t,a,et,r)}}}function Go(t,e,r,n){let i=n instanceof Uint8Array,o=i?new cr(n):gr,s=Ze(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return i?(o.push(a),o.toBytes()):a;let u=e[s.type.major];if(u.encodedSize){let f=u.encodedSize(s,r);if(i||(o=new St(f)),u(o,s,r),o.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return i?o.toBytes():Et(o.chunks[0])}}return o.reset(),vt(o,s,e,r),o.toBytes(!0)}function Ln(t,e){return e=Object.assign({},Tc,e),Bc(e)?(gr.reset(),Ho(gr,t,e,void 0),gr.toBytes(!0)):Go(t,et,e)}var Mc={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},yr=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=ue[e];if(r===void 0){let n=h[e];if(!n)throw new Error(`${y} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let i=e&31;r=n(this.data,this._pos,i,this.options)}return this._pos+=r.encodedLength,r}},ve=Symbol.for("DONE"),tt=Symbol.for("BREAK");function Pc(t,e,r){let n=[];for(let i=0;i<t.value;i++){let o=Ne(e,r);if(o===tt){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed array`)}if(o===ve)throw new Error(`${y} found array but not enough entries (got ${i}, expected ${t.value})`);n[i]=o}return n}function $c(t,e,r){let n=r.useMaps===!0,i=r.rejectDuplicateMapKeys===!0,o=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let u=Ne(e,r);if(u===tt){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed map`)}if(u===ve)throw new Error(`${y} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof u!="string")throw new Error(`${y} non-string keys not supported (got ${typeof u})`);if(i&&(n&&s.has(u)||!n&&Object.hasOwn(o,u)))throw new Error(`${y} found repeat map key "${u}"`);let f=Ne(e,r);if(f===ve)throw new Error(`${y} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(u,f):o[u]=f}return n?s:o}function*Vc(t,e,r){for(let n=0;n<t.value;n++){let i=Ne(e,r);if(i===tt){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed map`)}if(i===ve)throw new Error(`${y} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let o=Ne(e,r);if(o===ve)throw new Error(`${y} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[i,o]}}function Oc(t,e){let r=!1,n=function(){if(r)throw new Error(`${y} tag decode() may only be called once`);r=!0;let i=Ne(t,e);if(i===ve)throw new Error(`${y} tag content missing`);if(i===tt)throw new Error(`${y} got unexpected break in tag content`);return i};return n.entries=function(){if(r)throw new Error(`${y} tag decode() may only be called once`);r=!0;let i=t.next();if(!c.equals(i.type,c.map))throw new Error(`${y} entries() requires map content, got ${i.type.name}`);let o=[];for(let s of Vc(i,t,e))o.push(s);return o},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function Ne(t,e){if(t.done())return ve;let r=t.next();if(c.equals(r.type,c.break))return tt;if(r.type.terminal)return r.value;if(c.equals(r.type,c.array))return Pc(r,t,e);if(c.equals(r.type,c.map))return $c(r,t,e);if(c.equals(r.type,c.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=Oc(t,e),i=e.tags[r.value](n);if(!n._called)throw new Error(`${y} tag decoder must call decode() or entries()`);return i}throw new Error(`${y} tag not supported (${r.value})`)}throw new Error("unsupported")}function jo(t,e){if(!(t instanceof Uint8Array))throw new Error(`${y} data to decode must be a Uint8Array`);e=Object.assign({},Mc,e);let r=Et(t),n=e.tokenizer||new yr(r,e),i=Ne(n,e);if(i===ve)throw new Error(`${y} did not find any content to decode`);if(i===tt)throw new Error(`${y} got unexpected break`);return[i,t.subarray(n.pos())]}function Rn(t,e){let[r,n]=jo(t,e);if(n.length>0)throw new Error(`${y} too many terminals, data makes no sense`);return r}var xr=class t{constructor(e,r){if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=e,this.value=r}static decoder(e){return r=>new t(e,r())}static preserve(...e){let r={};for(let n of e)r[n]=t.decoder(n);return r}};Object.defineProperty(xr.prototype,Symbol.toStringTag,{value:"Tagged"});function Be(t,e="utf8"){let r=Jt[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var Ee="/",Yo=new TextEncoder().encode(Ee),wr=Yo[0],rt=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=$(e);else if(e instanceof Uint8Array)this._buf=e;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]!==wr)throw new Error("Invalid key")}toString(e="utf8"){return Be(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(Ee))}static random(){return new t(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new t(e):typeof e.uint8Array=="function"?new t(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Yo),this._buf[0]!==wr){let e=new Uint8Array(this._buf.byteLength+1);e.fill(wr,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===wr;)this._buf=this._buf.subarray(0,-1)}less(e){let r=this.list(),n=e.list();for(let i=0;i<r.length;i++){if(n.length<i+1)return!1;let o=r[i],s=n[i];if(o<s)return!0;if(o>s)return!1}return r.length<n.length}reverse(){return t.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(Ee).slice(1)}type(){return qc(this.baseNamespace())}name(){return Kc(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Ee)||(e+=Ee),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(Ee):new t(e.slice(0,-1).join(Ee))}child(e){return this.toString()===Ee?e:e.toString()===Ee?this:new t(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return t.withNamespaces([...this.namespaces(),...Hc(e.map(r=>r.namespaces()))])}};function qc(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function Kc(t){let e=t.split(":");return e[e.length-1]}function Hc(t){return[].concat(...t)}var Wo=114;var jc=1024*10,Jo=$("/ipns/"),Qo="/ipns/";function Yc(t,e){return t.code===e}var br="/dht/record/",Xc="/ipns/metadata/";function Ft(t){return new rt(br+Be(t,"base32"),!1)}function Er(t){return new rt(Xc+Be(t,"base32"),!1)}function Zo(t,e){let r=Date.now(),n=e.getTime()+1728e5,i=new Date(t.validity).getTime();return n-r<864e5||i-r<864e5}function es(t,e,r){let n=$(e),i=$(t);return rr([i,r,n],i.byteLength+r.byteLength+n.byteLength)}function Sr(t){let e=$("ipns-signature:");return rr([e,t])}function nt(t){let e=t.publicKey?.toProtobuf();return t.publicKey?.toMultihash().code===0&&(e=void 0),"signatureV1"in t?O.encode({value:$(t.value),signatureV1:t.signatureV1,validityType:t.validityType,validity:$(t.validity),sequence:t.sequence,ttl:t.ttl,publicKey:e,signatureV2:t.signatureV2,data:t.data}):O.encode({publicKey:e,signatureV2:t.signatureV2,data:t.data})}function Xo(t){try{return`/ipfs/${fe.decode(t)}`}catch{}return Be(t)}async function pe(t,e,r,n){if(e.byteLength>jc)throw new Ht("The record is too large");let i=O.decode(e);if(i.signatureV2==null||i.data==null)throw new se("Missing data or signatureV2");let o=rs(i.data),s=Be(o.Validity),a,u=Wc(t);if(Yc(u,0)&&(a=await r.loadPublicKeyFromProtobuf(u.digest,n)),a==null&&i.publicKey!=null&&(a=await r.loadPublicKeyFromProtobuf(i.publicKey,n)),a==null)throw new Xe("Could not extract public key from IPNS record or routing key");if(i.value!=null&&i.signatureV1!=null)return Qc(i),{value:Xo(o.Value),validityType:O.ValidityType.EOL,validity:s,sequence:o.Sequence,ttl:o.TTL,publicKey:a,signatureV1:i.signatureV1,signatureV2:i.signatureV2,data:i.data,bytes:e};if(i.signatureV2!=null)return{value:Xo(o.Value),validityType:O.ValidityType.EOL,validity:s,sequence:o.Sequence,ttl:o.TTL,publicKey:a,signatureV2:i.signatureV2,data:i.data,bytes:e};throw new Error("invalid record: does not include signatureV1 or signatureV2")}function kt(t){return rr([Jo,t.bytes])}function Wc(t){return ut(t.slice(Jo.length))}function ts(t,e,r,n,i){let o;if(e===O.ValidityType.EOL)o=0;else throw new Ue("The validity type is unsupported");let s={Value:$(t),Validity:r,ValidityType:o,Sequence:n,TTL:i};return Ln(s)}function rs(t){let e=Rn(t);if(e.ValidityType===0)e.ValidityType=O.ValidityType.EOL;else throw new Ue("The validity type is unsupported");return Number.isInteger(e.Sequence)&&(e.Sequence=BigInt(e.Sequence)),Number.isInteger(e.TTL)&&(e.TTL=BigInt(e.TTL)),e}function ns(t){if(t!=null){if(nr(t))return`/ipns/${t.toCID().toV1().toString(ne)}`;let e=is(t);if(e!=null)return e.code===Wo?`/ipns/${e.toV1().toString(ne)}`:`/ipfs/${e.toV1()}`;if(Zc(t))return`/ipns/${ne.encode(t.bytes)}`;let r=t.toString().trim();if(r.startsWith("/ipfs/")){let[,n,...i]=r.split("/").filter(o=>o.trim()!=="");return`/ipfs/${fe.parse(n).toV1()}${i.length>0?`/${i.join("/")}`:""}`}if(r.startsWith("/")&&r.length>1)return r}throw new Ye("Value must be a valid content path starting with /")}function Jc(t){return typeof t.code=="number"&&t.digest instanceof Uint8Array&&typeof t.size=="number"&&t.bytes instanceof Uint8Array}function Dt(t){if(t!=null){if(nr(t))return{digest:t.toMultihash(),path:"/"};let e=is(t);if(e!=null){if(e.code!==Wo)throw new Ye("CIDs must have the `libp2p-key` codec");return{digest:e.multihash,path:"/"}}if(Jc(t))return{digest:t,path:"/"};if(t=t.toString(),t.startsWith("/ipns/")){let[,,r,...n]=t.split("/"),i=ne;(r.startsWith("1")||r.startsWith("Q"))&&(r=`z${r}`,i=j);let o=i.decode(r),s;try{s=fe.decode(o).multihash}catch{s=ut(o)}return{digest:s,path:`/${n.join("/")}`}}}throw new Ye("Value must be a valid IPNS path starting with /")}function Qc(t){if(t.data==null)throw new Gt("Record data is missing");let e=rs(t.data);if(!wt(e.Value,t.value??new Uint8Array(0)))throw new se('Field "value" did not match between protobuf and CBOR');if(!wt(e.Validity,t.validity??new Uint8Array(0)))throw new se('Field "validity" did not match between protobuf and CBOR');if(e.ValidityType!==t.validityType)throw new se('Field "validityType" did not match between protobuf and CBOR');if(e.Sequence!==t.sequence)throw new se('Field "sequence" did not match between protobuf and CBOR');if(e.TTL!==t.ttl)throw new se('Field "ttl" did not match between protobuf and CBOR')}function Zc(t){return t.bytes instanceof Uint8Array}function eu(t){return typeof t?.toCID=="function"}function is(t){if(eu(t))return t.toCID();try{return fe.parse(t)}catch{}return fe.asCID(t)}var os=$r(jt(),1);async function Ut(t,e){if(t.publicKey==null)throw new Xe("The record had no public key associated with it");let r;try{let n=Sr(t.data);r=await t.publicKey.verify(n,t.signatureV2,e)}catch{r=!1}if(!r)throw new se("Record signature verification failed");if(t.validityType===O.ValidityType.EOL){if(os.default.fromString(t.validity).toDate().getTime()<Date.now())throw new Kt("record has expired")}else if(t.validityType!=null)throw new Ue("The validity type is unsupported")}var it=class{routers;localStore;log;keychain;constructor(e,r){this.log=e.logger.forComponent("helia:ipns"),this.localStore=r.localStore,this.routers=r.routers,this.keychain=e.keychain}async*resolve(e,r={}){let{digest:n}=Dt(e);for(;;){let i=kt(n),o=await this.#e(i,r);if(yield{record:o},!o.value.startsWith(Qo))break;({digest:n}=Dt(o.value))}}async#e(e,r={}){let n=[];if(await this.localStore.has(e,r))if(this.log("record is present in the cache"),r.nocache!==!0)try{let{record:u,created:f}=await this.localStore.get(e,r);this.log("record retrieved from cache");let l=await pe(e,u,this.keychain,r);await Ut(l,r),this.log("record was valid");let p=Number((l.ttl??je)/1000000n);if(f.getTime()+p>Date.now())return this.log("record TTL was valid"),l;if(r.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),l;this.log("record TTL has been reached, searching routing for updates"),n.push(l)}catch(u){this.log("cached record was invalid - %e",u),await this.localStore.delete(e,r)}else this.log("ignoring local cache due to nocache=true option");if(r.offline===!0)throw new ft("Record was not present in the cache or has expired");this.log("did not have record locally");let o=0,s=[];if(await Promise.all(this.routers.map(async u=>{let f;try{f=await u.get(e,{...r,validate:!1})}catch(l){this.log.error("error finding IPNS record using router %s - %e",u.toString(),l),s.push(l);return}try{let l=await pe(e,f,this.keychain,r);await Ut(l,r),n.push(l)}catch(l){o++,this.log.error("error validating IPNS record from router %s - %e",u.toString(),l)}})),n.length===0)throw o>0?new zt(`${o>1?`${o} records`:"Record"} found for routing key ${o>1?"were":"was"} invalid`):new ft("Could not find record for routing key");let a=n[tr(e,n)];return await this.localStore.put(e,a.bytes,r),a}};var Y=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};function Tr(t,e){if(typeof t=="string")return tu(t);if(typeof t=="number")return iu(t,e);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}function tu(t){if(typeof t!="string"||t.length===0||t.length>100)throw new Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(t)}`);let e=/^(?<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(t);if(!e?.groups)return NaN;let{value:r,unit:n="ms"}=e.groups,i=parseFloat(r),o=n.toLowerCase();switch(o){case"years":case"year":case"yrs":case"yr":case"y":return i*315576e5;case"months":case"month":case"mo":return i*26298e5;case"weeks":case"week":case"w":return i*6048e5;case"days":case"day":case"d":return i*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return i*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return i*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return i*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return i;default:throw new Error(`Unknown unit "${o}" provided to ms.parse(). value=${JSON.stringify(t)}`)}}function ru(t){let e=Math.abs(t);return e>=315576e5?`${Math.round(t/315576e5)}y`:e>=26298e5?`${Math.round(t/26298e5)}mo`:e>=6048e5?`${Math.round(t/6048e5)}w`:e>=864e5?`${Math.round(t/864e5)}d`:e>=36e5?`${Math.round(t/36e5)}h`:e>=6e4?`${Math.round(t/6e4)}m`:e>=1e3?`${Math.round(t/1e3)}s`:`${t}ms`}function nu(t){let e=Math.abs(t);return e>=315576e5?Me(t,e,315576e5,"year"):e>=26298e5?Me(t,e,26298e5,"month"):e>=6048e5?Me(t,e,6048e5,"week"):e>=864e5?Me(t,e,864e5,"day"):e>=36e5?Me(t,e,36e5,"hour"):e>=6e4?Me(t,e,6e4,"minute"):e>=1e3?Me(t,e,1e3,"second"):`${t} ms`}function iu(t,e){if(typeof t!="number"||!Number.isFinite(t))throw new Error("Value provided to ms.format() must be of type number.");return e?.long?nu(t):ru(t)}function Me(t,e,r,n){let i=e>=r*1.5;return`${Math.round(t/r)} ${n}${i?"s":""}`}function Bn(t){r.debug=r,r.default=r,r.coerce=u,r.disable=o,r.enable=i,r.enabled=s,r.humanize=Tr,r.destroy=f,Object.keys(t).forEach(l=>{r[l]=t[l]}),r.names=[],r.skips=[],r.formatters={};function e(l){let p=0;for(let m=0;m<l.length;m++)p=(p<<5)-p+l.charCodeAt(m),p|=0;return r.colors[Math.abs(p)%r.colors.length]}r.selectColor=e;function r(l,p){let m,b=null,S,E;function x(...T){if(!x.enabled)return;let F=x,k=Number(new Date),P=k-(m||k);F.diff=P,F.prev=m,F.curr=k,m=k,T[0]=r.coerce(T[0]),typeof T[0]!="string"&&T.unshift("%O");let B=0;T[0]=T[0].replace(/%([a-zA-Z%])/g,(R,g)=>{if(R==="%%")return"%";B++;let w=r.formatters[g];if(typeof w=="function"){let A=T[B];R=w.call(F,A),T.splice(B,1),B--}return R}),r.formatArgs.call(F,T),p?.onLog!=null&&p.onLog(...T),(F.log||r.log).apply(F,T)}return x.namespace=l,x.useColors=r.useColors(),x.color=r.selectColor(l),x.extend=n,x.destroy=r.destroy,Object.defineProperty(x,"enabled",{enumerable:!0,configurable:!1,get:()=>b!==null?b:(S!==r.namespaces&&(S=r.namespaces,E=r.enabled(l)),E),set:T=>{b=T}}),typeof r.init=="function"&&r.init(x),x}function n(l,p){let m=r(this.namespace+(typeof p>"u"?":":p)+l);return m.log=this.log,m}function i(l){r.save(l),r.namespaces=l,r.names=[],r.skips=[];let p,m=(typeof l=="string"?l:"").split(/[\s,]+/),b=m.length;for(p=0;p<b;p++)m[p]&&(l=m[p].replace(/\*/g,".*?"),l[0]==="-"?r.skips.push(new RegExp("^"+l.substr(1)+"$")):r.names.push(new RegExp("^"+l+"$")))}function o(){let l=[...r.names.map(a),...r.skips.map(a).map(p=>"-"+p)].join(",");return r.enable(""),l}function s(l){if(l[l.length-1]==="*")return!0;let p,m;for(p=0,m=r.skips.length;p<m;p++)if(r.skips[p].test(l))return!1;for(p=0,m=r.names.length;p<m;p++)if(r.names[p].test(l))return!0;return!1}function a(l){return l.toString().substring(2,l.toString().length-2).replace(/\.\*\?$/,"*")}function u(l){return l instanceof Error?l.stack??l.message:l}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 Ir=fu(),ou=["#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 su(){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 au(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+Tr(this.diff),!this.useColors)return;let e="color: "+this.color;t.splice(1,0,e,"color: inherit");let r=0,n=0;t[0].replace(/%[a-zA-Z%]/g,i=>{i!=="%%"&&(r++,i==="%c"&&(n=r))}),t.splice(n,0,e)}var cu=console.debug??console.log??(()=>{});function uu(t){try{t?Ir?.setItem("debug",t):Ir?.removeItem("debug")}catch{}}function lu(){let t;try{t=Ir?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function fu(){try{return localStorage}catch{}}function hu(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var ss=Bn({formatArgs:au,save:uu,load:lu,useColors:su,setupFormatters:hu,colors:ou,storage:Ir,log:cu});var X=ss;X.formatters.b=t=>t==null?"undefined":j.baseEncode(t);X.formatters.t=t=>t==null?"undefined":Te.baseEncode(t);X.formatters.m=t=>t==null?"undefined":sn.baseEncode(t);X.formatters.p=t=>t==null?"undefined":t.toString();X.formatters.c=t=>t==null?"undefined":t.toString();X.formatters.k=t=>t==null?"undefined":t.toString();X.formatters.a=t=>t==null?"undefined":t.toString();function as(t,e=""){let r=cs(t.message),n=cs(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
2
+ "use strict";var HeliaIpns=(()=>{var Yi=Object.create;var Ut=Object.defineProperty;var Xi=Object.getOwnPropertyDescriptor;var Ji=Object.getOwnPropertyNames;var Wi=Object.getPrototypeOf,Qi=Object.prototype.hasOwnProperty;var Zi=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},Y=(t,e)=>{for(var r in e)Ut(t,r,{get:e[r],enumerable:!0})},Fn=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ji(e))!Qi.call(t,o)&&o!==r&&Ut(t,o,{get:()=>e[o],enumerable:!(n=Xi(e,o))||n.enumerable});return t};var Ir=(t,e,r)=>(r=t!=null?Yi(Wi(t)):{},Fn(e||!t||!t.__esModule?Ut(r,"default",{value:t,enumerable:!0}):r,t)),es=t=>Fn(Ut({},"__esModule",{value:!0}),t);var Pt=Zi((bu,Br)=>{var xu=(function(){typeof Br<"u"&&(Br.exports=E);var t=86400,e=3200,r=146097*e/400,n=t*r,o=1e3*n,i=864e13,s=4294967296,a=1e6,u="000000000",f=Math.trunc||function(g){var b=g-g%1;return b==0&&(g<0||g===0&&1/g!=1/0)?-0:b},l=E.prototype,p=(E.fromDate=function(g){return new E(+g)},E.fromInt64BE=P(0,1,2,3,0,4),E.fromInt64LE=P(3,2,1,0,4,0),E.fromString=function(C){var b,I=new E,C=(C+="").replace(/^\s*[+\-]?\d+/,function(D){var D=+D,M=1970+(D-1970)%400;return I.year=D-M,M}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(v,D,M){return D<0&&(M*=-1),b=6e4*(60*+D+ +M),""}).replace(/\.\d+$/,function(v){return I.nano=+(v+u).substr(1,9),""}).split(/\D+/);if(1<C.length?C[1]--:C[1]=0,I.time=b=Date.UTC.apply(Date,C)-(b||0),isNaN(b))throw new TypeError("Invalid Date");return x(I)},E.fromTimeT=function(g){return k(g,0)},l.year=0,l.time=0,l.nano=0,l.addNano=function(g){return this.nano+=+g||0,this},l.getNano=function(){var g=x(this);return(g.time%1e3*a+ +g.nano+1e9)%1e9},l.getTimeT=function(){var b=x(this),g=Math.floor(b.time/1e3),b=b.year;return b&&(g+=b*r*t/e),g},l.getYear=function(){return this.toDate().getUTCFullYear()+this.year},l.toDate=function(){return T(x(this).time)},l.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},l.toString=function(g){var b=this,I=b.toDate(),C={H:function(){return q(I.getUTCHours())},L:function(){return R(I.getUTCMilliseconds(),3)},M:function(){return q(I.getUTCMinutes())},N:function(){return R(b.getNano(),9)},S:function(){return q(I.getUTCSeconds())},Y:function(){var v=b.getYear();return 999999<v?"+"+v:9999<v?"+"+R(v,6):0<=v?R(v,4):-999999<=v?"-"+R(-v,6):v},a:function(){return w[I.getUTCDay()]},b:function(){return m[I.getUTCMonth()]},d:function(){return q(I.getUTCDate())},e:function(){return(function(v){return(9<v?"":" ")+(0|v)})(I.getUTCDate())},m:function(){return q(I.getUTCMonth()+1)}};return(function v(D){return D.replace(/%./g,function(M){var L=M[1],N=S[L],L=C[L];return N?v(N):L?L():M})})(g||p)},l.writeInt64BE=F(0,1,2,3,0,4),l.writeInt64LE=F(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),m=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],w=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],S={"%":"%",F:"%Y-%m-%d",n:`
3
+ `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return E;function E(g,b,I){var C=this;if(!(C instanceof E))return new E(g,b,I);C.time=+g||0,C.nano=+b||0,C.year=+I||0,x(C)}function x(g){var b,I,C,v=g.year,D=g.time,M=g.nano,N=((M<0||a<=M)&&(M-=(I=Math.floor(M/a))*a,D+=I,I=1),v%e);return(D<-i||i<D||N)&&((b=f(D/o))&&(v+=b*e,D-=b*o),(C=T(D)).setUTCFullYear(N+C.getUTCFullYear()),C=(D=+C)+(b=f((v-=N)/e))*o,b&&-i<=C&&C<=i&&(v-=b*e,D=C),I=1),I&&(g.year=v,g.time=D,g.nano=M),g}function T(g){var b=new Date(0);return b.setTime(g),b}function k(v,C){v=+v||0;var I=f((C=(C|0)*s)/n)+f(v/n),C=C%n+v%n,v=f(C/n);return v&&(I+=v,C-=v*n),new E(1e3*C,0,I*e)}function F(g,b,I,C,v,D){return function(N,L){var he=x(this);N=N||new Array(8),B(N,L|=0);var Me=Math.floor(he.time/1e3),he=he.year*(r*t/e),de=f(he/s)+f(Me/s),he=he%s+Me%s,Me=Math.floor(he/s);return Me&&(de+=Me,he-=Me*s),M(N,L+v,de),M(N,L+D,he),N};function M(N,L,de){N[L+g]=de>>24&255,N[L+b]=de>>16&255,N[L+I]=de>>8&255,N[L+C]=255&de}}function P(g,b,I,C,v,D){return function(N,L){B(N,L|=0);var de=M(N,L+v);return k(M(N,L+D),de)};function M(N,L){return 16777216*N[L+g]+(N[L+b]<<16|N[L+I]<<8|N[L+C])}}function B(g,b){if(g=g&&g.length,g==null)throw new TypeError("Invalid Buffer");if(g<b+8)throw new RangeError("Out of range")}function q(g){return(9<g?"":"0")+(0|g)}function R(g,b){return(u+(0|g)).substr(-b)}})()});var Wc={};Y(Wc,{ipns:()=>Xc,ipnsResolver:()=>Jc});var Ur={};Y(Ur,{base32:()=>be,base32hex:()=>fs,base32hexpad:()=>hs,base32hexpadupper:()=>ps,base32hexupper:()=>ds,base32pad:()=>us,base32padupper:()=>ls,base32upper:()=>cs,base32z:()=>ms});var Zc=new Uint8Array(0);function Un(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function pe(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Ie(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Ie(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Dn(t){return new TextEncoder().encode(t)}function Ln(t){return new TextDecoder().decode(t)}function ts(t){return t?.buffer instanceof ArrayBuffer}function Ie(t){return ts(t)?t:t.slice()}function rs(t,e){if(t.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<t.length;o++){var i=t.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=t.length,u=t.charAt(0),f=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function p(S){if(S instanceof Uint8Array||(ArrayBuffer.isView(S)?S=new Uint8Array(S.buffer,S.byteOffset,S.byteLength):Array.isArray(S)&&(S=Uint8Array.from(S))),!(S instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(S.length===0)return"";for(var E=0,x=0,T=0,k=S.length;T!==k&&S[T]===0;)T++,E++;for(var F=(k-T)*l+1>>>0,P=new Uint8Array(F);T!==k;){for(var B=S[T],q=0,R=F-1;(B!==0||q<x)&&R!==-1;R--,q++)B+=256*P[R]>>>0,P[R]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");x=q,T++}for(var g=F-x;g!==F&&P[g]===0;)g++;for(var b=u.repeat(E);g<F;++g)b+=t.charAt(P[g]);return b}function m(S){if(typeof S!="string")throw new TypeError("Expected String");if(S.length===0)return new Uint8Array;var E=0;if(S[E]!==" "){for(var x=0,T=0;S[E]===u;)x++,E++;for(var k=(S.length-E)*f+1>>>0,F=new Uint8Array(k);S[E];){var P=r[S.charCodeAt(E)];if(P===255)return;for(var B=0,q=k-1;(P!==0||B<T)&&q!==-1;q--,B++)P+=a*F[q]>>>0,F[q]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");T=B,E++}if(S[E]!==" "){for(var R=k-T;R!==k&&F[R]===0;)R++;for(var g=new Uint8Array(x+(k-R)),b=x;R!==k;)g[b++]=F[R++];return g}}}function w(S){var E=m(S);if(E)return E;throw new Error(`Non-${e} character`)}return{encode:p,decodeUnsafe:m,decode:w}}var ns=rs,os=ns,Rn=os;var Ar=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Nr=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,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(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Bn(this,e)}},kr=class{decoders;constructor(e){this.decoders=e}or(e){return Bn(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Bn(t,e){return new kr({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Fr=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Ar(e,r,n),this.decoder=new Nr(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Pe({name:t,prefix:e,encode:r,decode:n}){return new Fr(t,e,r,n)}function xe({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Rn(r,t);return Pe({prefix:e,name:t,encode:n,decode:i=>pe(o(i))})}function is(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,u=0;for(let f=0;f<o;++f){let l=e[t[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|l,s+=r,s>=8&&(s-=8,i[u++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function ss(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let u=0;u<t.length;++u)for(a=a<<8|t[u],s+=8;s>r;)s-=r,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function as(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function _({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=as(n);return Pe({prefix:e,name:t,encode(i){return ss(i,n,r)},decode(i){return is(i,o,r,t)}})}var be=_({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),cs=_({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),us=_({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ls=_({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),fs=_({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ds=_({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),hs=_({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ps=_({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ms=_({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Dr={};Y(Dr,{base36:()=>ee,base36upper:()=>gs});var ee=xe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),gs=xe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Lr={};Y(Lr,{base58btc:()=>H,base58flickr:()=>ys});var H=xe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ys=xe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var xs=$n,Mn=128,bs=127,ws=~bs,Es=Math.pow(2,31);function $n(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Es;)e[r++]=t&255|Mn,t/=128;for(;t&ws;)e[r++]=t&255|Mn,t>>>=7;return e[r]=t|0,$n.bytes=r-n+1,e}var Ss=_r,Ts=128,Pn=127;function _r(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw _r.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&Pn)<<o:(s&Pn)*Math.pow(2,o),o+=7}while(s>=Ts);return _r.bytes=i-n,r}var vs=Math.pow(2,7),Cs=Math.pow(2,14),Is=Math.pow(2,21),As=Math.pow(2,28),Ns=Math.pow(2,35),ks=Math.pow(2,42),Fs=Math.pow(2,49),Us=Math.pow(2,56),Ds=Math.pow(2,63),Ls=function(t){return t<vs?1:t<Cs?2:t<Is?3:t<As?4:t<Ns?5:t<ks?6:t<Fs?7:t<Us?8:t<Ds?9:10},_s={encode:xs,decode:Ss,encodingLength:Ls},Rs=_s,ot=Rs;function it(t,e=0){return[ot.decode(t,e),ot.decode.bytes]}function $e(t,e,r=0){return ot.encode(t,e,r),e}function Ve(t){return ot.encodingLength(t)}function ze(t,e){let r=e.byteLength,n=Ve(t),o=n+Ve(r),i=new Uint8Array(o+r);return $e(t,i,0),$e(r,i,n),i.set(e,o),new Oe(t,r,e,i)}function st(t){let e=pe(t),[r,n]=it(e),[o,i]=it(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Oe(r,o,s,e)}function Vn(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Un(t.bytes,r.bytes)}}var Oe=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=Ie(n),this.bytes=Ie(o)}};function On(t,e){let{bytes:r,version:n}=t;return n===0?Ms(r,Rr(t),e??H.encoder):Ps(r,Rr(t),e??be.encoder)}var zn=new WeakMap;function Rr(t){let e=zn.get(t);if(e==null){let r=new Map;return zn.set(t,r),r}return e}var ae=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=Ie(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==at)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==$s)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.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:e,digest:r}=this.multihash,n=ze(e,r);return t.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(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&Vn(e.multihash,n.multihash)}toString(e){return On(this,e)}toJSON(){return{"/":On(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new t(n,o,i,s??qn(n,o,i.bytes))}else if(r[Vs]===!0){let{version:n,multihash:o,code:i}=r,s=st(o);return t.create(n,i,s)}else return null}static create(e,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(e){case 0:{if(r!==at)throw new Error(`Version 0 CID must use dag-pb (code: ${at}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=qn(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,at,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=pe(e.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 Oe(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[p,m]=it(e.subarray(r));return r+=m,p},o=n(),i=at;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(),u=n(),f=r+u,l=f-s;return{version:o,codec:i,multihashCode:a,digestSize:u,multihashSize:l,size:f}}static parse(e,r){let[n,o]=Bs(e,r),i=t.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Rr(i).set(n,e),i}};function Bs(t,e){switch(t[0]){case"Q":{let r=e??H;return[H.prefix,r.decode(`${H.prefix}${t}`)]}case H.prefix:{let r=e??H;return[H.prefix,r.decode(t)]}case be.prefix:{let r=e??be;return[be.prefix,r.decode(t)]}case ee.prefix:{let r=e??ee;return[ee.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Ms(t,e,r){let{prefix:n}=r;if(n!==H.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let i=r.encode(t).slice(1);return e.set(n,i),i}else return o}function Ps(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let i=r.encode(t);return e.set(n,i),i}else return o}var at=112,$s=18;function qn(t,e,r){let n=Ve(t),o=n+Ve(e),i=new Uint8Array(o+r.byteLength);return $e(t,i,0),$e(e,i,n),i.set(r,o),i}var Vs=Symbol.for("@ipld/js-cid/CID");var Ke=BigInt(6e4)*5000000n,Kn=5;var Lt=class extends Error{static name="RecordsFailedValidationError";name="RecordsFailedValidationError"};var He=class extends Error{static name="InvalidValueError";name="InvalidValueError"};var ct=class extends Error{static name="RecordNotFoundError";name="RecordNotFoundError"},_t=class extends Error{static name="SignatureCreationError";name="SignatureCreationError"},ne=class extends Error{static name="SignatureVerificationError";name="SignatureVerificationError"},Rt=class extends Error{static name="RecordExpiredError";name="RecordExpiredError"},Ae=class extends Error{static name="UnsupportedValidityError";name="UnsupportedValidityError"},Bt=class extends Error{static name="RecordTooLargeError";name="RecordTooLargeError"},Mt=class extends Error{static name="InvalidRecordDataError";name="InvalidRecordDataError"},je=class extends Error{static name="InvalidEmbeddedPublicKeyError";name="InvalidEmbeddedPublicKeyError"};var ln=Ir(Pt(),1);function Mr(t=0){return new Uint8Array(t)}function ce(t=0){return new Uint8Array(t)}var Os=Math.pow(2,7),zs=Math.pow(2,14),qs=Math.pow(2,21),Hn=Math.pow(2,28),jn=Math.pow(2,35),Gn=Math.pow(2,42),Yn=Math.pow(2,49),K=128,we=127;function ut(t){if(t<Os)return 1;if(t<zs)return 2;if(t<qs)return 3;if(t<Hn)return 4;if(t<jn)return 5;if(t<Gn)return 6;if(t<Yn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Xn(t,e,r=0){switch(ut(t)){case 8:e[r++]=t&255|K,t/=128;case 7:e[r++]=t&255|K,t/=128;case 6:e[r++]=t&255|K,t/=128;case 5:e[r++]=t&255|K,t/=128;case 4:e[r++]=t&255|K,t>>>=7;case 3:e[r++]=t&255|K,t>>>=7;case 2:e[r++]=t&255|K,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Jn(t,e){let r=t[e],n=0;if(n+=r&we,r<K||(r=t[e+1],n+=(r&we)<<7,r<K)||(r=t[e+2],n+=(r&we)<<14,r<K)||(r=t[e+3],n+=(r&we)<<21,r<K)||(r=t[e+4],n+=(r&we)*Hn,r<K)||(r=t[e+5],n+=(r&we)*jn,r<K)||(r=t[e+6],n+=(r&we)*Gn,r<K)||(r=t[e+7],n+=(r&we)*Yn,r<K))return n;throw new RangeError("Could not decode varint")}function Ks(t){return t.buffer instanceof ArrayBuffer}function Wn(t){return Ks(t)?t:t.slice()}var Pr=new Float32Array([-0]),Ee=new Uint8Array(Pr.buffer);function Qn(t,e,r){Pr[0]=t,e[r]=Ee[0],e[r+1]=Ee[1],e[r+2]=Ee[2],e[r+3]=Ee[3]}function Zn(t,e){return Ee[0]=t[e],Ee[1]=t[e+1],Ee[2]=t[e+2],Ee[3]=t[e+3],Pr[0]}var $r=new Float64Array([-0]),O=new Uint8Array($r.buffer);function eo(t,e,r){$r[0]=t,e[r]=O[0],e[r+1]=O[1],e[r+2]=O[2],e[r+3]=O[3],e[r+4]=O[4],e[r+5]=O[5],e[r+6]=O[6],e[r+7]=O[7]}function to(t,e){return O[0]=t[e],O[1]=t[e+1],O[2]=t[e+2],O[3]=t[e+3],O[4]=t[e+4],O[5]=t[e+5],O[6]=t[e+6],O[7]=t[e+7],$r[0]}var Hs=BigInt(Number.MAX_SAFE_INTEGER),js=BigInt(Number.MIN_SAFE_INTEGER),X=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&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(e=!1){if(e)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(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Ne;if(e<Hs&&e>js)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>ro&&(o=0n,++n>ro&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Ne;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Ne}},Ne=new X(0,0);Ne.toBigInt=function(){return 0n};Ne.zzEncode=Ne.zzDecode=function(){return this};Ne.length=function(){return 1};var ro=4294967296n;function no(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function oo(t,e,r){if(r-e<1)return"";let o,i=[],s=0,a;for(;e<r;)a=t[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&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 Vr(t,e,r){let n=r,o,i;for(let s=0;s<t.length;++s)o=t.charCodeAt(s),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((i=t.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function oe(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function $t(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Or=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Wn(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,oe(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw oe(this,4);return $t(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw oe(this,4);return $t(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw oe(this,4);let e=Zn(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw oe(this,4);let e=to(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw oe(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return oo(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw oe(this,e);this.pos+=e}else do if(this.pos>=this.len)throw oe(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new X(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw oe(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw oe(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw oe(this,8);let e=$t(this.buf,this.pos+=4),r=$t(this.buf,this.pos+=4);return new X(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Jn(this.buf,this.pos);return this.pos+=ut(e),e}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 lt(t){return new Or(t instanceof Uint8Array?t:t.subarray())}function ke(t,e,r){let n=lt(t);return e.decode(n,void 0,r)}var zr={};Y(zr,{base10:()=>Gs});var Gs=xe({prefix:"9",name:"base10",alphabet:"0123456789"});var qr={};Y(qr,{base16:()=>Ys,base16upper:()=>Xs});var Ys=_({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Xs=_({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Kr={};Y(Kr,{base2:()=>Js});var Js=_({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Hr={};Y(Hr,{base256emoji:()=>ta});var so=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}"),Ws=so.reduce((t,e,r)=>(t[r]=e,t),[]),Qs=so.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Zs(t){return t.reduce((e,r)=>(e+=Ws[r],e),"")}function ea(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Qs[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var ta=Pe({prefix:"\u{1F680}",name:"base256emoji",encode:Zs,decode:ea});var Gr={};Y(Gr,{base64:()=>jr,base64pad:()=>ra,base64url:()=>na,base64urlpad:()=>oa});var jr=_({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ra=_({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),na=_({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),oa=_({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Yr={};Y(Yr,{base8:()=>ia});var ia=_({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Xr={};Y(Xr,{identity:()=>sa});var sa=Pe({prefix:"\0",name:"identity",encode:t=>Ln(t),decode:t=>Dn(t)});var Ou=new TextEncoder,zu=new TextDecoder;var Jr={};Y(Jr,{identity:()=>fa});var ao=0,ua="identity",co=pe;function la(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return ze(ao,co(t))}var fa={code:ao,name:ua,encode:co,digest:la};var Zr={};Y(Zr,{sha256:()=>ha,sha512:()=>pa});var da=20;function Qr({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Wr(t,e,r,n,o)}var Wr=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??da,this.maxDigestLength=i}digest(e,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(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?uo(n,this.code,r?.truncate):n.then(o=>uo(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function uo(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return ze(e,t)}function fo(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var ha=Qr({name:"sha2-256",code:18,encode:fo("SHA-256")}),pa=Qr({name:"sha2-512",code:19,encode:fo("SHA-512")});var en={...Xr,...Kr,...Yr,...zr,...qr,...Ur,...Dr,...Lr,...Gr,...Hr},tl={...Zr,...Jr};function po(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var ho=po("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),tn=po("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=ce(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),ma={utf8:ho,"utf-8":ho,hex:en.base16,latin1:tn,ascii:tn,binary:tn,...en},Vt=ma;function z(t,e="utf8"){let r=Vt[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function rn(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return ce(s);o+s>e&&(n=ce(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Fe=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function nn(){}var sn=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},ga=rn();function ya(t){return globalThis.Buffer!=null?ce(t):ga(t)}var dt=class{len;head;tail;states;constructor(){this.len=0,this.head=new Fe(nn,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Fe(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new an((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Ot,10,X.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=X.fromBigInt(e);return this._push(Ot,r.length(),r)}uint64Number(e){return this._push(Xn,ut(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=X.fromBigInt(e).zzEncode();return this._push(Ot,r.length(),r)}sint64Number(e){let r=X.fromNumber(e).zzEncode();return this._push(Ot,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(on,1,e?1:0)}fixed32(e){return this._push(ft,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=X.fromBigInt(e);return this._push(ft,4,r.lo)._push(ft,4,r.hi)}fixed64Number(e){let r=X.fromNumber(e);return this._push(ft,4,r.lo)._push(ft,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Qn,4,e)}double(e){return this._push(eo,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(on,1,0):this.uint32(r)._push(ba,r,e)}string(e){let r=no(e);return r!==0?this.uint32(r)._push(Vr,r,e):this._push(on,1,0)}fork(){return this.states=new sn(this),this.head=this.tail=new Fe(nn,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 Fe(nn,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=ya(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function on(t,e,r){e[r]=t&255}function xa(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var an=class extends Fe{next;constructor(e,r){super(xa,e,r),this.next=void 0}};function Ot(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function ft(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function ba(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(dt.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(wa,e,t),this},dt.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Ea,e,t),this});function wa(t,e,r){e.set(t,r)}function Ea(t,e,r){t.length<40?Vr(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(z(t),r)}function cn(){return new dt}function Ue(t,e){let r=cn();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*De(t,e,r){let n=lt(t);yield*e.stream(n,void 0,"$",r)}var zt={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function qt(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function un(t){function e(i){if(t[i.toString()]==null)throw new Error("Invalid enum value");return t[i]}let r=function(s,a){let u=e(s);a.int32(u)},n=function(s){let a=s.int32();return e(a)},o=function*(s){let a=s.int32();yield e(a)};return qt("enum",zt.VARINT,r,n,o)}function Le(t,e,r){return qt("message",zt.LENGTH_DELIMITED,t,e,r)}var V;(function(t){let e;(function(a){a.EOL="EOL"})(e=t.ValidityType||(t.ValidityType={}));let r;(function(a){a[a.EOL=0]="EOL"})(r||(r={})),(function(a){a.codec=()=>un(r)})(e=t.ValidityType||(t.ValidityType={}));let n;t.codec=()=>(n==null&&(n=Le((a,u,f={})=>{f.lengthDelimited!==!1&&u.fork(),a.value!=null&&(u.uint32(10),u.bytes(a.value)),a.signatureV1!=null&&(u.uint32(18),u.bytes(a.signatureV1)),a.validityType!=null&&(u.uint32(24),t.ValidityType.codec().encode(a.validityType,u)),a.validity!=null&&(u.uint32(34),u.bytes(a.validity)),a.sequence!=null&&(u.uint32(40),u.uint64(a.sequence)),a.ttl!=null&&(u.uint32(48),u.uint64(a.ttl)),a.publicKey!=null&&(u.uint32(58),u.bytes(a.publicKey)),a.signatureV2!=null&&(u.uint32(66),u.bytes(a.signatureV2)),a.data!=null&&(u.uint32(74),u.bytes(a.data)),f.lengthDelimited!==!1&&u.ldelim()},(a,u,f={})=>{let l={},p=u==null?a.len:a.pos+u;for(;a.pos<p;){let m=a.uint32();switch(m>>>3){case 1:{l.value=a.bytes();break}case 2:{l.signatureV1=a.bytes();break}case 3:{l.validityType=t.ValidityType.codec().decode(a);break}case 4:{l.validity=a.bytes();break}case 5:{l.sequence=a.uint64();break}case 6:{l.ttl=a.uint64();break}case 7:{l.publicKey=a.bytes();break}case 8:{l.signatureV2=a.bytes();break}case 9:{l.data=a.bytes();break}default:{a.skipType(m&7);break}}}return l},function*(a,u,f,l={}){let p=u==null?a.len:a.pos+u;for(;a.pos<p;){let m=a.uint32();switch(m>>>3){case 1:{yield{field:`${f}.value`,value:a.bytes()};break}case 2:{yield{field:`${f}.signatureV1`,value:a.bytes()};break}case 3:{yield{field:`${f}.validityType`,value:t.ValidityType.codec().decode(a)};break}case 4:{yield{field:`${f}.validity`,value:a.bytes()};break}case 5:{yield{field:`${f}.sequence`,value:a.uint64()};break}case 6:{yield{field:`${f}.ttl`,value:a.uint64()};break}case 7:{yield{field:`${f}.publicKey`,value:a.bytes()};break}case 8:{yield{field:`${f}.signatureV2`,value:a.bytes()};break}case 9:{yield{field:`${f}.data`,value:a.bytes()};break}default:{a.skipType(m&7);break}}}})),n);function o(a){return Ue(a,t.codec())}t.encode=o;function i(a,u){return ke(a,t.codec(),u)}t.decode=i;function s(a,u){return De(a,t.codec(),u)}t.stream=s})(V||(V={}));function Kt(t,e){let r=e.map((n,o)=>({record: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===V.ValidityType.EOL&&o.record.validityType===V.ValidityType.EOL){let a=ln.default.fromString(n.record.validity).toDate(),u=ln.default.fromString(o.record.validity).toDate();if(a.getTime()>u.getTime())return-1;if(a.getTime()<u.getTime())return 1}return 0}),r[0].index}function Sa(t){return t?.buffer instanceof ArrayBuffer}function mo(t){if(Sa(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Ht(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=ce(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return mo(r)}function ht(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function jt(t){return t==null?!1:typeof t.type=="string"&&typeof t.code=="number"&&typeof t.verify=="function"}var me=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};function Ta(t){return typeof t?.handleEvent=="function"}function va(t){return(t!==!0&&t!==!1&&t?.once)??!1}var Gt=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let o=va(n);super.addEventListener(e,s=>{if(o){let a=this.#e.get(s.type);a!=null&&(a=a.filter(({callback:u})=>u!==r),this.#e.set(s.type,a))}Ta(r)?r.handleEvent(s):r(s)},n);let i=this.#e.get(e);i==null&&(i=[],this.#e.set(e,i)),i.push({callback:r,once:o})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==r),this.#e.set(e,o))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var Ca=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged"];function fn(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=Ia(t);return r||"Object"}function Ia(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Ca.includes(e))return e}var c=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};c.uint=new c(0,"uint",!0);c.negint=new c(1,"negint",!0);c.bytes=new c(2,"bytes",!0);c.string=new c(3,"string",!0);c.array=new c(4,"array",!1);c.map=new c(5,"map",!1);c.tag=new c(6,"tag",!1);c.float=new c(7,"float",!0);c.false=new c(7,"false",!0);c.true=new c(7,"true",!0);c.null=new c(7,"null",!0);c.undefined=new c(7,"undefined",!0);c.break=new c(7,"break",!0);var h=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var pt=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Aa=new TextEncoder;function Yt(t){return pt&&globalThis.Buffer.isBuffer(t)}function mt(t){return t instanceof Uint8Array?Yt(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Na=24,ka=200,Xt=pt?t=>t.length>=Na?globalThis.Buffer.from(t):go(t):t=>t.length>=ka?Aa.encode(t):go(t),ue=t=>Uint8Array.from(t),yo=pt?(t,e,r)=>Yt(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),xo=pt?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),mt(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let o of t)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},bo=pt?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function Jt(t,e){if(Yt(t)&&Yt(e))return t.compare(e);for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function go(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}var Fa=256,gt=class{constructor(e=Fa){this.chunkSize=e,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(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,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)}e.length<64&&e.length<this.chunkSize?(r=bo(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=yo(n,0,this.cursor)}else r=xo(this.chunks,this.cursor);return e&&this.reset(),r}},Wt=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var y="CBOR decode error:",Qt="CBOR encode error:",yt=[];yt[23]=1;yt[24]=2;yt[25]=3;yt[26]=5;yt[27]=9;function ge(t,e,r){if(t.length-e<r)throw new Error(`${y} not enough data for type`)}var $=[24,256,65536,4294967296,BigInt("18446744073709551616")];function J(t,e,r){ge(t,e,1);let n=t[e];if(r.strict===!0&&n<$[0])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function W(t,e,r){ge(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<$[1])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function Q(t,e,r){ge(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<$[2])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function Z(t,e,r){ge(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<$[3])throw new Error(`${y} 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(`${y} integers outside of the safe integer range are not supported`)}function wo(t,e,r,n){return new h(c.uint,J(t,e+1,n),2)}function Eo(t,e,r,n){return new h(c.uint,W(t,e+1,n),3)}function So(t,e,r,n){return new h(c.uint,Q(t,e+1,n),5)}function To(t,e,r,n){return new h(c.uint,Z(t,e+1,n),9)}function te(t,e){return U(t,0,e.value)}function U(t,e,r){if(r<$[0]){let n=Number(r);t.push([e|n])}else if(r<$[1]){let n=Number(r);t.push([e|24,n])}else if(r<$[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<$[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<$[4]){let o=[e|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,t.push(o)}else throw new Error(`${y} encountered BigInt larger than allowable range`)}}te.encodedSize=function(e){return U.encodedSize(e.value)};U.encodedSize=function(e){return e<$[0]?1:e<$[1]?2:e<$[2]?3:e<$[3]?5:9};te.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function vo(t,e,r,n){return new h(c.negint,-1-J(t,e+1,n),2)}function Co(t,e,r,n){return new h(c.negint,-1-W(t,e+1,n),3)}function Io(t,e,r,n){return new h(c.negint,-1-Q(t,e+1,n),5)}var dn=BigInt(-1),Ao=BigInt(1);function No(t,e,r,n){let o=Z(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new h(c.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${y} integers outside of the safe integer range are not supported`);return new h(c.negint,dn-BigInt(o),9)}function Zt(t,e){let r=e.value,n=typeof r=="bigint"?r*dn-Ao:r*-1-1;U(t,e.type.majorEncoded,n)}Zt.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*dn-Ao:r*-1-1;return n<$[0]?1:n<$[1]?2:n<$[2]?3:n<$[3]?5:9};Zt.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function xt(t,e,r,n){ge(t,e,r+n);let o=t.slice(e+r,e+r+n);return new h(c.bytes,o,r+n)}function ko(t,e,r,n){return xt(t,e,1,r)}function Fo(t,e,r,n){return xt(t,e,2,J(t,e+1,n))}function Uo(t,e,r,n){return xt(t,e,3,W(t,e+1,n))}function Do(t,e,r,n){return xt(t,e,5,Q(t,e+1,n))}function Lo(t,e,r,n){let o=Z(t,e+1,n);if(typeof o=="bigint")throw new Error(`${y} 64-bit integer bytes lengths not supported`);return xt(t,e,9,o)}function er(t){return t.encodedBytes===void 0&&(t.encodedBytes=c.equals(t.type,c.string)?Xt(t.value):t.value),t.encodedBytes}function Ge(t,e){let r=er(e);U(t,e.type.majorEncoded,r.length),t.push(r)}Ge.encodedSize=function(e){let r=er(e);return U.encodedSize(r.length)+r.length};Ge.compareTokens=function(e,r){return Da(er(e),er(r))};function Da(t,e){return t.length<e.length?-1:t.length>e.length?1:Jt(t,e)}var _o=new TextDecoder,_a=32;function Ra(t,e,r){if(r-e<_a){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return _o.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return _o.decode(t.subarray(e,r))}function bt(t,e,r,n,o){let i=r+n;ge(t,e,i);let s=new h(c.string,Ra(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function Ro(t,e,r,n){return bt(t,e,1,r,n)}function Bo(t,e,r,n){return bt(t,e,2,J(t,e+1,n),n)}function Mo(t,e,r,n){return bt(t,e,3,W(t,e+1,n),n)}function Po(t,e,r,n){return bt(t,e,5,Q(t,e+1,n),n)}function $o(t,e,r,n){let o=Z(t,e+1,n);if(typeof o=="bigint")throw new Error(`${y} 64-bit integer string lengths not supported`);return bt(t,e,9,o,n)}var Vo=Ge;function Ye(t,e,r,n){return new h(c.array,n,r)}function Oo(t,e,r,n){return Ye(t,e,1,r)}function zo(t,e,r,n){return Ye(t,e,2,J(t,e+1,n))}function qo(t,e,r,n){return Ye(t,e,3,W(t,e+1,n))}function Ko(t,e,r,n){return Ye(t,e,5,Q(t,e+1,n))}function Ho(t,e,r,n){let o=Z(t,e+1,n);if(typeof o=="bigint")throw new Error(`${y} 64-bit integer array lengths not supported`);return Ye(t,e,9,o)}function jo(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return Ye(t,e,1,1/0)}function tr(t,e){U(t,c.array.majorEncoded,e.value)}tr.compareTokens=te.compareTokens;tr.encodedSize=function(e){return U.encodedSize(e.value)};function Xe(t,e,r,n){return new h(c.map,n,r)}function Go(t,e,r,n){return Xe(t,e,1,r)}function Yo(t,e,r,n){return Xe(t,e,2,J(t,e+1,n))}function Xo(t,e,r,n){return Xe(t,e,3,W(t,e+1,n))}function Jo(t,e,r,n){return Xe(t,e,5,Q(t,e+1,n))}function Wo(t,e,r,n){let o=Z(t,e+1,n);if(typeof o=="bigint")throw new Error(`${y} 64-bit integer map lengths not supported`);return Xe(t,e,9,o)}function Qo(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return Xe(t,e,1,1/0)}function rr(t,e){U(t,c.map.majorEncoded,e.value)}rr.compareTokens=te.compareTokens;rr.encodedSize=function(e){return U.encodedSize(e.value)};function Zo(t,e,r,n){return new h(c.tag,r,1)}function ei(t,e,r,n){return new h(c.tag,J(t,e+1,n),2)}function ti(t,e,r,n){return new h(c.tag,W(t,e+1,n),3)}function ri(t,e,r,n){return new h(c.tag,Q(t,e+1,n),5)}function ni(t,e,r,n){return new h(c.tag,Z(t,e+1,n),9)}function nr(t,e){U(t,c.tag.majorEncoded,e.value)}nr.compareTokens=te.compareTokens;nr.encodedSize=function(e){return U.encodedSize(e.value)};var hn=20,pn=21,mn=22,gn=23;function oi(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${y} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new h(c.null,null,1):new h(c.undefined,void 0,1)}function ii(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return new h(c.break,void 0,1)}function yn(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${y} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${y} Infinity values are not supported`)}return new h(c.float,t,e)}function si(t,e,r,n){return yn(xn(t,e+1),3,n)}function ai(t,e,r,n){return yn(bn(t,e+1),5,n)}function ci(t,e,r,n){return yn(di(t,e+1),9,n)}function wt(t,e,r){let n=e.value;if(n===!1)t.push([c.float.majorEncoded|hn]);else if(n===!0)t.push([c.float.majorEncoded|pn]);else if(n===null)t.push([c.float.majorEncoded|mn]);else if(n===void 0)t.push([c.float.majorEncoded|gn]);else{let o,i=!1;(!r||r.float64!==!0)&&(li(n),o=xn(ie,1),n===o||Number.isNaN(n)?(ie[0]=249,t.push(ie.slice(0,3)),i=!0):(fi(n),o=bn(ie,1),n===o&&(ie[0]=250,t.push(ie.slice(0,5)),i=!0))),i||(Va(n),o=di(ie,1),ie[0]=251,t.push(ie.slice(0,9)))}}wt.encodedSize=function(e,r){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){li(n);let o=xn(ie,1);if(n===o||Number.isNaN(n))return 3;if(fi(n),o=bn(ie,1),n===o)return 5}return 9};var ui=new ArrayBuffer(9),re=new DataView(ui,1),ie=new Uint8Array(ui,0);function li(t){if(t===1/0)re.setUint16(0,31744,!1);else if(t===-1/0)re.setUint16(0,64512,!1);else if(Number.isNaN(t))re.setUint16(0,32256,!1);else{re.setFloat32(0,t);let e=re.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)re.setUint16(0,31744,!1);else if(r===0)re.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?re.setUint16(0,0):o<-14?re.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):re.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function xn(t,e){if(t.length-e<2)throw new Error(`${y} not enough data for float16`);let r=(t[e]<<8)+t[e+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 fi(t){re.setFloat32(0,t,!1)}function bn(t,e){if(t.length-e<4)throw new Error(`${y} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Va(t){re.setFloat64(0,t,!1)}function di(t,e){if(t.length-e<8)throw new Error(`${y} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}wt.compareTokens=te.compareTokens;function A(t,e,r){throw new Error(`${y} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function or(t){return()=>{throw new Error(`${y} ${t}`)}}var d=[];for(let t=0;t<=23;t++)d[t]=A;d[24]=wo;d[25]=Eo;d[26]=So;d[27]=To;d[28]=A;d[29]=A;d[30]=A;d[31]=A;for(let t=32;t<=55;t++)d[t]=A;d[56]=vo;d[57]=Co;d[58]=Io;d[59]=No;d[60]=A;d[61]=A;d[62]=A;d[63]=A;for(let t=64;t<=87;t++)d[t]=ko;d[88]=Fo;d[89]=Uo;d[90]=Do;d[91]=Lo;d[92]=A;d[93]=A;d[94]=A;d[95]=or("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)d[t]=Ro;d[120]=Bo;d[121]=Mo;d[122]=Po;d[123]=$o;d[124]=A;d[125]=A;d[126]=A;d[127]=or("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)d[t]=Oo;d[152]=zo;d[153]=qo;d[154]=Ko;d[155]=Ho;d[156]=A;d[157]=A;d[158]=A;d[159]=jo;for(let t=160;t<=183;t++)d[t]=Go;d[184]=Yo;d[185]=Xo;d[186]=Jo;d[187]=Wo;d[188]=A;d[189]=A;d[190]=A;d[191]=Qo;for(let t=192;t<=215;t++)d[t]=Zo;d[216]=ei;d[217]=ti;d[218]=ri;d[219]=ni;d[220]=A;d[221]=A;d[222]=A;d[223]=A;for(let t=224;t<=243;t++)d[t]=or("simple values are not supported");d[244]=A;d[245]=A;d[246]=A;d[247]=oi;d[248]=or("simple values are not supported");d[249]=si;d[250]=ai;d[251]=ci;d[252]=A;d[253]=A;d[254]=A;d[255]=ii;var se=[];for(let t=0;t<24;t++)se[t]=new h(c.uint,t,1);for(let t=-1;t>=-24;t--)se[31-t]=new h(c.negint,t,1);se[64]=new h(c.bytes,new Uint8Array(0),1);se[96]=new h(c.string,"",1);se[128]=new h(c.array,0,1);se[160]=new h(c.map,0,1);se[244]=new h(c.false,!1,1);se[245]=new h(c.true,!0,1);se[246]=new h(c.null,null,1);function wn(t){switch(t.type){case c.false:return ue([244]);case c.true:return ue([245]);case c.null:return ue([246]);case c.bytes:return t.value.length?void 0:ue([64]);case c.string:return t.value===""?ue([96]):void 0;case c.array:return t.value===0?ue([128]):void 0;case c.map:return t.value===0?ue([160]):void 0;case c.uint:return t.value<24?ue([Number(t.value)]):void 0;case c.negint:if(t.value>=-24)return ue([31-Number(t.value)])}}var za={float64:!1,mapSorter:Ha,quickEncodeToken:wn},yi=Object.freeze({float64:!0,mapSorter:ja,quickEncodeToken:wn});function qa(){let t=[];return t[c.uint.major]=te,t[c.negint.major]=Zt,t[c.bytes.major]=Ge,t[c.string.major]=Vo,t[c.array.major]=tr,t[c.map.major]=rr,t[c.tag.major]=nr,t[c.float.major]=wt,t}var We=qa(),ir=new gt,St=class t{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${Qt} object contains circular references`);return new t(r,e)}},Se={null:new h(c.null,null),undefined:new h(c.undefined,void 0),true:new h(c.true,!0),false:new h(c.false,!1),emptyArray:new h(c.array,0),emptyMap:new h(c.map,0)},le={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new h(c.float,t):t>=0?new h(c.uint,t):new h(c.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new h(c.uint,t):new h(c.negint,t)},Uint8Array(t,e,r,n){return new h(c.bytes,t)},string(t,e,r,n){return new h(c.string,t)},boolean(t,e,r,n){return t?Se.true:Se.false},null(t,e,r,n){return Se.null},undefined(t,e,r,n){return Se.undefined},ArrayBuffer(t,e,r,n){return new h(c.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new h(c.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Se.emptyArray,new h(c.break)]:Se.emptyArray;n=St.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=Je(s,r,n);return r.addBreakTokens?[new h(c.array,t.length),o,new h(c.break)]:[new h(c.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length,a;if(s){a=new Array(s),n=St.createCheck(n,t);let u=!o&&r.ignoreUndefinedProperties,f=0;for(let l of i){let p=o?t.get(l):t[l];u&&p===void 0||(a[f++]=[Je(l,r,n),Je(p,r,n)])}f<s&&(a.length=f)}return a?.length?(Ka(a,r),r.addBreakTokens?[new h(c.map,a.length),a,new h(c.break)]:[new h(c.map,a.length),a]):r.addBreakTokens===!0?[Se.emptyMap,new h(c.break)]:Se.emptyMap},Tagged(t,e,r,n){return[new h(c.tag,t.tag),Je(t.value,r,n)]}};le.Map=le.Object;le.Buffer=le.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))le[`${t}Array`]=le.DataView;function Je(t,e={},r){let n=fn(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||le[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=le[n];if(!i)throw new Error(`${Qt} unsupported type: ${n}`);return i(t,n,e,r)}function Ka(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Ha(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=We[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function ja(t,e){if(t[0]instanceof h&&e[0]instanceof h){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=hi(r.value)),n._keyBytes||(n._keyBytes=hi(n.value)),Jt(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function hi(t){return bi(t,We,yi)}function Et(t,e,r,n){if(Array.isArray(e))for(let o of e)Et(t,o,r,n);else r[e.type.major](t,e,n)}var pi=c.uint.majorEncoded,mi=c.negint.majorEncoded,Ga=c.bytes.majorEncoded,Ya=c.string.majorEncoded,gi=c.array.majorEncoded,Xa=c.float.majorEncoded|hn,Ja=c.float.majorEncoded|pn,Wa=c.float.majorEncoded|mn,Qa=c.float.majorEncoded|gn,Za=BigInt(-1),ec=BigInt(1);function tc(t){return t.addBreakTokens!==!0}function xi(t,e,r,n){let o=fn(e),i=r.typeEncoders&&r.typeEncoders[o];if(i){let s=i(e,o,r,n);if(s!=null){Et(t,s,We,r);return}}switch(o){case"null":t.push([Wa]);return;case"undefined":t.push([Qa]);return;case"boolean":t.push([e?Ja:Xa]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?wt(t,new h(c.float,e),r):e>=0?U(t,pi,e):U(t,mi,e*-1-1);return;case"bigint":e>=BigInt(0)?U(t,pi,e):U(t,mi,e*Za-ec);return;case"string":{let s=Xt(e);U(t,Ya,s.length),t.push(s);return}case"Uint8Array":U(t,Ga,e.length),t.push(e);return;case"Array":if(!e.length){t.push([gi]);return}n=St.createCheck(n,e),U(t,gi,e.length);for(let s of e)xi(t,s,r,n);return;case"Object":case"Map":{let s=le.Object(e,o,r,n);Et(t,s,We,r)}return;default:{let s=le[o];if(!s)throw new Error(`${Qt} unsupported type: ${o}`);let a=s(e,o,r,n);Et(t,a,We,r)}}}function bi(t,e,r,n){let o=n instanceof Uint8Array,i=o?new Wt(n):ir,s=Je(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let u=e[s.type.major];if(u.encodedSize){let f=u.encodedSize(s,r);if(o||(i=new gt(f)),u(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():mt(i.chunks[0])}}return i.reset(),Et(i,s,e,r),i.toBytes(!0)}function En(t,e){return e=Object.assign({},za,e),tc(e)?(ir.reset(),xi(ir,t,e,void 0),ir.toBytes(!0)):bi(t,We,e)}var rc={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},sr=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=se[e];if(r===void 0){let n=d[e];if(!n)throw new Error(`${y} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},Te=Symbol.for("DONE"),Qe=Symbol.for("BREAK");function nc(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=ve(e,r);if(i===Qe){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed array`)}if(i===Te)throw new Error(`${y} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function oc(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let u=ve(e,r);if(u===Qe){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed map`)}if(u===Te)throw new Error(`${y} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof u!="string")throw new Error(`${y} non-string keys not supported (got ${typeof u})`);if(o&&(n&&s.has(u)||!n&&Object.hasOwn(i,u)))throw new Error(`${y} found repeat map key "${u}"`);let f=ve(e,r);if(f===Te)throw new Error(`${y} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(u,f):i[u]=f}return n?s:i}function*ic(t,e,r){for(let n=0;n<t.value;n++){let o=ve(e,r);if(o===Qe){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed map`)}if(o===Te)throw new Error(`${y} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let i=ve(e,r);if(i===Te)throw new Error(`${y} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,i]}}function sc(t,e){let r=!1,n=function(){if(r)throw new Error(`${y} tag decode() may only be called once`);r=!0;let o=ve(t,e);if(o===Te)throw new Error(`${y} tag content missing`);if(o===Qe)throw new Error(`${y} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${y} tag decode() may only be called once`);r=!0;let o=t.next();if(!c.equals(o.type,c.map))throw new Error(`${y} entries() requires map content, got ${o.type.name}`);let i=[];for(let s of ic(o,t,e))i.push(s);return i},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function ve(t,e){if(t.done())return Te;let r=t.next();if(c.equals(r.type,c.break))return Qe;if(r.type.terminal)return r.value;if(c.equals(r.type,c.array))return nc(r,t,e);if(c.equals(r.type,c.map))return oc(r,t,e);if(c.equals(r.type,c.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=sc(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${y} tag decoder must call decode() or entries()`);return o}throw new Error(`${y} tag not supported (${r.value})`)}throw new Error("unsupported")}function wi(t,e){if(!(t instanceof Uint8Array))throw new Error(`${y} data to decode must be a Uint8Array`);e=Object.assign({},rc,e);let r=mt(t),n=e.tokenizer||new sr(r,e),o=ve(n,e);if(o===Te)throw new Error(`${y} did not find any content to decode`);if(o===Qe)throw new Error(`${y} got unexpected break`);return[o,t.subarray(n.pos())]}function Sn(t,e){let[r,n]=wi(t,e);if(n.length>0)throw new Error(`${y} too many terminals, data makes no sense`);return r}var ar=class t{constructor(e,r){if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=e,this.value=r}static decoder(e){return r=>new t(e,r())}static preserve(...e){let r={};for(let n of e)r[n]=t.decoder(n);return r}};Object.defineProperty(ar.prototype,Symbol.toStringTag,{value:"Tagged"});function Re(t,e="utf8"){let r=Vt[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var ye="/",Ei=new TextEncoder().encode(ye),cr=Ei[0],Ze=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=z(e);else if(e instanceof Uint8Array)this._buf=e;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]!==cr)throw new Error("Invalid key")}toString(e="utf8"){return Re(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(ye))}static random(){return new t(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new t(e):typeof e.uint8Array=="function"?new t(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Ei),this._buf[0]!==cr){let e=new Uint8Array(this._buf.byteLength+1);e.fill(cr,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===cr;)this._buf=this._buf.subarray(0,-1)}less(e){let r=this.list(),n=e.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 t.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(ye).slice(1)}type(){return cc(this.baseNamespace())}name(){return uc(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(ye)||(e+=ye),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(ye):new t(e.slice(0,-1).join(ye))}child(e){return this.toString()===ye?e:e.toString()===ye?this:new t(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return t.withNamespaces([...this.namespaces(),...lc(e.map(r=>r.namespaces()))])}};function cc(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function uc(t){let e=t.split(":");return e[e.length-1]}function lc(t){return[].concat(...t)}var Ti=114;var dc=1024*10,vi=z("/ipns/"),Ci="/ipns/";function hc(t,e){return t.code===e}var ur="/dht/record/",pc="/ipns/metadata/";function Tt(t){return new Ze(ur+Re(t,"base32"),!1)}function lr(t){return new Ze(pc+Re(t,"base32"),!1)}function Ii(t,e){let r=Date.now(),n=e.getTime()+1728e5,o=new Date(t.validity).getTime();return n-r<864e5||o-r<864e5}function Ai(t,e,r){let n=z(e),o=z(t);return Ht([o,r,n],o.byteLength+r.byteLength+n.byteLength)}function fr(t){let e=z("ipns-signature:");return Ht([e,t])}function et(t){let e=t.publicKey?.toProtobuf();return t.publicKey?.toMultihash().code===0&&(e=void 0),"signatureV1"in t?V.encode({value:z(t.value),signatureV1:t.signatureV1,validityType:t.validityType,validity:z(t.validity),sequence:t.sequence,ttl:t.ttl,publicKey:e,signatureV2:t.signatureV2,data:t.data}):V.encode({publicKey:e,signatureV2:t.signatureV2,data:t.data})}function Si(t){try{return`/ipfs/${ae.decode(t)}`}catch{}return Re(t)}async function fe(t,e,r,n){if(e.byteLength>dc)throw new Bt("The record is too large");let o=V.decode(e);if(o.signatureV2==null||o.data==null)throw new ne("Missing data or signatureV2");let i=ki(o.data),s=Re(i.Validity),a,u=mc(t);if(hc(u,0)&&(a=await r.loadPublicKeyFromProtobuf(u.digest,n)),a==null&&o.publicKey!=null&&(a=await r.loadPublicKeyFromProtobuf(o.publicKey,n)),a==null)throw new je("Could not extract public key from IPNS record or routing key");if(o.value!=null&&o.signatureV1!=null)return yc(o),{value:Si(i.Value),validityType:V.ValidityType.EOL,validity:s,sequence:i.Sequence,ttl:i.TTL,publicKey:a,signatureV1:o.signatureV1,signatureV2:o.signatureV2,data:o.data,bytes:e};if(o.signatureV2!=null)return{value:Si(i.Value),validityType:V.ValidityType.EOL,validity:s,sequence:i.Sequence,ttl:i.TTL,publicKey:a,signatureV2:o.signatureV2,data:o.data,bytes:e};throw new Error("invalid record: does not include signatureV1 or signatureV2")}function vt(t){return Ht([vi,t.bytes])}function mc(t){return st(t.slice(vi.length))}function Ni(t,e,r,n,o){let i;if(e===V.ValidityType.EOL)i=0;else throw new Ae("The validity type is unsupported");let s={Value:z(t),Validity:r,ValidityType:i,Sequence:n,TTL:o};return En(s)}function ki(t){let e=Sn(t);if(e.ValidityType===0)e.ValidityType=V.ValidityType.EOL;else throw new Ae("The validity type is unsupported");return Number.isInteger(e.Sequence)&&(e.Sequence=BigInt(e.Sequence)),Number.isInteger(e.TTL)&&(e.TTL=BigInt(e.TTL)),e}function Fi(t){if(t!=null){if(jt(t))return`/ipns/${t.toCID().toV1().toString(ee)}`;let e=Ui(t);if(e!=null)return e.code===Ti?`/ipns/${e.toV1().toString(ee)}`:`/ipfs/${e.toV1()}`;if(xc(t))return`/ipns/${ee.encode(t.bytes)}`;let r=t.toString().trim();if(r.startsWith("/ipfs/")){let[,n,...o]=r.split("/").filter(i=>i.trim()!=="");return`/ipfs/${ae.parse(n).toV1()}${o.length>0?`/${o.join("/")}`:""}`}if(r.startsWith("/")&&r.length>1)return r}throw new He("Value must be a valid content path starting with /")}function gc(t){return typeof t.code=="number"&&t.digest instanceof Uint8Array&&typeof t.size=="number"&&t.bytes instanceof Uint8Array}function Ct(t){if(t!=null){if(jt(t))return{digest:t.toMultihash(),path:"/"};let e=Ui(t);if(e!=null){if(e.code!==Ti)throw new He("CIDs must have the `libp2p-key` codec");return{digest:e.multihash,path:"/"}}if(gc(t))return{digest:t,path:"/"};if(t=t.toString(),t.startsWith("/ipns/")){let[,,r,...n]=t.split("/"),o=ee;(r.startsWith("1")||r.startsWith("Q"))&&(r=`z${r}`,o=H);let i=o.decode(r),s;try{s=ae.decode(i).multihash}catch{s=st(i)}return{digest:s,path:`/${n.join("/")}`}}}throw new He("Value must be a valid IPNS path starting with /")}function yc(t){if(t.data==null)throw new Mt("Record data is missing");let e=ki(t.data);if(!ht(e.Value,t.value??new Uint8Array(0)))throw new ne('Field "value" did not match between protobuf and CBOR');if(!ht(e.Validity,t.validity??new Uint8Array(0)))throw new ne('Field "validity" did not match between protobuf and CBOR');if(e.ValidityType!==t.validityType)throw new ne('Field "validityType" did not match between protobuf and CBOR');if(e.Sequence!==t.sequence)throw new ne('Field "sequence" did not match between protobuf and CBOR');if(e.TTL!==t.ttl)throw new ne('Field "ttl" did not match between protobuf and CBOR')}function xc(t){return t.bytes instanceof Uint8Array}function bc(t){return typeof t?.toCID=="function"}function Ui(t){if(bc(t))return t.toCID();try{return ae.parse(t)}catch{}return ae.asCID(t)}var Di=Ir(Pt(),1);async function It(t,e){if(t.publicKey==null)throw new je("The record had no public key associated with it");let r;try{let n=fr(t.data);r=await t.publicKey.verify(n,t.signatureV2,e)}catch{r=!1}if(!r)throw new ne("Record signature verification failed");if(t.validityType===V.ValidityType.EOL){if(Di.default.fromString(t.validity).toDate().getTime()<Date.now())throw new Rt("record has expired")}else if(t.validityType!=null)throw new Ae("The validity type is unsupported")}var tt=class{routers;localStore;log;keychain;constructor(e,r){this.log=e.logger.forComponent("helia:ipns"),this.localStore=r.localStore,this.routers=r.routers,this.keychain=e.keychain}async*resolve(e,r={}){let{digest:n}=Ct(e);for(;;){let o=vt(n),i=await this.#e(o,r);if(yield{record:i},!i.value.startsWith(Ci))break;({digest:n}=Ct(i.value))}}async#e(e,r={}){let n=[];if(await this.localStore.has(e,r))if(this.log("record is present in the cache"),r.nocache!==!0)try{let{record:u,created:f}=await this.localStore.get(e,r);this.log("record retrieved from cache");let l=await fe(e,u,this.keychain,r);await It(l,r),this.log("record was valid");let p=Number((l.ttl??Ke)/1000000n);if(f.getTime()+p>Date.now())return this.log("record TTL was valid"),l;if(r.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),l;this.log("record TTL has been reached, searching routing for updates"),n.push(l)}catch(u){this.log("cached record was invalid - %e",u),await this.localStore.delete(e,r)}else this.log("ignoring local cache due to nocache=true option");if(r.offline===!0)throw new ct("Record was not present in the cache or has expired");this.log("did not have record locally");let i=0,s=[];if(await Promise.all(this.routers.map(async u=>{let f;try{f=await u.get(e,{...r,validate:!1})}catch(l){this.log.error("error finding IPNS record using router %s - %e",u.toString(),l),s.push(l);return}try{let l=await fe(e,f,this.keychain,r);await It(l,r),n.push(l)}catch(l){i++,this.log.error("error validating IPNS record from router %s - %e",u.toString(),l)}})),n.length===0)throw i>0?new Lt(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`):new ct("Could not find record for routing key");let a=n[Kt(e,n)];return await this.localStore.put(e,a.bytes,r),a}};var j=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};function dr(t,e){if(typeof t=="string")return wc(t);if(typeof t=="number")return Tc(t,e);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}function wc(t){if(typeof t!="string"||t.length===0||t.length>100)throw new Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(t)}`);let e=/^(?<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(t);if(!e?.groups)return NaN;let{value:r,unit:n="ms"}=e.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 new Error(`Unknown unit "${i}" provided to ms.parse(). value=${JSON.stringify(t)}`)}}function Ec(t){let e=Math.abs(t);return e>=315576e5?`${Math.round(t/315576e5)}y`:e>=26298e5?`${Math.round(t/26298e5)}mo`:e>=6048e5?`${Math.round(t/6048e5)}w`:e>=864e5?`${Math.round(t/864e5)}d`:e>=36e5?`${Math.round(t/36e5)}h`:e>=6e4?`${Math.round(t/6e4)}m`:e>=1e3?`${Math.round(t/1e3)}s`:`${t}ms`}function Sc(t){let e=Math.abs(t);return e>=315576e5?Be(t,e,315576e5,"year"):e>=26298e5?Be(t,e,26298e5,"month"):e>=6048e5?Be(t,e,6048e5,"week"):e>=864e5?Be(t,e,864e5,"day"):e>=36e5?Be(t,e,36e5,"hour"):e>=6e4?Be(t,e,6e4,"minute"):e>=1e3?Be(t,e,1e3,"second"):`${t} ms`}function Tc(t,e){if(typeof t!="number"||!Number.isFinite(t))throw new Error("Value provided to ms.format() must be of type number.");return e?.long?Sc(t):Ec(t)}function Be(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function Tn(t){r.debug=r,r.default=r,r.coerce=u,r.disable=i,r.enable=o,r.enabled=s,r.humanize=dr,r.destroy=f,Object.keys(t).forEach(l=>{r[l]=t[l]}),r.names=[],r.skips=[],r.formatters={};function e(l){let p=0;for(let m=0;m<l.length;m++)p=(p<<5)-p+l.charCodeAt(m),p|=0;return r.colors[Math.abs(p)%r.colors.length]}r.selectColor=e;function r(l,p){let m,w=null,S,E;function x(...T){if(!x.enabled)return;let k=x,F=Number(new Date),P=F-(m||F);k.diff=P,k.prev=m,k.curr=F,m=F,T[0]=r.coerce(T[0]),typeof T[0]!="string"&&T.unshift("%O");let B=0;T[0]=T[0].replace(/%([a-zA-Z%])/g,(R,g)=>{if(R==="%%")return"%";B++;let b=r.formatters[g];if(typeof b=="function"){let I=T[B];R=b.call(k,I),T.splice(B,1),B--}return R}),r.formatArgs.call(k,T),p?.onLog!=null&&p.onLog(...T),(k.log||r.log).apply(k,T)}return x.namespace=l,x.useColors=r.useColors(),x.color=r.selectColor(l),x.extend=n,x.destroy=r.destroy,Object.defineProperty(x,"enabled",{enumerable:!0,configurable:!1,get:()=>w!==null?w:(S!==r.namespaces&&(S=r.namespaces,E=r.enabled(l)),E),set:T=>{w=T}}),typeof r.init=="function"&&r.init(x),x}function n(l,p){let m=r(this.namespace+(typeof p>"u"?":":p)+l);return m.log=this.log,m}function o(l){r.save(l),r.namespaces=l,r.names=[],r.skips=[];let p,m=(typeof l=="string"?l:"").split(/[\s,]+/),w=m.length;for(p=0;p<w;p++)m[p]&&(l=m[p].replace(/\*/g,".*?"),l[0]==="-"?r.skips.push(new RegExp("^"+l.substr(1)+"$")):r.names.push(new RegExp("^"+l+"$")))}function i(){let l=[...r.names.map(a),...r.skips.map(a).map(p=>"-"+p)].join(",");return r.enable(""),l}function s(l){if(l[l.length-1]==="*")return!0;let p,m;for(p=0,m=r.skips.length;p<m;p++)if(r.skips[p].test(l))return!1;for(p=0,m=r.names.length;p<m;p++)if(r.names[p].test(l))return!0;return!1}function a(l){return l.toString().substring(2,l.toString().length-2).replace(/\.\*\?$/,"*")}function u(l){return l instanceof Error?l.stack??l.message:l}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 hr=Fc(),vc=["#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 Cc(){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 Ic(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+dr(this.diff),!this.useColors)return;let e="color: "+this.color;t.splice(1,0,e,"color: inherit");let r=0,n=0;t[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(r++,o==="%c"&&(n=r))}),t.splice(n,0,e)}var Ac=console.debug??console.log??(()=>{});function Nc(t){try{t?hr?.setItem("debug",t):hr?.removeItem("debug")}catch{}}function kc(){let t;try{t=hr?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function Fc(){try{return localStorage}catch{}}function Uc(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Li=Tn({formatArgs:Ic,save:Nc,load:kc,useColors:Cc,setupFormatters:Uc,colors:vc,storage:hr,log:Ac});var G=Li;G.formatters.b=t=>t==null?"undefined":H.baseEncode(t);G.formatters.t=t=>t==null?"undefined":be.baseEncode(t);G.formatters.m=t=>t==null?"undefined":jr.baseEncode(t);G.formatters.p=t=>t==null?"undefined":t.toString();G.formatters.c=t=>t==null?"undefined":t.toString();G.formatters.k=t=>t==null?"undefined":t.toString();G.formatters.a=t=>t==null?"undefined":t.toString();function _i(t,e=""){let r=Ri(t.message),n=Ri(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
4
4
  `).join(`
5
5
  ${e}`)}`:`${r}
6
6
  ${e}${n.split(`
7
7
  `).join(`
8
8
  ${e}`)}`:n!=null?`${n.split(`
9
9
  `).join(`
10
- ${e}`)}`:r!=null?`${r}`:`${t.toString()}`}function du(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function us(t,e=""){if(du(t)){let r=as(t,e);return t.errors.length>0?(e=`${e} `,r+=`
11
- ${e}${t.errors.map(n=>`${us(n,`${e}`)}`).join(`
10
+ ${e}`)}`:r!=null?`${r}`:`${t.toString()}`}function Dc(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function Bi(t,e=""){if(Dc(t)){let r=_i(t,e);return t.errors.length>0?(e=`${e} `,r+=`
11
+ ${e}${t.errors.map(n=>`${Bi(n,`${e}`)}`).join(`
12
12
  ${e}`)}`):r+=`
13
- ${e}[Error list was empty]`,r.trim()}return as(t,e)}X.formatters.e=t=>t==null?"undefined":us(t);function pu(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e}function Mn(t,e){let r=pu(`${t}:trace`);return X.enabled(`${t}:trace`)&&X.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=X(`${t}:trace`,e)),Object.assign(X(t,e),{error:X(`${t}:error`,e),trace:r,newScope:n=>Mn(`${t}:${n}`,e)})}function cs(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var ls=$r(jt(),1);var mu=Mn("ipns"),fs=300*1e9,gu="/ipns/",Pd=gu.length,hs={v1Compatible:!0,ttlNs:fs};async function Cr(t,e,r,n,i=hs){let o=new ls.default(Date.now()+Number(n)),s=O.ValidityType.EOL,a=BigInt(i.ttlNs??fs);return yu(t,e,r,s,o.toString(),a,i)}var yu=async(t,e,r,n,i,o,s=hs)=>{r=BigInt(r);let a=$(i),u=ts(e,n,a,r,o),f=Sr(u),l=await t.sign(f,s),p=wu(t.publicKey)?t.publicKey:void 0,m;if(s.v1Compatible===!0){let b=await xu(t,e,n,a);m={value:e,signatureV1:b,validity:i,validityType:n,sequence:r,ttl:o,signatureV2:l,data:u,publicKey:p}}else m={value:e,validity:i,validityType:n,sequence:r,ttl:o,signatureV2:l,data:u,publicKey:p};return m.bytes=nt(m),m},xu=async(t,e,r,n,i)=>{try{let o=es(e,r,n);return await t.sign(o,i)}catch(o){throw mu.error("record signature creation failed",o),new qt("Record signature creation failed")}};function wu(t){return t.toMultihash().code!==0}var Ar=class{routers;localStore;keychain;constructor(e,r){this.keychain=e.keychain,this.localStore=r.localStore,this.routers=r.routers}async publish(e,r,n={}){try{let i=await this.#e(e,n),o=i.publicKey.toMultihash(),s=kt(o),a=1n;if(await this.localStore.has(s,n)){let{record:m}=await this.localStore.get(s,n);a=(await pe(s,m,this.keychain,n)).sequence+1n}let u=n.ttl!=null?BigInt(n.ttl)*1000000n:je,f=n.lifetime??1728e5,l=await Cr(i,r,a,f,{...n,ttlNs:u}),p=nt(l);return n.offline===!0?await this.localStore.put(s,p,{...n,metadata:{keyName:e,lifetime:f}}):await Promise.all(this.routers.map(async m=>{await m.put(s,p,{...n,metadata:{keyName:e,lifetime:f}})})),{record:{...l,publicKey:i.publicKey},name:`/ipns/${i.publicKey.toCID().toString(ne)}`,publicKey:i.publicKey}}catch(i){throw n.onProgress?.(new Y("ipns:publish:error",i)),i}}async#e(e,r){try{return await this.keychain.exportKey(e,r)}catch(n){if(n.name==="NotFoundError")return this.keychain.generateKey(e,r);throw n}}async unpublish(e,r){let i=(await this.keychain.exportKey(e,r)).publicKey.toMultihash(),o=kt(i);await this.localStore.delete(o,r)}};function ot(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var vr=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},st=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new vr(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new vr(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Pn=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function ds(t={}){return Eu(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}},t)}function Eu(t,e){e=e??{};let r=e.onEnd,n=new st,i,o,s,a=ot(),u=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((x,T)=>{o=F=>{o=null,n.push(F);try{x(t(n))}catch(k){T(k)}return i}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=ot()})}},f=x=>o!=null?o(x):(n.push(x),i),l=x=>(n=new st,o!=null?o({error:x}):(n.push({error:x}),i)),p=x=>{if(s)return i;if(e?.objectMode!==!0&&x?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:x})},m=x=>s?i:(s=!0,x!=null?l(x):f({done:!0})),b=()=>(n=new st,m(),{done:!0}),S=x=>(m(x),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:u,return:b,throw:S,push:p,end:m,get readableLength(){return n.size},onEmpty:async x=>{let T=x?.signal;if(T?.throwIfAborted(),n.isEmpty())return;let F,k;T!=null&&(F=new Promise((P,B)=>{k=()=>{B(new Pn)},T.addEventListener("abort",k)}));try{await Promise.race([a.promise,F])}finally{k!=null&&T!=null&&T?.removeEventListener("abort",k)}}},r==null)return i;let E=i;return i={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(x){return E.throw(x),r!=null&&(r(x),r=void 0),{done:!0}},return(){return E.return(),r!=null&&(r(),r=void 0),{done:!0}},push:p,end(x){return E.end(x),r!=null&&(r(x),r=void 0),i},get readableLength(){return E.readableLength},onEmpty:x=>E.onEmpty(x)},i}var $n=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},ps=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Vn(t,e){let{milliseconds:r,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout},signal:s}=e,a,u,l=new Promise((p,m)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){m(ps(s));return}if(s&&(u=()=>{m(ps(s))},s.addEventListener("abort",u,{once:!0})),t.then(p,m),r===Number.POSITIVE_INFINITY)return;let b=new $n;a=o.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(S){m(S)}return}typeof t.cancel=="function"&&t.cancel(),i===!1?p():i instanceof Error?m(i):(b.message=i??`Promise timed out after ${r} milliseconds`,m(b))},r)}).finally(()=>{l.clear(),u&&s&&s.removeEventListener("abort",u)});return l.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},l}var Su=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function Tu(t,e,r){let n,i=new Promise((o,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=[e].flat(),u=[],{addListener:f,removeListener:l}=Su(t),p=async(...b)=>{let S=r.multiArgs?b:b[0];if(r.filter)try{if(!await r.filter(S))return}catch(E){n(),s(E);return}u.push(S),r.count===u.length&&(n(),o(u))},m=(...b)=>{n(),s(r.rejectionMultiArgs?b:b[0])};n=()=>{for(let b of a)l(b,p);for(let b of r.rejectionEvents)a.includes(b)||l(b,m)};for(let b of a)f(b,p);for(let b of r.rejectionEvents)a.includes(b)||f(b,m);r.signal&&r.signal.addEventListener("abort",()=>{m(r.signal.reason)},{once:!0}),r.resolveImmediately&&o(u)});if(i.cancel=n,typeof r.timeout=="number"){let o=Vn(i,{milliseconds:r.timeout});return o.cancel=()=>{n(),o.clear()},o}return i}function Nr(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Tu(t,e,r),i=n.then(o=>o[0]);return i.cancel=n.cancel,i}function _t(t,e){let r,n=function(){let i=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(i,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Fr=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function Iu(t){return t.reason}async function ms(t,e,r){if(e==null)return t;let n=r?.translateError??Iu;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let i;try{return await Promise.race([t,new Promise((o,s)=>{i=()=>{s(n(e))},e.addEventListener("abort",i)})])}finally{i!=null&&e.removeEventListener("abort",i)}}var kr=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=ot(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new we)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Cu(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Dr=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,r){this.id=Cu(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new we),this.cleanup())}async join(e){let r=new kr(e);return this.recipients.push(r),e?.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await ms(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(!this.dispatchingProgress){this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(r)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var Ur=class extends ir{concurrency;maxSize;queue;pending;sort;paused;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=e.sort,this.queue=[],this.emitEmpty=_t(this.emitEmpty.bind(this),1),this.emitIdle=_t(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 e;for(let r of this.queue)if(r.status==="queued"){e=r;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===e){this.queue.splice(r,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}async add(e,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Fr;let n=new Dr(e,r);this.enqueue(n),this.safeDispatchEvent("add");let i=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 s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o});return this.tryToStartAnother(),i}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new we)}),this.clear()}async onEmpty(e){this.size!==0&&await Nr(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await Nr(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Nr(this,"idle",e)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let r=ds({objectMode:!0}),n=u=>{u!=null?this.abort():this.clear(),r.end(u)},i=u=>{u.detail!=null&&r.push(u.detail)},o=u=>{n(u.detail.error)},s=()=>{n()},a=()=>{n(new we("Queue aborted"))};this.addEventListener("completed",i),this.addEventListener("failure",o),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",i),this.removeEventListener("failure",o),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};function gs(t){let e=new globalThis.AbortController;function r(){let o=t.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();e.abort(o);for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let o of t){if(o?.aborted===!0){r();break}o?.addEventListener!=null&&o.addEventListener("abort",r)}function n(){for(let o of t)o?.removeEventListener!=null&&o.removeEventListener("abort",r)}let i=e.signal;return i.clear=n,i}function ys(t,e,r){let n,i,o=!1;function s(){let f={signal:i.signal},l;r?.timeout!=null&&(l=gs([i.signal,AbortSignal.timeout(r.timeout)]),f.signal=l),o=!0,Promise.resolve().then(async()=>{await t(f)}).catch(()=>{}).finally(()=>{l!=null&&(l.aborted?l.clear():l.addEventListener("abort",()=>{l.clear()},{once:!0})),o=!1,!i.signal.aborted&&(n=setTimeout(s,e))})}let a=_t(s,r?.debounce??100),u=!1;return{setInterval:f=>{e!==f&&(e=f,n!=null&&(clearTimeout(n),n=setTimeout(s,e)))},setTimeout:f=>{r??={},r.timeout=f},run:()=>{o||(clearTimeout(n),a())},start:()=>{u||(u=!0,i=new AbortController,i.signal,r?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,e))},stop:()=>{clearTimeout(n),i?.abort(),u=!1}}}var _r=class{routers;localStore;republishTask;log;keychain;started=!1;republishConcurrency;constructor(e,r){this.log=e.logger.forComponent("helia:ipns"),this.localStore=r.localStore,this.keychain=e.keychain,this.republishConcurrency=r.republishConcurrency||wi,this.started=!1,this.routers=r.routers??[],this.republishTask=ys(this.#e.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())}async#e(e={}){if(!this.started)return;this.log("starting ipns republish records loop");let r=new Ur({concurrency:this.republishConcurrency});try{let n=[],i=0;for await(let{routingKey:o,record:s,metadata:a,created:u}of this.localStore.list(e)){if(i++,a==null){this.log("no metadata found for record %b, skipping",o);continue}let f;try{f=await pe(o,s,this.keychain,e)}catch(b){this.log.error("error unmarshaling record - %e",b);continue}if(!Zo(f,u)){this.log.trace("skipping record %b within republish threshold",o);continue}let l=f.sequence+1n,p=f.ttl??je,m;try{m=await this.keychain.exportKey(a.keyName)}catch(b){this.log.error("missing key %s, skipping republishing record - %e",a.keyName,b);continue}try{let b=await Cr(m,f.value,l,a.lifetime,{...e,ttlNs:p});n.push({routingKey:o,record:b})}catch(b){this.log.error("error creating updated IPNS record for %s - %e",o,b);continue}}this.log(`found ${n.length}/${i} records to republish`);for(let{routingKey:o,record:s}of n)r.add(async()=>{try{let a=nt(s);await Promise.all(this.routers.map(u=>u.put(o,a,e)))}catch(a){this.log.error("error republishing record - %e",a)}},e)}catch(n){this.log.error("error during republish - %e",n)}await r.onIdle(e)}};var On=new Float32Array([-0]),Fe=new Uint8Array(On.buffer);function xs(t,e,r){On[0]=t,e[r]=Fe[0],e[r+1]=Fe[1],e[r+2]=Fe[2],e[r+3]=Fe[3]}function ws(t,e){return Fe[0]=t[e],Fe[1]=t[e+1],Fe[2]=t[e+2],Fe[3]=t[e+3],On[0]}var zn=new Float64Array([-0]),q=new Uint8Array(zn.buffer);function bs(t,e,r){zn[0]=t,e[r]=q[0],e[r+1]=q[1],e[r+2]=q[2],e[r+3]=q[3],e[r+4]=q[4],e[r+5]=q[5],e[r+6]=q[6],e[r+7]=q[7]}function Es(t,e){return q[0]=t[e],q[1]=t[e+1],q[2]=t[e+2],q[3]=t[e+3],q[4]=t[e+4],q[5]=t[e+5],q[6]=t[e+6],q[7]=t[e+7],zn[0]}var vu=BigInt(Number.MAX_SAFE_INTEGER),Nu=BigInt(Number.MIN_SAFE_INTEGER),re=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&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(e=!1){if(e)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(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Pe;if(e<vu&&e>Nu)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,i=e-(n<<32n);return r&&(n=~n|0n,i=~i|0n,++i>Ss&&(i=0n,++n>Ss&&(n=0n))),new t(Number(i),Number(n))}static fromNumber(e){if(e===0)return Pe;let r=e<0;r&&(e=-e);let n=e>>>0,i=(e-n)/4294967296>>>0;return r&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new t(n,i)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Pe}},Pe=new re(0,0);Pe.toBigInt=function(){return 0n};Pe.zzEncode=Pe.zzDecode=function(){return this};Pe.length=function(){return 1};var Ss=4294967296n;function Ts(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Is(t,e,r){if(r-e<1)return"";let i,o=[],s=0,a;for(;e<r;)a=t[e++],a<128?o[s++]=a:a>191&&a<224?o[s++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function qn(t,e,r){let n=r,i,o;for(let s=0;s<t.length;++s)i=t.charCodeAt(s),i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&((o=t.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128);return r-n}function le(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Lr(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Kn=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,le(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw le(this,4);return Lr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw le(this,4);return Lr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw le(this,4);let e=ws(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw le(this,4);let e=Es(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw le(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Is(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw le(this,e);this.pos+=e}else do if(this.pos>=this.len)throw le(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new re(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw le(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw le(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw le(this,8);let e=Lr(this.buf,this.pos+=4),r=Lr(this.buf,this.pos+=4);return new re(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Xt(this.buf,this.pos);return this.pos+=xe(e),e}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 Lt(t){return new Kn(t instanceof Uint8Array?t:t.subarray())}function Hn(t,e,r){let n=Lt(t);return e.decode(n,void 0,r)}function Gn(t){let e=t??8192,r=e>>>1,n,i=e;return function(s){if(s<1||s>r)return H(s);i+s>e&&(n=H(e),i=0);let a=n.subarray(i,i+=s);return(i&7)!==0&&(i=(i|7)+1),a}}var $e=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function jn(){}var Xn=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Fu=Gn();function ku(t){return globalThis.Buffer!=null?H(t):Fu(t)}var Bt=class{len;head;tail;states;constructor(){this.len=0,this.head=new $e(jn,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new $e(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Wn((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Rr,10,re.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=re.fromBigInt(e);return this._push(Rr,r.length(),r)}uint64Number(e){return this._push(Yt,xe(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=re.fromBigInt(e).zzEncode();return this._push(Rr,r.length(),r)}sint64Number(e){let r=re.fromNumber(e).zzEncode();return this._push(Rr,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Yn,1,e?1:0)}fixed32(e){return this._push(Rt,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=re.fromBigInt(e);return this._push(Rt,4,r.lo)._push(Rt,4,r.hi)}fixed64Number(e){let r=re.fromNumber(e);return this._push(Rt,4,r.lo)._push(Rt,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(xs,4,e)}double(e){return this._push(bs,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Yn,1,0):this.uint32(r)._push(Uu,r,e)}string(e){let r=Ts(e);return r!==0?this.uint32(r)._push(qn,r,e):this._push(Yn,1,0)}fork(){return this.states=new Xn(this),this.head=this.tail=new $e(jn,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 $e(jn,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=ku(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Yn(t,e,r){e[r]=t&255}function Du(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Wn=class extends $e{next;constructor(e,r){super(Du,e,r),this.next=void 0}};function Rr(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function Rt(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function Uu(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Bt.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(_u,e,t),this},Bt.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Lu,e,t),this});function _u(t,e,r){e.set(t,r)}function Lu(t,e,r){t.length<40?qn(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set($(t),r)}function Jn(){return new Bt}function Qn(t,e){let r=Jn();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Zn(t,e,r){let n=Lt(t);yield*e.stream(n,void 0,"$",r)}var ei={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function ti(t,e,r,n,i){return{name:t,type:e,encode:r,decode:n,stream:i}}function ri(t,e,r){return ti("message",ei.LENGTH_DELIMITED,t,e,r)}var Mt;(function(t){let e;t.codec=()=>(e==null&&(e=ri((o,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),o.key!=null&&o.key.byteLength>0&&(s.uint32(10),s.bytes(o.key)),o.value!=null&&o.value.byteLength>0&&(s.uint32(18),s.bytes(o.value)),o.timeReceived!=null&&o.timeReceived!==""&&(s.uint32(42),s.string(o.timeReceived)),a.lengthDelimited!==!1&&s.ldelim()},(o,s,a={})=>{let u={key:Wr(0),value:Wr(0),timeReceived:""},f=s==null?o.len:o.pos+s;for(;o.pos<f;){let l=o.uint32();switch(l>>>3){case 1:{u.key=o.bytes();break}case 2:{u.value=o.bytes();break}case 5:{u.timeReceived=o.string();break}default:{o.skipType(l&7);break}}}return u},function*(o,s,a,u={}){let f=s==null?o.len:o.pos+s;for(;o.pos<f;){let l=o.uint32();switch(l>>>3){case 1:{yield{field:`${a}.key`,value:o.bytes()};break}case 2:{yield{field:`${a}.value`,value:o.bytes()};break}case 5:{yield{field:`${a}.timeReceived`,value:o.string()};break}default:{o.skipType(l&7);break}}}})),e);function r(o){return Qn(o,t.codec())}t.encode=r;function n(o,s){return Hn(o,t.codec(),s)}t.decode=n;function i(o,s){return Zn(o,t.codec(),s)}t.stream=i})(Mt||(Mt={}));function As(t){let e=t.getUTCFullYear(),r=String(t.getUTCMonth()+1).padStart(2,"0"),n=String(t.getUTCDate()).padStart(2,"0"),i=String(t.getUTCHours()).padStart(2,"0"),o=String(t.getUTCMinutes()).padStart(2,"0"),s=String(t.getUTCSeconds()).padStart(2,"0"),a=t.getUTCMilliseconds(),u=String(a*1e3*1e3).padStart(9,"0");return`${e}-${r}-${n}T${i}:${o}:${s}.${u}Z`}function vs(t){let e=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),r=String(t).trim().match(e);if(r==null)throw new Error("Invalid format");let n=parseInt(r[1],10),i=parseInt(r[2],10)-1,o=parseInt(r[3],10),s=parseInt(r[4],10),a=parseInt(r[5],10),u=parseInt(r[6],10),f=parseInt(r[7].slice(0,-6),10);return new Date(Date.UTC(n,i,o,s,a,u,f))}var ke=class t{key;value;timeReceived;constructor(e,r,n){if(!(e instanceof Uint8Array))throw new Error("key must be a Uint8Array");if(!(r instanceof Uint8Array))throw new Error("value must be a Uint8Array");this.key=e,this.value=r,this.timeReceived=n}serialize(){return Mt.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:As(this.timeReceived)}}static deserialize(e){let r=Mt.decode(e);return new t(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(e){let r=vs(e.timeReceived);if(e.key==null)throw new Error("key missing from deserialized object");if(e.value==null)throw new Error("value missing from deserialized object");return new t(e.key,e.value,r)}};var Ns;(function(t){t[t.SEND_QUERY=0]="SEND_QUERY",t[t.PEER_RESPONSE=1]="PEER_RESPONSE",t[t.FINAL_PEER=2]="FINAL_PEER",t[t.QUERY_ERROR=3]="QUERY_ERROR",t[t.PROVIDER=4]="PROVIDER",t[t.VALUE=5]="VALUE",t[t.ADD_PEER=6]="ADD_PEER",t[t.DIAL_PEER=7]="DIAL_PEER",t[t.PATH_ENDED=8]="PATH_ENDED"})(Ns||(Ns={}));var Pt;(function(t){let e;t.codec=()=>(e==null&&(e=xt((o,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),o.keyName!=null&&o.keyName!==""&&(s.uint32(10),s.string(o.keyName)),o.lifetime!=null&&o.lifetime!==0&&(s.uint32(16),s.uint32(o.lifetime)),a.lengthDelimited!==!1&&s.ldelim()},(o,s,a={})=>{let u={keyName:"",lifetime:0},f=s==null?o.len:o.pos+s;for(;o.pos<f;){let l=o.uint32();switch(l>>>3){case 1:{u.keyName=o.string();break}case 2:{u.lifetime=o.uint32();break}default:{o.skipType(l&7);break}}}return u},function*(o,s,a,u={}){let f=s==null?o.len:o.pos+s;for(;o.pos<f;){let l=o.uint32();switch(l>>>3){case 1:{yield{field:`${a}.keyName`,value:o.string()};break}case 2:{yield{field:`${a}.lifetime`,value:o.uint32()};break}default:{o.skipType(l&7);break}}}})),e);function r(o){return gt(o,t.codec())}t.encode=r;function n(o,s){return dt(o,t.codec(),s)}t.decode=n;function i(o,s){return yt(o,t.codec(),s)}t.stream=i})(Pt||(Pt={}));function Br(t,e){return{async put(r,n,i={}){try{let o=Ft(r);try{let u=await t.get(o),f=ke.deserialize(u);if(wt(f.value,n))return}catch(u){if(u.name!=="NotFoundError")throw u}let s=new ke(r,n,new Date);i.onProgress?.(new Y("ipns:routing:datastore:put"));let a=t.batch();a.put(o,s.serialize()),i.metadata!=null&&a.put(Er(r),Pt.encode(i.metadata)),await a.commit(i)}catch(o){throw i.onProgress?.(new Y("ipns:routing:datastore:error",o)),o}},async get(r,n={}){try{let i=Ft(r);n.onProgress?.(new Y("ipns:routing:datastore:get"));let o=await t.get(i,n),s=ke.deserialize(o);return{record:s.value,created:s.timeReceived}}catch(i){throw n.onProgress?.(new Y("ipns:routing:datastore:error",i)),i}},async has(r,n={}){let i=Ft(r);return t.has(i,n)},async delete(r,n){let i=Ft(r),o=t.batch();o.delete(i),o.delete(Er(r)),await o.commit(n)},async*list(r={}){try{r.onProgress?.(new Y("ipns:routing:datastore:list"));for await(let{key:n,value:i}of t.query({prefix:br},r))try{let o=ke.deserialize(i),a=n.toString().substring(br.length),u=$(a,"base32"),f=Er(u),l;try{let p=await t.get(f,r);l=Pt.decode(p)}catch(p){e.error("Error deserializing metadata for %s - %e",a,p)}yield{routingKey:u,metadata:l,record:o.value,created:o.timeReceived}}catch(o){e.error("Error deserializing record - %e",o)}}catch(n){throw r.onProgress?.(new Y("ipns:routing:datastore:error",n)),n}}}}var ni=class{routing;constructor(e){this.routing=e}async put(e,r,n={}){try{await this.routing.put(e,r,n)}catch(i){throw n.onProgress?.(new Y("ipns:routing:helia:error",i)),i}}async get(e,r={}){try{return await this.routing.get(e,r)}catch(n){throw r.onProgress?.(new Y("ipns:routing:helia:error",n)),n}}toString(){return"HeliaRouting()"}};function $t(t){return new ni(t)}var ii=class{localStore;constructor(e){this.localStore=e}async put(e,r,n){await this.localStore.put(e,r,n)}async get(e,r){let{record:n}=await this.localStore.get(e,r);return n}toString(){return"LocalStoreRouting()"}};function Mr(t){return new ii(t)}var Pr=class{routers;publisher;republisher;resolver;localStore;components;started;constructor(e,r={}){this.localStore=Br(e.datastore,e.logger.forComponent("helia:ipns:local-store")),this.components=e,this.started=!1,this.routers=[Mr(this.localStore),$t(e.routing),...r.routers??[]],this.publisher=new Ar(e,{...r,routers:this.routers,localStore:this.localStore}),this.republisher=new _r(e,{...r,routers:this.routers,localStore:this.localStore}),this.resolver=new it(e,{...r,routers:this.routers,localStore:this.localStore}),e.events.addEventListener("start",this.start.bind(this)),e.events.addEventListener("stop",this.stop.bind(this)),this.started&&this.republisher.start();for(let n of Object.values(this.components))if(Bu(n))for(let i of Object.values(n.services))Mu(i)&&(i.selectors.ipns=async(o,s)=>{let a=await Promise.all(s.map(u=>pe(o,u,this.components.keychain)));return tr(o,a)},i.validators.ipns=async(o,s)=>{let a=await pe(o,s,this.components.keychain);await Ut(a)})}start(){this.started||(this.started=!0,this.republisher.start())}stop(){this.started&&(this.started=!1,this.republisher.stop())}async publish(e,r,n={}){return this.publisher.publish(e,ns(r),n)}async*resolve(e,r={}){let{digest:n}=Dt(e);yield*this.resolver.resolve(n,r)}async unpublish(e,r){return this.publisher.unpublish(e,r)}};function Bu(t){return t?.services!=null}function Mu(t){return t?.validators!=null&&t?.selectors!=null}function Pu(t,e={}){return new Pr(t,e)}function $u(t,e={}){let r=Br(t.datastore,t.logger.forComponent("helia:ipns:local-store")),n=[Mr(r),$t(t.routing),...e.routers??[]];return new it(t,{routers:n,localStore:r})}return Rs(Vu);})();
13
+ ${e}[Error list was empty]`,r.trim()}return _i(t,e)}G.formatters.e=t=>t==null?"undefined":Bi(t);function Lc(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e.useColors=()=>!1,e}function vn(t,e){let r=Lc(`${t}:trace`);return G.enabled(`${t}:trace`)&&G.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=G(`${t}:trace`,e)),Object.assign(G(t,e),{error:G(`${t}:error`,e),trace:r,newScope:n=>vn(`${t}:${n}`,e)})}function Ri(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var Mi=Ir(Pt(),1);var _c=vn("ipns"),Pi=300*1e9,Rc="/ipns/",Jd=Rc.length,$i={v1Compatible:!0,ttlNs:Pi};async function pr(t,e,r,n,o=$i){let i=new Mi.default(Date.now()+Number(n)),s=V.ValidityType.EOL,a=BigInt(o.ttlNs??Pi);return Bc(t,e,r,s,i.toString(),a,o)}var Bc=async(t,e,r,n,o,i,s=$i)=>{r=BigInt(r);let a=z(o),u=Ni(e,n,a,r,i),f=fr(u),l=await t.sign(f,s),p=Pc(t.publicKey)?t.publicKey:void 0,m;if(s.v1Compatible===!0){let w=await Mc(t,e,n,a);m={value:e,signatureV1:w,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:l,data:u,publicKey:p}}else m={value:e,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:l,data:u,publicKey:p};return m.bytes=et(m),m},Mc=async(t,e,r,n,o)=>{try{let i=Ai(e,r,n);return await t.sign(i,o)}catch(i){throw _c.error("record signature creation failed",i),new _t("Record signature creation failed")}};function Pc(t){return t.toMultihash().code!==0}var mr=class{routers;localStore;keychain;constructor(e,r){this.keychain=e.keychain,this.localStore=r.localStore,this.routers=r.routers}async publish(e,r,n={}){try{let o=await this.#e(e,n),i=o.publicKey.toMultihash(),s=vt(i),a=1n;if(await this.localStore.has(s,n)){let{record:m}=await this.localStore.get(s,n);a=(await fe(s,m,this.keychain,n)).sequence+1n}let u=n.ttl!=null?BigInt(n.ttl)*1000000n:Ke,f=n.lifetime??1728e5,l=await pr(o,r,a,f,{...n,ttlNs:u}),p=et(l);return n.offline===!0?await this.localStore.put(s,p,{...n,metadata:{keyName:e,lifetime:f}}):await Promise.all(this.routers.map(async m=>{await m.put(s,p,{...n,metadata:{keyName:e,lifetime:f}})})),{record:{...l,publicKey:o.publicKey},name:`/ipns/${o.publicKey.toCID().toString(ee)}`,publicKey:o.publicKey}}catch(o){throw n.onProgress?.(new j("ipns:publish:error",o)),o}}async#e(e,r){try{return await this.keychain.exportKey(e,r)}catch(n){if(n.name==="NotFoundError")return this.keychain.generateKey(e,r);throw n}}async unpublish(e,r){let o=(await this.keychain.exportKey(e,r)).publicKey.toMultihash(),i=vt(o);await this.localStore.delete(i,r)}};function rt(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var gr=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},nt=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new gr(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new gr(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Cn=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Vi(t={}){return Vc(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}},t)}function Vc(t,e){e=e??{};let r=e.onEnd,n=new nt,o,i,s,a=rt(),u=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((x,T)=>{i=k=>{i=null,n.push(k);try{x(t(n))}catch(F){T(F)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=rt()})}},f=x=>i!=null?i(x):(n.push(x),o),l=x=>(n=new nt,i!=null?i({error:x}):(n.push({error:x}),o)),p=x=>{if(s)return o;if(e?.objectMode!==!0&&x?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:x})},m=x=>s?o:(s=!0,x!=null?l(x):f({done:!0})),w=()=>(n=new nt,m(),{done:!0}),S=x=>(m(x),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:u,return:w,throw:S,push:p,end:m,get readableLength(){return n.size},onEmpty:async x=>{let T=x?.signal;if(T?.throwIfAborted(),n.isEmpty())return;let k,F;T!=null&&(k=new Promise((P,B)=>{F=()=>{B(new Cn)},T.addEventListener("abort",F)}));try{await Promise.race([a.promise,k])}finally{F!=null&&T!=null&&T?.removeEventListener("abort",F)}}},r==null)return o;let E=o;return o={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(x){return E.throw(x),r!=null&&(r(x),r=void 0),{done:!0}},return(){return E.return(),r!=null&&(r(),r=void 0),{done:!0}},push:p,end(x){return E.end(x),r!=null&&(r(x),r=void 0),o},get readableLength(){return E.readableLength},onEmpty:x=>E.onEmpty(x)},o}var In=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Oi=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function An(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,u,l=new Promise((p,m)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){m(Oi(s));return}if(s&&(u=()=>{m(Oi(s))},s.addEventListener("abort",u,{once:!0})),t.then(p,m),r===Number.POSITIVE_INFINITY)return;let w=new In;a=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(S){m(S)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?p():o instanceof Error?m(o):(w.message=o??`Promise timed out after ${r} milliseconds`,m(w))},r)}).finally(()=>{l.clear(),u&&s&&s.removeEventListener("abort",u)});return l.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},l}var Oc=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function zc(t,e,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=[e].flat(),u=[],{addListener:f,removeListener:l}=Oc(t),p=async(...w)=>{let S=r.multiArgs?w:w[0];if(r.filter)try{if(!await r.filter(S))return}catch(E){n(),s(E);return}u.push(S),r.count===u.length&&(n(),i(u))},m=(...w)=>{n(),s(r.rejectionMultiArgs?w:w[0])};n=()=>{for(let w of a)l(w,p);for(let w of r.rejectionEvents)a.includes(w)||l(w,m)};for(let w of a)f(w,p);for(let w of r.rejectionEvents)a.includes(w)||f(w,m);r.signal&&r.signal.addEventListener("abort",()=>{m(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(u)});if(o.cancel=n,typeof r.timeout=="number"){let i=An(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function yr(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=zc(t,e,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function At(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var xr=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function qc(t){return t.reason}async function zi(t,e,r){if(e==null)return t;let n=r?.translateError??qc;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var br=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=rt(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new me)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Kc(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var wr=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,r){this.id=Kc(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new me),this.cleanup())}async join(e){let r=new br(e);return this.recipients.push(r),e?.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await zi(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(!this.dispatchingProgress){this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(r)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var Er=class extends Gt{concurrency;maxSize;queue;pending;sort;paused;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=e.sort,this.queue=[],this.emitEmpty=At(this.emitEmpty.bind(this),1),this.emitIdle=At(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 e;for(let r of this.queue)if(r.status==="queued"){e=r;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===e){this.queue.splice(r,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}async add(e,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new xr;let n=new wr(e,r);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(r).then(i=>(this.safeDispatchEvent("completed",{detail:i}),this.safeDispatchEvent("success",{detail:{job:n,result:i}}),i)).catch(i=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:i}}),i});return this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new me)}),this.clear()}async onEmpty(e){this.size!==0&&await yr(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await yr(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await yr(this,"idle",e)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let r=Vi({objectMode:!0}),n=u=>{u!=null?this.abort():this.clear(),r.end(u)},o=u=>{u.detail!=null&&r.push(u.detail)},i=u=>{n(u.detail.error)},s=()=>{n()},a=()=>{n(new me("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};function qi(t){let e=new globalThis.AbortController;function r(){let i=t.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();e.abort(i);for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let i of t){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=e.signal;return o.clear=n,o}function Ki(t,e,r){let n,o,i=!1;function s(){let f={signal:o.signal},l;r?.timeout!=null&&(l=qi([o.signal,AbortSignal.timeout(r.timeout)]),f.signal=l),i=!0,Promise.resolve().then(async()=>{await t(f)}).catch(()=>{}).finally(()=>{l!=null&&(l.aborted?l.clear():l.addEventListener("abort",()=>{l.clear()},{once:!0})),i=!1,!o.signal.aborted&&(n=setTimeout(s,e))})}let a=At(s,r?.debounce??100),u=!1;return{setInterval:f=>{e!==f&&(e=f,n!=null&&(clearTimeout(n),n=setTimeout(s,e)))},setTimeout:f=>{r??={},r.timeout=f},run:()=>{i||(clearTimeout(n),a())},start:()=>{u||(u=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,e))},stop:()=>{clearTimeout(n),o?.abort(),u=!1}}}var Sr=class{routers;localStore;republishTask;log;keychain;started=!1;republishConcurrency;constructor(e,r){this.log=e.logger.forComponent("helia:ipns"),this.localStore=r.localStore,this.keychain=e.keychain,this.republishConcurrency=r.republishConcurrency||Kn,this.started=!1,this.routers=r.routers??[],this.republishTask=Ki(this.#e.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())}async#e(e={}){if(!this.started)return;this.log("starting ipns republish records loop");let r=new Er({concurrency:this.republishConcurrency});try{let n=[],o=0;for await(let{routingKey:i,record:s,metadata:a,created:u}of this.localStore.list(e)){if(o++,a==null){this.log("no metadata found for record %b, skipping",i);continue}let f;try{f=await fe(i,s,this.keychain,e)}catch(w){this.log.error("error unmarshaling record - %e",w);continue}if(!Ii(f,u)){this.log.trace("skipping record %b within republish threshold",i);continue}let l=f.sequence+1n,p=f.ttl??Ke,m;try{m=await this.keychain.exportKey(a.keyName)}catch(w){this.log.error("missing key %s, skipping republishing record - %e",a.keyName,w);continue}try{let w=await pr(m,f.value,l,a.lifetime,{...e,ttlNs:p});n.push({routingKey:i,record:w})}catch(w){this.log.error("error creating updated IPNS record for %s - %e",i,w);continue}}this.log(`found ${n.length}/${o} records to republish`);for(let{routingKey:i,record:s}of n)r.add(async()=>{try{let a=et(s);await Promise.all(this.routers.map(u=>u.put(i,a,e)))}catch(a){this.log.error("error republishing record - %e",a)}},e)}catch(n){this.log.error("error during republish - %e",n)}await r.onIdle(e)}};var Nt;(function(t){let e;t.codec=()=>(e==null&&(e=Le((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.key!=null&&i.key.byteLength>0&&(s.uint32(10),s.bytes(i.key)),i.value!=null&&i.value.byteLength>0&&(s.uint32(18),s.bytes(i.value)),i.timeReceived!=null&&i.timeReceived!==""&&(s.uint32(42),s.string(i.timeReceived)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let u={key:Mr(0),value:Mr(0),timeReceived:""},f=s==null?i.len:i.pos+s;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{u.key=i.bytes();break}case 2:{u.value=i.bytes();break}case 5:{u.timeReceived=i.string();break}default:{i.skipType(l&7);break}}}return u},function*(i,s,a,u={}){let f=s==null?i.len:i.pos+s;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{yield{field:`${a}.key`,value:i.bytes()};break}case 2:{yield{field:`${a}.value`,value:i.bytes()};break}case 5:{yield{field:`${a}.timeReceived`,value:i.string()};break}default:{i.skipType(l&7);break}}}})),e);function r(i){return Ue(i,t.codec())}t.encode=r;function n(i,s){return ke(i,t.codec(),s)}t.decode=n;function o(i,s){return De(i,t.codec(),s)}t.stream=o})(Nt||(Nt={}));function Hi(t){let e=t.getUTCFullYear(),r=String(t.getUTCMonth()+1).padStart(2,"0"),n=String(t.getUTCDate()).padStart(2,"0"),o=String(t.getUTCHours()).padStart(2,"0"),i=String(t.getUTCMinutes()).padStart(2,"0"),s=String(t.getUTCSeconds()).padStart(2,"0"),a=t.getUTCMilliseconds(),u=String(a*1e3*1e3).padStart(9,"0");return`${e}-${r}-${n}T${o}:${i}:${s}.${u}Z`}function ji(t){let e=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),r=String(t).trim().match(e);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),u=parseInt(r[6],10),f=parseInt(r[7].slice(0,-6),10);return new Date(Date.UTC(n,o,i,s,a,u,f))}var Ce=class t{key;value;timeReceived;constructor(e,r,n){if(!(e instanceof Uint8Array))throw new Error("key must be a Uint8Array");if(!(r instanceof Uint8Array))throw new Error("value must be a Uint8Array");this.key=e,this.value=r,this.timeReceived=n}serialize(){return Nt.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:Hi(this.timeReceived)}}static deserialize(e){let r=Nt.decode(e);return new t(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(e){let r=ji(e.timeReceived);if(e.key==null)throw new Error("key missing from deserialized object");if(e.value==null)throw new Error("value missing from deserialized object");return new t(e.key,e.value,r)}};var Gi;(function(t){t[t.SEND_QUERY=0]="SEND_QUERY",t[t.PEER_RESPONSE=1]="PEER_RESPONSE",t[t.FINAL_PEER=2]="FINAL_PEER",t[t.QUERY_ERROR=3]="QUERY_ERROR",t[t.PROVIDER=4]="PROVIDER",t[t.VALUE=5]="VALUE",t[t.ADD_PEER=6]="ADD_PEER",t[t.DIAL_PEER=7]="DIAL_PEER",t[t.PATH_ENDED=8]="PATH_ENDED"})(Gi||(Gi={}));var kt;(function(t){let e;t.codec=()=>(e==null&&(e=Le((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.keyName!=null&&i.keyName!==""&&(s.uint32(10),s.string(i.keyName)),i.lifetime!=null&&i.lifetime!==0&&(s.uint32(16),s.uint32(i.lifetime)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let u={keyName:"",lifetime:0},f=s==null?i.len:i.pos+s;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{u.keyName=i.string();break}case 2:{u.lifetime=i.uint32();break}default:{i.skipType(l&7);break}}}return u},function*(i,s,a,u={}){let f=s==null?i.len:i.pos+s;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{yield{field:`${a}.keyName`,value:i.string()};break}case 2:{yield{field:`${a}.lifetime`,value:i.uint32()};break}default:{i.skipType(l&7);break}}}})),e);function r(i){return Ue(i,t.codec())}t.encode=r;function n(i,s){return ke(i,t.codec(),s)}t.decode=n;function o(i,s){return De(i,t.codec(),s)}t.stream=o})(kt||(kt={}));function Tr(t,e){return{async put(r,n,o={}){try{let i=Tt(r);try{let u=await t.get(i),f=Ce.deserialize(u);if(ht(f.value,n))return}catch(u){if(u.name!=="NotFoundError")throw u}let s=new Ce(r,n,new Date);o.onProgress?.(new j("ipns:routing:datastore:put"));let a=t.batch();a.put(i,s.serialize()),o.metadata!=null&&a.put(lr(r),kt.encode(o.metadata)),await a.commit(o)}catch(i){throw o.onProgress?.(new j("ipns:routing:datastore:error",i)),i}},async get(r,n={}){try{let o=Tt(r);n.onProgress?.(new j("ipns:routing:datastore:get"));let i=await t.get(o,n),s=Ce.deserialize(i);return{record:s.value,created:s.timeReceived}}catch(o){throw n.onProgress?.(new j("ipns:routing:datastore:error",o)),o}},async has(r,n={}){let o=Tt(r);return t.has(o,n)},async delete(r,n){let o=Tt(r),i=t.batch();i.delete(o),i.delete(lr(r)),await i.commit(n)},async*list(r={}){try{r.onProgress?.(new j("ipns:routing:datastore:list"));for await(let{key:n,value:o}of t.query({prefix:ur},r))try{let i=Ce.deserialize(o),a=n.toString().substring(ur.length),u=z(a,"base32"),f=lr(u),l;try{let p=await t.get(f,r);l=kt.decode(p)}catch(p){e.error("Error deserializing metadata for %s - %e",a,p)}yield{routingKey:u,metadata:l,record:i.value,created:i.timeReceived}}catch(i){e.error("Error deserializing record - %e",i)}}catch(n){throw r.onProgress?.(new j("ipns:routing:datastore:error",n)),n}}}}var Nn=class{routing;constructor(e){this.routing=e}async put(e,r,n={}){try{await this.routing.put(e,r,n)}catch(o){throw n.onProgress?.(new j("ipns:routing:helia:error",o)),o}}async get(e,r={}){try{return await this.routing.get(e,r)}catch(n){throw r.onProgress?.(new j("ipns:routing:helia:error",n)),n}}toString(){return"HeliaRouting()"}};function Ft(t){return new Nn(t)}var kn=class{localStore;constructor(e){this.localStore=e}async put(e,r,n){await this.localStore.put(e,r,n)}async get(e,r){let{record:n}=await this.localStore.get(e,r);return n}toString(){return"LocalStoreRouting()"}};function vr(t){return new kn(t)}var Cr=class{routers;publisher;republisher;resolver;localStore;components;started;constructor(e,r={}){this.localStore=Tr(e.datastore,e.logger.forComponent("helia:ipns:local-store")),this.components=e,this.started=!1,this.routers=[vr(this.localStore),Ft(e.routing),...r.routers??[]],this.publisher=new mr(e,{...r,routers:this.routers,localStore:this.localStore}),this.republisher=new Sr(e,{...r,routers:this.routers,localStore:this.localStore}),this.resolver=new tt(e,{...r,routers:this.routers,localStore:this.localStore}),e.events.addEventListener("start",this.start.bind(this)),e.events.addEventListener("stop",this.stop.bind(this)),this.started&&this.republisher.start();for(let n of Object.values(this.components))if(Gc(n))for(let o of Object.values(n.services))Yc(o)&&(o.selectors.ipns=async(i,s)=>{let a=await Promise.all(s.map(u=>fe(i,u,this.components.keychain)));return Kt(i,a)},o.validators.ipns=async(i,s)=>{let a=await fe(i,s,this.components.keychain);await It(a)})}start(){this.started||(this.started=!0,this.republisher.start())}stop(){this.started&&(this.started=!1,this.republisher.stop())}async publish(e,r,n={}){return this.publisher.publish(e,Fi(r),n)}async*resolve(e,r={}){let{digest:n}=Ct(e);yield*this.resolver.resolve(n,r)}async unpublish(e,r){return this.publisher.unpublish(e,r)}};function Gc(t){return t?.services!=null}function Yc(t){return t?.validators!=null&&t?.selectors!=null}function Xc(t,e={}){return new Cr(t,e)}function Jc(t,e={}){let r=Tr(t.datastore,t.logger.forComponent("helia:ipns:local-store")),n=[vr(r),Ft(t.routing),...e.routers??[]];return new tt(t,{routers:n,localStore:r})}return es(Wc);})();
14
14
  return HeliaIpns}));
15
15
  //# sourceMappingURL=index.min.js.map