@helia/ipns 9.2.1-6f8165b5 → 9.2.1-73a28eda

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.
Files changed (65) hide show
  1. package/README.md +12 -49
  2. package/dist/index.min.js +5 -16
  3. package/dist/index.min.js.map +4 -4
  4. package/dist/src/errors.d.ts +33 -5
  5. package/dist/src/errors.d.ts.map +1 -1
  6. package/dist/src/errors.js +33 -20
  7. package/dist/src/errors.js.map +1 -1
  8. package/dist/src/index.d.ts +53 -91
  9. package/dist/src/index.d.ts.map +1 -1
  10. package/dist/src/index.js +12 -52
  11. package/dist/src/index.js.map +1 -1
  12. package/dist/src/ipns/publisher.d.ts +5 -9
  13. package/dist/src/ipns/publisher.d.ts.map +1 -1
  14. package/dist/src/ipns/publisher.js +30 -26
  15. package/dist/src/ipns/publisher.js.map +1 -1
  16. package/dist/src/ipns/republisher.d.ts +3 -5
  17. package/dist/src/ipns/republisher.d.ts.map +1 -1
  18. package/dist/src/ipns/republisher.js +18 -9
  19. package/dist/src/ipns/republisher.js.map +1 -1
  20. package/dist/src/ipns/resolver.d.ts +6 -5
  21. package/dist/src/ipns/resolver.d.ts.map +1 -1
  22. package/dist/src/ipns/resolver.js +32 -79
  23. package/dist/src/ipns/resolver.js.map +1 -1
  24. package/dist/src/ipns.d.ts +6 -4
  25. package/dist/src/ipns.d.ts.map +1 -1
  26. package/dist/src/ipns.js +33 -4
  27. package/dist/src/ipns.js.map +1 -1
  28. package/dist/src/pb/ipns.d.ts +62 -0
  29. package/dist/src/pb/ipns.d.ts.map +1 -0
  30. package/dist/src/pb/ipns.js +203 -0
  31. package/dist/src/pb/ipns.js.map +1 -0
  32. package/dist/src/records.d.ts +155 -0
  33. package/dist/src/records.d.ts.map +1 -0
  34. package/dist/src/records.js +88 -0
  35. package/dist/src/records.js.map +1 -0
  36. package/dist/src/routing/pubsub.d.ts +3 -0
  37. package/dist/src/routing/pubsub.d.ts.map +1 -1
  38. package/dist/src/routing/pubsub.js +15 -11
  39. package/dist/src/routing/pubsub.js.map +1 -1
  40. package/dist/src/selector.d.ts +14 -0
  41. package/dist/src/selector.d.ts.map +1 -0
  42. package/dist/src/selector.js +47 -0
  43. package/dist/src/selector.js.map +1 -0
  44. package/dist/src/utils.d.ts +29 -2
  45. package/dist/src/utils.d.ts.map +1 -1
  46. package/dist/src/utils.js +308 -0
  47. package/dist/src/utils.js.map +1 -1
  48. package/dist/src/validator.d.ts +18 -0
  49. package/dist/src/validator.d.ts.map +1 -0
  50. package/dist/src/validator.js +58 -0
  51. package/dist/src/validator.js.map +1 -0
  52. package/package.json +9 -8
  53. package/src/errors.ts +40 -25
  54. package/src/index.ts +54 -92
  55. package/src/ipns/publisher.ts +34 -33
  56. package/src/ipns/republisher.ts +24 -13
  57. package/src/ipns/resolver.ts +40 -89
  58. package/src/ipns.ts +44 -7
  59. package/src/pb/ipns.proto +39 -0
  60. package/src/pb/ipns.ts +280 -0
  61. package/src/records.ts +273 -0
  62. package/src/routing/pubsub.ts +17 -11
  63. package/src/selector.ts +55 -0
  64. package/src/utils.ts +371 -2
  65. package/src/validator.ts +67 -0
package/dist/index.min.js CHANGED
@@ -1,26 +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 b0=Object.create;var Ro=Object.defineProperty;var x0=Object.getOwnPropertyDescriptor;var w0=Object.getOwnPropertyNames;var E0=Object.getPrototypeOf,S0=Object.prototype.hasOwnProperty;var A0=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),z=(t,e)=>{for(var r in e)Ro(t,r,{get:e[r],enumerable:!0})},Zu=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of w0(e))!S0.call(t,o)&&o!==r&&Ro(t,o,{get:()=>e[o],enumerable:!(n=x0(e,o))||n.enumerable});return t};var Ss=(t,e,r)=>(r=t!=null?b0(E0(t)):{},Zu(e||!t||!t.__esModule?Ro(r,"default",{value:t,enumerable:!0}):r,t)),v0=t=>Zu(Ro({},"__esModule",{value:!0}),t);var Ai=A0((C3,ac)=>{var B3=(function(){typeof ac<"u"&&(ac.exports=y);var t=86400,e=3200,r=146097*e/400,n=t*r,o=1e3*n,i=864e13,s=4294967296,a=1e6,c="000000000",u=Math.trunc||function(x){var D=x-x%1;return D==0&&(x<0||x===0&&1/x!=1/0)?-0:D},f=y.prototype,l=(y.fromDate=function(x){return new y(+x)},y.fromInt64BE=C(0,1,2,3,0,4),y.fromInt64LE=C(3,2,1,0,4,0),y.fromString=function(k){var D,M=new y,k=(k+="").replace(/^\s*[+\-]?\d+/,function(S){var S=+S,T=1970+(S-1970)%400;return M.year=S-T,T}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(p,S,T){return S<0&&(T*=-1),D=6e4*(60*+S+ +T),""}).replace(/\.\d+$/,function(p){return M.nano=+(p+c).substr(1,9),""}).split(/\D+/);if(1<k.length?k[1]--:k[1]=0,M.time=D=Date.UTC.apply(Date,k)-(D||0),isNaN(D))throw new TypeError("Invalid Date");return d(M)},y.fromTimeT=function(x){return E(x,0)},f.year=0,f.time=0,f.nano=0,f.addNano=function(x){return this.nano+=+x||0,this},f.getNano=function(){var x=d(this);return(x.time%1e3*a+ +x.nano+1e9)%1e9},f.getTimeT=function(){var D=d(this),x=Math.floor(D.time/1e3),D=D.year;return D&&(x+=D*r*t/e),x},f.getYear=function(){return this.toDate().getUTCFullYear()+this.year},f.toDate=function(){return g(d(this).time)},f.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},f.toString=function(x){var D=this,M=D.toDate(),k={H:function(){return R(M.getUTCHours())},L:function(){return _(M.getUTCMilliseconds(),3)},M:function(){return R(M.getUTCMinutes())},N:function(){return _(D.getNano(),9)},S:function(){return R(M.getUTCSeconds())},Y:function(){var p=D.getYear();return 999999<p?"+"+p:9999<p?"+"+_(p,6):0<=p?_(p,4):-999999<=p?"-"+_(-p,6):p},a:function(){return b[M.getUTCDay()]},b:function(){return m[M.getUTCMonth()]},d:function(){return R(M.getUTCDate())},e:function(){return(function(p){return(9<p?"":" ")+(0|p)})(M.getUTCDate())},m:function(){return R(M.getUTCMonth()+1)}};return(function p(S){return S.replace(/%./g,function(T){var v=T[1],A=h[v],v=k[v];return A?p(A):v?v():T})})(x||l)},f.writeInt64BE=I(0,1,2,3,0,4),f.writeInt64LE=I(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),m=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],b=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],h={"%":"%",F:"%Y-%m-%d",n:`
3
- `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return y;function y(x,D,M){var k=this;if(!(k instanceof y))return new y(x,D,M);k.time=+x||0,k.nano=+D||0,k.year=+M||0,d(k)}function d(x){var D,M,k,p=x.year,S=x.time,T=x.nano,A=((T<0||a<=T)&&(T-=(M=Math.floor(T/a))*a,S+=M,M=1),p%e);return(S<-i||i<S||A)&&((D=u(S/o))&&(p+=D*e,S-=D*o),(k=g(S)).setUTCFullYear(A+k.getUTCFullYear()),k=(S=+k)+(D=u((p-=A)/e))*o,D&&-i<=k&&k<=i&&(p-=D*e,S=k),M=1),M&&(x.year=p,x.time=S,x.nano=T),x}function g(x){var D=new Date(0);return D.setTime(x),D}function E(p,k){p=+p||0;var M=u((k=(k|0)*s)/n)+u(p/n),k=k%n+p%n,p=u(k/n);return p&&(M+=p,k-=p*n),new y(1e3*k,0,M*e)}function I(x,D,M,k,p,S){return function(A,v){var L=d(this);A=A||new Array(8),B(A,v|=0);var N=Math.floor(L.time/1e3),L=L.year*(r*t/e),F=u(L/s)+u(N/s),L=L%s+N%s,N=Math.floor(L/s);return N&&(F+=N,L-=N*s),T(A,v+p,F),T(A,v+S,L),A};function T(A,v,F){A[v+x]=F>>24&255,A[v+D]=F>>16&255,A[v+M]=F>>8&255,A[v+k]=255&F}}function C(x,D,M,k,p,S){return function(A,v){B(A,v|=0);var F=T(A,v+p);return E(T(A,v+S),F)};function T(A,v){return 16777216*A[v+x]+(A[v+D]<<16|A[v+M]<<8|A[v+k])}}function B(x,D){if(x=x&&x.length,x==null)throw new TypeError("Invalid Buffer");if(x<D+8)throw new RangeError("Out of range")}function R(x){return(9<x?"":"0")+(0|x)}function _(x,D){return(c+(0|x)).substr(-D)}})()});var C2={};z(C2,{ipns:()=>T2,ipnsResolver:()=>B2,ipnsSelector:()=>Qi,ipnsValidator:()=>yo});var mt=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var W=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Ar=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},mn=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var No=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var vr=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};function Xu(t){return t==null?!1:(t.type==="RSA"||t.type==="Ed25519"||t.type==="secp256k1"||t.type==="ECDSA")&&t.raw instanceof Uint8Array&&typeof t.equals=="function"&&typeof t.toMultihash=="function"&&typeof t.toCID=="function"&&typeof t.verify=="function"}var I0=Symbol.for("@libp2p/peer-id");function ko(t){return!!t?.[I0]}function T0(t){return typeof t?.handleEvent=="function"}function B0(t){return(t!==!0&&t!==!1&&t?.once)??!1}var Oo=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=B0(n);super.addEventListener(e,s=>{if(o){let a=this.#e.get(s.type);a!=null&&(a=a.filter(({callback:c})=>c!==r),this.#e.set(s.type,a))}T0(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 Bs={};z(Bs,{base58btc:()=>fe,base58flickr:()=>R0});var R2=new Uint8Array(0);function Wu(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 gt(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function Ju(t){return new TextEncoder().encode(t)}function Qu(t){return new TextDecoder().decode(t)}function C0(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var y=0,d=0,g=0,E=h.length;g!==E&&h[g]===0;)g++,y++;for(var I=(E-g)*f+1>>>0,C=new Uint8Array(I);g!==E;){for(var B=h[g],R=0,_=I-1;(B!==0||R<d)&&_!==-1;_--,R++)B+=256*C[_]>>>0,C[_]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");d=R,g++}for(var x=I-d;x!==I&&C[x]===0;)x++;for(var D=c.repeat(y);x<I;++x)D+=t.charAt(C[x]);return D}function m(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var y=0;if(h[y]!==" "){for(var d=0,g=0;h[y]===c;)d++,y++;for(var E=(h.length-y)*u+1>>>0,I=new Uint8Array(E);h[y];){var C=r[h.charCodeAt(y)];if(C===255)return;for(var B=0,R=E-1;(C!==0||B<g)&&R!==-1;R--,B++)C+=a*I[R]>>>0,I[R]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");g=B,y++}if(h[y]!==" "){for(var _=E-g;_!==E&&I[_]===0;)_++;for(var x=new Uint8Array(d+(E-_)),D=d;_!==E;)x[D++]=I[_++];return x}}}function b(h){var y=m(h);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:m,decode:b}}var _0=C0,D0=_0,tf=D0;var As=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")}},vs=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 rf(this,e)}},Is=class{decoders;constructor(e){this.decoders=e}or(e){return rf(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 rf(t,e){return new Is({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Ts=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 As(e,r,n),this.decoder=new vs(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ir({name:t,prefix:e,encode:r,decode:n}){return new Ts(t,e,r,n)}function Ct({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=tf(r,t);return Ir({prefix:e,name:t,encode:n,decode:i=>gt(o(i))})}function F0(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,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function U0(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],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 L0(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function J({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=L0(n);return Ir({prefix:e,name:t,encode(i){return U0(i,n,r)},decode(i){return F0(i,o,r,t)}})}var fe=Ct({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),R0=Ct({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Cs={};z(Cs,{base32:()=>Tr,base32hex:()=>M0,base32hexpad:()=>K0,base32hexpadupper:()=>V0,base32hexupper:()=>P0,base32pad:()=>k0,base32padupper:()=>O0,base32upper:()=>N0,base32z:()=>z0});var Tr=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),N0=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),k0=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),O0=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),M0=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),P0=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),K0=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),V0=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),z0=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var _s={};z(_s,{base36:()=>gn,base36upper:()=>$0});var gn=Ct({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),$0=Ct({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var q0=sf,nf=128,H0=127,j0=~H0,Y0=Math.pow(2,31);function sf(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Y0;)e[r++]=t&255|nf,t/=128;for(;t&j0;)e[r++]=t&255|nf,t>>>=7;return e[r]=t|0,sf.bytes=r-n+1,e}var G0=Ds,Z0=128,of=127;function Ds(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw Ds.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&of)<<o:(s&of)*Math.pow(2,o),o+=7}while(s>=Z0);return Ds.bytes=i-n,r}var X0=Math.pow(2,7),W0=Math.pow(2,14),J0=Math.pow(2,21),Q0=Math.pow(2,28),em=Math.pow(2,35),tm=Math.pow(2,42),rm=Math.pow(2,49),nm=Math.pow(2,56),om=Math.pow(2,63),im=function(t){return t<X0?1:t<W0?2:t<J0?3:t<Q0?4:t<em?5:t<tm?6:t<rm?7:t<nm?8:t<om?9:10},sm={encode:q0,decode:G0,encodingLength:im},am=sm,yn=am;function bn(t,e=0){return[yn.decode(t,e),yn.decode.bytes]}function Br(t,e,r=0){return yn.encode(t,e,r),e}function Cr(t){return yn.encodingLength(t)}function st(t,e){let r=e.byteLength,n=Cr(t),o=n+Cr(r),i=new Uint8Array(o+r);return Br(t,i,0),Br(r,i,n),i.set(e,o),new _r(t,r,e,i)}function af(t){let e=gt(t),[r,n]=bn(e),[o,i]=bn(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new _r(r,o,s,e)}function cf(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Wu(t.bytes,r.bytes)}}var _r=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function uf(t,e){let{bytes:r,version:n}=t;return n===0?um(r,Fs(t),e??fe.encoder):fm(r,Fs(t),e??Tr.encoder)}var ff=new WeakMap;function Fs(t){let e=ff.get(t);if(e==null){let r=new Map;return ff.set(t,r),r}return e}var ze=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==wn)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==lm)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=st(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&&cf(e.multihash,n.multihash)}toString(e){return uf(this,e)}toJSON(){return{"/":uf(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??lf(n,o,i.bytes))}else if(r[hm]===!0){let{version:n,multihash:o,code:i}=r,s=af(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!==wn)throw new Error(`Version 0 CID must use dag-pb (code: ${wn}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=lf(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,wn,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=gt(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 _r(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[l,m]=bn(e.subarray(r));return r+=m,l},o=n(),i=wn;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),u=r+c,f=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=cm(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 Fs(i).set(n,e),i}};function cm(t,e){switch(t[0]){case"Q":{let r=e??fe;return[fe.prefix,r.decode(`${fe.prefix}${t}`)]}case fe.prefix:{let r=e??fe;return[fe.prefix,r.decode(t)]}case Tr.prefix:{let r=e??Tr;return[Tr.prefix,r.decode(t)]}case gn.prefix:{let r=e??gn;return[gn.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 um(t,e,r){let{prefix:n}=r;if(n!==fe.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 fm(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 wn=112,lm=18;function lf(t,e,r){let n=Cr(t),o=n+Cr(e),i=new Uint8Array(o+r.byteLength);return Br(t,i,0),Br(e,i,n),i.set(r,o),i}var hm=Symbol.for("@ipld/js-cid/CID");var Us={};z(Us,{identity:()=>er});var hf=0,dm="identity",df=gt;function pm(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 st(hf,df(t))}var er={code:hf,name:dm,encode:df,digest:pm};function Be(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}async function pf(t="P-256"){let e=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:t},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",e.publicKey),privateKey:await crypto.subtle.exportKey("jwk",e.privateKey)}}async function mf(t,e,r){let n=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["sign"]);r?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,e.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function gf(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,e,r.subarray());return n?.signal?.throwIfAborted(),i}function yt(t=0){return new Uint8Array(t)}function Ue(t=0){return new Uint8Array(t)}function Po(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 r}var bf=Symbol.for("@achingbrain/uint8arraylist");function yf(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function Ko(t){return!!t?.[bf]}var xe=class t{bufs;length;[bf]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Ko(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Ko(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=yf(this.bufs,e);return r.buf[r.index]}set(e,r){let n=yf(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(Ko(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return Po(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:Po(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),i=new t;return i.length=o,i.bufs=n,i}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(s);break}let l=e-a;n.push(s.subarray(l,l+(r-e)));break}if(u){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(f){if(r===c){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Ko(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let m=u;m>=0;m--){let b=this.get(l+m);if(n[m]!==b){f=Math.max(1,m-a[b]);break}}if(f===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Ue(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=yt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=yt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=yt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Ue(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=yt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=yt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=yt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=yt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=yt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!Be(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};var Ls={};z(Ls,{base10:()=>mm});var mm=Ct({prefix:"9",name:"base10",alphabet:"0123456789"});var Rs={};z(Rs,{base16:()=>gm,base16upper:()=>ym});var gm=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ym=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ns={};z(Ns,{base2:()=>bm});var bm=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ks={};z(ks,{base256emoji:()=>Am});var xf=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}"),xm=xf.reduce((t,e,r)=>(t[r]=e,t),[]),wm=xf.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Em(t){return t.reduce((e,r)=>(e+=xm[r],e),"")}function Sm(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=wm[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Am=Ir({prefix:"\u{1F680}",name:"base256emoji",encode:Em,decode:Sm});var Os={};z(Os,{base64:()=>vm,base64pad:()=>Im,base64url:()=>Tm,base64urlpad:()=>Bm});var vm=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Im=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Tm=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Bm=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ms={};z(Ms,{base8:()=>Cm});var Cm=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ps={};z(Ps,{identity:()=>_m});var _m=Ir({prefix:"\0",name:"identity",encode:t=>Qu(t),decode:t=>Ju(t)});var b1=new TextEncoder,x1=new TextDecoder;var zs={};z(zs,{sha256:()=>Vo,sha512:()=>Lm});var Um=20;function Vs({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Ks(t,e,r,n,o)}var Ks=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Um,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?wf(n,this.code,r?.truncate):n.then(o=>wf(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function wf(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 st(e,t)}function Sf(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Vo=Vs({name:"sha2-256",code:18,encode:Sf("SHA-256")}),Lm=Vs({name:"sha2-512",code:19,encode:Sf("SHA-512")});var $s={...Ps,...Ns,...Ms,...Ls,...Rs,...Cs,..._s,...Bs,...Os,...ks},F1={...zs,...Us};function vf(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Af=vf("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),qs=vf("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}),Rm={utf8:Af,"utf-8":Af,hex:$s.base16,latin1:qs,ascii:qs,binary:qs,...$s},zo=Rm;function Q(t,e="utf8"){let r=zo[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function oe(t,e="utf8"){let r=zo[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var Nm=parseInt("11111",2),Hs=parseInt("10000000",2),km=parseInt("01111111",2),If={0:En,1:En,2:Om,3:Km,4:Vm,5:Pm,6:Mm,16:En,22:En,48:En};function bt(t,e={offset:0}){let r=t[e.offset]&Nm;if(e.offset++,If[r]!=null)return If[r](t,e);throw new Error("No decoder for tag "+r)}function Sn(t,e){let r=0;if((t[e.offset]&Hs)===Hs){let n=t[e.offset]&km,o="0x";e.offset++;for(let i=0;i<n;i++,e.offset++)o+=t[e.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=t[e.offset],e.offset++;return r}function En(t,e){Sn(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=bt(t,e);if(n===null)break;r.push(n)}return r}function Om(t,e){let r=Sn(t,e),n=e.offset,o=e.offset+r,i=[];for(let s=n;s<o;s++)s===n&&t[s]===0||i.push(t[s]);return e.offset+=r,Uint8Array.from(i)}function Mm(t,e){let r=Sn(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function Pm(t,e){return e.offset++,null}function Km(t,e){let r=Sn(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Vm(t,e){let r=Sn(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function zm(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new xe;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function $o(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=zm(t.byteLength);return new xe(Uint8Array.from([e.byteLength|Hs]),e)}function we(t){let e=new xe,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new xe(Uint8Array.from([2]),$o(e),e)}function An(t){let e=Uint8Array.from([0]),r=new xe(e,t);return new xe(Uint8Array.from([3]),$o(r),r)}function Tf(t){return new xe(Uint8Array.from([4]),$o(t),t)}function je(t,e=48){let r=new xe;for(let n of t)r.append(n);return new xe(Uint8Array.from([e]),$o(r),r)}var $m=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),qm=Uint8Array.from([6,5,43,129,4,0,34]),Hm=Uint8Array.from([6,5,43,129,4,0,35]),jm={ext:!0,kty:"EC",crv:"P-256"},Ym={ext:!0,kty:"EC",crv:"P-384"},Gm={ext:!0,kty:"EC",crv:"P-521"},js=32,Ys=48,Gs=66;function Zs(t){let e=bt(t);return Bf(e)}function Bf(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===js*2+1)return n=oe(e.subarray(r,r+js),"base64url"),o=oe(e.subarray(r+js),"base64url"),new tr({...jm,key_ops:["verify"],x:n,y:o});if(e.byteLength===Ys*2+1)return n=oe(e.subarray(r,r+Ys),"base64url"),o=oe(e.subarray(r+Ys),"base64url"),new tr({...Ym,key_ops:["verify"],x:n,y:o});if(e.byteLength===Gs*2+1)return n=oe(e.subarray(r,r+Gs),"base64url"),o=oe(e.subarray(r+Gs),"base64url"),new tr({...Gm,key_ops:["verify"],x:n,y:o});throw new W(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Cf(t){return je([we(Uint8Array.from([1])),Tf(Q(t.d??"","base64url")),je([Df(t.crv)],160),je([An(new xe(Uint8Array.from([4]),Q(t.x??"","base64url"),Q(t.y??"","base64url")))],161)]).subarray()}function _f(t){return je([we(Uint8Array.from([1])),je([Df(t.crv)],160),je([An(new xe(Uint8Array.from([4]),Q(t.x??"","base64url"),Q(t.y??"","base64url")))],161)]).subarray()}function Df(t){if(t==="P-256")return $m;if(t==="P-384")return qm;if(t==="P-521")return Hm;throw new W(`Invalid curve ${t}`)}async function Ff(t="P-256"){let e=await pf(t);return new qo(e.privateKey)}var tr=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=_f(this.jwk)),this._raw}toMultihash(){return er.digest(_t(this))}toCID(){return ze.createV1(114,this.toMultihash())}toString(){return fe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Be(this.raw,e.raw)}async verify(e,r,n){return gf(this.jwk,r,e,n)}},qo=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new tr({crv:e.crv,ext:e.ext,key_ops:["verify"],kty:"EC",x:e.x,y:e.y})}get raw(){return this._raw==null&&(this._raw=Cf(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Be(this.raw,e.raw)}async sign(e,r){return mf(this.jwk,e,r)}};function Xs(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function Dt(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(`${r}expected number, got ${typeof t}`)}if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new RangeError(`${r}expected integer >= 0, got ${t}`)}}function Le(t,e,r=""){let n=Xs(t),o=t?.length,i=e!==void 0;if(!n||i&&o!==e){let s=r&&`"${r}" `,a=i?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof t}`,u=s+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return t}function Ho(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Dt(t.outputLen),Dt(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Dr(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function jo(t,e){Le(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function wt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Yo(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Ye(t,e){return t<<32-e|t>>>e}var Lf=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Zm=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Go(t){if(Le(t),Lf)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Zm[t[r]];return e}var xt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Uf(t){if(t>=xt._0&&t<=xt._9)return t-xt._0;if(t>=xt.A&&t<=xt.F)return t-(xt.A-10);if(t>=xt.a&&t<=xt.f)return t-(xt.a-10)}function vn(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Lf)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=Uf(t.charCodeAt(i)),a=Uf(t.charCodeAt(i+1));if(s===void 0||a===void 0){let c=t[i]+t[i+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function Ws(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Le(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let i=t[n];r.set(i,o),o+=i.length}return r}function Js(t,e={}){let r=(o,i)=>t(i).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function Rf(t=32){Dt(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var Qs=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Nf(t,e,r){return t&e^~t&r}function kf(t,e,r){return t&e^t&r^e&r}var In=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Yo(this.buffer)}update(e){Dr(this),Le(e);let{view:r,buffer:n,blockLen:o}=this,i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=Yo(e);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Dr(this),jo(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,wt(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),i),this.process(n,0);let a=Yo(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],i)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return e.destroyed=s,e.finished=i,e.length=o,e.pos=a,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Et=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var de=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Zo=BigInt(4294967295),Of=BigInt(32);function Xm(t,e=!1){return e?{h:Number(t&Zo),l:Number(t>>Of&Zo)}:{h:Number(t>>Of&Zo)|0,l:Number(t&Zo)|0}}function Mf(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let i=0;i<r;i++){let{h:s,l:a}=Xm(t[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var ea=(t,e,r)=>t>>>r,ta=(t,e,r)=>t<<32-r|e>>>r,rr=(t,e,r)=>t>>>r|e<<32-r,nr=(t,e,r)=>t<<32-r|e>>>r,Tn=(t,e,r)=>t<<64-r|e>>>r-32,Bn=(t,e,r)=>t>>>r-32|e<<64-r;function at(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Pf=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Kf=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Vf=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),zf=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,$f=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),qf=(t,e,r,n,o,i)=>e+r+n+o+i+(t/2**32|0)|0;var Jm=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Ft=new Uint32Array(64),ra=class extends In{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,r,n,o,i,s,a,c]}set(e,r,n,o,i,s,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,r){for(let l=0;l<16;l++,r+=4)Ft[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let m=Ft[l-15],b=Ft[l-2],h=Ye(m,7)^Ye(m,18)^m>>>3,y=Ye(b,17)^Ye(b,19)^b>>>10;Ft[l]=y+Ft[l-7]+h+Ft[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let m=Ye(a,6)^Ye(a,11)^Ye(a,25),b=f+m+Nf(a,c,u)+Jm[l]+Ft[l]|0,y=(Ye(n,2)^Ye(n,13)^Ye(n,22))+kf(n,o,i)|0;f=u,u=c,c=a,a=s+b|0,s=i,i=o,o=n,n=b+y|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,i,s,a,c,u,f)}roundClean(){wt(Ft)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),wt(this.buffer)}},na=class extends ra{A=Et[0]|0;B=Et[1]|0;C=Et[2]|0;D=Et[3]|0;E=Et[4]|0;F=Et[5]|0;G=Et[6]|0;H=Et[7]|0;constructor(){super(32)}};var Hf=Mf(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),Qm=Hf[0],eg=Hf[1],Ut=new Uint32Array(80),Lt=new Uint32Array(80),oa=class extends In{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:m,Gh:b,Gl:h,Hh:y,Hl:d}=this;return[e,r,n,o,i,s,a,c,u,f,l,m,b,h,y,d]}set(e,r,n,o,i,s,a,c,u,f,l,m,b,h,y,d){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=m|0,this.Gh=b|0,this.Gl=h|0,this.Hh=y|0,this.Hl=d|0}process(e,r){for(let I=0;I<16;I++,r+=4)Ut[I]=e.getUint32(r),Lt[I]=e.getUint32(r+=4);for(let I=16;I<80;I++){let C=Ut[I-15]|0,B=Lt[I-15]|0,R=rr(C,B,1)^rr(C,B,8)^ea(C,B,7),_=nr(C,B,1)^nr(C,B,8)^ta(C,B,7),x=Ut[I-2]|0,D=Lt[I-2]|0,M=rr(x,D,19)^Tn(x,D,61)^ea(x,D,6),k=nr(x,D,19)^Bn(x,D,61)^ta(x,D,6),p=Vf(_,k,Lt[I-7],Lt[I-16]),S=zf(p,R,M,Ut[I-7],Ut[I-16]);Ut[I]=S|0,Lt[I]=p|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:m,Fh:b,Fl:h,Gh:y,Gl:d,Hh:g,Hl:E}=this;for(let I=0;I<80;I++){let C=rr(l,m,14)^rr(l,m,18)^Tn(l,m,41),B=nr(l,m,14)^nr(l,m,18)^Bn(l,m,41),R=l&b^~l&y,_=m&h^~m&d,x=$f(E,B,_,eg[I],Lt[I]),D=qf(x,g,C,R,Qm[I],Ut[I]),M=x|0,k=rr(n,o,28)^Tn(n,o,34)^Tn(n,o,39),p=nr(n,o,28)^Bn(n,o,34)^Bn(n,o,39),S=n&i^n&a^i&a,T=o&s^o&c^s&c;g=y|0,E=d|0,y=b|0,d=h|0,b=l|0,h=m|0,{h:l,l:m}=at(u|0,f|0,D|0,M|0),u=a|0,f=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let A=Pf(M,p,T);n=Kf(A,D,k,S),o=A|0}({h:n,l:o}=at(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=at(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=at(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=at(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:m}=at(this.Eh|0,this.El|0,l|0,m|0),{h:b,l:h}=at(this.Fh|0,this.Fl|0,b|0,h|0),{h:y,l:d}=at(this.Gh|0,this.Gl|0,y|0,d|0),{h:g,l:E}=at(this.Hh|0,this.Hl|0,g|0,E|0),this.set(n,o,i,s,a,c,u,f,l,m,b,h,y,d,g,E)}roundClean(){wt(Ut,Lt)}destroy(){this.destroyed=!0,wt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ia=class extends oa{Ah=de[0]|0;Al=de[1]|0;Bh=de[2]|0;Bl=de[3]|0;Ch=de[4]|0;Cl=de[5]|0;Dh=de[6]|0;Dl=de[7]|0;Eh=de[8]|0;El=de[9]|0;Fh=de[10]|0;Fl=de[11]|0;Gh=de[12]|0;Gl=de[13]|0;Hh=de[14]|0;Hl=de[15]|0;constructor(){super(64)}};var Fr=Js(()=>new na,Qs(1));var Xo=Js(()=>new ia,Qs(3));var H=(t,e,r)=>Le(t,e,r),aa=Dt,Ur=Go,ae=(...t)=>Ws(...t),Lr=t=>vn(t),or=Xs,Cn=t=>Rf(t),Jo=BigInt(0),sa=BigInt(1);function Ge(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function Qo(t){if(typeof t=="bigint"){if(!Wo(t))throw new RangeError("positive bigint expected, got "+t)}else aa(t);return t}function Ze(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function _n(t){let e=Qo(t).toString(16);return e.length&1?"0"+e:e}function jf(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Jo:BigInt("0x"+t)}function ir(t){return jf(Go(t))}function ct(t){return jf(Go(Dn(Le(t)).reverse()))}function ei(t,e){if(Dt(e),e===0)throw new RangeError("zero length");t=Qo(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return vn(r.padStart(e*2,"0"))}function ca(t,e){return ei(t,e).reverse()}function Yf(t,e){if(t=H(t),e=H(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function Dn(t){return Uint8Array.from(H(t))}function ti(t){if(typeof t!="string")throw new TypeError("ascii string expected, got "+typeof t);return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var Wo=t=>typeof t=="bigint"&&Jo<=t;function tg(t,e,r){return Wo(t)&&Wo(e)&&Wo(r)&&e<=t&&t<r}function Rr(t,e,r,n){if(!tg(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Nr(t){if(t<Jo)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>Jo;t>>=sa,e+=1);return e}var Fn=t=>(sa<<BigInt(t))-sa;function Gf(t,e,r){if(Dt(t,"hashLen"),Dt(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=d=>new Uint8Array(d),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,l=()=>{c.fill(1),u.fill(0),f=0},m=(...d)=>r(u,ae(c,...d)),b=(d=o)=>{u=m(i,d),c=m(),d.length!==0&&(u=m(s,d),c=m())},h=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let d=0,g=[];for(;d<e;){c=m();let E=c.slice();g.push(E),d+=c.length}return ae(...g)};return(d,g)=>{l(),b(d);let E;for(;(E=g(h()))===void 0;)b();return l(),E}}function Xe(t,e={},r={}){if(Object.prototype.toString.call(t)!=="[object Object]")throw new TypeError("expected valid options object");function n(i,s,a){if(!a&&s!=="function"&&!Object.hasOwn(t,i))throw new TypeError(`param "${i}" is invalid: expected own property`);let c=t[i];if(a&&c===void 0)return;let u=typeof c;if(u!==s||c===null)throw new TypeError(`param "${i}" is invalid: expected ${s}, got ${u}`)}let o=(i,s)=>Object.entries(i).forEach(([a,c])=>n(a,c,s));o(e,!1),o(r,!0)}var ua=()=>{throw new Error("not implemented")};var pe=BigInt(0),ee=BigInt(1),sr=BigInt(2),Jf=BigInt(3),Qf=BigInt(4),el=BigInt(5),rg=BigInt(7),tl=BigInt(8),ng=BigInt(9),rl=BigInt(16);function ie(t,e){if(e<=pe)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=pe?r:e+r}function Z(t,e,r){if(e<pe)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >pe;)n*=n,n%=r;return n}function Zf(t,e){if(t===pe)throw new Error("invert: expected non-zero number");if(e<=pe)throw new Error("invert: expected positive modulus, got "+e);let r=ie(t,e),n=e,o=pe,i=ee,s=ee,a=pe;for(;r!==pe;){let u=n/r,f=n-r*u,l=o-s*u,m=i-a*u;n=r,r=f,o=s,i=a,s=l,a=m}if(n!==ee)throw new Error("invert: does not exist");return ie(o,e)}function fa(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function nl(t,e){let r=t,n=(r.ORDER+ee)/Qf,o=r.pow(e,n);return fa(r,o,e),o}function og(t,e){let r=t,n=(r.ORDER-el)/tl,o=r.mul(e,sr),i=r.pow(o,n),s=r.mul(e,i),a=r.mul(r.mul(s,sr),i),c=r.mul(s,r.sub(a,r.ONE));return fa(r,c,e),c}function ig(t){let e=kr(t),r=ol(t),n=r(e,e.neg(e.ONE)),o=r(e,n),i=r(e,e.neg(n)),s=(t+rg)/rl;return((a,c)=>{let u=a,f=u.pow(c,s),l=u.mul(f,n),m=u.mul(f,o),b=u.mul(f,i),h=u.eql(u.sqr(l),c),y=u.eql(u.sqr(m),c);f=u.cmov(f,l,h),l=u.cmov(b,m,y);let d=u.eql(u.sqr(l),c),g=u.cmov(f,l,d);return fa(u,g,c),g})}function ol(t){if(t<Jf)throw new Error("sqrt is not defined for small field");let e=t-ee,r=0;for(;e%sr===pe;)e/=sr,r++;let n=sr,o=kr(t);for(;Xf(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return nl;let i=o.pow(n,e),s=(e+ee)/sr;return function(c,u){let f=c;if(f.is0(u))return u;if(Xf(f,u)!==1)throw new Error("Cannot find square root");let l=r,m=f.mul(f.ONE,i),b=f.pow(u,e),h=f.pow(u,s);for(;!f.eql(b,f.ONE);){if(f.is0(b))return f.ZERO;let y=1,d=f.sqr(b);for(;!f.eql(d,f.ONE);)if(y++,d=f.sqr(d),y===l)throw new Error("Cannot find square root");let g=ee<<BigInt(l-y-1),E=f.pow(m,g);l=y,m=f.sqr(E),b=f.mul(b,m),h=f.mul(h,E)}return h}}function sg(t){return t%Qf===Jf?nl:t%tl===el?og:t%rl===ng?ig(t):ol(t)}var St=(t,e)=>(ie(t,e)&ee)===ee,ag=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function la(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=ag.reduce((n,o)=>(n[o]="function",n),e);if(Xe(t,r),Ze(t.BYTES,"BYTES"),Ze(t.BITS,"BITS"),t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=ee)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function cg(t,e,r){let n=t;if(r<pe)throw new Error("invalid exponent, negatives unsupported");if(r===pe)return n.ONE;if(r===ee)return e;let o=n.ONE,i=e;for(;r>pe;)r&ee&&(o=n.mul(o,i)),i=n.sqr(i),r>>=ee;return o}function Un(t,e,r=!1){let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),i=e.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),s=n.inv(i);return e.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),s),o}function Xf(t,e){let r=t,n=(r.ORDER-ee)/sr,o=r.pow(e,n),i=r.eql(o,r.ONE),s=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!i&&!s&&!a)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function ug(t,e){if(e!==void 0&&aa(e),t<=pe)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Nr(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${e})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Wf=new WeakMap,ri=class{ORDER;BITS;BYTES;isLE;ZERO=pe;ONE=ee;_lengths;_mod;constructor(e,r={}){if(e<=ee)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:i}=ug(e,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=i,Object.freeze(this)}create(e){return ie(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return pe<=e&&e<this.ORDER}is0(e){return e===pe}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&ee)===ee}neg(e){return ie(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ie(e*e,this.ORDER)}add(e,r){return ie(e+r,this.ORDER)}sub(e,r){return ie(e-r,this.ORDER)}mul(e,r){return ie(e*r,this.ORDER)}pow(e,r){return cg(this,e,r)}div(e,r){return ie(e*Zf(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return Zf(e,this.ORDER)}sqrt(e){let r=Wf.get(this);return r||Wf.set(this,r=sg(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?ca(e,this.BYTES):ei(e,this.BYTES)}fromBytes(e,r=!1){H(e);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,i?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=i?ct(e):ir(e);if(a&&(c=ie(c,s)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Un(this,e)}cmov(e,r,n){return Ge(n,"condition"),n?r:e}};Object.freeze(ri.prototype);function kr(t,e={}){return new ri(t,e)}function il(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=ee)throw new Error("field order must be greater than 1");let e=Nr(t-ee);return Math.ceil(e/8)}function ha(t){let e=il(t);return e+Math.ceil(e/2)}function da(t,e,r=!1){H(t);let n=t.length,o=il(e),i=Math.max(ha(e),16);if(n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?ct(t):ir(t),a=ie(s,e-ee)+ee;return r?ca(a,o):ei(a,o)}var Or=BigInt(0),ar=BigInt(1);function Ln(t,e){let r=e.negate();return t?r:e}function cr(t,e){let r=Un(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function ul(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function pa(t,e){ul(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,i=Fn(t),s=BigInt(t);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function sl(t,e,r){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r,a=Number(t&o),c=t>>s;a>n&&(a-=i,c+=ar);let u=e*n,f=u+Math.abs(a)-1,l=a===0,m=a<0,b=e%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:m,isNegF:b,offsetF:u}}var ma=new WeakMap,fl=new WeakMap;function ga(t){return fl.get(t)||1}function al(t){if(t!==Or)throw new Error("invalid wNAF")}var Mr=class{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let o=e;for(;r>Or;)r&ar&&(n=n.add(o)),o=o.double(),r>>=ar;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=pa(r,this.bits),i=[],s=e,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let u=1;u<o;u++)a=a.add(s),i.push(a);s=a.double()}return i}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=pa(e,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:m,offsetF:b}=sl(n,a,s);n=c,f?i=i.add(Ln(m,r[b])):o=o.add(Ln(l,r[u]))}return al(n),{p:o,f:i}}wNAFUnsafe(e,r,n,o=this.ZERO){let i=pa(e,this.bits);for(let s=0;s<i.windows&&n!==Or;s++){let{nextN:a,offset:c,isZero:u,isNeg:f}=sl(n,s,i);if(n=a,!u){let l=r[c];o=o.add(f?l.negate():l)}}return al(n),o}getPrecomputes(e,r,n){let o=ma.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),ma.set(r,o))),o}cached(e,r,n){let o=ga(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let i=ga(e);return i===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),r,o)}createCache(e,r){ul(r,this.bits),fl.set(e,r),ma.delete(e)}hasCache(e){return ga(e)!==1}};function ll(t,e,r,n){let o=e,i=t.ZERO,s=t.ZERO;for(;r>Or||n>Or;)r&ar&&(i=i.add(o)),n&ar&&(s=s.add(o)),o=o.double(),r>>=ar,n>>=ar;return{p1:i,p2:s}}function cl(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return la(e),e}else return kr(t,{isLE:r})}function ni(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let c of["p","n","h"]){let u=e[c];if(!(typeof u=="bigint"&&u>Or))throw new Error(`CURVE.${c} must be positive bigint`)}let o=cl(e.p,r.Fp,n),i=cl(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:i}}function oi(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var Rt=BigInt(0),le=BigInt(1),ya=BigInt(2),fg=BigInt(8);function lg(t,e,r,n){let o=t.sqr(r),i=t.sqr(n),s=t.add(t.mul(e.a,o),i),a=t.add(t.ONE,t.mul(e.d,t.mul(o,i)));return t.eql(s,a)}function hl(t,e={}){let r=e,n=ni("edwards",t,r,r.FpFnLE),{Fp:o,Fn:i}=n,s=n.CURVE,{h:a}=s;Xe(r,{},{uvRatio:"function"});let c=ya<<BigInt(i.BYTES*8)-le,u=y=>o.create(y),f=r.uvRatio===void 0?(y,d)=>{try{return{isValid:!0,value:o.sqrt(o.div(y,d))}}catch{return{isValid:!1,value:Rt}}}:r.uvRatio;if(!lg(o,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function l(y,d,g=!1){let E=g?le:Rt;return Rr("coordinate "+y,d,E,c),d}function m(y){if(!(y instanceof b))throw new Error("EdwardsPoint expected")}class b{static BASE=new b(s.Gx,s.Gy,le,u(s.Gx*s.Gy));static ZERO=new b(Rt,le,le,Rt);static Fp=o;static Fn=i;X;Y;Z;T;constructor(d,g,E,I){this.X=l("x",d),this.Y=l("y",g),this.Z=l("z",E,!0),this.T=l("t",I),Object.freeze(this)}static CURVE(){return s}static fromAffine(d){if(d instanceof b)throw new Error("extended point not allowed");let{x:g,y:E}=d||{};return l("x",g),l("y",E),new b(g,E,le,u(g*E))}static fromBytes(d,g=!1){let E=o.BYTES,{a:I,d:C}=s;d=Dn(H(d,E,"point")),Ge(g,"zip215");let B=Dn(d),R=d[E-1];B[E-1]=R&-129;let _=ct(B),x=g?c:o.ORDER;Rr("point.y",_,Rt,x);let D=u(_*_),M=u(D-le),k=u(C*D-I),{isValid:p,value:S}=f(M,k);if(!p)throw new Error("bad point: invalid y coordinate");let T=(S&le)===le,A=(R&128)!==0;if(!g&&S===Rt&&A)throw new Error("bad point: x=0 and x_0=1");return A!==T&&(S=u(-S)),b.fromAffine({x:S,y:_})}static fromHex(d,g=!1){return b.fromBytes(Lr(d),g)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=8,g=!0){return h.createCache(this,d),g||this.multiply(ya),this}assertValidity(){let d=this,{a:g,d:E}=s;if(d.is0())throw new Error("bad point: ZERO");let{X:I,Y:C,Z:B,T:R}=d,_=u(I*I),x=u(C*C),D=u(B*B),M=u(D*D),k=u(_*g),p=u(D*u(k+x)),S=u(M+u(E*u(_*x)));if(p!==S)throw new Error("bad point: equation left != right (1)");let T=u(I*C),A=u(B*R);if(T!==A)throw new Error("bad point: equation left != right (2)")}equals(d){m(d);let{X:g,Y:E,Z:I}=this,{X:C,Y:B,Z:R}=d,_=u(g*R),x=u(C*I),D=u(E*R),M=u(B*I);return _===x&&D===M}is0(){return this.equals(b.ZERO)}negate(){return new b(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:d}=s,{X:g,Y:E,Z:I}=this,C=u(g*g),B=u(E*E),R=u(ya*u(I*I)),_=u(d*C),x=g+E,D=u(u(x*x)-C-B),M=_+B,k=M-R,p=_-B,S=u(D*k),T=u(M*p),A=u(D*p),v=u(k*M);return new b(S,T,v,A)}add(d){m(d);let{a:g,d:E}=s,{X:I,Y:C,Z:B,T:R}=this,{X:_,Y:x,Z:D,T:M}=d,k=u(I*_),p=u(C*x),S=u(R*E*M),T=u(B*D),A=u((I+C)*(_+x)-k-p),v=T-S,F=T+S,L=u(p-g*k),N=u(A*v),P=u(F*L),V=u(A*L),q=u(v*F);return new b(N,P,q,V)}subtract(d){return m(d),this.add(d.negate())}multiply(d){if(!i.isValidNot0(d))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:g,f:E}=h.cached(this,d,I=>cr(b,I));return cr(b,[g,E])[0]}multiplyUnsafe(d){if(!i.isValid(d))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return d===Rt?b.ZERO:this.is0()||d===le?this:h.unsafe(this,d,g=>cr(b,g))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return h.unsafe(this,s.n).is0()}toAffine(d){let g=this,E=d,{X:I,Y:C,Z:B}=g,R=g.is0();E==null&&(E=R?fg:o.inv(B));let _=u(I*E),x=u(C*E),D=o.mul(B,E);if(R)return{x:Rt,y:le};if(D!==le)throw new Error("invZ was invalid");return{x:_,y:x}}clearCofactor(){return a===le?this:this.multiplyUnsafe(a)}toBytes(){let{x:d,y:g}=this.toAffine(),E=o.toBytes(g);return E[E.length-1]|=d&le?128:0,E}toHex(){return Ur(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let h=new Mr(b,i.BITS);return i.BITS>=8&&b.BASE.precompute(8),Object.freeze(b.prototype),Object.freeze(b),b}var ii=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){ua()}static fromHex(e){ua()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return Ur(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,r){return this.ep.precompute(e,r),this}};function dl(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Xe(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:i}=o,{BASE:s,Fp:a,Fn:c}=t,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(Ze(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?Cn:o.randomBytes,m=o.adjustScalarBytes===void 0?p=>p:o.adjustScalarBytes,b=o.domain===void 0?(p,S,T)=>{if(Ge(T,"phflag"),S.length||T)throw new Error("Contexts/pre-hash are not supported");return p}:o.domain;function h(p){return c.create(ct(p))}function y(p){let S=_.secretKey;H(p,_.secretKey,"secretKey");let T=H(n(p),2*S,"hashedSecretKey"),A=m(T.slice(0,S)),v=T.slice(S,2*S),F=h(A);return{head:A,prefix:v,scalar:F}}function d(p){let{head:S,prefix:T,scalar:A}=y(p),v=s.multiply(A),F=v.toBytes();return{head:S,prefix:T,scalar:A,point:v,pointBytes:F}}function g(p){return d(p).pointBytes}function E(p=Uint8Array.of(),...S){let T=ae(...S);return h(n(b(T,H(p,void 0,"context"),!!i)))}function I(p,S,T={}){p=H(p,void 0,"message"),i&&(p=i(p));let{prefix:A,scalar:v,pointBytes:F}=d(S),L=E(T.context,A,p),N=s.multiply(L).toBytes(),P=E(T.context,N,F,p),V=c.create(L+P*v);if(!c.isValid(V))throw new Error("sign failed: invalid s");let q=ae(N,c.toBytes(V));return H(q,_.signature,"result")}let C={zip215:o.zip215};function B(p,S,T,A=C){let{context:v}=A,F=A.zip215===void 0?!!C.zip215:A.zip215,L=_.signature;p=H(p,L,"signature"),S=H(S,void 0,"message"),T=H(T,_.publicKey,"publicKey"),F!==void 0&&Ge(F,"zip215"),i&&(S=i(S));let N=L/2,P=p.subarray(0,N),V=ct(p.subarray(N,L)),q,Y,$;try{q=t.fromBytes(T,F),Y=t.fromBytes(P,F),$=s.multiplyUnsafe(V)}catch{return!1}if(!F&&q.isSmallOrder())return!1;let se=E(v,P,T,S);return Y.add(q.multiplyUnsafe(se)).subtract($).clearCofactor().is0()}let R=a.BYTES,_={secretKey:R,publicKey:R,signature:2*R,seed:R};function x(p){return p=p===void 0?l(_.seed):p,H(p,_.seed,"seed")}function D(p){return or(p)&&p.length===_.secretKey}function M(p,S){try{return!!t.fromBytes(p,S===void 0?C.zip215:S)}catch{return!1}}let k={getExtendedPublicKey:d,randomSecretKey:x,isValidSecretKey:D,isValidPublicKey:M,toMontgomery(p){let{y:S}=t.fromBytes(p),T=_.publicKey,A=T===32;if(!A&&T!==57)throw new Error("only defined for 25519 and 448");let v=A?a.div(le+S,le-S):a.div(S-le,S+le);return a.toBytes(v)},toMontgomerySecret(p){let S=_.secretKey;H(p,S);let T=n(p.subarray(0,S));return m(T).subarray(0,S)}};return Object.freeze(_),Object.freeze(k),Object.freeze({keygen:oi(x,g),getPublicKey:g,sign:I,verify:B,utils:k,Point:t,lengths:_})}function Rn(t,e){if(Ze(t),Ze(e),e<0||e>4)throw new Error("invalid I2OSP length: "+e);if(t<0||t>2**(8*e)-1)throw new Error("invalid I2OSP input: "+t);let r=Array.from({length:e}).fill(0);for(let n=e-1;n>=0;n--)r[n]=t&255,t>>>=8;return new Uint8Array(r)}function hg(t,e){let r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function dg(t){if(!or(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?ti(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function ba(t,e,r,n){H(t),Ze(r),e=dg(e),e.length>255&&(e=n(ae(ti("H2C-OVERSIZE-DST-"),e)));let{outputLen:o,blockLen:i}=n,s=Math.ceil(r/o);if(r>65535||s>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=ae(e,Rn(e.length,1)),c=new Uint8Array(i),u=Rn(r,2),f=new Array(s),l=n(ae(c,t,u,Rn(0,1),a));f[0]=n(ae(l,Rn(1,1),a));for(let b=1;b<s;b++){let h=[hg(l,f[b-1]),Rn(b+1,1),a];f[b]=n(ae(...h))}return ae(...f).slice(0,r)}var pl="HashToScalar-";var pg=BigInt(0),At=BigInt(1),ml=BigInt(2);var mg=BigInt(5),gg=BigInt(8),Pr=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Sa={p:Pr,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:gg,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function yg(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=Pr,a=t*t%i*t%i,c=Z(a,ml,i)*a%i,u=Z(c,At,i)*t%i,f=Z(u,mg,i)*u%i,l=Z(f,e,i)*f%i,m=Z(l,r,i)*l%i,b=Z(m,n,i)*m%i,h=Z(b,o,i)*b%i,y=Z(h,o,i)*b%i,d=Z(y,e,i)*f%i;return{pow_p_5_8:Z(d,ml,i)*t%i,b2:a}}function bg(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var xa=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Aa(t,e){let r=Pr,n=ie(e*e*e,r),o=ie(n*n*e,r),i=yg(t*o).pow_p_5_8,s=ie(t*n*i,r),a=ie(e*s*s,r),c=s,u=ie(s*xa,r),f=a===t,l=a===ie(-t,r),m=a===ie(-t*xa,r);return f&&(s=c),(l||m)&&(s=u),St(s,r)&&(s=ie(-s,r)),{isValid:f||l,value:s}}var kt=hl(Sa,{uvRatio:Aa}),Nt=kt.Fp,bl=kt.Fn;function xg(t){return dl(kt,Xo,Object.assign({adjustScalarBytes:bg,zip215:!0},t))}var Nn=xg({});var wa=xa,wg=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Eg=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Sg=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Ag=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),gl=t=>Aa(At,t),vg=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Ea=t=>Nt.create(ct(t)&vg);function yl(t){let{d:e}=Sa,r=Pr,n=g=>Nt.create(g),o=n(wa*t*t),i=n((o+At)*Sg),s=BigInt(-1),a=n((s-e*o)*n(o+e)),{isValid:c,value:u}=Aa(i,a),f=n(u*t);St(f,r)||(f=n(-f)),c||(u=f),c||(s=o);let l=n(s*(o-At)*Ag-a),m=u*u,b=n((u+u)*a),h=n(l*wg),y=n(At-m),d=n(At+m);return new kt(n(b*d),n(y*h),n(h*d),n(b*y))}var Ot=class t extends ii{static BASE=new t(kt.BASE);static ZERO=new t(kt.ZERO);static Fp=Nt;static Fn=bl;constructor(e){super(e)}static fromAffine(e){return new t(kt.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static fromBytes(e){Le(e,32);let{a:r,d:n}=Sa,o=Pr,i=C=>Nt.create(C),s=Ea(e);if(!Yf(Nt.toBytes(s),e)||St(s,o))throw new Error("invalid ristretto255 encoding 1");let a=i(s*s),c=i(At+r*a),u=i(At-r*a),f=i(c*c),l=i(u*u),m=i(r*n*f-l),{isValid:b,value:h}=gl(i(m*l)),y=i(h*u),d=i(h*y*m),g=i((s+s)*y);St(g,o)&&(g=i(-g));let E=i(c*d),I=i(g*E);if(!b||St(I,o)||E===pg)throw new Error("invalid ristretto255 encoding 2");return new t(new kt(g,E,At,I))}static fromHex(e){return t.fromBytes(vn(e))}toBytes(){let{X:e,Y:r,Z:n,T:o}=this.ep,i=Pr,s=d=>Nt.create(d),a=s(s(n+r)*s(n-r)),c=s(e*r),u=s(c*c),{value:f}=gl(s(a*u)),l=s(f*a),m=s(f*c),b=s(l*m*o),h;if(St(o*b,i)){let d=s(r*wa),g=s(e*wa);e=d,r=g,h=s(l*Eg)}else h=m;St(e*b,i)&&(r=s(-r));let y=s((n-r)*h);return St(y,i)&&(y=s(-y)),Nt.toBytes(y)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:o,Y:i}=e.ep,s=u=>Nt.create(u),a=s(r*i)===s(n*o),c=s(n*i)===s(r*o);return a||c}is0(){return this.equals(t.ZERO)}};Object.freeze(Ot.BASE);Object.freeze(Ot.ZERO);Object.freeze(Ot.prototype);Object.freeze(Ot);var Ig=Object.freeze({Point:Ot,hashToCurve(t,e){let r=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=ba(t,r,64,Xo);return Ig.deriveToCurve(n)},hashToScalar(t,e={DST:pl}){let r=ba(t,e.DST,64,Xo);return bl.create(ct(r))},deriveToCurve(t){Le(t,64);let e=Ea(t.subarray(0,32)),r=yl(e),n=Ea(t.subarray(32,64)),o=yl(n);return new Ot(r.add(o))}});var kn=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},On=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},si=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var xl={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new si("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Ce=xl;var ai=32,Mn=64,va=32;var Kr,wl=(async()=>{try{return await Ce.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function El(){let t=Nn.utils.randomSecretKey(),e=Nn.getPublicKey(t);return{privateKey:Dg(t,e),publicKey:e}}async function Tg(t,e){let r;t.length===Mn?r=t.subarray(0,32):r=t;let n={crv:"Ed25519",kty:"OKP",x:oe(t.subarray(32),"base64url"),d:oe(r,"base64url"),ext:!0,key_ops:["sign"]},o=await Ce.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),i=await Ce.get().subtle.sign({name:"Ed25519"},o,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(i,0,i.byteLength)}function Bg(t,e){let r=t.subarray(0,va);return Nn.sign(e instanceof Uint8Array?e:e.subarray(),r)}async function Sl(t,e){return Kr==null&&(Kr=await wl),Kr?Tg(t,e):Bg(t,e)}async function Cg(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Ce.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Ce.get().subtle.verify({name:"Ed25519"},n,e,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function _g(t,e,r){return Nn.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function Al(t,e,r){return Kr==null&&(Kr=await wl),Kr?Cg(t,e,r):_g(t,e,r)}function Dg(t,e){let r=new Uint8Array(Mn);for(let n=0;n<va;n++)r[n]=t[n],r[va+n]=e[n];return r}function Vr(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Pn=class{type="Ed25519";raw;constructor(e){this.raw=ui(e,ai)}toMultihash(){return er.digest(_t(this))}toCID(){return ze.createV1(114,this.toMultihash())}toString(){return fe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Be(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=Al(this.raw,r,e);return Vr(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}},ci=class{type="Ed25519";raw;publicKey;constructor(e,r){this.raw=ui(e,Mn),this.publicKey=new Pn(r)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Be(this.raw,e.raw)}sign(e,r){r?.signal?.throwIfAborted();let n=Sl(this.raw,e);return Vr(n)?n.then(o=>(r?.signal?.throwIfAborted(),o)):(r?.signal?.throwIfAborted(),n)}};function Ia(t){return t=ui(t,ai),new Pn(t)}async function Il(){let{privateKey:t,publicKey:e}=El();return new ci(t,e)}function ui(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new W(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var Fg=Math.pow(2,7),Ug=Math.pow(2,14),Lg=Math.pow(2,21),Tl=Math.pow(2,28),Bl=Math.pow(2,35),Cl=Math.pow(2,42),_l=Math.pow(2,49),Ee=128,Mt=127;function Kn(t){if(t<Fg)return 1;if(t<Ug)return 2;if(t<Lg)return 3;if(t<Tl)return 4;if(t<Bl)return 5;if(t<Cl)return 6;if(t<_l)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Dl(t,e,r=0){switch(Kn(t)){case 8:e[r++]=t&255|Ee,t/=128;case 7:e[r++]=t&255|Ee,t/=128;case 6:e[r++]=t&255|Ee,t/=128;case 5:e[r++]=t&255|Ee,t/=128;case 4:e[r++]=t&255|Ee,t>>>=7;case 3:e[r++]=t&255|Ee,t>>>=7;case 2:e[r++]=t&255|Ee,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Fl(t,e){let r=t[e],n=0;if(n+=r&Mt,r<Ee||(r=t[e+1],n+=(r&Mt)<<7,r<Ee)||(r=t[e+2],n+=(r&Mt)<<14,r<Ee)||(r=t[e+3],n+=(r&Mt)<<21,r<Ee)||(r=t[e+4],n+=(r&Mt)*Tl,r<Ee)||(r=t[e+5],n+=(r&Mt)*Bl,r<Ee)||(r=t[e+6],n+=(r&Mt)*Cl,r<Ee)||(r=t[e+7],n+=(r&Mt)*_l,r<Ee))return n;throw new RangeError("Could not decode varint")}var Ta=new Float32Array([-0]),Pt=new Uint8Array(Ta.buffer);function Ul(t,e,r){Ta[0]=t,e[r]=Pt[0],e[r+1]=Pt[1],e[r+2]=Pt[2],e[r+3]=Pt[3]}function Ll(t,e){return Pt[0]=t[e],Pt[1]=t[e+1],Pt[2]=t[e+2],Pt[3]=t[e+3],Ta[0]}var Ba=new Float64Array([-0]),ge=new Uint8Array(Ba.buffer);function Rl(t,e,r){Ba[0]=t,e[r]=ge[0],e[r+1]=ge[1],e[r+2]=ge[2],e[r+3]=ge[3],e[r+4]=ge[4],e[r+5]=ge[5],e[r+6]=ge[6],e[r+7]=ge[7]}function Nl(t,e){return ge[0]=t[e],ge[1]=t[e+1],ge[2]=t[e+2],ge[3]=t[e+3],ge[4]=t[e+4],ge[5]=t[e+5],ge[6]=t[e+6],ge[7]=t[e+7],Ba[0]}var Rg=BigInt(Number.MAX_SAFE_INTEGER),Ng=BigInt(Number.MIN_SAFE_INTEGER),Re=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return ur;if(e<Rg&&e>Ng)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>kl&&(o=0n,++n>kl&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return ur;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):ur}},ur=new Re(0,0);ur.toBigInt=function(){return 0n};ur.zzEncode=ur.zzDecode=function(){return this};ur.length=function(){return 1};var kl=4294967296n;function Ol(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 Ml(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 Ca(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 We(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function fi(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var _a=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,We(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 We(this,4);return fi(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw We(this,4);return fi(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw We(this,4);let e=Ll(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw We(this,4);let e=Nl(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 We(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Ml(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw We(this,e);this.pos+=e}else do if(this.pos>=this.len)throw We(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Re(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw We(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 We(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 We(this,8);let e=fi(this.buf,this.pos+=4),r=fi(this.buf,this.pos+=4);return new Re(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Fl(this.buf,this.pos);return this.pos+=Kn(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 Vn(t){return new _a(t instanceof Uint8Array?t:t.subarray())}function li(t,e,r){let n=Vn(t);return e.decode(n,void 0,r)}function Da(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 fr=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Fa(){}var La=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},kg=Da();function Og(t){return globalThis.Buffer!=null?Ue(t):kg(t)}var $n=class{len;head;tail;states;constructor(){this.len=0,this.head=new fr(Fa,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new fr(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Ra((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(hi,10,Re.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Re.fromBigInt(e);return this._push(hi,r.length(),r)}uint64Number(e){return this._push(Dl,Kn(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=Re.fromBigInt(e).zzEncode();return this._push(hi,r.length(),r)}sint64Number(e){let r=Re.fromNumber(e).zzEncode();return this._push(hi,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ua,1,e?1:0)}fixed32(e){return this._push(zn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Re.fromBigInt(e);return this._push(zn,4,r.lo)._push(zn,4,r.hi)}fixed64Number(e){let r=Re.fromNumber(e);return this._push(zn,4,r.lo)._push(zn,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(Ul,4,e)}double(e){return this._push(Rl,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Ua,1,0):this.uint32(r)._push(Pg,r,e)}string(e){let r=Ol(e);return r!==0?this.uint32(r)._push(Ca,r,e):this._push(Ua,1,0)}fork(){return this.states=new La(this),this.head=this.tail=new fr(Fa,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 fr(Fa,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=Og(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Ua(t,e,r){e[r]=t&255}function Mg(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Ra=class extends fr{next;constructor(e,r){super(Mg,e,r),this.next=void 0}};function hi(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 zn(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 Pg(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&($n.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Kg,e,t),this},$n.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Vg,e,t),this});function Kg(t,e,r){e.set(t,r)}function Vg(t,e,r){t.length<40?Ca(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(Q(t),r)}function Na(){return new $n}function di(t,e){let r=Na();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*pi(t,e,r){let n=Vn(t);yield*e.stream(n,void 0,"$",r)}var mi={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function gi(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function ka(t){function e(i){if(t[i.toString()]==null)throw new Error("Invalid enum value");return t[i]}let r=function(s,a){let c=e(s);a.int32(c)},n=function(s){let a=s.int32();return e(a)},o=function*(s){let a=s.int32();yield e(a)};return gi("enum",mi.VARINT,r,n,o)}function yi(t,e,r){return gi("message",mi.LENGTH_DELIMITED,t,e,r)}var X;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(X||(X={}));var Oa;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Oa||(Oa={}));(function(t){t.codec=()=>ka(Oa)})(X||(X={}));var ut;(function(t){let e;t.codec=()=>(e==null&&(e=yi((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),X.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=X.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:X.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(f&7);break}}}})),e);function r(i){return di(i,t.codec())}t.encode=r;function n(i,s){return li(i,t.codec(),s)}t.decode=n;function o(i,s){return pi(i,t.codec(),s)}t.stream=o})(ut||(ut={}));var Ma;(function(t){let e;t.codec=()=>(e==null&&(e=yi((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),X.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=X.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:X.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(f&7);break}}}})),e);function r(i){return di(i,t.codec())}t.encode=r;function n(i,s){return li(i,t.codec(),s)}t.decode=n;function o(i,s){return pi(i,t.codec(),s)}t.stream=o})(Ma||(Ma={}));var Hn={};z(Hn,{MAX_RSA_KEY_SIZE:()=>Pa,generateRSAKeyPair:()=>Ga,jwkToJWKKeyPair:()=>ql,jwkToPkcs1:()=>Hg,jwkToPkix:()=>$a,jwkToRSAPrivateKey:()=>Ya,pkcs1MessageToJwk:()=>Va,pkcs1MessageToRSAPrivateKey:()=>qa,pkcs1ToJwk:()=>qg,pkcs1ToRSAPrivateKey:()=>$l,pkixMessageToJwk:()=>za,pkixMessageToRSAPublicKey:()=>ja,pkixToJwk:()=>jg,pkixToRSAPublicKey:()=>Ha});var zr=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Hn.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ze.createV1(114,this._multihash)}toString(){return fe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Be(this.raw,e.raw)}verify(e,r,n){return zl(this.jwk,r,e,n)}},qn=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Hn.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Be(this.raw,e.raw)}sign(e,r){return Vl(this.jwk,e,r)}};var Pa=8192,Ka=18,zg=1062,$g=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function qg(t){let e=bt(t);return Va(e)}function Va(t){return{n:oe(t[1],"base64url"),e:oe(t[2],"base64url"),d:oe(t[3],"base64url"),p:oe(t[4],"base64url"),q:oe(t[5],"base64url"),dp:oe(t[6],"base64url"),dq:oe(t[7],"base64url"),qi:oe(t[8],"base64url"),kty:"RSA"}}function Hg(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new W("JWK was missing components");return je([we(Uint8Array.from([0])),we(Q(t.n,"base64url")),we(Q(t.e,"base64url")),we(Q(t.d,"base64url")),we(Q(t.p,"base64url")),we(Q(t.q,"base64url")),we(Q(t.dp,"base64url")),we(Q(t.dq,"base64url")),we(Q(t.qi,"base64url"))]).subarray()}function jg(t){let e=bt(t,{offset:0});return za(e)}function za(t){let e=bt(t[1],{offset:0});return{kty:"RSA",n:oe(e[0],"base64url"),e:oe(e[1],"base64url")}}function $a(t){if(t.n==null||t.e==null)throw new W("JWK was missing components");return je([$g,An(je([we(Q(t.n,"base64url")),we(Q(t.e,"base64url"))]))]).subarray()}function $l(t){let e=bt(t);return qa(e)}function qa(t){let e=Va(t);return Ya(e)}function Ha(t,e){if(t.byteLength>=zg)throw new Ar("Key size is too large");let r=bt(t,{offset:0});return ja(r,t,e)}function ja(t,e,r){let n=za(t);if(r==null){let o=Fr(ut.encode({Type:X.RSA,Data:e}));r=st(Ka,o)}return new zr(n,r)}function Ya(t){if(jl(t)>Pa)throw new W("Key size is too large");let e=ql(t),r=Fr(ut.encode({Type:X.RSA,Data:$a(e.publicKey)})),n=st(Ka,r);return new qn(e.privateKey,new zr(e.publicKey,n))}async function Ga(t){if(t>Pa)throw new W("Key size is too large");let e=await Hl(t),r=Fr(ut.encode({Type:X.RSA,Data:$a(e.publicKey)})),n=st(Ka,r);return new qn(e.privateKey,new zr(e.publicKey,n))}function ql(t){if(t==null)throw new W("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function Hl(t,e){let r=await Ce.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await Yg(r,e);return{privateKey:n[0],publicKey:n[1]}}async function Vl(t,e,r){let n=await Ce.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Ce.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,e instanceof Uint8Array?e:e.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function zl(t,e,r,n){let o=await Ce.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Ce.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),i}async function Yg(t,e){if(t.privateKey==null||t.publicKey==null)throw new W("Private and public key are required");let r=await Promise.all([Ce.get().subtle.exportKey("jwk",t.privateKey),Ce.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function jl(t){if(t.kty!=="RSA")throw new W("invalid key type");if(t.n==null)throw new W("invalid key modulus");return Q(t.n,"base64url").length*8}var bi=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(Ho(e),Le(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=e.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),wt(o)}update(e){return Dr(this),this.iHash.update(e),this}digestInto(e){Dr(this),jo(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Yl=(()=>{let t=((e,r,n)=>new bi(e,r).update(n).digest());return t.create=(e,r)=>new bi(e,r),t})();var Gl=(t,e)=>(t+(t>=0?e:-e)/Zl)/e;function Gg(t,e,r){Rr("scalar",t,ft,r);let[[n,o],[i,s]]=e,a=Gl(s*t,r),c=Gl(-o*t,r),u=t-a*n-c*i,f=-a*o-c*s,l=u<ft,m=f<ft;l&&(u=-u),m&&(f=-f);let b=Fn(Math.ceil(Nr(r)/2))+Kt;if(u<ft||u>=b||f<ft||f>=b)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:m,k2:f}}function Xa(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Za(t,e){Xe(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Ge(r.lowS,"lowS"),Ge(r.prehash,"prehash"),r.format!==void 0&&Xa(r.format),r}var Wa=class extends Error{constructor(e=""){super(e)}},Je={Err:Wa,_tlv:{encode:(t,e)=>{let{Err:r}=Je;if(Ze(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(typeof e!="string")throw new TypeError('"data" expected string, got type='+typeof e);if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=_n(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?_n(o.length/2|128):"";return _n(t)+i+o+e},decode(t,e){let{Err:r}=Je;e=H(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)s=s<<8|f;if(n+=c,s<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(t){let{Err:e}=Je;if(Qo(t),t<ft)throw new e("integer: negative integers are not allowed");let r=_n(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=Je;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return ir(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=Je,o=H(t,void 0,"signature"),{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:u,l:f}=n.decode(2,c);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=Je,n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),i=n+o;return e.encode(48,i)}};Object.freeze(Je._tlv);Object.freeze(Je._int);Object.freeze(Je);var ft=BigInt(0),Kt=BigInt(1),Zl=BigInt(2),xi=BigInt(3),Zg=BigInt(4);function Xl(t,e={}){let r=ni("weierstrass",t,e),n=r.Fp,o=r.Fn,i=r.CURVE,{h:s,n:a}=i;Xe(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=e;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=Jl(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function m(k,p,S){if(u&&p.is0())return Uint8Array.of(0);let{x:T,y:A}=p.toAffine(),v=n.toBytes(T);if(Ge(S,"isCompressed"),S){l();let F=!n.isOdd(A);return ae(Wl(F),v)}else return ae(Uint8Array.of(4),v,n.toBytes(A))}function b(k){H(k,void 0,"Point");let{publicKey:p,publicKeyUncompressed:S}=f,T=k.length,A=k[0],v=k.subarray(1);if(u&&T===1&&A===0)return{x:n.ZERO,y:n.ZERO};if(T===p&&(A===2||A===3)){let F=n.fromBytes(v);if(!n.isValid(F))throw new Error("bad point: is not on curve, wrong x");let L=d(F),N;try{N=n.sqrt(L)}catch(q){let Y=q instanceof Error?": "+q.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}l();let P=n.isOdd(N);return(A&1)===1!==P&&(N=n.neg(N)),{x:F,y:N}}else if(T===S&&A===4){let F=n.BYTES,L=n.fromBytes(v.subarray(0,F)),N=n.fromBytes(v.subarray(F,F*2));if(!g(L,N))throw new Error("bad point: is not on curve");return{x:L,y:N}}else throw new Error(`bad point: got length ${T}, expected compressed=${p} or uncompressed=${S}`)}let h=e.toBytes===void 0?m:e.toBytes,y=e.fromBytes===void 0?b:e.fromBytes;function d(k){let p=n.sqr(k),S=n.mul(p,k);return n.add(n.add(S,n.mul(k,i.a)),i.b)}function g(k,p){let S=n.sqr(p),T=d(k);return n.eql(S,T)}if(!g(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let E=n.mul(n.pow(i.a,xi),Zg),I=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(E,I)))throw new Error("bad curve params: a or b");function C(k,p,S=!1){if(!n.isValid(p)||S&&n.is0(p))throw new Error(`bad point coordinate ${k}`);return p}function B(k){if(!(k instanceof x))throw new Error("Weierstrass Point expected")}function R(k){if(!c||!c.basises)throw new Error("no endo");return Gg(k,c.basises,o.ORDER)}function _(k,p,S,T,A){return S=new x(n.mul(S.X,k),S.Y,S.Z),p=Ln(T,p),S=Ln(A,S),p.add(S)}class x{static BASE=new x(i.Gx,i.Gy,n.ONE);static ZERO=new x(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(p,S,T){this.X=C("x",p),this.Y=C("y",S,!0),this.Z=C("z",T),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){let{x:S,y:T}=p||{};if(!p||!n.isValid(S)||!n.isValid(T))throw new Error("invalid affine point");if(p instanceof x)throw new Error("projective point not allowed");return n.is0(S)&&n.is0(T)?x.ZERO:new x(S,T,n.ONE)}static fromBytes(p){let S=x.fromAffine(y(H(p,void 0,"point")));return S.assertValidity(),S}static fromHex(p){return x.fromBytes(Lr(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,S=!0){return M.createCache(this,p),S||this.multiply(xi),this}assertValidity(){let p=this;if(p.is0()){if(e.allowInfinityPoint&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}let{x:S,y:T}=p.toAffine();if(!n.isValid(S)||!n.isValid(T))throw new Error("bad point: x or y not field elements");if(!g(S,T))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){B(p);let{X:S,Y:T,Z:A}=this,{X:v,Y:F,Z:L}=p,N=n.eql(n.mul(S,L),n.mul(v,A)),P=n.eql(n.mul(T,L),n.mul(F,A));return N&&P}negate(){return new x(this.X,n.neg(this.Y),this.Z)}double(){let{a:p,b:S}=i,T=n.mul(S,xi),{X:A,Y:v,Z:F}=this,L=n.ZERO,N=n.ZERO,P=n.ZERO,V=n.mul(A,A),q=n.mul(v,v),Y=n.mul(F,F),$=n.mul(A,v);return $=n.add($,$),P=n.mul(A,F),P=n.add(P,P),L=n.mul(p,P),N=n.mul(T,Y),N=n.add(L,N),L=n.sub(q,N),N=n.add(q,N),N=n.mul(L,N),L=n.mul($,L),P=n.mul(T,P),Y=n.mul(p,Y),$=n.sub(V,Y),$=n.mul(p,$),$=n.add($,P),P=n.add(V,V),V=n.add(P,V),V=n.add(V,Y),V=n.mul(V,$),N=n.add(N,V),Y=n.mul(v,F),Y=n.add(Y,Y),V=n.mul(Y,$),L=n.sub(L,V),P=n.mul(Y,q),P=n.add(P,P),P=n.add(P,P),new x(L,N,P)}add(p){B(p);let{X:S,Y:T,Z:A}=this,{X:v,Y:F,Z:L}=p,N=n.ZERO,P=n.ZERO,V=n.ZERO,q=i.a,Y=n.mul(i.b,xi),$=n.mul(S,v),se=n.mul(T,F),ce=n.mul(A,L),ue=n.add(S,T),ne=n.add(v,F);ue=n.mul(ue,ne),ne=n.add($,se),ue=n.sub(ue,ne),ne=n.add(S,A);let Te=n.add(v,L);return ne=n.mul(ne,Te),Te=n.add($,ce),ne=n.sub(ne,Te),Te=n.add(T,A),N=n.add(F,L),Te=n.mul(Te,N),N=n.add(se,ce),Te=n.sub(Te,N),V=n.mul(q,ne),N=n.mul(Y,ce),V=n.add(N,V),N=n.sub(se,V),V=n.add(se,V),P=n.mul(N,V),se=n.add($,$),se=n.add(se,$),ce=n.mul(q,ce),ne=n.mul(Y,ne),se=n.add(se,ce),ce=n.sub($,ce),ce=n.mul(q,ce),ne=n.add(ne,ce),$=n.mul(se,ne),P=n.add(P,$),$=n.mul(Te,ne),N=n.mul(ue,N),N=n.sub(N,$),$=n.mul(ue,se),V=n.mul(Te,V),V=n.add(V,$),new x(N,P,V)}subtract(p){return B(p),this.add(p.negate())}is0(){return this.equals(x.ZERO)}multiply(p){let{endo:S}=e;if(!o.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let T,A,v=F=>M.cached(this,F,L=>cr(x,L));if(S){let{k1neg:F,k1:L,k2neg:N,k2:P}=R(p),{p:V,f:q}=v(L),{p:Y,f:$}=v(P);A=q.add($),T=_(S.beta,V,Y,F,N)}else{let{p:F,f:L}=v(p);T=F,A=L}return cr(x,[T,A])[0]}multiplyUnsafe(p){let{endo:S}=e,T=this,A=p;if(!o.isValid(A))throw new RangeError("invalid scalar: out of range");if(A===ft||T.is0())return x.ZERO;if(A===Kt)return T;if(M.hasCache(this))return this.multiply(A);if(S){let{k1neg:v,k1:F,k2neg:L,k2:N}=R(A),{p1:P,p2:V}=ll(x,T,F,N);return _(S.beta,P,V,v,L)}else return M.unsafe(T,A)}toAffine(p){let S=this,T=p,{X:A,Y:v,Z:F}=S;if(n.eql(F,n.ONE))return{x:A,y:v};let L=S.is0();T==null&&(T=L?n.ONE:n.inv(F));let N=n.mul(A,T),P=n.mul(v,T),V=n.mul(F,T);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(V,n.ONE))throw new Error("invZ was invalid");return{x:N,y:P}}isTorsionFree(){let{isTorsionFree:p}=e;return s===Kt?!0:p?p(x,this):M.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:p}=e;return s===Kt?this:p?p(x,this):this.multiplyUnsafe(s)}isSmallOrder(){return s===Kt?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return Ge(p,"isCompressed"),this.assertValidity(),h(x,this,p)}toHex(p=!0){return Ur(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let D=o.BITS,M=new Mr(x,e.endo?Math.ceil(D/2):D);return D>=8&&x.BASE.precompute(8),Object.freeze(x.prototype),Object.freeze(x),x}function Wl(t){return Uint8Array.of(t?2:3)}function Jl(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Xg(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?Cn:e.randomBytes,o=Object.assign(Jl(t.Fp,r),{seed:Math.max(ha(r.ORDER),16)});function i(b){try{let h=r.fromBytes(b);return r.isValidNot0(h)}catch{return!1}}function s(b,h){let{publicKey:y,publicKeyUncompressed:d}=o;try{let g=b.length;return h===!0&&g!==y||h===!1&&g!==d?!1:!!t.fromBytes(b)}catch{return!1}}function a(b){return b=b===void 0?n(o.seed):b,da(H(b,o.seed,"seed"),r.ORDER)}function c(b,h=!0){return t.BASE.multiply(r.fromBytes(b)).toBytes(h)}function u(b){let{secretKey:h,publicKey:y,publicKeyUncompressed:d}=o,g=r._lengths;if(!or(b))return;let E=H(b,void 0,"key").length,I=E===y||E===d,C=E===h||!!g?.includes(E);if(!(I&&C))return I}function f(b,h,y=!0){if(u(b)===!0)throw new Error("first arg must be private key");if(u(h)===!1)throw new Error("second arg must be public key");let d=r.fromBytes(b);return t.fromBytes(h).multiply(d).toBytes(y)}let l={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},m=oi(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:m,Point:t,utils:l,lengths:o})}function Ql(t,e,r={}){let n=e;Ho(n),Xe(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?Cn:r.randomBytes,i=r.hmac===void 0?(A,v)=>Yl(n,A,v):r.hmac,{Fp:s,Fn:a}=t,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:m,utils:b,lengths:h}=Xg(t,r),y={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},d=c*Zl+Kt<s.ORDER;function g(A){let v=c>>Kt;return A>v}function E(A,v){if(!a.isValidNot0(v))throw new Error(`invalid signature ${A}: out of range 1..Point.Fn.ORDER`);return v}function I(){if(d)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function C(A,v){Xa(v);let F=h.signature,L=v==="compact"?F:v==="recovered"?F+1:void 0;return H(A,L)}class B{r;s;recovery;constructor(v,F,L){if(this.r=E("r",v),this.s=E("s",F),L!=null){if(I(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(v,F=y.format){C(v,F);let L;if(F==="der"){let{r:q,s:Y}=Je.toSig(H(v));return new B(q,Y)}F==="recovered"&&(L=v[0],F="compact",v=v.subarray(1));let N=h.signature/2,P=v.subarray(0,N),V=v.subarray(N,N*2);return new B(a.fromBytes(P),a.fromBytes(V),L)}static fromHex(v,F){return this.fromBytes(Lr(v),F)}assertRecovery(){let{recovery:v}=this;if(v==null)throw new Error("invalid recovery id: must be present");return v}addRecoveryBit(v){return new B(this.r,this.s,v)}recoverPublicKey(v){let{r:F,s:L}=this,N=this.assertRecovery(),P=N===2||N===3?F+c:F;if(!s.isValid(P))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let V=s.toBytes(P),q=t.fromBytes(ae(Wl((N&1)===0),V)),Y=a.inv(P),$=_(H(v,void 0,"msgHash")),se=a.create(-$*Y),ce=a.create(L*Y),ue=t.BASE.multiplyUnsafe(se).add(q.multiplyUnsafe(ce));if(ue.is0())throw new Error("invalid recovery: point at infinify");return ue.assertValidity(),ue}hasHighS(){return g(this.s)}toBytes(v=y.format){if(Xa(v),v==="der")return Lr(Je.hexFromSig(this));let{r:F,s:L}=this,N=a.toBytes(F),P=a.toBytes(L);return v==="recovered"?(I(),ae(Uint8Array.of(this.assertRecovery()),N,P)):ae(N,P)}toHex(v){return Ur(this.toBytes(v))}}Object.freeze(B.prototype),Object.freeze(B);let R=r.bits2int===void 0?function(v){if(v.length>8192)throw new Error("input is too large");let F=ir(v),L=v.length*8-u;return L>0?F>>BigInt(L):F}:r.bits2int,_=r.bits2int_modN===void 0?function(v){return a.create(R(v))}:r.bits2int_modN,x=Fn(u);function D(A){return Rr("num < 2^"+u,A,ft,x),a.toBytes(A)}function M(A,v){return H(A,void 0,"message"),v?H(n(A),void 0,"prehashed message"):A}function k(A,v,F){let{lowS:L,prehash:N,extraEntropy:P}=Za(F,y);A=M(A,N);let V=_(A),q=a.fromBytes(v);if(!a.isValidNot0(q))throw new Error("invalid private key");let Y=[D(q),D(V)];if(P!=null&&P!==!1){let ue=P===!0?o(h.secretKey):P;Y.push(H(ue,void 0,"extraEntropy"))}let $=ae(...Y),se=V;function ce(ue){let ne=R(ue);if(!a.isValidNot0(ne))return;let Te=a.inv(ne),Sr=t.BASE.multiply(ne).toAffine(),pn=a.create(Sr.x);if(pn===ft)return;let Lo=a.create(Te*a.create(se+pn*q));if(Lo===ft)return;let Yu=(Sr.x===pn?0:2)|Number(Sr.y&Kt),Gu=Lo;return L&&g(Lo)&&(Gu=a.neg(Lo),Yu^=1),new B(pn,Gu,d?void 0:Yu)}return{seed:$,k2sig:ce}}function p(A,v,F={}){let{seed:L,k2sig:N}=k(A,v,F);return Gf(n.outputLen,a.BYTES,i)(L,N).toBytes(F.format)}function S(A,v,F,L={}){let{lowS:N,prehash:P,format:V}=Za(L,y);if(F=H(F,void 0,"publicKey"),v=M(v,P),!or(A)){let q=A instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+q)}C(A,V);try{let q=B.fromBytes(A,V),Y=t.fromBytes(F);if(N&&q.hasHighS())return!1;let{r:$,s:se}=q,ce=_(v),ue=a.inv(se),ne=a.create(ce*ue),Te=a.create($*ue),Sr=t.BASE.multiplyUnsafe(ne).add(Y.multiplyUnsafe(Te));return Sr.is0()?!1:a.create(Sr.x)===$}catch{return!1}}function T(A,v,F={}){let{prehash:L}=Za(F,y);return v=M(v,L),B.fromBytes(A,"recovered").recoverPublicKey(v).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:m,utils:b,lengths:h,Point:t,sign:p,verify:S,recoverPublicKey:T,Signature:B,hash:n})}var Qa={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Wg={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var eh=BigInt(2);function Jg(t){let e=Qa.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,l=Z(f,r,e)*f%e,m=Z(l,r,e)*f%e,b=Z(m,eh,e)*u%e,h=Z(b,o,e)*b%e,y=Z(h,i,e)*h%e,d=Z(y,a,e)*y%e,g=Z(d,c,e)*d%e,E=Z(g,a,e)*y%e,I=Z(E,r,e)*f%e,C=Z(I,s,e)*h%e,B=Z(C,n,e)*u%e,R=Z(B,eh,e);if(!Ja.eql(Ja.sqr(R),t))throw new Error("Cannot find square root");return R}var Ja=kr(Qa.p,{sqrt:Jg}),Qg=Xl(Qa,{Fp:Ja,endo:Wg}),Qe=Ql(Qg,Fr);function th(t,e,r){let n=Vo.digest(e instanceof Uint8Array?e:e.subarray());if(Vr(n))return n.then(({digest:o})=>(r?.signal?.throwIfAborted(),Qe.sign(o,t,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new kn(String(o))});try{return Qe.sign(n.digest,t,{prehash:!1,format:"der"})}catch(o){throw new kn(String(o))}}function rh(t,e,r,n){let o=Vo.digest(r instanceof Uint8Array?r:r.subarray());if(Vr(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Qe.verify(e,i,t,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new On(String(i))});try{return n?.signal?.throwIfAborted(),Qe.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(i){throw new On(String(i))}}var jn=class{type="secp256k1";raw;_key;constructor(e){this._key=ih(e),this.raw=nh(this._key)}toMultihash(){return er.digest(_t(this))}toCID(){return ze.createV1(114,this.toMultihash())}toString(){return fe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Be(this.raw,e.raw)}verify(e,r,n){return rh(this._key,r,e,n)}},wi=class{type="secp256k1";raw;publicKey;constructor(e,r){this.raw=oh(e),this.publicKey=new jn(r??sh(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Be(this.raw,e.raw)}sign(e,r){return th(this.raw,e,r)}};function ec(t){return new jn(t)}async function ah(){let t=ey();return new wi(t)}function nh(t){return Qe.Point.fromBytes(t).toBytes()}function oh(t){try{return Qe.getPublicKey(t,!0),t}catch(e){throw new mn(String(e))}}function ih(t){try{return Qe.Point.fromBytes(t),t}catch(e){throw new Ar(String(e))}}function sh(t){try{return Qe.getPublicKey(t,!0)}catch(e){throw new mn(String(e))}}function ey(){return Qe.utils.randomSecretKey()}async function ch(t,e){if(t==="Ed25519")return Il();if(t==="secp256k1")return ah();if(t==="RSA")return Ga(ty(e));if(t==="ECDSA")return Ff(ry(e));throw new vr}function uh(t,e){let{Type:r,Data:n}=ut.decode(t),o=n??new Uint8Array;switch(r){case X.RSA:return Ha(o,e);case X.Ed25519:return Ia(o);case X.secp256k1:return ec(o);case X.ECDSA:return Zs(o);default:throw new vr}}function fh(t){let{Type:e,Data:r}=ut.decode(t.digest),n=r??new Uint8Array;switch(e){case X.Ed25519:return Ia(n);case X.secp256k1:return ec(n);case X.ECDSA:return Zs(n);default:throw new vr}}function _t(t){return ut.encode({Type:X[t.type],Data:t.raw})}function ty(t){return t==null?2048:parseInt(t,10)}function ry(t){if(t==="P-256"||t==null)return"P-256";if(t==="P-384")return"P-384";if(t==="P-521")return"P-521";throw new W("Unsupported curve, should be P-256, P-384 or P-521")}var q8=new Uint8Array(0);function lh(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function ny(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var y=0,d=0,g=0,E=h.length;g!==E&&h[g]===0;)g++,y++;for(var I=(E-g)*f+1>>>0,C=new Uint8Array(I);g!==E;){for(var B=h[g],R=0,_=I-1;(B!==0||R<d)&&_!==-1;_--,R++)B+=256*C[_]>>>0,C[_]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");d=R,g++}for(var x=I-d;x!==I&&C[x]===0;)x++;for(var D=c.repeat(y);x<I;++x)D+=t.charAt(C[x]);return D}function m(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var y=0;if(h[y]!==" "){for(var d=0,g=0;h[y]===c;)d++,y++;for(var E=(h.length-y)*u+1>>>0,I=new Uint8Array(E);h[y];){var C=r[h.charCodeAt(y)];if(C===255)return;for(var B=0,R=E-1;(C!==0||B<g)&&R!==-1;R--,B++)C+=a*I[R]>>>0,I[R]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");g=B,y++}if(h[y]!==" "){for(var _=E-g;_!==E&&I[_]===0;)_++;for(var x=new Uint8Array(d+(E-_)),D=d;_!==E;)x[D++]=I[_++];return x}}}function b(h){var y=m(h);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:m,decode:b}}var oy=ny,iy=oy,hh=iy;var tc=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")}},rc=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 dh(this,e)}},nc=class{decoders;constructor(e){this.decoders=e}or(e){return dh(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 dh(t,e){return new nc({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var oc=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 tc(e,r,n),this.decoder=new rc(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ph({name:t,prefix:e,encode:r,decode:n}){return new oc(t,e,r,n)}function ic({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=hh(r,t);return ph({prefix:e,name:t,encode:n,decode:i=>lh(o(i))})}function sy(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,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function ay(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],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 cy(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function Se({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=cy(n);return ph({prefix:e,name:t,encode(i){return ay(i,n,r)},decode(i){return sy(i,o,r,t)}})}var mh=Se({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),W8=Se({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),J8=Se({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Q8=Se({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),e3=Se({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),t3=Se({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),r3=Se({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),n3=Se({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),o3=Se({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var gh=ic({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),a3=ic({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var yh=Se({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),f3=Se({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),l3=Se({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),h3=Se({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function uy(t,e){if(typeof t=="string")return fy(t);if(typeof t=="number")return dy(t,e);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}var Ei=uy;function fy(t){if(typeof t!="string"||t.length===0||t.length>100)throw 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 Error(`Unknown unit "${i}" provided to ms.parse(). value=${JSON.stringify(t)}`)}}function ly(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 hy(t){let e=Math.abs(t);return e>=315576e5?lr(t,e,315576e5,"year"):e>=26298e5?lr(t,e,26298e5,"month"):e>=6048e5?lr(t,e,6048e5,"week"):e>=864e5?lr(t,e,864e5,"day"):e>=36e5?lr(t,e,36e5,"hour"):e>=6e4?lr(t,e,6e4,"minute"):e>=1e3?lr(t,e,1e3,"second"):`${t} ms`}function dy(t,e){if(typeof t!="number"||!Number.isFinite(t))throw Error("Value provided to ms.format() must be of type number.");return e?.long?hy(t):ly(t)}function lr(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function sc(t){r.debug=r,r.default=r,r.coerce=c,r.disable=i,r.enable=o,r.enabled=s,r.humanize=Ei,r.destroy=u,Object.keys(t).forEach(f=>{r[f]=t[f]}),r.names=[],r.skips=[],r.formatters={};function e(f){let l=0;for(let m=0;m<f.length;m++)l=(l<<5)-l+f.charCodeAt(m),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=e;function r(f,l){let m,b=null,h,y;function d(...g){if(!d.enabled)return;let E=d,I=Number(new Date),C=I-(m||I);E.diff=C,E.prev=m,E.curr=I,m=I,g[0]=r.coerce(g[0]),typeof g[0]!="string"&&g.unshift("%O");let B=0;g[0]=g[0].replace(/%([a-zA-Z%])/g,(_,x)=>{if(_==="%%")return"%";B++;let D=r.formatters[x];if(typeof D=="function"){let M=g[B];_=D.call(E,M),g.splice(B,1),B--}return _}),r.formatArgs.call(E,g),l?.onLog!=null&&l.onLog(...g),(E.log||r.log).apply(E,g)}return d.namespace=f,d.useColors=r.useColors(),d.color=r.selectColor(f),d.extend=n,d.destroy=r.destroy,Object.defineProperty(d,"enabled",{enumerable:!0,configurable:!1,get:()=>b!==null?b:(h!==r.namespaces&&(h=r.namespaces,y=r.enabled(f)),y),set:g=>{b=g}}),typeof r.init=="function"&&r.init(d),d}function n(f,l){let m=r(this.namespace+(typeof l>"u"?":":l)+f);return m.log=this.log,m}function o(f){r.save(f),r.namespaces=f,r.names=[],r.skips=[];let l,m=(typeof f=="string"?f:"").split(/[\s,]+/),b=m.length;for(l=0;l<b;l++)m[l]&&(f=m[l].replace(/\*/g,".*?"),f[0]==="-"?r.skips.push(new RegExp("^"+f.substr(1)+"$")):r.names.push(new RegExp("^"+f+"$")))}function i(){let f=[...r.names.map(a),...r.skips.map(a).map(l=>"-"+l)].join(",");return r.enable(""),f}function s(f){if(f[f.length-1]==="*")return!0;let l,m;for(l=0,m=r.skips.length;l<m;l++)if(r.skips[l].test(f))return!1;for(l=0,m=r.names.length;l<m;l++)if(r.names[l].test(f))return!0;return!1}function a(f){return f.toString().substring(2,f.toString().length-2).replace(/\.\*\?$/,"*")}function c(f){return f instanceof Error?f.stack??f.message:f}function u(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var Si=wy(),py=["#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 my(){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 gy(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+Ei(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 yy=console.debug??console.log??(()=>{});function by(t){try{t?Si?.setItem("debug",t):Si?.removeItem("debug")}catch{}}function xy(){let t;try{t=Si?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function wy(){try{return localStorage}catch{}}function Ey(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var bh=sc({formatArgs:gy,save:by,load:xy,useColors:my,setupFormatters:Ey,colors:py,storage:Si,log:yy});var _e=bh;_e.formatters.b=t=>t==null?"undefined":gh.baseEncode(t);_e.formatters.t=t=>t==null?"undefined":mh.baseEncode(t);_e.formatters.m=t=>t==null?"undefined":yh.baseEncode(t);_e.formatters.p=t=>t==null?"undefined":t.toString();_e.formatters.c=t=>t==null?"undefined":t.toString();_e.formatters.k=t=>t==null?"undefined":t.toString();_e.formatters.a=t=>t==null?"undefined":t.toString();function xh(t,e=""){let r=wh(t.message),n=wh(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
2
+ "use strict";var HeliaIpns=(()=>{var Fs=Object.create;var Vt=Object.defineProperty;var ks=Object.getOwnPropertyDescriptor;var Ds=Object.getOwnPropertyNames;var Us=Object.getPrototypeOf,_s=Object.prototype.hasOwnProperty;var Ls=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),W=(t,e)=>{for(var r in e)Vt(t,r,{get:e[r],enumerable:!0})},oi=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ds(e))!_s.call(t,i)&&i!==r&&Vt(t,i,{get:()=>e[i],enumerable:!(n=ks(e,i))||n.enumerable});return t};var $r=(t,e,r)=>(r=t!=null?Fs(Us(t)):{},oi(e||!t||!t.__esModule?Vt(r,"default",{value:t,enumerable:!0}):r,t)),Rs=t=>oi(Vt({},"__esModule",{value:!0}),t);var jt=Ls((cl,Xr)=>{var al=(function(){typeof Xr<"u"&&(Xr.exports=E);var t=86400,e=3200,r=146097*e/400,n=t*r,i=1e3*n,o=864e13,s=4294967296,a=1e6,u="000000000",f=Math.trunc||function(g){var w=g-g%1;return w==0&&(g<0||g===0&&1/g!=1/0)?-0:w},l=E.prototype,p=(E.fromDate=function(g){return new E(+g)},E.fromInt64BE=P(0,1,2,3,0,4),E.fromInt64LE=P(3,2,1,0,4,0),E.fromString=function(C){var w,A=new E,C=(C+="").replace(/^\s*[+\-]?\d+/,function(U){var U=+U,M=1970+(U-1970)%400;return A.year=U-M,M}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(I,U,M){return U<0&&(M*=-1),w=6e4*(60*+U+ +M),""}).replace(/\.\d+$/,function(I){return A.nano=+(I+u).substr(1,9),""}).split(/\D+/);if(1<C.length?C[1]--:C[1]=0,A.time=w=Date.UTC.apply(Date,C)-(w||0),isNaN(w))throw new TypeError("Invalid Date");return x(A)},E.fromTimeT=function(g){return F(g,0)},l.year=0,l.time=0,l.nano=0,l.addNano=function(g){return this.nano+=+g||0,this},l.getNano=function(){var g=x(this);return(g.time%1e3*a+ +g.nano+1e9)%1e9},l.getTimeT=function(){var w=x(this),g=Math.floor(w.time/1e3),w=w.year;return w&&(g+=w*r*t/e),g},l.getYear=function(){return this.toDate().getUTCFullYear()+this.year},l.toDate=function(){return T(x(this).time)},l.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},l.toString=function(g){var w=this,A=w.toDate(),C={H:function(){return K(A.getUTCHours())},L:function(){return R(A.getUTCMilliseconds(),3)},M:function(){return K(A.getUTCMinutes())},N:function(){return R(w.getNano(),9)},S:function(){return K(A.getUTCSeconds())},Y:function(){var I=w.getYear();return 999999<I?"+"+I:9999<I?"+"+R(I,6):0<=I?R(I,4):-999999<=I?"-"+R(-I,6):I},a:function(){return b[A.getUTCDay()]},b:function(){return m[A.getUTCMonth()]},d:function(){return K(A.getUTCDate())},e:function(){return(function(I){return(9<I?"":" ")+(0|I)})(A.getUTCDate())},m:function(){return K(A.getUTCMonth()+1)}};return(function I(U){return U.replace(/%./g,function(M){var _=M[1],N=S[_],_=C[_];return N?I(N):_?_():M})})(g||p)},l.writeInt64BE=k(0,1,2,3,0,4),l.writeInt64LE=k(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),m=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],b=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],S={"%":"%",F:"%Y-%m-%d",n:`
3
+ `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return E;function E(g,w,A){var C=this;if(!(C instanceof E))return new E(g,w,A);C.time=+g||0,C.nano=+w||0,C.year=+A||0,x(C)}function x(g){var w,A,C,I=g.year,U=g.time,M=g.nano,N=((M<0||a<=M)&&(M-=(A=Math.floor(M/a))*a,U+=A,A=1),I%e);return(U<-o||o<U||N)&&((w=f(U/i))&&(I+=w*e,U-=w*i),(C=T(U)).setUTCFullYear(N+C.getUTCFullYear()),C=(U=+C)+(w=f((I-=N)/e))*i,w&&-o<=C&&C<=o&&(I-=w*e,U=C),A=1),A&&(g.year=I,g.time=U,g.nano=M),g}function T(g){var w=new Date(0);return w.setTime(g),w}function F(I,C){I=+I||0;var A=f((C=(C|0)*s)/n)+f(I/n),C=C%n+I%n,I=f(C/n);return I&&(A+=I,C-=I*n),new E(1e3*C,0,A*e)}function k(g,w,A,C,I,U){return function(N,_){var ge=x(this);N=N||new Array(8),B(N,_|=0);var Ve=Math.floor(ge.time/1e3),ge=ge.year*(r*t/e),me=f(ge/s)+f(Ve/s),ge=ge%s+Ve%s,Ve=Math.floor(ge/s);return Ve&&(me+=Ve,ge-=Ve*s),M(N,_+I,me),M(N,_+U,ge),N};function M(N,_,me){N[_+g]=me>>24&255,N[_+w]=me>>16&255,N[_+A]=me>>8&255,N[_+C]=255&me}}function P(g,w,A,C,I,U){return function(N,_){B(N,_|=0);var me=M(N,_+I);return F(M(N,_+U),me)};function M(N,_){return 16777216*N[_+g]+(N[_+w]<<16|N[_+A]<<8|N[_+C])}}function B(g,w){if(g=g&&g.length,g==null)throw new TypeError("Invalid Buffer");if(g<w+8)throw new RangeError("Out of range")}function K(g){return(9<g?"":"0")+(0|g)}function R(g,w){return(u+(0|g)).substr(-w)}})()});var Vu={};W(Vu,{ipns:()=>Pu,ipnsResolver:()=>$u});var Kr={};W(Kr,{base32:()=>Te,base32hex:()=>Gs,base32hexpad:()=>Ys,base32hexpadupper:()=>Xs,base32hexupper:()=>js,base32pad:()=>Ks,base32padupper:()=>Hs,base32upper:()=>qs,base32z:()=>Ws});var zu=new Uint8Array(0);function si(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function ye(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return De(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return De(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function ai(t){return new TextEncoder().encode(t)}function ci(t){return new TextDecoder().decode(t)}function Bs(t){return t?.buffer instanceof ArrayBuffer}function De(t){return Bs(t)?t:t.slice()}function Ms(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<t.length;i++){var o=t.charAt(i),s=o.charCodeAt(0);if(r[s]!==255)throw new TypeError(o+" is ambiguous");r[s]=i}var a=t.length,u=t.charAt(0),f=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function p(S){if(S instanceof Uint8Array||(ArrayBuffer.isView(S)?S=new Uint8Array(S.buffer,S.byteOffset,S.byteLength):Array.isArray(S)&&(S=Uint8Array.from(S))),!(S instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(S.length===0)return"";for(var E=0,x=0,T=0,F=S.length;T!==F&&S[T]===0;)T++,E++;for(var k=(F-T)*l+1>>>0,P=new Uint8Array(k);T!==F;){for(var B=S[T],K=0,R=k-1;(B!==0||K<x)&&R!==-1;R--,K++)B+=256*P[R]>>>0,P[R]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");x=K,T++}for(var g=k-x;g!==k&&P[g]===0;)g++;for(var w=u.repeat(E);g<k;++g)w+=t.charAt(P[g]);return w}function m(S){if(typeof S!="string")throw new TypeError("Expected String");if(S.length===0)return new Uint8Array;var E=0;if(S[E]!==" "){for(var x=0,T=0;S[E]===u;)x++,E++;for(var F=(S.length-E)*f+1>>>0,k=new Uint8Array(F);S[E];){var P=r[S.charCodeAt(E)];if(P===255)return;for(var B=0,K=F-1;(P!==0||B<T)&&K!==-1;K--,B++)P+=a*k[K]>>>0,k[K]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");T=B,E++}if(S[E]!==" "){for(var R=F-T;R!==F&&k[R]===0;)R++;for(var g=new Uint8Array(x+(F-R)),w=x;R!==F;)g[w++]=k[R++];return g}}}function b(S){var E=m(S);if(E)return E;throw new Error(`Non-${e} character`)}return{encode:p,decodeUnsafe:m,decode:b}}var Ps=Ms,$s=Ps,li=$s;var Vr=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Or=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let i=r.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return fi(this,e)}},zr=class{decoders;constructor(e){this.decoders=e}or(e){return fi(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function fi(t,e){return new zr({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var qr=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new Vr(e,r,n),this.decoder=new Or(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Oe({name:t,prefix:e,encode:r,decode:n}){return new qr(t,e,r,n)}function Se({name:t,prefix:e,alphabet:r}){let{encode:n,decode:i}=li(r,t);return Oe({prefix:e,name:t,encode:n,decode:o=>ye(i(o))})}function Vs(t,e,r,n){let i=t.length;for(;t[i-1]==="=";)--i;let o=new Uint8Array(i*r/8|0),s=0,a=0,u=0;for(let f=0;f<i;++f){let l=e[t[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|l,s+=r,s>=8&&(s-=8,o[u++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return o}function Os(t,e,r){let n=e[e.length-1]==="=",i=(1<<r)-1,o="",s=0,a=0;for(let u=0;u<t.length;++u)for(a=a<<8|t[u],s+=8;s>r;)s-=r,o+=e[i&a>>s];if(s!==0&&(o+=e[i&a<<r-s]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function zs(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function L({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let i=zs(n);return Oe({prefix:e,name:t,encode(o){return Os(o,n,r)},decode(o){return Vs(o,i,r,t)}})}var Te=L({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),qs=L({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ks=L({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Hs=L({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Gs=L({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),js=L({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ys=L({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Xs=L({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ws=L({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Hr={};W(Hr,{base36:()=>ne,base36upper:()=>Js});var ne=Se({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Js=Se({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Gr={};W(Gr,{base58btc:()=>j,base58flickr:()=>Qs});var j=Se({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Qs=Se({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Zs=pi,hi=128,ea=127,ta=~ea,ra=Math.pow(2,31);function pi(t,e,r){e=e||[],r=r||0;for(var n=r;t>=ra;)e[r++]=t&255|hi,t/=128;for(;t&ta;)e[r++]=t&255|hi,t>>>=7;return e[r]=t|0,pi.bytes=r-n+1,e}var na=jr,ia=128,di=127;function jr(t,n){var r=0,n=n||0,i=0,o=n,s,a=t.length;do{if(o>=a)throw jr.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&di)<<i:(s&di)*Math.pow(2,i),i+=7}while(s>=ia);return jr.bytes=o-n,r}var oa=Math.pow(2,7),sa=Math.pow(2,14),aa=Math.pow(2,21),ca=Math.pow(2,28),ua=Math.pow(2,35),la=Math.pow(2,42),fa=Math.pow(2,49),ha=Math.pow(2,56),da=Math.pow(2,63),pa=function(t){return t<oa?1:t<sa?2:t<aa?3:t<ca?4:t<ua?5:t<la?6:t<fa?7:t<ha?8:t<da?9:10},ma={encode:Zs,decode:na,encodingLength:pa},ga=ma,at=ga;function ct(t,e=0){return[at.decode(t,e),at.decode.bytes]}function ze(t,e,r=0){return at.encode(t,e,r),e}function qe(t){return at.encodingLength(t)}function He(t,e){let r=e.byteLength,n=qe(t),i=n+qe(r),o=new Uint8Array(i+r);return ze(t,o,0),ze(r,o,n),o.set(e,i),new Ke(t,r,e,o)}function ut(t){let e=ye(t),[r,n]=ct(e),[i,o]=ct(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new Ke(r,i,s,e)}function mi(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&si(t.bytes,r.bytes)}}var Ke=class{code;size;digest;bytes;constructor(e,r,n,i){this.code=e,this.size=r,this.digest=De(n),this.bytes=De(i)}};function gi(t,e){let{bytes:r,version:n}=t;return n===0?xa(r,Yr(t),e??j.encoder):wa(r,Yr(t),e??Te.encoder)}var yi=new WeakMap;function Yr(t){let e=yi.get(t);if(e==null){let r=new Map;return yi.set(t,r),r}return e}var fe=class t{code;version;multihash;bytes;"/";constructor(e,r,n,i){this.code=r,this.version=e,this.multihash=n,this.bytes=De(i),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==lt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==ba)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=He(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&mi(e.multihash,n.multihash)}toString(e){return gi(this,e)}toJSON(){return{"/":gi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:i,multihash:o,bytes:s}=r;return new t(n,i,o,s??xi(n,i,o.bytes))}else if(r[Ea]===!0){let{version:n,multihash:i,code:o}=r,s=ut(i);return t.create(n,o,s)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==lt)throw new Error(`Version 0 CID must use dag-pb (code: ${lt}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let i=xi(e,r,n.bytes);return new t(e,r,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,lt,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,i=ye(e.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=i.subarray(r.multihashSize-r.digestSize),s=new Ke(r.multihashCode,r.digestSize,o,i);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[p,m]=ct(e.subarray(r));return r+=m,p},i=n(),o=lt;if(i===18?(i=0,r=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=r,a=n(),u=n(),f=r+u,l=f-s;return{version:i,codec:o,multihashCode:a,digestSize:u,multihashSize:l,size:f}}static parse(e,r){let[n,i]=ya(e,r),o=t.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Yr(o).set(n,e),o}};function ya(t,e){switch(t[0]){case"Q":{let r=e??j;return[j.prefix,r.decode(`${j.prefix}${t}`)]}case j.prefix:{let r=e??j;return[j.prefix,r.decode(t)]}case Te.prefix:{let r=e??Te;return[Te.prefix,r.decode(t)]}case ne.prefix:{let r=e??ne;return[ne.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function xa(t,e,r){let{prefix:n}=r;if(n!==j.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=e.get(n);if(i==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return i}function wa(t,e,r){let{prefix:n}=r,i=e.get(n);if(i==null){let o=r.encode(t);return e.set(n,o),o}else return i}var lt=112,ba=18;function xi(t,e,r){let n=qe(t),i=n+qe(e),o=new Uint8Array(i+r.byteLength);return ze(t,o,0),ze(e,o,n),o.set(r,i),o}var Ea=Symbol.for("@ipld/js-cid/CID");var je=BigInt(6e4)*5000000n,wi=5;var zt=class extends Error{static name="RecordsFailedValidationError";name="RecordsFailedValidationError"};var Ye=class extends Error{static name="InvalidValueError";name="InvalidValueError"};var ft=class extends Error{static name="RecordNotFoundError";name="RecordNotFoundError"},qt=class extends Error{static name="SignatureCreationError";name="SignatureCreationError"},se=class extends Error{static name="SignatureVerificationError";name="SignatureVerificationError"},Kt=class extends Error{static name="RecordExpiredError";name="RecordExpiredError"},Ue=class extends Error{static name="UnsupportedValidityError";name="UnsupportedValidityError"},Ht=class extends Error{static name="RecordTooLargeError";name="RecordTooLargeError"},Gt=class extends Error{static name="InvalidRecordDataError";name="InvalidRecordDataError"},Xe=class extends Error{static name="InvalidEmbeddedPublicKeyError";name="InvalidEmbeddedPublicKeyError"};var Tn=$r(jt(),1);function Wr(t=0){return new Uint8Array(t)}function H(t=0){return new Uint8Array(t)}var Sa=Math.pow(2,7),Ta=Math.pow(2,14),Ia=Math.pow(2,21),bi=Math.pow(2,28),Ei=Math.pow(2,35),Si=Math.pow(2,42),Ti=Math.pow(2,49),G=128,Ie=127;function xe(t){if(t<Sa)return 1;if(t<Ta)return 2;if(t<Ia)return 3;if(t<bi)return 4;if(t<Ei)return 5;if(t<Si)return 6;if(t<Ti)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Yt(t,e,r=0){switch(xe(t)){case 8:e[r++]=t&255|G,t/=128;case 7:e[r++]=t&255|G,t/=128;case 6:e[r++]=t&255|G,t/=128;case 5:e[r++]=t&255|G,t/=128;case 4:e[r++]=t&255|G,t>>>=7;case 3:e[r++]=t&255|G,t>>>=7;case 2:e[r++]=t&255|G,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Xt(t,e){let r=t[e],n=0;if(n+=r&Ie,r<G||(r=t[e+1],n+=(r&Ie)<<7,r<G)||(r=t[e+2],n+=(r&Ie)<<14,r<G)||(r=t[e+3],n+=(r&Ie)<<21,r<G)||(r=t[e+4],n+=(r&Ie)*bi,r<G)||(r=t[e+5],n+=(r&Ie)*Ei,r<G)||(r=t[e+6],n+=(r&Ie)*Si,r<G)||(r=t[e+7],n+=(r&Ie)*Ti,r<G))return n;throw new RangeError("Could not decode varint")}function Ca(t){return t.buffer instanceof ArrayBuffer}function Ii(t){return Ca(t)?t:t.slice()}var Jr=new Float32Array([-0]),Ce=new Uint8Array(Jr.buffer);function Ci(t,e,r){Jr[0]=t,e[r]=Ce[0],e[r+1]=Ce[1],e[r+2]=Ce[2],e[r+3]=Ce[3]}function Ai(t,e){return Ce[0]=t[e],Ce[1]=t[e+1],Ce[2]=t[e+2],Ce[3]=t[e+3],Jr[0]}var Qr=new Float64Array([-0]),z=new Uint8Array(Qr.buffer);function vi(t,e,r){Qr[0]=t,e[r]=z[0],e[r+1]=z[1],e[r+2]=z[2],e[r+3]=z[3],e[r+4]=z[4],e[r+5]=z[5],e[r+6]=z[6],e[r+7]=z[7]}function Ni(t,e){return z[0]=t[e],z[1]=t[e+1],z[2]=t[e+2],z[3]=t[e+3],z[4]=t[e+4],z[5]=t[e+5],z[6]=t[e+6],z[7]=t[e+7],Qr[0]}var Aa=BigInt(Number.MAX_SAFE_INTEGER),va=BigInt(Number.MIN_SAFE_INTEGER),J=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return _e;if(e<Aa&&e>va)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,i=e-(n<<32n);return r&&(n=~n|0n,i=~i|0n,++i>Fi&&(i=0n,++n>Fi&&(n=0n))),new t(Number(i),Number(n))}static fromNumber(e){if(e===0)return _e;let r=e<0;r&&(e=-e);let n=e>>>0,i=(e-n)/4294967296>>>0;return r&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new t(n,i)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):_e}},_e=new J(0,0);_e.toBigInt=function(){return 0n};_e.zzEncode=_e.zzDecode=function(){return this};_e.length=function(){return 1};var Fi=4294967296n;function ki(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Di(t,e,r){if(r-e<1)return"";let i,o=[],s=0,a;for(;e<r;)a=t[e++],a<128?o[s++]=a:a>191&&a<224?o[s++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function Zr(t,e,r){let n=r,i,o;for(let s=0;s<t.length;++s)i=t.charCodeAt(s),i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&((o=t.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128);return r-n}function ae(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Wt(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var en=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Ii(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,ae(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw ae(this,4);return Wt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ae(this,4);return Wt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ae(this,4);let e=Ai(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw ae(this,4);let e=Ni(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw ae(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Di(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw ae(this,e);this.pos+=e}else do if(this.pos>=this.len)throw ae(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new J(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw ae(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw ae(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw ae(this,8);let e=Wt(this.buf,this.pos+=4),r=Wt(this.buf,this.pos+=4);return new J(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Xt(this.buf,this.pos);return this.pos+=xe(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function ht(t){return new en(t instanceof Uint8Array?t:t.subarray())}function dt(t,e,r){let n=ht(t);return e.decode(n,void 0,r)}var tn={};W(tn,{base10:()=>Na});var Na=Se({prefix:"9",name:"base10",alphabet:"0123456789"});var rn={};W(rn,{base16:()=>Fa,base16upper:()=>ka});var Fa=L({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ka=L({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var nn={};W(nn,{base2:()=>Da});var Da=L({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var on={};W(on,{base256emoji:()=>Ba});var _i=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Ua=_i.reduce((t,e,r)=>(t[r]=e,t),[]),_a=_i.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function La(t){return t.reduce((e,r)=>(e+=Ua[r],e),"")}function Ra(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let i=_a[n];if(i==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(i)}return new Uint8Array(e)}var Ba=Oe({prefix:"\u{1F680}",name:"base256emoji",encode:La,decode:Ra});var an={};W(an,{base64:()=>sn,base64pad:()=>Ma,base64url:()=>Pa,base64urlpad:()=>$a});var sn=L({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ma=L({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Pa=L({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),$a=L({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var cn={};W(cn,{base8:()=>Va});var Va=L({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var un={};W(un,{identity:()=>Oa});var Oa=Oe({prefix:"\0",name:"identity",encode:t=>ci(t),decode:t=>ai(t)});var kl=new TextEncoder,Dl=new TextDecoder;var ln={};W(ln,{identity:()=>Ga});var Li=0,Ka="identity",Ri=ye;function Ha(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return He(Li,Ri(t))}var Ga={code:Li,name:Ka,encode:Ri,digest:Ha};var dn={};W(dn,{sha256:()=>Ya,sha512:()=>Xa});var ja=20;function hn({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:i}){return new fn(t,e,r,n,i)}var fn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,i,o){this.name=e,this.code=r,this.encode=n,this.minDigestLength=i??ja,this.maxDigestLength=o}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Bi(n,this.code,r?.truncate):n.then(i=>Bi(i,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Bi(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return He(e,t)}function Pi(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Ya=hn({name:"sha2-256",code:18,encode:Pi("SHA-256")}),Xa=hn({name:"sha2-512",code:19,encode:Pi("SHA-512")});var pn={...un,...nn,...cn,...tn,...rn,...Kr,...Hr,...Gr,...an,...on},Kl={...dn,...ln};function Vi(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var $i=Vi("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),mn=Vi("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=H(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Wa={utf8:$i,"utf-8":$i,hex:pn.base16,latin1:mn,ascii:mn,binary:mn,...pn},Jt=Wa;function $(t,e="utf8"){let r=Jt[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function gn(t){let e=t??8192,r=e>>>1,n,i=e;return function(s){if(s<1||s>r)return H(s);i+s>e&&(n=H(e),i=0);let a=n.subarray(i,i+=s);return(i&7)!==0&&(i=(i|7)+1),a}}var Le=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function yn(){}var wn=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Ja=gn();function Qa(t){return globalThis.Buffer!=null?H(t):Ja(t)}var mt=class{len;head;tail;states;constructor(){this.len=0,this.head=new Le(yn,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Le(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new bn((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Qt,10,J.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=J.fromBigInt(e);return this._push(Qt,r.length(),r)}uint64Number(e){return this._push(Yt,xe(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=J.fromBigInt(e).zzEncode();return this._push(Qt,r.length(),r)}sint64Number(e){let r=J.fromNumber(e).zzEncode();return this._push(Qt,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(xn,1,e?1:0)}fixed32(e){return this._push(pt,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=J.fromBigInt(e);return this._push(pt,4,r.lo)._push(pt,4,r.hi)}fixed64Number(e){let r=J.fromNumber(e);return this._push(pt,4,r.lo)._push(pt,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Ci,4,e)}double(e){return this._push(vi,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(xn,1,0):this.uint32(r)._push(ec,r,e)}string(e){let r=ki(e);return r!==0?this.uint32(r)._push(Zr,r,e):this._push(xn,1,0)}fork(){return this.states=new wn(this),this.head=this.tail=new Le(yn,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Le(yn,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=Qa(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function xn(t,e,r){e[r]=t&255}function Za(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var bn=class extends Le{next;constructor(e,r){super(Za,e,r),this.next=void 0}};function Qt(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function pt(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function ec(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(mt.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(tc,e,t),this},mt.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(rc,e,t),this});function tc(t,e,r){e.set(t,r)}function rc(t,e,r){t.length<40?Zr(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set($(t),r)}function En(){return new mt}function gt(t,e){let r=En();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*yt(t,e,r){let n=ht(t);yield*e.stream(n,void 0,"$",r)}var Zt={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function er(t,e,r,n,i){return{name:t,type:e,encode:r,decode:n,stream:i}}function Sn(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(s,a){let u=e(s);a.int32(u)},n=function(s){let a=s.int32();return e(a)},i=function*(s){let a=s.int32();yield e(a)};return er("enum",Zt.VARINT,r,n,i)}function xt(t,e,r){return er("message",Zt.LENGTH_DELIMITED,t,e,r)}var O;(function(t){let e;(function(a){a.EOL="EOL"})(e=t.ValidityType||(t.ValidityType={}));let r;(function(a){a[a.EOL=0]="EOL"})(r||(r={})),(function(a){a.codec=()=>Sn(r)})(e=t.ValidityType||(t.ValidityType={}));let n;t.codec=()=>(n==null&&(n=xt((a,u,f={})=>{f.lengthDelimited!==!1&&u.fork(),a.value!=null&&(u.uint32(10),u.bytes(a.value)),a.signatureV1!=null&&(u.uint32(18),u.bytes(a.signatureV1)),a.validityType!=null&&(u.uint32(24),t.ValidityType.codec().encode(a.validityType,u)),a.validity!=null&&(u.uint32(34),u.bytes(a.validity)),a.sequence!=null&&(u.uint32(40),u.uint64(a.sequence)),a.ttl!=null&&(u.uint32(48),u.uint64(a.ttl)),a.publicKey!=null&&(u.uint32(58),u.bytes(a.publicKey)),a.signatureV2!=null&&(u.uint32(66),u.bytes(a.signatureV2)),a.data!=null&&(u.uint32(74),u.bytes(a.data)),f.lengthDelimited!==!1&&u.ldelim()},(a,u,f={})=>{let l={},p=u==null?a.len:a.pos+u;for(;a.pos<p;){let m=a.uint32();switch(m>>>3){case 1:{l.value=a.bytes();break}case 2:{l.signatureV1=a.bytes();break}case 3:{l.validityType=t.ValidityType.codec().decode(a);break}case 4:{l.validity=a.bytes();break}case 5:{l.sequence=a.uint64();break}case 6:{l.ttl=a.uint64();break}case 7:{l.publicKey=a.bytes();break}case 8:{l.signatureV2=a.bytes();break}case 9:{l.data=a.bytes();break}default:{a.skipType(m&7);break}}}return l},function*(a,u,f,l={}){let p=u==null?a.len:a.pos+u;for(;a.pos<p;){let m=a.uint32();switch(m>>>3){case 1:{yield{field:`${f}.value`,value:a.bytes()};break}case 2:{yield{field:`${f}.signatureV1`,value:a.bytes()};break}case 3:{yield{field:`${f}.validityType`,value:t.ValidityType.codec().decode(a)};break}case 4:{yield{field:`${f}.validity`,value:a.bytes()};break}case 5:{yield{field:`${f}.sequence`,value:a.uint64()};break}case 6:{yield{field:`${f}.ttl`,value:a.uint64()};break}case 7:{yield{field:`${f}.publicKey`,value:a.bytes()};break}case 8:{yield{field:`${f}.signatureV2`,value:a.bytes()};break}case 9:{yield{field:`${f}.data`,value:a.bytes()};break}default:{a.skipType(m&7);break}}}})),n);function i(a){return gt(a,t.codec())}t.encode=i;function o(a,u){return dt(a,t.codec(),u)}t.decode=o;function s(a,u){return yt(a,t.codec(),u)}t.stream=s})(O||(O={}));function tr(t,e){let r=e.map((n,i)=>({record:n,index:i}));return r.sort((n,i)=>{let o=n.record.sequence,s=i.record.sequence;if(o>s)return-1;if(o<s)return 1;if(n.record.validityType===O.ValidityType.EOL&&i.record.validityType===O.ValidityType.EOL){let a=Tn.default.fromString(n.record.validity).toDate(),u=Tn.default.fromString(i.record.validity).toDate();if(a.getTime()>u.getTime())return-1;if(a.getTime()<u.getTime())return 1}return 0}),r[0].index}function nc(t){return t?.buffer instanceof ArrayBuffer}function Oi(t){if(nc(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function rr(t,e){e==null&&(e=t.reduce((i,o)=>i+o.length,0));let r=H(e),n=0;for(let i of t)r.set(i,n),n+=i.length;return Oi(r)}function wt(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function nr(t){return t==null?!1:typeof t.type=="string"&&typeof t.code=="number"&&typeof t.verify=="function"}var we=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};function ic(t){return typeof t?.handleEvent=="function"}function oc(t){return(t!==!0&&t!==!1&&t?.once)??!1}var ir=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let i=oc(n);super.addEventListener(e,s=>{if(i){let a=this.#e.get(s.type);a!=null&&(a=a.filter(({callback:u})=>u!==r),this.#e.set(s.type,a))}ic(r)?r.handleEvent(s):r(s)},n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:r,once:i})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let i=this.#e.get(e);i!=null&&(i=i.filter(({callback:o})=>o!==r),this.#e.set(e,i))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var sc=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged"];function In(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=ac(t);return r||"Object"}function ac(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(sc.includes(e))return e}var c=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};c.uint=new c(0,"uint",!0);c.negint=new c(1,"negint",!0);c.bytes=new c(2,"bytes",!0);c.string=new c(3,"string",!0);c.array=new c(4,"array",!1);c.map=new c(5,"map",!1);c.tag=new c(6,"tag",!1);c.float=new c(7,"float",!0);c.false=new c(7,"false",!0);c.true=new c(7,"true",!0);c.null=new c(7,"null",!0);c.undefined=new c(7,"undefined",!0);c.break=new c(7,"break",!0);var d=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var bt=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",cc=new TextEncoder;function or(t){return bt&&globalThis.Buffer.isBuffer(t)}function Et(t){return t instanceof Uint8Array?or(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var uc=24,lc=200,sr=bt?t=>t.length>=uc?globalThis.Buffer.from(t):zi(t):t=>t.length>=lc?cc.encode(t):zi(t),he=t=>Uint8Array.from(t),qi=bt?(t,e,r)=>or(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),Ki=bt?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Et(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let i of t)n+i.length>r.length&&(i=i.subarray(0,r.length-n)),r.set(i,n),n+=i.length;return r},Hi=bt?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function ar(t,e){if(or(t)&&or(e))return t.compare(e);for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function zi(t){let e=[],r=0;for(let n=0;n<t.length;n++){let i=t.charCodeAt(n);i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(i=65536+((i&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(i>=55296&&i<=57343&&(i=65533),e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128)}return e}var fc=256,St=class{constructor(e=fc){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let i=r.length-(this.maxCursor-this.cursor)-1;r.set(e,i)}else{if(r){let i=r.length-(this.maxCursor-this.cursor)-1;i<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,i),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=Hi(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=qi(n,0,this.cursor)}else r=Ki(this.chunks,this.cursor);return e&&this.reset(),r}},cr=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var y="CBOR decode error:",ur="CBOR encode error:",Tt=[];Tt[23]=1;Tt[24]=2;Tt[25]=3;Tt[26]=5;Tt[27]=9;function be(t,e,r){if(t.length-e<r)throw new Error(`${y} not enough data for type`)}var V=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Q(t,e,r){be(t,e,1);let n=t[e];if(r.strict===!0&&n<V[0])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function Z(t,e,r){be(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<V[1])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function ee(t,e,r){be(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<V[2])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function te(t,e,r){be(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],i=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],o=(BigInt(n)<<BigInt(32))+BigInt(i);if(r.strict===!0&&o<V[3])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);if(o<=Number.MAX_SAFE_INTEGER)return Number(o);if(r.allowBigInt===!0)return o;throw new Error(`${y} integers outside of the safe integer range are not supported`)}function Gi(t,e,r,n){return new d(c.uint,Q(t,e+1,n),2)}function ji(t,e,r,n){return new d(c.uint,Z(t,e+1,n),3)}function Yi(t,e,r,n){return new d(c.uint,ee(t,e+1,n),5)}function Xi(t,e,r,n){return new d(c.uint,te(t,e+1,n),9)}function ie(t,e){return D(t,0,e.value)}function D(t,e,r){if(r<V[0]){let n=Number(r);t.push([e|n])}else if(r<V[1]){let n=Number(r);t.push([e|24,n])}else if(r<V[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<V[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<V[4]){let i=[e|27,0,0,0,0,0,0,0],o=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));i[8]=o&255,o=o>>8,i[7]=o&255,o=o>>8,i[6]=o&255,o=o>>8,i[5]=o&255,i[4]=s&255,s=s>>8,i[3]=s&255,s=s>>8,i[2]=s&255,s=s>>8,i[1]=s&255,t.push(i)}else throw new Error(`${y} encountered BigInt larger than allowable range`)}}ie.encodedSize=function(e){return D.encodedSize(e.value)};D.encodedSize=function(e){return e<V[0]?1:e<V[1]?2:e<V[2]?3:e<V[3]?5:9};ie.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Wi(t,e,r,n){return new d(c.negint,-1-Q(t,e+1,n),2)}function Ji(t,e,r,n){return new d(c.negint,-1-Z(t,e+1,n),3)}function Qi(t,e,r,n){return new d(c.negint,-1-ee(t,e+1,n),5)}var Cn=BigInt(-1),Zi=BigInt(1);function eo(t,e,r,n){let i=te(t,e+1,n);if(typeof i!="bigint"){let o=-1-i;if(o>=Number.MIN_SAFE_INTEGER)return new d(c.negint,o,9)}if(n.allowBigInt!==!0)throw new Error(`${y} integers outside of the safe integer range are not supported`);return new d(c.negint,Cn-BigInt(i),9)}function lr(t,e){let r=e.value,n=typeof r=="bigint"?r*Cn-Zi:r*-1-1;D(t,e.type.majorEncoded,n)}lr.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Cn-Zi:r*-1-1;return n<V[0]?1:n<V[1]?2:n<V[2]?3:n<V[3]?5:9};lr.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function It(t,e,r,n){be(t,e,r+n);let i=t.slice(e+r,e+r+n);return new d(c.bytes,i,r+n)}function to(t,e,r,n){return It(t,e,1,r)}function ro(t,e,r,n){return It(t,e,2,Q(t,e+1,n))}function no(t,e,r,n){return It(t,e,3,Z(t,e+1,n))}function io(t,e,r,n){return It(t,e,5,ee(t,e+1,n))}function oo(t,e,r,n){let i=te(t,e+1,n);if(typeof i=="bigint")throw new Error(`${y} 64-bit integer bytes lengths not supported`);return It(t,e,9,i)}function fr(t){return t.encodedBytes===void 0&&(t.encodedBytes=c.equals(t.type,c.string)?sr(t.value):t.value),t.encodedBytes}function We(t,e){let r=fr(e);D(t,e.type.majorEncoded,r.length),t.push(r)}We.encodedSize=function(e){let r=fr(e);return D.encodedSize(r.length)+r.length};We.compareTokens=function(e,r){return dc(fr(e),fr(r))};function dc(t,e){return t.length<e.length?-1:t.length>e.length?1:ar(t,e)}var so=new TextDecoder,mc=32;function gc(t,e,r){if(r-e<mc){let i="";for(let o=e;o<r;o++){let s=t[o];if(s&128)return so.decode(t.subarray(e,r));i+=String.fromCharCode(s)}return i}return so.decode(t.subarray(e,r))}function Ct(t,e,r,n,i){let o=r+n;be(t,e,o);let s=new d(c.string,gc(t,e+r,e+o),o);return i.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+o)),s}function ao(t,e,r,n){return Ct(t,e,1,r,n)}function co(t,e,r,n){return Ct(t,e,2,Q(t,e+1,n),n)}function uo(t,e,r,n){return Ct(t,e,3,Z(t,e+1,n),n)}function lo(t,e,r,n){return Ct(t,e,5,ee(t,e+1,n),n)}function fo(t,e,r,n){let i=te(t,e+1,n);if(typeof i=="bigint")throw new Error(`${y} 64-bit integer string lengths not supported`);return Ct(t,e,9,i,n)}var ho=We;function Je(t,e,r,n){return new d(c.array,n,r)}function po(t,e,r,n){return Je(t,e,1,r)}function mo(t,e,r,n){return Je(t,e,2,Q(t,e+1,n))}function go(t,e,r,n){return Je(t,e,3,Z(t,e+1,n))}function yo(t,e,r,n){return Je(t,e,5,ee(t,e+1,n))}function xo(t,e,r,n){let i=te(t,e+1,n);if(typeof i=="bigint")throw new Error(`${y} 64-bit integer array lengths not supported`);return Je(t,e,9,i)}function wo(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return Je(t,e,1,1/0)}function hr(t,e){D(t,c.array.majorEncoded,e.value)}hr.compareTokens=ie.compareTokens;hr.encodedSize=function(e){return D.encodedSize(e.value)};function Qe(t,e,r,n){return new d(c.map,n,r)}function bo(t,e,r,n){return Qe(t,e,1,r)}function Eo(t,e,r,n){return Qe(t,e,2,Q(t,e+1,n))}function So(t,e,r,n){return Qe(t,e,3,Z(t,e+1,n))}function To(t,e,r,n){return Qe(t,e,5,ee(t,e+1,n))}function Io(t,e,r,n){let i=te(t,e+1,n);if(typeof i=="bigint")throw new Error(`${y} 64-bit integer map lengths not supported`);return Qe(t,e,9,i)}function Co(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return Qe(t,e,1,1/0)}function dr(t,e){D(t,c.map.majorEncoded,e.value)}dr.compareTokens=ie.compareTokens;dr.encodedSize=function(e){return D.encodedSize(e.value)};function Ao(t,e,r,n){return new d(c.tag,r,1)}function vo(t,e,r,n){return new d(c.tag,Q(t,e+1,n),2)}function No(t,e,r,n){return new d(c.tag,Z(t,e+1,n),3)}function Fo(t,e,r,n){return new d(c.tag,ee(t,e+1,n),5)}function ko(t,e,r,n){return new d(c.tag,te(t,e+1,n),9)}function pr(t,e){D(t,c.tag.majorEncoded,e.value)}pr.compareTokens=ie.compareTokens;pr.encodedSize=function(e){return D.encodedSize(e.value)};var An=20,vn=21,Nn=22,Fn=23;function Do(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${y} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new d(c.null,null,1):new d(c.undefined,void 0,1)}function Uo(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return new d(c.break,void 0,1)}function kn(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${y} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${y} Infinity values are not supported`)}return new d(c.float,t,e)}function _o(t,e,r,n){return kn(Dn(t,e+1),3,n)}function Lo(t,e,r,n){return kn(Un(t,e+1),5,n)}function Ro(t,e,r,n){return kn($o(t,e+1),9,n)}function At(t,e,r){let n=e.value;if(n===!1)t.push([c.float.majorEncoded|An]);else if(n===!0)t.push([c.float.majorEncoded|vn]);else if(n===null)t.push([c.float.majorEncoded|Nn]);else if(n===void 0)t.push([c.float.majorEncoded|Fn]);else{let i,o=!1;(!r||r.float64!==!0)&&(Mo(n),i=Dn(ce,1),n===i||Number.isNaN(n)?(ce[0]=249,t.push(ce.slice(0,3)),o=!0):(Po(n),i=Un(ce,1),n===i&&(ce[0]=250,t.push(ce.slice(0,5)),o=!0))),o||(Ec(n),i=$o(ce,1),ce[0]=251,t.push(ce.slice(0,9)))}}At.encodedSize=function(e,r){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){Mo(n);let i=Dn(ce,1);if(n===i||Number.isNaN(n))return 3;if(Po(n),i=Un(ce,1),n===i)return 5}return 9};var Bo=new ArrayBuffer(9),oe=new DataView(Bo,1),ce=new Uint8Array(Bo,0);function Mo(t){if(t===1/0)oe.setUint16(0,31744,!1);else if(t===-1/0)oe.setUint16(0,64512,!1);else if(Number.isNaN(t))oe.setUint16(0,32256,!1);else{oe.setFloat32(0,t);let e=oe.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)oe.setUint16(0,31744,!1);else if(r===0)oe.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let i=r-127;i<-24?oe.setUint16(0,0):i<-14?oe.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):oe.setUint16(0,(e&2147483648)>>16|i+15<<10|n>>13,!1)}}}function Dn(t,e){if(t.length-e<2)throw new Error(`${y} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,i=r&1023,o;return n===0?o=i*2**-24:n!==31?o=(i+1024)*2**(n-25):o=i===0?1/0:NaN,r&32768?-o:o}function Po(t){oe.setFloat32(0,t,!1)}function Un(t,e){if(t.length-e<4)throw new Error(`${y} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Ec(t){oe.setFloat64(0,t,!1)}function $o(t,e){if(t.length-e<8)throw new Error(`${y} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}At.compareTokens=ie.compareTokens;function v(t,e,r){throw new Error(`${y} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function mr(t){return()=>{throw new Error(`${y} ${t}`)}}var h=[];for(let t=0;t<=23;t++)h[t]=v;h[24]=Gi;h[25]=ji;h[26]=Yi;h[27]=Xi;h[28]=v;h[29]=v;h[30]=v;h[31]=v;for(let t=32;t<=55;t++)h[t]=v;h[56]=Wi;h[57]=Ji;h[58]=Qi;h[59]=eo;h[60]=v;h[61]=v;h[62]=v;h[63]=v;for(let t=64;t<=87;t++)h[t]=to;h[88]=ro;h[89]=no;h[90]=io;h[91]=oo;h[92]=v;h[93]=v;h[94]=v;h[95]=mr("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)h[t]=ao;h[120]=co;h[121]=uo;h[122]=lo;h[123]=fo;h[124]=v;h[125]=v;h[126]=v;h[127]=mr("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)h[t]=po;h[152]=mo;h[153]=go;h[154]=yo;h[155]=xo;h[156]=v;h[157]=v;h[158]=v;h[159]=wo;for(let t=160;t<=183;t++)h[t]=bo;h[184]=Eo;h[185]=So;h[186]=To;h[187]=Io;h[188]=v;h[189]=v;h[190]=v;h[191]=Co;for(let t=192;t<=215;t++)h[t]=Ao;h[216]=vo;h[217]=No;h[218]=Fo;h[219]=ko;h[220]=v;h[221]=v;h[222]=v;h[223]=v;for(let t=224;t<=243;t++)h[t]=mr("simple values are not supported");h[244]=v;h[245]=v;h[246]=v;h[247]=Do;h[248]=mr("simple values are not supported");h[249]=_o;h[250]=Lo;h[251]=Ro;h[252]=v;h[253]=v;h[254]=v;h[255]=Uo;var ue=[];for(let t=0;t<24;t++)ue[t]=new d(c.uint,t,1);for(let t=-1;t>=-24;t--)ue[31-t]=new d(c.negint,t,1);ue[64]=new d(c.bytes,new Uint8Array(0),1);ue[96]=new d(c.string,"",1);ue[128]=new d(c.array,0,1);ue[160]=new d(c.map,0,1);ue[244]=new d(c.false,!1,1);ue[245]=new d(c.true,!0,1);ue[246]=new d(c.null,null,1);function _n(t){switch(t.type){case c.false:return he([244]);case c.true:return he([245]);case c.null:return he([246]);case c.bytes:return t.value.length?void 0:he([64]);case c.string:return t.value===""?he([96]):void 0;case c.array:return t.value===0?he([128]):void 0;case c.map:return t.value===0?he([160]):void 0;case c.uint:return t.value<24?he([Number(t.value)]):void 0;case c.negint:if(t.value>=-24)return he([31-Number(t.value)])}}var Tc={float64:!1,mapSorter:Ac,quickEncodeToken:_n},Ko=Object.freeze({float64:!0,mapSorter:vc,quickEncodeToken:_n});function Ic(){let t=[];return t[c.uint.major]=ie,t[c.negint.major]=lr,t[c.bytes.major]=We,t[c.string.major]=ho,t[c.array.major]=hr,t[c.map.major]=dr,t[c.tag.major]=pr,t[c.float.major]=At,t}var et=Ic(),gr=new St,Nt=class t{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${ur} object contains circular references`);return new t(r,e)}},Ae={null:new d(c.null,null),undefined:new d(c.undefined,void 0),true:new d(c.true,!0),false:new d(c.false,!1),emptyArray:new d(c.array,0),emptyMap:new d(c.map,0)},de={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new d(c.float,t):t>=0?new d(c.uint,t):new d(c.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new d(c.uint,t):new d(c.negint,t)},Uint8Array(t,e,r,n){return new d(c.bytes,t)},string(t,e,r,n){return new d(c.string,t)},boolean(t,e,r,n){return t?Ae.true:Ae.false},null(t,e,r,n){return Ae.null},undefined(t,e,r,n){return Ae.undefined},ArrayBuffer(t,e,r,n){return new d(c.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new d(c.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Ae.emptyArray,new d(c.break)]:Ae.emptyArray;n=Nt.createCheck(n,t);let i=[],o=0;for(let s of t)i[o++]=Ze(s,r,n);return r.addBreakTokens?[new d(c.array,t.length),i,new d(c.break)]:[new d(c.array,t.length),i]},Object(t,e,r,n){let i=e!=="Object",o=i?t.keys():Object.keys(t),s=i?t.size:o.length,a;if(s){a=new Array(s),n=Nt.createCheck(n,t);let u=!i&&r.ignoreUndefinedProperties,f=0;for(let l of o){let p=i?t.get(l):t[l];u&&p===void 0||(a[f++]=[Ze(l,r,n),Ze(p,r,n)])}f<s&&(a.length=f)}return a?.length?(Cc(a,r),r.addBreakTokens?[new d(c.map,a.length),a,new d(c.break)]:[new d(c.map,a.length),a]):r.addBreakTokens===!0?[Ae.emptyMap,new d(c.break)]:Ae.emptyMap},Tagged(t,e,r,n){return[new d(c.tag,t.tag),Ze(t.value,r,n)]}};de.Map=de.Object;de.Buffer=de.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))de[`${t}Array`]=de.DataView;function Ze(t,e={},r){let n=In(t),i=e&&e.typeEncoders&&e.typeEncoders[n]||de[n];if(typeof i=="function"){let s=i(t,n,e,r);if(s!=null)return s}let o=de[n];if(!o)throw new Error(`${ur} unsupported type: ${n}`);return o(t,n,e,r)}function Cc(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Ac(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let i=r.type.major,o=et[i].compareTokens(r,n);return o===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),o}function vc(t,e){if(t[0]instanceof d&&e[0]instanceof d){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=Vo(r.value)),n._keyBytes||(n._keyBytes=Vo(n.value)),ar(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Vo(t){return Go(t,et,Ko)}function vt(t,e,r,n){if(Array.isArray(e))for(let i of e)vt(t,i,r,n);else r[e.type.major](t,e,n)}var Oo=c.uint.majorEncoded,zo=c.negint.majorEncoded,Nc=c.bytes.majorEncoded,Fc=c.string.majorEncoded,qo=c.array.majorEncoded,kc=c.float.majorEncoded|An,Dc=c.float.majorEncoded|vn,Uc=c.float.majorEncoded|Nn,_c=c.float.majorEncoded|Fn,Lc=BigInt(-1),Rc=BigInt(1);function Bc(t){return t.addBreakTokens!==!0}function Ho(t,e,r,n){let i=In(e),o=r.typeEncoders&&r.typeEncoders[i];if(o){let s=o(e,i,r,n);if(s!=null){vt(t,s,et,r);return}}switch(i){case"null":t.push([Uc]);return;case"undefined":t.push([_c]);return;case"boolean":t.push([e?Dc:kc]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?At(t,new d(c.float,e),r):e>=0?D(t,Oo,e):D(t,zo,e*-1-1);return;case"bigint":e>=BigInt(0)?D(t,Oo,e):D(t,zo,e*Lc-Rc);return;case"string":{let s=sr(e);D(t,Fc,s.length),t.push(s);return}case"Uint8Array":D(t,Nc,e.length),t.push(e);return;case"Array":if(!e.length){t.push([qo]);return}n=Nt.createCheck(n,e),D(t,qo,e.length);for(let s of e)Ho(t,s,r,n);return;case"Object":case"Map":{let s=de.Object(e,i,r,n);vt(t,s,et,r)}return;default:{let s=de[i];if(!s)throw new Error(`${ur} unsupported type: ${i}`);let a=s(e,i,r,n);vt(t,a,et,r)}}}function Go(t,e,r,n){let i=n instanceof Uint8Array,o=i?new cr(n):gr,s=Ze(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return i?(o.push(a),o.toBytes()):a;let u=e[s.type.major];if(u.encodedSize){let f=u.encodedSize(s,r);if(i||(o=new St(f)),u(o,s,r),o.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return i?o.toBytes():Et(o.chunks[0])}}return o.reset(),vt(o,s,e,r),o.toBytes(!0)}function Ln(t,e){return e=Object.assign({},Tc,e),Bc(e)?(gr.reset(),Ho(gr,t,e,void 0),gr.toBytes(!0)):Go(t,et,e)}var Mc={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},yr=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=ue[e];if(r===void 0){let n=h[e];if(!n)throw new Error(`${y} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let i=e&31;r=n(this.data,this._pos,i,this.options)}return this._pos+=r.encodedLength,r}},ve=Symbol.for("DONE"),tt=Symbol.for("BREAK");function Pc(t,e,r){let n=[];for(let i=0;i<t.value;i++){let o=Ne(e,r);if(o===tt){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed array`)}if(o===ve)throw new Error(`${y} found array but not enough entries (got ${i}, expected ${t.value})`);n[i]=o}return n}function $c(t,e,r){let n=r.useMaps===!0,i=r.rejectDuplicateMapKeys===!0,o=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let u=Ne(e,r);if(u===tt){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed map`)}if(u===ve)throw new Error(`${y} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof u!="string")throw new Error(`${y} non-string keys not supported (got ${typeof u})`);if(i&&(n&&s.has(u)||!n&&Object.hasOwn(o,u)))throw new Error(`${y} found repeat map key "${u}"`);let f=Ne(e,r);if(f===ve)throw new Error(`${y} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(u,f):o[u]=f}return n?s:o}function*Vc(t,e,r){for(let n=0;n<t.value;n++){let i=Ne(e,r);if(i===tt){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed map`)}if(i===ve)throw new Error(`${y} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let o=Ne(e,r);if(o===ve)throw new Error(`${y} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[i,o]}}function Oc(t,e){let r=!1,n=function(){if(r)throw new Error(`${y} tag decode() may only be called once`);r=!0;let i=Ne(t,e);if(i===ve)throw new Error(`${y} tag content missing`);if(i===tt)throw new Error(`${y} got unexpected break in tag content`);return i};return n.entries=function(){if(r)throw new Error(`${y} tag decode() may only be called once`);r=!0;let i=t.next();if(!c.equals(i.type,c.map))throw new Error(`${y} entries() requires map content, got ${i.type.name}`);let o=[];for(let s of Vc(i,t,e))o.push(s);return o},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function Ne(t,e){if(t.done())return ve;let r=t.next();if(c.equals(r.type,c.break))return tt;if(r.type.terminal)return r.value;if(c.equals(r.type,c.array))return Pc(r,t,e);if(c.equals(r.type,c.map))return $c(r,t,e);if(c.equals(r.type,c.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=Oc(t,e),i=e.tags[r.value](n);if(!n._called)throw new Error(`${y} tag decoder must call decode() or entries()`);return i}throw new Error(`${y} tag not supported (${r.value})`)}throw new Error("unsupported")}function jo(t,e){if(!(t instanceof Uint8Array))throw new Error(`${y} data to decode must be a Uint8Array`);e=Object.assign({},Mc,e);let r=Et(t),n=e.tokenizer||new yr(r,e),i=Ne(n,e);if(i===ve)throw new Error(`${y} did not find any content to decode`);if(i===tt)throw new Error(`${y} got unexpected break`);return[i,t.subarray(n.pos())]}function Rn(t,e){let[r,n]=jo(t,e);if(n.length>0)throw new Error(`${y} too many terminals, data makes no sense`);return r}var xr=class t{constructor(e,r){if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=e,this.value=r}static decoder(e){return r=>new t(e,r())}static preserve(...e){let r={};for(let n of e)r[n]=t.decoder(n);return r}};Object.defineProperty(xr.prototype,Symbol.toStringTag,{value:"Tagged"});function Be(t,e="utf8"){let r=Jt[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var Ee="/",Yo=new TextEncoder().encode(Ee),wr=Yo[0],rt=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=$(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==wr)throw new Error("Invalid key")}toString(e="utf8"){return Be(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(Ee))}static random(){return new t(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new t(e):typeof e.uint8Array=="function"?new t(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Yo),this._buf[0]!==wr){let e=new Uint8Array(this._buf.byteLength+1);e.fill(wr,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===wr;)this._buf=this._buf.subarray(0,-1)}less(e){let r=this.list(),n=e.list();for(let i=0;i<r.length;i++){if(n.length<i+1)return!1;let o=r[i],s=n[i];if(o<s)return!0;if(o>s)return!1}return r.length<n.length}reverse(){return t.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(Ee).slice(1)}type(){return qc(this.baseNamespace())}name(){return Kc(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Ee)||(e+=Ee),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(Ee):new t(e.slice(0,-1).join(Ee))}child(e){return this.toString()===Ee?e:e.toString()===Ee?this:new t(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return t.withNamespaces([...this.namespaces(),...Hc(e.map(r=>r.namespaces()))])}};function qc(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function Kc(t){let e=t.split(":");return e[e.length-1]}function Hc(t){return[].concat(...t)}var Wo=114;var jc=1024*10,Jo=$("/ipns/"),Qo="/ipns/";function Yc(t,e){return t.code===e}var br="/dht/record/",Xc="/ipns/metadata/";function Ft(t){return new rt(br+Be(t,"base32"),!1)}function Er(t){return new rt(Xc+Be(t,"base32"),!1)}function Zo(t,e){let r=Date.now(),n=e.getTime()+1728e5,i=new Date(t.validity).getTime();return n-r<864e5||i-r<864e5}function es(t,e,r){let n=$(e),i=$(t);return rr([i,r,n],i.byteLength+r.byteLength+n.byteLength)}function Sr(t){let e=$("ipns-signature:");return rr([e,t])}function nt(t){let e=t.publicKey?.toProtobuf();return t.publicKey?.toMultihash().code===0&&(e=void 0),"signatureV1"in t?O.encode({value:$(t.value),signatureV1:t.signatureV1,validityType:t.validityType,validity:$(t.validity),sequence:t.sequence,ttl:t.ttl,publicKey:e,signatureV2:t.signatureV2,data:t.data}):O.encode({publicKey:e,signatureV2:t.signatureV2,data:t.data})}function Xo(t){try{return`/ipfs/${fe.decode(t)}`}catch{}return Be(t)}async function pe(t,e,r,n){if(e.byteLength>jc)throw new Ht("The record is too large");let i=O.decode(e);if(i.signatureV2==null||i.data==null)throw new se("Missing data or signatureV2");let o=rs(i.data),s=Be(o.Validity),a,u=Wc(t);if(Yc(u,0)&&(a=await r.loadPublicKeyFromProtobuf(u.digest,n)),a==null&&i.publicKey!=null&&(a=await r.loadPublicKeyFromProtobuf(i.publicKey,n)),a==null)throw new Xe("Could not extract public key from IPNS record or routing key");if(i.value!=null&&i.signatureV1!=null)return Qc(i),{value:Xo(o.Value),validityType:O.ValidityType.EOL,validity:s,sequence:o.Sequence,ttl:o.TTL,publicKey:a,signatureV1:i.signatureV1,signatureV2:i.signatureV2,data:i.data,bytes:e};if(i.signatureV2!=null)return{value:Xo(o.Value),validityType:O.ValidityType.EOL,validity:s,sequence:o.Sequence,ttl:o.TTL,publicKey:a,signatureV2:i.signatureV2,data:i.data,bytes:e};throw new Error("invalid record: does not include signatureV1 or signatureV2")}function kt(t){return rr([Jo,t.bytes])}function Wc(t){return ut(t.slice(Jo.length))}function ts(t,e,r,n,i){let o;if(e===O.ValidityType.EOL)o=0;else throw new Ue("The validity type is unsupported");let s={Value:$(t),Validity:r,ValidityType:o,Sequence:n,TTL:i};return Ln(s)}function rs(t){let e=Rn(t);if(e.ValidityType===0)e.ValidityType=O.ValidityType.EOL;else throw new Ue("The validity type is unsupported");return Number.isInteger(e.Sequence)&&(e.Sequence=BigInt(e.Sequence)),Number.isInteger(e.TTL)&&(e.TTL=BigInt(e.TTL)),e}function ns(t){if(t!=null){if(nr(t))return`/ipns/${t.toCID().toV1().toString(ne)}`;let e=is(t);if(e!=null)return e.code===Wo?`/ipns/${e.toV1().toString(ne)}`:`/ipfs/${e.toV1()}`;if(Zc(t))return`/ipns/${ne.encode(t.bytes)}`;let r=t.toString().trim();if(r.startsWith("/ipfs/")){let[,n,...i]=r.split("/").filter(o=>o.trim()!=="");return`/ipfs/${fe.parse(n).toV1()}${i.length>0?`/${i.join("/")}`:""}`}if(r.startsWith("/")&&r.length>1)return r}throw new Ye("Value must be a valid content path starting with /")}function Jc(t){return typeof t.code=="number"&&t.digest instanceof Uint8Array&&typeof t.size=="number"&&t.bytes instanceof Uint8Array}function Dt(t){if(t!=null){if(nr(t))return{digest:t.toMultihash(),path:"/"};let e=is(t);if(e!=null){if(e.code!==Wo)throw new Ye("CIDs must have the `libp2p-key` codec");return{digest:e.multihash,path:"/"}}if(Jc(t))return{digest:t,path:"/"};if(t=t.toString(),t.startsWith("/ipns/")){let[,,r,...n]=t.split("/"),i=ne;(r.startsWith("1")||r.startsWith("Q"))&&(r=`z${r}`,i=j);let o=i.decode(r),s;try{s=fe.decode(o).multihash}catch{s=ut(o)}return{digest:s,path:`/${n.join("/")}`}}}throw new Ye("Value must be a valid IPNS path starting with /")}function Qc(t){if(t.data==null)throw new Gt("Record data is missing");let e=rs(t.data);if(!wt(e.Value,t.value??new Uint8Array(0)))throw new se('Field "value" did not match between protobuf and CBOR');if(!wt(e.Validity,t.validity??new Uint8Array(0)))throw new se('Field "validity" did not match between protobuf and CBOR');if(e.ValidityType!==t.validityType)throw new se('Field "validityType" did not match between protobuf and CBOR');if(e.Sequence!==t.sequence)throw new se('Field "sequence" did not match between protobuf and CBOR');if(e.TTL!==t.ttl)throw new se('Field "ttl" did not match between protobuf and CBOR')}function Zc(t){return t.bytes instanceof Uint8Array}function eu(t){return typeof t?.toCID=="function"}function is(t){if(eu(t))return t.toCID();try{return fe.parse(t)}catch{}return fe.asCID(t)}var os=$r(jt(),1);async function Ut(t,e){if(t.publicKey==null)throw new Xe("The record had no public key associated with it");let r;try{let n=Sr(t.data);r=await t.publicKey.verify(n,t.signatureV2,e)}catch{r=!1}if(!r)throw new se("Record signature verification failed");if(t.validityType===O.ValidityType.EOL){if(os.default.fromString(t.validity).toDate().getTime()<Date.now())throw new Kt("record has expired")}else if(t.validityType!=null)throw new Ue("The validity type is unsupported")}var it=class{routers;localStore;log;keychain;constructor(e,r){this.log=e.logger.forComponent("helia:ipns"),this.localStore=r.localStore,this.routers=r.routers,this.keychain=e.keychain}async*resolve(e,r={}){let{digest:n}=Dt(e);for(;;){let i=kt(n),o=await this.#e(i,r);if(yield{record:o},!o.value.startsWith(Qo))break;({digest:n}=Dt(o.value))}}async#e(e,r={}){let n=[];if(await this.localStore.has(e,r))if(this.log("record is present in the cache"),r.nocache!==!0)try{let{record:u,created:f}=await this.localStore.get(e,r);this.log("record retrieved from cache");let l=await pe(e,u,this.keychain,r);await Ut(l,r),this.log("record was valid");let p=Number((l.ttl??je)/1000000n);if(f.getTime()+p>Date.now())return this.log("record TTL was valid"),l;if(r.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),l;this.log("record TTL has been reached, searching routing for updates"),n.push(l)}catch(u){this.log("cached record was invalid - %e",u),await this.localStore.delete(e,r)}else this.log("ignoring local cache due to nocache=true option");if(r.offline===!0)throw new ft("Record was not present in the cache or has expired");this.log("did not have record locally");let o=0,s=[];if(await Promise.all(this.routers.map(async u=>{let f;try{f=await u.get(e,{...r,validate:!1})}catch(l){this.log.error("error finding IPNS record using router %s - %e",u.toString(),l),s.push(l);return}try{let l=await pe(e,f,this.keychain,r);await Ut(l,r),n.push(l)}catch(l){o++,this.log.error("error validating IPNS record from router %s - %e",u.toString(),l)}})),n.length===0)throw o>0?new zt(`${o>1?`${o} records`:"Record"} found for routing key ${o>1?"were":"was"} invalid`):new ft("Could not find record for routing key");let a=n[tr(e,n)];return await this.localStore.put(e,a.bytes,r),a}};var Y=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};function Tr(t,e){if(typeof t=="string")return tu(t);if(typeof t=="number")return iu(t,e);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}function tu(t){if(typeof t!="string"||t.length===0||t.length>100)throw new Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(t)}`);let e=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(t);if(!e?.groups)return NaN;let{value:r,unit:n="ms"}=e.groups,i=parseFloat(r),o=n.toLowerCase();switch(o){case"years":case"year":case"yrs":case"yr":case"y":return i*315576e5;case"months":case"month":case"mo":return i*26298e5;case"weeks":case"week":case"w":return i*6048e5;case"days":case"day":case"d":return i*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return i*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return i*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return i*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return i;default:throw new Error(`Unknown unit "${o}" provided to ms.parse(). value=${JSON.stringify(t)}`)}}function ru(t){let e=Math.abs(t);return e>=315576e5?`${Math.round(t/315576e5)}y`:e>=26298e5?`${Math.round(t/26298e5)}mo`:e>=6048e5?`${Math.round(t/6048e5)}w`:e>=864e5?`${Math.round(t/864e5)}d`:e>=36e5?`${Math.round(t/36e5)}h`:e>=6e4?`${Math.round(t/6e4)}m`:e>=1e3?`${Math.round(t/1e3)}s`:`${t}ms`}function nu(t){let e=Math.abs(t);return e>=315576e5?Me(t,e,315576e5,"year"):e>=26298e5?Me(t,e,26298e5,"month"):e>=6048e5?Me(t,e,6048e5,"week"):e>=864e5?Me(t,e,864e5,"day"):e>=36e5?Me(t,e,36e5,"hour"):e>=6e4?Me(t,e,6e4,"minute"):e>=1e3?Me(t,e,1e3,"second"):`${t} ms`}function iu(t,e){if(typeof t!="number"||!Number.isFinite(t))throw new Error("Value provided to ms.format() must be of type number.");return e?.long?nu(t):ru(t)}function Me(t,e,r,n){let i=e>=r*1.5;return`${Math.round(t/r)} ${n}${i?"s":""}`}function Bn(t){r.debug=r,r.default=r,r.coerce=u,r.disable=o,r.enable=i,r.enabled=s,r.humanize=Tr,r.destroy=f,Object.keys(t).forEach(l=>{r[l]=t[l]}),r.names=[],r.skips=[],r.formatters={};function e(l){let p=0;for(let m=0;m<l.length;m++)p=(p<<5)-p+l.charCodeAt(m),p|=0;return r.colors[Math.abs(p)%r.colors.length]}r.selectColor=e;function r(l,p){let m,b=null,S,E;function x(...T){if(!x.enabled)return;let F=x,k=Number(new Date),P=k-(m||k);F.diff=P,F.prev=m,F.curr=k,m=k,T[0]=r.coerce(T[0]),typeof T[0]!="string"&&T.unshift("%O");let B=0;T[0]=T[0].replace(/%([a-zA-Z%])/g,(R,g)=>{if(R==="%%")return"%";B++;let w=r.formatters[g];if(typeof w=="function"){let A=T[B];R=w.call(F,A),T.splice(B,1),B--}return R}),r.formatArgs.call(F,T),p?.onLog!=null&&p.onLog(...T),(F.log||r.log).apply(F,T)}return x.namespace=l,x.useColors=r.useColors(),x.color=r.selectColor(l),x.extend=n,x.destroy=r.destroy,Object.defineProperty(x,"enabled",{enumerable:!0,configurable:!1,get:()=>b!==null?b:(S!==r.namespaces&&(S=r.namespaces,E=r.enabled(l)),E),set:T=>{b=T}}),typeof r.init=="function"&&r.init(x),x}function n(l,p){let m=r(this.namespace+(typeof p>"u"?":":p)+l);return m.log=this.log,m}function i(l){r.save(l),r.namespaces=l,r.names=[],r.skips=[];let p,m=(typeof l=="string"?l:"").split(/[\s,]+/),b=m.length;for(p=0;p<b;p++)m[p]&&(l=m[p].replace(/\*/g,".*?"),l[0]==="-"?r.skips.push(new RegExp("^"+l.substr(1)+"$")):r.names.push(new RegExp("^"+l+"$")))}function o(){let l=[...r.names.map(a),...r.skips.map(a).map(p=>"-"+p)].join(",");return r.enable(""),l}function s(l){if(l[l.length-1]==="*")return!0;let p,m;for(p=0,m=r.skips.length;p<m;p++)if(r.skips[p].test(l))return!1;for(p=0,m=r.names.length;p<m;p++)if(r.names[p].test(l))return!0;return!1}function a(l){return l.toString().substring(2,l.toString().length-2).replace(/\.\*\?$/,"*")}function u(l){return l instanceof Error?l.stack??l.message:l}function f(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var Ir=fu(),ou=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function su(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function au(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+Tr(this.diff),!this.useColors)return;let e="color: "+this.color;t.splice(1,0,e,"color: inherit");let r=0,n=0;t[0].replace(/%[a-zA-Z%]/g,i=>{i!=="%%"&&(r++,i==="%c"&&(n=r))}),t.splice(n,0,e)}var cu=console.debug??console.log??(()=>{});function uu(t){try{t?Ir?.setItem("debug",t):Ir?.removeItem("debug")}catch{}}function lu(){let t;try{t=Ir?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function fu(){try{return localStorage}catch{}}function hu(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var ss=Bn({formatArgs:au,save:uu,load:lu,useColors:su,setupFormatters:hu,colors:ou,storage:Ir,log:cu});var X=ss;X.formatters.b=t=>t==null?"undefined":j.baseEncode(t);X.formatters.t=t=>t==null?"undefined":Te.baseEncode(t);X.formatters.m=t=>t==null?"undefined":sn.baseEncode(t);X.formatters.p=t=>t==null?"undefined":t.toString();X.formatters.c=t=>t==null?"undefined":t.toString();X.formatters.k=t=>t==null?"undefined":t.toString();X.formatters.a=t=>t==null?"undefined":t.toString();function as(t,e=""){let r=cs(t.message),n=cs(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
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 Sy(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function Eh(t,e=""){if(Sy(t)){let r=xh(t,e);return t.errors.length>0?(e=`${e} `,r+=`
11
- ${e}${t.errors.map(n=>`${Eh(n,`${e}`)}`).join(`
10
+ ${e}`)}`:r!=null?`${r}`:`${t.toString()}`}function du(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function us(t,e=""){if(du(t)){let r=as(t,e);return t.errors.length>0?(e=`${e} `,r+=`
11
+ ${e}${t.errors.map(n=>`${us(n,`${e}`)}`).join(`
12
12
  ${e}`)}`):r+=`
13
- ${e}[Error list was empty]`,r.trim()}return xh(t,e)}_e.formatters.e=t=>t==null?"undefined":Eh(t);function Ay(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e}function hr(t,e){let r=Ay(`${t}:trace`);return _e.enabled(`${t}:trace`)&&_e.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=_e(`${t}:trace`,e)),Object.assign(_e(t,e),{error:_e(`${t}:error`,e),trace:r,newScope:n=>hr(`${t}:${n}`,e)})}function wh(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var yp=Ss(Ai(),1);function dr(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}var vi=class extends Error{static name="SignatureCreationError";constructor(e="Record signature creation failed"){super(e),this.name="SignatureCreationError"}},et=class extends Error{static name="SignatureVerificationError";constructor(e="Record signature verification failed"){super(e),this.name="SignatureVerificationError"}},Ii=class extends Error{static name="RecordExpiredError";constructor(e="Record has expired"){super(e),this.name="RecordExpiredError"}},pr=class extends Error{static name="UnsupportedValidityError";constructor(e="The validity type is unsupported"){super(e),this.name="UnsupportedValidityError"}},Ti=class extends Error{static name="RecordTooLargeError";constructor(e="The record is too large"){super(e),this.name="RecordTooLargeError"}},Yn=class extends Error{static name="InvalidValueError";constructor(e="Value must be a valid content path starting with /"){super(e),this.name="InvalidValueError"}},Bi=class extends Error{static name="InvalidRecordDataError";constructor(e="Invalid record data"){super(e),this.name="InvalidRecordDataError"}},Gn=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(e="Invalid embedded public key"){super(e),this.name="InvalidEmbeddedPublicKeyError"}};function lt(t=0){return new Uint8Array(t)}var vy=Math.pow(2,7),Iy=Math.pow(2,14),Ty=Math.pow(2,21),Sh=Math.pow(2,28),Ah=Math.pow(2,35),vh=Math.pow(2,42),Ih=Math.pow(2,49),Ae=128,Vt=127;function Zn(t){if(t<vy)return 1;if(t<Iy)return 2;if(t<Ty)return 3;if(t<Sh)return 4;if(t<Ah)return 5;if(t<vh)return 6;if(t<Ih)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Th(t,e,r=0){switch(Zn(t)){case 8:e[r++]=t&255|Ae,t/=128;case 7:e[r++]=t&255|Ae,t/=128;case 6:e[r++]=t&255|Ae,t/=128;case 5:e[r++]=t&255|Ae,t/=128;case 4:e[r++]=t&255|Ae,t>>>=7;case 3:e[r++]=t&255|Ae,t>>>=7;case 2:e[r++]=t&255|Ae,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Bh(t,e){let r=t[e],n=0;if(n+=r&Vt,r<Ae||(r=t[e+1],n+=(r&Vt)<<7,r<Ae)||(r=t[e+2],n+=(r&Vt)<<14,r<Ae)||(r=t[e+3],n+=(r&Vt)<<21,r<Ae)||(r=t[e+4],n+=(r&Vt)*Sh,r<Ae)||(r=t[e+5],n+=(r&Vt)*Ah,r<Ae)||(r=t[e+6],n+=(r&Vt)*vh,r<Ae)||(r=t[e+7],n+=(r&Vt)*Ih,r<Ae))return n;throw new RangeError("Could not decode varint")}function By(t){return t.buffer instanceof ArrayBuffer}function Ch(t){return By(t)?t:t.slice()}var cc=new Float32Array([-0]),zt=new Uint8Array(cc.buffer);function _h(t,e,r){cc[0]=t,e[r]=zt[0],e[r+1]=zt[1],e[r+2]=zt[2],e[r+3]=zt[3]}function Dh(t,e){return zt[0]=t[e],zt[1]=t[e+1],zt[2]=t[e+2],zt[3]=t[e+3],cc[0]}var uc=new Float64Array([-0]),ye=new Uint8Array(uc.buffer);function Fh(t,e,r){uc[0]=t,e[r]=ye[0],e[r+1]=ye[1],e[r+2]=ye[2],e[r+3]=ye[3],e[r+4]=ye[4],e[r+5]=ye[5],e[r+6]=ye[6],e[r+7]=ye[7]}function Uh(t,e){return ye[0]=t[e],ye[1]=t[e+1],ye[2]=t[e+2],ye[3]=t[e+3],ye[4]=t[e+4],ye[5]=t[e+5],ye[6]=t[e+6],ye[7]=t[e+7],uc[0]}var Cy=BigInt(Number.MAX_SAFE_INTEGER),_y=BigInt(Number.MIN_SAFE_INTEGER),Ne=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 mr;if(e<Cy&&e>_y)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>Lh&&(o=0n,++n>Lh&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return mr;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):mr}},mr=new Ne(0,0);mr.toBigInt=function(){return 0n};mr.zzEncode=mr.zzDecode=function(){return this};mr.length=function(){return 1};var Lh=4294967296n;function Rh(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 Nh(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 fc(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 tt(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Ci(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var lc=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Ch(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,tt(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 tt(this,4);return Ci(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw tt(this,4);return Ci(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw tt(this,4);let e=Dh(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw tt(this,4);let e=Uh(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 tt(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Nh(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw tt(this,e);this.pos+=e}else do if(this.pos>=this.len)throw tt(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 Ne(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 tt(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 tt(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 tt(this,8);let e=Ci(this.buf,this.pos+=4),r=Ci(this.buf,this.pos+=4);return new Ne(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=Bh(this.buf,this.pos);return this.pos+=Zn(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 Xn(t){return new lc(t instanceof Uint8Array?t:t.subarray())}function Wn(t,e,r){let n=Xn(t);return e.decode(n,void 0,r)}var gc={};z(gc,{base10:()=>Oy});var q3=new Uint8Array(0);function Oh(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 vt(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return gr(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return gr(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Mh(t){return new TextEncoder().encode(t)}function Ph(t){return new TextDecoder().decode(t)}function Dy(t){return t?.buffer instanceof ArrayBuffer}function gr(t){return Dy(t)?t:t.slice()}function Fy(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var y=0,d=0,g=0,E=h.length;g!==E&&h[g]===0;)g++,y++;for(var I=(E-g)*f+1>>>0,C=new Uint8Array(I);g!==E;){for(var B=h[g],R=0,_=I-1;(B!==0||R<d)&&_!==-1;_--,R++)B+=256*C[_]>>>0,C[_]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");d=R,g++}for(var x=I-d;x!==I&&C[x]===0;)x++;for(var D=c.repeat(y);x<I;++x)D+=t.charAt(C[x]);return D}function m(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var y=0;if(h[y]!==" "){for(var d=0,g=0;h[y]===c;)d++,y++;for(var E=(h.length-y)*u+1>>>0,I=new Uint8Array(E);h[y];){var C=r[h.charCodeAt(y)];if(C===255)return;for(var B=0,R=E-1;(C!==0||B<g)&&R!==-1;R--,B++)C+=a*I[R]>>>0,I[R]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");g=B,y++}if(h[y]!==" "){for(var _=E-g;_!==E&&I[_]===0;)_++;for(var x=new Uint8Array(d+(E-_)),D=d;_!==E;)x[D++]=I[_++];return x}}}function b(h){var y=m(h);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:m,decode:b}}var Uy=Fy,Ly=Uy,Vh=Ly;var hc=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")}},dc=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 zh(this,e)}},pc=class{decoders;constructor(e){this.decoders=e}or(e){return zh(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 zh(t,e){return new pc({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var mc=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 hc(e,r,n),this.decoder=new dc(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function $r({name:t,prefix:e,encode:r,decode:n}){return new mc(t,e,r,n)}function $t({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Vh(r,t);return $r({prefix:e,name:t,encode:n,decode:i=>vt(o(i))})}function Ry(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,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Ny(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],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 ky(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function te({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=ky(n);return $r({prefix:e,name:t,encode(i){return Ny(i,n,r)},decode(i){return Ry(i,o,r,t)}})}var Oy=$t({prefix:"9",name:"base10",alphabet:"0123456789"});var yc={};z(yc,{base16:()=>My,base16upper:()=>Py});var My=te({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Py=te({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var bc={};z(bc,{base2:()=>Ky});var Ky=te({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var xc={};z(xc,{base256emoji:()=>Hy});var $h=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}"),Vy=$h.reduce((t,e,r)=>(t[r]=e,t),[]),zy=$h.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function $y(t){return t.reduce((e,r)=>(e+=Vy[r],e),"")}function qy(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=zy[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Hy=$r({prefix:"\u{1F680}",name:"base256emoji",encode:$y,decode:qy});var wc={};z(wc,{base32:()=>qr,base32hex:()=>Zy,base32hexpad:()=>Wy,base32hexpadupper:()=>Jy,base32hexupper:()=>Xy,base32pad:()=>Yy,base32padupper:()=>Gy,base32upper:()=>jy,base32z:()=>Qy});var qr=te({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),jy=te({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Yy=te({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Gy=te({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Zy=te({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Xy=te({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wy=te({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Jy=te({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Qy=te({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ec={};z(Ec,{base36:()=>rt,base36upper:()=>eb});var rt=$t({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),eb=$t({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Sc={};z(Sc,{base58btc:()=>De,base58flickr:()=>tb});var De=$t({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),tb=$t({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ac={};z(Ac,{base64:()=>rb,base64pad:()=>nb,base64url:()=>ob,base64urlpad:()=>ib});var rb=te({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),nb=te({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ob=te({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ib=te({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var vc={};z(vc,{base8:()=>sb});var sb=te({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ic={};z(Ic,{identity:()=>ab});var ab=$r({prefix:"\0",name:"identity",encode:t=>Ph(t),decode:t=>Mh(t)});var sS=new TextEncoder,aS=new TextDecoder;var Bc={};z(Bc,{identity:()=>Db});var fb=jh,qh=128,lb=127,hb=~lb,db=Math.pow(2,31);function jh(t,e,r){e=e||[],r=r||0;for(var n=r;t>=db;)e[r++]=t&255|qh,t/=128;for(;t&hb;)e[r++]=t&255|qh,t>>>=7;return e[r]=t|0,jh.bytes=r-n+1,e}var pb=Tc,mb=128,Hh=127;function Tc(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw Tc.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&Hh)<<o:(s&Hh)*Math.pow(2,o),o+=7}while(s>=mb);return Tc.bytes=i-n,r}var gb=Math.pow(2,7),yb=Math.pow(2,14),bb=Math.pow(2,21),xb=Math.pow(2,28),wb=Math.pow(2,35),Eb=Math.pow(2,42),Sb=Math.pow(2,49),Ab=Math.pow(2,56),vb=Math.pow(2,63),Ib=function(t){return t<gb?1:t<yb?2:t<bb?3:t<xb?4:t<wb?5:t<Eb?6:t<Sb?7:t<Ab?8:t<vb?9:10},Tb={encode:fb,decode:pb,encodingLength:Ib},Bb=Tb,Jn=Bb;function Qn(t,e=0){return[Jn.decode(t,e),Jn.decode.bytes]}function Hr(t,e,r=0){return Jn.encode(t,e,r),e}function jr(t){return Jn.encodingLength(t)}function Gr(t,e){let r=e.byteLength,n=jr(t),o=n+jr(r),i=new Uint8Array(o+r);return Hr(t,i,0),Hr(r,i,n),i.set(e,o),new Yr(t,r,e,i)}function Zr(t){let e=vt(t),[r,n]=Qn(e),[o,i]=Qn(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Yr(r,o,s,e)}function Yh(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Oh(t.bytes,r.bytes)}}var Yr=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=gr(n),this.bytes=gr(o)}};var Gh=0,Cb="identity",Zh=vt;function _b(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 Gr(Gh,Zh(t))}var Db={code:Gh,name:Cb,encode:Zh,digest:_b};var Dc={};z(Dc,{sha256:()=>Ub,sha512:()=>Lb});var Fb=20;function _c({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Cc(t,e,r,n,o)}var Cc=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Fb,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?Xh(n,this.code,r?.truncate):n.then(o=>Xh(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Xh(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 Gr(e,t)}function Jh(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Ub=_c({name:"sha2-256",code:18,encode:Jh("SHA-256")}),Lb=_c({name:"sha2-512",code:19,encode:Jh("SHA-512")});function Qh(t,e){let{bytes:r,version:n}=t;return n===0?Nb(r,Fc(t),e??De.encoder):kb(r,Fc(t),e??qr.encoder)}var ed=new WeakMap;function Fc(t){let e=ed.get(t);if(e==null){let r=new Map;return ed.set(t,r),r}return e}var $e=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=gr(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!==eo)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ob)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=Gr(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&&Yh(e.multihash,n.multihash)}toString(e){return Qh(this,e)}toJSON(){return{"/":Qh(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??td(n,o,i.bytes))}else if(r[Mb]===!0){let{version:n,multihash:o,code:i}=r,s=Zr(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!==eo)throw new Error(`Version 0 CID must use dag-pb (code: ${eo}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=td(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,eo,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=vt(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 Yr(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[l,m]=Qn(e.subarray(r));return r+=m,l},o=n(),i=eo;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),u=r+c,f=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=Rb(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 Fc(i).set(n,e),i}};function Rb(t,e){switch(t[0]){case"Q":{let r=e??De;return[De.prefix,r.decode(`${De.prefix}${t}`)]}case De.prefix:{let r=e??De;return[De.prefix,r.decode(t)]}case qr.prefix:{let r=e??qr;return[qr.prefix,r.decode(t)]}case rt.prefix:{let r=e??rt;return[rt.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 Nb(t,e,r){let{prefix:n}=r;if(n!==De.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 kb(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 eo=112,Ob=18;function td(t,e,r){let n=jr(t),o=n+jr(e),i=new Uint8Array(o+r.byteLength);return Hr(t,i,0),Hr(e,i,n),i.set(r,o),i}var Mb=Symbol.for("@ipld/js-cid/CID");var Uc={...Ic,...bc,...vc,...gc,...yc,...wc,...Ec,...Sc,...Ac,...xc},_S={...Dc,...Bc};function nd(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var rd=nd("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Lc=nd("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=lt(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Pb={utf8:rd,"utf-8":rd,hex:Uc.base16,latin1:Lc,ascii:Lc,binary:Lc,...Uc},Di=Pb;function ve(t,e="utf8"){let r=Di[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Rc(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return lt(s);o+s>e&&(n=lt(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var br=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Nc(){}var Oc=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Kb=Rc();function Vb(t){return globalThis.Buffer!=null?lt(t):Kb(t)}var ro=class{len;head;tail;states;constructor(){this.len=0,this.head=new br(Nc,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new br(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Mc((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(Fi,10,Ne.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Ne.fromBigInt(e);return this._push(Fi,r.length(),r)}uint64Number(e){return this._push(Th,Zn(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=Ne.fromBigInt(e).zzEncode();return this._push(Fi,r.length(),r)}sint64Number(e){let r=Ne.fromNumber(e).zzEncode();return this._push(Fi,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(kc,1,e?1:0)}fixed32(e){return this._push(to,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Ne.fromBigInt(e);return this._push(to,4,r.lo)._push(to,4,r.hi)}fixed64Number(e){let r=Ne.fromNumber(e);return this._push(to,4,r.lo)._push(to,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(_h,4,e)}double(e){return this._push(Fh,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(kc,1,0):this.uint32(r)._push($b,r,e)}string(e){let r=Rh(e);return r!==0?this.uint32(r)._push(fc,r,e):this._push(kc,1,0)}fork(){return this.states=new Oc(this),this.head=this.tail=new br(Nc,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 br(Nc,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=Vb(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function kc(t,e,r){e[r]=t&255}function zb(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Mc=class extends br{next;constructor(e,r){super(zb,e,r),this.next=void 0}};function Fi(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 to(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 $b(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(ro.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(qb,e,t),this},ro.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Hb,e,t),this});function qb(t,e,r){e.set(t,r)}function Hb(t,e,r){t.length<40?fc(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(ve(t),r)}function Pc(){return new ro}function no(t,e){let r=Pc();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*oo(t,e,r){let n=Xn(t);yield*e.stream(n,void 0,"$",r)}var Ui={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Li(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Kc(t){function e(i){if(t[i.toString()]==null)throw new Error("Invalid enum value");return t[i]}let r=function(s,a){let c=e(s);a.int32(c)},n=function(s){let a=s.int32();return e(a)},o=function*(s){let a=s.int32();yield e(a)};return Li("enum",Ui.VARINT,r,n,o)}function io(t,e,r){return Li("message",Ui.LENGTH_DELIMITED,t,e,r)}var me;(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=()=>Kc(r)})(e=t.ValidityType||(t.ValidityType={}));let n;t.codec=()=>(n==null&&(n=io((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.value!=null&&(c.uint32(10),c.bytes(a.value)),a.signatureV1!=null&&(c.uint32(18),c.bytes(a.signatureV1)),a.validityType!=null&&(c.uint32(24),t.ValidityType.codec().encode(a.validityType,c)),a.validity!=null&&(c.uint32(34),c.bytes(a.validity)),a.sequence!=null&&(c.uint32(40),c.uint64(a.sequence)),a.ttl!=null&&(c.uint32(48),c.uint64(a.ttl)),a.pubKey!=null&&(c.uint32(58),c.bytes(a.pubKey)),a.signatureV2!=null&&(c.uint32(66),c.bytes(a.signatureV2)),a.data!=null&&(c.uint32(74),c.bytes(a.data)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let m=a.uint32();switch(m>>>3){case 1:{f.value=a.bytes();break}case 2:{f.signatureV1=a.bytes();break}case 3:{f.validityType=t.ValidityType.codec().decode(a);break}case 4:{f.validity=a.bytes();break}case 5:{f.sequence=a.uint64();break}case 6:{f.ttl=a.uint64();break}case 7:{f.pubKey=a.bytes();break}case 8:{f.signatureV2=a.bytes();break}case 9:{f.data=a.bytes();break}default:{a.skipType(m&7);break}}}return f},function*(a,c,u,f={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let m=a.uint32();switch(m>>>3){case 1:{yield{field:`${u}.value`,value:a.bytes()};break}case 2:{yield{field:`${u}.signatureV1`,value:a.bytes()};break}case 3:{yield{field:`${u}.validityType`,value:t.ValidityType.codec().decode(a)};break}case 4:{yield{field:`${u}.validity`,value:a.bytes()};break}case 5:{yield{field:`${u}.sequence`,value:a.uint64()};break}case 6:{yield{field:`${u}.ttl`,value:a.uint64()};break}case 7:{yield{field:`${u}.pubKey`,value:a.bytes()};break}case 8:{yield{field:`${u}.signatureV2`,value:a.bytes()};break}case 9:{yield{field:`${u}.data`,value:a.bytes()};break}default:{a.skipType(m&7);break}}}})),n);function o(a){return no(a,t.codec())}t.encode=o;function i(a,c){return Wn(a,t.codec(),c)}t.decode=i;function s(a,c){return oo(a,t.codec(),c)}t.stream=s})(me||(me={}));var jb=["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 Vc(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=Yb(t);return r||"Object"}function Yb(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(jb.includes(e))return e}var w=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}};w.uint=new w(0,"uint",!0);w.negint=new w(1,"negint",!0);w.bytes=new w(2,"bytes",!0);w.string=new w(3,"string",!0);w.array=new w(4,"array",!1);w.map=new w(5,"map",!1);w.tag=new w(6,"tag",!1);w.float=new w(7,"float",!0);w.false=new w(7,"false",!0);w.true=new w(7,"true",!0);w.null=new w(7,"null",!0);w.undefined=new w(7,"undefined",!0);w.break=new w(7,"break",!0);var O=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 so=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Gb=new TextEncoder;function Ri(t){return so&&globalThis.Buffer.isBuffer(t)}function ao(t){return t instanceof Uint8Array?Ri(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Zb=24,Xb=200,Ni=so?t=>t.length>=Zb?globalThis.Buffer.from(t):od(t):t=>t.length>=Xb?Gb.encode(t):od(t),ht=t=>Uint8Array.from(t),id=so?(t,e,r)=>Ri(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),sd=so?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),ao(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},ad=so?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function ki(t,e){if(Ri(t)&&Ri(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 od(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 Wb=256,co=class{constructor(e=Wb){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=ad(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=id(n,0,this.cursor)}else r=sd(this.chunks,this.cursor);return e&&this.reset(),r}},Oi=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 K="CBOR decode error:",Mi="CBOR encode error:",uo=[];uo[23]=1;uo[24]=2;uo[25]=3;uo[26]=5;uo[27]=9;function It(t,e,r){if(t.length-e<r)throw new Error(`${K} not enough data for type`)}var he=[24,256,65536,4294967296,BigInt("18446744073709551616")];function ke(t,e,r){It(t,e,1);let n=t[e];if(r.strict===!0&&n<he[0])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Oe(t,e,r){It(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<he[1])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Me(t,e,r){It(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<he[2])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Pe(t,e,r){It(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<he[3])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${K} integers outside of the safe integer range are not supported`)}function cd(t,e,r,n){return new O(w.uint,ke(t,e+1,n),2)}function ud(t,e,r,n){return new O(w.uint,Oe(t,e+1,n),3)}function fd(t,e,r,n){return new O(w.uint,Me(t,e+1,n),5)}function ld(t,e,r,n){return new O(w.uint,Pe(t,e+1,n),9)}function qe(t,e){return G(t,0,e.value)}function G(t,e,r){if(r<he[0]){let n=Number(r);t.push([e|n])}else if(r<he[1]){let n=Number(r);t.push([e|24,n])}else if(r<he[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<he[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<he[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(`${K} encountered BigInt larger than allowable range`)}}qe.encodedSize=function(e){return G.encodedSize(e.value)};G.encodedSize=function(e){return e<he[0]?1:e<he[1]?2:e<he[2]?3:e<he[3]?5:9};qe.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function hd(t,e,r,n){return new O(w.negint,-1-ke(t,e+1,n),2)}function dd(t,e,r,n){return new O(w.negint,-1-Oe(t,e+1,n),3)}function pd(t,e,r,n){return new O(w.negint,-1-Me(t,e+1,n),5)}var zc=BigInt(-1),md=BigInt(1);function gd(t,e,r,n){let o=Pe(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new O(w.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${K} integers outside of the safe integer range are not supported`);return new O(w.negint,zc-BigInt(o),9)}function Pi(t,e){let r=e.value,n=typeof r=="bigint"?r*zc-md:r*-1-1;G(t,e.type.majorEncoded,n)}Pi.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*zc-md:r*-1-1;return n<he[0]?1:n<he[1]?2:n<he[2]?3:n<he[3]?5:9};Pi.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function fo(t,e,r,n){It(t,e,r+n);let o=t.slice(e+r,e+r+n);return new O(w.bytes,o,r+n)}function yd(t,e,r,n){return fo(t,e,1,r)}function bd(t,e,r,n){return fo(t,e,2,ke(t,e+1,n))}function xd(t,e,r,n){return fo(t,e,3,Oe(t,e+1,n))}function wd(t,e,r,n){return fo(t,e,5,Me(t,e+1,n))}function Ed(t,e,r,n){let o=Pe(t,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer bytes lengths not supported`);return fo(t,e,9,o)}function Ki(t){return t.encodedBytes===void 0&&(t.encodedBytes=w.equals(t.type,w.string)?Ni(t.value):t.value),t.encodedBytes}function Xr(t,e){let r=Ki(e);G(t,e.type.majorEncoded,r.length),t.push(r)}Xr.encodedSize=function(e){let r=Ki(e);return G.encodedSize(r.length)+r.length};Xr.compareTokens=function(e,r){return Qb(Ki(e),Ki(r))};function Qb(t,e){return t.length<e.length?-1:t.length>e.length?1:ki(t,e)}var Sd=new TextDecoder,tx=32;function rx(t,e,r){if(r-e<tx){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return Sd.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return Sd.decode(t.subarray(e,r))}function lo(t,e,r,n,o){let i=r+n;It(t,e,i);let s=new O(w.string,rx(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function Ad(t,e,r,n){return lo(t,e,1,r,n)}function vd(t,e,r,n){return lo(t,e,2,ke(t,e+1,n),n)}function Id(t,e,r,n){return lo(t,e,3,Oe(t,e+1,n),n)}function Td(t,e,r,n){return lo(t,e,5,Me(t,e+1,n),n)}function Bd(t,e,r,n){let o=Pe(t,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer string lengths not supported`);return lo(t,e,9,o,n)}var Cd=Xr;function Wr(t,e,r,n){return new O(w.array,n,r)}function _d(t,e,r,n){return Wr(t,e,1,r)}function Dd(t,e,r,n){return Wr(t,e,2,ke(t,e+1,n))}function Fd(t,e,r,n){return Wr(t,e,3,Oe(t,e+1,n))}function Ud(t,e,r,n){return Wr(t,e,5,Me(t,e+1,n))}function Ld(t,e,r,n){let o=Pe(t,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer array lengths not supported`);return Wr(t,e,9,o)}function Rd(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return Wr(t,e,1,1/0)}function Vi(t,e){G(t,w.array.majorEncoded,e.value)}Vi.compareTokens=qe.compareTokens;Vi.encodedSize=function(e){return G.encodedSize(e.value)};function Jr(t,e,r,n){return new O(w.map,n,r)}function Nd(t,e,r,n){return Jr(t,e,1,r)}function kd(t,e,r,n){return Jr(t,e,2,ke(t,e+1,n))}function Od(t,e,r,n){return Jr(t,e,3,Oe(t,e+1,n))}function Md(t,e,r,n){return Jr(t,e,5,Me(t,e+1,n))}function Pd(t,e,r,n){let o=Pe(t,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer map lengths not supported`);return Jr(t,e,9,o)}function Kd(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return Jr(t,e,1,1/0)}function zi(t,e){G(t,w.map.majorEncoded,e.value)}zi.compareTokens=qe.compareTokens;zi.encodedSize=function(e){return G.encodedSize(e.value)};function Vd(t,e,r,n){return new O(w.tag,r,1)}function zd(t,e,r,n){return new O(w.tag,ke(t,e+1,n),2)}function $d(t,e,r,n){return new O(w.tag,Oe(t,e+1,n),3)}function qd(t,e,r,n){return new O(w.tag,Me(t,e+1,n),5)}function Hd(t,e,r,n){return new O(w.tag,Pe(t,e+1,n),9)}function $i(t,e){G(t,w.tag.majorEncoded,e.value)}$i.compareTokens=qe.compareTokens;$i.encodedSize=function(e){return G.encodedSize(e.value)};var $c=20,qc=21,Hc=22,jc=23;function jd(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${K} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new O(w.null,null,1):new O(w.undefined,void 0,1)}function Yd(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return new O(w.break,void 0,1)}function Yc(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${K} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${K} Infinity values are not supported`)}return new O(w.float,t,e)}function Gd(t,e,r,n){return Yc(Gc(t,e+1),3,n)}function Zd(t,e,r,n){return Yc(Zc(t,e+1),5,n)}function Xd(t,e,r,n){return Yc(ep(t,e+1),9,n)}function ho(t,e,r){let n=e.value;if(n===!1)t.push([w.float.majorEncoded|$c]);else if(n===!0)t.push([w.float.majorEncoded|qc]);else if(n===null)t.push([w.float.majorEncoded|Hc]);else if(n===void 0)t.push([w.float.majorEncoded|jc]);else{let o,i=!1;(!r||r.float64!==!0)&&(Jd(n),o=Gc(nt,1),n===o||Number.isNaN(n)?(nt[0]=249,t.push(nt.slice(0,3)),i=!0):(Qd(n),o=Zc(nt,1),n===o&&(nt[0]=250,t.push(nt.slice(0,5)),i=!0))),i||(ax(n),o=ep(nt,1),nt[0]=251,t.push(nt.slice(0,9)))}}ho.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){Jd(n);let o=Gc(nt,1);if(n===o||Number.isNaN(n))return 3;if(Qd(n),o=Zc(nt,1),n===o)return 5}return 9};var Wd=new ArrayBuffer(9),He=new DataView(Wd,1),nt=new Uint8Array(Wd,0);function Jd(t){if(t===1/0)He.setUint16(0,31744,!1);else if(t===-1/0)He.setUint16(0,64512,!1);else if(Number.isNaN(t))He.setUint16(0,32256,!1);else{He.setFloat32(0,t);let e=He.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)He.setUint16(0,31744,!1);else if(r===0)He.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?He.setUint16(0,0):o<-14?He.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):He.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Gc(t,e){if(t.length-e<2)throw new Error(`${K} 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 Qd(t){He.setFloat32(0,t,!1)}function Zc(t,e){if(t.length-e<4)throw new Error(`${K} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function ax(t){He.setFloat64(0,t,!1)}function ep(t,e){if(t.length-e<8)throw new Error(`${K} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}ho.compareTokens=qe.compareTokens;function j(t,e,r){throw new Error(`${K} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function qi(t){return()=>{throw new Error(`${K} ${t}`)}}var U=[];for(let t=0;t<=23;t++)U[t]=j;U[24]=cd;U[25]=ud;U[26]=fd;U[27]=ld;U[28]=j;U[29]=j;U[30]=j;U[31]=j;for(let t=32;t<=55;t++)U[t]=j;U[56]=hd;U[57]=dd;U[58]=pd;U[59]=gd;U[60]=j;U[61]=j;U[62]=j;U[63]=j;for(let t=64;t<=87;t++)U[t]=yd;U[88]=bd;U[89]=xd;U[90]=wd;U[91]=Ed;U[92]=j;U[93]=j;U[94]=j;U[95]=qi("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)U[t]=Ad;U[120]=vd;U[121]=Id;U[122]=Td;U[123]=Bd;U[124]=j;U[125]=j;U[126]=j;U[127]=qi("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)U[t]=_d;U[152]=Dd;U[153]=Fd;U[154]=Ud;U[155]=Ld;U[156]=j;U[157]=j;U[158]=j;U[159]=Rd;for(let t=160;t<=183;t++)U[t]=Nd;U[184]=kd;U[185]=Od;U[186]=Md;U[187]=Pd;U[188]=j;U[189]=j;U[190]=j;U[191]=Kd;for(let t=192;t<=215;t++)U[t]=Vd;U[216]=zd;U[217]=$d;U[218]=qd;U[219]=Hd;U[220]=j;U[221]=j;U[222]=j;U[223]=j;for(let t=224;t<=243;t++)U[t]=qi("simple values are not supported");U[244]=j;U[245]=j;U[246]=j;U[247]=jd;U[248]=qi("simple values are not supported");U[249]=Gd;U[250]=Zd;U[251]=Xd;U[252]=j;U[253]=j;U[254]=j;U[255]=Yd;var ot=[];for(let t=0;t<24;t++)ot[t]=new O(w.uint,t,1);for(let t=-1;t>=-24;t--)ot[31-t]=new O(w.negint,t,1);ot[64]=new O(w.bytes,new Uint8Array(0),1);ot[96]=new O(w.string,"",1);ot[128]=new O(w.array,0,1);ot[160]=new O(w.map,0,1);ot[244]=new O(w.false,!1,1);ot[245]=new O(w.true,!0,1);ot[246]=new O(w.null,null,1);function Xc(t){switch(t.type){case w.false:return ht([244]);case w.true:return ht([245]);case w.null:return ht([246]);case w.bytes:return t.value.length?void 0:ht([64]);case w.string:return t.value===""?ht([96]):void 0;case w.array:return t.value===0?ht([128]):void 0;case w.map:return t.value===0?ht([160]):void 0;case w.uint:return t.value<24?ht([Number(t.value)]):void 0;case w.negint:if(t.value>=-24)return ht([31-Number(t.value)])}}var ux={float64:!1,mapSorter:hx,quickEncodeToken:Xc},ip=Object.freeze({float64:!0,mapSorter:dx,quickEncodeToken:Xc});function fx(){let t=[];return t[w.uint.major]=qe,t[w.negint.major]=Pi,t[w.bytes.major]=Xr,t[w.string.major]=Cd,t[w.array.major]=Vi,t[w.map.major]=zi,t[w.tag.major]=$i,t[w.float.major]=ho,t}var en=fx(),Hi=new co,mo=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(`${Mi} object contains circular references`);return new t(r,e)}},qt={null:new O(w.null,null),undefined:new O(w.undefined,void 0),true:new O(w.true,!0),false:new O(w.false,!1),emptyArray:new O(w.array,0),emptyMap:new O(w.map,0)},dt={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new O(w.float,t):t>=0?new O(w.uint,t):new O(w.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new O(w.uint,t):new O(w.negint,t)},Uint8Array(t,e,r,n){return new O(w.bytes,t)},string(t,e,r,n){return new O(w.string,t)},boolean(t,e,r,n){return t?qt.true:qt.false},null(t,e,r,n){return qt.null},undefined(t,e,r,n){return qt.undefined},ArrayBuffer(t,e,r,n){return new O(w.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new O(w.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[qt.emptyArray,new O(w.break)]:qt.emptyArray;n=mo.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=Qr(s,r,n);return r.addBreakTokens?[new O(w.array,t.length),o,new O(w.break)]:[new O(w.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=mo.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,u=0;for(let f of i){let l=o?t.get(f):t[f];c&&l===void 0||(a[u++]=[Qr(f,r,n),Qr(l,r,n)])}u<s&&(a.length=u)}return a?.length?(lx(a,r),r.addBreakTokens?[new O(w.map,a.length),a,new O(w.break)]:[new O(w.map,a.length),a]):r.addBreakTokens===!0?[qt.emptyMap,new O(w.break)]:qt.emptyMap},Tagged(t,e,r,n){return[new O(w.tag,t.tag),Qr(t.value,r,n)]}};dt.Map=dt.Object;dt.Buffer=dt.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))dt[`${t}Array`]=dt.DataView;function Qr(t,e={},r){let n=Vc(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||dt[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=dt[n];if(!i)throw new Error(`${Mi} unsupported type: ${n}`);return i(t,n,e,r)}function lx(t,e){e.mapSorter&&t.sort(e.mapSorter)}function hx(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=en[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function dx(t,e){if(t[0]instanceof O&&e[0]instanceof O){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=tp(r.value)),n._keyBytes||(n._keyBytes=tp(n.value)),ki(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function tp(t){return ap(t,en,ip)}function po(t,e,r,n){if(Array.isArray(e))for(let o of e)po(t,o,r,n);else r[e.type.major](t,e,n)}var rp=w.uint.majorEncoded,np=w.negint.majorEncoded,px=w.bytes.majorEncoded,mx=w.string.majorEncoded,op=w.array.majorEncoded,gx=w.float.majorEncoded|$c,yx=w.float.majorEncoded|qc,bx=w.float.majorEncoded|Hc,xx=w.float.majorEncoded|jc,wx=BigInt(-1),Ex=BigInt(1);function Sx(t){return t.addBreakTokens!==!0}function sp(t,e,r,n){let o=Vc(e),i=r.typeEncoders&&r.typeEncoders[o];if(i){let s=i(e,o,r,n);if(s!=null){po(t,s,en,r);return}}switch(o){case"null":t.push([bx]);return;case"undefined":t.push([xx]);return;case"boolean":t.push([e?yx:gx]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?ho(t,new O(w.float,e),r):e>=0?G(t,rp,e):G(t,np,e*-1-1);return;case"bigint":e>=BigInt(0)?G(t,rp,e):G(t,np,e*wx-Ex);return;case"string":{let s=Ni(e);G(t,mx,s.length),t.push(s);return}case"Uint8Array":G(t,px,e.length),t.push(e);return;case"Array":if(!e.length){t.push([op]);return}n=mo.createCheck(n,e),G(t,op,e.length);for(let s of e)sp(t,s,r,n);return;case"Object":case"Map":{let s=dt.Object(e,o,r,n);po(t,s,en,r)}return;default:{let s=dt[o];if(!s)throw new Error(`${Mi} unsupported type: ${o}`);let a=s(e,o,r,n);po(t,a,en,r)}}}function ap(t,e,r,n){let o=n instanceof Uint8Array,i=o?new Oi(n):Hi,s=Qr(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let u=c.encodedSize(s,r);if(o||(i=new co(u)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():ao(i.chunks[0])}}return i.reset(),po(i,s,e,r),i.toBytes(!0)}function Wc(t,e){return e=Object.assign({},ux,e),Sx(e)?(Hi.reset(),sp(Hi,t,e,void 0),Hi.toBytes(!0)):ap(t,en,e)}var Ax={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},ji=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=ot[e];if(r===void 0){let n=U[e];if(!n)throw new Error(`${K} 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}},Ht=Symbol.for("DONE"),tn=Symbol.for("BREAK");function vx(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=jt(e,r);if(i===tn){if(t.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed array`)}if(i===Ht)throw new Error(`${K} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Ix(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 c=jt(e,r);if(c===tn){if(t.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed map`)}if(c===Ht)throw new Error(`${K} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${K} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${K} found repeat map key "${c}"`);let u=jt(e,r);if(u===Ht)throw new Error(`${K} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,u):i[c]=u}return n?s:i}function*Tx(t,e,r){for(let n=0;n<t.value;n++){let o=jt(e,r);if(o===tn){if(t.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed map`)}if(o===Ht)throw new Error(`${K} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let i=jt(e,r);if(i===Ht)throw new Error(`${K} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,i]}}function Bx(t,e){let r=!1,n=function(){if(r)throw new Error(`${K} tag decode() may only be called once`);r=!0;let o=jt(t,e);if(o===Ht)throw new Error(`${K} tag content missing`);if(o===tn)throw new Error(`${K} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${K} tag decode() may only be called once`);r=!0;let o=t.next();if(!w.equals(o.type,w.map))throw new Error(`${K} entries() requires map content, got ${o.type.name}`);let i=[];for(let s of Tx(o,t,e))i.push(s);return i},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function jt(t,e){if(t.done())return Ht;let r=t.next();if(w.equals(r.type,w.break))return tn;if(r.type.terminal)return r.value;if(w.equals(r.type,w.array))return vx(r,t,e);if(w.equals(r.type,w.map))return Ix(r,t,e);if(w.equals(r.type,w.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=Bx(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${K} tag decoder must call decode() or entries()`);return o}throw new Error(`${K} tag not supported (${r.value})`)}throw new Error("unsupported")}function cp(t,e){if(!(t instanceof Uint8Array))throw new Error(`${K} data to decode must be a Uint8Array`);e=Object.assign({},Ax,e);let r=ao(t),n=e.tokenizer||new ji(r,e),o=jt(n,e);if(o===Ht)throw new Error(`${K} did not find any content to decode`);if(o===tn)throw new Error(`${K} got unexpected break`);return[o,t.subarray(n.pos())]}function Jc(t,e){let[r,n]=cp(t,e);if(n.length>0)throw new Error(`${K} too many terminals, data makes no sense`);return r}var Yi=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(Yi.prototype,Symbol.toStringTag,{value:"Tagged"});function _x(t){return t?.buffer instanceof ArrayBuffer}function up(t){if(_x(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Gi(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=lt(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return up(r)}function Yt(t,e="utf8"){let r=Di[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var Dx=hr("ipns:utils"),fp=ve("/ipns/"),Fx=114,Ux=0,Lx=18;function lp(t){let e;if(t.pubKey!=null)try{e=uh(t.pubKey)}catch(r){throw Dx.error(r),r}if(e!=null)return e}function hp(t,e,r){let n=ve(e);return Gi([t,r,n])}function Xi(t){let e=ve("ipns-signature:");return Gi([e,t])}function go(t){return"signatureV1"in t?me.encode({value:ve(t.value),signatureV1:t.signatureV1,validityType:t.validityType,validity:ve(t.validity),sequence:t.sequence,ttl:t.ttl,pubKey:t.pubKey,signatureV2:t.signatureV2,data:t.data}):me.encode({pubKey:t.pubKey,signatureV2:t.signatureV2,data:t.data})}function Ke(t){let e=me.decode(t);if(e.sequence!=null&&(e.sequence=BigInt(e.sequence)),e.ttl!=null&&(e.ttl=BigInt(e.ttl)),e.signatureV2==null||e.data==null)throw new et("Missing data or signatureV2");let r=mp(e.data),n=Rx(r.Value),o=Yt(r.Validity);if(e.value!=null&&e.signatureV1!=null)return Nx(e),{value:n,validityType:me.ValidityType.EOL,validity:o,sequence:r.Sequence,ttl:r.TTL,pubKey:e.pubKey,signatureV1:e.signatureV1,signatureV2:e.signatureV2,data:e.data};if(e.signatureV2!=null)return{value:n,validityType:me.ValidityType.EOL,validity:o,sequence:r.Sequence,ttl:r.TTL,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}function Gt(t){return Gi([fp,t.bytes])}function dp(t){let e=Zr(t.slice(fp.length));if(!Zi(e,Ux)&&!Zi(e,Lx))throw new No("Multihash in IPNS key was not identity or sha2-256");return e}function pp(t,e,r,n,o){let i;if(e===me.ValidityType.EOL)i=0;else throw new pr("The validity type is unsupported");return Wc({Value:t,Validity:r,ValidityType:i,Sequence:n,TTL:o})}function mp(t){let e=Jc(t);if(e.ValidityType===0)e.ValidityType=me.ValidityType.EOL;else throw new pr("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 Rx(t){let e=Yt(t).trim();if(e.startsWith("/"))return e;try{return`/ipfs/${$e.decode(t).toV1().toString()}`}catch{}try{return`/ipfs/${$e.parse(e).toV1().toString()}`}catch{}throw new Yn("Value must be a valid content path starting with /")}function gp(t){if(t!=null){let e=Mx(t);if(e!=null)return e.code===Fx?`/ipns/${e.toString(rt)}`:`/ipfs/${e.toV1().toString()}`;if(kx(t))return`/ipns/${rt.encode(t.bytes)}`;let r=t.toString().trim();if(r.startsWith("/")&&r.length>1)return r}throw new Yn("Value must be a valid content path starting with /")}function Nx(t){if(t.data==null)throw new Bi("Record data is missing");let e=mp(t.data);if(!dr(e.Value,t.value??new Uint8Array(0)))throw new et('Field "value" did not match between protobuf and CBOR');if(!dr(e.Validity,t.validity??new Uint8Array(0)))throw new et('Field "validity" did not match between protobuf and CBOR');if(e.ValidityType!==t.validityType)throw new et('Field "validityType" did not match between protobuf and CBOR');if(e.Sequence!==t.sequence)throw new et('Field "sequence" did not match between protobuf and CBOR');if(e.TTL!==t.ttl)throw new et('Field "ttl" did not match between protobuf and CBOR')}function kx(t){return t.bytes instanceof Uint8Array}function Ox(t){return typeof t?.toCID=="function"}function Mx(t){if(Ox(t))return t.toCID();try{return $e.parse(t)}catch{}return $e.asCID(t)}function Zi(t,e){return t.code===e}var Wi=hr("ipns:validator"),Px=1024*10;async function Kx(t,e){let r=Ke(e),n;try{let o=Xi(r.data);n=await t.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw Wi.error("record signature verification failed"),new et("Record signature verification failed");if(r.validityType===me.ValidityType.EOL){if(yp.default.fromString(r.validity).toDate().getTime()<Date.now())throw Wi.error("record has expired"),new Ii("record has expired")}else if(r.validityType!=null)throw Wi.error("the validity type is unsupported"),new pr("The validity type is unsupported");Wi("ipns record for %s is valid",r.value)}async function yo(t,e){if(e.byteLength>Px)throw new Ti("The record is too large");let r=dp(t),n;Zi(r,0)&&(n=fh(r));let o=Ke(e),i=lp(o)??n;if(i==null)throw new Gn("Could not extract public key from IPNS record or routing key");let s=Gt(i.toMultihash());if(!dr(s,t))throw new Gn("Embedded public key did not match routing key");await Kx(i,e)}var bp=Ss(Ai(),1);var Vx=hr("ipns"),xp=300*1e9,zx="/ipns/",V5=zx.length,wp={v1Compatible:!0,ttlNs:xp};async function Ji(t,e,r,n,o=wp){let i=new bp.default(Date.now()+Number(n)),s=me.ValidityType.EOL,a=BigInt(o.ttlNs??xp);return $x(t,e,r,s,i.toString(),a,o)}var $x=async(t,e,r,n,o,i,s=wp)=>{r=BigInt(r);let a=ve(o),c=gp(e),u=ve(c),f=pp(u,n,a,r,i),l=Xi(f),m=await t.sign(l),b;if(t.type==="RSA"&&(b=_t(t.publicKey)),s.v1Compatible===!0){let h=await qx(t,u,n,a),y={value:c,signatureV1:h,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:m,data:f};return b!=null&&(y.pubKey=b),y}else{let h={value:c,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:m,data:f};return b!=null&&(h.pubKey=b),h}},qx=async(t,e,r,n)=>{try{let o=hp(e,r,n);return await t.sign(o)}catch(o){throw Vx.error("record signature creation failed",o),new vi("Record signature creation failed")}};var Qc=Ss(Ai(),1);function Qi(t,e){let r=e.map((n,o)=>({record:Ke(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===me.ValidityType.EOL&&o.record.validityType===me.ValidityType.EOL){let a=Qc.default.fromString(n.record.validity).toDate(),c=Qc.default.fromString(o.record.validity).toDate();if(a.getTime()>c.getTime())return-1;if(a.getTime()<c.getTime())return 1}return 0}),r[0].index}var rn=BigInt(6e4)*5000000n,Ep=5;var es=class extends Error{static name="RecordsFailedValidationError";constructor(e="Records failed validation"){super(e),this.name="RecordsFailedValidationError"}},ts=class extends Error{static name="UnsupportedMultibasePrefixError";constructor(e="Unsupported multibase prefix"){super(e),this.name="UnsupportedMultibasePrefixError"}},rs=class extends Error{static name="UnsupportedMultihashCodecError";constructor(e="Unsupported multihash codec"){super(e),this.name="UnsupportedMultihashCodecError"}},ns=class extends Error{static name="InvalidValueError";constructor(e="Invalid value"){super(e),this.name="InvalidValueError"}};var bo=class extends Error{static name="RecordNotFoundError";name="RecordNotFoundError"};var Tt="/",Sp=new TextEncoder().encode(Tt),os=Sp[0],nn=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=ve(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]!==os)throw new Error("Invalid key")}toString(e="utf8"){return Yt(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(Tt))}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=Sp),this._buf[0]!==os){let e=new Uint8Array(this._buf.byteLength+1);e.fill(os,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===os;)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(Tt).slice(1)}type(){return Hx(this.baseNamespace())}name(){return jx(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Tt)||(e+=Tt),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(Tt):new t(e.slice(0,-1).join(Tt))}child(e){return this.toString()===Tt?e:e.toString()===Tt?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(),...Yx(e.map(r=>r.namespaces()))])}};function Hx(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function jx(t){let e=t.split(":");return e[e.length-1]}function Yx(t){return[].concat(...t)}var Zx=114,eu=0,tu=18;function ru(t,e){return t.code===e}var is="/dht/record/",Xx="/ipns/metadata/";function xo(t){return new nn(is+Yt(t,"base32"),!1)}function ss(t){return new nn(Xx+Yt(t,"base32"),!1)}function Ap(t,e){let r=Date.now(),n=e.getTime()+1728e5,o=new Date(t.validity).getTime();return n-r<864e5||o-r<864e5}function Wx(t){return t?.asCID===t}function vp(t){if(!Wx(t))return!1;if(t.code!==Zx)throw new W(`CID codec ${t.code} was not libp2p-key`);if(t.multihash.code!==eu&&t.multihash.code!==tu)throw new W(`Multihash algorithm codec ${t.multihash.code} was not Identity or SHA256 hash`);return!0}var Ip={[rt.prefix]:rt,[De.prefix]:De},on=class{routers;localStore;log;constructor(e,r){this.log=e.logger.forComponent("helia:ipns"),this.localStore=r.localStore,this.routers=r.routers}async resolve(e,r={}){let n=Xu(e)||ko(e)?e.toMultihash():vp(e)?e.multihash:e,o=Gt(n),i=await this.#t(o,r);return{...await this.#e(i.value,r),record:i}}async#e(e,r={}){let n=e.split("/");try{let o=n[1];if(o==="ipns"){let i=n[2],s=i.substring(0,1),a;if(s==="1"||s==="Q")a=De.decode(`z${i}`);else if(Ip[s]!=null)a=Ip[s].decode(i);else throw new ts(`Unsupported multibase prefix "${s}"`);let c;try{c=Zr(a)}catch{c=$e.decode(a).multihash}if(!ru(c,eu)&&!ru(c,tu))throw new rs(`Unsupported multihash codec "${c.code}"`);let{cid:u}=await this.resolve(c,r),f=n.slice(3).join("/");return{cid:u,path:f===""?void 0:f}}else if(o==="ipfs"){let i=$e.parse(n[2]),s=n.slice(3).join("/");return{cid:i,path:s===""?void 0:s}}}catch(o){this.log.error("error parsing ipfs path - %e",o)}throw this.log.error("invalid ipfs path %s",e),new ns("Invalid value")}async#t(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:c,created:u}=await this.localStore.get(e,r);this.log("record retrieved from cache"),await yo(e,c),this.log("record was valid");let f=Ke(c),l=Number((f.ttl??rn)/1000000n);if(u.getTime()+l>Date.now())return this.log("record TTL was valid"),f;if(r.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),f;this.log("record TTL has been reached, searching routing for updates"),n.push(c)}catch(c){this.log("cached record was invalid - %e",c),await this.localStore.delete(e,r)}else this.log("ignoring local cache due to nocache=true option");if(r.offline===!0)throw new bo("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 c=>{let u;try{u=await c.get(e,{...r,validate:!1})}catch(f){this.log.error("error finding IPNS record using router %s - %e",c.toString(),f),s.push(f);return}try{await yo(e,u),n.push(u)}catch(f){i++,this.log.error("error validating IPNS record from router %s - %e",c.toString(),f)}})),n.length===0)throw i>0?new es(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`):new bo("Could not find record for routing key");let a=n[Qi(e,n)];return await this.localStore.put(e,a,r),Ke(a)}};var Fe=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};var as=class{routers;localStore;keychain;constructor(e,r){this.keychain=e.libp2p.services.keychain,this.localStore=r.localStore,this.routers=r.routers}async publish(e,r,n={}){try{let o=await this.#e(e),i=1n,s=Gt(o.publicKey.toMultihash());if(await this.localStore.has(s,n)){let{record:l}=await this.localStore.get(s,n);i=Ke(l).sequence+1n}ko(r)&&(r=r.toCID());let a=n.ttl!=null?BigInt(n.ttl)*1000000n:rn,c=n.lifetime??1728e5,u=await Ji(o,r,i,c,{...n,ttlNs:a}),f=go(u);return n.offline===!0?await this.localStore.put(s,f,{...n,metadata:{keyName:e,lifetime:c}}):await Promise.all(this.routers.map(async l=>{await l.put(s,f,{...n,metadata:{keyName:e,lifetime:c}})})),{record:u,publicKey:o.publicKey}}catch(o){throw n.onProgress?.(new Fe("ipns:publish:error",o)),o}}async#e(e){try{return await this.keychain.exportKey(e)}catch{let n=await ch("Ed25519");return await this.keychain.importKey(e,n),n}}async unpublish(e,r){let{publicKey:n}=await this.keychain.exportKey(e),o=n.toMultihash(),i=Gt(o);await this.localStore.delete(i,r)}};function sn(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var cs=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}},an=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new cs(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 cs(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 nu=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Tp(t={}){return Qx(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 Qx(t,e){e=e??{};let r=e.onEnd,n=new an,o,i,s,a=sn(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((d,g)=>{i=E=>{i=null,n.push(E);try{d(t(n))}catch(I){g(I)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=sn()})}},u=d=>i!=null?i(d):(n.push(d),o),f=d=>(n=new an,i!=null?i({error:d}):(n.push({error:d}),o)),l=d=>{if(s)return o;if(e?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:d})},m=d=>s?o:(s=!0,d!=null?f(d):u({done:!0})),b=()=>(n=new an,m(),{done:!0}),h=d=>(m(d),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:b,throw:h,push:l,end:m,get readableLength(){return n.size},onEmpty:async d=>{let g=d?.signal;if(g?.throwIfAborted(),n.isEmpty())return;let E,I;g!=null&&(E=new Promise((C,B)=>{I=()=>{B(new nu)},g.addEventListener("abort",I)}));try{await Promise.race([a.promise,E])}finally{I!=null&&g!=null&&g?.removeEventListener("abort",I)}}},r==null)return o;let y=o;return o={[Symbol.asyncIterator](){return this},next(){return y.next()},throw(d){return y.throw(d),r!=null&&(r(d),r=void 0),{done:!0}},return(){return y.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(d){return y.end(d),r!=null&&(r(d),r=void 0),o},get readableLength(){return y.readableLength},onEmpty:d=>y.onEmpty(d)},o}var ou=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Bp=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function iu(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,c,f=new Promise((l,m)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){m(Bp(s));return}if(s&&(c=()=>{m(Bp(s))},s.addEventListener("abort",c,{once:!0})),t.then(l,m),r===Number.POSITIVE_INFINITY)return;let b=new ou;a=i.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(h){m(h)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?l():o instanceof Error?m(o):(b.message=o??`Promise timed out after ${r} milliseconds`,m(b))},r)}).finally(()=>{f.clear(),c&&s&&s.removeEventListener("abort",c)});return f.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},f}var ew=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 tw(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(),c=[],{addListener:u,removeListener:f}=ew(t),l=async(...b)=>{let h=r.multiArgs?b:b[0];if(r.filter)try{if(!await r.filter(h))return}catch(y){n(),s(y);return}c.push(h),r.count===c.length&&(n(),i(c))},m=(...b)=>{n(),s(r.rejectionMultiArgs?b:b[0])};n=()=>{for(let b of a)f(b,l);for(let b of r.rejectionEvents)a.includes(b)||f(b,m)};for(let b of a)u(b,l);for(let b of r.rejectionEvents)a.includes(b)||u(b,m);r.signal&&r.signal.addEventListener("abort",()=>{m(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(o.cancel=n,typeof r.timeout=="number"){let i=iu(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function us(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=tw(t,e,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function wo(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 fs=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function rw(t){return t.reason}async function Cp(t,e,r){if(e==null)return t;let n=r?.translateError??rw;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 ls=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=sn(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new mt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function nw(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var hs=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,r){this.id=nw(),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 mt),this.cleanup())}async join(e){let r=new ls(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 Cp(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 ds=class extends Oo{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=wo(this.emitEmpty.bind(this),1),this.emitIdle=wo(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 fs;let n=new hs(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 mt)}),this.clear()}async onEmpty(e){this.size!==0&&await us(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await us(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await us(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=Tp({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail)},i=c=>{n(c.detail.error)},s=()=>{n()},a=()=>{n(new mt("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 _p(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 Dp(t,e,r){let n,o,i=!1;function s(){let u={signal:o.signal},f;r?.timeout!=null&&(f=_p([o.signal,AbortSignal.timeout(r.timeout)]),u.signal=f),i=!0,Promise.resolve().then(async()=>{await t(u)}).catch(()=>{}).finally(()=>{f!=null&&(f.aborted?f.clear():f.addEventListener("abort",()=>{f.clear()},{once:!0})),i=!1,!o.signal.aborted&&(n=setTimeout(s,e))})}let a=wo(s,r?.debounce??100),c=!1;return{setInterval:u=>{e!==u&&(e=u,n!=null&&(clearTimeout(n),n=setTimeout(s,e)))},setTimeout:u=>{r??={},r.timeout=u},run:()=>{i||(clearTimeout(n),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,e))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var ps=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.libp2p.services.keychain,this.republishConcurrency=r.republishConcurrency||Ep,this.started=e.libp2p.status==="started",this.routers=r.routers??[],this.republishTask=Dp(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 ds({concurrency:this.republishConcurrency});try{let n=[];for await(let{routingKey:o,record:i,metadata:s,created:a}of this.localStore.list(e)){if(s==null){this.log(`no metadata found for record ${o.toString()}, skipping`);continue}let c;try{c=Ke(i)}catch(m){this.log.error("error unmarshaling record - %e",m);continue}if(!Ap(c,a)){this.log.trace(`skipping record ${o.toString()}within republish threshold`);continue}let u=c.sequence+1n,f=c.ttl??rn,l;try{l=await this.keychain.exportKey(s.keyName)}catch(m){this.log.error("missing key %s, skipping republishing record - %e",s.keyName,m);continue}try{let m=await Ji(l,c.value,u,s.lifetime,{...e,ttlNs:f});n.push({routingKey:o,record:m})}catch(m){this.log.error("error creating updated IPNS record for %s - %e",o,m);continue}}this.log(`found ${n.length} records to republish`);for(let{routingKey:o,record:i}of n)r.add(async()=>{try{let s=go(i);await Promise.all(this.routers.map(a=>a.put(o,s,e)))}catch(s){this.log.error("error republishing record - %e",s)}},e)}catch(n){this.log.error("error during republish - %e",n)}await r.onIdle(e)}};function su(t=0){return new Uint8Array(t)}function Zt(t=0){return new Uint8Array(t)}var iw=Math.pow(2,7),sw=Math.pow(2,14),aw=Math.pow(2,21),Fp=Math.pow(2,28),Up=Math.pow(2,35),Lp=Math.pow(2,42),Rp=Math.pow(2,49),Ie=128,Xt=127;function Eo(t){if(t<iw)return 1;if(t<sw)return 2;if(t<aw)return 3;if(t<Fp)return 4;if(t<Up)return 5;if(t<Lp)return 6;if(t<Rp)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Np(t,e,r=0){switch(Eo(t)){case 8:e[r++]=t&255|Ie,t/=128;case 7:e[r++]=t&255|Ie,t/=128;case 6:e[r++]=t&255|Ie,t/=128;case 5:e[r++]=t&255|Ie,t/=128;case 4:e[r++]=t&255|Ie,t>>>=7;case 3:e[r++]=t&255|Ie,t>>>=7;case 2:e[r++]=t&255|Ie,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function kp(t,e){let r=t[e],n=0;if(n+=r&Xt,r<Ie||(r=t[e+1],n+=(r&Xt)<<7,r<Ie)||(r=t[e+2],n+=(r&Xt)<<14,r<Ie)||(r=t[e+3],n+=(r&Xt)<<21,r<Ie)||(r=t[e+4],n+=(r&Xt)*Fp,r<Ie)||(r=t[e+5],n+=(r&Xt)*Up,r<Ie)||(r=t[e+6],n+=(r&Xt)*Lp,r<Ie)||(r=t[e+7],n+=(r&Xt)*Rp,r<Ie))return n;throw new RangeError("Could not decode varint")}var au=new Float32Array([-0]),Wt=new Uint8Array(au.buffer);function Op(t,e,r){au[0]=t,e[r]=Wt[0],e[r+1]=Wt[1],e[r+2]=Wt[2],e[r+3]=Wt[3]}function Mp(t,e){return Wt[0]=t[e],Wt[1]=t[e+1],Wt[2]=t[e+2],Wt[3]=t[e+3],au[0]}var cu=new Float64Array([-0]),be=new Uint8Array(cu.buffer);function Pp(t,e,r){cu[0]=t,e[r]=be[0],e[r+1]=be[1],e[r+2]=be[2],e[r+3]=be[3],e[r+4]=be[4],e[r+5]=be[5],e[r+6]=be[6],e[r+7]=be[7]}function Kp(t,e){return be[0]=t[e],be[1]=t[e+1],be[2]=t[e+2],be[3]=t[e+3],be[4]=t[e+4],be[5]=t[e+5],be[6]=t[e+6],be[7]=t[e+7],cu[0]}var cw=BigInt(Number.MAX_SAFE_INTEGER),uw=BigInt(Number.MIN_SAFE_INTEGER),Ve=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 wr;if(e<cw&&e>uw)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>Vp&&(o=0n,++n>Vp&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return wr;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):wr}},wr=new Ve(0,0);wr.toBigInt=function(){return 0n};wr.zzEncode=wr.zzDecode=function(){return this};wr.length=function(){return 1};var Vp=4294967296n;function zp(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 $p(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 uu(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 it(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function ms(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var fu=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,it(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 it(this,4);return ms(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw it(this,4);return ms(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw it(this,4);let e=Mp(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw it(this,4);let e=Kp(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 it(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return $p(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw it(this,e);this.pos+=e}else do if(this.pos>=this.len)throw it(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 Ve(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 it(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 it(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 it(this,8);let e=ms(this.buf,this.pos+=4),r=ms(this.buf,this.pos+=4);return new Ve(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=kp(this.buf,this.pos);return this.pos+=Eo(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 So(t){return new fu(t instanceof Uint8Array?t:t.subarray())}function lu(t,e,r){let n=So(t);return e.decode(n,void 0,r)}var gu={};z(gu,{base10:()=>gw});var xv=new Uint8Array(0);function Hp(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 Bt(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function jp(t){return new TextEncoder().encode(t)}function Yp(t){return new TextDecoder().decode(t)}function fw(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var y=0,d=0,g=0,E=h.length;g!==E&&h[g]===0;)g++,y++;for(var I=(E-g)*f+1>>>0,C=new Uint8Array(I);g!==E;){for(var B=h[g],R=0,_=I-1;(B!==0||R<d)&&_!==-1;_--,R++)B+=256*C[_]>>>0,C[_]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");d=R,g++}for(var x=I-d;x!==I&&C[x]===0;)x++;for(var D=c.repeat(y);x<I;++x)D+=t.charAt(C[x]);return D}function m(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var y=0;if(h[y]!==" "){for(var d=0,g=0;h[y]===c;)d++,y++;for(var E=(h.length-y)*u+1>>>0,I=new Uint8Array(E);h[y];){var C=r[h.charCodeAt(y)];if(C===255)return;for(var B=0,R=E-1;(C!==0||B<g)&&R!==-1;R--,B++)C+=a*I[R]>>>0,I[R]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");g=B,y++}if(h[y]!==" "){for(var _=E-g;_!==E&&I[_]===0;)_++;for(var x=new Uint8Array(d+(E-_)),D=d;_!==E;)x[D++]=I[_++];return x}}}function b(h){var y=m(h);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:m,decode:b}}var lw=fw,hw=lw,Zp=hw;var hu=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")}},du=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 Xp(this,e)}},pu=class{decoders;constructor(e){this.decoders=e}or(e){return Xp(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 Xp(t,e){return new pu({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var mu=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 hu(e,r,n),this.decoder=new du(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function cn({name:t,prefix:e,encode:r,decode:n}){return new mu(t,e,r,n)}function Jt({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Zp(r,t);return cn({prefix:e,name:t,encode:n,decode:i=>Bt(o(i))})}function dw(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,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function pw(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],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 mw(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function re({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=mw(n);return cn({prefix:e,name:t,encode(i){return pw(i,n,r)},decode(i){return dw(i,o,r,t)}})}var gw=Jt({prefix:"9",name:"base10",alphabet:"0123456789"});var yu={};z(yu,{base16:()=>yw,base16upper:()=>bw});var yw=re({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),bw=re({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var bu={};z(bu,{base2:()=>xw});var xw=re({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var xu={};z(xu,{base256emoji:()=>vw});var Wp=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}"),ww=Wp.reduce((t,e,r)=>(t[r]=e,t),[]),Ew=Wp.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Sw(t){return t.reduce((e,r)=>(e+=ww[r],e),"")}function Aw(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ew[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var vw=cn({prefix:"\u{1F680}",name:"base256emoji",encode:Sw,decode:Aw});var wu={};z(wu,{base32:()=>un,base32hex:()=>Cw,base32hexpad:()=>Dw,base32hexpadupper:()=>Fw,base32hexupper:()=>_w,base32pad:()=>Tw,base32padupper:()=>Bw,base32upper:()=>Iw,base32z:()=>Uw});var un=re({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Iw=re({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Tw=re({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Bw=re({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Cw=re({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),_w=re({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Dw=re({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Fw=re({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Uw=re({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Eu={};z(Eu,{base36:()=>Ao,base36upper:()=>Lw});var Ao=Jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Lw=Jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Su={};z(Su,{base58btc:()=>pt,base58flickr:()=>Rw});var pt=Jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Rw=Jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Au={};z(Au,{base64:()=>Nw,base64pad:()=>kw,base64url:()=>Ow,base64urlpad:()=>Mw});var Nw=re({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),kw=re({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ow=re({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Mw=re({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var vu={};z(vu,{base8:()=>Pw});var Pw=re({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Iu={};z(Iu,{identity:()=>Kw});var Kw=cn({prefix:"\0",name:"identity",encode:t=>Yp(t),decode:t=>jp(t)});var Nv=new TextEncoder,kv=new TextDecoder;var Bu={};z(Bu,{identity:()=>u2});var $w=e0,Jp=128,qw=127,Hw=~qw,jw=Math.pow(2,31);function e0(t,e,r){e=e||[],r=r||0;for(var n=r;t>=jw;)e[r++]=t&255|Jp,t/=128;for(;t&Hw;)e[r++]=t&255|Jp,t>>>=7;return e[r]=t|0,e0.bytes=r-n+1,e}var Yw=Tu,Gw=128,Qp=127;function Tu(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw Tu.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&Qp)<<o:(s&Qp)*Math.pow(2,o),o+=7}while(s>=Gw);return Tu.bytes=i-n,r}var Zw=Math.pow(2,7),Xw=Math.pow(2,14),Ww=Math.pow(2,21),Jw=Math.pow(2,28),Qw=Math.pow(2,35),e2=Math.pow(2,42),t2=Math.pow(2,49),r2=Math.pow(2,56),n2=Math.pow(2,63),o2=function(t){return t<Zw?1:t<Xw?2:t<Ww?3:t<Jw?4:t<Qw?5:t<e2?6:t<t2?7:t<r2?8:t<n2?9:10},i2={encode:$w,decode:Yw,encodingLength:o2},s2=i2,vo=s2;function Io(t,e=0){return[vo.decode(t,e),vo.decode.bytes]}function fn(t,e,r=0){return vo.encode(t,e,r),e}function ln(t){return vo.encodingLength(t)}function dn(t,e){let r=e.byteLength,n=ln(t),o=n+ln(r),i=new Uint8Array(o+r);return fn(t,i,0),fn(r,i,n),i.set(e,o),new hn(t,r,e,i)}function t0(t){let e=Bt(t),[r,n]=Io(e),[o,i]=Io(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new hn(r,o,s,e)}function r0(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Hp(t.bytes,r.bytes)}}var hn=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var n0=0,a2="identity",o0=Bt;function c2(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 dn(n0,o0(t))}var u2={code:n0,name:a2,encode:o0,digest:c2};var Du={};z(Du,{sha256:()=>l2,sha512:()=>h2});var f2=20;function _u({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Cu(t,e,r,n,o)}var Cu=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??f2,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?i0(n,this.code,r?.truncate):n.then(o=>i0(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function i0(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 dn(e,t)}function a0(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var l2=_u({name:"sha2-256",code:18,encode:a0("SHA-256")}),h2=_u({name:"sha2-512",code:19,encode:a0("SHA-512")});function c0(t,e){let{bytes:r,version:n}=t;return n===0?p2(r,Fu(t),e??pt.encoder):m2(r,Fu(t),e??un.encoder)}var u0=new WeakMap;function Fu(t){let e=u0.get(t);if(e==null){let r=new Map;return u0.set(t,r),r}return e}var ys=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Bo)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==g2)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=dn(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&&r0(e.multihash,n.multihash)}toString(e){return c0(this,e)}toJSON(){return{"/":c0(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??f0(n,o,i.bytes))}else if(r[y2]===!0){let{version:n,multihash:o,code:i}=r,s=t0(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!==Bo)throw new Error(`Version 0 CID must use dag-pb (code: ${Bo}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=f0(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Bo,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=Bt(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 hn(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[l,m]=Io(e.subarray(r));return r+=m,l},o=n(),i=Bo;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),u=r+c,f=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=d2(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 Fu(i).set(n,e),i}};function d2(t,e){switch(t[0]){case"Q":{let r=e??pt;return[pt.prefix,r.decode(`${pt.prefix}${t}`)]}case pt.prefix:{let r=e??pt;return[pt.prefix,r.decode(t)]}case un.prefix:{let r=e??un;return[un.prefix,r.decode(t)]}case Ao.prefix:{let r=e??Ao;return[Ao.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 p2(t,e,r){let{prefix:n}=r;if(n!==pt.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 m2(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 Bo=112,g2=18;function f0(t,e,r){let n=ln(t),o=n+ln(e),i=new Uint8Array(o+r.byteLength);return fn(t,i,0),fn(e,i,n),i.set(r,o),i}var y2=Symbol.for("@ipld/js-cid/CID");var Uu={...Iu,...bu,...vu,...gu,...yu,...wu,...Eu,...Su,...Au,...xu},oI={...Du,...Bu};function h0(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var l0=h0("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Lu=h0("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=Zt(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),b2={utf8:l0,"utf-8":l0,hex:Uu.base16,latin1:Lu,ascii:Lu,binary:Lu,...Uu},d0=b2;function p0(t,e="utf8"){let r=d0[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Ru(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return Zt(s);o+s>e&&(n=Zt(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Er=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Nu(){}var Ou=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},x2=Ru();function w2(t){return globalThis.Buffer!=null?Zt(t):x2(t)}var _o=class{len;head;tail;states;constructor(){this.len=0,this.head=new Er(Nu,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Er(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Mu((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(bs,10,Ve.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Ve.fromBigInt(e);return this._push(bs,r.length(),r)}uint64Number(e){return this._push(Np,Eo(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=Ve.fromBigInt(e).zzEncode();return this._push(bs,r.length(),r)}sint64Number(e){let r=Ve.fromNumber(e).zzEncode();return this._push(bs,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(ku,1,e?1:0)}fixed32(e){return this._push(Co,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Ve.fromBigInt(e);return this._push(Co,4,r.lo)._push(Co,4,r.hi)}fixed64Number(e){let r=Ve.fromNumber(e);return this._push(Co,4,r.lo)._push(Co,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(Op,4,e)}double(e){return this._push(Pp,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(ku,1,0):this.uint32(r)._push(S2,r,e)}string(e){let r=zp(e);return r!==0?this.uint32(r)._push(uu,r,e):this._push(ku,1,0)}fork(){return this.states=new Ou(this),this.head=this.tail=new Er(Nu,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 Er(Nu,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=w2(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function ku(t,e,r){e[r]=t&255}function E2(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Mu=class extends Er{next;constructor(e,r){super(E2,e,r),this.next=void 0}};function bs(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 Co(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 S2(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(_o.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(A2,e,t),this},_o.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(v2,e,t),this});function A2(t,e,r){e.set(t,r)}function v2(t,e,r){t.length<40?uu(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(p0(t),r)}function Pu(){return new _o}function Ku(t,e){let r=Pu();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Vu(t,e,r){let n=So(t);yield*e.stream(n,void 0,"$",r)}var zu={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function $u(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function qu(t,e,r){return $u("message",zu.LENGTH_DELIMITED,t,e,r)}var Do;(function(t){let e;t.codec=()=>(e==null&&(e=qu((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 c={key:su(0),value:su(0),timeReceived:""},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.key=i.bytes();break}case 2:{c.value=i.bytes();break}case 5:{c.timeReceived=i.string();break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.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(f&7);break}}}})),e);function r(i){return Ku(i,t.codec())}t.encode=r;function n(i,s){return lu(i,t.codec(),s)}t.decode=n;function o(i,s){return Vu(i,t.codec(),s)}t.stream=o})(Do||(Do={}));function m0(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(),c=String(a*1e3*1e3).padStart(9,"0");return`${e}-${r}-${n}T${o}:${i}:${s}.${c}Z`}function g0(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),c=parseInt(r[6],10),u=parseInt(r[7].slice(0,-6),10);return new Date(Date.UTC(n,o,i,s,a,c,u))}var Qt=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 Do.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:m0(this.timeReceived)}}static deserialize(e){let r=Do.decode(e);return new t(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(e){let r=g0(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 y0;(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"})(y0||(y0={}));var Fo;(function(t){let e;t.codec=()=>(e==null&&(e=io((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 c={keyName:"",lifetime:0},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.keyName=i.string();break}case 2:{c.lifetime=i.uint32();break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.keyName`,value:i.string()};break}case 2:{yield{field:`${a}.lifetime`,value:i.uint32()};break}default:{i.skipType(f&7);break}}}})),e);function r(i){return no(i,t.codec())}t.encode=r;function n(i,s){return Wn(i,t.codec(),s)}t.decode=n;function o(i,s){return oo(i,t.codec(),s)}t.stream=o})(Fo||(Fo={}));function xs(t,e){return{async put(r,n,o={}){try{let i=xo(r);try{let c=await t.get(i),u=Qt.deserialize(c);if(dr(u.value,n))return}catch(c){if(c.name!=="NotFoundError")throw c}let s=new Qt(r,n,new Date);o.onProgress?.(new Fe("ipns:routing:datastore:put"));let a=t.batch();a.put(i,s.serialize()),o.metadata!=null&&a.put(ss(r),Fo.encode(o.metadata)),await a.commit(o)}catch(i){throw o.onProgress?.(new Fe("ipns:routing:datastore:error",i)),i}},async get(r,n={}){try{let o=xo(r);n.onProgress?.(new Fe("ipns:routing:datastore:get"));let i=await t.get(o,n),s=Qt.deserialize(i);return{record:s.value,created:s.timeReceived}}catch(o){throw n.onProgress?.(new Fe("ipns:routing:datastore:error",o)),o}},async has(r,n={}){let o=xo(r);return t.has(o,n)},async delete(r,n){let o=xo(r),i=t.batch();i.delete(o),i.delete(ss(r)),await i.commit(n)},async*list(r={}){try{r.onProgress?.(new Fe("ipns:routing:datastore:list"));for await(let{key:n,value:o}of t.query({prefix:is},r))try{let i=Qt.deserialize(o),a=n.toString().substring(is.length),c=ve(a,"base32"),u=ss(c),f;try{let l=await t.get(u,r);f=Fo.decode(l)}catch(l){e.error("Error deserializing metadata for %s - %e",a,l)}yield{routingKey:c,metadata:f,record:i.value,created:i.timeReceived}}catch(i){e.error("Error deserializing record - %e",i)}}catch(n){throw r.onProgress?.(new Fe("ipns:routing:datastore:error",n)),n}}}}var Hu=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 Fe("ipns:routing:helia:error",o)),o}}async get(e,r={}){try{return await this.routing.get(e,r)}catch(n){throw r.onProgress?.(new Fe("ipns:routing:helia:error",n)),n}}toString(){return"HeliaRouting()"}};function Uo(t){return new Hu(t)}var ju=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 ws(t){return new ju(t)}var Es=class{routers;publisher;republisher;resolver;localStore;started;constructor(e,r={}){this.localStore=xs(e.datastore,e.logger.forComponent("helia:ipns:local-store")),this.started=e.libp2p.status==="started",this.routers=[ws(this.localStore),Uo(e.routing),...r.routers??[]],this.publisher=new as(e,{...r,routers:this.routers,localStore:this.localStore}),this.republisher=new ps(e,{...r,routers:this.routers,localStore:this.localStore}),this.resolver=new on(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()}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,r,n)}async resolve(e,r={}){return this.resolver.resolve(e,r)}async unpublish(e,r){return this.publisher.unpublish(e,r)}};function T2(t,e={}){return new Es(t,e)}function B2(t,e={}){let r=xs(t.datastore,t.logger.forComponent("helia:ipns:local-store")),n=[ws(r),Uo(t.routing),...e.routers??[]];return new on(t,{routers:n,localStore:r})}return v0(C2);})();
14
- /*! Bundled license information:
15
-
16
- @noble/curves/utils.js:
17
- @noble/curves/abstract/modular.js:
18
- @noble/curves/abstract/curve.js:
19
- @noble/curves/abstract/edwards.js:
20
- @noble/curves/ed25519.js:
21
- @noble/curves/abstract/weierstrass.js:
22
- @noble/curves/secp256k1.js:
23
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
24
- */
13
+ ${e}[Error list was empty]`,r.trim()}return as(t,e)}X.formatters.e=t=>t==null?"undefined":us(t);function pu(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e}function Mn(t,e){let r=pu(`${t}:trace`);return X.enabled(`${t}:trace`)&&X.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=X(`${t}:trace`,e)),Object.assign(X(t,e),{error:X(`${t}:error`,e),trace:r,newScope:n=>Mn(`${t}:${n}`,e)})}function cs(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var ls=$r(jt(),1);var mu=Mn("ipns"),fs=300*1e9,gu="/ipns/",Pd=gu.length,hs={v1Compatible:!0,ttlNs:fs};async function Cr(t,e,r,n,i=hs){let o=new ls.default(Date.now()+Number(n)),s=O.ValidityType.EOL,a=BigInt(i.ttlNs??fs);return yu(t,e,r,s,o.toString(),a,i)}var yu=async(t,e,r,n,i,o,s=hs)=>{r=BigInt(r);let a=$(i),u=ts(e,n,a,r,o),f=Sr(u),l=await t.sign(f,s),p=wu(t.publicKey)?t.publicKey:void 0,m;if(s.v1Compatible===!0){let b=await xu(t,e,n,a);m={value:e,signatureV1:b,validity:i,validityType:n,sequence:r,ttl:o,signatureV2:l,data:u,publicKey:p}}else m={value:e,validity:i,validityType:n,sequence:r,ttl:o,signatureV2:l,data:u,publicKey:p};return m.bytes=nt(m),m},xu=async(t,e,r,n,i)=>{try{let o=es(e,r,n);return await t.sign(o,i)}catch(o){throw mu.error("record signature creation failed",o),new qt("Record signature creation failed")}};function wu(t){return t.toMultihash().code!==0}var Ar=class{routers;localStore;keychain;constructor(e,r){this.keychain=e.keychain,this.localStore=r.localStore,this.routers=r.routers}async publish(e,r,n={}){try{let i=await this.#e(e,n),o=i.publicKey.toMultihash(),s=kt(o),a=1n;if(await this.localStore.has(s,n)){let{record:m}=await this.localStore.get(s,n);a=(await pe(s,m,this.keychain,n)).sequence+1n}let u=n.ttl!=null?BigInt(n.ttl)*1000000n:je,f=n.lifetime??1728e5,l=await Cr(i,r,a,f,{...n,ttlNs:u}),p=nt(l);return n.offline===!0?await this.localStore.put(s,p,{...n,metadata:{keyName:e,lifetime:f}}):await Promise.all(this.routers.map(async m=>{await m.put(s,p,{...n,metadata:{keyName:e,lifetime:f}})})),{record:{...l,publicKey:i.publicKey},name:`/ipns/${i.publicKey.toCID().toString(ne)}`,publicKey:i.publicKey}}catch(i){throw n.onProgress?.(new Y("ipns:publish:error",i)),i}}async#e(e,r){try{return await this.keychain.exportKey(e,r)}catch(n){if(n.name==="NotFoundError")return this.keychain.generateKey(e,r);throw n}}async unpublish(e,r){let i=(await this.keychain.exportKey(e,r)).publicKey.toMultihash(),o=kt(i);await this.localStore.delete(o,r)}};function ot(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var vr=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},st=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new vr(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new vr(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Pn=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function ds(t={}){return Eu(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function Eu(t,e){e=e??{};let r=e.onEnd,n=new st,i,o,s,a=ot(),u=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((x,T)=>{o=F=>{o=null,n.push(F);try{x(t(n))}catch(k){T(k)}return i}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=ot()})}},f=x=>o!=null?o(x):(n.push(x),i),l=x=>(n=new st,o!=null?o({error:x}):(n.push({error:x}),i)),p=x=>{if(s)return i;if(e?.objectMode!==!0&&x?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:x})},m=x=>s?i:(s=!0,x!=null?l(x):f({done:!0})),b=()=>(n=new st,m(),{done:!0}),S=x=>(m(x),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:u,return:b,throw:S,push:p,end:m,get readableLength(){return n.size},onEmpty:async x=>{let T=x?.signal;if(T?.throwIfAborted(),n.isEmpty())return;let F,k;T!=null&&(F=new Promise((P,B)=>{k=()=>{B(new Pn)},T.addEventListener("abort",k)}));try{await Promise.race([a.promise,F])}finally{k!=null&&T!=null&&T?.removeEventListener("abort",k)}}},r==null)return i;let E=i;return i={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(x){return E.throw(x),r!=null&&(r(x),r=void 0),{done:!0}},return(){return E.return(),r!=null&&(r(),r=void 0),{done:!0}},push:p,end(x){return E.end(x),r!=null&&(r(x),r=void 0),i},get readableLength(){return E.readableLength},onEmpty:x=>E.onEmpty(x)},i}var $n=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},ps=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Vn(t,e){let{milliseconds:r,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout},signal:s}=e,a,u,l=new Promise((p,m)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){m(ps(s));return}if(s&&(u=()=>{m(ps(s))},s.addEventListener("abort",u,{once:!0})),t.then(p,m),r===Number.POSITIVE_INFINITY)return;let b=new $n;a=o.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(S){m(S)}return}typeof t.cancel=="function"&&t.cancel(),i===!1?p():i instanceof Error?m(i):(b.message=i??`Promise timed out after ${r} milliseconds`,m(b))},r)}).finally(()=>{l.clear(),u&&s&&s.removeEventListener("abort",u)});return l.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},l}var Su=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function Tu(t,e,r){let n,i=new Promise((o,s)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),u=[],{addListener:f,removeListener:l}=Su(t),p=async(...b)=>{let S=r.multiArgs?b:b[0];if(r.filter)try{if(!await r.filter(S))return}catch(E){n(),s(E);return}u.push(S),r.count===u.length&&(n(),o(u))},m=(...b)=>{n(),s(r.rejectionMultiArgs?b:b[0])};n=()=>{for(let b of a)l(b,p);for(let b of r.rejectionEvents)a.includes(b)||l(b,m)};for(let b of a)f(b,p);for(let b of r.rejectionEvents)a.includes(b)||f(b,m);r.signal&&r.signal.addEventListener("abort",()=>{m(r.signal.reason)},{once:!0}),r.resolveImmediately&&o(u)});if(i.cancel=n,typeof r.timeout=="number"){let o=Vn(i,{milliseconds:r.timeout});return o.cancel=()=>{n(),o.clear()},o}return i}function Nr(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Tu(t,e,r),i=n.then(o=>o[0]);return i.cancel=n.cancel,i}function _t(t,e){let r,n=function(){let i=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(i,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Fr=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function Iu(t){return t.reason}async function ms(t,e,r){if(e==null)return t;let n=r?.translateError??Iu;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let i;try{return await Promise.race([t,new Promise((o,s)=>{i=()=>{s(n(e))},e.addEventListener("abort",i)})])}finally{i!=null&&e.removeEventListener("abort",i)}}var kr=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=ot(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new we)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Cu(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Dr=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,r){this.id=Cu(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new we),this.cleanup())}async join(e){let r=new kr(e);return this.recipients.push(r),e?.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await ms(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(!this.dispatchingProgress){this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(r)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var Ur=class extends ir{concurrency;maxSize;queue;pending;sort;paused;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=e.sort,this.queue=[],this.emitEmpty=_t(this.emitEmpty.bind(this),1),this.emitIdle=_t(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let r of this.queue)if(r.status==="queued"){e=r;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===e){this.queue.splice(r,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}async add(e,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Fr;let n=new Dr(e,r);this.enqueue(n),this.safeDispatchEvent("add");let i=n.join(r).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o});return this.tryToStartAnother(),i}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new we)}),this.clear()}async onEmpty(e){this.size!==0&&await Nr(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await Nr(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Nr(this,"idle",e)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let r=ds({objectMode:!0}),n=u=>{u!=null?this.abort():this.clear(),r.end(u)},i=u=>{u.detail!=null&&r.push(u.detail)},o=u=>{n(u.detail.error)},s=()=>{n()},a=()=>{n(new we("Queue aborted"))};this.addEventListener("completed",i),this.addEventListener("failure",o),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",i),this.removeEventListener("failure",o),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};function gs(t){let e=new globalThis.AbortController;function r(){let o=t.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();e.abort(o);for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let o of t){if(o?.aborted===!0){r();break}o?.addEventListener!=null&&o.addEventListener("abort",r)}function n(){for(let o of t)o?.removeEventListener!=null&&o.removeEventListener("abort",r)}let i=e.signal;return i.clear=n,i}function ys(t,e,r){let n,i,o=!1;function s(){let f={signal:i.signal},l;r?.timeout!=null&&(l=gs([i.signal,AbortSignal.timeout(r.timeout)]),f.signal=l),o=!0,Promise.resolve().then(async()=>{await t(f)}).catch(()=>{}).finally(()=>{l!=null&&(l.aborted?l.clear():l.addEventListener("abort",()=>{l.clear()},{once:!0})),o=!1,!i.signal.aborted&&(n=setTimeout(s,e))})}let a=_t(s,r?.debounce??100),u=!1;return{setInterval:f=>{e!==f&&(e=f,n!=null&&(clearTimeout(n),n=setTimeout(s,e)))},setTimeout:f=>{r??={},r.timeout=f},run:()=>{o||(clearTimeout(n),a())},start:()=>{u||(u=!0,i=new AbortController,i.signal,r?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,e))},stop:()=>{clearTimeout(n),i?.abort(),u=!1}}}var _r=class{routers;localStore;republishTask;log;keychain;started=!1;republishConcurrency;constructor(e,r){this.log=e.logger.forComponent("helia:ipns"),this.localStore=r.localStore,this.keychain=e.keychain,this.republishConcurrency=r.republishConcurrency||wi,this.started=!1,this.routers=r.routers??[],this.republishTask=ys(this.#e.bind(this),r.republishInterval??36e5,{runImmediately:!0}),this.started&&this.republishTask.start()}start(){this.started||(this.started=!0,this.republishTask.start())}stop(){this.started&&(this.started=!1,this.republishTask.stop())}async#e(e={}){if(!this.started)return;this.log("starting ipns republish records loop");let r=new Ur({concurrency:this.republishConcurrency});try{let n=[],i=0;for await(let{routingKey:o,record:s,metadata:a,created:u}of this.localStore.list(e)){if(i++,a==null){this.log("no metadata found for record %b, skipping",o);continue}let f;try{f=await pe(o,s,this.keychain,e)}catch(b){this.log.error("error unmarshaling record - %e",b);continue}if(!Zo(f,u)){this.log.trace("skipping record %b within republish threshold",o);continue}let l=f.sequence+1n,p=f.ttl??je,m;try{m=await this.keychain.exportKey(a.keyName)}catch(b){this.log.error("missing key %s, skipping republishing record - %e",a.keyName,b);continue}try{let b=await Cr(m,f.value,l,a.lifetime,{...e,ttlNs:p});n.push({routingKey:o,record:b})}catch(b){this.log.error("error creating updated IPNS record for %s - %e",o,b);continue}}this.log(`found ${n.length}/${i} records to republish`);for(let{routingKey:o,record:s}of n)r.add(async()=>{try{let a=nt(s);await Promise.all(this.routers.map(u=>u.put(o,a,e)))}catch(a){this.log.error("error republishing record - %e",a)}},e)}catch(n){this.log.error("error during republish - %e",n)}await r.onIdle(e)}};var On=new Float32Array([-0]),Fe=new Uint8Array(On.buffer);function xs(t,e,r){On[0]=t,e[r]=Fe[0],e[r+1]=Fe[1],e[r+2]=Fe[2],e[r+3]=Fe[3]}function ws(t,e){return Fe[0]=t[e],Fe[1]=t[e+1],Fe[2]=t[e+2],Fe[3]=t[e+3],On[0]}var zn=new Float64Array([-0]),q=new Uint8Array(zn.buffer);function bs(t,e,r){zn[0]=t,e[r]=q[0],e[r+1]=q[1],e[r+2]=q[2],e[r+3]=q[3],e[r+4]=q[4],e[r+5]=q[5],e[r+6]=q[6],e[r+7]=q[7]}function Es(t,e){return q[0]=t[e],q[1]=t[e+1],q[2]=t[e+2],q[3]=t[e+3],q[4]=t[e+4],q[5]=t[e+5],q[6]=t[e+6],q[7]=t[e+7],zn[0]}var vu=BigInt(Number.MAX_SAFE_INTEGER),Nu=BigInt(Number.MIN_SAFE_INTEGER),re=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Pe;if(e<vu&&e>Nu)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,i=e-(n<<32n);return r&&(n=~n|0n,i=~i|0n,++i>Ss&&(i=0n,++n>Ss&&(n=0n))),new t(Number(i),Number(n))}static fromNumber(e){if(e===0)return Pe;let r=e<0;r&&(e=-e);let n=e>>>0,i=(e-n)/4294967296>>>0;return r&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new t(n,i)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Pe}},Pe=new re(0,0);Pe.toBigInt=function(){return 0n};Pe.zzEncode=Pe.zzDecode=function(){return this};Pe.length=function(){return 1};var Ss=4294967296n;function Ts(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Is(t,e,r){if(r-e<1)return"";let i,o=[],s=0,a;for(;e<r;)a=t[e++],a<128?o[s++]=a:a>191&&a<224?o[s++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function qn(t,e,r){let n=r,i,o;for(let s=0;s<t.length;++s)i=t.charCodeAt(s),i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&((o=t.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128);return r-n}function le(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Lr(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Kn=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,le(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw le(this,4);return Lr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw le(this,4);return Lr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw le(this,4);let e=ws(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw le(this,4);let e=Es(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw le(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Is(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw le(this,e);this.pos+=e}else do if(this.pos>=this.len)throw le(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new re(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw le(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw le(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw le(this,8);let e=Lr(this.buf,this.pos+=4),r=Lr(this.buf,this.pos+=4);return new re(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Xt(this.buf,this.pos);return this.pos+=xe(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Lt(t){return new Kn(t instanceof Uint8Array?t:t.subarray())}function Hn(t,e,r){let n=Lt(t);return e.decode(n,void 0,r)}function Gn(t){let e=t??8192,r=e>>>1,n,i=e;return function(s){if(s<1||s>r)return H(s);i+s>e&&(n=H(e),i=0);let a=n.subarray(i,i+=s);return(i&7)!==0&&(i=(i|7)+1),a}}var $e=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function jn(){}var Xn=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Fu=Gn();function ku(t){return globalThis.Buffer!=null?H(t):Fu(t)}var Bt=class{len;head;tail;states;constructor(){this.len=0,this.head=new $e(jn,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new $e(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Wn((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Rr,10,re.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=re.fromBigInt(e);return this._push(Rr,r.length(),r)}uint64Number(e){return this._push(Yt,xe(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=re.fromBigInt(e).zzEncode();return this._push(Rr,r.length(),r)}sint64Number(e){let r=re.fromNumber(e).zzEncode();return this._push(Rr,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Yn,1,e?1:0)}fixed32(e){return this._push(Rt,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=re.fromBigInt(e);return this._push(Rt,4,r.lo)._push(Rt,4,r.hi)}fixed64Number(e){let r=re.fromNumber(e);return this._push(Rt,4,r.lo)._push(Rt,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(xs,4,e)}double(e){return this._push(bs,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Yn,1,0):this.uint32(r)._push(Uu,r,e)}string(e){let r=Ts(e);return r!==0?this.uint32(r)._push(qn,r,e):this._push(Yn,1,0)}fork(){return this.states=new Xn(this),this.head=this.tail=new $e(jn,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new $e(jn,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=ku(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Yn(t,e,r){e[r]=t&255}function Du(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Wn=class extends $e{next;constructor(e,r){super(Du,e,r),this.next=void 0}};function Rr(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function Rt(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function Uu(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Bt.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(_u,e,t),this},Bt.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Lu,e,t),this});function _u(t,e,r){e.set(t,r)}function Lu(t,e,r){t.length<40?qn(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set($(t),r)}function Jn(){return new Bt}function Qn(t,e){let r=Jn();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Zn(t,e,r){let n=Lt(t);yield*e.stream(n,void 0,"$",r)}var ei={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function ti(t,e,r,n,i){return{name:t,type:e,encode:r,decode:n,stream:i}}function ri(t,e,r){return ti("message",ei.LENGTH_DELIMITED,t,e,r)}var Mt;(function(t){let e;t.codec=()=>(e==null&&(e=ri((o,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),o.key!=null&&o.key.byteLength>0&&(s.uint32(10),s.bytes(o.key)),o.value!=null&&o.value.byteLength>0&&(s.uint32(18),s.bytes(o.value)),o.timeReceived!=null&&o.timeReceived!==""&&(s.uint32(42),s.string(o.timeReceived)),a.lengthDelimited!==!1&&s.ldelim()},(o,s,a={})=>{let u={key:Wr(0),value:Wr(0),timeReceived:""},f=s==null?o.len:o.pos+s;for(;o.pos<f;){let l=o.uint32();switch(l>>>3){case 1:{u.key=o.bytes();break}case 2:{u.value=o.bytes();break}case 5:{u.timeReceived=o.string();break}default:{o.skipType(l&7);break}}}return u},function*(o,s,a,u={}){let f=s==null?o.len:o.pos+s;for(;o.pos<f;){let l=o.uint32();switch(l>>>3){case 1:{yield{field:`${a}.key`,value:o.bytes()};break}case 2:{yield{field:`${a}.value`,value:o.bytes()};break}case 5:{yield{field:`${a}.timeReceived`,value:o.string()};break}default:{o.skipType(l&7);break}}}})),e);function r(o){return Qn(o,t.codec())}t.encode=r;function n(o,s){return Hn(o,t.codec(),s)}t.decode=n;function i(o,s){return Zn(o,t.codec(),s)}t.stream=i})(Mt||(Mt={}));function As(t){let e=t.getUTCFullYear(),r=String(t.getUTCMonth()+1).padStart(2,"0"),n=String(t.getUTCDate()).padStart(2,"0"),i=String(t.getUTCHours()).padStart(2,"0"),o=String(t.getUTCMinutes()).padStart(2,"0"),s=String(t.getUTCSeconds()).padStart(2,"0"),a=t.getUTCMilliseconds(),u=String(a*1e3*1e3).padStart(9,"0");return`${e}-${r}-${n}T${i}:${o}:${s}.${u}Z`}function vs(t){let e=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),r=String(t).trim().match(e);if(r==null)throw new Error("Invalid format");let n=parseInt(r[1],10),i=parseInt(r[2],10)-1,o=parseInt(r[3],10),s=parseInt(r[4],10),a=parseInt(r[5],10),u=parseInt(r[6],10),f=parseInt(r[7].slice(0,-6),10);return new Date(Date.UTC(n,i,o,s,a,u,f))}var ke=class t{key;value;timeReceived;constructor(e,r,n){if(!(e instanceof Uint8Array))throw new Error("key must be a Uint8Array");if(!(r instanceof Uint8Array))throw new Error("value must be a Uint8Array");this.key=e,this.value=r,this.timeReceived=n}serialize(){return Mt.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:As(this.timeReceived)}}static deserialize(e){let r=Mt.decode(e);return new t(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(e){let r=vs(e.timeReceived);if(e.key==null)throw new Error("key missing from deserialized object");if(e.value==null)throw new Error("value missing from deserialized object");return new t(e.key,e.value,r)}};var Ns;(function(t){t[t.SEND_QUERY=0]="SEND_QUERY",t[t.PEER_RESPONSE=1]="PEER_RESPONSE",t[t.FINAL_PEER=2]="FINAL_PEER",t[t.QUERY_ERROR=3]="QUERY_ERROR",t[t.PROVIDER=4]="PROVIDER",t[t.VALUE=5]="VALUE",t[t.ADD_PEER=6]="ADD_PEER",t[t.DIAL_PEER=7]="DIAL_PEER",t[t.PATH_ENDED=8]="PATH_ENDED"})(Ns||(Ns={}));var Pt;(function(t){let e;t.codec=()=>(e==null&&(e=xt((o,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),o.keyName!=null&&o.keyName!==""&&(s.uint32(10),s.string(o.keyName)),o.lifetime!=null&&o.lifetime!==0&&(s.uint32(16),s.uint32(o.lifetime)),a.lengthDelimited!==!1&&s.ldelim()},(o,s,a={})=>{let u={keyName:"",lifetime:0},f=s==null?o.len:o.pos+s;for(;o.pos<f;){let l=o.uint32();switch(l>>>3){case 1:{u.keyName=o.string();break}case 2:{u.lifetime=o.uint32();break}default:{o.skipType(l&7);break}}}return u},function*(o,s,a,u={}){let f=s==null?o.len:o.pos+s;for(;o.pos<f;){let l=o.uint32();switch(l>>>3){case 1:{yield{field:`${a}.keyName`,value:o.string()};break}case 2:{yield{field:`${a}.lifetime`,value:o.uint32()};break}default:{o.skipType(l&7);break}}}})),e);function r(o){return gt(o,t.codec())}t.encode=r;function n(o,s){return dt(o,t.codec(),s)}t.decode=n;function i(o,s){return yt(o,t.codec(),s)}t.stream=i})(Pt||(Pt={}));function Br(t,e){return{async put(r,n,i={}){try{let o=Ft(r);try{let u=await t.get(o),f=ke.deserialize(u);if(wt(f.value,n))return}catch(u){if(u.name!=="NotFoundError")throw u}let s=new ke(r,n,new Date);i.onProgress?.(new Y("ipns:routing:datastore:put"));let a=t.batch();a.put(o,s.serialize()),i.metadata!=null&&a.put(Er(r),Pt.encode(i.metadata)),await a.commit(i)}catch(o){throw i.onProgress?.(new Y("ipns:routing:datastore:error",o)),o}},async get(r,n={}){try{let i=Ft(r);n.onProgress?.(new Y("ipns:routing:datastore:get"));let o=await t.get(i,n),s=ke.deserialize(o);return{record:s.value,created:s.timeReceived}}catch(i){throw n.onProgress?.(new Y("ipns:routing:datastore:error",i)),i}},async has(r,n={}){let i=Ft(r);return t.has(i,n)},async delete(r,n){let i=Ft(r),o=t.batch();o.delete(i),o.delete(Er(r)),await o.commit(n)},async*list(r={}){try{r.onProgress?.(new Y("ipns:routing:datastore:list"));for await(let{key:n,value:i}of t.query({prefix:br},r))try{let o=ke.deserialize(i),a=n.toString().substring(br.length),u=$(a,"base32"),f=Er(u),l;try{let p=await t.get(f,r);l=Pt.decode(p)}catch(p){e.error("Error deserializing metadata for %s - %e",a,p)}yield{routingKey:u,metadata:l,record:o.value,created:o.timeReceived}}catch(o){e.error("Error deserializing record - %e",o)}}catch(n){throw r.onProgress?.(new Y("ipns:routing:datastore:error",n)),n}}}}var ni=class{routing;constructor(e){this.routing=e}async put(e,r,n={}){try{await this.routing.put(e,r,n)}catch(i){throw n.onProgress?.(new Y("ipns:routing:helia:error",i)),i}}async get(e,r={}){try{return await this.routing.get(e,r)}catch(n){throw r.onProgress?.(new Y("ipns:routing:helia:error",n)),n}}toString(){return"HeliaRouting()"}};function $t(t){return new ni(t)}var ii=class{localStore;constructor(e){this.localStore=e}async put(e,r,n){await this.localStore.put(e,r,n)}async get(e,r){let{record:n}=await this.localStore.get(e,r);return n}toString(){return"LocalStoreRouting()"}};function Mr(t){return new ii(t)}var Pr=class{routers;publisher;republisher;resolver;localStore;components;started;constructor(e,r={}){this.localStore=Br(e.datastore,e.logger.forComponent("helia:ipns:local-store")),this.components=e,this.started=!1,this.routers=[Mr(this.localStore),$t(e.routing),...r.routers??[]],this.publisher=new Ar(e,{...r,routers:this.routers,localStore:this.localStore}),this.republisher=new _r(e,{...r,routers:this.routers,localStore:this.localStore}),this.resolver=new it(e,{...r,routers:this.routers,localStore:this.localStore}),e.events.addEventListener("start",this.start.bind(this)),e.events.addEventListener("stop",this.stop.bind(this)),this.started&&this.republisher.start();for(let n of Object.values(this.components))if(Bu(n))for(let i of Object.values(n.services))Mu(i)&&(i.selectors.ipns=async(o,s)=>{let a=await Promise.all(s.map(u=>pe(o,u,this.components.keychain)));return tr(o,a)},i.validators.ipns=async(o,s)=>{let a=await pe(o,s,this.components.keychain);await Ut(a)})}start(){this.started||(this.started=!0,this.republisher.start())}stop(){this.started&&(this.started=!1,this.republisher.stop())}async publish(e,r,n={}){return this.publisher.publish(e,ns(r),n)}async*resolve(e,r={}){let{digest:n}=Dt(e);yield*this.resolver.resolve(n,r)}async unpublish(e,r){return this.publisher.unpublish(e,r)}};function Bu(t){return t?.services!=null}function Mu(t){return t?.validators!=null&&t?.selectors!=null}function Pu(t,e={}){return new Pr(t,e)}function $u(t,e={}){let r=Br(t.datastore,t.logger.forComponent("helia:ipns:local-store")),n=[Mr(r),$t(t.routing),...e.routers??[]];return new it(t,{routers:n,localStore:r})}return Rs(Vu);})();
25
14
  return HeliaIpns}));
26
15
  //# sourceMappingURL=index.min.js.map