@helia/ipns 10.0.0-3a1dd561 → 10.0.0-3d869e9d

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 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((wu,Br)=>{var xu=(function(){typeof Br<"u"&&(Br.exports=A);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 w=g-g%1;return w==0&&(g<0||g===0&&1/g!=1/0)?-0:w},l=A.prototype,p=(A.fromDate=function(g){return new A(+g)},A.fromInt64BE=P(0,1,2,3,0,4),A.fromInt64LE=P(3,2,1,0,4,0),A.fromString=function(S){var w,E=new A,S=(S+="").replace(/^\s*[+\-]?\d+/,function(F){var F=+F,B=1970+(F-1970)%400;return E.year=F-B,B}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(v,F,B){return F<0&&(B*=-1),w=6e4*(60*+F+ +B),""}).replace(/\.\d+$/,function(v){return E.nano=+(v+u).substr(1,9),""}).split(/\D+/);if(1<S.length?S[1]--:S[1]=0,E.time=w=Date.UTC.apply(Date,S)-(w||0),isNaN(w))throw new TypeError("Invalid Date");return b(E)},A.fromTimeT=function(g){return I(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=b(this);return(g.time%1e3*a+ +g.nano+1e9)%1e9},l.getTimeT=function(){var w=b(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 x(b(this).time)},l.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},l.toString=function(g){var w=this,E=w.toDate(),S={H:function(){return $(E.getUTCHours())},L:function(){return L(E.getUTCMilliseconds(),3)},M:function(){return $(E.getUTCMinutes())},N:function(){return L(w.getNano(),9)},S:function(){return $(E.getUTCSeconds())},Y:function(){var v=w.getYear();return 999999<v?"+"+v:9999<v?"+"+L(v,6):0<=v?L(v,4):-999999<=v?"-"+L(-v,6):v},a:function(){return T[E.getUTCDay()]},b:function(){return m[E.getUTCMonth()]},d:function(){return $(E.getUTCDate())},e:function(){return(function(v){return(9<v?"":" ")+(0|v)})(E.getUTCDate())},m:function(){return $(E.getUTCMonth()+1)}};return(function v(F){return F.replace(/%./g,function(B){var U=B[1],N=G[U],U=S[U];return N?v(N):U?U():B})})(g||p)},l.writeInt64BE=D(0,1,2,3,0,4),l.writeInt64LE=D(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"],T=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],G={"%":"%",F:"%Y-%m-%d",n:`
3
- `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return A;function A(g,w,E){var S=this;if(!(S instanceof A))return new A(g,w,E);S.time=+g||0,S.nano=+w||0,S.year=+E||0,b(S)}function b(g){var w,E,S,v=g.year,F=g.time,B=g.nano,N=((B<0||a<=B)&&(B-=(E=Math.floor(B/a))*a,F+=E,E=1),v%e);return(F<-i||i<F||N)&&((w=f(F/o))&&(v+=w*e,F-=w*o),(S=x(F)).setUTCFullYear(N+S.getUTCFullYear()),S=(F=+S)+(w=f((v-=N)/e))*o,w&&-i<=S&&S<=i&&(v-=w*e,F=S),E=1),E&&(g.year=v,g.time=F,g.nano=B),g}function x(g){var w=new Date(0);return w.setTime(g),w}function I(v,S){v=+v||0;var E=f((S=(S|0)*s)/n)+f(v/n),S=S%n+v%n,v=f(S/n);return v&&(E+=v,S-=v*n),new A(1e3*S,0,E*e)}function D(g,w,E,S,v,F){return function(N,U){var he=b(this);N=N||new Array(8),R(N,U|=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),B(N,U+v,de),B(N,U+F,he),N};function B(N,U,de){N[U+g]=de>>24&255,N[U+w]=de>>16&255,N[U+E]=de>>8&255,N[U+S]=255&de}}function P(g,w,E,S,v,F){return function(N,U){R(N,U|=0);var de=B(N,U+v);return I(B(N,U+F),de)};function B(N,U){return 16777216*N[U+g]+(N[U+w]<<16|N[U+E]<<8|N[U+S])}}function R(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 $(g){return(9<g?"":"0")+(0|g)}function L(g,w){return(u+(0|g)).substr(-w)}})()});var Wc={};Y(Wc,{ipns:()=>Xc,ipnsResolver:()=>Jc});var Ur={};Y(Ur,{base32:()=>we,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,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),a=s.charCodeAt(0);if(n[a]!==255)throw new TypeError(s+" is ambiguous");if(n[a]=i,r){var u=s.toLowerCase().charCodeAt(0),f=s.toUpperCase().charCodeAt(0);u!==a&&(n[u]=i),f!==a&&(n[f]=i)}}var l=t.length,p=t.charAt(0),m=Math.log(l)/Math.log(256),T=Math.log(256)/Math.log(l);function G(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var I=0,D=0,P=0,R=x.length;P!==R&&x[P]===0;)P++,I++;for(var $=(R-P)*T+1>>>0,L=new Uint8Array($);P!==R;){for(var g=x[P],w=0,E=$-1;(g!==0||w<D)&&E!==-1;E--,w++)g+=256*L[E]>>>0,L[E]=g%l>>>0,g=g/l>>>0;if(g!==0)throw new Error("Non-zero carry");D=w,P++}for(var S=$-D;S!==$&&L[S]===0;)S++;for(var v=p.repeat(I);S<$;++S)v+=t.charAt(L[S]);return v}function A(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var I=0;if(x[I]!==" "){for(var D=0,P=0;x[I]===p;)D++,I++;for(var R=(x.length-I)*m+1>>>0,$=new Uint8Array(R);x[I];){var L=n[x.charCodeAt(I)];if(L===255)return;for(var g=0,w=R-1;(L!==0||g<P)&&w!==-1;w--,g++)L+=l*$[w]>>>0,$[w]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");P=g,I++}if(x[I]!==" "){for(var E=R-P;E!==R&&$[E]===0;)E++;for(var S=new Uint8Array(D+(R-E)),v=D;E!==R;)S[v++]=$[E++];return S}}}function b(x){var I=A(x);if(I)return I;throw new Error(`Non-${e} character`)}return{encode:G,decodeUnsafe:A,decode:b}}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,caseInsensitive:n=!1}){let{encode:o,decode:i}=Rn(r,t,n);return Pe({prefix:e,name:t,encode:o,decode:s=>pe(i(s))})}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,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let o=t[n].toLowerCase(),i=t[n].toUpperCase();o!==t[n]&&(r[o]=n),i!==t[n]&&(r[i]=n)}return r}function _({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let i=as(n,o);return Pe({prefix:e,name:t,encode(s){return ss(s,n,r)},decode(s){return is(s,i,r,t)}})}var we=_({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),cs=_({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),us=_({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),ls=_({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),fs=_({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),ds=_({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),hs=_({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),ps=_({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),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",caseInsensitive:!0}),gs=xe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Lr={};Y(Lr,{base58btc:()=>K,base58flickr:()=>ys});var K=xe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ys=xe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var xs=$n,Mn=128,ws=127,bs=~ws,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&bs;)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??K.encoder):Ps(r,Rr(t),e??we.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??K;return[K.prefix,r.decode(`${K.prefix}${t}`)]}case K.prefix:{let r=e??K;return[K.prefix,r.decode(t)]}case we.prefix:{let r=e??we;return[we.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!==K.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),q=128,be=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|q,t/=128;case 7:e[r++]=t&255|q,t/=128;case 6:e[r++]=t&255|q,t/=128;case 5:e[r++]=t&255|q,t/=128;case 4:e[r++]=t&255|q,t>>>=7;case 3:e[r++]=t&255|q,t>>>=7;case 2:e[r++]=t&255|q,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&be,r<q||(r=t[e+1],n+=(r&be)<<7,r<q)||(r=t[e+2],n+=(r&be)<<14,r<q)||(r=t[e+3],n+=(r&be)<<21,r<q)||(r=t[e+4],n+=(r&be)*Hn,r<q)||(r=t[e+5],n+=(r&be)*jn,r<q)||(r=t[e+6],n+=(r&be)*Gn,r<q)||(r=t[e+7],n+=(r&be)*Yn,r<q))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,caseInsensitive:!0}),Xs=_({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});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(wa,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 wa(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(ba,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 ba(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},wo=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=wo(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 M=[24,256,65536,4294967296,BigInt("18446744073709551616")];function J(t,e,r){ge(t,e,1);let n=t[e];if(r.strict===!0&&n<M[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<M[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<M[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<M[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 bo(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 k(t,0,e.value)}function k(t,e,r){if(r<M[0]){let n=Number(r);t.push([e|n])}else if(r<M[1]){let n=Number(r);t.push([e|24,n])}else if(r<M[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<M[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<M[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 k.encodedSize(e.value)};k.encodedSize=function(e){return e<M[0]?1:e<M[1]?2:e<M[2]?3:e<M[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;k(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<M[0]?1:n<M[1]?2:n<M[2]?3:n<M[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);k(t,e.type.majorEncoded,r.length),t.push(r)}Ge.encodedSize=function(e){let r=er(e);return k.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 wt(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 wt(t,e,1,r,n)}function Bo(t,e,r,n){return wt(t,e,2,J(t,e+1,n),n)}function Mo(t,e,r,n){return wt(t,e,3,W(t,e+1,n),n)}function Po(t,e,r,n){return wt(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 wt(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){k(t,c.array.majorEncoded,e.value)}tr.compareTokens=te.compareTokens;tr.encodedSize=function(e){return k.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){k(t,c.map.majorEncoded,e.value)}rr.compareTokens=te.compareTokens;rr.encodedSize=function(e){return k.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){k(t,c.tag.majorEncoded,e.value)}nr.compareTokens=te.compareTokens;nr.encodedSize=function(e){return k.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(wn(t,e+1),5,n)}function ci(t,e,r,n){return yn(di(t,e+1),9,n)}function bt(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=wn(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)))}}bt.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=wn(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 wn(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)}bt.compareTokens=te.compareTokens;function C(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]=C;d[24]=bo;d[25]=Eo;d[26]=So;d[27]=To;d[28]=C;d[29]=C;d[30]=C;d[31]=C;for(let t=32;t<=55;t++)d[t]=C;d[56]=vo;d[57]=Co;d[58]=Io;d[59]=No;d[60]=C;d[61]=C;d[62]=C;d[63]=C;for(let t=64;t<=87;t++)d[t]=ko;d[88]=Fo;d[89]=Uo;d[90]=Do;d[91]=Lo;d[92]=C;d[93]=C;d[94]=C;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]=C;d[125]=C;d[126]=C;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]=C;d[157]=C;d[158]=C;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]=C;d[189]=C;d[190]=C;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]=C;d[221]=C;d[222]=C;d[223]=C;for(let t=224;t<=243;t++)d[t]=or("simple values are not supported");d[244]=C;d[245]=C;d[246]=C;d[247]=oi;d[248]=or("simple values are not supported");d[249]=si;d[250]=ai;d[251]=ci;d[252]=C;d[253]=C;d[254]=C;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 bn(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:bn},yi=Object.freeze({mapSorter:ja,quickEncodeToken:bn});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]=bt,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 wi(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)?bt(t,new h(c.float,e),r):e>=0?k(t,pi,e):k(t,mi,e*-1-1);return;case"bigint":e>=BigInt(0)?k(t,pi,e):k(t,mi,e*Za-ec);return;case"string":{let s=Xt(e);k(t,Ya,s.length),t.push(s);return}case"Uint8Array":k(t,Ga,e.length),t.push(e);return;case"Array":if(!e.length){t.push([gi]);return}n=St.createCheck(n,e),k(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 wi(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)):wi(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 bi(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]=bi(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=K);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 wc(t){return typeof t?.toCID=="function"}function Ui(t){if(wc(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 H=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 bc(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 bc(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,T=null,G,A;function b(...x){if(!b.enabled)return;let I=b,D=Number(new Date),P=D-(m||D);I.diff=P,I.prev=m,I.curr=D,m=D,x[0]=r.coerce(x[0]),typeof x[0]!="string"&&x.unshift("%O");let R=0;x[0]=x[0].replace(/%([a-zA-Z%])/g,(L,g)=>{if(L==="%%")return"%";R++;let w=r.formatters[g];if(typeof w=="function"){let E=x[R];L=w.call(I,E),x.splice(R,1),R--}return L}),r.formatArgs.call(I,x),p?.onLog!=null&&p.onLog(...x),(I.log||r.log).apply(I,x)}return b.namespace=l,b.useColors=r.useColors(),b.color=r.selectColor(l),b.extend=n,b.destroy=r.destroy,Object.defineProperty(b,"enabled",{enumerable:!0,configurable:!1,get:()=>T!==null?T:(G!==r.namespaces&&(G=r.namespaces,A=r.enabled(l)),A),set:x=>{T=x}}),typeof r.init=="function"&&r.init(b),b}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,]+/),T=m.length;for(p=0;p<T;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 j=Li;j.formatters.b=t=>t==null?"undefined":K.baseEncode(t);j.formatters.t=t=>t==null?"undefined":we.baseEncode(t);j.formatters.m=t=>t==null?"undefined":jr.baseEncode(t);j.formatters.p=t=>t==null?"undefined":t.toString();j.formatters.c=t=>t==null?"undefined":t.toString();j.formatters.k=t=>t==null?"undefined":t.toString();j.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(`
2
+ "use strict";var HeliaIpns=(()=>{var Xi=Object.create;var Ut=Object.defineProperty;var Ji=Object.getOwnPropertyDescriptor;var Wi=Object.getOwnPropertyNames;var Qi=Object.getPrototypeOf,Zi=Object.prototype.hasOwnProperty;var es=(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 Wi(e))!Zi.call(t,o)&&o!==r&&Ut(t,o,{get:()=>e[o],enumerable:!(n=Ji(e,o))||n.enumerable});return t};var Ir=(t,e,r)=>(r=t!=null?Xi(Qi(t)):{},Fn(e||!t||!t.__esModule?Ut(r,"default",{value:t,enumerable:!0}):r,t)),ts=t=>Fn(Ut({},"__esModule",{value:!0}),t);var Pt=es((bu,Br)=>{var wu=(function(){typeof Br<"u"&&(Br.exports=A);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 w=g-g%1;return w==0&&(g<0||g===0&&1/g!=1/0)?-0:w},l=A.prototype,p=(A.fromDate=function(g){return new A(+g)},A.fromInt64BE=P(0,1,2,3,0,4),A.fromInt64LE=P(3,2,1,0,4,0),A.fromString=function(S){var w,E=new A,S=(S+="").replace(/^\s*[+\-]?\d+/,function(F){var F=+F,B=1970+(F-1970)%400;return E.year=F-B,B}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(v,F,B){return F<0&&(B*=-1),w=6e4*(60*+F+ +B),""}).replace(/\.\d+$/,function(v){return E.nano=+(v+u).substr(1,9),""}).split(/\D+/);if(1<S.length?S[1]--:S[1]=0,E.time=w=Date.UTC.apply(Date,S)-(w||0),isNaN(w))throw new TypeError("Invalid Date");return b(E)},A.fromTimeT=function(g){return I(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=b(this);return(g.time%1e3*a+ +g.nano+1e9)%1e9},l.getTimeT=function(){var w=b(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 x(b(this).time)},l.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},l.toString=function(g){var w=this,E=w.toDate(),S={H:function(){return $(E.getUTCHours())},L:function(){return L(E.getUTCMilliseconds(),3)},M:function(){return $(E.getUTCMinutes())},N:function(){return L(w.getNano(),9)},S:function(){return $(E.getUTCSeconds())},Y:function(){var v=w.getYear();return 999999<v?"+"+v:9999<v?"+"+L(v,6):0<=v?L(v,4):-999999<=v?"-"+L(-v,6):v},a:function(){return T[E.getUTCDay()]},b:function(){return m[E.getUTCMonth()]},d:function(){return $(E.getUTCDate())},e:function(){return(function(v){return(9<v?"":" ")+(0|v)})(E.getUTCDate())},m:function(){return $(E.getUTCMonth()+1)}};return(function v(F){return F.replace(/%./g,function(B){var U=B[1],N=G[U],U=S[U];return N?v(N):U?U():B})})(g||p)},l.writeInt64BE=D(0,1,2,3,0,4),l.writeInt64LE=D(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"],T=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],G={"%":"%",F:"%Y-%m-%d",n:`
3
+ `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return A;function A(g,w,E){var S=this;if(!(S instanceof A))return new A(g,w,E);S.time=+g||0,S.nano=+w||0,S.year=+E||0,b(S)}function b(g){var w,E,S,v=g.year,F=g.time,B=g.nano,N=((B<0||a<=B)&&(B-=(E=Math.floor(B/a))*a,F+=E,E=1),v%e);return(F<-i||i<F||N)&&((w=f(F/o))&&(v+=w*e,F-=w*o),(S=x(F)).setUTCFullYear(N+S.getUTCFullYear()),S=(F=+S)+(w=f((v-=N)/e))*o,w&&-i<=S&&S<=i&&(v-=w*e,F=S),E=1),E&&(g.year=v,g.time=F,g.nano=B),g}function x(g){var w=new Date(0);return w.setTime(g),w}function I(v,S){v=+v||0;var E=f((S=(S|0)*s)/n)+f(v/n),S=S%n+v%n,v=f(S/n);return v&&(E+=v,S-=v*n),new A(1e3*S,0,E*e)}function D(g,w,E,S,v,F){return function(N,U){var pe=b(this);N=N||new Array(8),R(N,U|=0);var Me=Math.floor(pe.time/1e3),pe=pe.year*(r*t/e),he=f(pe/s)+f(Me/s),pe=pe%s+Me%s,Me=Math.floor(pe/s);return Me&&(he+=Me,pe-=Me*s),B(N,U+v,he),B(N,U+F,pe),N};function B(N,U,he){N[U+g]=he>>24&255,N[U+w]=he>>16&255,N[U+E]=he>>8&255,N[U+S]=255&he}}function P(g,w,E,S,v,F){return function(N,U){R(N,U|=0);var he=B(N,U+v);return I(B(N,U+F),he)};function B(N,U){return 16777216*N[U+g]+(N[U+w]<<16|N[U+E]<<8|N[U+S])}}function R(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 $(g){return(9<g?"":"0")+(0|g)}function L(g,w){return(u+(0|g)).substr(-w)}})()});var Qc={};Y(Qc,{ipns:()=>Jc,ipnsResolver:()=>Wc});var Ur={};Y(Ur,{base32:()=>we,base32hex:()=>ds,base32hexpad:()=>ps,base32hexpadupper:()=>ms,base32hexupper:()=>hs,base32pad:()=>ls,base32padupper:()=>fs,base32upper:()=>us,base32z:()=>gs});var eu=new Uint8Array(0);function Dn(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 ee(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 Ln(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var Un=4096;function _n(t){let e=t.length;if(e<=Un)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=Un));return r}function rs(t){return t?.buffer instanceof ArrayBuffer}function Ie(t){return rs(t)?t:t.slice()}function ns(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),a=s.charCodeAt(0);if(n[a]!==255)throw new TypeError(s+" is ambiguous");if(n[a]=i,r){var u=s.toLowerCase().charCodeAt(0),f=s.toUpperCase().charCodeAt(0);u!==a&&(n[u]=i),f!==a&&(n[f]=i)}}var l=t.length,p=t.charAt(0),m=Math.log(l)/Math.log(256),T=Math.log(256)/Math.log(l);function G(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var I=0,D=0,P=0,R=x.length;P!==R&&x[P]===0;)P++,I++;for(var $=(R-P)*T+1>>>0,L=new Uint8Array($);P!==R;){for(var g=x[P],w=0,E=$-1;(g!==0||w<D)&&E!==-1;E--,w++)g+=256*L[E]>>>0,L[E]=g%l>>>0,g=g/l>>>0;if(g!==0)throw new Error("Non-zero carry");D=w,P++}for(var S=$-D;S!==$&&L[S]===0;)S++;for(var v=p.repeat(I);S<$;++S)v+=t.charAt(L[S]);return v}function A(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var I=0;if(x[I]!==" "){for(var D=0,P=0;x[I]===p;)D++,I++;for(var R=(x.length-I)*m+1>>>0,$=new Uint8Array(R);x[I];){var L=n[x.charCodeAt(I)];if(L===255)return;for(var g=0,w=R-1;(L!==0||g<P)&&w!==-1;w--,g++)L+=l*$[w]>>>0,$[w]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");P=g,I++}if(x[I]!==" "){for(var E=R-P;E!==R&&$[E]===0;)E++;for(var S=new Uint8Array(D+(R-E)),v=D;E!==R;)S[v++]=$[E++];return S}}}function b(x){var I=A(x);if(I)return I;throw new Error(`Non-${e} character`)}return{encode:G,decodeUnsafe:A,decode:b}}var os=ns,is=os,Bn=is;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 Mn(this,e)}},kr=class{decoders;constructor(e){this.decoders=e}or(e){return Mn(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 Mn(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,caseInsensitive:n=!1}){let{encode:o,decode:i}=Bn(r,t,n);return Pe({prefix:e,name:t,encode:o,decode:s=>ee(i(s))})}function ss(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 as(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 cs(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let o=t[n].toLowerCase(),i=t[n].toUpperCase();o!==t[n]&&(r[o]=n),i!==t[n]&&(r[i]=n)}return r}function _({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let i=cs(n,o);return Pe({prefix:e,name:t,encode(s){return as(s,n,r)},decode(s){return ss(s,i,r,t)}})}var we=_({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),us=_({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),ls=_({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),fs=_({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),ds=_({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),hs=_({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),ps=_({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),ms=_({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),gs=_({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Dr={};Y(Dr,{base36:()=>te,base36upper:()=>ys});var te=xe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),ys=xe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Lr={};Y(Lr,{base58btc:()=>K,base58flickr:()=>xs});var K=xe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),xs=xe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ws=Vn,Pn=128,bs=127,Es=~bs,Ss=Math.pow(2,31);function Vn(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Ss;)e[r++]=t&255|Pn,t/=128;for(;t&Es;)e[r++]=t&255|Pn,t>>>=7;return e[r]=t|0,Vn.bytes=r-n+1,e}var Ts=_r,vs=128,$n=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&$n)<<o:(s&$n)*Math.pow(2,o),o+=7}while(s>=vs);return _r.bytes=i-n,r}var Cs=Math.pow(2,7),Is=Math.pow(2,14),As=Math.pow(2,21),Ns=Math.pow(2,28),ks=Math.pow(2,35),Fs=Math.pow(2,42),Us=Math.pow(2,49),Ds=Math.pow(2,56),Ls=Math.pow(2,63),_s=function(t){return t<Cs?1:t<Is?2:t<As?3:t<Ns?4:t<ks?5:t<Fs?6:t<Us?7:t<Ds?8:t<Ls?9:10},Rs={encode:ws,decode:Ts,encodingLength:_s},Bs=Rs,ot=Bs;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=ee(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 On(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Dn(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 zn(t,e){let{bytes:r,version:n}=t;return n===0?Ps(r,Rr(t),e??K.encoder):$s(r,Rr(t),e??we.encoder)}var qn=new WeakMap;function Rr(t){let e=qn.get(t);if(e==null){let r=new Map;return qn.set(t,r),r}return e}var ce=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!==Vs)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&&On(e.multihash,n.multihash)}toString(e){return zn(this,e)}toJSON(){return{"/":zn(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??Kn(n,o,i.bytes))}else if(r[Os]===!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=Kn(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=ee(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]=Ms(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 Ms(t,e){switch(t[0]){case"Q":{let r=e??K;return[K.prefix,r.decode(`${K.prefix}${t}`)]}case K.prefix:{let r=e??K;return[K.prefix,r.decode(t)]}case we.prefix:{let r=e??we;return[we.prefix,r.decode(t)]}case te.prefix:{let r=e??te;return[te.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 Ps(t,e,r){let{prefix:n}=r;if(n!==K.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 $s(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,Vs=18;function Kn(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 Os=Symbol.for("@ipld/js-cid/CID");var Ke=BigInt(6e4)*5000000n,Hn=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"},oe=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 ue(t=0){return new Uint8Array(t)}var zs=Math.pow(2,7),qs=Math.pow(2,14),Ks=Math.pow(2,21),jn=Math.pow(2,28),Gn=Math.pow(2,35),Yn=Math.pow(2,42),Xn=Math.pow(2,49),q=128,be=127;function ut(t){if(t<zs)return 1;if(t<qs)return 2;if(t<Ks)return 3;if(t<jn)return 4;if(t<Gn)return 5;if(t<Yn)return 6;if(t<Xn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Jn(t,e,r=0){switch(ut(t)){case 8:e[r++]=t&255|q,t/=128;case 7:e[r++]=t&255|q,t/=128;case 6:e[r++]=t&255|q,t/=128;case 5:e[r++]=t&255|q,t/=128;case 4:e[r++]=t&255|q,t>>>=7;case 3:e[r++]=t&255|q,t>>>=7;case 2:e[r++]=t&255|q,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Wn(t,e){let r=t[e],n=0;if(n+=r&be,r<q||(r=t[e+1],n+=(r&be)<<7,r<q)||(r=t[e+2],n+=(r&be)<<14,r<q)||(r=t[e+3],n+=(r&be)<<21,r<q)||(r=t[e+4],n+=(r&be)*jn,r<q)||(r=t[e+5],n+=(r&be)*Gn,r<q)||(r=t[e+6],n+=(r&be)*Yn,r<q)||(r=t[e+7],n+=(r&be)*Xn,r<q))return n;throw new RangeError("Could not decode varint")}function Hs(t){return t.buffer instanceof ArrayBuffer}function Qn(t){return Hs(t)?t:t.slice()}var Pr=new Float32Array([-0]),Ee=new Uint8Array(Pr.buffer);function Zn(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 eo(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 to(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 ro(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 js=BigInt(Number.MAX_SAFE_INTEGER),Gs=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<js&&e>Gs)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>no&&(o=0n,++n>no&&(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 no=4294967296n;function oo(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 io(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 ie(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=Qn(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,ie(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 ie(this,4);return $t(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ie(this,4);return $t(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ie(this,4);let e=eo(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw ie(this,4);let e=ro(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 ie(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return io(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw ie(this,e);this.pos+=e}else do if(this.pos>=this.len)throw ie(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 ie(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 ie(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 ie(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=Wn(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:()=>Ys});var Ys=xe({prefix:"9",name:"base10",alphabet:"0123456789"});var qr={};Y(qr,{base16:()=>Xs,base16upper:()=>Js});var Xs=_({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Js=_({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Kr={};Y(Kr,{base2:()=>Ws});var Ws=_({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Hr={};Y(Hr,{base256emoji:()=>ra});var ao=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}"),Qs=ao.reduce((t,e,r)=>(t[r]=e,t),[]),Zs=ao.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function ea(t){return t.reduce((e,r)=>(e+=Qs[r],e),"")}function ta(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Zs[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var ra=Pe({prefix:"\u{1F680}",name:"base256emoji",encode:ea,decode:ta});var Gr={};Y(Gr,{base64:()=>jr,base64pad:()=>na,base64url:()=>oa,base64urlpad:()=>ia});var jr=_({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),na=_({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),oa=_({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ia=_({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Yr={};Y(Yr,{base8:()=>sa});var sa=_({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Xr={};Y(Xr,{identity:()=>aa});var aa=Pe({prefix:"\0",name:"identity",encode:t=>_n(ee(t)),decode:t=>ee(Ln(t))});var zu=new TextEncoder,qu=new TextDecoder;var Jr={};Y(Jr,{identity:()=>da});var co=0,la="identity",uo=ee;function fa(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(co,uo(t))}var da={code:co,name:la,encode:uo,digest:fa};var Zr={};Y(Zr,{sha256:()=>pa,sha512:()=>ma});var ha=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??ha,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?lo(n,this.code,r?.truncate):n.then(o=>lo(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function lo(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 ho(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var pa=Qr({name:"sha2-256",code:18,encode:ho("SHA-256")}),ma=Qr({name:"sha2-512",code:19,encode:ho("SHA-512")});var en={...Xr,...Kr,...Yr,...zr,...qr,...Ur,...Dr,...Lr,...Gr,...Hr},rl={...Zr,...Jr};function mo(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var po=mo("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),tn=mo("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=ue(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),ga={utf8:po,"utf-8":po,hex:en.base16,latin1:tn,ascii:tn,binary:tn,...en},Vt=ga;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 ue(s);o+s>e&&(n=ue(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}},ya=rn();function xa(t){return globalThis.Buffer!=null?ue(t):ya(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(Jn,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(Zn,4,e)}double(e){return this._push(to,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=oo(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=xa(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 wa(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(wa,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(Ea,e,t),this},dt.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Sa,e,t),this});function Ea(t,e,r){e.set(t,r)}function Sa(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 Ta(t){return t?.buffer instanceof ArrayBuffer}function go(t){if(Ta(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=ue(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return go(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 va(t){return typeof t?.handleEvent=="function"}function Ca(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=Ca(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))}va(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 Ia=["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=Aa(t);return r||"Object"}function Aa(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Ia.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",Na=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 ka=24,Fa=200,Xt=pt?t=>t.length>=ka?globalThis.Buffer.from(t):yo(t):t=>t.length>=Fa?Na.encode(t):yo(t),le=t=>Uint8Array.from(t),xo=pt?(t,e,r)=>Yt(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),wo=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 yo(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 Ua=256,gt=class{constructor(e=Ua){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=xo(n,0,this.cursor)}else r=wo(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 M=[24,256,65536,4294967296,BigInt("18446744073709551616")];function J(t,e,r){ge(t,e,1);let n=t[e];if(r.strict===!0&&n<M[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<M[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<M[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<M[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 Eo(t,e,r,n){return new h(c.uint,J(t,e+1,n),2)}function So(t,e,r,n){return new h(c.uint,W(t,e+1,n),3)}function To(t,e,r,n){return new h(c.uint,Q(t,e+1,n),5)}function vo(t,e,r,n){return new h(c.uint,Z(t,e+1,n),9)}function re(t,e){return k(t,0,e.value)}function k(t,e,r){if(r<M[0]){let n=Number(r);t.push([e|n])}else if(r<M[1]){let n=Number(r);t.push([e|24,n])}else if(r<M[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<M[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<M[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`)}}re.encodedSize=function(e){return k.encodedSize(e.value)};k.encodedSize=function(e){return e<M[0]?1:e<M[1]?2:e<M[2]?3:e<M[3]?5:9};re.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Co(t,e,r,n){return new h(c.negint,-1-J(t,e+1,n),2)}function Io(t,e,r,n){return new h(c.negint,-1-W(t,e+1,n),3)}function Ao(t,e,r,n){return new h(c.negint,-1-Q(t,e+1,n),5)}var dn=BigInt(-1),No=BigInt(1);function ko(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-No:r*-1-1;k(t,e.type.majorEncoded,n)}Zt.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*dn-No:r*-1-1;return n<M[0]?1:n<M[1]?2:n<M[2]?3:n<M[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 Fo(t,e,r,n){return xt(t,e,1,r)}function Uo(t,e,r,n){return xt(t,e,2,J(t,e+1,n))}function Do(t,e,r,n){return xt(t,e,3,W(t,e+1,n))}function Lo(t,e,r,n){return xt(t,e,5,Q(t,e+1,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 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);k(t,e.type.majorEncoded,r.length),t.push(r)}Ge.encodedSize=function(e){let r=er(e);return k.encodedSize(r.length)+r.length};Ge.compareTokens=function(e,r){return La(er(e),er(r))};function La(t,e){return t.length<e.length?-1:t.length>e.length?1:Jt(t,e)}var Ro=new TextDecoder,Ra=32;function Ba(t,e,r){if(r-e<Ra){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return Ro.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return Ro.decode(t.subarray(e,r))}function wt(t,e,r,n,o){let i=r+n;ge(t,e,i);let s=new h(c.string,Ba(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function Bo(t,e,r,n){return wt(t,e,1,r,n)}function Mo(t,e,r,n){return wt(t,e,2,J(t,e+1,n),n)}function Po(t,e,r,n){return wt(t,e,3,W(t,e+1,n),n)}function $o(t,e,r,n){return wt(t,e,5,Q(t,e+1,n),n)}function Vo(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 wt(t,e,9,o,n)}var Oo=Ge;function Ye(t,e,r,n){return new h(c.array,n,r)}function zo(t,e,r,n){return Ye(t,e,1,r)}function qo(t,e,r,n){return Ye(t,e,2,J(t,e+1,n))}function Ko(t,e,r,n){return Ye(t,e,3,W(t,e+1,n))}function Ho(t,e,r,n){return Ye(t,e,5,Q(t,e+1,n))}function jo(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 Go(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){k(t,c.array.majorEncoded,e.value)}tr.compareTokens=re.compareTokens;tr.encodedSize=function(e){return k.encodedSize(e.value)};function Xe(t,e,r,n){return new h(c.map,n,r)}function Yo(t,e,r,n){return Xe(t,e,1,r)}function Xo(t,e,r,n){return Xe(t,e,2,J(t,e+1,n))}function Jo(t,e,r,n){return Xe(t,e,3,W(t,e+1,n))}function Wo(t,e,r,n){return Xe(t,e,5,Q(t,e+1,n))}function Qo(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 Zo(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){k(t,c.map.majorEncoded,e.value)}rr.compareTokens=re.compareTokens;rr.encodedSize=function(e){return k.encodedSize(e.value)};function ei(t,e,r,n){return new h(c.tag,r,1)}function ti(t,e,r,n){return new h(c.tag,J(t,e+1,n),2)}function ri(t,e,r,n){return new h(c.tag,W(t,e+1,n),3)}function ni(t,e,r,n){return new h(c.tag,Q(t,e+1,n),5)}function oi(t,e,r,n){return new h(c.tag,Z(t,e+1,n),9)}function nr(t,e){k(t,c.tag.majorEncoded,e.value)}nr.compareTokens=re.compareTokens;nr.encodedSize=function(e){return k.encodedSize(e.value)};var hn=20,pn=21,mn=22,gn=23;function ii(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 si(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 ai(t,e,r,n){return yn(xn(t,e+1),3,n)}function ci(t,e,r,n){return yn(wn(t,e+1),5,n)}function ui(t,e,r,n){return yn(hi(t,e+1),9,n)}function bt(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)&&(fi(n),o=xn(se,1),n===o||Number.isNaN(n)?(se[0]=249,t.push(se.slice(0,3)),i=!0):(di(n),o=wn(se,1),n===o&&(se[0]=250,t.push(se.slice(0,5)),i=!0))),i||(Oa(n),o=hi(se,1),se[0]=251,t.push(se.slice(0,9)))}}bt.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){fi(n);let o=xn(se,1);if(n===o||Number.isNaN(n))return 3;if(di(n),o=wn(se,1),n===o)return 5}return 9};var li=new ArrayBuffer(9),ne=new DataView(li,1),se=new Uint8Array(li,0);function fi(t){if(t===1/0)ne.setUint16(0,31744,!1);else if(t===-1/0)ne.setUint16(0,64512,!1);else if(Number.isNaN(t))ne.setUint16(0,32256,!1);else{ne.setFloat32(0,t);let e=ne.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)ne.setUint16(0,31744,!1);else if(r===0)ne.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?ne.setUint16(0,0):o<-14?ne.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):ne.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 di(t){ne.setFloat32(0,t,!1)}function wn(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 Oa(t){ne.setFloat64(0,t,!1)}function hi(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)}bt.compareTokens=re.compareTokens;function C(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]=C;d[24]=Eo;d[25]=So;d[26]=To;d[27]=vo;d[28]=C;d[29]=C;d[30]=C;d[31]=C;for(let t=32;t<=55;t++)d[t]=C;d[56]=Co;d[57]=Io;d[58]=Ao;d[59]=ko;d[60]=C;d[61]=C;d[62]=C;d[63]=C;for(let t=64;t<=87;t++)d[t]=Fo;d[88]=Uo;d[89]=Do;d[90]=Lo;d[91]=_o;d[92]=C;d[93]=C;d[94]=C;d[95]=or("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)d[t]=Bo;d[120]=Mo;d[121]=Po;d[122]=$o;d[123]=Vo;d[124]=C;d[125]=C;d[126]=C;d[127]=or("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)d[t]=zo;d[152]=qo;d[153]=Ko;d[154]=Ho;d[155]=jo;d[156]=C;d[157]=C;d[158]=C;d[159]=Go;for(let t=160;t<=183;t++)d[t]=Yo;d[184]=Xo;d[185]=Jo;d[186]=Wo;d[187]=Qo;d[188]=C;d[189]=C;d[190]=C;d[191]=Zo;for(let t=192;t<=215;t++)d[t]=ei;d[216]=ti;d[217]=ri;d[218]=ni;d[219]=oi;d[220]=C;d[221]=C;d[222]=C;d[223]=C;for(let t=224;t<=243;t++)d[t]=or("simple values are not supported");d[244]=C;d[245]=C;d[246]=C;d[247]=ii;d[248]=or("simple values are not supported");d[249]=ai;d[250]=ci;d[251]=ui;d[252]=C;d[253]=C;d[254]=C;d[255]=si;var ae=[];for(let t=0;t<24;t++)ae[t]=new h(c.uint,t,1);for(let t=-1;t>=-24;t--)ae[31-t]=new h(c.negint,t,1);ae[64]=new h(c.bytes,new Uint8Array(0),1);ae[96]=new h(c.string,"",1);ae[128]=new h(c.array,0,1);ae[160]=new h(c.map,0,1);ae[244]=new h(c.false,!1,1);ae[245]=new h(c.true,!0,1);ae[246]=new h(c.null,null,1);function bn(t){switch(t.type){case c.false:return le([244]);case c.true:return le([245]);case c.null:return le([246]);case c.bytes:return t.value.length?void 0:le([64]);case c.string:return t.value===""?le([96]):void 0;case c.array:return t.value===0?le([128]):void 0;case c.map:return t.value===0?le([160]):void 0;case c.uint:return t.value<24?le([Number(t.value)]):void 0;case c.negint:if(t.value>=-24)return le([31-Number(t.value)])}}var qa={float64:!1,mapSorter:ja,quickEncodeToken:bn},xi=Object.freeze({mapSorter:Ga,quickEncodeToken:bn});function Ka(){let t=[];return t[c.uint.major]=re,t[c.negint.major]=Zt,t[c.bytes.major]=Ge,t[c.string.major]=Oo,t[c.array.major]=tr,t[c.map.major]=rr,t[c.tag.major]=nr,t[c.float.major]=bt,t}var We=Ka(),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)},fe={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?(Ha(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)]}};fe.Map=fe.Object;fe.Buffer=fe.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))fe[`${t}Array`]=fe.DataView;function Je(t,e={},r){let n=fn(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||fe[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=fe[n];if(!i)throw new Error(`${Qt} unsupported type: ${n}`);return i(t,n,e,r)}function Ha(t,e){e.mapSorter&&t.sort(e.mapSorter)}function ja(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 Ga(t,e){if(t[0]instanceof h&&e[0]instanceof h){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=pi(r.value)),n._keyBytes||(n._keyBytes=pi(n.value)),Jt(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function pi(t){return bi(t,We,xi)}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 mi=c.uint.majorEncoded,gi=c.negint.majorEncoded,Ya=c.bytes.majorEncoded,Xa=c.string.majorEncoded,yi=c.array.majorEncoded,Ja=c.float.majorEncoded|hn,Wa=c.float.majorEncoded|pn,Qa=c.float.majorEncoded|mn,Za=c.float.majorEncoded|gn,ec=BigInt(-1),tc=BigInt(1);function rc(t){return t.addBreakTokens!==!0}function wi(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([Qa]);return;case"undefined":t.push([Za]);return;case"boolean":t.push([e?Wa:Ja]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?bt(t,new h(c.float,e),r):e>=0?k(t,mi,e):k(t,gi,e*-1-1);return;case"bigint":e>=BigInt(0)?k(t,mi,e):k(t,gi,e*ec-tc);return;case"string":{let s=Xt(e);k(t,Xa,s.length),t.push(s);return}case"Uint8Array":k(t,Ya,e.length),t.push(e);return;case"Array":if(!e.length){t.push([yi]);return}n=St.createCheck(n,e),k(t,yi,e.length);for(let s of e)wi(t,s,r,n);return;case"Object":case"Map":{let s=fe.Object(e,o,r,n);Et(t,s,We,r)}return;default:{let s=fe[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({},qa,e),rc(e)?(ir.reset(),wi(ir,t,e,void 0),ir.toBytes(!0)):bi(t,We,e)}var nc={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=ae[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 oc(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 ic(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*sc(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 ac(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 sc(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 oc(r,t,e);if(c.equals(r.type,c.map))return ic(r,t,e);if(c.equals(r.type,c.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=ac(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 Ei(t,e){if(!(t instanceof Uint8Array))throw new Error(`${y} data to decode must be a Uint8Array`);e=Object.assign({},nc,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]=Ei(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="/",Si=new TextEncoder().encode(ye),cr=Si[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=Si),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 uc(this.baseNamespace())}name(){return lc(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(),...fc(e.map(r=>r.namespaces()))])}};function uc(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function lc(t){let e=t.split(":");return e[e.length-1]}function fc(t){return[].concat(...t)}var vi=114;var hc=1024*10,Ci=z("/ipns/"),Ii="/ipns/";function pc(t,e){return t.code===e}var ur="/dht/record/",mc="/ipns/metadata/";function Tt(t){return new Ze(ur+Re(t,"base32"),!1)}function lr(t){return new Ze(mc+Re(t,"base32"),!1)}function Ai(t,e){let r=Date.now(),n=e.getTime()+1728e5,o=new Date(t.validity).getTime();return n-r<864e5||o-r<864e5}function Ni(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 Ti(t){try{return`/ipfs/${ce.decode(t)}`}catch{}return Re(t)}async function de(t,e,r,n){if(e.byteLength>hc)throw new Bt("The record is too large");let o=V.decode(e);if(o.signatureV2==null||o.data==null)throw new oe("Missing data or signatureV2");let i=Fi(o.data),s=Re(i.Validity),a,u=gc(t);if(pc(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 xc(o),{value:Ti(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:Ti(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([Ci,t.bytes])}function gc(t){return st(t.slice(Ci.length))}function ki(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 Fi(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 Ui(t){if(t!=null){if(jt(t))return`/ipns/${t.toCID().toV1().toString(te)}`;let e=Di(t);if(e!=null)return e.code===vi?`/ipns/${e.toV1().toString(te)}`:`/ipfs/${e.toV1()}`;if(wc(t))return`/ipns/${te.encode(t.bytes)}`;let r=t.toString().trim();if(r.startsWith("/ipfs/")){let[,n,...o]=r.split("/").filter(i=>i.trim()!=="");return`/ipfs/${ce.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 yc(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=Di(t);if(e!=null){if(e.code!==vi)throw new He("CIDs must have the `libp2p-key` codec");return{digest:e.multihash,path:"/"}}if(yc(t))return{digest:t,path:"/"};if(t=t.toString(),t.startsWith("/ipns/")){let[,,r,...n]=t.split("/"),o=te;(r.startsWith("1")||r.startsWith("Q"))&&(r=`z${r}`,o=K);let i=o.decode(r),s;try{s=ce.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 xc(t){if(t.data==null)throw new Mt("Record data is missing");let e=Fi(t.data);if(!ht(e.Value,t.value??new Uint8Array(0)))throw new oe('Field "value" did not match between protobuf and CBOR');if(!ht(e.Validity,t.validity??new Uint8Array(0)))throw new oe('Field "validity" did not match between protobuf and CBOR');if(e.ValidityType!==t.validityType)throw new oe('Field "validityType" did not match between protobuf and CBOR');if(e.Sequence!==t.sequence)throw new oe('Field "sequence" did not match between protobuf and CBOR');if(e.TTL!==t.ttl)throw new oe('Field "ttl" did not match between protobuf and CBOR')}function wc(t){return t.bytes instanceof Uint8Array}function bc(t){return typeof t?.toCID=="function"}function Di(t){if(bc(t))return t.toCID();try{return ce.parse(t)}catch{}return ce.asCID(t)}var Li=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 oe("Record signature verification failed");if(t.validityType===V.ValidityType.EOL){if(Li.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(Ii))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 de(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 de(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 H=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 Ec(t);if(typeof t=="number")return vc(t,e);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}function Ec(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 Sc(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 Tc(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 vc(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?Tc(t):Sc(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,T=null,G,A;function b(...x){if(!b.enabled)return;let I=b,D=Number(new Date),P=D-(m||D);I.diff=P,I.prev=m,I.curr=D,m=D,x[0]=r.coerce(x[0]),typeof x[0]!="string"&&x.unshift("%O");let R=0;x[0]=x[0].replace(/%([a-zA-Z%])/g,(L,g)=>{if(L==="%%")return"%";R++;let w=r.formatters[g];if(typeof w=="function"){let E=x[R];L=w.call(I,E),x.splice(R,1),R--}return L}),r.formatArgs.call(I,x),p?.onLog!=null&&p.onLog(...x),(I.log||r.log).apply(I,x)}return b.namespace=l,b.useColors=r.useColors(),b.color=r.selectColor(l),b.extend=n,b.destroy=r.destroy,Object.defineProperty(b,"enabled",{enumerable:!0,configurable:!1,get:()=>T!==null?T:(G!==r.namespaces&&(G=r.namespaces,A=r.enabled(l)),A),set:x=>{T=x}}),typeof r.init=="function"&&r.init(b),b}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,]+/),T=m.length;for(p=0;p<T;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=Uc(),Cc=["#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 Ic(){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 Ac(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 Nc=console.debug??console.log??(()=>{});function kc(t){try{t?hr?.setItem("debug",t):hr?.removeItem("debug")}catch{}}function Fc(){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 Uc(){try{return localStorage}catch{}}function Dc(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var _i=Tn({formatArgs:Ac,save:kc,load:Fc,useColors:Ic,setupFormatters:Dc,colors:Cc,storage:hr,log:Nc});var j=_i;j.formatters.b=t=>t==null?"undefined":K.baseEncode(t);j.formatters.t=t=>t==null?"undefined":we.baseEncode(t);j.formatters.m=t=>t==null?"undefined":jr.baseEncode(t);j.formatters.p=t=>t==null?"undefined":t.toString();j.formatters.c=t=>t==null?"undefined":t.toString();j.formatters.k=t=>t==null?"undefined":t.toString();j.formatters.a=t=>t==null?"undefined":t.toString();function Ri(t,e=""){let r=Bi(t.message),n=Bi(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 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(`
10
+ ${e}`)}`:r!=null?`${r}`:`${t.toString()}`}function Lc(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function Mi(t,e=""){if(Lc(t)){let r=Ri(t,e);return t.errors.length>0?(e=`${e} `,r+=`
11
+ ${e}${t.errors.map(n=>`${Mi(n,`${e}`)}`).join(`
12
12
  ${e}`)}`):r+=`
13
- ${e}[Error list was empty]`,r.trim()}return _i(t,e)}j.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 j.enabled(`${t}:trace`)&&j.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=j(`${t}:trace`,e)),Object.assign(j(t,e),{error:j(`${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 T=await Mc(t,e,n,a);m={value:e,signatureV1:T,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 H("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((b,x)=>{i=I=>{i=null,n.push(I);try{b(t(n))}catch(D){x(D)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=rt()})}},f=b=>i!=null?i(b):(n.push(b),o),l=b=>(n=new nt,i!=null?i({error:b}):(n.push({error:b}),o)),p=b=>{if(s)return o;if(e?.objectMode!==!0&&b?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:b})},m=b=>s?o:(s=!0,b!=null?l(b):f({done:!0})),T=()=>(n=new nt,m(),{done:!0}),G=b=>(m(b),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:u,return:T,throw:G,push:p,end:m,get readableLength(){return n.size},onEmpty:async b=>{let x=b?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let I,D;x!=null&&(I=new Promise((P,R)=>{D=()=>{R(new Cn)},x.addEventListener("abort",D)}));try{await Promise.race([a.promise,I])}finally{D!=null&&x!=null&&x?.removeEventListener("abort",D)}}},r==null)return o;let A=o;return o={[Symbol.asyncIterator](){return this},next(){return A.next()},throw(b){return A.throw(b),r!=null&&(r(b),r=void 0),{done:!0}},return(){return A.return(),r!=null&&(r(),r=void 0),{done:!0}},push:p,end(b){return A.end(b),r!=null&&(r(b),r=void 0),o},get readableLength(){return A.readableLength},onEmpty:b=>A.onEmpty(b)},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 T=new In;a=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(G){m(G)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?p():o instanceof Error?m(o):(T.message=o??`Promise timed out after ${r} milliseconds`,m(T))},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(...T)=>{let G=r.multiArgs?T:T[0];if(r.filter)try{if(!await r.filter(G))return}catch(A){n(),s(A);return}u.push(G),r.count===u.length&&(n(),i(u))},m=(...T)=>{n(),s(r.rejectionMultiArgs?T:T[0])};n=()=>{for(let T of a)l(T,p);for(let T of r.rejectionEvents)a.includes(T)||l(T,m)};for(let T of a)f(T,p);for(let T of r.rejectionEvents)a.includes(T)||f(T,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 wr=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 br=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 wr(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 br(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(T){this.log.error("error unmarshaling record - %e",T);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(T){this.log.error("missing key %s, skipping republishing record - %e",a.keyName,T);continue}try{let T=await pr(m,f.value,l,a.lifetime,{...e,ttlNs:p});n.push({routingKey:i,record:T})}catch(T){this.log.error("error creating updated IPNS record for %s - %e",i,T);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 H("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 H("ipns:routing:datastore:error",i)),i}},async get(r,n={}){try{let o=Tt(r);n.onProgress?.(new H("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 H("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 H("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 H("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 H("ipns:routing:helia:error",o)),o}}async get(e,r={}){try{return await this.routing.get(e,r)}catch(n){throw r.onProgress?.(new H("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);})();
13
+ ${e}[Error list was empty]`,r.trim()}return Ri(t,e)}j.formatters.e=t=>t==null?"undefined":Mi(t);function _c(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=_c(`${t}:trace`);return j.enabled(`${t}:trace`)&&j.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=j(`${t}:trace`,e)),Object.assign(j(t,e),{error:j(`${t}:error`,e),trace:r,newScope:n=>vn(`${t}:${n}`,e)})}function Bi(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var Pi=Ir(Pt(),1);var Rc=vn("ipns"),$i=300*1e9,Bc="/ipns/",Wd=Bc.length,Vi={v1Compatible:!0,ttlNs:$i};async function pr(t,e,r,n,o=Vi){let i=new Pi.default(Date.now()+Number(n)),s=V.ValidityType.EOL,a=BigInt(o.ttlNs??$i);return Mc(t,e,r,s,i.toString(),a,o)}var Mc=async(t,e,r,n,o,i,s=Vi)=>{r=BigInt(r);let a=z(o),u=ki(e,n,a,r,i),f=fr(u),l=await t.sign(f,s),p=$c(t.publicKey)?t.publicKey:void 0,m;if(s.v1Compatible===!0){let T=await Pc(t,e,n,a);m={value:e,signatureV1:T,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},Pc=async(t,e,r,n,o)=>{try{let i=Ni(e,r,n);return await t.sign(i,o)}catch(i){throw Rc.error("record signature creation failed",i),new _t("Record signature creation failed")}};function $c(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 de(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(te)}`,publicKey:o.publicKey}}catch(o){throw n.onProgress?.(new H("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 Oi(t={}){return Oc(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 Oc(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((b,x)=>{i=I=>{i=null,n.push(I);try{b(t(n))}catch(D){x(D)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=rt()})}},f=b=>i!=null?i(b):(n.push(b),o),l=b=>(n=new nt,i!=null?i({error:b}):(n.push({error:b}),o)),p=b=>{if(s)return o;if(e?.objectMode!==!0&&b?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:b})},m=b=>s?o:(s=!0,b!=null?l(b):f({done:!0})),T=()=>(n=new nt,m(),{done:!0}),G=b=>(m(b),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:u,return:T,throw:G,push:p,end:m,get readableLength(){return n.size},onEmpty:async b=>{let x=b?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let I,D;x!=null&&(I=new Promise((P,R)=>{D=()=>{R(new Cn)},x.addEventListener("abort",D)}));try{await Promise.race([a.promise,I])}finally{D!=null&&x!=null&&x?.removeEventListener("abort",D)}}},r==null)return o;let A=o;return o={[Symbol.asyncIterator](){return this},next(){return A.next()},throw(b){return A.throw(b),r!=null&&(r(b),r=void 0),{done:!0}},return(){return A.return(),r!=null&&(r(),r=void 0),{done:!0}},push:p,end(b){return A.end(b),r!=null&&(r(b),r=void 0),o},get readableLength(){return A.readableLength},onEmpty:b=>A.onEmpty(b)},o}var In=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},zi=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(zi(s));return}if(s&&(u=()=>{m(zi(s))},s.addEventListener("abort",u,{once:!0})),t.then(p,m),r===Number.POSITIVE_INFINITY)return;let T=new In;a=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(G){m(G)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?p():o instanceof Error?m(o):(T.message=o??`Promise timed out after ${r} milliseconds`,m(T))},r)}).finally(()=>{l.clear(),u&&s&&s.removeEventListener("abort",u)});return l.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},l}var zc=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 qc(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}=zc(t),p=async(...T)=>{let G=r.multiArgs?T:T[0];if(r.filter)try{if(!await r.filter(G))return}catch(A){n(),s(A);return}u.push(G),r.count===u.length&&(n(),i(u))},m=(...T)=>{n(),s(r.rejectionMultiArgs?T:T[0])};n=()=>{for(let T of a)l(T,p);for(let T of r.rejectionEvents)a.includes(T)||l(T,m)};for(let T of a)f(T,p);for(let T of r.rejectionEvents)a.includes(T)||f(T,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=qc(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 Kc(t){return t.reason}async function qi(t,e,r){if(e==null)return t;let n=r?.translateError??Kc;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 wr=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 Hc(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var br=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,r){this.id=Hc(),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 wr(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 qi(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 br(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=Oi({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 Ki(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 Hi(t,e,r){let n,o,i=!1;function s(){let f={signal:o.signal},l;r?.timeout!=null&&(l=Ki([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||Hn,this.started=!1,this.routers=r.routers??[],this.republishTask=Hi(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 de(i,s,this.keychain,e)}catch(T){this.log.error("error unmarshaling record - %e",T);continue}if(!Ai(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(T){this.log.error("missing key %s, skipping republishing record - %e",a.keyName,T);continue}try{let T=await pr(m,f.value,l,a.lifetime,{...e,ttlNs:p});n.push({routingKey:i,record:T})}catch(T){this.log.error("error creating updated IPNS record for %s - %e",i,T);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 ji(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 Gi(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:ji(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=Gi(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 Yi;(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"})(Yi||(Yi={}));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 H("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 H("ipns:routing:datastore:error",i)),i}},async get(r,n={}){try{let o=Tt(r);n.onProgress?.(new H("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 H("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 H("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 H("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 H("ipns:routing:helia:error",o)),o}}async get(e,r={}){try{return await this.routing.get(e,r)}catch(n){throw r.onProgress?.(new H("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(Yc(n))for(let o of Object.values(n.services))Xc(o)&&(o.selectors.ipns=async(i,s)=>{let a=await Promise.all(s.map(u=>de(i,u,this.components.keychain)));return Kt(i,a)},o.validators.ipns=async(i,s)=>{let a=await de(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,Ui(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 Yc(t){return t?.services!=null}function Xc(t){return t?.validators!=null&&t?.selectors!=null}function Jc(t,e={}){return new Cr(t,e)}function Wc(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 ts(Qc);})();
14
14
  return HeliaIpns}));
15
15
  //# sourceMappingURL=index.min.js.map