@helia/ipns 9.2.0 → 9.2.1-17530ed8

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 (69) hide show
  1. package/README.md +21 -57
  2. package/dist/index.min.js +9 -23
  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 +62 -99
  9. package/dist/src/index.d.ts.map +1 -1
  10. package/dist/src/index.js +21 -60
  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 -22
  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 -78
  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/pb/metadata.d.ts +1 -1
  33. package/dist/src/pb/metadata.d.ts.map +1 -1
  34. package/dist/src/records.d.ts +155 -0
  35. package/dist/src/records.d.ts.map +1 -0
  36. package/dist/src/records.js +88 -0
  37. package/dist/src/records.js.map +1 -0
  38. package/dist/src/routing/pubsub.d.ts +3 -0
  39. package/dist/src/routing/pubsub.d.ts.map +1 -1
  40. package/dist/src/routing/pubsub.js +15 -10
  41. package/dist/src/routing/pubsub.js.map +1 -1
  42. package/dist/src/selector.d.ts +14 -0
  43. package/dist/src/selector.d.ts.map +1 -0
  44. package/dist/src/selector.js +47 -0
  45. package/dist/src/selector.js.map +1 -0
  46. package/dist/src/utils.d.ts +29 -2
  47. package/dist/src/utils.d.ts.map +1 -1
  48. package/dist/src/utils.js +308 -0
  49. package/dist/src/utils.js.map +1 -1
  50. package/dist/src/validator.d.ts +18 -0
  51. package/dist/src/validator.d.ts.map +1 -0
  52. package/dist/src/validator.js +58 -0
  53. package/dist/src/validator.js.map +1 -0
  54. package/package.json +32 -28
  55. package/src/errors.ts +40 -25
  56. package/src/index.ts +63 -100
  57. package/src/ipns/publisher.ts +34 -29
  58. package/src/ipns/republisher.ts +24 -13
  59. package/src/ipns/resolver.ts +40 -88
  60. package/src/ipns.ts +44 -7
  61. package/src/pb/ipns.proto +39 -0
  62. package/src/pb/ipns.ts +280 -0
  63. package/src/pb/metadata.ts +1 -1
  64. package/src/records.ts +273 -0
  65. package/src/routing/pubsub.ts +17 -10
  66. package/src/selector.ts +55 -0
  67. package/src/utils.ts +371 -2
  68. package/src/validator.ts +67 -0
  69. package/dist/typedoc-urls.json +0 -51
package/dist/index.min.js CHANGED
@@ -1,29 +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 il=Object.create;var En=Object.defineProperty;var sl=Object.getOwnPropertyDescriptor;var al=Object.getOwnPropertyNames;var cl=Object.getPrototypeOf,ul=Object.prototype.hasOwnProperty;var fl=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Et=(e,t)=>{for(var r in t)En(e,r,{get:t[r],enumerable:!0})},ca=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of al(t))!ul.call(e,o)&&o!==r&&En(e,o,{get:()=>t[o],enumerable:!(n=sl(t,o))||n.enumerable});return e};var Zo=(e,t,r)=>(r=e!=null?il(cl(e)):{},ca(t||!e||!e.__esModule?En(r,"default",{value:e,enumerable:!0}):r,e)),ll=e=>ca(En({},"__esModule",{value:!0}),e);var to=fl((Hb,As)=>{var $b=(function(){typeof As<"u"&&(As.exports=T);var e=86400,t=3200,r=146097*t/400,n=e*r,o=1e3*n,i=864e13,s=4294967296,a=1e6,c="000000000",f=Math.trunc||function(p){var m=p-p%1;return m==0&&(p<0||p===0&&1/p!=1/0)?-0:m},u=T.prototype,l=(T.fromDate=function(p){return new T(+p)},T.fromInt64BE=N(0,1,2,3,0,4),T.fromInt64LE=N(3,2,1,0,4,0),T.fromString=function(R){var m,C=new T,R=(R+="").replace(/^\s*[+\-]?\d+/,function(y){var y=+y,b=1970+(y-1970)%400;return C.year=y-b,b}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(I,y,b){return y<0&&(b*=-1),m=6e4*(60*+y+ +b),""}).replace(/\.\d+$/,function(I){return C.nano=+(I+c).substr(1,9),""}).split(/\D+/);if(1<R.length?R[1]--:R[1]=0,C.time=m=Date.UTC.apply(Date,R)-(m||0),isNaN(m))throw new TypeError("Invalid Date");return E(C)},T.fromTimeT=function(p){return B(p,0)},u.year=0,u.time=0,u.nano=0,u.addNano=function(p){return this.nano+=+p||0,this},u.getNano=function(){var p=E(this);return(p.time%1e3*a+ +p.nano+1e9)%1e9},u.getTimeT=function(){var m=E(this),p=Math.floor(m.time/1e3),m=m.year;return m&&(p+=m*r*e/t),p},u.getYear=function(){return this.toDate().getUTCFullYear()+this.year},u.toDate=function(){return w(E(this).time)},u.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},u.toString=function(p){var m=this,C=m.toDate(),R={H:function(){return F(C.getUTCHours())},L:function(){return P(C.getUTCMilliseconds(),3)},M:function(){return F(C.getUTCMinutes())},N:function(){return P(m.getNano(),9)},S:function(){return F(C.getUTCSeconds())},Y:function(){var I=m.getYear();return 999999<I?"+"+I:9999<I?"+"+P(I,6):0<=I?P(I,4):-999999<=I?"-"+P(-I,6):I},a:function(){return S[C.getUTCDay()]},b:function(){return g[C.getUTCMonth()]},d:function(){return F(C.getUTCDate())},e:function(){return(function(I){return(9<I?"":" ")+(0|I)})(C.getUTCDate())},m:function(){return F(C.getUTCMonth()+1)}};return(function I(y){return y.replace(/%./g,function(b){var v=b[1],d=x[v],v=R[v];return d?I(d):v?v():b})})(p||l)},u.writeInt64BE=A(0,1,2,3,0,4),u.writeInt64LE=A(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),g=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],S=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],x={"%":"%",F:"%Y-%m-%d",n:`
3
- `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return T;function T(p,m,C){var R=this;if(!(R instanceof T))return new T(p,m,C);R.time=+p||0,R.nano=+m||0,R.year=+C||0,E(R)}function E(p){var m,C,R,I=p.year,y=p.time,b=p.nano,d=((b<0||a<=b)&&(b-=(C=Math.floor(b/a))*a,y+=C,C=1),I%t);return(y<-i||i<y||d)&&((m=f(y/o))&&(I+=m*t,y-=m*o),(R=w(y)).setUTCFullYear(d+R.getUTCFullYear()),R=(y=+R)+(m=f((I-=d)/t))*o,m&&-i<=R&&R<=i&&(I-=m*t,y=R),C=1),C&&(p.year=I,p.time=y,p.nano=b),p}function w(p){var m=new Date(0);return m.setTime(p),m}function B(I,R){I=+I||0;var C=f((R=(R|0)*s)/n)+f(I/n),R=R%n+I%n,I=f(R/n);return I&&(C+=I,R-=I*n),new T(1e3*R,0,C*t)}function A(p,m,C,R,I,y){return function(d,v){var U=E(this);d=d||new Array(8),O(d,v|=0);var k=Math.floor(U.time/1e3),U=U.year*(r*e/t),L=f(U/s)+f(k/s),U=U%s+k%s,k=Math.floor(U/s);return k&&(L+=k,U-=k*s),b(d,v+I,L),b(d,v+y,U),d};function b(d,v,L){d[v+p]=L>>24&255,d[v+m]=L>>16&255,d[v+C]=L>>8&255,d[v+R]=255&L}}function N(p,m,C,R,I,y){return function(d,v){O(d,v|=0);var L=b(d,v+I);return B(b(d,v+y),L)};function b(d,v){return 16777216*d[v+p]+(d[v+m]<<16|d[v+C]<<8|d[v+R])}}function O(p,m){if(p=p&&p.length,p==null)throw new TypeError("Invalid Buffer");if(p<m+8)throw new RangeError("Out of range")}function F(p){return(9<p?"":"0")+(0|p)}function P(p,m){return(c+(0|p)).substr(-m)}})()});var bp={};Et(bp,{ipns:()=>yp,ipnsResolver:()=>gp,ipnsSelector:()=>_o,ipnsValidator:()=>hn});var Jt=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var rt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ge=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},Ir=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var Sn=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Xe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};function ua(e){return e==null?!1:(e.type==="RSA"||e.type==="Ed25519"||e.type==="secp256k1"||e.type==="ECDSA")&&e.raw instanceof Uint8Array&&typeof e.equals=="function"&&typeof e.toMultihash=="function"&&typeof e.toCID=="function"&&typeof e.verify=="function"}var dl=Symbol.for("@libp2p/peer-id");function An(e){return!!e?.[dl]}var vn=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){super.addEventListener(t,r,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:i})=>i!==r),this.#t.set(t,o))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var Jo={};Et(Jo,{base58btc:()=>X,base58flickr:()=>xl});var vp=new Uint8Array(0);function fa(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Qt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function la(e){return new TextEncoder().encode(e)}function da(e){return new TextDecoder().decode(e)}function hl(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=e.length,c=e.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var T=0,E=0,w=0,B=x.length;w!==B&&x[w]===0;)w++,T++;for(var A=(B-w)*u+1>>>0,N=new Uint8Array(A);w!==B;){for(var O=x[w],F=0,P=A-1;(O!==0||F<E)&&P!==-1;P--,F++)O+=256*N[P]>>>0,N[P]=O%a>>>0,O=O/a>>>0;if(O!==0)throw new Error("Non-zero carry");E=F,w++}for(var p=A-E;p!==A&&N[p]===0;)p++;for(var m=c.repeat(T);p<A;++p)m+=e.charAt(N[p]);return m}function g(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var T=0;if(x[T]!==" "){for(var E=0,w=0;x[T]===c;)E++,T++;for(var B=(x.length-T)*f+1>>>0,A=new Uint8Array(B);x[T];){var N=r[x.charCodeAt(T)];if(N===255)return;for(var O=0,F=B-1;(N!==0||O<w)&&F!==-1;F--,O++)N+=a*A[F]>>>0,A[F]=N%256>>>0,N=N/256>>>0;if(N!==0)throw new Error("Non-zero carry");w=O,T++}if(x[T]!==" "){for(var P=B-w;P!==B&&A[P]===0;)P++;for(var p=new Uint8Array(E+(B-P)),m=E;P!==B;)p[m++]=A[P++];return p}}}function S(x){var T=g(x);if(T)return T;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:g,decode:S}}var pl=hl,ml=pl,pa=ml;var Yo=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Go=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ma(this,t)}},Xo=class{decoders;constructor(t){this.decoders=t}or(t){return ma(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ma(e,t){return new Xo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Wo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Yo(t,r,n),this.decoder=new Go(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function We({name:e,prefix:t,encode:r,decode:n}){return new Wo(e,t,r,n)}function le({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=pa(r,e);return We({prefix:t,name:e,encode:n,decode:i=>Qt(o(i))})}function yl(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let f=0;f<o;++f){let u=t[e[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function gl(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],s+=8;s>r;)s-=r,i+=t[o&a>>s];if(s!==0&&(i+=t[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function bl(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function nt({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=bl(n);return We({prefix:t,name:e,encode(i){return gl(i,n,r)},decode(i){return yl(i,o,r,e)}})}var X=le({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),xl=le({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Qo={};Et(Qo,{base32:()=>de,base32hex:()=>Al,base32hexpad:()=>Il,base32hexpadupper:()=>Tl,base32hexupper:()=>vl,base32pad:()=>El,base32padupper:()=>Sl,base32upper:()=>wl,base32z:()=>Bl});var de=nt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),wl=nt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),El=nt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Sl=nt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Al=nt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),vl=nt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Il=nt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Tl=nt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Bl=nt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ti={};Et(ti,{base36:()=>Kt,base36upper:()=>_l});var Kt=le({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),_l=le({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Cl=ba,ya=128,Rl=127,Ll=~Rl,Dl=Math.pow(2,31);function ba(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Dl;)t[r++]=e&255|ya,e/=128;for(;e&Ll;)t[r++]=e&255|ya,e>>>=7;return t[r]=e|0,ba.bytes=r-n+1,t}var Nl=ei,Ul=128,ga=127;function ei(e,n){var r=0,n=n||0,o=0,i=n,s,a=e.length;do{if(i>=a)throw ei.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&ga)<<o:(s&ga)*Math.pow(2,o),o+=7}while(s>=Ul);return ei.bytes=i-n,r}var kl=Math.pow(2,7),Kl=Math.pow(2,14),Ol=Math.pow(2,21),Ml=Math.pow(2,28),Pl=Math.pow(2,35),Fl=Math.pow(2,42),Vl=Math.pow(2,49),ql=Math.pow(2,56),$l=Math.pow(2,63),Hl=function(e){return e<kl?1:e<Kl?2:e<Ol?3:e<Ml?4:e<Pl?5:e<Fl?6:e<Vl?7:e<ql?8:e<$l?9:10},zl={encode:Cl,decode:Nl,encodingLength:Hl},jl=zl,Tr=jl;function Br(e,t=0){return[Tr.decode(e,t),Tr.decode.bytes]}function Je(e,t,r=0){return Tr.encode(e,t,r),t}function Qe(e){return Tr.encodingLength(e)}function jt(e,t){let r=t.byteLength,n=Qe(e),o=n+Qe(r),i=new Uint8Array(o+r);return Je(e,i,0),Je(r,i,n),i.set(t,o),new tr(e,r,t,i)}function er(e){let t=Qt(e),[r,n]=Br(t),[o,i]=Br(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new tr(r,o,s,t)}function xa(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&fa(e.bytes,r.bytes)}}var tr=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function wa(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Yl(r,ri(e),t??X.encoder);default:return Gl(r,ri(e),t??de.encoder)}}var Ea=new WeakMap;function ri(e){let t=Ea.get(e);if(t==null){let r=new Map;return Ea.set(e,r),r}return t}var st=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==_r)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Xl)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=jt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&xa(t.multihash,n.multihash)}toString(t){return wa(this,t)}toJSON(){return{"/":wa(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new e(n,o,i,s??Sa(n,o,i.bytes))}else if(r[Wl]===!0){let{version:n,multihash:o,code:i}=r,s=er(o);return e.create(n,i,s)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==_r)throw new Error(`Version 0 CID must use dag-pb (code: ${_r}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Sa(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,_r,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Qt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new tr(r.multihashCode,r.digestSize,i,o);return[r.version===0?e.createV0(s):e.createV1(r.codec,s),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,g]=Br(t.subarray(r));return r+=g,l},o=n(),i=_r;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),f=r+c,u=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(t,r){let[n,o]=Zl(t,r),i=e.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ri(i).set(n,t),i}};function Zl(e,t){switch(e[0]){case"Q":{let r=t??X;return[X.prefix,r.decode(`${X.prefix}${e}`)]}case X.prefix:{let r=t??X;return[X.prefix,r.decode(e)]}case de.prefix:{let r=t??de;return[de.prefix,r.decode(e)]}case Kt.prefix:{let r=t??Kt;return[Kt.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function Yl(e,t,r){let{prefix:n}=r;if(n!==X.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return o}function Gl(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o}var _r=112,Xl=18;function Sa(e,t,r){let n=Qe(e),o=n+Qe(t),i=new Uint8Array(o+r.byteLength);return Je(e,i,0),Je(t,i,n),i.set(r,o),i}var Wl=Symbol.for("@ipld/js-cid/CID");var ni={};Et(ni,{identity:()=>De});var Aa=0,Jl="identity",va=Qt;function Ql(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return jt(Aa,va(e))}var De={code:Aa,name:Jl,encode:va,digest:Ql};function ot(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Nt(e=0){return new Uint8Array(e)}function at(e=0){return new Uint8Array(e)}function he(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=at(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Ta=Symbol.for("@achingbrain/uint8arraylist");function Ia(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Tn(e){return!!e?.[Ta]}var gt=class e{bufs;length;[Ta]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Tn(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Tn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Ia(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Ia(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Tn(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return he(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:he(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),i=new e;return i.length=o,i.bufs=[...n],i}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,u=r>a&&r<=c;if(f&&u){if(t===a&&r===c){n.push(s);break}let l=t-a;n.push(s.subarray(l,l+(r-t)));break}if(f){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(u){if(r===c){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Tn(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=r;l<=c;l+=u){u=0;for(let g=f;g>=0;g--){let S=this.get(l+g);if(n[g]!==S){u=Math.max(1,g-a[S]);break}}if(u===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=at(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=Nt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=Nt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=Nt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=at(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=Nt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=Nt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=Nt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=Nt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=Nt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ot(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};var oi={};Et(oi,{base10:()=>td});var td=le({prefix:"9",name:"base10",alphabet:"0123456789"});var ii={};Et(ii,{base16:()=>ed,base16upper:()=>rd});var ed=nt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),rd=nt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var si={};Et(si,{base2:()=>nd});var nd=nt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ai={};Et(ai,{base256emoji:()=>cd});var Ba=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}"),od=Ba.reduce((e,t,r)=>(e[r]=t,e),[]),id=Ba.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function sd(e){return e.reduce((t,r)=>(t+=od[r],t),"")}function ad(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=id[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var cd=We({prefix:"\u{1F680}",name:"base256emoji",encode:sd,decode:ad});var ui={};Et(ui,{base64:()=>ci,base64pad:()=>ud,base64url:()=>fd,base64urlpad:()=>ld});var ci=nt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ud=nt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),fd=nt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ld=nt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var fi={};Et(fi,{base8:()=>dd});var dd=nt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var li={};Et(li,{identity:()=>hd});var hd=We({prefix:"\0",name:"identity",encode:e=>da(e),decode:e=>la(e)});var am=new TextEncoder,cm=new TextDecoder;var pi={};Et(pi,{sha256:()=>Bn,sha512:()=>gd});var yd=20;function hi({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new di(e,t,r,n,o)}var di=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??yd,this.maxDigestLength=i}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?_a(n,this.code,r?.truncate):n.then(o=>_a(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function _a(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return jt(t,e)}function Ra(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Bn=hi({name:"sha2-256",code:18,encode:Ra("SHA-256")}),gd=hi({name:"sha2-512",code:19,encode:Ra("SHA-512")});var mi={...li,...si,...fi,...oi,...ii,...Qo,...ti,...Jo,...ui,...ai},wm={...pi,...ni};function Da(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var La=Da("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),yi=Da("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=at(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),bd={utf8:La,"utf-8":La,hex:mi.base16,latin1:yi,ascii:yi,binary:yi,...mi},_n=bd;function H(e,t="utf8"){let r=_n[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function Z(e,t="utf8"){let r=_n[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var xd=parseInt("11111",2),gi=parseInt("10000000",2),wd=parseInt("01111111",2),Na={0:Cr,1:Cr,2:Ed,3:vd,4:Id,5:Ad,6:Sd,16:Cr,22:Cr,48:Cr};function te(e,t={offset:0}){let r=e[t.offset]&xd;if(t.offset++,Na[r]!=null)return Na[r](e,t);throw new Error("No decoder for tag "+r)}function Rr(e,t){let r=0;if((e[t.offset]&gi)===gi){let n=e[t.offset]&wd,o="0x";t.offset++;for(let i=0;i<n;i++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Cr(e,t){Rr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=te(e,t);if(n===null)break;r.push(n)}return r}function Ed(e,t){let r=Rr(e,t),n=t.offset,o=t.offset+r,i=[];for(let s=n;s<o;s++)s===n&&e[s]===0||i.push(e[s]);return t.offset+=r,Uint8Array.from(i)}function Sd(e,t){let r=Rr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;t.offset<n;){let f=e[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let l=0;l<c.length;l++)u+=c[l]<<l*7;a+=`.${u}`,c=[]}}return a}function Ad(e,t){return t.offset++,null}function vd(e,t){let r=Rr(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Id(e,t){let r=Rr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Td(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new gt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Cn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Td(e.byteLength);return new gt(Uint8Array.from([t.byteLength|gi]),t)}function bt(e){let t=new gt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new gt(Uint8Array.from([2]),Cn(t),t)}function Lr(e){let t=Uint8Array.from([0]),r=new gt(t,e);return new gt(Uint8Array.from([3]),Cn(r),r)}function Ua(e){return new gt(Uint8Array.from([4]),Cn(e),e)}function Ot(e,t=48){let r=new gt;for(let n of e)r.append(n);return new gt(Uint8Array.from([t]),Cn(r),r)}async function ka(e="P-256"){let t=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:e},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",t.publicKey),privateKey:await crypto.subtle.exportKey("jwk",t.privateKey)}}async function Ka(e,t,r){let n=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["sign"]);r?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Oa(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),i}var Bd=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),_d=Uint8Array.from([6,5,43,129,4,0,34]),Cd=Uint8Array.from([6,5,43,129,4,0,35]),Rd={ext:!0,kty:"EC",crv:"P-256"},Ld={ext:!0,kty:"EC",crv:"P-384"},Dd={ext:!0,kty:"EC",crv:"P-521"},bi=32,xi=48,wi=66;function Ei(e){let t=te(e);return Ma(t)}function Ma(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===bi*2+1)return n=Z(t.subarray(r,r+bi),"base64url"),o=Z(t.subarray(r+bi),"base64url"),new Ne({...Rd,key_ops:["verify"],x:n,y:o});if(t.byteLength===xi*2+1)return n=Z(t.subarray(r,r+xi),"base64url"),o=Z(t.subarray(r+xi),"base64url"),new Ne({...Ld,key_ops:["verify"],x:n,y:o});if(t.byteLength===wi*2+1)return n=Z(t.subarray(r,r+wi),"base64url"),o=Z(t.subarray(r+wi),"base64url"),new Ne({...Dd,key_ops:["verify"],x:n,y:o});throw new rt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Pa(e){return Ot([bt(Uint8Array.from([1])),Ua(H(e.d??"","base64url")),Ot([Va(e.crv)],160),Ot([Lr(new gt(Uint8Array.from([4]),H(e.x??"","base64url"),H(e.y??"","base64url")))],161)]).subarray()}function Fa(e){return Ot([bt(Uint8Array.from([1])),Ot([Va(e.crv)],160),Ot([Lr(new gt(Uint8Array.from([4]),H(e.x??"","base64url"),H(e.y??"","base64url")))],161)]).subarray()}function Va(e){if(e==="P-256")return Bd;if(e==="P-384")return _d;if(e==="P-521")return Cd;throw new rt(`Invalid curve ${e}`)}async function qa(e="P-256"){let t=await ka(e);return new Rn(t.privateKey)}var Ne=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Fa(this.jwk)),this._raw}toMultihash(){return De.digest(pe(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}async verify(t,r,n){return Oa(this.jwk,r,t,n)}},Rn=class{type="ECDSA";jwk;publicKey;_raw;constructor(t){this.jwk=t,this.publicKey=new Ne({crv:t.crv,ext:t.ext,key_ops:["verify"],kty:"EC",x:t.x,y:t.y})}get raw(){return this._raw==null&&(this._raw=Pa(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}async sign(t,r){return Ka(this.jwk,t,r)}};function Ue(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Zt(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function $(e,t,r=""){let n=Ue(e),o=e?.length,i=t!==void 0;if(!n||i&&o!==t){let s=r&&`"${r}" `,a=i?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`;throw new Error(s+"expected Uint8Array"+a+", got "+c)}return e}function Ln(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Zt(e.outputLen),Zt(e.blockLen)}function rr(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Ha(e,t){$(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function re(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Dn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Mt(e,t){return e<<32-t|e>>>t}var za=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Nd=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ne(e){if($(e),za)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Nd[e[r]];return t}var ee={_0:48,_9:57,A:65,F:70,a:97,f:102};function $a(e){if(e>=ee._0&&e<=ee._9)return e-ee._0;if(e>=ee.A&&e<=ee.F)return e-(ee.A-10);if(e>=ee.a&&e<=ee.f)return e-(ee.a-10)}function oe(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(za)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=$a(e.charCodeAt(i)),a=$a(e.charCodeAt(i+1));if(s===void 0||a===void 0){let c=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function St(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];$(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let i=e[n];r.set(i,o),o+=i.length}return r}function Si(e,t={}){let r=(o,i)=>e(i).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function nr(e=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}var Ai=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ja(e,t,r){return e&t^~e&r}function Za(e,t,r){return e&t^e&r^t&r}var Dr=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Dn(this.buffer)}update(t){rr(this),$(t);let{view:r,buffer:n,blockLen:o}=this,i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=Dn(t);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){rr(this),Ha(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,re(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=Dn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return t.destroyed=s,t.finished=i,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},ie=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var dt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Nn=BigInt(4294967295),Ya=BigInt(32);function Ud(e,t=!1){return t?{h:Number(e&Nn),l:Number(e>>Ya&Nn)}:{h:Number(e>>Ya&Nn)|0,l:Number(e&Nn)|0}}function Ga(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let i=0;i<r;i++){let{h:s,l:a}=Ud(e[i],t);[n[i],o[i]]=[s,a]}return[n,o]}var vi=(e,t,r)=>e>>>r,Ii=(e,t,r)=>e<<32-r|t>>>r,ke=(e,t,r)=>e>>>r|t<<32-r,Ke=(e,t,r)=>e<<32-r|t>>>r,Nr=(e,t,r)=>e<<64-r|t>>>r-32,Ur=(e,t,r)=>e>>>r-32|t<<64-r;function Yt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Xa=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Wa=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Ja=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Qa=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,tc=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ec=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;var Kd=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]),me=new Uint32Array(64),Ti=class extends Dr{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[t,r,n,o,i,s,a,c]}set(t,r,n,o,i,s,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)me[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let g=me[l-15],S=me[l-2],x=Mt(g,7)^Mt(g,18)^g>>>3,T=Mt(S,17)^Mt(S,19)^S>>>10;me[l]=T+me[l-7]+x+me[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let g=Mt(a,6)^Mt(a,11)^Mt(a,25),S=u+g+ja(a,c,f)+Kd[l]+me[l]|0,T=(Mt(n,2)^Mt(n,13)^Mt(n,22))+Za(n,o,i)|0;u=f,f=c,c=a,a=s+S|0,s=i,i=o,o=n,n=S+T|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,i,s,a,c,f,u)}roundClean(){re(me)}destroy(){this.set(0,0,0,0,0,0,0,0),re(this.buffer)}},Bi=class extends Ti{A=ie[0]|0;B=ie[1]|0;C=ie[2]|0;D=ie[3]|0;E=ie[4]|0;F=ie[5]|0;G=ie[6]|0;H=ie[7]|0;constructor(){super(32)}};var rc=Ga(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Od=rc[0],Md=rc[1],ye=new Uint32Array(80),ge=new Uint32Array(80),_i=class extends Dr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:g,Gh:S,Gl:x,Hh:T,Hl:E}=this;return[t,r,n,o,i,s,a,c,f,u,l,g,S,x,T,E]}set(t,r,n,o,i,s,a,c,f,u,l,g,S,x,T,E){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=g|0,this.Gh=S|0,this.Gl=x|0,this.Hh=T|0,this.Hl=E|0}process(t,r){for(let A=0;A<16;A++,r+=4)ye[A]=t.getUint32(r),ge[A]=t.getUint32(r+=4);for(let A=16;A<80;A++){let N=ye[A-15]|0,O=ge[A-15]|0,F=ke(N,O,1)^ke(N,O,8)^vi(N,O,7),P=Ke(N,O,1)^Ke(N,O,8)^Ii(N,O,7),p=ye[A-2]|0,m=ge[A-2]|0,C=ke(p,m,19)^Nr(p,m,61)^vi(p,m,6),R=Ke(p,m,19)^Ur(p,m,61)^Ii(p,m,6),I=Ja(P,R,ge[A-7],ge[A-16]),y=Qa(I,F,C,ye[A-7],ye[A-16]);ye[A]=y|0,ge[A]=I|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:g,Fh:S,Fl:x,Gh:T,Gl:E,Hh:w,Hl:B}=this;for(let A=0;A<80;A++){let N=ke(l,g,14)^ke(l,g,18)^Nr(l,g,41),O=Ke(l,g,14)^Ke(l,g,18)^Ur(l,g,41),F=l&S^~l&T,P=g&x^~g&E,p=tc(B,O,P,Md[A],ge[A]),m=ec(p,w,N,F,Od[A],ye[A]),C=p|0,R=ke(n,o,28)^Nr(n,o,34)^Nr(n,o,39),I=Ke(n,o,28)^Ur(n,o,34)^Ur(n,o,39),y=n&i^n&a^i&a,b=o&s^o&c^s&c;w=T|0,B=E|0,T=S|0,E=x|0,S=l|0,x=g|0,{h:l,l:g}=Yt(f|0,u|0,m|0,C|0),f=a|0,u=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let d=Xa(C,I,b);n=Wa(d,m,R,y),o=d|0}({h:n,l:o}=Yt(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Yt(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Yt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=Yt(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:g}=Yt(this.Eh|0,this.El|0,l|0,g|0),{h:S,l:x}=Yt(this.Fh|0,this.Fl|0,S|0,x|0),{h:T,l:E}=Yt(this.Gh|0,this.Gl|0,T|0,E|0),{h:w,l:B}=Yt(this.Hh|0,this.Hl|0,w|0,B|0),this.set(n,o,i,s,a,c,f,u,l,g,S,x,T,E,w,B)}roundClean(){re(ye,ge)}destroy(){re(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Ci=class extends _i{Ah=dt[0]|0;Al=dt[1]|0;Bh=dt[2]|0;Bl=dt[3]|0;Ch=dt[4]|0;Cl=dt[5]|0;Dh=dt[6]|0;Dl=dt[7]|0;Eh=dt[8]|0;El=dt[9]|0;Fh=dt[10]|0;Fl=dt[11]|0;Gh=dt[12]|0;Gl=dt[13]|0;Hh=dt[14]|0;Hl=dt[15]|0;constructor(){super(64)}};var or=Si(()=>new Bi,Ai(1));var nc=Si(()=>new Ci,Ai(3));var Li=BigInt(0),Ri=BigInt(1);function se(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function oc(e){if(typeof e=="bigint"){if(!Un(e))throw new Error("positive bigint expected, got "+e)}else Zt(e);return e}function kr(e){let t=oc(e).toString(16);return t.length&1?"0"+t:t}function ic(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Li:BigInt("0x"+e)}function ir(e){return ic(ne(e))}function Oe(e){return ic(ne(Kn($(e)).reverse()))}function kn(e,t){Zt(t),e=oc(e);let r=oe(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function Di(e,t){return kn(e,t).reverse()}function Kn(e){return Uint8Array.from(e)}var Un=e=>typeof e=="bigint"&&Li<=e;function Pd(e,t,r){return Un(e)&&Un(t)&&Un(r)&&t<=e&&e<r}function Kr(e,t,r,n){if(!Pd(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ni(e){let t;for(t=0;e>Li;e>>=Ri,t+=1);return t}var Or=e=>(Ri<<BigInt(e))-Ri;function sc(e,t,r){if(Zt(e,"hashLen"),Zt(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=E=>new Uint8Array(E),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=n(e),f=n(e),u=0,l=()=>{c.fill(1),f.fill(0),u=0},g=(...E)=>r(f,St(c,...E)),S=(E=o)=>{f=g(i,E),c=g(),E.length!==0&&(f=g(s,E),c=g())},x=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let E=0,w=[];for(;E<t;){c=g();let B=c.slice();w.push(B),E+=c.length}return St(...w)};return(E,w)=>{l(),S(E);let B;for(;!(B=w(x()));)S();return l(),B}}function be(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(i,s,a){let c=e[i];if(a&&c===void 0)return;let f=typeof c;if(f!==s||c===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${f}`)}let o=(i,s)=>Object.entries(i).forEach(([a,c])=>n(a,c,s));o(t,!1),o(r,!0)}function sr(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let i=e(r,...n);return t.set(r,i),i}}var xt=BigInt(0),ct=BigInt(1),Me=BigInt(2),uc=BigInt(3),fc=BigInt(4),lc=BigInt(5),Fd=BigInt(7),dc=BigInt(8),Vd=BigInt(9),hc=BigInt(16);function it(e,t){let r=e%t;return r>=xt?r:t+r}function W(e,t,r){let n=e;for(;t-- >xt;)n*=n,n%=r;return n}function ac(e,t){if(e===xt)throw new Error("invert: expected non-zero number");if(t<=xt)throw new Error("invert: expected positive modulus, got "+t);let r=it(e,t),n=t,o=xt,i=ct,s=ct,a=xt;for(;r!==xt;){let f=n/r,u=n%r,l=o-s*f,g=i-a*f;n=r,r=u,o=s,i=a,s=l,a=g}if(n!==ct)throw new Error("invert: does not exist");return it(o,t)}function ki(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function pc(e,t){let r=(e.ORDER+ct)/fc,n=e.pow(t,r);return ki(e,n,t),n}function qd(e,t){let r=(e.ORDER-lc)/dc,n=e.mul(t,Me),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,Me),o),a=e.mul(i,e.sub(s,e.ONE));return ki(e,a,t),a}function $d(e){let t=ar(e),r=mc(e),n=r(t,t.neg(t.ONE)),o=r(t,n),i=r(t,t.neg(n)),s=(e+Fd)/hc;return(a,c)=>{let f=a.pow(c,s),u=a.mul(f,n),l=a.mul(f,o),g=a.mul(f,i),S=a.eql(a.sqr(u),c),x=a.eql(a.sqr(l),c);f=a.cmov(f,u,S),u=a.cmov(g,l,x);let T=a.eql(a.sqr(u),c),E=a.cmov(f,u,T);return ki(a,E,c),E}}function mc(e){if(e<uc)throw new Error("sqrt is not defined for small field");let t=e-ct,r=0;for(;t%Me===xt;)t/=Me,r++;let n=Me,o=ar(e);for(;cc(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return pc;let i=o.pow(n,t),s=(t+ct)/Me;return function(c,f){if(c.is0(f))return f;if(cc(c,f)!==1)throw new Error("Cannot find square root");let u=r,l=c.mul(c.ONE,i),g=c.pow(f,t),S=c.pow(f,s);for(;!c.eql(g,c.ONE);){if(c.is0(g))return c.ZERO;let x=1,T=c.sqr(g);for(;!c.eql(T,c.ONE);)if(x++,T=c.sqr(T),x===u)throw new Error("Cannot find square root");let E=ct<<BigInt(u-x-1),w=c.pow(l,E);u=x,l=c.sqr(w),g=c.mul(g,l),S=c.mul(S,w)}return S}}function Hd(e){return e%fc===uc?pc:e%dc===lc?qd:e%hc===Vd?$d(e):mc(e)}var yc=(e,t)=>(it(e,t)&ct)===ct,zd=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ki(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=zd.reduce((n,o)=>(n[o]="function",n),t);return be(e,r),e}function jd(e,t,r){if(r<xt)throw new Error("invalid exponent, negatives unsupported");if(r===xt)return e.ONE;if(r===ct)return t;let n=e.ONE,o=t;for(;r>xt;)r&ct&&(n=e.mul(n,o)),o=e.sqr(o),r>>=ct;return n}function Mr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((s,a,c)=>e.is0(a)?s:(n[c]=s,e.mul(s,a)),e.ONE),i=e.inv(o);return t.reduceRight((s,a,c)=>e.is0(a)?s:(n[c]=e.mul(s,n[c]),e.mul(s,a)),i),n}function cc(e,t){let r=(e.ORDER-ct)/Me,n=e.pow(t,r),o=e.eql(n,e.ONE),i=e.eql(n,e.ZERO),s=e.eql(n,e.neg(e.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function Zd(e,t){t!==void 0&&Zt(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var Ui=class{ORDER;BITS;BYTES;isLE;ZERO=xt;ONE=ct;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=xt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:i}=Zd(t,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=i,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return it(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return xt<=t&&t<this.ORDER}is0(t){return t===xt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&ct)===ct}neg(t){return it(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return it(t*t,this.ORDER)}add(t,r){return it(t+r,this.ORDER)}sub(t,r){return it(t-r,this.ORDER)}mul(t,r){return it(t*r,this.ORDER)}pow(t,r){return jd(this,t,r)}div(t,r){return it(t*ac(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return ac(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=Hd(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?Di(t,this.BYTES):kn(t,this.BYTES)}fromBytes(t,r=!1){$(t);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=new Uint8Array(o);f.set(t,i?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=i?Oe(t):ir(t);if(a&&(c=it(c,s)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Mr(this,t)}cmov(t,r,n){return n?r:t}};function ar(e,t={}){return new Ui(e,t)}function gc(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function Oi(e){let t=gc(e);return t+Math.ceil(t/2)}function Mi(e,t,r=!1){$(e);let n=e.length,o=gc(t),i=Oi(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Oe(e):ir(e),a=it(s,t-ct)+ct;return r?Di(a,o):kn(a,o)}var cr=BigInt(0),Pe=BigInt(1);function Pr(e,t){let r=t.negate();return e?r:t}function Fe(e,t){let r=Mr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Ec(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Pi(e,t){Ec(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,i=Or(e),s=BigInt(e);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function bc(e,t,r){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r,a=Number(e&o),c=e>>s;a>n&&(a-=i,c+=Pe);let f=t*n,u=f+Math.abs(a)-1,l=a===0,g=a<0,S=t%2!==0;return{nextN:c,offset:u,isZero:l,isNeg:g,isNegF:S,offsetF:f}}var Fi=new WeakMap,Sc=new WeakMap;function Vi(e){return Sc.get(e)||1}function xc(e){if(e!==cr)throw new Error("invalid wNAF")}var ur=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>cr;)r&Pe&&(n=n.add(o)),o=o.double(),r>>=Pe;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Pi(r,this.bits),i=[],s=t,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let f=1;f<o;f++)a=a.add(s),i.push(a);s=a.double()}return i}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=Pi(t,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:f,isZero:u,isNeg:l,isNegF:g,offsetF:S}=bc(n,a,s);n=c,u?i=i.add(Pr(g,r[S])):o=o.add(Pr(l,r[f]))}return xc(n),{p:o,f:i}}wNAFUnsafe(t,r,n,o=this.ZERO){let i=Pi(t,this.bits);for(let s=0;s<i.windows&&n!==cr;s++){let{nextN:a,offset:c,isZero:f,isNeg:u}=bc(n,s,i);if(n=a,!f){let l=r[c];o=o.add(u?l.negate():l)}}return xc(n),o}getPrecomputes(t,r,n){let o=Fi.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Fi.set(r,o))),o}cached(t,r,n){let o=Vi(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let i=Vi(t);return i===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,t,n),r,o)}createCache(t,r){Ec(r,this.bits),Sc.set(t,r),Fi.delete(t)}hasCache(t){return Vi(t)!==1}};function Ac(e,t,r,n){let o=t,i=e.ZERO,s=e.ZERO;for(;r>cr||n>cr;)r&Pe&&(i=i.add(o)),n&Pe&&(s=s.add(o)),o=o.double(),r>>=Pe,n>>=Pe;return{p1:i,p2:s}}function wc(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ki(t),t}else return ar(e,{isLE:r})}function On(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let f=t[c];if(!(typeof f=="bigint"&&f>cr))throw new Error(`CURVE.${c} must be positive bigint`)}let o=wc(t.p,r.Fp,n),i=wc(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:i}}function Mn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var xe=BigInt(0),ut=BigInt(1),qi=BigInt(2),Yd=BigInt(8);function Gd(e,t,r,n){let o=e.sqr(r),i=e.sqr(n),s=e.add(e.mul(t.a,o),i),a=e.add(e.ONE,e.mul(t.d,e.mul(o,i)));return e.eql(s,a)}function vc(e,t={}){let r=On("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s}=i;be(t,{},{uvRatio:"function"});let a=qi<<BigInt(o.BYTES*8)-ut,c=E=>n.create(E),f=t.uvRatio||((E,w)=>{try{return{isValid:!0,value:n.sqrt(n.div(E,w))}}catch{return{isValid:!1,value:xe}}});if(!Gd(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function u(E,w,B=!1){let A=B?ut:xe;return Kr("coordinate "+E,w,A,a),w}function l(E){if(!(E instanceof x))throw new Error("EdwardsPoint expected")}let g=sr((E,w)=>{let{X:B,Y:A,Z:N}=E,O=E.is0();w==null&&(w=O?Yd:n.inv(N));let F=c(B*w),P=c(A*w),p=n.mul(N,w);if(O)return{x:xe,y:ut};if(p!==ut)throw new Error("invZ was invalid");return{x:F,y:P}}),S=sr(E=>{let{a:w,d:B}=i;if(E.is0())throw new Error("bad point: ZERO");let{X:A,Y:N,Z:O,T:F}=E,P=c(A*A),p=c(N*N),m=c(O*O),C=c(m*m),R=c(P*w),I=c(m*c(R+p)),y=c(C+c(B*c(P*p)));if(I!==y)throw new Error("bad point: equation left != right (1)");let b=c(A*N),d=c(O*F);if(b!==d)throw new Error("bad point: equation left != right (2)");return!0});class x{static BASE=new x(i.Gx,i.Gy,ut,c(i.Gx*i.Gy));static ZERO=new x(xe,ut,ut,xe);static Fp=n;static Fn=o;X;Y;Z;T;constructor(w,B,A,N){this.X=u("x",w),this.Y=u("y",B),this.Z=u("z",A,!0),this.T=u("t",N),Object.freeze(this)}static CURVE(){return i}static fromAffine(w){if(w instanceof x)throw new Error("extended point not allowed");let{x:B,y:A}=w||{};return u("x",B),u("y",A),new x(B,A,ut,c(B*A))}static fromBytes(w,B=!1){let A=n.BYTES,{a:N,d:O}=i;w=Kn($(w,A,"point")),se(B,"zip215");let F=Kn(w),P=w[A-1];F[A-1]=P&-129;let p=Oe(F),m=B?a:n.ORDER;Kr("point.y",p,xe,m);let C=c(p*p),R=c(C-ut),I=c(O*C-N),{isValid:y,value:b}=f(R,I);if(!y)throw new Error("bad point: invalid y coordinate");let d=(b&ut)===ut,v=(P&128)!==0;if(!B&&b===xe&&v)throw new Error("bad point: x=0 and x_0=1");return v!==d&&(b=c(-b)),x.fromAffine({x:b,y:p})}static fromHex(w,B=!1){return x.fromBytes(oe(w),B)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(w=8,B=!0){return T.createCache(this,w),B||this.multiply(qi),this}assertValidity(){S(this)}equals(w){l(w);let{X:B,Y:A,Z:N}=this,{X:O,Y:F,Z:P}=w,p=c(B*P),m=c(O*N),C=c(A*P),R=c(F*N);return p===m&&C===R}is0(){return this.equals(x.ZERO)}negate(){return new x(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:w}=i,{X:B,Y:A,Z:N}=this,O=c(B*B),F=c(A*A),P=c(qi*c(N*N)),p=c(w*O),m=B+A,C=c(c(m*m)-O-F),R=p+F,I=R-P,y=p-F,b=c(C*I),d=c(R*y),v=c(C*y),L=c(I*R);return new x(b,d,L,v)}add(w){l(w);let{a:B,d:A}=i,{X:N,Y:O,Z:F,T:P}=this,{X:p,Y:m,Z:C,T:R}=w,I=c(N*p),y=c(O*m),b=c(P*A*R),d=c(F*C),v=c((N+O)*(p+m)-I-y),L=d-b,U=d+b,k=c(y-B*I),K=c(v*L),M=c(U*k),q=c(v*k),Q=c(L*U);return new x(K,M,Q,q)}subtract(w){return this.add(w.negate())}multiply(w){if(!o.isValidNot0(w))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:B,f:A}=T.cached(this,w,N=>Fe(x,N));return Fe(x,[B,A])[0]}multiplyUnsafe(w,B=x.ZERO){if(!o.isValid(w))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return w===xe?x.ZERO:this.is0()||w===ut?this:T.unsafe(this,w,A=>Fe(x,A),B)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return T.unsafe(this,i.n).is0()}toAffine(w){return g(this,w)}clearCofactor(){return s===ut?this:this.multiplyUnsafe(s)}toBytes(){let{x:w,y:B}=this.toAffine(),A=n.toBytes(B);return A[A.length-1]|=w&ut?128:0,A}toHex(){return ne(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let T=new ur(x,o.BITS);return x.BASE.precompute(8),x}function Ic(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');be(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:i,Fn:s}=e,a=r.randomBytes||nr,c=r.adjustScalarBytes||(p=>p),f=r.domain||((p,m,C)=>{if(se(C,"phflag"),m.length||C)throw new Error("Contexts/pre-hash are not supported");return p});function u(p){return s.create(Oe(p))}function l(p){let m=A.secretKey;$(p,A.secretKey,"secretKey");let C=$(t(p),2*m,"hashedSecretKey"),R=c(C.slice(0,m)),I=C.slice(m,2*m),y=u(R);return{head:R,prefix:I,scalar:y}}function g(p){let{head:m,prefix:C,scalar:R}=l(p),I=o.multiply(R),y=I.toBytes();return{head:m,prefix:C,scalar:R,point:I,pointBytes:y}}function S(p){return g(p).pointBytes}function x(p=Uint8Array.of(),...m){let C=St(...m);return u(t(f(C,$(p,void 0,"context"),!!n)))}function T(p,m,C={}){p=$(p,void 0,"message"),n&&(p=n(p));let{prefix:R,scalar:I,pointBytes:y}=g(m),b=x(C.context,R,p),d=o.multiply(b).toBytes(),v=x(C.context,d,y,p),L=s.create(b+v*I);if(!s.isValid(L))throw new Error("sign failed: invalid s");let U=St(d,s.toBytes(L));return $(U,A.signature,"result")}let E={zip215:!0};function w(p,m,C,R=E){let{context:I,zip215:y}=R,b=A.signature;p=$(p,b,"signature"),m=$(m,void 0,"message"),C=$(C,A.publicKey,"publicKey"),y!==void 0&&se(y,"zip215"),n&&(m=n(m));let d=b/2,v=p.subarray(0,d),L=Oe(p.subarray(d,b)),U,k,K;try{U=e.fromBytes(C,y),k=e.fromBytes(v,y),K=o.multiplyUnsafe(L)}catch{return!1}if(!y&&U.isSmallOrder())return!1;let M=x(I,k.toBytes(),U.toBytes(),m);return k.add(U.multiplyUnsafe(M)).subtract(K).clearCofactor().is0()}let B=i.BYTES,A={secretKey:B,publicKey:B,signature:2*B,seed:B};function N(p=a(A.seed)){return $(p,A.seed,"seed")}function O(p){return Ue(p)&&p.length===s.BYTES}function F(p,m){try{return!!e.fromBytes(p,m)}catch{return!1}}let P={getExtendedPublicKey:g,randomSecretKey:N,isValidSecretKey:O,isValidPublicKey:F,toMontgomery(p){let{y:m}=e.fromBytes(p),C=A.publicKey,R=C===32;if(!R&&C!==57)throw new Error("only defined for 25519 and 448");let I=R?i.div(ut+m,ut-m):i.div(m-ut,m+ut);return i.toBytes(I)},toMontgomerySecret(p){let m=A.secretKey;$(p,m);let C=t(p.subarray(0,m));return c(C).subarray(0,m)}};return Object.freeze({keygen:Mn(N,S),getPublicKey:S,sign:T,verify:w,utils:P,Point:e,lengths:A})}var Xd=BigInt(1),Tc=BigInt(2);var Wd=BigInt(5),Jd=BigInt(8),$i=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Qd={p:$i,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Jd,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function th(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=$i,a=e*e%i*e%i,c=W(a,Tc,i)*a%i,f=W(c,Xd,i)*e%i,u=W(f,Wd,i)*f%i,l=W(u,t,i)*u%i,g=W(l,r,i)*l%i,S=W(g,n,i)*g%i,x=W(S,o,i)*S%i,T=W(x,o,i)*S%i,E=W(T,t,i)*u%i;return{pow_p_5_8:W(E,Tc,i)*e%i,b2:a}}function eh(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Bc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function rh(e,t){let r=$i,n=it(t*t*t,r),o=it(n*n*t,r),i=th(e*o).pow_p_5_8,s=it(e*n*i,r),a=it(t*s*s,r),c=s,f=it(s*Bc,r),u=a===e,l=a===it(-e,r),g=a===it(-e*Bc,r);return u&&(s=c),(l||g)&&(s=f),yc(s,r)&&(s=it(-s,r)),{isValid:u||l,value:s}}var nh=vc(Qd,{uvRatio:rh});function oh(e){return Ic(nh,nc,Object.assign({adjustScalarBytes:eh},e))}var Fr=oh({});var Vr=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},qr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Pn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var _c={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Pn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var At=_c;var Fn=32,$r=64,Hi=32;var fr,Cc=(async()=>{try{return await At.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function Rc(){let e=Fr.utils.randomSecretKey(),t=Fr.getPublicKey(e);return{privateKey:uh(e,t),publicKey:t}}async function ih(e,t){let r;e.length===$r?r=e.subarray(0,32):r=e;let n={crv:"Ed25519",kty:"OKP",x:Z(e.subarray(32),"base64url"),d:Z(r,"base64url"),ext:!0,key_ops:["sign"]},o=await At.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),i=await At.get().subtle.sign({name:"Ed25519"},o,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(i,0,i.byteLength)}function sh(e,t){let r=e.subarray(0,Hi);return Fr.sign(t instanceof Uint8Array?t:t.subarray(),r)}async function Lc(e,t){return fr==null&&(fr=await Cc),fr?ih(e,t):sh(e,t)}async function ah(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await At.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await At.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function ch(e,t,r){return Fr.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Dc(e,t,r){return fr==null&&(fr=await Cc),fr?ah(e,t,r):ch(e,t,r)}function uh(e,t){let r=new Uint8Array($r);for(let n=0;n<Hi;n++)r[n]=e[n],r[Hi+n]=t[n];return r}function lr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Hr=class{type="Ed25519";raw;constructor(t){this.raw=qn(t,Fn)}toMultihash(){return De.digest(pe(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Dc(this.raw,r,t);return lr(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}},Vn=class{type="Ed25519";raw;publicKey;constructor(t,r){this.raw=qn(t,$r),this.publicKey=new Hr(r)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}sign(t,r){r?.signal?.throwIfAborted();let n=Lc(this.raw,t);return lr(n)?n.then(o=>(r?.signal?.throwIfAborted(),o)):(r?.signal?.throwIfAborted(),n)}};function zi(e){return e=qn(e,Fn),new Hr(e)}async function Uc(){let{privateKey:e,publicKey:t}=Rc();return new Vn(e,t)}function qn(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new rt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var fh=Math.pow(2,7),lh=Math.pow(2,14),dh=Math.pow(2,21),kc=Math.pow(2,28),Kc=Math.pow(2,35),Oc=Math.pow(2,42),Mc=Math.pow(2,49),wt=128,we=127;function ae(e){if(e<fh)return 1;if(e<lh)return 2;if(e<dh)return 3;if(e<kc)return 4;if(e<Kc)return 5;if(e<Oc)return 6;if(e<Mc)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function $n(e,t,r=0){switch(ae(e)){case 8:t[r++]=e&255|wt,e/=128;case 7:t[r++]=e&255|wt,e/=128;case 6:t[r++]=e&255|wt,e/=128;case 5:t[r++]=e&255|wt,e/=128;case 4:t[r++]=e&255|wt,e>>>=7;case 3:t[r++]=e&255|wt,e>>>=7;case 2:t[r++]=e&255|wt,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Hn(e,t){let r=e[t],n=0;if(n+=r&we,r<wt||(r=e[t+1],n+=(r&we)<<7,r<wt)||(r=e[t+2],n+=(r&we)<<14,r<wt)||(r=e[t+3],n+=(r&we)<<21,r<wt)||(r=e[t+4],n+=(r&we)*kc,r<wt)||(r=e[t+5],n+=(r&we)*Kc,r<wt)||(r=e[t+6],n+=(r&we)*Oc,r<wt)||(r=e[t+7],n+=(r&we)*Mc,r<wt))return n;throw new RangeError("Could not decode varint")}var ji=new Float32Array([-0]),Ee=new Uint8Array(ji.buffer);function Pc(e,t,r){ji[0]=e,t[r]=Ee[0],t[r+1]=Ee[1],t[r+2]=Ee[2],t[r+3]=Ee[3]}function Fc(e,t){return Ee[0]=e[t],Ee[1]=e[t+1],Ee[2]=e[t+2],Ee[3]=e[t+3],ji[0]}var Zi=new Float64Array([-0]),mt=new Uint8Array(Zi.buffer);function Vc(e,t,r){Zi[0]=e,t[r]=mt[0],t[r+1]=mt[1],t[r+2]=mt[2],t[r+3]=mt[3],t[r+4]=mt[4],t[r+5]=mt[5],t[r+6]=mt[6],t[r+7]=mt[7]}function qc(e,t){return mt[0]=e[t],mt[1]=e[t+1],mt[2]=e[t+2],mt[3]=e[t+3],mt[4]=e[t+4],mt[5]=e[t+5],mt[6]=e[t+6],mt[7]=e[t+7],Zi[0]}var hh=BigInt(Number.MAX_SAFE_INTEGER),ph=BigInt(Number.MIN_SAFE_INTEGER),Tt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Ve;if(t<hh&&t>ph)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>$c&&(o=0n,++n>$c&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ve;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):Ve}},Ve=new Tt(0,0);Ve.toBigInt=function(){return 0n};Ve.zzEncode=Ve.zzDecode=function(){return this};Ve.length=function(){return 1};var $c=4294967296n;function Hc(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function zc(e,t,r){if(r-t<1)return"";let o,i=[],s=0,a;for(;t<r;)a=e[t++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Yi(e,t,r){let n=r,o,i;for(let s=0;s<e.length;++s)o=e.charCodeAt(s),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((i=e.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Pt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function zn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Gi=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Pt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Pt(this,4);return zn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Pt(this,4);return zn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Pt(this,4);let t=Fc(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Pt(this,4);let t=qc(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Pt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return zc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Pt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Pt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Tt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Pt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Pt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Pt(this,8);let t=zn(this.buf,this.pos+=4),r=zn(this.buf,this.pos+=4);return new Tt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Hn(this.buf,this.pos);return this.pos+=ae(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function zr(e){return new Gi(e instanceof Uint8Array?e:e.subarray())}function Se(e,t,r){let n=zr(e);return t.decode(n,void 0,r)}function Xi(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return at(s);o+s>t&&(n=at(t),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var qe=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Wi(){}var Qi=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},mh=Xi();function yh(e){return globalThis.Buffer!=null?at(e):mh(e)}var Zr=class{len;head;tail;states;constructor(){this.len=0,this.head=new qe(Wi,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new qe(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ts((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(jn,10,Tt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Tt.fromBigInt(t);return this._push(jn,r.length(),r)}uint64Number(t){return this._push($n,ae(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=Tt.fromBigInt(t).zzEncode();return this._push(jn,r.length(),r)}sint64Number(t){let r=Tt.fromNumber(t).zzEncode();return this._push(jn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ji,1,t?1:0)}fixed32(t){return this._push(jr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Tt.fromBigInt(t);return this._push(jr,4,r.lo)._push(jr,4,r.hi)}fixed64Number(t){let r=Tt.fromNumber(t);return this._push(jr,4,r.lo)._push(jr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Pc,4,t)}double(t){return this._push(Vc,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Ji,1,0):this.uint32(r)._push(bh,r,t)}string(t){let r=Hc(t);return r!==0?this.uint32(r)._push(Yi,r,t):this._push(Ji,1,0)}fork(){return this.states=new Qi(this),this.head=this.tail=new qe(Wi,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 qe(Wi,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=yh(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Ji(e,t,r){t[r]=e&255}function gh(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var ts=class extends qe{next;constructor(t,r){super(gh,t,r),this.next=void 0}};function jn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function jr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function bh(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Zr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(xh,t,e),this},Zr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(wh,t,e),this});function xh(e,t,r){t.set(e,r)}function wh(e,t,r){e.length<40?Yi(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(H(e),r)}function es(){return new Zr}function Ae(e,t){let r=es();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*ve(e,t,r){let n=zr(e);yield*t.stream(n,void 0,"$",r)}var Zn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Yn(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function rs(e){function t(i){if(e[i.toString()]==null)throw new Error("Invalid enum value");return e[i]}let r=function(s,a){let c=t(s);a.int32(c)},n=function(s){let a=s.int32();return t(a)},o=function*(s){let a=s.int32();yield t(a)};return Yn("enum",Zn.VARINT,r,n,o)}function Ie(e,t,r){return Yn("message",Zn.LENGTH_DELIMITED,e,t,r)}var J;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(J||(J={}));var ns;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(ns||(ns={}));(function(e){e.codec=()=>rs(ns)})(J||(J={}));var Gt;(function(e){let t;e.codec=()=>(t==null&&(t=Ie((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),J.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={},f=s==null?i.len:i.pos+s;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{c.Type=J.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(u&7);break}}}return c},function*(i,s,a,c={}){let f=s==null?i.len:i.pos+s;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:J.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(u&7);break}}}})),t);function r(i){return Ae(i,e.codec())}e.encode=r;function n(i,s){return Se(i,e.codec(),s)}e.decode=n;function o(i,s){return ve(i,e.codec(),s)}e.stream=o})(Gt||(Gt={}));var os;(function(e){let t;e.codec=()=>(t==null&&(t=Ie((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),J.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={},f=s==null?i.len:i.pos+s;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{c.Type=J.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(u&7);break}}}return c},function*(i,s,a,c={}){let f=s==null?i.len:i.pos+s;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:J.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(u&7);break}}}})),t);function r(i){return Ae(i,e.codec())}e.encode=r;function n(i,s){return Se(i,e.codec(),s)}e.decode=n;function o(i,s){return ve(i,e.codec(),s)}e.stream=o})(os||(os={}));var Gr={};Et(Gr,{MAX_RSA_KEY_SIZE:()=>is,generateRSAKeyPair:()=>ps,jwkToJWKKeyPair:()=>Wc,jwkToPkcs1:()=>vh,jwkToPkix:()=>us,jwkToRSAPrivateKey:()=>hs,pkcs1MessageToJwk:()=>as,pkcs1MessageToRSAPrivateKey:()=>fs,pkcs1ToJwk:()=>Ah,pkcs1ToRSAPrivateKey:()=>Xc,pkixMessageToJwk:()=>cs,pkixMessageToRSAPublicKey:()=>ds,pkixToJwk:()=>Ih,pkixToRSAPublicKey:()=>ls});var dr=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Gr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return st.createV1(114,this._multihash)}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}verify(t,r,n){return Gc(this.jwk,r,t,n)}},Yr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Gr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}sign(t,r){return Yc(this.jwk,t,r)}};var is=8192,ss=18,Eh=1062,Sh=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Ah(e){let t=te(e);return as(t)}function as(e){return{n:Z(e[1],"base64url"),e:Z(e[2],"base64url"),d:Z(e[3],"base64url"),p:Z(e[4],"base64url"),q:Z(e[5],"base64url"),dp:Z(e[6],"base64url"),dq:Z(e[7],"base64url"),qi:Z(e[8],"base64url"),kty:"RSA"}}function vh(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new rt("JWK was missing components");return Ot([bt(Uint8Array.from([0])),bt(H(e.n,"base64url")),bt(H(e.e,"base64url")),bt(H(e.d,"base64url")),bt(H(e.p,"base64url")),bt(H(e.q,"base64url")),bt(H(e.dp,"base64url")),bt(H(e.dq,"base64url")),bt(H(e.qi,"base64url"))]).subarray()}function Ih(e){let t=te(e,{offset:0});return cs(t)}function cs(e){let t=te(e[1],{offset:0});return{kty:"RSA",n:Z(t[0],"base64url"),e:Z(t[1],"base64url")}}function us(e){if(e.n==null||e.e==null)throw new rt("JWK was missing components");return Ot([Sh,Lr(Ot([bt(H(e.n,"base64url")),bt(H(e.e,"base64url"))]))]).subarray()}function Xc(e){let t=te(e);return fs(t)}function fs(e){let t=as(e);return hs(t)}function ls(e,t){if(e.byteLength>=Eh)throw new Ge("Key size is too large");let r=te(e,{offset:0});return ds(r,e,t)}function ds(e,t,r){let n=cs(e);if(r==null){let o=or(Gt.encode({Type:J.RSA,Data:t}));r=jt(ss,o)}return new dr(n,r)}function hs(e){if(Qc(e)>is)throw new rt("Key size is too large");let t=Wc(e),r=or(Gt.encode({Type:J.RSA,Data:us(t.publicKey)})),n=jt(ss,r);return new Yr(t.privateKey,new dr(t.publicKey,n))}async function ps(e){if(e>is)throw new rt("Key size is too large");let t=await Jc(e),r=or(Gt.encode({Type:J.RSA,Data:us(t.publicKey)})),n=jt(ss,r);return new Yr(t.privateKey,new dr(t.publicKey,n))}function Wc(e){if(e==null)throw new rt("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Jc(e,t){let r=await At.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Th(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Yc(e,t,r){let n=await At.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await At.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Gc(e,t,r,n){let o=await At.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await At.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),i}async function Th(e,t){if(e.privateKey==null||e.publicKey==null)throw new rt("Private and public key are required");let r=await Promise.all([At.get().subtle.exportKey("jwk",e.privateKey),At.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Qc(e){if(e.kty!=="RSA")throw new rt("invalid key type");if(e.n==null)throw new rt("invalid key modulus");return H(e.n,"base64url").length*8}var Gn=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(Ln(t),$(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),re(o)}update(t){return rr(this),this.iHash.update(t),this}digestInto(t){rr(this),$(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=i,t.blockLen=s,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ms=(e,t,r)=>new Gn(e,t).update(r).digest();ms.create=(e,t)=>new Gn(e,t);var tu=(e,t)=>(e+(e>=0?t:-t)/eu)/t;function Bh(e,t,r){let[[n,o],[i,s]]=t,a=tu(s*e,r),c=tu(-o*e,r),f=e-a*n-c*i,u=-a*o-c*s,l=f<ce,g=u<ce;l&&(f=-f),g&&(u=-u);let S=Or(Math.ceil(Ni(r)/2))+hr;if(f<ce||f>=S||u<ce||u>=S)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:f,k2neg:g,k2:u}}function gs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function ys(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return se(r.lowS,"lowS"),se(r.prehash,"prehash"),r.format!==void 0&&gs(r.format),r}var bs=class extends Error{constructor(t=""){super(t)}},Te={Err:bs,_tlv:{encode:(e,t)=>{let{Err:r}=Te;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=kr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?kr(o.length/2|128):"";return kr(e)+i+o+t},decode(e,t){let{Err:r}=Te,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)s=s<<8|u;if(n+=c,s<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+s)}}},_int:{encode(e){let{Err:t}=Te;if(e<ce)throw new t("integer: negative integers are not allowed");let r=kr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Te;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return ir(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Te,o=$(e,void 0,"signature"),{v:i,l:s}=n.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:f,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=Te,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),i=n+o;return t.encode(48,i)}},ce=BigInt(0),hr=BigInt(1),eu=BigInt(2),Xn=BigInt(3),_h=BigInt(4);function ru(e,t={}){let r=On("weierstrass",e,t),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s,n:a}=i;be(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=t;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=ou(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(I,y,b){let{x:d,y:v}=y.toAffine(),L=n.toBytes(d);if(se(b,"isCompressed"),b){u();let U=!n.isOdd(v);return St(nu(U),L)}else return St(Uint8Array.of(4),L,n.toBytes(v))}function g(I){$(I,void 0,"Point");let{publicKey:y,publicKeyUncompressed:b}=f,d=I.length,v=I[0],L=I.subarray(1);if(d===y&&(v===2||v===3)){let U=n.fromBytes(L);if(!n.isValid(U))throw new Error("bad point: is not on curve, wrong x");let k=T(U),K;try{K=n.sqrt(k)}catch(Q){let G=Q instanceof Error?": "+Q.message:"";throw new Error("bad point: is not on curve, sqrt error"+G)}u();let M=n.isOdd(K);return(v&1)===1!==M&&(K=n.neg(K)),{x:U,y:K}}else if(d===b&&v===4){let U=n.BYTES,k=n.fromBytes(L.subarray(0,U)),K=n.fromBytes(L.subarray(U,U*2));if(!E(k,K))throw new Error("bad point: is not on curve");return{x:k,y:K}}else throw new Error(`bad point: got length ${d}, expected compressed=${y} or uncompressed=${b}`)}let S=t.toBytes||l,x=t.fromBytes||g;function T(I){let y=n.sqr(I),b=n.mul(y,I);return n.add(n.add(b,n.mul(I,i.a)),i.b)}function E(I,y){let b=n.sqr(y),d=T(I);return n.eql(b,d)}if(!E(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let w=n.mul(n.pow(i.a,Xn),_h),B=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(w,B)))throw new Error("bad curve params: a or b");function A(I,y,b=!1){if(!n.isValid(y)||b&&n.is0(y))throw new Error(`bad point coordinate ${I}`);return y}function N(I){if(!(I instanceof m))throw new Error("Weierstrass Point expected")}function O(I){if(!c||!c.basises)throw new Error("no endo");return Bh(I,c.basises,o.ORDER)}let F=sr((I,y)=>{let{X:b,Y:d,Z:v}=I;if(n.eql(v,n.ONE))return{x:b,y:d};let L=I.is0();y==null&&(y=L?n.ONE:n.inv(v));let U=n.mul(b,y),k=n.mul(d,y),K=n.mul(v,y);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(K,n.ONE))throw new Error("invZ was invalid");return{x:U,y:k}}),P=sr(I=>{if(I.is0()){if(t.allowInfinityPoint&&!n.is0(I.Y))return;throw new Error("bad point: ZERO")}let{x:y,y:b}=I.toAffine();if(!n.isValid(y)||!n.isValid(b))throw new Error("bad point: x or y not field elements");if(!E(y,b))throw new Error("bad point: equation left != right");if(!I.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function p(I,y,b,d,v){return b=new m(n.mul(b.X,I),b.Y,b.Z),y=Pr(d,y),b=Pr(v,b),y.add(b)}class m{static BASE=new m(i.Gx,i.Gy,n.ONE);static ZERO=new m(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(y,b,d){this.X=A("x",y),this.Y=A("y",b,!0),this.Z=A("z",d),Object.freeze(this)}static CURVE(){return i}static fromAffine(y){let{x:b,y:d}=y||{};if(!y||!n.isValid(b)||!n.isValid(d))throw new Error("invalid affine point");if(y instanceof m)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(d)?m.ZERO:new m(b,d,n.ONE)}static fromBytes(y){let b=m.fromAffine(x($(y,void 0,"point")));return b.assertValidity(),b}static fromHex(y){return m.fromBytes(oe(y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,b=!0){return R.createCache(this,y),b||this.multiply(Xn),this}assertValidity(){P(this)}hasEvenY(){let{y}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(y)}equals(y){N(y);let{X:b,Y:d,Z:v}=this,{X:L,Y:U,Z:k}=y,K=n.eql(n.mul(b,k),n.mul(L,v)),M=n.eql(n.mul(d,k),n.mul(U,v));return K&&M}negate(){return new m(this.X,n.neg(this.Y),this.Z)}double(){let{a:y,b}=i,d=n.mul(b,Xn),{X:v,Y:L,Z:U}=this,k=n.ZERO,K=n.ZERO,M=n.ZERO,q=n.mul(v,v),Q=n.mul(L,L),G=n.mul(U,U),z=n.mul(v,L);return z=n.add(z,z),M=n.mul(v,U),M=n.add(M,M),k=n.mul(y,M),K=n.mul(d,G),K=n.add(k,K),k=n.sub(Q,K),K=n.add(Q,K),K=n.mul(k,K),k=n.mul(z,k),M=n.mul(d,M),G=n.mul(y,G),z=n.sub(q,G),z=n.mul(y,z),z=n.add(z,M),M=n.add(q,q),q=n.add(M,q),q=n.add(q,G),q=n.mul(q,z),K=n.add(K,q),G=n.mul(L,U),G=n.add(G,G),q=n.mul(G,z),k=n.sub(k,q),M=n.mul(G,Q),M=n.add(M,M),M=n.add(M,M),new m(k,K,M)}add(y){N(y);let{X:b,Y:d,Z:v}=this,{X:L,Y:U,Z:k}=y,K=n.ZERO,M=n.ZERO,q=n.ZERO,Q=i.a,G=n.mul(i.b,Xn),z=n.mul(b,L),tt=n.mul(d,U),lt=n.mul(v,k),zt=n.add(b,d),et=n.add(L,U);zt=n.mul(zt,et),et=n.add(z,tt),zt=n.sub(zt,et),et=n.add(b,v);let pt=n.add(L,k);return et=n.mul(et,pt),pt=n.add(z,lt),et=n.sub(et,pt),pt=n.add(d,v),K=n.add(U,k),pt=n.mul(pt,K),K=n.add(tt,lt),pt=n.sub(pt,K),q=n.mul(Q,et),K=n.mul(G,lt),q=n.add(K,q),K=n.sub(tt,q),q=n.add(tt,q),M=n.mul(K,q),tt=n.add(z,z),tt=n.add(tt,z),lt=n.mul(Q,lt),et=n.mul(G,et),tt=n.add(tt,lt),lt=n.sub(z,lt),lt=n.mul(Q,lt),et=n.add(et,lt),z=n.mul(tt,et),M=n.add(M,z),z=n.mul(pt,et),K=n.mul(zt,K),K=n.sub(K,z),z=n.mul(zt,tt),q=n.mul(pt,q),q=n.add(q,z),new m(K,M,q)}subtract(y){return this.add(y.negate())}is0(){return this.equals(m.ZERO)}multiply(y){let{endo:b}=t;if(!o.isValidNot0(y))throw new Error("invalid scalar: out of range");let d,v,L=U=>R.cached(this,U,k=>Fe(m,k));if(b){let{k1neg:U,k1:k,k2neg:K,k2:M}=O(y),{p:q,f:Q}=L(k),{p:G,f:z}=L(M);v=Q.add(z),d=p(b.beta,q,G,U,K)}else{let{p:U,f:k}=L(y);d=U,v=k}return Fe(m,[d,v])[0]}multiplyUnsafe(y){let{endo:b}=t,d=this;if(!o.isValid(y))throw new Error("invalid scalar: out of range");if(y===ce||d.is0())return m.ZERO;if(y===hr)return d;if(R.hasCache(this))return this.multiply(y);if(b){let{k1neg:v,k1:L,k2neg:U,k2:k}=O(y),{p1:K,p2:M}=Ac(m,d,L,k);return p(b.beta,K,M,v,U)}else return R.unsafe(d,y)}toAffine(y){return F(this,y)}isTorsionFree(){let{isTorsionFree:y}=t;return s===hr?!0:y?y(m,this):R.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:y}=t;return s===hr?this:y?y(m,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(y=!0){return se(y,"isCompressed"),this.assertValidity(),S(m,this,y)}toHex(y=!0){return ne(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let C=o.BITS,R=new ur(m,t.endo?Math.ceil(C/2):C);return m.BASE.precompute(8),m}function nu(e){return Uint8Array.of(e?2:3)}function ou(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Ch(e,t={}){let{Fn:r}=e,n=t.randomBytes||nr,o=Object.assign(ou(e.Fp,r),{seed:Oi(r.ORDER)});function i(S){try{let x=r.fromBytes(S);return r.isValidNot0(x)}catch{return!1}}function s(S,x){let{publicKey:T,publicKeyUncompressed:E}=o;try{let w=S.length;return x===!0&&w!==T||x===!1&&w!==E?!1:!!e.fromBytes(S)}catch{return!1}}function a(S=n(o.seed)){return Mi($(S,o.seed,"seed"),r.ORDER)}function c(S,x=!0){return e.BASE.multiply(r.fromBytes(S)).toBytes(x)}function f(S){let{secretKey:x,publicKey:T,publicKeyUncompressed:E}=o;if(!Ue(S)||"_lengths"in r&&r._lengths||x===T)return;let w=$(S,void 0,"key").length;return w===T||w===E}function u(S,x,T=!0){if(f(S)===!0)throw new Error("first arg must be private key");if(f(x)===!1)throw new Error("second arg must be public key");let E=r.fromBytes(S);return e.fromBytes(x).multiply(E).toBytes(T)}let l={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},g=Mn(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:g,Point:e,utils:l,lengths:o})}function iu(e,t,r={}){Ln(t),be(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||nr,o=r.hmac||((b,d)=>ms(t,b,d)),{Fp:i,Fn:s}=e,{ORDER:a,BITS:c}=s,{keygen:f,getPublicKey:u,getSharedSecret:l,utils:g,lengths:S}=Ch(e,r),x={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},T=a*eu<i.ORDER;function E(b){let d=a>>hr;return b>d}function w(b,d){if(!s.isValidNot0(d))throw new Error(`invalid signature ${b}: out of range 1..Point.Fn.ORDER`);return d}function B(){if(T)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function A(b,d){gs(d);let v=S.signature,L=d==="compact"?v:d==="recovered"?v+1:void 0;return $(b,L)}class N{r;s;recovery;constructor(d,v,L){if(this.r=w("r",d),this.s=w("s",v),L!=null){if(B(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(d,v=x.format){A(d,v);let L;if(v==="der"){let{r:M,s:q}=Te.toSig($(d));return new N(M,q)}v==="recovered"&&(L=d[0],v="compact",d=d.subarray(1));let U=S.signature/2,k=d.subarray(0,U),K=d.subarray(U,U*2);return new N(s.fromBytes(k),s.fromBytes(K),L)}static fromHex(d,v){return this.fromBytes(oe(d),v)}assertRecovery(){let{recovery:d}=this;if(d==null)throw new Error("invalid recovery id: must be present");return d}addRecoveryBit(d){return new N(this.r,this.s,d)}recoverPublicKey(d){let{r:v,s:L}=this,U=this.assertRecovery(),k=U===2||U===3?v+a:v;if(!i.isValid(k))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let K=i.toBytes(k),M=e.fromBytes(St(nu((U&1)===0),K)),q=s.inv(k),Q=F($(d,void 0,"msgHash")),G=s.create(-Q*q),z=s.create(L*q),tt=e.BASE.multiplyUnsafe(G).add(M.multiplyUnsafe(z));if(tt.is0())throw new Error("invalid recovery: point at infinify");return tt.assertValidity(),tt}hasHighS(){return E(this.s)}toBytes(d=x.format){if(gs(d),d==="der")return oe(Te.hexFromSig(this));let{r:v,s:L}=this,U=s.toBytes(v),k=s.toBytes(L);return d==="recovered"?(B(),St(Uint8Array.of(this.assertRecovery()),U,k)):St(U,k)}toHex(d){return ne(this.toBytes(d))}}let O=r.bits2int||function(d){if(d.length>8192)throw new Error("input is too large");let v=ir(d),L=d.length*8-c;return L>0?v>>BigInt(L):v},F=r.bits2int_modN||function(d){return s.create(O(d))},P=Or(c);function p(b){return Kr("num < 2^"+c,b,ce,P),s.toBytes(b)}function m(b,d){return $(b,void 0,"message"),d?$(t(b),void 0,"prehashed message"):b}function C(b,d,v){let{lowS:L,prehash:U,extraEntropy:k}=ys(v,x);b=m(b,U);let K=F(b),M=s.fromBytes(d);if(!s.isValidNot0(M))throw new Error("invalid private key");let q=[p(M),p(K)];if(k!=null&&k!==!1){let tt=k===!0?n(S.secretKey):k;q.push($(tt,void 0,"extraEntropy"))}let Q=St(...q),G=K;function z(tt){let lt=O(tt);if(!s.isValidNot0(lt))return;let zt=s.inv(lt),et=e.BASE.multiply(lt).toAffine(),pt=s.create(et.x);if(pt===ce)return;let wn=s.create(zt*s.create(G+pt*M));if(wn===ce)return;let sa=(et.x===pt?0:2)|Number(et.y&hr),aa=wn;return L&&E(wn)&&(aa=s.neg(wn),sa^=1),new N(pt,aa,T?void 0:sa)}return{seed:Q,k2sig:z}}function R(b,d,v={}){let{seed:L,k2sig:U}=C(b,d,v);return sc(t.outputLen,s.BYTES,o)(L,U).toBytes(v.format)}function I(b,d,v,L={}){let{lowS:U,prehash:k,format:K}=ys(L,x);if(v=$(v,void 0,"publicKey"),d=m(d,k),!Ue(b)){let M=b instanceof N?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+M)}A(b,K);try{let M=N.fromBytes(b,K),q=e.fromBytes(v);if(U&&M.hasHighS())return!1;let{r:Q,s:G}=M,z=F(d),tt=s.inv(G),lt=s.create(z*tt),zt=s.create(Q*tt),et=e.BASE.multiplyUnsafe(lt).add(q.multiplyUnsafe(zt));return et.is0()?!1:s.create(et.x)===Q}catch{return!1}}function y(b,d,v={}){let{prehash:L}=ys(v,x);return d=m(d,L),N.fromBytes(b,"recovered").recoverPublicKey(d).toBytes()}return Object.freeze({keygen:f,getPublicKey:u,getSharedSecret:l,utils:g,lengths:S,Point:e,sign:R,verify:I,recoverPublicKey:y,Signature:N,hash:t})}var ws={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Rh={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var su=BigInt(2);function Lh(e){let t=ws.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=e*e*e%t,u=f*f*e%t,l=W(u,r,t)*u%t,g=W(l,r,t)*u%t,S=W(g,su,t)*f%t,x=W(S,o,t)*S%t,T=W(x,i,t)*x%t,E=W(T,a,t)*T%t,w=W(E,c,t)*E%t,B=W(w,a,t)*T%t,A=W(B,r,t)*u%t,N=W(A,s,t)*x%t,O=W(N,n,t)*f%t,F=W(O,su,t);if(!xs.eql(xs.sqr(F),e))throw new Error("Cannot find square root");return F}var xs=ar(ws.p,{sqrt:Lh}),Dh=ru(ws,{Fp:xs,endo:Rh}),Ft=iu(Dh,or);function au(e,t,r){let n=Bn.digest(t instanceof Uint8Array?t:t.subarray());if(lr(n))return n.then(({digest:o})=>(r?.signal?.throwIfAborted(),Ft.sign(o,e,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new Vr(String(o))});try{return Ft.sign(n.digest,e,{prehash:!1,format:"der"})}catch(o){throw new Vr(String(o))}}function cu(e,t,r,n){let o=Bn.digest(r instanceof Uint8Array?r:r.subarray());if(lr(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Ft.verify(t,i,e,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new qr(String(i))});try{return n?.signal?.throwIfAborted(),Ft.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(i){throw new qr(String(i))}}var Xr=class{type="secp256k1";raw;_key;constructor(t){this._key=lu(t),this.raw=uu(this._key)}toMultihash(){return De.digest(pe(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}verify(t,r,n){return cu(this._key,r,t,n)}},Wn=class{type="secp256k1";raw;publicKey;constructor(t,r){this.raw=fu(t),this.publicKey=new Xr(r??du(t))}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}sign(t,r){return au(this.raw,t,r)}};function Es(e){return new Xr(e)}async function hu(){let e=Nh();return new Wn(e)}function uu(e){return Ft.Point.fromBytes(e).toBytes()}function fu(e){try{return Ft.getPublicKey(e,!0),e}catch(t){throw new Ir(String(t))}}function lu(e){try{return Ft.Point.fromBytes(e),e}catch(t){throw new Ge(String(t))}}function du(e){try{return Ft.getPublicKey(e,!0)}catch(t){throw new Ir(String(t))}}function Nh(){return Ft.utils.randomSecretKey()}async function pu(e,t){if(e==="Ed25519")return Uc();if(e==="secp256k1")return hu();if(e==="RSA")return ps(Uh(t));if(e==="ECDSA")return qa(kh(t));throw new Xe}function mu(e,t){let{Type:r,Data:n}=Gt.decode(e),o=n??new Uint8Array;switch(r){case J.RSA:return ls(o,t);case J.Ed25519:return zi(o);case J.secp256k1:return Es(o);case J.ECDSA:return Ei(o);default:throw new Xe}}function yu(e){let{Type:t,Data:r}=Gt.decode(e.digest),n=r??new Uint8Array;switch(t){case J.Ed25519:return zi(n);case J.secp256k1:return Es(n);case J.ECDSA:return Ei(n);default:throw new Xe}}function pe(e){return Gt.encode({Type:J[e.type],Data:e.raw})}function Uh(e){return e==null?2048:parseInt(e,10)}function kh(e){if(e==="P-256"||e==null)return"P-256";if(e==="P-384")return"P-384";if(e==="P-521")return"P-521";throw new rt("Unsupported curve, should be P-256, P-384 or P-521")}function Kh(e,t){if(typeof e=="string")return Oh(e);if(typeof e=="number")return Fh(e,t);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(e)}`)}var Jn=Kh;function Oh(e){if(typeof e!="string"||e.length===0||e.length>100)throw Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(e)}`);let t=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(e);if(!t?.groups)return NaN;let{value:r,unit:n="ms"}=t.groups,o=parseFloat(r),i=n.toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw Error(`Unknown unit "${i}" provided to ms.parse(). value=${JSON.stringify(e)}`)}}function Mh(e){let t=Math.abs(e);return t>=315576e5?`${Math.round(e/315576e5)}y`:t>=26298e5?`${Math.round(e/26298e5)}mo`:t>=6048e5?`${Math.round(e/6048e5)}w`:t>=864e5?`${Math.round(e/864e5)}d`:t>=36e5?`${Math.round(e/36e5)}h`:t>=6e4?`${Math.round(e/6e4)}m`:t>=1e3?`${Math.round(e/1e3)}s`:`${e}ms`}function Ph(e){let t=Math.abs(e);return t>=315576e5?$e(e,t,315576e5,"year"):t>=26298e5?$e(e,t,26298e5,"month"):t>=6048e5?$e(e,t,6048e5,"week"):t>=864e5?$e(e,t,864e5,"day"):t>=36e5?$e(e,t,36e5,"hour"):t>=6e4?$e(e,t,6e4,"minute"):t>=1e3?$e(e,t,1e3,"second"):`${e} ms`}function Fh(e,t){if(typeof e!="number"||!Number.isFinite(e))throw Error("Value provided to ms.format() must be of type number.");return t?.long?Ph(e):Mh(e)}function $e(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function Ss(e){r.debug=r,r.default=r,r.coerce=c,r.disable=i,r.enable=o,r.enabled=s,r.humanize=Jn,r.destroy=f,Object.keys(e).forEach(u=>{r[u]=e[u]}),r.names=[],r.skips=[],r.formatters={};function t(u){let l=0;for(let g=0;g<u.length;g++)l=(l<<5)-l+u.charCodeAt(g),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=t;function r(u,l){let g,S=null,x,T;function E(...w){if(!E.enabled)return;let B=E,A=Number(new Date),N=A-(g||A);B.diff=N,B.prev=g,B.curr=A,g=A,w[0]=r.coerce(w[0]),typeof w[0]!="string"&&w.unshift("%O");let O=0;w[0]=w[0].replace(/%([a-zA-Z%])/g,(P,p)=>{if(P==="%%")return"%";O++;let m=r.formatters[p];if(typeof m=="function"){let C=w[O];P=m.call(B,C),w.splice(O,1),O--}return P}),r.formatArgs.call(B,w),l?.onLog!=null&&l.onLog(...w),(B.log||r.log).apply(B,w)}return E.namespace=u,E.useColors=r.useColors(),E.color=r.selectColor(u),E.extend=n,E.destroy=r.destroy,Object.defineProperty(E,"enabled",{enumerable:!0,configurable:!1,get:()=>S!==null?S:(x!==r.namespaces&&(x=r.namespaces,T=r.enabled(u)),T),set:w=>{S=w}}),typeof r.init=="function"&&r.init(E),E}function n(u,l){let g=r(this.namespace+(typeof l>"u"?":":l)+u);return g.log=this.log,g}function o(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];let l,g=(typeof u=="string"?u:"").split(/[\s,]+/),S=g.length;for(l=0;l<S;l++)g[l]&&(u=g[l].replace(/\*/g,".*?"),u[0]==="-"?r.skips.push(new RegExp("^"+u.substr(1)+"$")):r.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...r.names.map(a),...r.skips.map(a).map(l=>"-"+l)].join(",");return r.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let l,g;for(l=0,g=r.skips.length;l<g;l++)if(r.skips[l].test(u))return!1;for(l=0,g=r.names.length;l<g;l++)if(r.names[l].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function c(u){return u instanceof Error?u.stack??u.message:u}function f(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var Qn=Zh(),Vh=["#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 qh(){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 $h(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+Jn(this.diff),!this.useColors)return;let t="color: "+this.color;e.splice(1,0,t,"color: inherit");let r=0,n=0;e[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(r++,o==="%c"&&(n=r))}),e.splice(n,0,t)}var Hh=console.debug??console.log??(()=>{});function zh(e){try{e?Qn?.setItem("debug",e):Qn?.removeItem("debug")}catch{}}function jh(){let e;try{e=Qn?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function Zh(){try{return localStorage}catch{}}function Yh(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var gu=Ss({formatArgs:$h,save:zh,load:jh,useColors:qh,setupFormatters:Yh,colors:Vh,storage:Qn,log:Hh});var vt=gu;vt.formatters.b=e=>e==null?"undefined":X.baseEncode(e);vt.formatters.t=e=>e==null?"undefined":de.baseEncode(e);vt.formatters.m=e=>e==null?"undefined":ci.baseEncode(e);vt.formatters.p=e=>e==null?"undefined":e.toString();vt.formatters.c=e=>e==null?"undefined":e.toString();vt.formatters.k=e=>e==null?"undefined":e.toString();vt.formatters.a=e=>e==null?"undefined":e.toString();function bu(e,t=""){let r=xu(e.message),n=xu(e.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
2
+ "use strict";var HeliaIpns=(()=>{var Yi=Object.create;var Ut=Object.defineProperty;var Xi=Object.getOwnPropertyDescriptor;var Ji=Object.getOwnPropertyNames;var Wi=Object.getPrototypeOf,Qi=Object.prototype.hasOwnProperty;var Zi=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},Y=(t,e)=>{for(var r in e)Ut(t,r,{get:e[r],enumerable:!0})},Fn=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ji(e))!Qi.call(t,o)&&o!==r&&Ut(t,o,{get:()=>e[o],enumerable:!(n=Xi(e,o))||n.enumerable});return t};var Ir=(t,e,r)=>(r=t!=null?Yi(Wi(t)):{},Fn(e||!t||!t.__esModule?Ut(r,"default",{value:t,enumerable:!0}):r,t)),es=t=>Fn(Ut({},"__esModule",{value:!0}),t);var Pt=Zi((bu,Br)=>{var xu=(function(){typeof Br<"u"&&(Br.exports=E);var t=86400,e=3200,r=146097*e/400,n=t*r,o=1e3*n,i=864e13,s=4294967296,a=1e6,u="000000000",f=Math.trunc||function(g){var b=g-g%1;return b==0&&(g<0||g===0&&1/g!=1/0)?-0:b},l=E.prototype,p=(E.fromDate=function(g){return new E(+g)},E.fromInt64BE=P(0,1,2,3,0,4),E.fromInt64LE=P(3,2,1,0,4,0),E.fromString=function(C){var b,I=new E,C=(C+="").replace(/^\s*[+\-]?\d+/,function(D){var D=+D,M=1970+(D-1970)%400;return I.year=D-M,M}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(v,D,M){return D<0&&(M*=-1),b=6e4*(60*+D+ +M),""}).replace(/\.\d+$/,function(v){return I.nano=+(v+u).substr(1,9),""}).split(/\D+/);if(1<C.length?C[1]--:C[1]=0,I.time=b=Date.UTC.apply(Date,C)-(b||0),isNaN(b))throw new TypeError("Invalid Date");return x(I)},E.fromTimeT=function(g){return k(g,0)},l.year=0,l.time=0,l.nano=0,l.addNano=function(g){return this.nano+=+g||0,this},l.getNano=function(){var g=x(this);return(g.time%1e3*a+ +g.nano+1e9)%1e9},l.getTimeT=function(){var b=x(this),g=Math.floor(b.time/1e3),b=b.year;return b&&(g+=b*r*t/e),g},l.getYear=function(){return this.toDate().getUTCFullYear()+this.year},l.toDate=function(){return T(x(this).time)},l.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},l.toString=function(g){var b=this,I=b.toDate(),C={H:function(){return q(I.getUTCHours())},L:function(){return R(I.getUTCMilliseconds(),3)},M:function(){return q(I.getUTCMinutes())},N:function(){return R(b.getNano(),9)},S:function(){return q(I.getUTCSeconds())},Y:function(){var v=b.getYear();return 999999<v?"+"+v:9999<v?"+"+R(v,6):0<=v?R(v,4):-999999<=v?"-"+R(-v,6):v},a:function(){return w[I.getUTCDay()]},b:function(){return m[I.getUTCMonth()]},d:function(){return q(I.getUTCDate())},e:function(){return(function(v){return(9<v?"":" ")+(0|v)})(I.getUTCDate())},m:function(){return q(I.getUTCMonth()+1)}};return(function v(D){return D.replace(/%./g,function(M){var L=M[1],N=S[L],L=C[L];return N?v(N):L?L():M})})(g||p)},l.writeInt64BE=F(0,1,2,3,0,4),l.writeInt64LE=F(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),m=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],w=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],S={"%":"%",F:"%Y-%m-%d",n:`
3
+ `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return E;function E(g,b,I){var C=this;if(!(C instanceof E))return new E(g,b,I);C.time=+g||0,C.nano=+b||0,C.year=+I||0,x(C)}function x(g){var b,I,C,v=g.year,D=g.time,M=g.nano,N=((M<0||a<=M)&&(M-=(I=Math.floor(M/a))*a,D+=I,I=1),v%e);return(D<-i||i<D||N)&&((b=f(D/o))&&(v+=b*e,D-=b*o),(C=T(D)).setUTCFullYear(N+C.getUTCFullYear()),C=(D=+C)+(b=f((v-=N)/e))*o,b&&-i<=C&&C<=i&&(v-=b*e,D=C),I=1),I&&(g.year=v,g.time=D,g.nano=M),g}function T(g){var b=new Date(0);return b.setTime(g),b}function k(v,C){v=+v||0;var I=f((C=(C|0)*s)/n)+f(v/n),C=C%n+v%n,v=f(C/n);return v&&(I+=v,C-=v*n),new E(1e3*C,0,I*e)}function F(g,b,I,C,v,D){return function(N,L){var he=x(this);N=N||new Array(8),B(N,L|=0);var Me=Math.floor(he.time/1e3),he=he.year*(r*t/e),de=f(he/s)+f(Me/s),he=he%s+Me%s,Me=Math.floor(he/s);return Me&&(de+=Me,he-=Me*s),M(N,L+v,de),M(N,L+D,he),N};function M(N,L,de){N[L+g]=de>>24&255,N[L+b]=de>>16&255,N[L+I]=de>>8&255,N[L+C]=255&de}}function P(g,b,I,C,v,D){return function(N,L){B(N,L|=0);var de=M(N,L+v);return k(M(N,L+D),de)};function M(N,L){return 16777216*N[L+g]+(N[L+b]<<16|N[L+I]<<8|N[L+C])}}function B(g,b){if(g=g&&g.length,g==null)throw new TypeError("Invalid Buffer");if(g<b+8)throw new RangeError("Out of range")}function q(g){return(9<g?"":"0")+(0|g)}function R(g,b){return(u+(0|g)).substr(-b)}})()});var Wc={};Y(Wc,{ipns:()=>Xc,ipnsResolver:()=>Jc});var Ur={};Y(Ur,{base32:()=>be,base32hex:()=>fs,base32hexpad:()=>hs,base32hexpadupper:()=>ps,base32hexupper:()=>ds,base32pad:()=>us,base32padupper:()=>ls,base32upper:()=>cs,base32z:()=>ms});var Zc=new Uint8Array(0);function Un(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function pe(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Ie(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Ie(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Dn(t){return new TextEncoder().encode(t)}function Ln(t){return new TextDecoder().decode(t)}function ts(t){return t?.buffer instanceof ArrayBuffer}function Ie(t){return ts(t)?t:t.slice()}function rs(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=t.length,u=t.charAt(0),f=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function p(S){if(S instanceof Uint8Array||(ArrayBuffer.isView(S)?S=new Uint8Array(S.buffer,S.byteOffset,S.byteLength):Array.isArray(S)&&(S=Uint8Array.from(S))),!(S instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(S.length===0)return"";for(var E=0,x=0,T=0,k=S.length;T!==k&&S[T]===0;)T++,E++;for(var F=(k-T)*l+1>>>0,P=new Uint8Array(F);T!==k;){for(var B=S[T],q=0,R=F-1;(B!==0||q<x)&&R!==-1;R--,q++)B+=256*P[R]>>>0,P[R]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");x=q,T++}for(var g=F-x;g!==F&&P[g]===0;)g++;for(var b=u.repeat(E);g<F;++g)b+=t.charAt(P[g]);return b}function m(S){if(typeof S!="string")throw new TypeError("Expected String");if(S.length===0)return new Uint8Array;var E=0;if(S[E]!==" "){for(var x=0,T=0;S[E]===u;)x++,E++;for(var k=(S.length-E)*f+1>>>0,F=new Uint8Array(k);S[E];){var P=r[S.charCodeAt(E)];if(P===255)return;for(var B=0,q=k-1;(P!==0||B<T)&&q!==-1;q--,B++)P+=a*F[q]>>>0,F[q]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");T=B,E++}if(S[E]!==" "){for(var R=k-T;R!==k&&F[R]===0;)R++;for(var g=new Uint8Array(x+(k-R)),b=x;R!==k;)g[b++]=F[R++];return g}}}function w(S){var E=m(S);if(E)return E;throw new Error(`Non-${e} character`)}return{encode:p,decodeUnsafe:m,decode:w}}var ns=rs,os=ns,Rn=os;var Ar=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Nr=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Bn(this,e)}},kr=class{decoders;constructor(e){this.decoders=e}or(e){return Bn(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Bn(t,e){return new kr({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Fr=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Ar(e,r,n),this.decoder=new Nr(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Pe({name:t,prefix:e,encode:r,decode:n}){return new Fr(t,e,r,n)}function xe({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Rn(r,t);return Pe({prefix:e,name:t,encode:n,decode:i=>pe(o(i))})}function is(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,u=0;for(let f=0;f<o;++f){let l=e[t[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|l,s+=r,s>=8&&(s-=8,i[u++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function ss(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let u=0;u<t.length;++u)for(a=a<<8|t[u],s+=8;s>r;)s-=r,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function as(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function _({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=as(n);return Pe({prefix:e,name:t,encode(i){return ss(i,n,r)},decode(i){return is(i,o,r,t)}})}var be=_({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),cs=_({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),us=_({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ls=_({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),fs=_({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ds=_({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),hs=_({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ps=_({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ms=_({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Dr={};Y(Dr,{base36:()=>ee,base36upper:()=>gs});var ee=xe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),gs=xe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Lr={};Y(Lr,{base58btc:()=>H,base58flickr:()=>ys});var H=xe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ys=xe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var xs=$n,Mn=128,bs=127,ws=~bs,Es=Math.pow(2,31);function $n(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Es;)e[r++]=t&255|Mn,t/=128;for(;t&ws;)e[r++]=t&255|Mn,t>>>=7;return e[r]=t|0,$n.bytes=r-n+1,e}var Ss=_r,Ts=128,Pn=127;function _r(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw _r.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&Pn)<<o:(s&Pn)*Math.pow(2,o),o+=7}while(s>=Ts);return _r.bytes=i-n,r}var vs=Math.pow(2,7),Cs=Math.pow(2,14),Is=Math.pow(2,21),As=Math.pow(2,28),Ns=Math.pow(2,35),ks=Math.pow(2,42),Fs=Math.pow(2,49),Us=Math.pow(2,56),Ds=Math.pow(2,63),Ls=function(t){return t<vs?1:t<Cs?2:t<Is?3:t<As?4:t<Ns?5:t<ks?6:t<Fs?7:t<Us?8:t<Ds?9:10},_s={encode:xs,decode:Ss,encodingLength:Ls},Rs=_s,ot=Rs;function it(t,e=0){return[ot.decode(t,e),ot.decode.bytes]}function $e(t,e,r=0){return ot.encode(t,e,r),e}function Ve(t){return ot.encodingLength(t)}function ze(t,e){let r=e.byteLength,n=Ve(t),o=n+Ve(r),i=new Uint8Array(o+r);return $e(t,i,0),$e(r,i,n),i.set(e,o),new Oe(t,r,e,i)}function st(t){let e=pe(t),[r,n]=it(e),[o,i]=it(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Oe(r,o,s,e)}function Vn(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Un(t.bytes,r.bytes)}}var Oe=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=Ie(n),this.bytes=Ie(o)}};function On(t,e){let{bytes:r,version:n}=t;return n===0?Ms(r,Rr(t),e??H.encoder):Ps(r,Rr(t),e??be.encoder)}var zn=new WeakMap;function Rr(t){let e=zn.get(t);if(e==null){let r=new Map;return zn.set(t,r),r}return e}var ae=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=Ie(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==at)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==$s)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=ze(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&Vn(e.multihash,n.multihash)}toString(e){return On(this,e)}toJSON(){return{"/":On(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new t(n,o,i,s??qn(n,o,i.bytes))}else if(r[Vs]===!0){let{version:n,multihash:o,code:i}=r,s=st(o);return t.create(n,i,s)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==at)throw new Error(`Version 0 CID must use dag-pb (code: ${at}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=qn(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,at,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=pe(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new Oe(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[p,m]=it(e.subarray(r));return r+=m,p},o=n(),i=at;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),u=n(),f=r+u,l=f-s;return{version:o,codec:i,multihashCode:a,digestSize:u,multihashSize:l,size:f}}static parse(e,r){let[n,o]=Bs(e,r),i=t.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Rr(i).set(n,e),i}};function Bs(t,e){switch(t[0]){case"Q":{let r=e??H;return[H.prefix,r.decode(`${H.prefix}${t}`)]}case H.prefix:{let r=e??H;return[H.prefix,r.decode(t)]}case be.prefix:{let r=e??be;return[be.prefix,r.decode(t)]}case ee.prefix:{let r=e??ee;return[ee.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Ms(t,e,r){let{prefix:n}=r;if(n!==H.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let i=r.encode(t).slice(1);return e.set(n,i),i}else return o}function Ps(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let i=r.encode(t);return e.set(n,i),i}else return o}var at=112,$s=18;function qn(t,e,r){let n=Ve(t),o=n+Ve(e),i=new Uint8Array(o+r.byteLength);return $e(t,i,0),$e(e,i,n),i.set(r,o),i}var Vs=Symbol.for("@ipld/js-cid/CID");var Ke=BigInt(6e4)*5000000n,Kn=5;var Lt=class extends Error{static name="RecordsFailedValidationError";name="RecordsFailedValidationError"};var He=class extends Error{static name="InvalidValueError";name="InvalidValueError"};var ct=class extends Error{static name="RecordNotFoundError";name="RecordNotFoundError"},_t=class extends Error{static name="SignatureCreationError";name="SignatureCreationError"},ne=class extends Error{static name="SignatureVerificationError";name="SignatureVerificationError"},Rt=class extends Error{static name="RecordExpiredError";name="RecordExpiredError"},Ae=class extends Error{static name="UnsupportedValidityError";name="UnsupportedValidityError"},Bt=class extends Error{static name="RecordTooLargeError";name="RecordTooLargeError"},Mt=class extends Error{static name="InvalidRecordDataError";name="InvalidRecordDataError"},je=class extends Error{static name="InvalidEmbeddedPublicKeyError";name="InvalidEmbeddedPublicKeyError"};var ln=Ir(Pt(),1);function Mr(t=0){return new Uint8Array(t)}function ce(t=0){return new Uint8Array(t)}var Os=Math.pow(2,7),zs=Math.pow(2,14),qs=Math.pow(2,21),Hn=Math.pow(2,28),jn=Math.pow(2,35),Gn=Math.pow(2,42),Yn=Math.pow(2,49),K=128,we=127;function ut(t){if(t<Os)return 1;if(t<zs)return 2;if(t<qs)return 3;if(t<Hn)return 4;if(t<jn)return 5;if(t<Gn)return 6;if(t<Yn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Xn(t,e,r=0){switch(ut(t)){case 8:e[r++]=t&255|K,t/=128;case 7:e[r++]=t&255|K,t/=128;case 6:e[r++]=t&255|K,t/=128;case 5:e[r++]=t&255|K,t/=128;case 4:e[r++]=t&255|K,t>>>=7;case 3:e[r++]=t&255|K,t>>>=7;case 2:e[r++]=t&255|K,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Jn(t,e){let r=t[e],n=0;if(n+=r&we,r<K||(r=t[e+1],n+=(r&we)<<7,r<K)||(r=t[e+2],n+=(r&we)<<14,r<K)||(r=t[e+3],n+=(r&we)<<21,r<K)||(r=t[e+4],n+=(r&we)*Hn,r<K)||(r=t[e+5],n+=(r&we)*jn,r<K)||(r=t[e+6],n+=(r&we)*Gn,r<K)||(r=t[e+7],n+=(r&we)*Yn,r<K))return n;throw new RangeError("Could not decode varint")}function Ks(t){return t.buffer instanceof ArrayBuffer}function Wn(t){return Ks(t)?t:t.slice()}var Pr=new Float32Array([-0]),Ee=new Uint8Array(Pr.buffer);function Qn(t,e,r){Pr[0]=t,e[r]=Ee[0],e[r+1]=Ee[1],e[r+2]=Ee[2],e[r+3]=Ee[3]}function Zn(t,e){return Ee[0]=t[e],Ee[1]=t[e+1],Ee[2]=t[e+2],Ee[3]=t[e+3],Pr[0]}var $r=new Float64Array([-0]),O=new Uint8Array($r.buffer);function eo(t,e,r){$r[0]=t,e[r]=O[0],e[r+1]=O[1],e[r+2]=O[2],e[r+3]=O[3],e[r+4]=O[4],e[r+5]=O[5],e[r+6]=O[6],e[r+7]=O[7]}function to(t,e){return O[0]=t[e],O[1]=t[e+1],O[2]=t[e+2],O[3]=t[e+3],O[4]=t[e+4],O[5]=t[e+5],O[6]=t[e+6],O[7]=t[e+7],$r[0]}var Hs=BigInt(Number.MAX_SAFE_INTEGER),js=BigInt(Number.MIN_SAFE_INTEGER),X=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Ne;if(e<Hs&&e>js)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>ro&&(o=0n,++n>ro&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Ne;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Ne}},Ne=new X(0,0);Ne.toBigInt=function(){return 0n};Ne.zzEncode=Ne.zzDecode=function(){return this};Ne.length=function(){return 1};var ro=4294967296n;function no(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function oo(t,e,r){if(r-e<1)return"";let o,i=[],s=0,a;for(;e<r;)a=t[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Vr(t,e,r){let n=r,o,i;for(let s=0;s<t.length;++s)o=t.charCodeAt(s),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((i=t.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function oe(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function $t(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Or=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Wn(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,oe(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw oe(this,4);return $t(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw oe(this,4);return $t(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw oe(this,4);let e=Zn(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw oe(this,4);let e=to(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw oe(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return oo(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw oe(this,e);this.pos+=e}else do if(this.pos>=this.len)throw oe(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new X(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw oe(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw oe(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw oe(this,8);let e=$t(this.buf,this.pos+=4),r=$t(this.buf,this.pos+=4);return new X(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Jn(this.buf,this.pos);return this.pos+=ut(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function lt(t){return new Or(t instanceof Uint8Array?t:t.subarray())}function ke(t,e,r){let n=lt(t);return e.decode(n,void 0,r)}var zr={};Y(zr,{base10:()=>Gs});var Gs=xe({prefix:"9",name:"base10",alphabet:"0123456789"});var qr={};Y(qr,{base16:()=>Ys,base16upper:()=>Xs});var Ys=_({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Xs=_({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Kr={};Y(Kr,{base2:()=>Js});var Js=_({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Hr={};Y(Hr,{base256emoji:()=>ta});var so=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Ws=so.reduce((t,e,r)=>(t[r]=e,t),[]),Qs=so.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Zs(t){return t.reduce((e,r)=>(e+=Ws[r],e),"")}function ea(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Qs[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var ta=Pe({prefix:"\u{1F680}",name:"base256emoji",encode:Zs,decode:ea});var Gr={};Y(Gr,{base64:()=>jr,base64pad:()=>ra,base64url:()=>na,base64urlpad:()=>oa});var jr=_({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ra=_({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),na=_({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),oa=_({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Yr={};Y(Yr,{base8:()=>ia});var ia=_({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Xr={};Y(Xr,{identity:()=>sa});var sa=Pe({prefix:"\0",name:"identity",encode:t=>Ln(t),decode:t=>Dn(t)});var Ou=new TextEncoder,zu=new TextDecoder;var Jr={};Y(Jr,{identity:()=>fa});var ao=0,ua="identity",co=pe;function la(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return ze(ao,co(t))}var fa={code:ao,name:ua,encode:co,digest:la};var Zr={};Y(Zr,{sha256:()=>ha,sha512:()=>pa});var da=20;function Qr({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Wr(t,e,r,n,o)}var Wr=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??da,this.maxDigestLength=i}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?uo(n,this.code,r?.truncate):n.then(o=>uo(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function uo(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return ze(e,t)}function fo(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var ha=Qr({name:"sha2-256",code:18,encode:fo("SHA-256")}),pa=Qr({name:"sha2-512",code:19,encode:fo("SHA-512")});var en={...Xr,...Kr,...Yr,...zr,...qr,...Ur,...Dr,...Lr,...Gr,...Hr},tl={...Zr,...Jr};function po(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var ho=po("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),tn=po("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=ce(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),ma={utf8:ho,"utf-8":ho,hex:en.base16,latin1:tn,ascii:tn,binary:tn,...en},Vt=ma;function z(t,e="utf8"){let r=Vt[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function rn(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return ce(s);o+s>e&&(n=ce(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Fe=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function nn(){}var sn=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},ga=rn();function ya(t){return globalThis.Buffer!=null?ce(t):ga(t)}var dt=class{len;head;tail;states;constructor(){this.len=0,this.head=new Fe(nn,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Fe(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new an((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Ot,10,X.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=X.fromBigInt(e);return this._push(Ot,r.length(),r)}uint64Number(e){return this._push(Xn,ut(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=X.fromBigInt(e).zzEncode();return this._push(Ot,r.length(),r)}sint64Number(e){let r=X.fromNumber(e).zzEncode();return this._push(Ot,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(on,1,e?1:0)}fixed32(e){return this._push(ft,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=X.fromBigInt(e);return this._push(ft,4,r.lo)._push(ft,4,r.hi)}fixed64Number(e){let r=X.fromNumber(e);return this._push(ft,4,r.lo)._push(ft,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Qn,4,e)}double(e){return this._push(eo,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(on,1,0):this.uint32(r)._push(ba,r,e)}string(e){let r=no(e);return r!==0?this.uint32(r)._push(Vr,r,e):this._push(on,1,0)}fork(){return this.states=new sn(this),this.head=this.tail=new Fe(nn,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Fe(nn,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=ya(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function on(t,e,r){e[r]=t&255}function xa(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var an=class extends Fe{next;constructor(e,r){super(xa,e,r),this.next=void 0}};function Ot(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function ft(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function ba(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(dt.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(wa,e,t),this},dt.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Ea,e,t),this});function wa(t,e,r){e.set(t,r)}function Ea(t,e,r){t.length<40?Vr(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(z(t),r)}function cn(){return new dt}function Ue(t,e){let r=cn();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*De(t,e,r){let n=lt(t);yield*e.stream(n,void 0,"$",r)}var zt={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function qt(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function un(t){function e(i){if(t[i.toString()]==null)throw new Error("Invalid enum value");return t[i]}let r=function(s,a){let u=e(s);a.int32(u)},n=function(s){let a=s.int32();return e(a)},o=function*(s){let a=s.int32();yield e(a)};return qt("enum",zt.VARINT,r,n,o)}function Le(t,e,r){return qt("message",zt.LENGTH_DELIMITED,t,e,r)}var V;(function(t){let e;(function(a){a.EOL="EOL"})(e=t.ValidityType||(t.ValidityType={}));let r;(function(a){a[a.EOL=0]="EOL"})(r||(r={})),(function(a){a.codec=()=>un(r)})(e=t.ValidityType||(t.ValidityType={}));let n;t.codec=()=>(n==null&&(n=Le((a,u,f={})=>{f.lengthDelimited!==!1&&u.fork(),a.value!=null&&(u.uint32(10),u.bytes(a.value)),a.signatureV1!=null&&(u.uint32(18),u.bytes(a.signatureV1)),a.validityType!=null&&(u.uint32(24),t.ValidityType.codec().encode(a.validityType,u)),a.validity!=null&&(u.uint32(34),u.bytes(a.validity)),a.sequence!=null&&(u.uint32(40),u.uint64(a.sequence)),a.ttl!=null&&(u.uint32(48),u.uint64(a.ttl)),a.publicKey!=null&&(u.uint32(58),u.bytes(a.publicKey)),a.signatureV2!=null&&(u.uint32(66),u.bytes(a.signatureV2)),a.data!=null&&(u.uint32(74),u.bytes(a.data)),f.lengthDelimited!==!1&&u.ldelim()},(a,u,f={})=>{let l={},p=u==null?a.len:a.pos+u;for(;a.pos<p;){let m=a.uint32();switch(m>>>3){case 1:{l.value=a.bytes();break}case 2:{l.signatureV1=a.bytes();break}case 3:{l.validityType=t.ValidityType.codec().decode(a);break}case 4:{l.validity=a.bytes();break}case 5:{l.sequence=a.uint64();break}case 6:{l.ttl=a.uint64();break}case 7:{l.publicKey=a.bytes();break}case 8:{l.signatureV2=a.bytes();break}case 9:{l.data=a.bytes();break}default:{a.skipType(m&7);break}}}return l},function*(a,u,f,l={}){let p=u==null?a.len:a.pos+u;for(;a.pos<p;){let m=a.uint32();switch(m>>>3){case 1:{yield{field:`${f}.value`,value:a.bytes()};break}case 2:{yield{field:`${f}.signatureV1`,value:a.bytes()};break}case 3:{yield{field:`${f}.validityType`,value:t.ValidityType.codec().decode(a)};break}case 4:{yield{field:`${f}.validity`,value:a.bytes()};break}case 5:{yield{field:`${f}.sequence`,value:a.uint64()};break}case 6:{yield{field:`${f}.ttl`,value:a.uint64()};break}case 7:{yield{field:`${f}.publicKey`,value:a.bytes()};break}case 8:{yield{field:`${f}.signatureV2`,value:a.bytes()};break}case 9:{yield{field:`${f}.data`,value:a.bytes()};break}default:{a.skipType(m&7);break}}}})),n);function o(a){return Ue(a,t.codec())}t.encode=o;function i(a,u){return ke(a,t.codec(),u)}t.decode=i;function s(a,u){return De(a,t.codec(),u)}t.stream=s})(V||(V={}));function Kt(t,e){let r=e.map((n,o)=>({record:n,index:o}));return r.sort((n,o)=>{let i=n.record.sequence,s=o.record.sequence;if(i>s)return-1;if(i<s)return 1;if(n.record.validityType===V.ValidityType.EOL&&o.record.validityType===V.ValidityType.EOL){let a=ln.default.fromString(n.record.validity).toDate(),u=ln.default.fromString(o.record.validity).toDate();if(a.getTime()>u.getTime())return-1;if(a.getTime()<u.getTime())return 1}return 0}),r[0].index}function Sa(t){return t?.buffer instanceof ArrayBuffer}function mo(t){if(Sa(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Ht(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=ce(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return mo(r)}function ht(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function jt(t){return t==null?!1:typeof t.type=="string"&&typeof t.code=="number"&&typeof t.verify=="function"}var me=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};function Ta(t){return typeof t?.handleEvent=="function"}function va(t){return(t!==!0&&t!==!1&&t?.once)??!1}var Gt=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let o=va(n);super.addEventListener(e,s=>{if(o){let a=this.#e.get(s.type);a!=null&&(a=a.filter(({callback:u})=>u!==r),this.#e.set(s.type,a))}Ta(r)?r.handleEvent(s):r(s)},n);let i=this.#e.get(e);i==null&&(i=[],this.#e.set(e,i)),i.push({callback:r,once:o})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==r),this.#e.set(e,o))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var Ca=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged"];function fn(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=Ia(t);return r||"Object"}function Ia(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Ca.includes(e))return e}var c=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};c.uint=new c(0,"uint",!0);c.negint=new c(1,"negint",!0);c.bytes=new c(2,"bytes",!0);c.string=new c(3,"string",!0);c.array=new c(4,"array",!1);c.map=new c(5,"map",!1);c.tag=new c(6,"tag",!1);c.float=new c(7,"float",!0);c.false=new c(7,"false",!0);c.true=new c(7,"true",!0);c.null=new c(7,"null",!0);c.undefined=new c(7,"undefined",!0);c.break=new c(7,"break",!0);var h=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var pt=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Aa=new TextEncoder;function Yt(t){return pt&&globalThis.Buffer.isBuffer(t)}function mt(t){return t instanceof Uint8Array?Yt(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Na=24,ka=200,Xt=pt?t=>t.length>=Na?globalThis.Buffer.from(t):go(t):t=>t.length>=ka?Aa.encode(t):go(t),ue=t=>Uint8Array.from(t),yo=pt?(t,e,r)=>Yt(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),xo=pt?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),mt(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let o of t)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},bo=pt?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function Jt(t,e){if(Yt(t)&&Yt(e))return t.compare(e);for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function go(t){let e=[],r=0;for(let n=0;n<t.length;n++){let o=t.charCodeAt(n);o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128)}return e}var Fa=256,gt=class{constructor(e=Fa){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=bo(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=yo(n,0,this.cursor)}else r=xo(this.chunks,this.cursor);return e&&this.reset(),r}},Wt=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var y="CBOR decode error:",Qt="CBOR encode error:",yt=[];yt[23]=1;yt[24]=2;yt[25]=3;yt[26]=5;yt[27]=9;function ge(t,e,r){if(t.length-e<r)throw new Error(`${y} not enough data for type`)}var $=[24,256,65536,4294967296,BigInt("18446744073709551616")];function J(t,e,r){ge(t,e,1);let n=t[e];if(r.strict===!0&&n<$[0])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function W(t,e,r){ge(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<$[1])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function Q(t,e,r){ge(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<$[2])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);return n}function Z(t,e,r){ge(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<$[3])throw new Error(`${y} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${y} integers outside of the safe integer range are not supported`)}function wo(t,e,r,n){return new h(c.uint,J(t,e+1,n),2)}function Eo(t,e,r,n){return new h(c.uint,W(t,e+1,n),3)}function So(t,e,r,n){return new h(c.uint,Q(t,e+1,n),5)}function To(t,e,r,n){return new h(c.uint,Z(t,e+1,n),9)}function te(t,e){return U(t,0,e.value)}function U(t,e,r){if(r<$[0]){let n=Number(r);t.push([e|n])}else if(r<$[1]){let n=Number(r);t.push([e|24,n])}else if(r<$[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<$[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<$[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${y} encountered BigInt larger than allowable range`)}}te.encodedSize=function(e){return U.encodedSize(e.value)};U.encodedSize=function(e){return e<$[0]?1:e<$[1]?2:e<$[2]?3:e<$[3]?5:9};te.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function vo(t,e,r,n){return new h(c.negint,-1-J(t,e+1,n),2)}function Co(t,e,r,n){return new h(c.negint,-1-W(t,e+1,n),3)}function Io(t,e,r,n){return new h(c.negint,-1-Q(t,e+1,n),5)}var dn=BigInt(-1),Ao=BigInt(1);function No(t,e,r,n){let o=Z(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new h(c.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${y} integers outside of the safe integer range are not supported`);return new h(c.negint,dn-BigInt(o),9)}function Zt(t,e){let r=e.value,n=typeof r=="bigint"?r*dn-Ao:r*-1-1;U(t,e.type.majorEncoded,n)}Zt.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*dn-Ao:r*-1-1;return n<$[0]?1:n<$[1]?2:n<$[2]?3:n<$[3]?5:9};Zt.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function xt(t,e,r,n){ge(t,e,r+n);let o=t.slice(e+r,e+r+n);return new h(c.bytes,o,r+n)}function ko(t,e,r,n){return xt(t,e,1,r)}function Fo(t,e,r,n){return xt(t,e,2,J(t,e+1,n))}function Uo(t,e,r,n){return xt(t,e,3,W(t,e+1,n))}function Do(t,e,r,n){return xt(t,e,5,Q(t,e+1,n))}function Lo(t,e,r,n){let o=Z(t,e+1,n);if(typeof o=="bigint")throw new Error(`${y} 64-bit integer bytes lengths not supported`);return xt(t,e,9,o)}function er(t){return t.encodedBytes===void 0&&(t.encodedBytes=c.equals(t.type,c.string)?Xt(t.value):t.value),t.encodedBytes}function Ge(t,e){let r=er(e);U(t,e.type.majorEncoded,r.length),t.push(r)}Ge.encodedSize=function(e){let r=er(e);return U.encodedSize(r.length)+r.length};Ge.compareTokens=function(e,r){return Da(er(e),er(r))};function Da(t,e){return t.length<e.length?-1:t.length>e.length?1:Jt(t,e)}var _o=new TextDecoder,_a=32;function Ra(t,e,r){if(r-e<_a){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return _o.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return _o.decode(t.subarray(e,r))}function bt(t,e,r,n,o){let i=r+n;ge(t,e,i);let s=new h(c.string,Ra(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function Ro(t,e,r,n){return bt(t,e,1,r,n)}function Bo(t,e,r,n){return bt(t,e,2,J(t,e+1,n),n)}function Mo(t,e,r,n){return bt(t,e,3,W(t,e+1,n),n)}function Po(t,e,r,n){return bt(t,e,5,Q(t,e+1,n),n)}function $o(t,e,r,n){let o=Z(t,e+1,n);if(typeof o=="bigint")throw new Error(`${y} 64-bit integer string lengths not supported`);return bt(t,e,9,o,n)}var Vo=Ge;function Ye(t,e,r,n){return new h(c.array,n,r)}function Oo(t,e,r,n){return Ye(t,e,1,r)}function zo(t,e,r,n){return Ye(t,e,2,J(t,e+1,n))}function qo(t,e,r,n){return Ye(t,e,3,W(t,e+1,n))}function Ko(t,e,r,n){return Ye(t,e,5,Q(t,e+1,n))}function Ho(t,e,r,n){let o=Z(t,e+1,n);if(typeof o=="bigint")throw new Error(`${y} 64-bit integer array lengths not supported`);return Ye(t,e,9,o)}function jo(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return Ye(t,e,1,1/0)}function tr(t,e){U(t,c.array.majorEncoded,e.value)}tr.compareTokens=te.compareTokens;tr.encodedSize=function(e){return U.encodedSize(e.value)};function Xe(t,e,r,n){return new h(c.map,n,r)}function Go(t,e,r,n){return Xe(t,e,1,r)}function Yo(t,e,r,n){return Xe(t,e,2,J(t,e+1,n))}function Xo(t,e,r,n){return Xe(t,e,3,W(t,e+1,n))}function Jo(t,e,r,n){return Xe(t,e,5,Q(t,e+1,n))}function Wo(t,e,r,n){let o=Z(t,e+1,n);if(typeof o=="bigint")throw new Error(`${y} 64-bit integer map lengths not supported`);return Xe(t,e,9,o)}function Qo(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return Xe(t,e,1,1/0)}function rr(t,e){U(t,c.map.majorEncoded,e.value)}rr.compareTokens=te.compareTokens;rr.encodedSize=function(e){return U.encodedSize(e.value)};function Zo(t,e,r,n){return new h(c.tag,r,1)}function ei(t,e,r,n){return new h(c.tag,J(t,e+1,n),2)}function ti(t,e,r,n){return new h(c.tag,W(t,e+1,n),3)}function ri(t,e,r,n){return new h(c.tag,Q(t,e+1,n),5)}function ni(t,e,r,n){return new h(c.tag,Z(t,e+1,n),9)}function nr(t,e){U(t,c.tag.majorEncoded,e.value)}nr.compareTokens=te.compareTokens;nr.encodedSize=function(e){return U.encodedSize(e.value)};var hn=20,pn=21,mn=22,gn=23;function oi(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${y} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new h(c.null,null,1):new h(c.undefined,void 0,1)}function ii(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${y} indefinite length items not allowed`);return new h(c.break,void 0,1)}function yn(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${y} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${y} Infinity values are not supported`)}return new h(c.float,t,e)}function si(t,e,r,n){return yn(xn(t,e+1),3,n)}function ai(t,e,r,n){return yn(bn(t,e+1),5,n)}function ci(t,e,r,n){return yn(di(t,e+1),9,n)}function wt(t,e,r){let n=e.value;if(n===!1)t.push([c.float.majorEncoded|hn]);else if(n===!0)t.push([c.float.majorEncoded|pn]);else if(n===null)t.push([c.float.majorEncoded|mn]);else if(n===void 0)t.push([c.float.majorEncoded|gn]);else{let o,i=!1;(!r||r.float64!==!0)&&(li(n),o=xn(ie,1),n===o||Number.isNaN(n)?(ie[0]=249,t.push(ie.slice(0,3)),i=!0):(fi(n),o=bn(ie,1),n===o&&(ie[0]=250,t.push(ie.slice(0,5)),i=!0))),i||(Va(n),o=di(ie,1),ie[0]=251,t.push(ie.slice(0,9)))}}wt.encodedSize=function(e,r){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){li(n);let o=xn(ie,1);if(n===o||Number.isNaN(n))return 3;if(fi(n),o=bn(ie,1),n===o)return 5}return 9};var ui=new ArrayBuffer(9),re=new DataView(ui,1),ie=new Uint8Array(ui,0);function li(t){if(t===1/0)re.setUint16(0,31744,!1);else if(t===-1/0)re.setUint16(0,64512,!1);else if(Number.isNaN(t))re.setUint16(0,32256,!1);else{re.setFloat32(0,t);let e=re.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)re.setUint16(0,31744,!1);else if(r===0)re.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?re.setUint16(0,0):o<-14?re.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):re.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function xn(t,e){if(t.length-e<2)throw new Error(`${y} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function fi(t){re.setFloat32(0,t,!1)}function bn(t,e){if(t.length-e<4)throw new Error(`${y} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Va(t){re.setFloat64(0,t,!1)}function di(t,e){if(t.length-e<8)throw new Error(`${y} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}wt.compareTokens=te.compareTokens;function A(t,e,r){throw new Error(`${y} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function or(t){return()=>{throw new Error(`${y} ${t}`)}}var d=[];for(let t=0;t<=23;t++)d[t]=A;d[24]=wo;d[25]=Eo;d[26]=So;d[27]=To;d[28]=A;d[29]=A;d[30]=A;d[31]=A;for(let t=32;t<=55;t++)d[t]=A;d[56]=vo;d[57]=Co;d[58]=Io;d[59]=No;d[60]=A;d[61]=A;d[62]=A;d[63]=A;for(let t=64;t<=87;t++)d[t]=ko;d[88]=Fo;d[89]=Uo;d[90]=Do;d[91]=Lo;d[92]=A;d[93]=A;d[94]=A;d[95]=or("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)d[t]=Ro;d[120]=Bo;d[121]=Mo;d[122]=Po;d[123]=$o;d[124]=A;d[125]=A;d[126]=A;d[127]=or("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)d[t]=Oo;d[152]=zo;d[153]=qo;d[154]=Ko;d[155]=Ho;d[156]=A;d[157]=A;d[158]=A;d[159]=jo;for(let t=160;t<=183;t++)d[t]=Go;d[184]=Yo;d[185]=Xo;d[186]=Jo;d[187]=Wo;d[188]=A;d[189]=A;d[190]=A;d[191]=Qo;for(let t=192;t<=215;t++)d[t]=Zo;d[216]=ei;d[217]=ti;d[218]=ri;d[219]=ni;d[220]=A;d[221]=A;d[222]=A;d[223]=A;for(let t=224;t<=243;t++)d[t]=or("simple values are not supported");d[244]=A;d[245]=A;d[246]=A;d[247]=oi;d[248]=or("simple values are not supported");d[249]=si;d[250]=ai;d[251]=ci;d[252]=A;d[253]=A;d[254]=A;d[255]=ii;var se=[];for(let t=0;t<24;t++)se[t]=new h(c.uint,t,1);for(let t=-1;t>=-24;t--)se[31-t]=new h(c.negint,t,1);se[64]=new h(c.bytes,new Uint8Array(0),1);se[96]=new h(c.string,"",1);se[128]=new h(c.array,0,1);se[160]=new h(c.map,0,1);se[244]=new h(c.false,!1,1);se[245]=new h(c.true,!0,1);se[246]=new h(c.null,null,1);function wn(t){switch(t.type){case c.false:return ue([244]);case c.true:return ue([245]);case c.null:return ue([246]);case c.bytes:return t.value.length?void 0:ue([64]);case c.string:return t.value===""?ue([96]):void 0;case c.array:return t.value===0?ue([128]):void 0;case c.map:return t.value===0?ue([160]):void 0;case c.uint:return t.value<24?ue([Number(t.value)]):void 0;case c.negint:if(t.value>=-24)return ue([31-Number(t.value)])}}var za={float64:!1,mapSorter:Ha,quickEncodeToken:wn},yi=Object.freeze({float64:!0,mapSorter:ja,quickEncodeToken:wn});function qa(){let t=[];return t[c.uint.major]=te,t[c.negint.major]=Zt,t[c.bytes.major]=Ge,t[c.string.major]=Vo,t[c.array.major]=tr,t[c.map.major]=rr,t[c.tag.major]=nr,t[c.float.major]=wt,t}var We=qa(),ir=new gt,St=class t{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${Qt} object contains circular references`);return new t(r,e)}},Se={null:new h(c.null,null),undefined:new h(c.undefined,void 0),true:new h(c.true,!0),false:new h(c.false,!1),emptyArray:new h(c.array,0),emptyMap:new h(c.map,0)},le={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new h(c.float,t):t>=0?new h(c.uint,t):new h(c.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new h(c.uint,t):new h(c.negint,t)},Uint8Array(t,e,r,n){return new h(c.bytes,t)},string(t,e,r,n){return new h(c.string,t)},boolean(t,e,r,n){return t?Se.true:Se.false},null(t,e,r,n){return Se.null},undefined(t,e,r,n){return Se.undefined},ArrayBuffer(t,e,r,n){return new h(c.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new h(c.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Se.emptyArray,new h(c.break)]:Se.emptyArray;n=St.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=Je(s,r,n);return r.addBreakTokens?[new h(c.array,t.length),o,new h(c.break)]:[new h(c.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),s=o?t.size:i.length,a;if(s){a=new Array(s),n=St.createCheck(n,t);let u=!o&&r.ignoreUndefinedProperties,f=0;for(let l of i){let p=o?t.get(l):t[l];u&&p===void 0||(a[f++]=[Je(l,r,n),Je(p,r,n)])}f<s&&(a.length=f)}return a?.length?(Ka(a,r),r.addBreakTokens?[new h(c.map,a.length),a,new h(c.break)]:[new h(c.map,a.length),a]):r.addBreakTokens===!0?[Se.emptyMap,new h(c.break)]:Se.emptyMap},Tagged(t,e,r,n){return[new h(c.tag,t.tag),Je(t.value,r,n)]}};le.Map=le.Object;le.Buffer=le.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))le[`${t}Array`]=le.DataView;function Je(t,e={},r){let n=fn(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||le[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=le[n];if(!i)throw new Error(`${Qt} unsupported type: ${n}`);return i(t,n,e,r)}function Ka(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Ha(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=We[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function ja(t,e){if(t[0]instanceof h&&e[0]instanceof h){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=hi(r.value)),n._keyBytes||(n._keyBytes=hi(n.value)),Jt(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function hi(t){return bi(t,We,yi)}function Et(t,e,r,n){if(Array.isArray(e))for(let o of e)Et(t,o,r,n);else r[e.type.major](t,e,n)}var pi=c.uint.majorEncoded,mi=c.negint.majorEncoded,Ga=c.bytes.majorEncoded,Ya=c.string.majorEncoded,gi=c.array.majorEncoded,Xa=c.float.majorEncoded|hn,Ja=c.float.majorEncoded|pn,Wa=c.float.majorEncoded|mn,Qa=c.float.majorEncoded|gn,Za=BigInt(-1),ec=BigInt(1);function tc(t){return t.addBreakTokens!==!0}function xi(t,e,r,n){let o=fn(e),i=r.typeEncoders&&r.typeEncoders[o];if(i){let s=i(e,o,r,n);if(s!=null){Et(t,s,We,r);return}}switch(o){case"null":t.push([Wa]);return;case"undefined":t.push([Qa]);return;case"boolean":t.push([e?Ja:Xa]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?wt(t,new h(c.float,e),r):e>=0?U(t,pi,e):U(t,mi,e*-1-1);return;case"bigint":e>=BigInt(0)?U(t,pi,e):U(t,mi,e*Za-ec);return;case"string":{let s=Xt(e);U(t,Ya,s.length),t.push(s);return}case"Uint8Array":U(t,Ga,e.length),t.push(e);return;case"Array":if(!e.length){t.push([gi]);return}n=St.createCheck(n,e),U(t,gi,e.length);for(let s of e)xi(t,s,r,n);return;case"Object":case"Map":{let s=le.Object(e,o,r,n);Et(t,s,We,r)}return;default:{let s=le[o];if(!s)throw new Error(`${Qt} unsupported type: ${o}`);let a=s(e,o,r,n);Et(t,a,We,r)}}}function bi(t,e,r,n){let o=n instanceof Uint8Array,i=o?new Wt(n):ir,s=Je(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let u=e[s.type.major];if(u.encodedSize){let f=u.encodedSize(s,r);if(o||(i=new gt(f)),u(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():mt(i.chunks[0])}}return i.reset(),Et(i,s,e,r),i.toBytes(!0)}function En(t,e){return e=Object.assign({},za,e),tc(e)?(ir.reset(),xi(ir,t,e,void 0),ir.toBytes(!0)):bi(t,We,e)}var rc={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},sr=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=se[e];if(r===void 0){let n=d[e];if(!n)throw new Error(`${y} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},Te=Symbol.for("DONE"),Qe=Symbol.for("BREAK");function nc(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=ve(e,r);if(i===Qe){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed array`)}if(i===Te)throw new Error(`${y} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function oc(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let u=ve(e,r);if(u===Qe){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed map`)}if(u===Te)throw new Error(`${y} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof u!="string")throw new Error(`${y} non-string keys not supported (got ${typeof u})`);if(o&&(n&&s.has(u)||!n&&Object.hasOwn(i,u)))throw new Error(`${y} found repeat map key "${u}"`);let f=ve(e,r);if(f===Te)throw new Error(`${y} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(u,f):i[u]=f}return n?s:i}function*ic(t,e,r){for(let n=0;n<t.value;n++){let o=ve(e,r);if(o===Qe){if(t.value===1/0)break;throw new Error(`${y} got unexpected break to lengthed map`)}if(o===Te)throw new Error(`${y} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let i=ve(e,r);if(i===Te)throw new Error(`${y} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,i]}}function sc(t,e){let r=!1,n=function(){if(r)throw new Error(`${y} tag decode() may only be called once`);r=!0;let o=ve(t,e);if(o===Te)throw new Error(`${y} tag content missing`);if(o===Qe)throw new Error(`${y} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${y} tag decode() may only be called once`);r=!0;let o=t.next();if(!c.equals(o.type,c.map))throw new Error(`${y} entries() requires map content, got ${o.type.name}`);let i=[];for(let s of ic(o,t,e))i.push(s);return i},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function ve(t,e){if(t.done())return Te;let r=t.next();if(c.equals(r.type,c.break))return Qe;if(r.type.terminal)return r.value;if(c.equals(r.type,c.array))return nc(r,t,e);if(c.equals(r.type,c.map))return oc(r,t,e);if(c.equals(r.type,c.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=sc(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${y} tag decoder must call decode() or entries()`);return o}throw new Error(`${y} tag not supported (${r.value})`)}throw new Error("unsupported")}function wi(t,e){if(!(t instanceof Uint8Array))throw new Error(`${y} data to decode must be a Uint8Array`);e=Object.assign({},rc,e);let r=mt(t),n=e.tokenizer||new sr(r,e),o=ve(n,e);if(o===Te)throw new Error(`${y} did not find any content to decode`);if(o===Qe)throw new Error(`${y} got unexpected break`);return[o,t.subarray(n.pos())]}function Sn(t,e){let[r,n]=wi(t,e);if(n.length>0)throw new Error(`${y} too many terminals, data makes no sense`);return r}var ar=class t{constructor(e,r){if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=e,this.value=r}static decoder(e){return r=>new t(e,r())}static preserve(...e){let r={};for(let n of e)r[n]=t.decoder(n);return r}};Object.defineProperty(ar.prototype,Symbol.toStringTag,{value:"Tagged"});function Re(t,e="utf8"){let r=Vt[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var ye="/",Ei=new TextEncoder().encode(ye),cr=Ei[0],Ze=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=z(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==cr)throw new Error("Invalid key")}toString(e="utf8"){return Re(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(ye))}static random(){return new t(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new t(e):typeof e.uint8Array=="function"?new t(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Ei),this._buf[0]!==cr){let e=new Uint8Array(this._buf.byteLength+1);e.fill(cr,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===cr;)this._buf=this._buf.subarray(0,-1)}less(e){let r=this.list(),n=e.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let i=r[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return r.length<n.length}reverse(){return t.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(ye).slice(1)}type(){return cc(this.baseNamespace())}name(){return uc(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(ye)||(e+=ye),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(ye):new t(e.slice(0,-1).join(ye))}child(e){return this.toString()===ye?e:e.toString()===ye?this:new t(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return t.withNamespaces([...this.namespaces(),...lc(e.map(r=>r.namespaces()))])}};function cc(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function uc(t){let e=t.split(":");return e[e.length-1]}function lc(t){return[].concat(...t)}var Ti=114;var dc=1024*10,vi=z("/ipns/"),Ci="/ipns/";function hc(t,e){return t.code===e}var ur="/dht/record/",pc="/ipns/metadata/";function Tt(t){return new Ze(ur+Re(t,"base32"),!1)}function lr(t){return new Ze(pc+Re(t,"base32"),!1)}function Ii(t,e){let r=Date.now(),n=e.getTime()+1728e5,o=new Date(t.validity).getTime();return n-r<864e5||o-r<864e5}function Ai(t,e,r){let n=z(e),o=z(t);return Ht([o,r,n],o.byteLength+r.byteLength+n.byteLength)}function fr(t){let e=z("ipns-signature:");return Ht([e,t])}function et(t){let e=t.publicKey?.toProtobuf();return t.publicKey?.toMultihash().code===0&&(e=void 0),"signatureV1"in t?V.encode({value:z(t.value),signatureV1:t.signatureV1,validityType:t.validityType,validity:z(t.validity),sequence:t.sequence,ttl:t.ttl,publicKey:e,signatureV2:t.signatureV2,data:t.data}):V.encode({publicKey:e,signatureV2:t.signatureV2,data:t.data})}function Si(t){try{return`/ipfs/${ae.decode(t)}`}catch{}return Re(t)}async function fe(t,e,r,n){if(e.byteLength>dc)throw new Bt("The record is too large");let o=V.decode(e);if(o.signatureV2==null||o.data==null)throw new ne("Missing data or signatureV2");let i=ki(o.data),s=Re(i.Validity),a,u=mc(t);if(hc(u,0)&&(a=await r.loadPublicKeyFromProtobuf(u.digest,n)),a==null&&o.publicKey!=null&&(a=await r.loadPublicKeyFromProtobuf(o.publicKey,n)),a==null)throw new je("Could not extract public key from IPNS record or routing key");if(o.value!=null&&o.signatureV1!=null)return yc(o),{value:Si(i.Value),validityType:V.ValidityType.EOL,validity:s,sequence:i.Sequence,ttl:i.TTL,publicKey:a,signatureV1:o.signatureV1,signatureV2:o.signatureV2,data:o.data,bytes:e};if(o.signatureV2!=null)return{value:Si(i.Value),validityType:V.ValidityType.EOL,validity:s,sequence:i.Sequence,ttl:i.TTL,publicKey:a,signatureV2:o.signatureV2,data:o.data,bytes:e};throw new Error("invalid record: does not include signatureV1 or signatureV2")}function vt(t){return Ht([vi,t.bytes])}function mc(t){return st(t.slice(vi.length))}function Ni(t,e,r,n,o){let i;if(e===V.ValidityType.EOL)i=0;else throw new Ae("The validity type is unsupported");let s={Value:z(t),Validity:r,ValidityType:i,Sequence:n,TTL:o};return En(s)}function ki(t){let e=Sn(t);if(e.ValidityType===0)e.ValidityType=V.ValidityType.EOL;else throw new Ae("The validity type is unsupported");return Number.isInteger(e.Sequence)&&(e.Sequence=BigInt(e.Sequence)),Number.isInteger(e.TTL)&&(e.TTL=BigInt(e.TTL)),e}function Fi(t){if(t!=null){if(jt(t))return`/ipns/${t.toCID().toV1().toString(ee)}`;let e=Ui(t);if(e!=null)return e.code===Ti?`/ipns/${e.toV1().toString(ee)}`:`/ipfs/${e.toV1()}`;if(xc(t))return`/ipns/${ee.encode(t.bytes)}`;let r=t.toString().trim();if(r.startsWith("/ipfs/")){let[,n,...o]=r.split("/").filter(i=>i.trim()!=="");return`/ipfs/${ae.parse(n).toV1()}${o.length>0?`/${o.join("/")}`:""}`}if(r.startsWith("/")&&r.length>1)return r}throw new He("Value must be a valid content path starting with /")}function gc(t){return typeof t.code=="number"&&t.digest instanceof Uint8Array&&typeof t.size=="number"&&t.bytes instanceof Uint8Array}function Ct(t){if(t!=null){if(jt(t))return{digest:t.toMultihash(),path:"/"};let e=Ui(t);if(e!=null){if(e.code!==Ti)throw new He("CIDs must have the `libp2p-key` codec");return{digest:e.multihash,path:"/"}}if(gc(t))return{digest:t,path:"/"};if(t=t.toString(),t.startsWith("/ipns/")){let[,,r,...n]=t.split("/"),o=ee;(r.startsWith("1")||r.startsWith("Q"))&&(r=`z${r}`,o=H);let i=o.decode(r),s;try{s=ae.decode(i).multihash}catch{s=st(i)}return{digest:s,path:`/${n.join("/")}`}}}throw new He("Value must be a valid IPNS path starting with /")}function yc(t){if(t.data==null)throw new Mt("Record data is missing");let e=ki(t.data);if(!ht(e.Value,t.value??new Uint8Array(0)))throw new ne('Field "value" did not match between protobuf and CBOR');if(!ht(e.Validity,t.validity??new Uint8Array(0)))throw new ne('Field "validity" did not match between protobuf and CBOR');if(e.ValidityType!==t.validityType)throw new ne('Field "validityType" did not match between protobuf and CBOR');if(e.Sequence!==t.sequence)throw new ne('Field "sequence" did not match between protobuf and CBOR');if(e.TTL!==t.ttl)throw new ne('Field "ttl" did not match between protobuf and CBOR')}function xc(t){return t.bytes instanceof Uint8Array}function bc(t){return typeof t?.toCID=="function"}function Ui(t){if(bc(t))return t.toCID();try{return ae.parse(t)}catch{}return ae.asCID(t)}var Di=Ir(Pt(),1);async function It(t,e){if(t.publicKey==null)throw new je("The record had no public key associated with it");let r;try{let n=fr(t.data);r=await t.publicKey.verify(n,t.signatureV2,e)}catch{r=!1}if(!r)throw new ne("Record signature verification failed");if(t.validityType===V.ValidityType.EOL){if(Di.default.fromString(t.validity).toDate().getTime()<Date.now())throw new Rt("record has expired")}else if(t.validityType!=null)throw new Ae("The validity type is unsupported")}var tt=class{routers;localStore;log;keychain;constructor(e,r){this.log=e.logger.forComponent("helia:ipns"),this.localStore=r.localStore,this.routers=r.routers,this.keychain=e.keychain}async*resolve(e,r={}){let{digest:n}=Ct(e);for(;;){let o=vt(n),i=await this.#e(o,r);if(yield{record:i},!i.value.startsWith(Ci))break;({digest:n}=Ct(i.value))}}async#e(e,r={}){let n=[];if(await this.localStore.has(e,r))if(this.log("record is present in the cache"),r.nocache!==!0)try{let{record:u,created:f}=await this.localStore.get(e,r);this.log("record retrieved from cache");let l=await fe(e,u,this.keychain,r);await It(l,r),this.log("record was valid");let p=Number((l.ttl??Ke)/1000000n);if(f.getTime()+p>Date.now())return this.log("record TTL was valid"),l;if(r.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),l;this.log("record TTL has been reached, searching routing for updates"),n.push(l)}catch(u){this.log("cached record was invalid - %e",u),await this.localStore.delete(e,r)}else this.log("ignoring local cache due to nocache=true option");if(r.offline===!0)throw new ct("Record was not present in the cache or has expired");this.log("did not have record locally");let i=0,s=[];if(await Promise.all(this.routers.map(async u=>{let f;try{f=await u.get(e,{...r,validate:!1})}catch(l){this.log.error("error finding IPNS record using router %s - %e",u.toString(),l),s.push(l);return}try{let l=await fe(e,f,this.keychain,r);await It(l,r),n.push(l)}catch(l){i++,this.log.error("error validating IPNS record from router %s - %e",u.toString(),l)}})),n.length===0)throw i>0?new Lt(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`):new ct("Could not find record for routing key");let a=n[Kt(e,n)];return await this.localStore.put(e,a.bytes,r),a}};var j=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};function dr(t,e){if(typeof t=="string")return wc(t);if(typeof t=="number")return Tc(t,e);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}function wc(t){if(typeof t!="string"||t.length===0||t.length>100)throw new Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(t)}`);let e=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(t);if(!e?.groups)return NaN;let{value:r,unit:n="ms"}=e.groups,o=parseFloat(r),i=n.toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw new Error(`Unknown unit "${i}" provided to ms.parse(). value=${JSON.stringify(t)}`)}}function Ec(t){let e=Math.abs(t);return e>=315576e5?`${Math.round(t/315576e5)}y`:e>=26298e5?`${Math.round(t/26298e5)}mo`:e>=6048e5?`${Math.round(t/6048e5)}w`:e>=864e5?`${Math.round(t/864e5)}d`:e>=36e5?`${Math.round(t/36e5)}h`:e>=6e4?`${Math.round(t/6e4)}m`:e>=1e3?`${Math.round(t/1e3)}s`:`${t}ms`}function Sc(t){let e=Math.abs(t);return e>=315576e5?Be(t,e,315576e5,"year"):e>=26298e5?Be(t,e,26298e5,"month"):e>=6048e5?Be(t,e,6048e5,"week"):e>=864e5?Be(t,e,864e5,"day"):e>=36e5?Be(t,e,36e5,"hour"):e>=6e4?Be(t,e,6e4,"minute"):e>=1e3?Be(t,e,1e3,"second"):`${t} ms`}function Tc(t,e){if(typeof t!="number"||!Number.isFinite(t))throw new Error("Value provided to ms.format() must be of type number.");return e?.long?Sc(t):Ec(t)}function Be(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function Tn(t){r.debug=r,r.default=r,r.coerce=u,r.disable=i,r.enable=o,r.enabled=s,r.humanize=dr,r.destroy=f,Object.keys(t).forEach(l=>{r[l]=t[l]}),r.names=[],r.skips=[],r.formatters={};function e(l){let p=0;for(let m=0;m<l.length;m++)p=(p<<5)-p+l.charCodeAt(m),p|=0;return r.colors[Math.abs(p)%r.colors.length]}r.selectColor=e;function r(l,p){let m,w=null,S,E;function x(...T){if(!x.enabled)return;let k=x,F=Number(new Date),P=F-(m||F);k.diff=P,k.prev=m,k.curr=F,m=F,T[0]=r.coerce(T[0]),typeof T[0]!="string"&&T.unshift("%O");let B=0;T[0]=T[0].replace(/%([a-zA-Z%])/g,(R,g)=>{if(R==="%%")return"%";B++;let b=r.formatters[g];if(typeof b=="function"){let I=T[B];R=b.call(k,I),T.splice(B,1),B--}return R}),r.formatArgs.call(k,T),p?.onLog!=null&&p.onLog(...T),(k.log||r.log).apply(k,T)}return x.namespace=l,x.useColors=r.useColors(),x.color=r.selectColor(l),x.extend=n,x.destroy=r.destroy,Object.defineProperty(x,"enabled",{enumerable:!0,configurable:!1,get:()=>w!==null?w:(S!==r.namespaces&&(S=r.namespaces,E=r.enabled(l)),E),set:T=>{w=T}}),typeof r.init=="function"&&r.init(x),x}function n(l,p){let m=r(this.namespace+(typeof p>"u"?":":p)+l);return m.log=this.log,m}function o(l){r.save(l),r.namespaces=l,r.names=[],r.skips=[];let p,m=(typeof l=="string"?l:"").split(/[\s,]+/),w=m.length;for(p=0;p<w;p++)m[p]&&(l=m[p].replace(/\*/g,".*?"),l[0]==="-"?r.skips.push(new RegExp("^"+l.substr(1)+"$")):r.names.push(new RegExp("^"+l+"$")))}function i(){let l=[...r.names.map(a),...r.skips.map(a).map(p=>"-"+p)].join(",");return r.enable(""),l}function s(l){if(l[l.length-1]==="*")return!0;let p,m;for(p=0,m=r.skips.length;p<m;p++)if(r.skips[p].test(l))return!1;for(p=0,m=r.names.length;p<m;p++)if(r.names[p].test(l))return!0;return!1}function a(l){return l.toString().substring(2,l.toString().length-2).replace(/\.\*\?$/,"*")}function u(l){return l instanceof Error?l.stack??l.message:l}function f(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var hr=Fc(),vc=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Cc(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function Ic(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+dr(this.diff),!this.useColors)return;let e="color: "+this.color;t.splice(1,0,e,"color: inherit");let r=0,n=0;t[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(r++,o==="%c"&&(n=r))}),t.splice(n,0,e)}var Ac=console.debug??console.log??(()=>{});function Nc(t){try{t?hr?.setItem("debug",t):hr?.removeItem("debug")}catch{}}function kc(){let t;try{t=hr?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function Fc(){try{return localStorage}catch{}}function Uc(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Li=Tn({formatArgs:Ic,save:Nc,load:kc,useColors:Cc,setupFormatters:Uc,colors:vc,storage:hr,log:Ac});var G=Li;G.formatters.b=t=>t==null?"undefined":H.baseEncode(t);G.formatters.t=t=>t==null?"undefined":be.baseEncode(t);G.formatters.m=t=>t==null?"undefined":jr.baseEncode(t);G.formatters.p=t=>t==null?"undefined":t.toString();G.formatters.c=t=>t==null?"undefined":t.toString();G.formatters.k=t=>t==null?"undefined":t.toString();G.formatters.a=t=>t==null?"undefined":t.toString();function _i(t,e=""){let r=Ri(t.message),n=Ri(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
4
4
  `).join(`
5
- ${t}`)}`:`${r}
6
- ${t}${n.split(`
5
+ ${e}`)}`:`${r}
6
+ ${e}${n.split(`
7
7
  `).join(`
8
- ${t}`)}`:n!=null?`${n.split(`
8
+ ${e}`)}`:n!=null?`${n.split(`
9
9
  `).join(`
10
- ${t}`)}`:r!=null?`${r}`:`${e.toString()}`}function Gh(e){return e instanceof AggregateError||e?.name==="AggregateError"&&Array.isArray(e.errors)}function wu(e,t=""){if(Gh(e)){let r=bu(e,t);return e.errors.length>0?(t=`${t} `,r+=`
11
- ${t}${e.errors.map(n=>`${wu(n,`${t}`)}`).join(`
12
- ${t}`)}`):r+=`
13
- ${t}[Error list was empty]`,r.trim()}return bu(e,t)}vt.formatters.e=e=>e==null?"undefined":wu(e);function Xh(e){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=e,t.destroy=()=>!0,t.extend=()=>t,t}function He(e,t){let r=Xh(`${e}:trace`);return vt.enabled(`${e}:trace`)&&vt.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=vt(`${e}:trace`,t)),Object.assign(vt(e,t),{error:vt(`${e}:error`,t),trace:r,newScope:n=>He(`${e}:${n}`,t)})}function xu(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var qf=Zo(to(),1);var eo=class extends Error{static name="SignatureCreationError";constructor(t="Record signature creation failed"){super(t),this.name="SignatureCreationError"}},Vt=class extends Error{static name="SignatureVerificationError";constructor(t="Record signature verification failed"){super(t),this.name="SignatureVerificationError"}},ro=class extends Error{static name="RecordExpiredError";constructor(t="Record has expired"){super(t),this.name="RecordExpiredError"}},ze=class extends Error{static name="UnsupportedValidityError";constructor(t="The validity type is unsupported"){super(t),this.name="UnsupportedValidityError"}},no=class extends Error{static name="RecordTooLargeError";constructor(t="The record is too large"){super(t),this.name="RecordTooLargeError"}},Wr=class extends Error{static name="InvalidValueError";constructor(t="Value must be a valid content path starting with /"){super(t),this.name="InvalidValueError"}},oo=class extends Error{static name="InvalidRecordDataError";constructor(t="Invalid record data"){super(t),this.name="InvalidRecordDataError"}},Jr=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(t="Invalid embedded public key"){super(t),this.name="InvalidEmbeddedPublicKeyError"}};var vs=new Float32Array([-0]),Be=new Uint8Array(vs.buffer);function Eu(e,t,r){vs[0]=e,t[r]=Be[0],t[r+1]=Be[1],t[r+2]=Be[2],t[r+3]=Be[3]}function Su(e,t){return Be[0]=e[t],Be[1]=e[t+1],Be[2]=e[t+2],Be[3]=e[t+3],vs[0]}var Is=new Float64Array([-0]),yt=new Uint8Array(Is.buffer);function Au(e,t,r){Is[0]=e,t[r]=yt[0],t[r+1]=yt[1],t[r+2]=yt[2],t[r+3]=yt[3],t[r+4]=yt[4],t[r+5]=yt[5],t[r+6]=yt[6],t[r+7]=yt[7]}function vu(e,t){return yt[0]=e[t],yt[1]=e[t+1],yt[2]=e[t+2],yt[3]=e[t+3],yt[4]=e[t+4],yt[5]=e[t+5],yt[6]=e[t+6],yt[7]=e[t+7],Is[0]}var Wh=BigInt(Number.MAX_SAFE_INTEGER),Jh=BigInt(Number.MIN_SAFE_INTEGER),Bt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return je;if(t<Wh&&t>Jh)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Iu&&(o=0n,++n>Iu&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return je;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):je}},je=new Bt(0,0);je.toBigInt=function(){return 0n};je.zzEncode=je.zzDecode=function(){return this};je.length=function(){return 1};var Iu=4294967296n;function Tu(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Bu(e,t,r){if(r-t<1)return"";let o,i=[],s=0,a;for(;t<r;)a=e[t++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Ts(e,t,r){let n=r,o,i;for(let s=0;s<e.length;++s)o=e.charCodeAt(s),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((i=e.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function qt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function io(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Bs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,qt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw qt(this,4);return io(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw qt(this,4);return io(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw qt(this,4);let t=Su(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw qt(this,4);let t=vu(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw qt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Bu(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw qt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw qt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Bt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw qt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw qt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw qt(this,8);let t=io(this.buf,this.pos+=4),r=io(this.buf,this.pos+=4);return new Bt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Hn(this.buf,this.pos);return this.pos+=ae(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function _s(e){return new Bs(e instanceof Uint8Array?e:e.subarray())}function Cs(e,t,r){let n=_s(e);return t.decode(n,void 0,r)}function Rs(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return at(s);o+s>t&&(n=at(t),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Ze=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Ls(){}var Ns=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Qh=Rs();function t0(e){return globalThis.Buffer!=null?at(e):Qh(e)}var tn=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ze(Ls,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Ze(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Us((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(so,10,Bt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Bt.fromBigInt(t);return this._push(so,r.length(),r)}uint64Number(t){return this._push($n,ae(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=Bt.fromBigInt(t).zzEncode();return this._push(so,r.length(),r)}sint64Number(t){let r=Bt.fromNumber(t).zzEncode();return this._push(so,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ds,1,t?1:0)}fixed32(t){return this._push(Qr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Bt.fromBigInt(t);return this._push(Qr,4,r.lo)._push(Qr,4,r.hi)}fixed64Number(t){let r=Bt.fromNumber(t);return this._push(Qr,4,r.lo)._push(Qr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Eu,4,t)}double(t){return this._push(Au,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Ds,1,0):this.uint32(r)._push(r0,r,t)}string(t){let r=Tu(t);return r!==0?this.uint32(r)._push(Ts,r,t):this._push(Ds,1,0)}fork(){return this.states=new Ns(this),this.head=this.tail=new Ze(Ls,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 Ze(Ls,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=t0(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Ds(e,t,r){t[r]=e&255}function e0(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Us=class extends Ze{next;constructor(t,r){super(e0,t,r),this.next=void 0}};function so(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Qr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function r0(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(tn.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(n0,t,e),this},tn.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(o0,t,e),this});function n0(e,t,r){t.set(e,r)}function o0(e,t,r){e.length<40?Ts(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(H(e),r)}function ks(){return new tn}function Ks(e,t){let r=ks();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var pr;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(pr||(pr={}));function ao(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Os(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(i,s){let a=t(i);s.int32(a)},n=function(i){let s=i.int32();return t(s)};return ao("enum",pr.VARINT,r,n)}function Ms(e,t){return ao("message",pr.LENGTH_DELIMITED,e,t)}var ht;(function(e){let t;(function(o){o.EOL="EOL"})(t=e.ValidityType||(e.ValidityType={}));let r;(function(o){o[o.EOL=0]="EOL"})(r||(r={})),(function(o){o.codec=()=>Os(r)})(t=e.ValidityType||(e.ValidityType={}));let n;e.codec=()=>(n==null&&(n=Ms((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.value!=null&&(i.uint32(10),i.bytes(o.value)),o.signatureV1!=null&&(i.uint32(18),i.bytes(o.signatureV1)),o.validityType!=null&&(i.uint32(24),e.ValidityType.codec().encode(o.validityType,i)),o.validity!=null&&(i.uint32(34),i.bytes(o.validity)),o.sequence!=null&&(i.uint32(40),i.uint64(o.sequence)),o.ttl!=null&&(i.uint32(48),i.uint64(o.ttl)),o.pubKey!=null&&(i.uint32(58),i.bytes(o.pubKey)),o.signatureV2!=null&&(i.uint32(66),i.bytes(o.signatureV2)),o.data!=null&&(i.uint32(74),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let f=o.uint32();switch(f>>>3){case 1:{a.value=o.bytes();break}case 2:{a.signatureV1=o.bytes();break}case 3:{a.validityType=e.ValidityType.codec().decode(o);break}case 4:{a.validity=o.bytes();break}case 5:{a.sequence=o.uint64();break}case 6:{a.ttl=o.uint64();break}case 7:{a.pubKey=o.bytes();break}case 8:{a.signatureV2=o.bytes();break}case 9:{a.data=o.bytes();break}default:{o.skipType(f&7);break}}}return a})),n),e.encode=o=>Ks(o,e.codec()),e.decode=(o,i)=>Cs(o,e.codec(),i)})(ht||(ht={}));var i0=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Ps(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(t==="string"||t==="number"||t==="bigint"||t==="symbol")return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(e instanceof Uint8Array)return"Uint8Array";if(e.constructor===Object)return"Object";let r=s0(e);return r||"Object"}function s0(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(i0.includes(t))return t}var h=class{constructor(t,r,n){this.major=t,this.majorEncoded=t<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}static equals(t,r){return t===r||t.major===r.major&&t.name===r.name}};h.uint=new h(0,"uint",!0);h.negint=new h(1,"negint",!0);h.bytes=new h(2,"bytes",!0);h.string=new h(3,"string",!0);h.array=new h(4,"array",!1);h.map=new h(5,"map",!1);h.tag=new h(6,"tag",!1);h.float=new h(7,"float",!0);h.false=new h(7,"false",!0);h.true=new h(7,"true",!0);h.null=new h(7,"null",!0);h.undefined=new h(7,"undefined",!0);h.break=new h(7,"break",!0);var D=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var en=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",a0=new TextEncoder;function co(e){return en&&globalThis.Buffer.isBuffer(e)}function rn(e){return e instanceof Uint8Array?co(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var c0=24,u0=200,uo=en?e=>e.length>=c0?globalThis.Buffer.from(e):Cu(e):e=>e.length>=u0?a0.encode(e):Cu(e),Xt=e=>Uint8Array.from(e),Ru=en?(e,t,r)=>co(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Lu=en?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),rn(globalThis.Buffer.concat(e,t))):(e,t)=>{let r=new Uint8Array(t),n=0;for(let o of e)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},Du=en?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function fo(e,t){if(co(e)&&co(t))return e.compare(t);for(let r=0;r<e.length;r++)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return 0}function Cu(e){let t=[],r=0;for(let n=0;n<e.length;n++){let o=e.charCodeAt(n);o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&n+1<e.length&&(e.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(e.charCodeAt(++n)&1023),t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128)}return t}var f0=256,nn=class{constructor(t=f0){this.chunkSize=t,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(t){let r=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(t,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(r=Du(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(t,0)):(this.chunks.push(t),this.maxCursor+=t.length)}this.cursor+=t.length}toBytes(t=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];t&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=Ru(n,0,this.cursor)}else r=Lu(this.chunks,this.cursor);return t&&this.reset(),r}},lo=class{constructor(t){this.dest=t,this.cursor=0,this.chunks=[t]}reset(){this.cursor=0}push(t){if(this.cursor+t.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(t,this.cursor),this.cursor+=t.length}toBytes(t=!1){let r=this.dest.subarray(0,this.cursor);return t&&this.reset(),r}};var V="CBOR decode error:",ho="CBOR encode error:",on=[];on[23]=1;on[24]=2;on[25]=3;on[26]=5;on[27]=9;function ue(e,t,r){if(e.length-t<r)throw new Error(`${V} not enough data for type`)}var ft=[24,256,65536,4294967296,BigInt("18446744073709551616")];function _t(e,t,r){ue(e,t,1);let n=e[t];if(r.strict===!0&&n<ft[0])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function Ct(e,t,r){ue(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<ft[1])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function Rt(e,t,r){ue(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<ft[2])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function Lt(e,t,r){ue(e,t,8);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<ft[3])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${V} integers outside of the safe integer range are not supported`)}function Nu(e,t,r,n){return new D(h.uint,_t(e,t+1,n),2)}function Uu(e,t,r,n){return new D(h.uint,Ct(e,t+1,n),3)}function ku(e,t,r,n){return new D(h.uint,Rt(e,t+1,n),5)}function Ku(e,t,r,n){return new D(h.uint,Lt(e,t+1,n),9)}function Ut(e,t){return Y(e,0,t.value)}function Y(e,t,r){if(r<ft[0]){let n=Number(r);e.push([t|n])}else if(r<ft[1]){let n=Number(r);e.push([t|24,n])}else if(r<ft[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<ft[3]){let n=Number(r);e.push([t|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<ft[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,e.push(o)}else throw new Error(`${V} encountered BigInt larger than allowable range`)}}Ut.encodedSize=function(t){return Y.encodedSize(t.value)};Y.encodedSize=function(t){return t<ft[0]?1:t<ft[1]?2:t<ft[2]?3:t<ft[3]?5:9};Ut.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function Ou(e,t,r,n){return new D(h.negint,-1-_t(e,t+1,n),2)}function Mu(e,t,r,n){return new D(h.negint,-1-Ct(e,t+1,n),3)}function Pu(e,t,r,n){return new D(h.negint,-1-Rt(e,t+1,n),5)}var Fs=BigInt(-1),Fu=BigInt(1);function Vu(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new D(h.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${V} integers outside of the safe integer range are not supported`);return new D(h.negint,Fs-BigInt(o),9)}function po(e,t){let r=t.value,n=typeof r=="bigint"?r*Fs-Fu:r*-1-1;Y(e,t.type.majorEncoded,n)}po.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*Fs-Fu:r*-1-1;return n<ft[0]?1:n<ft[1]?2:n<ft[2]?3:n<ft[3]?5:9};po.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function sn(e,t,r,n){ue(e,t,r+n);let o=e.slice(t+r,t+r+n);return new D(h.bytes,o,r+n)}function qu(e,t,r,n){return sn(e,t,1,r)}function $u(e,t,r,n){return sn(e,t,2,_t(e,t+1,n))}function Hu(e,t,r,n){return sn(e,t,3,Ct(e,t+1,n))}function zu(e,t,r,n){return sn(e,t,5,Rt(e,t+1,n))}function ju(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer bytes lengths not supported`);return sn(e,t,9,o)}function mo(e){return e.encodedBytes===void 0&&(e.encodedBytes=h.equals(e.type,h.string)?uo(e.value):e.value),e.encodedBytes}function mr(e,t){let r=mo(t);Y(e,t.type.majorEncoded,r.length),e.push(r)}mr.encodedSize=function(t){let r=mo(t);return Y.encodedSize(r.length)+r.length};mr.compareTokens=function(t,r){return d0(mo(t),mo(r))};function d0(e,t){return e.length<t.length?-1:e.length>t.length?1:fo(e,t)}var Zu=new TextDecoder,p0=32;function m0(e,t,r){if(r-t<p0){let o="";for(let i=t;i<r;i++){let s=e[i];if(s&128)return Zu.decode(e.subarray(t,r));o+=String.fromCharCode(s)}return o}return Zu.decode(e.subarray(t,r))}function an(e,t,r,n,o){let i=r+n;ue(e,t,i);let s=new D(h.string,m0(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=e.slice(t+r,t+i)),s}function Yu(e,t,r,n){return an(e,t,1,r,n)}function Gu(e,t,r,n){return an(e,t,2,_t(e,t+1,n),n)}function Xu(e,t,r,n){return an(e,t,3,Ct(e,t+1,n),n)}function Wu(e,t,r,n){return an(e,t,5,Rt(e,t+1,n),n)}function Ju(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer string lengths not supported`);return an(e,t,9,o,n)}var Qu=mr;function yr(e,t,r,n){return new D(h.array,n,r)}function tf(e,t,r,n){return yr(e,t,1,r)}function ef(e,t,r,n){return yr(e,t,2,_t(e,t+1,n))}function rf(e,t,r,n){return yr(e,t,3,Ct(e,t+1,n))}function nf(e,t,r,n){return yr(e,t,5,Rt(e,t+1,n))}function of(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer array lengths not supported`);return yr(e,t,9,o)}function sf(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return yr(e,t,1,1/0)}function yo(e,t){Y(e,h.array.majorEncoded,t.value)}yo.compareTokens=Ut.compareTokens;yo.encodedSize=function(t){return Y.encodedSize(t.value)};function gr(e,t,r,n){return new D(h.map,n,r)}function af(e,t,r,n){return gr(e,t,1,r)}function cf(e,t,r,n){return gr(e,t,2,_t(e,t+1,n))}function uf(e,t,r,n){return gr(e,t,3,Ct(e,t+1,n))}function ff(e,t,r,n){return gr(e,t,5,Rt(e,t+1,n))}function lf(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer map lengths not supported`);return gr(e,t,9,o)}function df(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return gr(e,t,1,1/0)}function go(e,t){Y(e,h.map.majorEncoded,t.value)}go.compareTokens=Ut.compareTokens;go.encodedSize=function(t){return Y.encodedSize(t.value)};function hf(e,t,r,n){return new D(h.tag,r,1)}function pf(e,t,r,n){return new D(h.tag,_t(e,t+1,n),2)}function mf(e,t,r,n){return new D(h.tag,Ct(e,t+1,n),3)}function yf(e,t,r,n){return new D(h.tag,Rt(e,t+1,n),5)}function gf(e,t,r,n){return new D(h.tag,Lt(e,t+1,n),9)}function bo(e,t){Y(e,h.tag.majorEncoded,t.value)}bo.compareTokens=Ut.compareTokens;bo.encodedSize=function(t){return Y.encodedSize(t.value)};var Vs=20,qs=21,$s=22,Hs=23;function bf(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${V} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new D(h.null,null,1):new D(h.undefined,void 0,1)}function xf(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return new D(h.break,void 0,1)}function zs(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${V} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${V} Infinity values are not supported`)}return new D(h.float,e,t)}function wf(e,t,r,n){return zs(js(e,t+1),3,n)}function Ef(e,t,r,n){return zs(Zs(e,t+1),5,n)}function Sf(e,t,r,n){return zs(Tf(e,t+1),9,n)}function cn(e,t,r){let n=t.value;if(n===!1)e.push([h.float.majorEncoded|Vs]);else if(n===!0)e.push([h.float.majorEncoded|qs]);else if(n===null)e.push([h.float.majorEncoded|$s]);else if(n===void 0)e.push([h.float.majorEncoded|Hs]);else{let o,i=!1;(!r||r.float64!==!0)&&(vf(n),o=js($t,1),n===o||Number.isNaN(n)?($t[0]=249,e.push($t.slice(0,3)),i=!0):(If(n),o=Zs($t,1),n===o&&($t[0]=250,e.push($t.slice(0,5)),i=!0))),i||(w0(n),o=Tf($t,1),$t[0]=251,e.push($t.slice(0,9)))}}cn.encodedSize=function(t,r){let n=t.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){vf(n);let o=js($t,1);if(n===o||Number.isNaN(n))return 3;if(If(n),o=Zs($t,1),n===o)return 5}return 9};var Af=new ArrayBuffer(9),kt=new DataView(Af,1),$t=new Uint8Array(Af,0);function vf(e){if(e===1/0)kt.setUint16(0,31744,!1);else if(e===-1/0)kt.setUint16(0,64512,!1);else if(Number.isNaN(e))kt.setUint16(0,32256,!1);else{kt.setFloat32(0,e);let t=kt.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)kt.setUint16(0,31744,!1);else if(r===0)kt.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?kt.setUint16(0,0):o<-14?kt.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):kt.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function js(e,t){if(e.length-t<2)throw new Error(`${V} not enough data for float16`);let r=(e[t]<<8)+e[t+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function If(e){kt.setFloat32(0,e,!1)}function Zs(e,t){if(e.length-t<4)throw new Error(`${V} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function w0(e){kt.setFloat64(0,e,!1)}function Tf(e,t){if(e.length-t<8)throw new Error(`${V} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}cn.compareTokens=Ut.compareTokens;function j(e,t,r){throw new Error(`${V} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function xo(e){return()=>{throw new Error(`${V} ${e}`)}}var _=[];for(let e=0;e<=23;e++)_[e]=j;_[24]=Nu;_[25]=Uu;_[26]=ku;_[27]=Ku;_[28]=j;_[29]=j;_[30]=j;_[31]=j;for(let e=32;e<=55;e++)_[e]=j;_[56]=Ou;_[57]=Mu;_[58]=Pu;_[59]=Vu;_[60]=j;_[61]=j;_[62]=j;_[63]=j;for(let e=64;e<=87;e++)_[e]=qu;_[88]=$u;_[89]=Hu;_[90]=zu;_[91]=ju;_[92]=j;_[93]=j;_[94]=j;_[95]=xo("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)_[e]=Yu;_[120]=Gu;_[121]=Xu;_[122]=Wu;_[123]=Ju;_[124]=j;_[125]=j;_[126]=j;_[127]=xo("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)_[e]=tf;_[152]=ef;_[153]=rf;_[154]=nf;_[155]=of;_[156]=j;_[157]=j;_[158]=j;_[159]=sf;for(let e=160;e<=183;e++)_[e]=af;_[184]=cf;_[185]=uf;_[186]=ff;_[187]=lf;_[188]=j;_[189]=j;_[190]=j;_[191]=df;for(let e=192;e<=215;e++)_[e]=hf;_[216]=pf;_[217]=mf;_[218]=yf;_[219]=gf;_[220]=j;_[221]=j;_[222]=j;_[223]=j;for(let e=224;e<=243;e++)_[e]=xo("simple values are not supported");_[244]=j;_[245]=j;_[246]=j;_[247]=bf;_[248]=xo("simple values are not supported");_[249]=wf;_[250]=Ef;_[251]=Sf;_[252]=j;_[253]=j;_[254]=j;_[255]=xf;var Ht=[];for(let e=0;e<24;e++)Ht[e]=new D(h.uint,e,1);for(let e=-1;e>=-24;e--)Ht[31-e]=new D(h.negint,e,1);Ht[64]=new D(h.bytes,new Uint8Array(0),1);Ht[96]=new D(h.string,"",1);Ht[128]=new D(h.array,0,1);Ht[160]=new D(h.map,0,1);Ht[244]=new D(h.false,!1,1);Ht[245]=new D(h.true,!0,1);Ht[246]=new D(h.null,null,1);function Ys(e){switch(e.type){case h.false:return Xt([244]);case h.true:return Xt([245]);case h.null:return Xt([246]);case h.bytes:return e.value.length?void 0:Xt([64]);case h.string:return e.value===""?Xt([96]):void 0;case h.array:return e.value===0?Xt([128]):void 0;case h.map:return e.value===0?Xt([160]):void 0;case h.uint:return e.value<24?Xt([Number(e.value)]):void 0;case h.negint:if(e.value>=-24)return Xt([31-Number(e.value)])}}var S0={float64:!1,mapSorter:I0,quickEncodeToken:Ys},Lf=Object.freeze({float64:!0,mapSorter:T0,quickEncodeToken:Ys});function A0(){let e=[];return e[h.uint.major]=Ut,e[h.negint.major]=po,e[h.bytes.major]=mr,e[h.string.major]=Qu,e[h.array.major]=yo,e[h.map.major]=go,e[h.tag.major]=bo,e[h.float.major]=cn,e}var br=A0(),wo=new nn,fn=class e{constructor(t,r){this.obj=t,this.parent=r}includes(t){let r=this;do if(r.obj===t)return!0;while(r=r.parent);return!1}static createCheck(t,r){if(t&&t.includes(r))throw new Error(`${ho} object contains circular references`);return new e(r,t)}},_e={null:new D(h.null,null),undefined:new D(h.undefined,void 0),true:new D(h.true,!0),false:new D(h.false,!1),emptyArray:new D(h.array,0),emptyMap:new D(h.map,0)},Wt={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new D(h.float,e):e>=0?new D(h.uint,e):new D(h.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new D(h.uint,e):new D(h.negint,e)},Uint8Array(e,t,r,n){return new D(h.bytes,e)},string(e,t,r,n){return new D(h.string,e)},boolean(e,t,r,n){return e?_e.true:_e.false},null(e,t,r,n){return _e.null},undefined(e,t,r,n){return _e.undefined},ArrayBuffer(e,t,r,n){return new D(h.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new D(h.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[_e.emptyArray,new D(h.break)]:_e.emptyArray;n=fn.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=Eo(s,r,n);return r.addBreakTokens?[new D(h.array,e.length),o,new D(h.break)]:[new D(h.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),s=o?e.size:i.length,a;if(s){a=new Array(s),n=fn.createCheck(n,e);let c=!o&&r.ignoreUndefinedProperties,f=0;for(let u of i){let l=o?e.get(u):e[u];c&&l===void 0||(a[f++]=[Eo(u,r,n),Eo(l,r,n)])}f<s&&(a.length=f)}return a?.length?(v0(a,r),r.addBreakTokens?[new D(h.map,a.length),a,new D(h.break)]:[new D(h.map,a.length),a]):r.addBreakTokens===!0?[_e.emptyMap,new D(h.break)]:_e.emptyMap}};Wt.Map=Wt.Object;Wt.Buffer=Wt.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Wt[`${e}Array`]=Wt.DataView;function Eo(e,t={},r){let n=Ps(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||Wt[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=Wt[n];if(!i)throw new Error(`${ho} unsupported type: ${n}`);return i(e,n,t,r)}function v0(e,t){t.mapSorter&&e.sort(t.mapSorter)}function I0(e,t){let r=Array.isArray(e[0])?e[0][0]:e[0],n=Array.isArray(t[0])?t[0][0]:t[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=br[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function T0(e,t){if(e[0]instanceof D&&t[0]instanceof D){let r=e[0],n=t[0];return r._keyBytes||(r._keyBytes=Bf(r.value)),n._keyBytes||(n._keyBytes=Bf(n.value)),fo(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Bf(e){return Nf(e,br,Lf)}function un(e,t,r,n){if(Array.isArray(t))for(let o of t)un(e,o,r,n);else r[t.type.major](e,t,n)}var _f=h.uint.majorEncoded,Cf=h.negint.majorEncoded,B0=h.bytes.majorEncoded,_0=h.string.majorEncoded,Rf=h.array.majorEncoded,C0=h.float.majorEncoded|Vs,R0=h.float.majorEncoded|qs,L0=h.float.majorEncoded|$s,D0=h.float.majorEncoded|Hs,N0=BigInt(-1),U0=BigInt(1);function k0(e){return e.addBreakTokens!==!0}function Df(e,t,r,n){let o=Ps(t),i=r.typeEncoders&&r.typeEncoders[o];if(i){let s=i(t,o,r,n);if(s!=null){un(e,s,br,r);return}}switch(o){case"null":e.push([L0]);return;case"undefined":e.push([D0]);return;case"boolean":e.push([t?R0:C0]);return;case"number":!Number.isInteger(t)||!Number.isSafeInteger(t)?cn(e,new D(h.float,t),r):t>=0?Y(e,_f,t):Y(e,Cf,t*-1-1);return;case"bigint":t>=BigInt(0)?Y(e,_f,t):Y(e,Cf,t*N0-U0);return;case"string":{let s=uo(t);Y(e,_0,s.length),e.push(s);return}case"Uint8Array":Y(e,B0,t.length),e.push(t);return;case"Array":if(!t.length){e.push([Rf]);return}n=fn.createCheck(n,t),Y(e,Rf,t.length);for(let s of t)Df(e,s,r,n);return;case"Object":case"Map":{let s=Wt.Object(t,o,r,n);un(e,s,br,r)}return;default:{let s=Wt[o];if(!s)throw new Error(`${ho} unsupported type: ${o}`);let a=s(t,o,r,n);un(e,a,br,r)}}}function Nf(e,t,r,n){let o=n instanceof Uint8Array,i=o?new lo(n):wo,s=Eo(e,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=t[s.type.major];if(c.encodedSize){let f=c.encodedSize(s,r);if(o||(i=new nn(f)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():rn(i.chunks[0])}}return i.reset(),un(i,s,t,r),i.toBytes(!0)}function Gs(e,t){return t=Object.assign({},S0,t),k0(t)?(wo.reset(),Df(wo,e,t,void 0),wo.toBytes(!0)):Nf(e,br,t)}var K0={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},So=class{constructor(t,r={}){this._pos=0,this.data=t,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let t=this.data[this._pos],r=Ht[t];if(r===void 0){let n=_[t];if(!n)throw new Error(`${V} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},ln=Symbol.for("DONE"),Ao=Symbol.for("BREAK");function O0(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=xr(t,r);if(i===Ao){if(e.value===1/0)break;throw new Error(`${V} got unexpected break to lengthed array`)}if(i===ln)throw new Error(`${V} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function M0(e,t,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<e.value;a++){let c=xr(t,r);if(c===Ao){if(e.value===1/0)break;throw new Error(`${V} got unexpected break to lengthed map`)}if(c===ln)throw new Error(`${V} found map but not enough entries (got ${a} [no key], expected ${e.value})`);if(!n&&typeof c!="string")throw new Error(`${V} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${V} found repeat map key "${c}"`);let f=xr(t,r);if(f===ln)throw new Error(`${V} found map but not enough entries (got ${a} [no value], expected ${e.value})`);n?s.set(c,f):i[c]=f}return n?s:i}function xr(e,t){if(e.done())return ln;let r=e.next();if(h.equals(r.type,h.break))return Ao;if(r.type.terminal)return r.value;if(h.equals(r.type,h.array))return O0(r,e,t);if(h.equals(r.type,h.map))return M0(r,e,t);if(h.equals(r.type,h.tag)){if(t.tags&&typeof t.tags[r.value]=="function"){let n=xr(e,t);return t.tags[r.value](n)}throw new Error(`${V} tag not supported (${r.value})`)}throw new Error("unsupported")}function Uf(e,t){if(!(e instanceof Uint8Array))throw new Error(`${V} data to decode must be a Uint8Array`);t=Object.assign({},K0,t);let r=rn(e),n=t.tokenizer||new So(r,t),o=xr(n,t);if(o===ln)throw new Error(`${V} did not find any content to decode`);if(o===Ao)throw new Error(`${V} got unexpected break`);return[o,e.subarray(n.pos())]}function Xs(e,t){let[r,n]=Uf(e,t);if(n.length>0)throw new Error(`${V} too many terminals, data makes no sense`);return r}var F0=He("ipns:utils"),kf=H("/ipns/"),V0=114,q0=0,$0=18;function Kf(e){let t;if(e.pubKey!=null)try{t=mu(e.pubKey)}catch(r){throw F0.error(r),r}if(t!=null)return t}function Of(e,t,r){let n=H(t);return he([e,r,n])}function Io(e){let t=H("ipns-signature:");return he([t,e])}function dn(e){return"signatureV1"in e?ht.encode({value:H(e.value),signatureV1:e.signatureV1,validityType:e.validityType,validity:H(e.validity),sequence:e.sequence,ttl:e.ttl,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data}):ht.encode({pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data})}function Dt(e){let t=ht.decode(e);if(t.sequence!=null&&(t.sequence=BigInt(t.sequence)),t.ttl!=null&&(t.ttl=BigInt(t.ttl)),t.signatureV2==null||t.data==null)throw new Vt("Missing data or signatureV2");let r=Ff(t.data),n=H0(r.Value),o=Z(r.Validity);if(t.value!=null&&t.signatureV1!=null)return z0(t),{value:n,validityType:ht.ValidityType.EOL,validity:o,sequence:r.Sequence,ttl:r.TTL,pubKey:t.pubKey,signatureV1:t.signatureV1,signatureV2:t.signatureV2,data:t.data};if(t.signatureV2!=null)return{value:n,validityType:ht.ValidityType.EOL,validity:o,sequence:r.Sequence,ttl:r.TTL,pubKey:t.pubKey,signatureV2:t.signatureV2,data:t.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}function Ce(e){return he([kf,e.bytes])}function Mf(e){let t=er(e.slice(kf.length));if(!vo(t,q0)&&!vo(t,$0))throw new Sn("Multihash in IPNS key was not identity or sha2-256");return t}function Pf(e,t,r,n,o){let i;if(t===ht.ValidityType.EOL)i=0;else throw new ze("The validity type is unsupported");return Gs({Value:e,Validity:r,ValidityType:i,Sequence:n,TTL:o})}function Ff(e){let t=Xs(e);if(t.ValidityType===0)t.ValidityType=ht.ValidityType.EOL;else throw new ze("The validity type is unsupported");return Number.isInteger(t.Sequence)&&(t.Sequence=BigInt(t.Sequence)),Number.isInteger(t.TTL)&&(t.TTL=BigInt(t.TTL)),t}function H0(e){let t=Z(e).trim();if(t.startsWith("/"))return t;try{return`/ipfs/${st.decode(e).toV1().toString()}`}catch{}try{return`/ipfs/${st.parse(t).toV1().toString()}`}catch{}throw new Wr("Value must be a valid content path starting with /")}function Vf(e){if(e!=null){let t=Y0(e);if(t!=null)return t.code===V0?`/ipns/${t.toString(Kt)}`:`/ipfs/${t.toV1().toString()}`;if(j0(e))return`/ipns/${Kt.encode(e.bytes)}`;let r=e.toString().trim();if(r.startsWith("/")&&r.length>1)return r}throw new Wr("Value must be a valid content path starting with /")}function z0(e){if(e.data==null)throw new oo("Record data is missing");let t=Ff(e.data);if(!ot(t.Value,e.value??new Uint8Array(0)))throw new Vt('Field "value" did not match between protobuf and CBOR');if(!ot(t.Validity,e.validity??new Uint8Array(0)))throw new Vt('Field "validity" did not match between protobuf and CBOR');if(t.ValidityType!==e.validityType)throw new Vt('Field "validityType" did not match between protobuf and CBOR');if(t.Sequence!==e.sequence)throw new Vt('Field "sequence" did not match between protobuf and CBOR');if(t.TTL!==e.ttl)throw new Vt('Field "ttl" did not match between protobuf and CBOR')}function j0(e){return e.bytes instanceof Uint8Array}function Z0(e){return typeof e?.toCID=="function"}function Y0(e){if(Z0(e))return e.toCID();try{return st.parse(e)}catch{}return st.asCID(e)}function vo(e,t){return e.code===t}var To=He("ipns:validator"),G0=1024*10;async function X0(e,t){let r=Dt(t),n;try{let o=Io(r.data);n=await e.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw To.error("record signature verification failed"),new Vt("Record signature verification failed");if(r.validityType===ht.ValidityType.EOL){if(qf.default.fromString(r.validity).toDate().getTime()<Date.now())throw To.error("record has expired"),new ro("record has expired")}else if(r.validityType!=null)throw To.error("the validity type is unsupported"),new ze("The validity type is unsupported");To("ipns record for %s is valid",r.value)}async function hn(e,t){if(t.byteLength>G0)throw new no("The record is too large");let r=Mf(e),n;vo(r,0)&&(n=yu(r));let o=Dt(t),i=Kf(o)??n;if(i==null)throw new Jr("Could not extract public key from IPNS record or routing key");let s=Ce(i.toMultihash());if(!ot(s,e))throw new Jr("Embedded public key did not match routing key");await X0(i,t)}var $f=Zo(to(),1);var W0=He("ipns"),Hf=300*1e9,J0="/ipns/",Yw=J0.length,zf={v1Compatible:!0,ttlNs:Hf};async function Bo(e,t,r,n,o=zf){let i=new $f.default(Date.now()+Number(n)),s=ht.ValidityType.EOL,a=BigInt(o.ttlNs??Hf);return Q0(e,t,r,s,i.toString(),a,o)}var Q0=async(e,t,r,n,o,i,s=zf)=>{r=BigInt(r);let a=H(o),c=Vf(t),f=H(c),u=Pf(f,n,a,r,i),l=Io(u),g=await e.sign(l),S;if(e.type==="RSA"&&(S=pe(e.publicKey)),s.v1Compatible===!0){let x=await tp(e,f,n,a),T={value:c,signatureV1:x,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:g,data:u};return S!=null&&(T.pubKey=S),T}else{let x={value:c,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:g,data:u};return S!=null&&(x.pubKey=S),x}},tp=async(e,t,r,n)=>{try{let o=Of(t,r,n);return await e.sign(o)}catch(o){throw W0.error("record signature creation failed",o),new eo("Record signature creation failed")}};var Ws=Zo(to(),1);function _o(e,t){let r=t.map((n,o)=>({record:Dt(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===ht.ValidityType.EOL&&o.record.validityType===ht.ValidityType.EOL){let a=Ws.default.fromString(n.record.validity).toDate(),c=Ws.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 wr=BigInt(6e4)*5000000n,jf=5;var Co=class extends Error{static name="RecordsFailedValidationError";constructor(t="Records failed validation"){super(t),this.name="RecordsFailedValidationError"}},Ro=class extends Error{static name="UnsupportedMultibasePrefixError";constructor(t="Unsupported multibase prefix"){super(t),this.name="UnsupportedMultibasePrefixError"}},Lo=class extends Error{static name="UnsupportedMultihashCodecError";constructor(t="Unsupported multihash codec"){super(t),this.name="UnsupportedMultihashCodecError"}},Do=class extends Error{static name="InvalidValueError";constructor(t="Invalid value"){super(t),this.name="InvalidValueError"}};var pn=class extends Error{static name="RecordNotFoundError";name="RecordNotFoundError"};var fe="/",Zf=new TextEncoder().encode(fe),No=Zf[0],Er=class e{_buf;constructor(t,r){if(typeof t=="string")this._buf=H(t);else if(t instanceof Uint8Array)this._buf=t;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==No)throw new Error("Invalid key")}toString(t="utf8"){return Z(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new e(t.join(fe))}static random(){return new e(Math.random().toString().substring(2))}static asKey(t){return t instanceof Uint8Array||typeof t=="string"?new e(t):typeof t.uint8Array=="function"?new e(t.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Zf),this._buf[0]!==No){let t=new Uint8Array(this._buf.byteLength+1);t.fill(No,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===No;)this._buf=this._buf.subarray(0,-1)}less(t){let r=this.list(),n=t.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let i=r[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return r.length<n.length}reverse(){return e.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(fe).slice(1)}type(){return ep(this.baseNamespace())}name(){return rp(this.baseNamespace())}instance(t){return new e(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(fe)||(t+=fe),t+=this.type(),new e(t)}parent(){let t=this.list();return t.length===1?new e(fe):new e(t.slice(0,-1).join(fe))}child(t){return this.toString()===fe?t:t.toString()===fe?this:new e(this.toString()+t.toString(),!1)}isAncestorOf(t){return t.toString()===this.toString()?!1:t.toString().startsWith(this.toString())}isDecendantOf(t){return t.toString()===this.toString()?!1:this.toString().startsWith(t.toString())}isTopLevel(){return this.list().length===1}concat(...t){return e.withNamespaces([...this.namespaces(),...np(t.map(r=>r.namespaces()))])}};function ep(e){let t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function rp(e){let t=e.split(":");return t[t.length-1]}function np(e){return[].concat(...e)}var ip=114,Js=0,Qs=18;function ta(e,t){return e.code===t}var Uo="/dht/record/",sp="/ipns/metadata/";function mn(e){return new Er(Uo+Z(e,"base32"),!1)}function ko(e){return new Er(sp+Z(e,"base32"),!1)}function Yf(e,t){let r=Date.now(),n=t.getTime()+1728e5,o=new Date(e.validity).getTime();return n-r<864e5||o-r<864e5}function ap(e){return e?.asCID===e}function Gf(e){if(!ap(e))return!1;if(e.code!==ip)throw new rt(`CID codec ${e.code} was not libp2p-key`);if(e.multihash.code!==Js&&e.multihash.code!==Qs)throw new rt(`Multihash algorithm codec ${e.multihash.code} was not Identity or SHA256 hash`);return!0}var Xf={[Kt.prefix]:Kt,[X.prefix]:X},Sr=class{routers;localStore;log;constructor(t,r){this.log=t.logger.forComponent("helia:ipns"),this.localStore=r.localStore,this.routers=r.routers}async resolve(t,r={}){let n=ua(t)||An(t)?t.toMultihash():Gf(t)?t.multihash:t,o=Ce(n),i=await this.#e(o,r);return{...await this.#t(i.value,r),record:i}}async#t(t,r={}){let n=t.split("/");try{let o=n[1];if(o==="ipns"){let i=n[2],s=i.substring(0,1),a;if(s==="1"||s==="Q")a=X.decode(`z${i}`);else if(Xf[s]!=null)a=Xf[s].decode(i);else throw new Ro(`Unsupported multibase prefix "${s}"`);let c;try{c=er(a)}catch{c=st.decode(a).multihash}if(!ta(c,Js)&&!ta(c,Qs))throw new Lo(`Unsupported multihash codec "${c.code}"`);let{cid:f}=await this.resolve(c,r),u=n.slice(3).join("/");return{cid:f,path:u===""?void 0:u}}else if(o==="ipfs"){let i=st.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",t),new Do("Invalid value")}async#e(t,r={}){let n=[];if(await this.localStore.has(t,r))if(this.log("record is present in the cache"),r.nocache!==!0)try{let{record:c,created:f}=await this.localStore.get(t,r);this.log("record retrieved from cache"),await hn(t,c),this.log("record was valid");let u=Dt(c),l=Number((u.ttl??wr)/1000000n);if(f.getTime()+l>Date.now())return this.log("record TTL was valid"),u;if(r.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),u;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(t,r)}else this.log("ignoring local cache due to nocache=true option");if(r.offline===!0)throw new pn("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 f;try{f=await c.get(t,{...r,validate:!1})}catch(u){this.log.error("error finding IPNS record using router %s - %e",c.toString(),u),s.push(u);return}try{await hn(t,f),n.push(f)}catch(u){i++,this.log.error("error validating IPNS record from router %s - %e",c.toString(),u)}})),n.length===0)throw i>0?new Co(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`):new pn("Could not find record for routing key");let a=n[_o(t,n)];return await this.localStore.put(t,a,r),Dt(a)}};var It=class extends Event{type;detail;constructor(t,r){super(t),this.type=t,this.detail=r}};var Ko=class{routers;localStore;keychain;constructor(t,r){this.keychain=t.libp2p.services.keychain,this.localStore=r.localStore,this.routers=r.routers}async publish(t,r,n={}){try{let o=await this.#t(t),i=1n,s=Ce(o.publicKey.toMultihash());if(await this.localStore.has(s,n)){let{record:l}=await this.localStore.get(s,n);i=Dt(l).sequence+1n}An(r)&&(r=r.toCID());let a=n.ttl!=null?BigInt(n.ttl)*1000000n:wr,c=n.lifetime??1728e5,f=await Bo(o,r,i,c,{...n,ttlNs:a}),u=dn(f);return n.offline===!0?await this.localStore.put(s,u,{...n,metadata:{keyName:t,lifetime:c}}):await Promise.all(this.routers.map(async l=>{await l.put(s,u,{...n,metadata:{keyName:t,lifetime:c}})})),{record:f,publicKey:o.publicKey}}catch(o){throw n.onProgress?.(new It("ipns:publish:error",o)),o}}async#t(t){try{return await this.keychain.exportKey(t)}catch{let n=await pu("Ed25519");return await this.keychain.importKey(t,n),n}}async unpublish(t,r){let{publicKey:n}=await this.keychain.exportKey(t),o=n.toMultihash(),i=Ce(o);await this.localStore.delete(i,r)}};function Ar(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Oo=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},vr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Oo(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new Oo(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var ea=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Wf(e={}){return up(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function up(e,t){t=t??{};let r=t.onEnd,n=new vr,o,i,s,a=Ar(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((E,w)=>{i=B=>{i=null,n.push(B);try{E(e(n))}catch(A){w(A)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ar()})}},f=E=>i!=null?i(E):(n.push(E),o),u=E=>(n=new vr,i!=null?i({error:E}):(n.push({error:E}),o)),l=E=>{if(s)return o;if(t?.objectMode!==!0&&E?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:E})},g=E=>s?o:(s=!0,E!=null?u(E):f({done:!0})),S=()=>(n=new vr,g(),{done:!0}),x=E=>(g(E),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:S,throw:x,push:l,end:g,get readableLength(){return n.size},onEmpty:async E=>{let w=E?.signal;if(w?.throwIfAborted(),n.isEmpty())return;let B,A;w!=null&&(B=new Promise((N,O)=>{A=()=>{O(new ea)},w.addEventListener("abort",A)}));try{await Promise.race([a.promise,B])}finally{A!=null&&w!=null&&w?.removeEventListener("abort",A)}}},r==null)return o;let T=o;return o={[Symbol.asyncIterator](){return this},next(){return T.next()},throw(E){return T.throw(E),r!=null&&(r(E),r=void 0),{done:!0}},return(){return T.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(E){return T.end(E),r!=null&&(r(E),r=void 0),o},get readableLength(){return T.readableLength},onEmpty:E=>T.onEmpty(E)},o}var ra=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},Jf=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function na(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=t,a,c,u=new Promise((l,g)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){g(Jf(s));return}if(s&&(c=()=>{g(Jf(s))},s.addEventListener("abort",c,{once:!0})),e.then(l,g),r===Number.POSITIVE_INFINITY)return;let S=new ra;a=i.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(x){g(x)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?l():o instanceof Error?g(o):(S.message=o??`Promise timed out after ${r} milliseconds`,g(S))},r)}).finally(()=>{u.clear(),c&&s&&s.removeEventListener("abort",c)});return u.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},u}var fp=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function lp(e,t,r){let n,o=new Promise((i,s)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:f,removeListener:u}=fp(e),l=async(...S)=>{let x=r.multiArgs?S:S[0];if(r.filter)try{if(!await r.filter(x))return}catch(T){n(),s(T);return}c.push(x),r.count===c.length&&(n(),i(c))},g=(...S)=>{n(),s(r.rejectionMultiArgs?S:S[0])};n=()=>{for(let S of a)u(S,l);for(let S of r.rejectionEvents)a.includes(S)||u(S,g)};for(let S of a)f(S,l);for(let S of r.rejectionEvents)a.includes(S)||f(S,g);r.signal&&r.signal.addEventListener("abort",()=>{g(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(o.cancel=n,typeof r.timeout=="number"){let i=na(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function Mo(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=lp(e,t,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function yn(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Po=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};function dp(e){return e.reason}async function Qf(e,t,r){if(t==null)return e;let n=r?.translateError??dp;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((i,s)=>{o=()=>{s(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var Fo=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Ar(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Jt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function hp(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Vo=class{id;fn;options;recipients;status;timeline;controller;constructor(t,r){this.id=hp(),this.status="queued",this.fn=t,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Jt),this.cleanup())}async join(t={}){let r=new Fo(t.signal);return this.recipients.push(r),t.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await Qf(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(r=>{r.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};var qo=class extends vn{concurrency;maxSize;queue;pending;sort;paused;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,t.metricName!=null&&t.metrics?.registerMetricGroup(t.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=t.sort,this.queue=[],this.emitEmpty=yn(this.emitEmpty.bind(this),1),this.emitIdle=yn(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let r of this.queue)if(r.status==="queued"){t=r;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===t){this.queue.splice(r,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Po;let n=new Vo(t,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new Jt)}),this.clear()}async onEmpty(t){this.size!==0&&await Mo(this,"empty",t)}async onSizeLessThan(t,r){this.size<t||await Mo(this,"next",{...r,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Mo(this,"idle",t)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let r=Wf({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 Jt("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",i),this.addEventListener("idle",s),t?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),t?.signal?.removeEventListener("abort",a),n()}}};function tl(e){let t=new globalThis.AbortController;function r(){let i=e.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();t.abort(i);for(let s of e)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let i of e){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of e)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=t.signal;return o.clear=n,o}function el(e,t,r){let n,o,i=!1;function s(){let f={signal:o.signal},u;r?.timeout!=null&&(u=tl([o.signal,AbortSignal.timeout(r.timeout)]),f.signal=u),i=!0,Promise.resolve().then(async()=>{await e(f)}).catch(()=>{}).finally(()=>{u!=null&&(u.aborted?u.clear():u.addEventListener("abort",()=>{u.clear()},{once:!0})),i=!1,!o.signal.aborted&&(n=setTimeout(s,t))})}let a=yn(s,r?.debounce??100),c=!1;return{setInterval:f=>{t!==f&&(t=f,n!=null&&(clearTimeout(n),n=setTimeout(s,t)))},setTimeout:f=>{r??={},r.timeout=f},run:()=>{i||(clearTimeout(n),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,t))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var $o=class{routers;localStore;republishTask;log;keychain;started=!1;republishConcurrency;constructor(t,r){this.log=t.logger.forComponent("helia:ipns"),this.localStore=r.localStore,this.keychain=t.libp2p.services.keychain,this.republishConcurrency=r.republishConcurrency||jf,this.started=t.libp2p.status==="started",this.routers=r.routers??[],this.republishTask=el(this.#t.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#t(t={}){if(!this.started)return;this.log("starting ipns republish records loop");let r=new qo({concurrency:this.republishConcurrency});try{let n=[];for await(let{routingKey:o,record:i,metadata:s,created:a}of this.localStore.list(t)){if(s==null){this.log(`no metadata found for record ${o.toString()}, skipping`);continue}let c;try{c=Dt(i)}catch(g){this.log.error("error unmarshaling record - %e",g);continue}if(!Yf(c,a)){this.log.trace(`skipping record ${o.toString()}within republish threshold`);continue}let f=c.sequence+1n,u=c.ttl??wr,l;try{l=await this.keychain.exportKey(s.keyName)}catch(g){this.log.error("missing key %s, skipping republishing record - %e",s.keyName,g);continue}try{let g=await Bo(l,c.value,f,s.lifetime,{...t,ttlNs:u});n.push({routingKey:o,record:g})}catch(g){this.log.error("error creating updated IPNS record for %s - %e",o,g);continue}}this.log(`found ${n.length} records to republish`);for(let{routingKey:o,record:i}of n)r.add(async()=>{try{let s=dn(i);await Promise.all(this.routers.map(a=>a.put(o,s,t)))}catch(s){this.log.error("error republishing record - %e",s)}},t)}catch(n){this.log.error("error during republish - %e",n)}await r.onIdle(t)}};var gn;(function(e){let t;e.codec=()=>(t==null&&(t=Ie((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:Nt(0),value:Nt(0),timeReceived:""},f=s==null?i.len:i.pos+s;for(;i.pos<f;){let u=i.uint32();switch(u>>>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(u&7);break}}}return c},function*(i,s,a,c={}){let f=s==null?i.len:i.pos+s;for(;i.pos<f;){let u=i.uint32();switch(u>>>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(u&7);break}}}})),t);function r(i){return Ae(i,e.codec())}e.encode=r;function n(i,s){return Se(i,e.codec(),s)}e.decode=n;function o(i,s){return ve(i,e.codec(),s)}e.stream=o})(gn||(gn={}));function rl(e){let t=e.getUTCFullYear(),r=String(e.getUTCMonth()+1).padStart(2,"0"),n=String(e.getUTCDate()).padStart(2,"0"),o=String(e.getUTCHours()).padStart(2,"0"),i=String(e.getUTCMinutes()).padStart(2,"0"),s=String(e.getUTCSeconds()).padStart(2,"0"),a=e.getUTCMilliseconds(),c=String(a*1e3*1e3).padStart(9,"0");return`${t}-${r}-${n}T${o}:${i}:${s}.${c}Z`}function nl(e){let t=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),r=String(e).trim().match(t);if(r==null)throw new Error("Invalid format");let n=parseInt(r[1],10),o=parseInt(r[2],10)-1,i=parseInt(r[3],10),s=parseInt(r[4],10),a=parseInt(r[5],10),c=parseInt(r[6],10),f=parseInt(r[7].slice(0,-6),10);return new Date(Date.UTC(n,o,i,s,a,c,f))}var Re=class e{key;value;timeReceived;constructor(t,r,n){if(!(t instanceof Uint8Array))throw new Error("key must be a Uint8Array");if(!(r instanceof Uint8Array))throw new Error("value must be a Uint8Array");this.key=t,this.value=r,this.timeReceived=n}serialize(){return gn.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:rl(this.timeReceived)}}static deserialize(t){let r=gn.decode(t);return new e(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(t){let r=nl(t.timeReceived);if(t.key==null)throw new Error("key missing from deserialized object");if(t.value==null)throw new Error("value missing from deserialized object");return new e(t.key,t.value,r)}};var ol;(function(e){e[e.SEND_QUERY=0]="SEND_QUERY",e[e.PEER_RESPONSE=1]="PEER_RESPONSE",e[e.FINAL_PEER=2]="FINAL_PEER",e[e.QUERY_ERROR=3]="QUERY_ERROR",e[e.PROVIDER=4]="PROVIDER",e[e.VALUE=5]="VALUE",e[e.ADD_PEER=6]="ADD_PEER",e[e.DIAL_PEER=7]="DIAL_PEER",e[e.PATH_ENDED=8]="PATH_ENDED"})(ol||(ol={}));var bn;(function(e){let t;e.codec=()=>(t==null&&(t=Ie((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},f=s==null?i.len:i.pos+s;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{c.keyName=i.string();break}case 2:{c.lifetime=i.uint32();break}default:{i.skipType(u&7);break}}}return c},function*(i,s,a,c={}){let f=s==null?i.len:i.pos+s;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{yield{field:`${a}.keyName`,value:i.string()};break}case 2:{yield{field:`${a}.lifetime`,value:i.uint32()};break}default:{i.skipType(u&7);break}}}})),t);function r(i){return Ae(i,e.codec())}e.encode=r;function n(i,s){return Se(i,e.codec(),s)}e.decode=n;function o(i,s){return ve(i,e.codec(),s)}e.stream=o})(bn||(bn={}));function Ho(e,t){return{async put(r,n,o={}){try{let i=mn(r);try{let c=await e.get(i),f=Re.deserialize(c);if(ot(f.value,n))return}catch(c){if(c.name!=="NotFoundError")throw c}let s=new Re(r,n,new Date);o.onProgress?.(new It("ipns:routing:datastore:put"));let a=e.batch();a.put(i,s.serialize()),o.metadata!=null&&a.put(ko(r),bn.encode(o.metadata)),await a.commit(o)}catch(i){throw o.onProgress?.(new It("ipns:routing:datastore:error",i)),i}},async get(r,n={}){try{let o=mn(r);n.onProgress?.(new It("ipns:routing:datastore:get"));let i=await e.get(o,n),s=Re.deserialize(i);return{record:s.value,created:s.timeReceived}}catch(o){throw n.onProgress?.(new It("ipns:routing:datastore:error",o)),o}},async has(r,n={}){let o=mn(r);return e.has(o,n)},async delete(r,n){let o=mn(r),i=e.batch();i.delete(o),i.delete(ko(r)),await i.commit(n)},async*list(r={}){try{r.onProgress?.(new It("ipns:routing:datastore:list"));for await(let{key:n,value:o}of e.query({prefix:Uo},r))try{let i=Re.deserialize(o),a=n.toString().substring(Uo.length),c=H(a,"base32"),f=ko(c),u;try{let l=await e.get(f,r);u=bn.decode(l)}catch(l){t.error("Error deserializing metadata for %s - %e",a,l)}yield{routingKey:c,metadata:u,record:i.value,created:i.timeReceived}}catch(i){t.error("Error deserializing record - %e",i)}}catch(n){throw r.onProgress?.(new It("ipns:routing:datastore:error",n)),n}}}}var oa=class{routing;constructor(t){this.routing=t}async put(t,r,n={}){try{await this.routing.put(t,r,n)}catch(o){throw n.onProgress?.(new It("ipns:routing:helia:error",o)),o}}async get(t,r={}){try{return await this.routing.get(t,r)}catch(n){throw r.onProgress?.(new It("ipns:routing:helia:error",n)),n}}toString(){return"HeliaRouting()"}};function xn(e){return new oa(e)}var ia=class{localStore;constructor(t){this.localStore=t}async put(t,r,n){await this.localStore.put(t,r,n)}async get(t,r){let{record:n}=await this.localStore.get(t,r);return n}toString(){return"LocalStoreRouting()"}};function zo(e){return new ia(e)}var jo=class{routers;publisher;republisher;resolver;localStore;started;constructor(t,r={}){this.localStore=Ho(t.datastore,t.logger.forComponent("helia:ipns:local-store")),this.started=t.libp2p.status==="started",this.routers=[zo(this.localStore),xn(t.routing),...r.routers??[]],this.publisher=new Ko(t,{...r,routers:this.routers,localStore:this.localStore}),this.republisher=new $o(t,{...r,routers:this.routers,localStore:this.localStore}),this.resolver=new Sr(t,{...r,routers:this.routers,localStore:this.localStore}),t.events.addEventListener("start",this.start.bind(this)),t.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(t,r,n={}){return this.publisher.publish(t,r,n)}async resolve(t,r={}){return this.resolver.resolve(t,r)}async unpublish(t,r){return this.publisher.unpublish(t,r)}};function yp(e,t={}){return new jo(e,t)}function gp(e,t={}){let r=Ho(e.datastore,e.logger.forComponent("helia:ipns:local-store")),n=[zo(r),xn(e.routing),...t.routers??[]];return new Sr(e,{routers:n,localStore:r})}return ll(bp);})();
14
- /*! Bundled license information:
15
-
16
- @noble/hashes/utils.js:
17
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
18
-
19
- @noble/curves/utils.js:
20
- @noble/curves/abstract/modular.js:
21
- @noble/curves/abstract/curve.js:
22
- @noble/curves/abstract/edwards.js:
23
- @noble/curves/ed25519.js:
24
- @noble/curves/abstract/weierstrass.js:
25
- @noble/curves/secp256k1.js:
26
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
27
- */
10
+ ${e}`)}`:r!=null?`${r}`:`${t.toString()}`}function Dc(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function Bi(t,e=""){if(Dc(t)){let r=_i(t,e);return t.errors.length>0?(e=`${e} `,r+=`
11
+ ${e}${t.errors.map(n=>`${Bi(n,`${e}`)}`).join(`
12
+ ${e}`)}`):r+=`
13
+ ${e}[Error list was empty]`,r.trim()}return _i(t,e)}G.formatters.e=t=>t==null?"undefined":Bi(t);function Lc(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e.useColors=()=>!1,e}function vn(t,e){let r=Lc(`${t}:trace`);return G.enabled(`${t}:trace`)&&G.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=G(`${t}:trace`,e)),Object.assign(G(t,e),{error:G(`${t}:error`,e),trace:r,newScope:n=>vn(`${t}:${n}`,e)})}function Ri(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var Mi=Ir(Pt(),1);var _c=vn("ipns"),Pi=300*1e9,Rc="/ipns/",Xd=Rc.length,$i={v1Compatible:!0,ttlNs:Pi};async function pr(t,e,r,n,o=$i){let i=new Mi.default(Date.now()+Number(n)),s=V.ValidityType.EOL,a=BigInt(o.ttlNs??Pi);return Bc(t,e,r,s,i.toString(),a,o)}var Bc=async(t,e,r,n,o,i,s=$i)=>{r=BigInt(r);let a=z(o),u=Ni(e,n,a,r,i),f=fr(u),l=await t.sign(f,s),p=Pc(t.publicKey)?t.publicKey:void 0,m;if(s.v1Compatible===!0){let w=await Mc(t,e,n,a);m={value:e,signatureV1:w,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:l,data:u,publicKey:p}}else m={value:e,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:l,data:u,publicKey:p};return m.bytes=et(m),m},Mc=async(t,e,r,n,o)=>{try{let i=Ai(e,r,n);return await t.sign(i,o)}catch(i){throw _c.error("record signature creation failed",i),new _t("Record signature creation failed")}};function Pc(t){return t.toMultihash().code!==0}var mr=class{routers;localStore;keychain;constructor(e,r){this.keychain=e.keychain,this.localStore=r.localStore,this.routers=r.routers}async publish(e,r,n={}){try{let o=await this.#e(e,n),i=o.publicKey.toMultihash(),s=vt(i),a=1n;if(await this.localStore.has(s,n)){let{record:m}=await this.localStore.get(s,n);a=(await fe(s,m,this.keychain,n)).sequence+1n}let u=n.ttl!=null?BigInt(n.ttl)*1000000n:Ke,f=n.lifetime??1728e5,l=await pr(o,r,a,f,{...n,ttlNs:u}),p=et(l);return n.offline===!0?await this.localStore.put(s,p,{...n,metadata:{keyName:e,lifetime:f}}):await Promise.all(this.routers.map(async m=>{await m.put(s,p,{...n,metadata:{keyName:e,lifetime:f}})})),{record:{...l,publicKey:o.publicKey},name:`/ipns/${o.publicKey.toCID().toString(ee)}`,publicKey:o.publicKey}}catch(o){throw n.onProgress?.(new j("ipns:publish:error",o)),o}}async#e(e,r){try{return await this.keychain.exportKey(e,r)}catch(n){if(n.name==="NotFoundError")return this.keychain.generateKey(e,r);throw n}}async unpublish(e,r){let o=(await this.keychain.exportKey(e,r)).publicKey.toMultihash(),i=vt(o);await this.localStore.delete(i,r)}};function rt(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var gr=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},nt=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new gr(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new gr(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Cn=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Vi(t={}){return Vc(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function Vc(t,e){e=e??{};let r=e.onEnd,n=new nt,o,i,s,a=rt(),u=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((x,T)=>{i=k=>{i=null,n.push(k);try{x(t(n))}catch(F){T(F)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=rt()})}},f=x=>i!=null?i(x):(n.push(x),o),l=x=>(n=new nt,i!=null?i({error:x}):(n.push({error:x}),o)),p=x=>{if(s)return o;if(e?.objectMode!==!0&&x?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:x})},m=x=>s?o:(s=!0,x!=null?l(x):f({done:!0})),w=()=>(n=new nt,m(),{done:!0}),S=x=>(m(x),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:u,return:w,throw:S,push:p,end:m,get readableLength(){return n.size},onEmpty:async x=>{let T=x?.signal;if(T?.throwIfAborted(),n.isEmpty())return;let k,F;T!=null&&(k=new Promise((P,B)=>{F=()=>{B(new Cn)},T.addEventListener("abort",F)}));try{await Promise.race([a.promise,k])}finally{F!=null&&T!=null&&T?.removeEventListener("abort",F)}}},r==null)return o;let E=o;return o={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(x){return E.throw(x),r!=null&&(r(x),r=void 0),{done:!0}},return(){return E.return(),r!=null&&(r(),r=void 0),{done:!0}},push:p,end(x){return E.end(x),r!=null&&(r(x),r=void 0),o},get readableLength(){return E.readableLength},onEmpty:x=>E.onEmpty(x)},o}var In=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Oi=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function An(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,u,l=new Promise((p,m)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){m(Oi(s));return}if(s&&(u=()=>{m(Oi(s))},s.addEventListener("abort",u,{once:!0})),t.then(p,m),r===Number.POSITIVE_INFINITY)return;let w=new In;a=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(S){m(S)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?p():o instanceof Error?m(o):(w.message=o??`Promise timed out after ${r} milliseconds`,m(w))},r)}).finally(()=>{l.clear(),u&&s&&s.removeEventListener("abort",u)});return l.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},l}var Oc=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function zc(t,e,r){let n,o=new Promise((i,s)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),u=[],{addListener:f,removeListener:l}=Oc(t),p=async(...w)=>{let S=r.multiArgs?w:w[0];if(r.filter)try{if(!await r.filter(S))return}catch(E){n(),s(E);return}u.push(S),r.count===u.length&&(n(),i(u))},m=(...w)=>{n(),s(r.rejectionMultiArgs?w:w[0])};n=()=>{for(let w of a)l(w,p);for(let w of r.rejectionEvents)a.includes(w)||l(w,m)};for(let w of a)f(w,p);for(let w of r.rejectionEvents)a.includes(w)||f(w,m);r.signal&&r.signal.addEventListener("abort",()=>{m(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(u)});if(o.cancel=n,typeof r.timeout=="number"){let i=An(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function yr(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=zc(t,e,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function At(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var xr=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function qc(t){return t.reason}async function zi(t,e,r){if(e==null)return t;let n=r?.translateError??qc;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var br=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=rt(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new me)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Kc(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var wr=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,r){this.id=Kc(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new me),this.cleanup())}async join(e){let r=new br(e);return this.recipients.push(r),e?.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await zi(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(!this.dispatchingProgress){this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(r)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var Er=class extends Gt{concurrency;maxSize;queue;pending;sort;paused;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=e.sort,this.queue=[],this.emitEmpty=At(this.emitEmpty.bind(this),1),this.emitIdle=At(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let r of this.queue)if(r.status==="queued"){e=r;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===e){this.queue.splice(r,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}async add(e,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new xr;let n=new wr(e,r);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(r).then(i=>(this.safeDispatchEvent("completed",{detail:i}),this.safeDispatchEvent("success",{detail:{job:n,result:i}}),i)).catch(i=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:i}}),i});return this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new me)}),this.clear()}async onEmpty(e){this.size!==0&&await yr(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await yr(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await yr(this,"idle",e)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let r=Vi({objectMode:!0}),n=u=>{u!=null?this.abort():this.clear(),r.end(u)},o=u=>{u.detail!=null&&r.push(u.detail)},i=u=>{n(u.detail.error)},s=()=>{n()},a=()=>{n(new me("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",i),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",i),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};function qi(t){let e=new globalThis.AbortController;function r(){let i=t.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();e.abort(i);for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let i of t){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=e.signal;return o.clear=n,o}function Ki(t,e,r){let n,o,i=!1;function s(){let f={signal:o.signal},l;r?.timeout!=null&&(l=qi([o.signal,AbortSignal.timeout(r.timeout)]),f.signal=l),i=!0,Promise.resolve().then(async()=>{await t(f)}).catch(()=>{}).finally(()=>{l!=null&&(l.aborted?l.clear():l.addEventListener("abort",()=>{l.clear()},{once:!0})),i=!1,!o.signal.aborted&&(n=setTimeout(s,e))})}let a=At(s,r?.debounce??100),u=!1;return{setInterval:f=>{e!==f&&(e=f,n!=null&&(clearTimeout(n),n=setTimeout(s,e)))},setTimeout:f=>{r??={},r.timeout=f},run:()=>{i||(clearTimeout(n),a())},start:()=>{u||(u=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,e))},stop:()=>{clearTimeout(n),o?.abort(),u=!1}}}var Sr=class{routers;localStore;republishTask;log;keychain;started=!1;republishConcurrency;constructor(e,r){this.log=e.logger.forComponent("helia:ipns"),this.localStore=r.localStore,this.keychain=e.keychain,this.republishConcurrency=r.republishConcurrency||Kn,this.started=!1,this.routers=r.routers??[],this.republishTask=Ki(this.#e.bind(this),r.republishInterval??36e5,{runImmediately:!0}),this.started&&this.republishTask.start()}start(){this.started||(this.started=!0,this.republishTask.start())}stop(){this.started&&(this.started=!1,this.republishTask.stop())}async#e(e={}){if(!this.started)return;this.log("starting ipns republish records loop");let r=new Er({concurrency:this.republishConcurrency});try{let n=[],o=0;for await(let{routingKey:i,record:s,metadata:a,created:u}of this.localStore.list(e)){if(o++,a==null){this.log("no metadata found for record %b, skipping",i);continue}let f;try{f=await fe(i,s,this.keychain,e)}catch(w){this.log.error("error unmarshaling record - %e",w);continue}if(!Ii(f,u)){this.log.trace("skipping record %b within republish threshold",i);continue}let l=f.sequence+1n,p=f.ttl??Ke,m;try{m=await this.keychain.exportKey(a.keyName)}catch(w){this.log.error("missing key %s, skipping republishing record - %e",a.keyName,w);continue}try{let w=await pr(m,f.value,l,a.lifetime,{...e,ttlNs:p});n.push({routingKey:i,record:w})}catch(w){this.log.error("error creating updated IPNS record for %s - %e",i,w);continue}}this.log(`found ${n.length}/${o} records to republish`);for(let{routingKey:i,record:s}of n)r.add(async()=>{try{let a=et(s);await Promise.all(this.routers.map(u=>u.put(i,a,e)))}catch(a){this.log.error("error republishing record - %e",a)}},e)}catch(n){this.log.error("error during republish - %e",n)}await r.onIdle(e)}};var Nt;(function(t){let e;t.codec=()=>(e==null&&(e=Le((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.key!=null&&i.key.byteLength>0&&(s.uint32(10),s.bytes(i.key)),i.value!=null&&i.value.byteLength>0&&(s.uint32(18),s.bytes(i.value)),i.timeReceived!=null&&i.timeReceived!==""&&(s.uint32(42),s.string(i.timeReceived)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let u={key:Mr(0),value:Mr(0),timeReceived:""},f=s==null?i.len:i.pos+s;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{u.key=i.bytes();break}case 2:{u.value=i.bytes();break}case 5:{u.timeReceived=i.string();break}default:{i.skipType(l&7);break}}}return u},function*(i,s,a,u={}){let f=s==null?i.len:i.pos+s;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{yield{field:`${a}.key`,value:i.bytes()};break}case 2:{yield{field:`${a}.value`,value:i.bytes()};break}case 5:{yield{field:`${a}.timeReceived`,value:i.string()};break}default:{i.skipType(l&7);break}}}})),e);function r(i){return Ue(i,t.codec())}t.encode=r;function n(i,s){return ke(i,t.codec(),s)}t.decode=n;function o(i,s){return De(i,t.codec(),s)}t.stream=o})(Nt||(Nt={}));function Hi(t){let e=t.getUTCFullYear(),r=String(t.getUTCMonth()+1).padStart(2,"0"),n=String(t.getUTCDate()).padStart(2,"0"),o=String(t.getUTCHours()).padStart(2,"0"),i=String(t.getUTCMinutes()).padStart(2,"0"),s=String(t.getUTCSeconds()).padStart(2,"0"),a=t.getUTCMilliseconds(),u=String(a*1e3*1e3).padStart(9,"0");return`${e}-${r}-${n}T${o}:${i}:${s}.${u}Z`}function ji(t){let e=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),r=String(t).trim().match(e);if(r==null)throw new Error("Invalid format");let n=parseInt(r[1],10),o=parseInt(r[2],10)-1,i=parseInt(r[3],10),s=parseInt(r[4],10),a=parseInt(r[5],10),u=parseInt(r[6],10),f=parseInt(r[7].slice(0,-6),10);return new Date(Date.UTC(n,o,i,s,a,u,f))}var Ce=class t{key;value;timeReceived;constructor(e,r,n){if(!(e instanceof Uint8Array))throw new Error("key must be a Uint8Array");if(!(r instanceof Uint8Array))throw new Error("value must be a Uint8Array");this.key=e,this.value=r,this.timeReceived=n}serialize(){return Nt.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:Hi(this.timeReceived)}}static deserialize(e){let r=Nt.decode(e);return new t(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(e){let r=ji(e.timeReceived);if(e.key==null)throw new Error("key missing from deserialized object");if(e.value==null)throw new Error("value missing from deserialized object");return new t(e.key,e.value,r)}};var Gi;(function(t){t[t.SEND_QUERY=0]="SEND_QUERY",t[t.PEER_RESPONSE=1]="PEER_RESPONSE",t[t.FINAL_PEER=2]="FINAL_PEER",t[t.QUERY_ERROR=3]="QUERY_ERROR",t[t.PROVIDER=4]="PROVIDER",t[t.VALUE=5]="VALUE",t[t.ADD_PEER=6]="ADD_PEER",t[t.DIAL_PEER=7]="DIAL_PEER",t[t.PATH_ENDED=8]="PATH_ENDED"})(Gi||(Gi={}));var kt;(function(t){let e;t.codec=()=>(e==null&&(e=Le((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.keyName!=null&&i.keyName!==""&&(s.uint32(10),s.string(i.keyName)),i.lifetime!=null&&i.lifetime!==0&&(s.uint32(16),s.uint32(i.lifetime)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let u={keyName:"",lifetime:0},f=s==null?i.len:i.pos+s;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{u.keyName=i.string();break}case 2:{u.lifetime=i.uint32();break}default:{i.skipType(l&7);break}}}return u},function*(i,s,a,u={}){let f=s==null?i.len:i.pos+s;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{yield{field:`${a}.keyName`,value:i.string()};break}case 2:{yield{field:`${a}.lifetime`,value:i.uint32()};break}default:{i.skipType(l&7);break}}}})),e);function r(i){return Ue(i,t.codec())}t.encode=r;function n(i,s){return ke(i,t.codec(),s)}t.decode=n;function o(i,s){return De(i,t.codec(),s)}t.stream=o})(kt||(kt={}));function Tr(t,e){return{async put(r,n,o={}){try{let i=Tt(r);try{let u=await t.get(i),f=Ce.deserialize(u);if(ht(f.value,n))return}catch(u){if(u.name!=="NotFoundError")throw u}let s=new Ce(r,n,new Date);o.onProgress?.(new j("ipns:routing:datastore:put"));let a=t.batch();a.put(i,s.serialize()),o.metadata!=null&&a.put(lr(r),kt.encode(o.metadata)),await a.commit(o)}catch(i){throw o.onProgress?.(new j("ipns:routing:datastore:error",i)),i}},async get(r,n={}){try{let o=Tt(r);n.onProgress?.(new j("ipns:routing:datastore:get"));let i=await t.get(o,n),s=Ce.deserialize(i);return{record:s.value,created:s.timeReceived}}catch(o){throw n.onProgress?.(new j("ipns:routing:datastore:error",o)),o}},async has(r,n={}){let o=Tt(r);return t.has(o,n)},async delete(r,n){let o=Tt(r),i=t.batch();i.delete(o),i.delete(lr(r)),await i.commit(n)},async*list(r={}){try{r.onProgress?.(new j("ipns:routing:datastore:list"));for await(let{key:n,value:o}of t.query({prefix:ur},r))try{let i=Ce.deserialize(o),a=n.toString().substring(ur.length),u=z(a,"base32"),f=lr(u),l;try{let p=await t.get(f,r);l=kt.decode(p)}catch(p){e.error("Error deserializing metadata for %s - %e",a,p)}yield{routingKey:u,metadata:l,record:i.value,created:i.timeReceived}}catch(i){e.error("Error deserializing record - %e",i)}}catch(n){throw r.onProgress?.(new j("ipns:routing:datastore:error",n)),n}}}}var Nn=class{routing;constructor(e){this.routing=e}async put(e,r,n={}){try{await this.routing.put(e,r,n)}catch(o){throw n.onProgress?.(new j("ipns:routing:helia:error",o)),o}}async get(e,r={}){try{return await this.routing.get(e,r)}catch(n){throw r.onProgress?.(new j("ipns:routing:helia:error",n)),n}}toString(){return"HeliaRouting()"}};function Ft(t){return new Nn(t)}var kn=class{localStore;constructor(e){this.localStore=e}async put(e,r,n){await this.localStore.put(e,r,n)}async get(e,r){let{record:n}=await this.localStore.get(e,r);return n}toString(){return"LocalStoreRouting()"}};function vr(t){return new kn(t)}var Cr=class{routers;publisher;republisher;resolver;localStore;components;started;constructor(e,r={}){this.localStore=Tr(e.datastore,e.logger.forComponent("helia:ipns:local-store")),this.components=e,this.started=!1,this.routers=[vr(this.localStore),Ft(e.routing),...r.routers??[]],this.publisher=new mr(e,{...r,routers:this.routers,localStore:this.localStore}),this.republisher=new Sr(e,{...r,routers:this.routers,localStore:this.localStore}),this.resolver=new tt(e,{...r,routers:this.routers,localStore:this.localStore}),e.events.addEventListener("start",this.start.bind(this)),e.events.addEventListener("stop",this.stop.bind(this)),this.started&&this.republisher.start();for(let n of Object.values(this.components))if(Gc(n))for(let o of Object.values(n.services))Yc(o)&&(o.selectors.ipns=async(i,s)=>{let a=await Promise.all(s.map(u=>fe(i,u,this.components.keychain)));return Kt(i,a)},o.validators.ipns=async(i,s)=>{let a=await fe(i,s,this.components.keychain);await It(a)})}start(){this.started||(this.started=!0,this.republisher.start())}stop(){this.started&&(this.started=!1,this.republisher.stop())}async publish(e,r,n={}){return this.publisher.publish(e,Fi(r),n)}async*resolve(e,r={}){let{digest:n}=Ct(e);yield*this.resolver.resolve(n,r)}async unpublish(e,r){return this.publisher.unpublish(e,r)}};function Gc(t){return t?.services!=null}function Yc(t){return t?.validators!=null&&t?.selectors!=null}function Xc(t,e={}){return new Cr(t,e)}function Jc(t,e={}){let r=Tr(t.datastore,t.logger.forComponent("helia:ipns:local-store")),n=[vr(r),Ft(t.routing),...e.routers??[]];return new tt(t,{routers:n,localStore:r})}return es(Wc);})();
28
14
  return HeliaIpns}));
29
15
  //# sourceMappingURL=index.min.js.map