@helia/ipns 10.1.0-dc9e15bc → 10.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,16 +1,16 @@
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 jf=Object.create;var pn=Object.defineProperty;var Yf=Object.getOwnPropertyDescriptor;var Zf=Object.getOwnPropertyNames;var Gf=Object.getPrototypeOf,Xf=Object.prototype.hasOwnProperty;var Wf=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},Ae=(t,e)=>{for(var r in e)pn(t,r,{get:e[r],enumerable:!0})},ea=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Zf(e))!Xf.call(t,o)&&o!==r&&pn(t,o,{get:()=>e[o],enumerable:!(n=Yf(e,o))||n.enumerable});return t};var oi=(t,e,r)=>(r=t!=null?jf(Gf(t)):{},ea(e||!t||!t.__esModule?pn(r,"default",{value:t,enumerable:!0}):r,t)),Qf=t=>ea(pn({},"__esModule",{value:!0}),t);var _n=Wf((Q0,Pi)=>{var W0=(function(){typeof Pi<"u"&&(Pi.exports=v);var t=86400,e=3200,r=146097*e/400,n=t*r,o=1e3*n,i=864e13,s=4294967296,a=1e6,c="000000000",f=Math.trunc||function(w){var S=w-w%1;return S==0&&(w<0||w===0&&1/w!=1/0)?-0:S},u=v.prototype,l=(v.fromDate=function(w){return new v(+w)},v.fromInt64BE=N(0,1,2,3,0,4),v.fromInt64LE=N(3,2,1,0,4,0),v.fromString=function(F){var S,I=new v,F=(F+="").replace(/^\s*[+\-]?\d+/,function(q){var q=+q,C=1970+(q-1970)%400;return I.year=q-C,C}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(x,q,C){return q<0&&(C*=-1),S=6e4*(60*+q+ +C),""}).replace(/\.\d+$/,function(x){return I.nano=+(x+c).substr(1,9),""}).split(/\D+/);if(1<F.length?F[1]--:F[1]=0,I.time=S=Date.UTC.apply(Date,F)-(S||0),isNaN(S))throw new TypeError("Invalid Date");return b(I)},v.fromTimeT=function(w){return B(w,0)},u.year=0,u.time=0,u.nano=0,u.addNano=function(w){return this.nano+=+w||0,this},u.getNano=function(){var w=b(this);return(w.time%1e3*a+ +w.nano+1e9)%1e9},u.getTimeT=function(){var S=b(this),w=Math.floor(S.time/1e3),S=S.year;return S&&(w+=S*r*t/e),w},u.getYear=function(){return this.toDate().getUTCFullYear()+this.year},u.toDate=function(){return E(b(this).time)},u.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},u.toString=function(w){var S=this,I=S.toDate(),F={H:function(){return V(I.getUTCHours())},L:function(){return $(I.getUTCMilliseconds(),3)},M:function(){return V(I.getUTCMinutes())},N:function(){return $(S.getNano(),9)},S:function(){return V(I.getUTCSeconds())},Y:function(){var x=S.getYear();return 999999<x?"+"+x:9999<x?"+"+$(x,6):0<=x?$(x,4):-999999<=x?"-"+$(-x,6):x},a:function(){return m[I.getUTCDay()]},b:function(){return h[I.getUTCMonth()]},d:function(){return V(I.getUTCDate())},e:function(){return(function(x){return(9<x?"":" ")+(0|x)})(I.getUTCDate())},m:function(){return V(I.getUTCMonth()+1)}};return(function x(q){return q.replace(/%./g,function(C){var p=C[1],A=L[p],p=F[p];return A?x(A):p?p():C})})(w||l)},u.writeInt64BE=y(0,1,2,3,0,4),u.writeInt64LE=y(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],m=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],L={"%":"%",F:"%Y-%m-%d",n:`
3
- `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return v;function v(w,S,I){var F=this;if(!(F instanceof v))return new v(w,S,I);F.time=+w||0,F.nano=+S||0,F.year=+I||0,b(F)}function b(w){var S,I,F,x=w.year,q=w.time,C=w.nano,A=((C<0||a<=C)&&(C-=(I=Math.floor(C/a))*a,q+=I,I=1),x%e);return(q<-i||i<q||A)&&((S=f(q/o))&&(x+=S*e,q-=S*o),(F=E(q)).setUTCFullYear(A+F.getUTCFullYear()),F=(q=+F)+(S=f((x-=A)/e))*o,S&&-i<=F&&F<=i&&(x-=S*e,q=F),I=1),I&&(w.year=x,w.time=q,w.nano=C),w}function E(w){var S=new Date(0);return S.setTime(w),S}function B(x,F){x=+x||0;var I=f((F=(F|0)*s)/n)+f(x/n),F=F%n+x%n,x=f(F/n);return x&&(I+=x,F-=x*n),new v(1e3*F,0,I*e)}function y(w,S,I,F,x,q){return function(A,p){var _=b(this);A=A||new Array(8),U(A,p|=0);var M=Math.floor(_.time/1e3),_=_.year*(r*t/e),T=f(_/s)+f(M/s),_=_%s+M%s,M=Math.floor(_/s);return M&&(T+=M,_-=M*s),C(A,p+x,T),C(A,p+q,_),A};function C(A,p,T){A[p+w]=T>>24&255,A[p+S]=T>>16&255,A[p+I]=T>>8&255,A[p+F]=255&T}}function N(w,S,I,F,x,q){return function(A,p){U(A,p|=0);var T=C(A,p+x);return B(C(A,p+q),T)};function C(A,p){return 16777216*A[p+w]+(A[p+S]<<16|A[p+I]<<8|A[p+F])}}function U(w,S){if(w=w&&w.length,w==null)throw new TypeError("Invalid Buffer");if(w<S+8)throw new RangeError("Out of range")}function V(w){return(9<w?"":"0")+(0|w)}function $(w,S){return(c+(0|w)).substr(-S)}})()});var pm={};Ae(pm,{IPNSEntry:()=>Q,createIPNSRecord:()=>ur,heliaIPNSRouting:()=>Ar,ipns:()=>dm,ipnsResolver:()=>hm,ipnsSelector:()=>St,ipnsValidator:()=>Qe,multihashFromIPNSRoutingKey:()=>io,multihashToIPNSRoutingKey:()=>it,pubSubIPNSRouting:()=>$f});var ui={};Ae(ui,{base32:()=>lt,base32hex:()=>ul,base32hexpad:()=>ll,base32hexpadupper:()=>dl,base32hexupper:()=>fl,base32pad:()=>al,base32padupper:()=>cl,base32upper:()=>sl,base32z:()=>hl});var ym=new Uint8Array(0);function ra(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 Le(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Nt(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Nt(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function na(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var ta=4096;function oa(t){let e=t.length;if(e<=ta)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=ta));return r}function Jf(t){return t?.buffer instanceof ArrayBuffer}function Nt(t){return Jf(t)?t:t.slice()}function el(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),a=s.charCodeAt(0);if(n[a]!==255)throw new TypeError(s+" is ambiguous");if(n[a]=i,r){var c=s.toLowerCase().charCodeAt(0),f=s.toUpperCase().charCodeAt(0);c!==a&&(n[c]=i),f!==a&&(n[f]=i)}}var u=t.length,l=t.charAt(0),h=Math.log(u)/Math.log(256),m=Math.log(256)/Math.log(u);function L(E){if(E instanceof Uint8Array||(ArrayBuffer.isView(E)?E=new Uint8Array(E.buffer,E.byteOffset,E.byteLength):Array.isArray(E)&&(E=Uint8Array.from(E))),!(E instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(E.length===0)return"";for(var B=0,y=0,N=0,U=E.length;N!==U&&E[N]===0;)N++,B++;for(var V=(U-N)*m+1>>>0,$=new Uint8Array(V);N!==U;){for(var w=E[N],S=0,I=V-1;(w!==0||S<y)&&I!==-1;I--,S++)w+=256*$[I]>>>0,$[I]=w%u>>>0,w=w/u>>>0;if(w!==0)throw new Error("Non-zero carry");y=S,N++}for(var F=V-y;F!==V&&$[F]===0;)F++;for(var x=l.repeat(B);F<V;++F)x+=t.charAt($[F]);return x}function v(E){if(typeof E!="string")throw new TypeError("Expected String");if(E.length===0)return new Uint8Array;var B=0;if(E[B]!==" "){for(var y=0,N=0;E[B]===l;)y++,B++;for(var U=(E.length-B)*h+1>>>0,V=new Uint8Array(U);E[B];){var $=n[E.charCodeAt(B)];if($===255)return;for(var w=0,S=U-1;($!==0||w<N)&&S!==-1;S--,w++)$+=u*V[S]>>>0,V[S]=$%256>>>0,$=$/256>>>0;if($!==0)throw new Error("Non-zero carry");N=w,B++}if(E[B]!==" "){for(var I=U-N;I!==U&&V[I]===0;)I++;for(var F=new Uint8Array(y+(U-I)),x=y;I!==U;)F[x++]=V[I++];return F}}}function b(E){var B=v(E);if(B)return B;throw new Error(`Non-${e} character`)}return{encode:L,decodeUnsafe:v,decode:b}}var tl=el,rl=tl,sa=rl;var ii=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")}},si=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 aa(this,e)}},ai=class{decoders;constructor(e){this.decoders=e}or(e){return aa(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 aa(t,e){return new ai({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var ci=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 ii(e,r,n),this.decoder=new si(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Zt({name:t,prefix:e,encode:r,decode:n}){return new ci(t,e,r,n)}function ft({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:i}=sa(r,t,n);return Zt({prefix:e,name:t,encode:o,decode:s=>Le(i(s))})}function nl(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let f=0;f<o;++f){let u=e[t[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 ol(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],s+=8;s>r;)s-=r,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function il(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let o=t[n].toLowerCase(),i=t[n].toUpperCase();o!==t[n]&&(r[o]=n),i!==t[n]&&(r[i]=n)}return r}function ie({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let i=il(n,o);return Zt({prefix:e,name:t,encode(s){return ol(s,n,r)},decode(s){return nl(s,i,r,t)}})}var lt=ie({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),sl=ie({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),al=ie({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),cl=ie({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),ul=ie({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),fl=ie({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),ll=ie({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),dl=ie({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),hl=ie({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var fi={};Ae(fi,{base36:()=>we,base36upper:()=>pl});var we=ft({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),pl=ft({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var li={};Ae(li,{base58btc:()=>J,base58flickr:()=>ml});var J=ft({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ml=ft({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var yl=fa,ca=128,gl=127,bl=~gl,wl=Math.pow(2,31);function fa(t,e,r){e=e||[],r=r||0;for(var n=r;t>=wl;)e[r++]=t&255|ca,t/=128;for(;t&bl;)e[r++]=t&255|ca,t>>>=7;return e[r]=t|0,fa.bytes=r-n+1,e}var xl=di,El=128,ua=127;function di(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw di.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&ua)<<o:(s&ua)*Math.pow(2,o),o+=7}while(s>=El);return di.bytes=i-n,r}var Sl=Math.pow(2,7),vl=Math.pow(2,14),Al=Math.pow(2,21),Tl=Math.pow(2,28),Bl=Math.pow(2,35),Il=Math.pow(2,42),Cl=Math.pow(2,49),_l=Math.pow(2,56),Dl=Math.pow(2,63),Rl=function(t){return t<Sl?1:t<vl?2:t<Al?3:t<Tl?4:t<Bl?5:t<Il?6:t<Cl?7:t<_l?8:t<Dl?9:10},Ll={encode:yl,decode:xl,encodingLength:Rl},Nl=Ll,Ir=Nl;function Cr(t,e=0){let r=Ir.decode(t,e),n=Ir.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function Gt(t,e,r=0){return Ir.encode(t,e,r),e}function Xt(t){return Ir.encodingLength(t)}function Qt(t,e){let r=e.byteLength,n=Xt(t),o=n+Xt(r),i=new Uint8Array(o+r);return Gt(t,i,0),Gt(r,i,n),i.set(e,o),new Wt(t,r,e,i)}function dt(t){let e=Le(t),[r,n]=Cr(e),[o,i]=Cr(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Wt(r,o,s,e)}function la(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ra(t.bytes,r.bytes)}}var Wt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=Nt(n),this.bytes=Nt(o)}};function da(t,e){let{bytes:r,version:n}=t;return n===0?kl(r,hi(t),e??J.encoder):Fl(r,hi(t),e??lt.encoder)}var ha=new WeakMap;function hi(t){let e=ha.get(t);if(e==null){let r=new Map;return ha.set(t,r),r}return e}var te=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=Nt(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!==_r)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ol)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=Qt(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&&la(e.multihash,n.multihash)}toString(e){return da(this,e)}toJSON(){return{"/":da(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??pa(n,o,i.bytes))}else if(r[Pl]===!0){let{version:n,multihash:o,code:i}=r,s=dt(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!==_r)throw new Error(`Version 0 CID must use dag-pb (code: ${_r}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=pa(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,_r,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=Le(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 Wt(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,h]=Cr(e.subarray(r));return r+=h,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(e,r){let[n,o]=Ul(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 hi(i).set(n,e),i}};function Ul(t,e){switch(t[0]){case"Q":{let r=e??J;return[J.prefix,r.decode(`${J.prefix}${t}`)]}case J.prefix:{let r=e??J;return[J.prefix,r.decode(t)]}case lt.prefix:{let r=e??lt;return[lt.prefix,r.decode(t)]}case we.prefix:{let r=e??we;return[we.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 kl(t,e,r){let{prefix:n}=r;if(n!==J.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 Fl(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 _r=112,Ol=18;function pa(t,e,r){let n=Xt(t),o=n+Xt(e),i=new Uint8Array(o+r.byteLength);return Gt(t,i,0),Gt(e,i,n),i.set(r,o),i}var Pl=Symbol.for("@ipld/js-cid/CID");var yn=BigInt(6e4)*5000000n,ma=5;var gn=class extends Error{static name="RecordsFailedValidationError";name="RecordsFailedValidationError"},pt=class extends Error{static name="InvalidValueError";name="InvalidValueError"},bn=class extends Error{static name="InvalidTopicError";name="InvalidTopicError"},Dr=class extends Error{static name="RecordNotFoundError";name="RecordNotFoundError"},wn=class extends Error{static name="SignatureCreationError";name="SignatureCreationError"},Pe=class extends Error{static name="SignatureVerificationError";name="SignatureVerificationError"},xn=class extends Error{static name="RecordExpiredError";name="RecordExpiredError"},Jt=class extends Error{static name="UnsupportedValidityError";name="UnsupportedValidityError"},En=class extends Error{static name="RecordTooLargeError";name="RecordTooLargeError"},Sn=class extends Error{static name="InvalidRecordDataError";name="InvalidRecordDataError"},vn=class extends Error{static name="InvalidEmbeddedPublicKeyError";name="InvalidEmbeddedPublicKeyError"};function Ne(t=0){return new Uint8Array(t)}function Te(t=0){return new Uint8Array(t)}var Ml=Math.pow(2,7),Kl=Math.pow(2,14),Vl=Math.pow(2,21),ya=Math.pow(2,28),ga=Math.pow(2,35),ba=Math.pow(2,42),wa=Math.pow(2,49),ge=128,mt=127;function Rr(t){if(t<Ml)return 1;if(t<Kl)return 2;if(t<Vl)return 3;if(t<ya)return 4;if(t<ga)return 5;if(t<ba)return 6;if(t<wa)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function xa(t,e,r=0){switch(Rr(t)){case 8:e[r++]=t&255|ge,t/=128;case 7:e[r++]=t&255|ge,t/=128;case 6:e[r++]=t&255|ge,t/=128;case 5:e[r++]=t&255|ge,t/=128;case 4:e[r++]=t&255|ge,t>>>=7;case 3:e[r++]=t&255|ge,t>>>=7;case 2:e[r++]=t&255|ge,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Ea(t,e){let r=t[e],n=0;if(n+=r&mt,r<ge||(r=t[e+1],n+=(r&mt)<<7,r<ge)||(r=t[e+2],n+=(r&mt)<<14,r<ge)||(r=t[e+3],n+=(r&mt)<<21,r<ge)||(r=t[e+4],n+=(r&mt)*ya,r<ge)||(r=t[e+5],n+=(r&mt)*ga,r<ge)||(r=t[e+6],n+=(r&mt)*ba,r<ge)||(r=t[e+7],n+=(r&mt)*wa,r<ge))return n;throw new RangeError("Could not decode varint")}function $l(t){return t.buffer instanceof ArrayBuffer}function xe(t){return $l(t)?t:t.slice()}var pi=new Float32Array([-0]),yt=new Uint8Array(pi.buffer);function Sa(t,e,r){pi[0]=t,e[r]=yt[0],e[r+1]=yt[1],e[r+2]=yt[2],e[r+3]=yt[3]}function va(t,e){return yt[0]=t[e],yt[1]=t[e+1],yt[2]=t[e+2],yt[3]=t[e+3],pi[0]}var mi=new Float64Array([-0]),me=new Uint8Array(mi.buffer);function Aa(t,e,r){mi[0]=t,e[r]=me[0],e[r+1]=me[1],e[r+2]=me[2],e[r+3]=me[3],e[r+4]=me[4],e[r+5]=me[5],e[r+6]=me[6],e[r+7]=me[7]}function Ta(t,e){return me[0]=t[e],me[1]=t[e+1],me[2]=t[e+2],me[3]=t[e+3],me[4]=t[e+4],me[5]=t[e+5],me[6]=t[e+6],me[7]=t[e+7],mi[0]}var ql=BigInt(Number.MAX_SAFE_INTEGER),zl=BigInt(Number.MIN_SAFE_INTEGER),Be=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 Ut;if(e<ql&&e>zl)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>Ba&&(o=0n,++n>Ba&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Ut;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):Ut}},Ut=new Be(0,0);Ut.toBigInt=function(){return 0n};Ut.zzEncode=Ut.zzDecode=function(){return this};Ut.length=function(){return 1};var Ba=4294967296n;function Ia(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 Ca(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 yi(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 Me(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function An(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var gi=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=xe(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,Me(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 Me(this,4);return An(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Me(this,4);return An(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Me(this,4);let e=va(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Me(this,4);let e=Ta(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 Me(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Ca(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Me(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Me(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 Be(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 Me(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 Me(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 Me(this,8);let e=An(this.buf,this.pos+=4),r=An(this.buf,this.pos+=4);return new Be(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=Ea(this.buf,this.pos);return this.pos+=Rr(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 Lr(t){return new gi(t instanceof Uint8Array?t:t.subarray())}function He(t,e,r){let n=Lr(t);return e.decode(n,void 0,r)}var bi={};Ae(bi,{base10:()=>Hl});var Hl=ft({prefix:"9",name:"base10",alphabet:"0123456789"});var wi={};Ae(wi,{base16:()=>jl,base16upper:()=>Yl});var jl=ie({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Yl=ie({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var xi={};Ae(xi,{base2:()=>Zl});var Zl=ie({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ei={};Ae(Ei,{base256emoji:()=>Jl});var Da=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}"),Gl=Da.reduce((t,e,r)=>(t[r]=e,t),[]),Xl=Da.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Wl(t){return t.reduce((e,r)=>(e+=Gl[r],e),"")}function Ql(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Xl[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Jl=Zt({prefix:"\u{1F680}",name:"base256emoji",encode:Wl,decode:Ql});var vi={};Ae(vi,{base64:()=>Si,base64pad:()=>ed,base64url:()=>td,base64urlpad:()=>rd});var Si=ie({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ed=ie({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),td=ie({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),rd=ie({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ai={};Ae(Ai,{base8:()=>nd});var nd=ie({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ti={};Ae(Ti,{identity:()=>od});var od=Zt({prefix:"\0",name:"identity",encode:t=>oa(Le(t)),decode:t=>Le(na(t))});var r0=new TextEncoder,n0=new TextDecoder;var Bi={};Ae(Bi,{identity:()=>Ke});var Ra=0,ad="identity",La=Le;function cd(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 Qt(Ra,La(t))}var Ke={code:Ra,name:ad,encode:La,digest:cd};var _i={};Ae(_i,{sha256:()=>Nr,sha512:()=>fd});var ud=20;function Ci({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Ii(t,e,r,n,o)}var Ii=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??ud,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?Na(n,this.code,r?.truncate):n.then(o=>Na(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Na(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 Qt(e,t)}function ka(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Nr=Ci({name:"sha2-256",code:18,encode:ka("SHA-256")}),fd=Ci({name:"sha2-512",code:19,encode:ka("SHA-512")});var Di={...Ti,...xi,...Ai,...bi,...wi,...ui,...fi,...li,...vi,...Ei},y0={..._i,...Bi};function Oa(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Fa=Oa("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Ri=Oa("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=Te(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),ld={utf8:Fa,"utf-8":Fa,hex:Di.base16,latin1:Ri,ascii:Ri,binary:Ri,...Di},Tn=ld;function se(t,e="utf8"){let r=Tn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Li(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return Te(s);o+s>e&&(n=Te(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var kt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Ni(){}var ki=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},dd=Li();function hd(t){return globalThis.Buffer!=null?Te(t):dd(t)}var kr=class{len;head;tail;states;constructor(){this.len=0,this.head=new kt(Ni,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new kt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Fi((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(Bn,10,Be.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Be.fromBigInt(e);return this._push(Bn,r.length(),r)}uint64Number(e){return this._push(xa,Rr(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=Be.fromBigInt(e).zzEncode();return this._push(Bn,r.length(),r)}sint64Number(e){let r=Be.fromNumber(e).zzEncode();return this._push(Bn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ui,1,e?1:0)}fixed32(e){return this._push(Ur,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Be.fromBigInt(e);return this._push(Ur,4,r.lo)._push(Ur,4,r.hi)}fixed64Number(e){let r=Be.fromNumber(e);return this._push(Ur,4,r.lo)._push(Ur,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(Sa,4,e)}double(e){return this._push(Aa,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Ui,1,0):this.uint32(r)._push(md,r,e)}string(e){let r=Ia(e);return r!==0?this.uint32(r)._push(yi,r,e):this._push(Ui,1,0)}fork(){return this.states=new ki(this),this.head=this.tail=new kt(Ni,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 kt(Ni,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=hd(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Ui(t,e,r){e[r]=t&255}function pd(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Fi=class extends kt{next;constructor(e,r){super(pd,e,r),this.next=void 0}};function Bn(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 Ur(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 md(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(kr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(yd,e,t),this},kr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(gd,e,t),this});function yd(t,e,r){e.set(t,r)}function gd(t,e,r){t.length<40?yi(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(se(t),r)}function Oi(){return new kr}function je(t,e){let r=Oi();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Ye(t,e,r){let n=Lr(t);yield*e.stream(n,void 0,"$",r)}var In={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Cn(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Fr(t){function e(i){if(t[i.toString()]==null)throw new Error("Invalid enum value");return t[i]}let r=function(s,a){let c=e(s);a.int32(c)},n=function(s){let a=s.int32();return e(a)},o=function*(s){let a=s.int32();yield e(a)};return Cn("enum",In.VARINT,r,n,o)}function Ze(t,e,r){return Cn("message",In.LENGTH_DELIMITED,t,e,r)}var Q;(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=()=>Fr(r)})(e=t.ValidityType||(t.ValidityType={}));let n;t.codec=()=>(n==null&&(n=Ze((a,c,f={})=>{f.lengthDelimited!==!1&&c.fork(),a.value!=null&&(c.uint32(10),c.bytes(a.value)),a.signatureV1!=null&&(c.uint32(18),c.bytes(a.signatureV1)),a.validityType!=null&&(c.uint32(24),t.ValidityType.codec().encode(a.validityType,c)),a.validity!=null&&(c.uint32(34),c.bytes(a.validity)),a.sequence!=null&&(c.uint32(40),c.uint64(a.sequence)),a.ttl!=null&&(c.uint32(48),c.uint64(a.ttl)),a.publicKey!=null&&(c.uint32(58),c.bytes(a.publicKey)),a.signatureV2!=null&&(c.uint32(66),c.bytes(a.signatureV2)),a.data!=null&&(c.uint32(74),c.bytes(a.data)),f.lengthDelimited!==!1&&c.ldelim()},(a,c,f={})=>{let u={},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let h=a.uint32();switch(h>>>3){case 1:{u.value=a.bytes();break}case 2:{u.signatureV1=a.bytes();break}case 3:{u.validityType=t.ValidityType.codec().decode(a);break}case 4:{u.validity=a.bytes();break}case 5:{u.sequence=a.uint64();break}case 6:{u.ttl=a.uint64();break}case 7:{u.publicKey=a.bytes();break}case 8:{u.signatureV2=a.bytes();break}case 9:{u.data=a.bytes();break}default:{a.skipType(h&7);break}}}return u},function*(a,c,f,u={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let h=a.uint32();switch(h>>>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(h&7);break}}}})),n);function o(a){return je(a,t.codec())}t.encode=o;function i(a,c){return He(a,t.codec(),c)}t.decode=i;function s(a,c){return Ye(a,t.codec(),c)}t.stream=s})(Q||(Q={}));var rs=oi(_n(),1);function W(t,e="utf8"){let r=Tn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}function bd(t){return t?.buffer instanceof ArrayBuffer}function Pa(t){if(bd(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function gt(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=Te(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return Pa(r)}function de(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var Ka=Symbol.for("@achingbrain/uint8arraylist");function Ma(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function Dn(t){return!!t?.[Ka]}var Ie=class t{bufs;length;[Ka]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Dn(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Dn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=Ma(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Ma(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(Dn(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return gt(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:gt(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),i=new t;return i.length=o,i.bufs=n,i}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let f=e>=a&&e<c,u=r>a&&r<=c;if(f&&u){if(e===a&&r===c){n.push(s);break}let l=e-a;n.push(s.subarray(l,l+(r-e)));break}if(f){if(e===0){n.push(s);continue}n.push(s.subarray(e-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-e}}indexOf(e,r=0){if(!Dn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=r;l<=c;l+=u){u=0;for(let h=f;h>=0;h--){let m=this.get(l+h);if(n[h]!==m){u=Math.max(1,h-a[m]);break}}if(u===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Te(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=Ne(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=Ne(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=Ne(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Te(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=Ne(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=Ne(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=Ne(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=Ne(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=Ne(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!de(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};function Rn(t){return t==null?!1:typeof t.type=="string"&&typeof t.code=="number"&&typeof t.verify=="function"}var wd=["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 Mi(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=xd(t);return r||"Object"}function xd(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(wd.includes(e))return e}var d=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}};d.uint=new d(0,"uint",!0);d.negint=new d(1,"negint",!0);d.bytes=new d(2,"bytes",!0);d.string=new d(3,"string",!0);d.array=new d(4,"array",!1);d.map=new d(5,"map",!1);d.tag=new d(6,"tag",!1);d.float=new d(7,"float",!0);d.false=new d(7,"false",!0);d.true=new d(7,"true",!0);d.null=new d(7,"null",!0);d.undefined=new d(7,"undefined",!0);d.break=new d(7,"break",!0);var k=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 Or=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Ed=new TextEncoder;function Ln(t){return Or&&globalThis.Buffer.isBuffer(t)}function Pr(t){return t instanceof Uint8Array?Ln(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Sd=24,vd=200,Nn=Or?t=>t.length>=Sd?globalThis.Buffer.from(t):Va(t):t=>t.length>=vd?Ed.encode(t):Va(t),Ge=t=>Uint8Array.from(t),$a=Or?(t,e,r)=>Ln(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),qa=Or?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Pr(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},Ki=Or?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function er(t,e){if(Ln(t)&&Ln(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 Va(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 Ad=256,Mr=class{constructor(e=Ad){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)}pushByte(e){let r=this.chunks[this.chunks.length-1];this.cursor>this.maxCursor&&(r=Ki(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r));let n=r.length-(this.maxCursor-this.cursor)-1;r[n]=e,this.cursor++}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=Ki(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=$a(n,0,this.cursor)}else r=qa(this.chunks,this.cursor);return e&&this.reset(),r}},Un=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}pushByte(e){if(this.cursor>=this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest[this.cursor++]=e}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var K="CBOR decode error:",kn="CBOR encode error:",Kr=[];Kr[23]=1;Kr[24]=2;Kr[25]=3;Kr[26]=5;Kr[27]=9;function tt(t,e,r){if(t.length-e<r)throw new Error(`${K} not enough data for type`)}var he=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Ce(t,e,r){tt(t,e,1);let n=t[e];if(r.strict===!0&&n<he[0])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function _e(t,e,r){tt(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<he[1])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function De(t,e,r){tt(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<he[2])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Re(t,e,r){tt(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<he[3])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${K} integers outside of the safe integer range are not supported`)}function za(t,e,r,n){return new k(d.uint,Ce(t,e+1,n),2)}function Ha(t,e,r,n){return new k(d.uint,_e(t,e+1,n),3)}function ja(t,e,r,n){return new k(d.uint,De(t,e+1,n),5)}function Ya(t,e,r,n){return new k(d.uint,Re(t,e+1,n),9)}function Xe(t,e){return ce(t,0,e.value)}function ce(t,e,r){if(r<he[0]){let n=Number(r);t.pushByte(e|n)}else if(r<he[1]){let n=Number(r);t.push([e|24,n])}else if(r<he[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<he[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<he[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,t.push(o)}else throw new Error(`${K} encountered BigInt larger than allowable range`)}}Xe.encodedSize=function(e){return ce.encodedSize(e.value)};ce.encodedSize=function(e){return e<he[0]?1:e<he[1]?2:e<he[2]?3:e<he[3]?5:9};Xe.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Za(t,e,r,n){return new k(d.negint,-1-Ce(t,e+1,n),2)}function Ga(t,e,r,n){return new k(d.negint,-1-_e(t,e+1,n),3)}function Xa(t,e,r,n){return new k(d.negint,-1-De(t,e+1,n),5)}var Vi=BigInt(-1),Wa=BigInt(1);function Qa(t,e,r,n){let o=Re(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new k(d.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${K} integers outside of the safe integer range are not supported`);return new k(d.negint,Vi-BigInt(o),9)}function Fn(t,e){let r=e.value,n=typeof r=="bigint"?r*Vi-Wa:r*-1-1;ce(t,e.type.majorEncoded,n)}Fn.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Vi-Wa:r*-1-1;return n<he[0]?1:n<he[1]?2:n<he[2]?3:n<he[3]?5:9};Fn.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Vr(t,e,r,n){tt(t,e,r+n);let o=t.slice(e+r,e+r+n);return new k(d.bytes,o,r+n)}function Ja(t,e,r,n){return Vr(t,e,1,r)}function ec(t,e,r,n){return Vr(t,e,2,Ce(t,e+1,n))}function tc(t,e,r,n){return Vr(t,e,3,_e(t,e+1,n))}function rc(t,e,r,n){return Vr(t,e,5,De(t,e+1,n))}function nc(t,e,r,n){let o=Re(t,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer bytes lengths not supported`);return Vr(t,e,9,o)}function On(t){return t.encodedBytes===void 0&&(t.encodedBytes=d.equals(t.type,d.string)?Nn(t.value):t.value),t.encodedBytes}function tr(t,e){let r=On(e);ce(t,e.type.majorEncoded,r.length),t.push(r)}tr.encodedSize=function(e){let r=On(e);return ce.encodedSize(r.length)+r.length};tr.compareTokens=function(e,r){return Bd(On(e),On(r))};function Bd(t,e){return t.length<e.length?-1:t.length>e.length?1:er(t,e)}var oc=new TextDecoder,Cd=32;function _d(t,e,r){if(r-e<Cd){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return oc.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return oc.decode(t.subarray(e,r))}function $r(t,e,r,n,o){let i=r+n;tt(t,e,i);let s=new k(d.string,_d(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function ic(t,e,r,n){return $r(t,e,1,r,n)}function sc(t,e,r,n){return $r(t,e,2,Ce(t,e+1,n),n)}function ac(t,e,r,n){return $r(t,e,3,_e(t,e+1,n),n)}function cc(t,e,r,n){return $r(t,e,5,De(t,e+1,n),n)}function uc(t,e,r,n){let o=Re(t,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer string lengths not supported`);return $r(t,e,9,o,n)}var fc=tr;function rr(t,e,r,n){return new k(d.array,n,r)}function lc(t,e,r,n){return rr(t,e,1,r)}function dc(t,e,r,n){return rr(t,e,2,Ce(t,e+1,n))}function hc(t,e,r,n){return rr(t,e,3,_e(t,e+1,n))}function pc(t,e,r,n){return rr(t,e,5,De(t,e+1,n))}function mc(t,e,r,n){let o=Re(t,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer array lengths not supported`);return rr(t,e,9,o)}function yc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return rr(t,e,1,1/0)}function Pn(t,e){ce(t,d.array.majorEncoded,e.value)}Pn.compareTokens=Xe.compareTokens;Pn.encodedSize=function(e){return ce.encodedSize(e.value)};function nr(t,e,r,n){return new k(d.map,n,r)}function gc(t,e,r,n){return nr(t,e,1,r)}function bc(t,e,r,n){return nr(t,e,2,Ce(t,e+1,n))}function wc(t,e,r,n){return nr(t,e,3,_e(t,e+1,n))}function xc(t,e,r,n){return nr(t,e,5,De(t,e+1,n))}function Ec(t,e,r,n){let o=Re(t,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer map lengths not supported`);return nr(t,e,9,o)}function Sc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return nr(t,e,1,1/0)}function Mn(t,e){ce(t,d.map.majorEncoded,e.value)}Mn.compareTokens=Xe.compareTokens;Mn.encodedSize=function(e){return ce.encodedSize(e.value)};function vc(t,e,r,n){return new k(d.tag,r,1)}function Ac(t,e,r,n){return new k(d.tag,Ce(t,e+1,n),2)}function Tc(t,e,r,n){return new k(d.tag,_e(t,e+1,n),3)}function Bc(t,e,r,n){return new k(d.tag,De(t,e+1,n),5)}function Ic(t,e,r,n){return new k(d.tag,Re(t,e+1,n),9)}function Kn(t,e){ce(t,d.tag.majorEncoded,e.value)}Kn.compareTokens=Xe.compareTokens;Kn.encodedSize=function(e){return ce.encodedSize(e.value)};var Vn=20,$n=21,qn=22,zn=23;function _c(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${K} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new k(d.null,null,1):new k(d.undefined,void 0,1)}function Dc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return new k(d.break,void 0,1)}function $i(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${K} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${K} Infinity values are not supported`)}return new k(d.float,t,e)}function Rc(t,e,r,n){return $i(Hn(t,e+1),3,n)}function Lc(t,e,r,n){return $i(jn(t,e+1),5,n)}function Nc(t,e,r,n){return $i(Fc(t,e+1),9,n)}function qr(t,e,r){let n=e.value;if(n===!1)t.pushByte(d.float.majorEncoded|Vn);else if(n===!0)t.pushByte(d.float.majorEncoded|$n);else if(n===null)t.pushByte(d.float.majorEncoded|qn);else if(n===void 0)t.pushByte(d.float.majorEncoded|zn);else{let o,i=!1;(!r||r.float64!==!0)&&(qi(n),o=Hn(ue,1),n===o||Number.isNaN(n)?(ue[0]=249,t.push(ue.slice(0,3)),i=!0):(zi(n),o=jn(ue,1),n===o&&(ue[0]=250,t.push(ue.slice(0,5)),i=!0))),i||(kc(n),o=Fc(ue,1),ue[0]=251,t.push(ue.slice(0,9)))}}qr.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){qi(n);let o=Hn(ue,1);if(n===o||Number.isNaN(n))return 3;if(zi(n),o=jn(ue,1),n===o)return 5}return 9};var Uc=new ArrayBuffer(9),Ue=new DataView(Uc,1),ue=new Uint8Array(Uc,0);function qi(t){if(t===1/0)Ue.setUint16(0,31744,!1);else if(t===-1/0)Ue.setUint16(0,64512,!1);else if(Number.isNaN(t))Ue.setUint16(0,32256,!1);else{Ue.setFloat32(0,t);let e=Ue.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)Ue.setUint16(0,31744,!1);else if(r===0)Ue.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Ue.setUint16(0,0):o<-14?Ue.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):Ue.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Hn(t,e){if(t.length-e<2)throw new Error(`${K} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function zi(t){Ue.setFloat32(0,t,!1)}function jn(t,e){if(t.length-e<4)throw new Error(`${K} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function kc(t){Ue.setFloat64(0,t,!1)}function Fc(t,e){if(t.length-e<8)throw new Error(`${K} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}function Ud(t,e){let r=t.value;if(r===!1)return Uint8Array.of(d.float.majorEncoded|Vn);if(r===!0)return Uint8Array.of(d.float.majorEncoded|$n);if(r===null)return Uint8Array.of(d.float.majorEncoded|qn);if(r===void 0)return Uint8Array.of(d.float.majorEncoded|zn);if(!e){if(qi(r),r===Hn(ue,1)||Number.isNaN(r))return ue[0]=249,ue.slice(0,3);if(zi(r),r===jn(ue,1))return ue[0]=250,ue.slice(0,5)}return kc(r),ue[0]=251,ue.slice(0,9)}function Cc(t,e){let r=t,n=e?.float64===!0,o=n?r._keyBytesFloat64:r._keyBytes;if(o!==void 0)return o;let i=Ud(t,n);return n?r._keyBytesFloat64=i:r._keyBytes=i,i}qr.compareTokens=function(e,r,n){let o=Cc(e,n),i=Cc(r,n);return o.length!==i.length?o.length<i.length?-1:1:er(o,i)};function j(t,e,r){throw new Error(`${K} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function Yn(t){return()=>{throw new Error(`${K} ${t}`)}}var R=[];for(let t=0;t<=23;t++)R[t]=j;R[24]=za;R[25]=Ha;R[26]=ja;R[27]=Ya;R[28]=j;R[29]=j;R[30]=j;R[31]=j;for(let t=32;t<=55;t++)R[t]=j;R[56]=Za;R[57]=Ga;R[58]=Xa;R[59]=Qa;R[60]=j;R[61]=j;R[62]=j;R[63]=j;for(let t=64;t<=87;t++)R[t]=Ja;R[88]=ec;R[89]=tc;R[90]=rc;R[91]=nc;R[92]=j;R[93]=j;R[94]=j;R[95]=Yn("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)R[t]=ic;R[120]=sc;R[121]=ac;R[122]=cc;R[123]=uc;R[124]=j;R[125]=j;R[126]=j;R[127]=Yn("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)R[t]=lc;R[152]=dc;R[153]=hc;R[154]=pc;R[155]=mc;R[156]=j;R[157]=j;R[158]=j;R[159]=yc;for(let t=160;t<=183;t++)R[t]=gc;R[184]=bc;R[185]=wc;R[186]=xc;R[187]=Ec;R[188]=j;R[189]=j;R[190]=j;R[191]=Sc;for(let t=192;t<=215;t++)R[t]=vc;R[216]=Ac;R[217]=Tc;R[218]=Bc;R[219]=Ic;R[220]=j;R[221]=j;R[222]=j;R[223]=j;for(let t=224;t<=243;t++)R[t]=Yn("simple values are not supported");R[244]=j;R[245]=j;R[246]=j;R[247]=_c;R[248]=Yn("simple values are not supported");R[249]=Rc;R[250]=Lc;R[251]=Nc;R[252]=j;R[253]=j;R[254]=j;R[255]=Dc;var Ve=[];for(let t=0;t<24;t++)Ve[t]=new k(d.uint,t,1);for(let t=-1;t>=-24;t--)Ve[31-t]=new k(d.negint,t,1);Ve[64]=new k(d.bytes,new Uint8Array(0),1);Ve[96]=new k(d.string,"",1);Ve[128]=new k(d.array,0,1);Ve[160]=new k(d.map,0,1);Ve[244]=new k(d.false,!1,1);Ve[245]=new k(d.true,!0,1);Ve[246]=new k(d.null,null,1);function Hi(t){switch(t.type){case d.false:return Ge([244]);case d.true:return Ge([245]);case d.null:return Ge([246]);case d.bytes:return t.value.length?void 0:Ge([64]);case d.string:return t.value===""?Ge([96]):void 0;case d.array:return t.value===0?Ge([128]):void 0;case d.map:return t.value===0?Ge([160]):void 0;case d.uint:return t.value<24?Ge([Number(t.value)]):void 0;case d.negint:if(t.value>=-24)return Ge([31-Number(t.value)])}}var Fd={float64:!1,mapSorter:Yi,quickEncodeToken:Hi},Vc=Object.freeze({mapSorter:Md,quickEncodeToken:Hi});function Od(){let t=[];return t[d.uint.major]=Xe,t[d.negint.major]=Fn,t[d.bytes.major]=tr,t[d.string.major]=fc,t[d.array.major]=Pn,t[d.map.major]=Mn,t[d.tag.major]=Kn,t[d.float.major]=qr,t}var Pt=Od(),Zn=new Mr,ir=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(`${kn} object contains circular references`);return new t(r,e)}},bt={null:new k(d.null,null),undefined:new k(d.undefined,void 0),true:new k(d.true,!0),false:new k(d.false,!1),emptyArray:new k(d.array,0),emptyMap:new k(d.map,0)},We={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new k(d.float,t):t>=0?new k(d.uint,t):new k(d.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new k(d.uint,t):new k(d.negint,t)},Uint8Array(t,e,r,n){return new k(d.bytes,t)},string(t,e,r,n){return new k(d.string,t)},boolean(t,e,r,n){return t?bt.true:bt.false},null(t,e,r,n){return bt.null},undefined(t,e,r,n){return bt.undefined},ArrayBuffer(t,e,r,n){return new k(d.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new k(d.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[bt.emptyArray,new k(d.break)]:bt.emptyArray;n=ir.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=Ot(s,r,n);return r.addBreakTokens?[new k(d.array,t.length),o,new k(d.break)]:[new k(d.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=ir.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,f=0;for(let u of i){let l=o?t.get(u):t[u];c&&l===void 0||(a[f++]=[Ot(u,r,n),Ot(l,r,n)])}f<s&&(a.length=f)}return a?.length?(Pd(a,r),r.addBreakTokens?[new k(d.map,a.length),a,new k(d.break)]:[new k(d.map,a.length),a]):r.addBreakTokens===!0?[bt.emptyMap,new k(d.break)]:bt.emptyMap},Tagged(t,e,r,n){return[new k(d.tag,t.tag),Ot(t.value,r,n)]}};We.Map=We.Object;We.Buffer=We.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))We[`${t}Array`]=We.DataView;function Ot(t,e={},r){let n=Mi(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||We[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=We[n];if(!i)throw new Error(`${kn} unsupported type: ${n}`);return i(t,n,e,r)}function Pd(t,e){let r=e.mapSorter;r&&t.sort((n,o)=>r(n,o,e))}function Yi(t,e,r){let n=Array.isArray(t[0])?t[0][0]:t[0],o=Array.isArray(e[0])?e[0][0]:e[0];if(n.type.major!==o.type.major)return n.type.compare(o.type);let i=n.type.major,s=Pt[i].compareTokens(n,o,r);return s===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),s}function Md(t,e){if(t[0]instanceof k&&e[0]instanceof k){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=Oc(r.value)),n._keyBytes||(n._keyBytes=Oc(n.value)),er(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Oc(t){return $c(t,Pt,Vc)}function or(t,e,r,n){if(Array.isArray(e))for(let o of e)or(t,o,r,n);else r[e.type.major](t,e,n)}var Pc=d.uint.majorEncoded,Mc=d.negint.majorEncoded,Kd=d.bytes.majorEncoded,Vd=d.string.majorEncoded,Kc=d.array.majorEncoded,ji=d.map.majorEncoded,$d=d.float.majorEncoded|Vn,qd=d.float.majorEncoded|$n,zd=d.float.majorEncoded|qn,Hd=d.float.majorEncoded|zn,jd=BigInt(-1),Yd=BigInt(1);function wt(t,e,r){r<24?t.pushByte(e|Number(r)):ce(t,e,r)}function Zd(t){return t.addBreakTokens!==!0}function Gd(t,e,r,n,o){let i=r==="Map",s=i?e.keys():Object.keys(e),a=i?e.size:s.length;if(!a){t.pushByte(ji);return}o=ir.createCheck(o,e);let c=!i&&n.ignoreUndefinedProperties,f=new Array(a),u=0;for(let l of s){let h=i?e.get(l):e[l];c&&h===void 0||(f[u++]=[Ot(l,n,o),h])}if(u===0){t.pushByte(ji);return}u<a&&(f.length=u),f.sort((l,h)=>Yi(l,h,n)),wt(t,ji,u);for(let[l,h]of f)or(t,l,Pt,n),Zi(t,h,n,o)}function Zi(t,e,r,n){let o=Mi(e),i=r.typeEncoders&&r.typeEncoders[o];if(i){let s=i(e,o,r,n);if(s!=null){or(t,s,Pt,r);return}}switch(o){case"null":t.pushByte(zd);return;case"undefined":t.pushByte(Hd);return;case"boolean":t.pushByte(e?qd:$d);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?qr(t,new k(d.float,e),r):e>=0?wt(t,Pc,e):wt(t,Mc,e*-1-1);return;case"bigint":e>=BigInt(0)?wt(t,Pc,e):wt(t,Mc,e*jd-Yd);return;case"string":{let s=Nn(e);wt(t,Vd,s.length),t.push(s);return}case"Uint8Array":wt(t,Kd,e.length),t.push(e);return;case"Array":if(!e.length){t.pushByte(Kc);return}n=ir.createCheck(n,e),wt(t,Kc,e.length);for(let s of e)Zi(t,s,r,n);return;case"Object":case"Map":if(r.mapSorter===Yi)Gd(t,e,o,r,n);else{let s=We.Object(e,o,r,n);or(t,s,Pt,r)}return;default:{let s=We[o];if(!s)throw new Error(`${kn} unsupported type: ${o}`);let a=s(e,o,r,n);or(t,a,Pt,r)}}}function $c(t,e,r,n){let o=n instanceof Uint8Array,i=o?new Un(n):Zn,s=Ot(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let f=c.encodedSize(s,r);if(o||(i=new Mr(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():Pr(i.chunks[0])}}return i.reset(),or(i,s,e,r),i.toBytes(!0)}function Gi(t,e){return e=Object.assign({},Fd,e),Zd(e)?(Zn.reset(),Zi(Zn,t,e,void 0),Zn.toBytes(!0)):$c(t,Pt,e)}var Xd={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Gn=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=Ve[e];if(r===void 0){let n=R[e];if(!n)throw new Error(`${K} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},xt=Symbol.for("DONE"),sr=Symbol.for("BREAK");function Wd(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=Et(e,r);if(i===sr){if(t.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed array`)}if(i===xt)throw new Error(`${K} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Qd(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=Et(e,r);if(c===sr){if(t.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed map`)}if(c===xt)throw new Error(`${K} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${K} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${K} found repeat map key "${c}"`);let f=Et(e,r);if(f===xt)throw new Error(`${K} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,f):i[c]=f}return n?s:i}function*Jd(t,e,r){for(let n=0;n<t.value;n++){let o=Et(e,r);if(o===sr){if(t.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed map`)}if(o===xt)throw new Error(`${K} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let i=Et(e,r);if(i===xt)throw new Error(`${K} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,i]}}function eh(t,e){let r=function(){if(r._called)throw new Error(`${K} tag decode() may only be called once`);r._called=!0;let n=Et(t,e);if(n===xt)throw new Error(`${K} tag content missing`);if(n===sr)throw new Error(`${K} got unexpected break in tag content`);return n};return r.entries=function(){if(r._called)throw new Error(`${K} tag decode() may only be called once`);r._called=!0;let n=t.next();if(!d.equals(n.type,d.map))throw new Error(`${K} entries() requires map content, got ${n.type.name}`);let o=[];for(let i of Jd(n,t,e))o.push(i);return o},r._called=!1,r}function Et(t,e){if(t.done())return xt;let r=t.next();if(d.equals(r.type,d.break))return sr;if(r.type.terminal)return r.value;if(d.equals(r.type,d.array))return Wd(r,t,e);if(d.equals(r.type,d.map))return Qd(r,t,e);if(d.equals(r.type,d.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=eh(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${K} tag decoder must call decode() or entries()`);return o}throw new Error(`${K} tag not supported (${r.value})`)}throw new Error("unsupported")}function qc(t,e){if(!(t instanceof Uint8Array))throw new Error(`${K} data to decode must be a Uint8Array`);e=Object.assign({},Xd,e);let r=Pr(t),n=e.tokenizer||new Gn(r,e),o=Et(n,e);if(o===xt)throw new Error(`${K} did not find any content to decode`);if(o===sr)throw new Error(`${K} got unexpected break`);return[o,t.subarray(n.pos())]}function Xi(t,e){let[r,n]=qc(t,e);if(n.length>0)throw new Error(`${K} too many terminals, data makes no sense`);return r}var Xn=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(Xn.prototype,Symbol.toStringTag,{value:"Tagged"});var zc=42;function rh(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function nh(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=te.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new k(d.tag,zc),new k(d.bytes,r)]}function oh(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function ih(t){if(Number.isNaN(t))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(t===1/0||t===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}function sh(t){for(let e of t.keys())if(typeof e!="string"||e.length===0)throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");return null}var Wi={float64:!0,typeEncoders:{Map:sh,Object:nh,undefined:oh,number:ih}},xg={...Wi,typeEncoders:{...Wi.typeEncoders}};function ah(t){let e=t();if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return te.decode(e.subarray(1))}var Qi={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[zc]:ah}},Eg={...Qi,tags:{...Qi.tags}};var Hc=t=>Gi(t,Wi),jc=t=>Xi(rh(t),Qi);var rt=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var nt=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Wn=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var zr=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var Qn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Hr=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};function Yc(t){return t==null?!1:(t.type==="RSA"||t.type==="Ed25519"||t.type==="secp256k1"||t.type==="ECDSA")&&t.raw instanceof Uint8Array&&typeof t.equals=="function"&&typeof t.toMultihash=="function"&&typeof t.toCID=="function"&&typeof t.verify=="function"}var Ji=Symbol.for("@libp2p/peer-id");function uh(t){return typeof t?.handleEvent=="function"}function fh(t){return t===!0||t===!1}function lh(t){return fh(t)?t:t?.capture??!1}function es(t){let e={capture:lh(t),once:!!t?.once};return t?.passive!=null&&(e.passive=t?.passive),t?.signal!=null&&(e.signal=t?.signal),e}function Zc(t,e){return es(t).capture===es(e).capture}var Jn=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=es(n);if(o?.signal?.aborted===!0)return;let i=f=>{o.once&&this.removeEventListener(e,r,o),uh(r)?r.handleEvent(f):r(f)},s=this.#e.get(e);if(s==null&&(s=[],this.#e.set(e,s)),s.some(f=>f.callback!==r?!1:Zc(f.options,o)))return;super.addEventListener(e,i,o);let c=()=>{this.removeEventListener(e,r,o)};o.signal?.addEventListener("abort",c),s.push({callback:r,wrapper:i,options:o,onAbort:c})}removeEventListener(e,r,n){let o=this.#e.get(e);if(o==null){super.removeEventListener(e,r??null,n);return}this.#e.set(e,o.filter(i=>i.callback===r&&Zc(i.options,n)?(super.removeEventListener(e,i.wrapper,n),i.options?.signal?.removeEventListener("abort",i.onAbort),!1):!0))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var ot="/",Gc=new TextEncoder().encode(ot),eo=Gc[0],ar=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=se(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]!==eo)throw new Error("Invalid key")}toString(e="utf8"){return W(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(ot))}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=Gc),this._buf[0]!==eo){let e=new Uint8Array(this._buf.byteLength+1);e.fill(eo,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===eo;)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(ot).slice(1)}type(){return dh(this.baseNamespace())}name(){return hh(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(ot)||(e+=ot),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(ot):new t(e.slice(0,-1).join(ot))}child(e){return this.toString()===ot?e:e.toString()===ot?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(),...ph(e.map(r=>r.namespaces()))])}};function dh(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function hh(t){let e=t.split(":");return e[e.length-1]}function ph(t){return[].concat(...t)}var Xc=114,Wc=0;var Qc=se("/ipns/"),to="/ipns/";function Jc(t,e){return t.code===e}var ro="/dht/record/",yh="/ipns/metadata/";function jr(t){return new ar(ro+W(t,"base32"),!1)}function no(t){return new ar(yh+W(t,"base32"),!1)}function eu(t,e){let r=Date.now();return t.getTime()+1728e5-r<864e5||e.getTime()-r<864e5}function tu(t,e,r){let n=se(e);return gt([t,r,n],t.byteLength+r.byteLength+n.byteLength)}function oo(t){let e=se("ipns-signature:");return gt([e,t])}function ts(t){try{return`/ipfs/${te.decode(t)}`}catch{}return W(t)}function it(t){return gt([Qc,t.bytes])}function io(t){return dt(t.slice(Qc.length))}function ru(t){return xe(Hc(t))}function ke(t){if(t==null)throw new Sn("Record data is missing");let e=jc(t);if(e.ValidityType===0&&(e.ValidityType=Q.ValidityType.EOL),e.ValidityType!==Q.ValidityType.EOL)throw new Jt("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 so(t){if(t!=null){if(Rn(t))return`/ipns/${t.toCID().toV1().toString(we)}`;let e=ou(t);if(e!=null)return e.code===Xc?`/ipns/${e.toV1().toString(we)}`:`/ipfs/${e.toV1()}`;if(bh(t))return`/ipns/${we.encode(t.bytes)}`;let r=t.toString().trim();if(r.startsWith("/ipfs/")){let[,n,...o]=r.split("/").filter(i=>i.trim()!=="");return`/ipfs/${te.parse(n).toV1()}${o.length>0?`/${o.join("/")}`:""}`}if(r.startsWith("/")&&r.length>1)return r}throw new pt("Value must be a valid content path starting with /")}function gh(t){return typeof t.code=="number"&&t.digest instanceof Uint8Array&&typeof t.size=="number"&&t.bytes instanceof Uint8Array}function Yr(t){if(t!=null){if(Rn(t))return{digest:t.toMultihash(),path:"/"};let e=ou(t);if(e!=null){if(e.code!==Xc)throw new pt("CIDs must have the `libp2p-key` codec");return{digest:e.multihash,path:"/"}}if(gh(t))return{digest:t,path:"/"};if(t=t.toString(),t.startsWith("/ipns/")){let[,,r,...n]=t.split("/"),o=we;(r.startsWith("1")||r.startsWith("Q"))&&(r=`z${r}`,o=J);let i=o.decode(r),s;try{s=te.decode(i).multihash}catch{s=dt(i)}return{digest:s,path:`/${n.join("/")}`}}}throw new pt("Value must be a valid IPNS path starting with /")}function nu(t,e){if(!de(e.Value,t.value??new Uint8Array(0)))throw new Pe('Field "value" did not match between protobuf and CBOR');if(!de(e.Validity,t.validity??new Uint8Array(0)))throw new Pe('Field "validity" did not match between protobuf and CBOR');if(e.ValidityType!==t.validityType)throw new Pe('Field "validityType" did not match between protobuf and CBOR');if(e.Sequence!==t.sequence)throw new Pe('Field "sequence" did not match between protobuf and CBOR');if(e.TTL!==t.ttl)throw new Pe('Field "ttl" did not match between protobuf and CBOR')}function bh(t){return t.bytes instanceof Uint8Array}function wh(t){return typeof t?.toCID=="function"}function ou(t){if(wh(t))return t.toCID();try{return te.parse(t)}catch{}return te.asCID(t)}function St(t,e){let r=e.map((n,o)=>({record:n,index:o}));return r.sort((n,o)=>{let i=ke(n.record.data),s=ke(o.record.data),a=i.Sequence,c=s.Sequence;if(a>c)return-1;if(a<c)return 1;if(i.ValidityType===Q.ValidityType.EOL&&s.ValidityType===Q.ValidityType.EOL){let f=rs.default.fromString(W(i.Validity)).toDate(),u=rs.default.fromString(W(s.Validity)).toDate();if(f.getTime()>u.getTime())return-1;if(f.getTime()<u.getTime())return 1}return 0}),r[0].index}var iu=oi(_n(),1);var xh=1024*10;async function Qe(t,e,r,n){if(e.byteLength>xh)throw new En("The record is too large");let o=Q.decode(e);if(o.signatureV2==null)throw new Pe("Missing signatureV2");let i=ke(o.data),s=W(i.Validity),a,c=io(t);if(Jc(c,0)&&(a=await r.loadPublicKeyFromProtobuf(c.digest,n)),a==null&&o.publicKey!=null&&(a=await r.loadPublicKeyFromProtobuf(o.publicKey,n)),a==null)throw new vn("Could not extract public key from IPNS record or routing key");let f;try{if(o.data==null)throw new Error("Missing data");let u=oo(o.data);f=await a.verify(u,o.signatureV2,n)}catch{f=!1}if(!f)throw new Pe("Record signature verification failed");if(i.ValidityType===Q.ValidityType.EOL){if(iu.default.fromString(s).toDate().getTime()<Date.now())throw new xn("record has expired")}else if(i.ValidityType!=null)throw new Jt(`The validity type ${i.ValidityType} is unsupported`);return o.value!=null&&o.signatureV1!=null&&nu(o,i),o}var cr=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}=Yr(e);for(;;){let o=it(n),i=await this.#e(o,r),s="";if(i.data!=null){let a=ke(i.data);s=ts(a.Value)}else if(i.value!=null)s=ts(i.value);else throw new pt(`Record for key ${we.encode(n.bytes)} contained no value`);if(yield{record:i,value:s},!s.startsWith(to))break;({digest:n}=Yr(s))}}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:c,created:f}=await this.localStore.get(e,r);this.log("record retrieved from cache");let u;r.validate===!1?(u=Q.decode(c),this.log("skipped validation of record")):(u=await Qe(e,c,this.keychain,r),this.log("record was valid"));let l=ke(u.data),h=Number((l.TTL??yn)/1000000n);if(f.getTime()+h>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(u)}catch(c){this.log("cached record was invalid - %e",c),await this.localStore.delete(e,r)}else this.log("ignoring local cache due to nocache=true option");if(r.offline===!0)throw new Dr("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(e,{...r,validate:!1})}catch(u){this.log.error("error finding IPNS record using router %s - %e",c.toString(),u),s.push(u);return}try{let u;r.validate===!1?u=Q.decode(f):u=await Qe(e,f,this.keychain,r),n.push(u)}catch(u){i++,this.log.error("error validating IPNS record from router %s - %e",c.toString(),u)}})),n.length===0)throw i>0?new gn(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`):new Dr("Could not find record for routing key");let a=n[St(e,n)];return await this.localStore.put(e,Q.encode(a),r),a}};var fe=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};function ao(t,e){if(typeof t=="string")return Eh(t);if(typeof t=="number")return Ah(t,e);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}function Eh(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 Sh(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 vh(t){let e=Math.abs(t);return e>=315576e5?Mt(t,e,315576e5,"year"):e>=26298e5?Mt(t,e,26298e5,"month"):e>=6048e5?Mt(t,e,6048e5,"week"):e>=864e5?Mt(t,e,864e5,"day"):e>=36e5?Mt(t,e,36e5,"hour"):e>=6e4?Mt(t,e,6e4,"minute"):e>=1e3?Mt(t,e,1e3,"second"):`${t} ms`}function Ah(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?vh(t):Sh(t)}function Mt(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function ns(t){r.debug=r,r.default=r,r.coerce=c,r.disable=i,r.enable=o,r.enabled=s,r.humanize=ao,r.destroy=f,Object.keys(t).forEach(u=>{r[u]=t[u]}),r.names=[],r.skips=[],r.formatters={};function e(u){let l=0;for(let h=0;h<u.length;h++)l=(l<<5)-l+u.charCodeAt(h),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=e;function r(u,l){let h,m=null,L,v;function b(...E){if(!b.enabled)return;let B=b,y=Number(new Date),N=y-(h||y);B.diff=N,B.prev=h,B.curr=y,h=y,E[0]=r.coerce(E[0]),typeof E[0]!="string"&&E.unshift("%O");let U=0;E[0]=E[0].replace(/%([a-zA-Z%])/g,($,w)=>{if($==="%%")return"%";U++;let S=r.formatters[w];if(typeof S=="function"){let I=E[U];$=S.call(B,I),E.splice(U,1),U--}return $}),r.formatArgs.call(B,E),l?.onLog!=null&&l.onLog(...E),(B.log||r.log).apply(B,E)}return b.namespace=u,b.useColors=r.useColors(),b.color=r.selectColor(u),b.extend=n,b.destroy=r.destroy,Object.defineProperty(b,"enabled",{enumerable:!0,configurable:!1,get:()=>m!==null?m:(L!==r.namespaces&&(L=r.namespaces,v=r.enabled(u)),v),set:E=>{m=E}}),typeof r.init=="function"&&r.init(b),b}function n(u,l){let h=r(this.namespace+(typeof l>"u"?":":l)+u);return h.log=this.log,h}function o(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];let l,h=(typeof u=="string"?u:"").split(/[\s,]+/),m=h.length;for(l=0;l<m;l++)h[l]&&(u=h[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,h;for(l=0,h=r.skips.length;l<h;l++)if(r.skips[l].test(u))return!1;for(l=0,h=r.names.length;l<h;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 co=Rh(),Th=["#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 Bh(){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 Ih(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+ao(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 Ch=console.debug??console.log??(()=>{});function _h(t){try{t?co?.setItem("debug",t):co?.removeItem("debug")}catch{}}function Dh(){let t;try{t=co?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function Rh(){try{return localStorage}catch{}}function Lh(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var su=ns({formatArgs:Ih,save:_h,load:Dh,useColors:Bh,setupFormatters:Lh,colors:Th,storage:co,log:Ch});var Ee=su;Ee.formatters.b=t=>t==null?"undefined":J.baseEncode(t);Ee.formatters.t=t=>t==null?"undefined":lt.baseEncode(t);Ee.formatters.m=t=>t==null?"undefined":Si.baseEncode(t);Ee.formatters.p=t=>t==null?"undefined":t.toString();Ee.formatters.c=t=>t==null?"undefined":t.toString();Ee.formatters.k=t=>t==null?"undefined":t.toString();Ee.formatters.a=t=>t==null?"undefined":t.toString();function au(t,e=""){let r=cu(t.message),n=cu(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
2
+ "use strict";var HeliaIpns=(()=>{var Yf=Object.create;var mn=Object.defineProperty;var Zf=Object.getOwnPropertyDescriptor;var Gf=Object.getOwnPropertyNames;var Xf=Object.getPrototypeOf,Wf=Object.prototype.hasOwnProperty;var Qf=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},Ce=(t,e)=>{for(var r in e)mn(t,r,{get:e[r],enumerable:!0})},ea=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Gf(e))!Wf.call(t,o)&&o!==r&&mn(t,o,{get:()=>e[o],enumerable:!(n=Zf(e,o))||n.enumerable});return t};var ii=(t,e,r)=>(r=t!=null?Yf(Xf(t)):{},ea(e||!t||!t.__esModule?mn(r,"default",{value:t,enumerable:!0}):r,t)),Jf=t=>ea(mn({},"__esModule",{value:!0}),t);var Dn=Qf((ey,Mi)=>{var J0=(function(){typeof Mi<"u"&&(Mi.exports=x);var t=86400,e=3200,r=146097*e/400,n=t*r,o=1e3*n,i=864e13,s=4294967296,a=1e6,c="000000000",f=Math.trunc||function(b){var E=b-b%1;return E==0&&(b<0||b===0&&1/b!=1/0)?-0:E},u=x.prototype,l=(x.fromDate=function(b){return new x(+b)},x.fromInt64BE=R(0,1,2,3,0,4),x.fromInt64LE=R(3,2,1,0,4,0),x.fromString=function(N){var E,v=new x,N=(N+="").replace(/^\s*[+\-]?\d+/,function(z){var z=+z,I=1970+(z-1970)%400;return v.year=z-I,I}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(L,z,I){return z<0&&(I*=-1),E=6e4*(60*+z+ +I),""}).replace(/\.\d+$/,function(L){return v.nano=+(L+c).substr(1,9),""}).split(/\D+/);if(1<N.length?N[1]--:N[1]=0,v.time=E=Date.UTC.apply(Date,N)-(E||0),isNaN(E))throw new TypeError("Invalid Date");return g(v)},x.fromTimeT=function(b){return T(b,0)},u.year=0,u.time=0,u.nano=0,u.addNano=function(b){return this.nano+=+b||0,this},u.getNano=function(){var b=g(this);return(b.time%1e3*a+ +b.nano+1e9)%1e9},u.getTimeT=function(){var E=g(this),b=Math.floor(E.time/1e3),E=E.year;return E&&(b+=E*r*t/e),b},u.getYear=function(){return this.toDate().getUTCFullYear()+this.year},u.toDate=function(){return S(g(this).time)},u.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},u.toString=function(b){var E=this,v=E.toDate(),N={H:function(){return $(v.getUTCHours())},L:function(){return q(v.getUTCMilliseconds(),3)},M:function(){return $(v.getUTCMinutes())},N:function(){return q(E.getNano(),9)},S:function(){return $(v.getUTCSeconds())},Y:function(){var L=E.getYear();return 999999<L?"+"+L:9999<L?"+"+q(L,6):0<=L?q(L,4):-999999<=L?"-"+q(-L,6):L},a:function(){return m[v.getUTCDay()]},b:function(){return h[v.getUTCMonth()]},d:function(){return $(v.getUTCDate())},e:function(){return(function(L){return(9<L?"":" ")+(0|L)})(v.getUTCDate())},m:function(){return $(v.getUTCMonth()+1)}};return(function L(z){return z.replace(/%./g,function(I){var O=I[1],k=C[O],O=N[O];return k?L(k):O?O():I})})(b||l)},u.writeInt64BE=y(0,1,2,3,0,4),u.writeInt64LE=y(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],m=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],C={"%":"%",F:"%Y-%m-%d",n:`
3
+ `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return x;function x(b,E,v){var N=this;if(!(N instanceof x))return new x(b,E,v);N.time=+b||0,N.nano=+E||0,N.year=+v||0,g(N)}function g(b){var E,v,N,L=b.year,z=b.time,I=b.nano,k=((I<0||a<=I)&&(I-=(v=Math.floor(I/a))*a,z+=v,v=1),L%e);return(z<-i||i<z||k)&&((E=f(z/o))&&(L+=E*e,z-=E*o),(N=S(z)).setUTCFullYear(k+N.getUTCFullYear()),N=(z=+N)+(E=f((L-=k)/e))*o,E&&-i<=N&&N<=i&&(L-=E*e,z=N),v=1),v&&(b.year=L,b.time=z,b.nano=I),b}function S(b){var E=new Date(0);return E.setTime(b),E}function T(L,N){L=+L||0;var v=f((N=(N|0)*s)/n)+f(L/n),N=N%n+L%n,L=f(N/n);return L&&(v+=L,N-=L*n),new x(1e3*N,0,v*e)}function y(b,E,v,N,L,z){return function(k,O){var Y=g(this);k=k||new Array(8),_(k,O|=0);var W=Math.floor(Y.time/1e3),Y=Y.year*(r*t/e),P=f(Y/s)+f(W/s),Y=Y%s+W%s,W=Math.floor(Y/s);return W&&(P+=W,Y-=W*s),I(k,O+L,P),I(k,O+z,Y),k};function I(k,O,P){k[O+b]=P>>24&255,k[O+E]=P>>16&255,k[O+v]=P>>8&255,k[O+N]=255&P}}function R(b,E,v,N,L,z){return function(k,O){_(k,O|=0);var P=I(k,O+L);return T(I(k,O+z),P)};function I(k,O){return 16777216*k[O+b]+(k[O+E]<<16|k[O+v]<<8|k[O+N])}}function _(b,E){if(b=b&&b.length,b==null)throw new TypeError("Invalid Buffer");if(b<E+8)throw new RangeError("Out of range")}function $(b){return(9<b?"":"0")+(0|b)}function q(b,E){return(c+(0|b)).substr(-E)}})()});var ym={};Ce(ym,{IPNSEntry:()=>te,createIPNSRecord:()=>fr,heliaIPNSRouting:()=>Tr,ipns:()=>pm,ipnsResolver:()=>mm,ipnsSelector:()=>Tt,ipnsValidator:()=>rt,multihashFromIPNSRoutingKey:()=>so,multihashToIPNSRoutingKey:()=>ct,pubSubIPNSRouting:()=>qf});var fi={};Ce(fi,{base32:()=>pt,base32hex:()=>fl,base32hexpad:()=>dl,base32hexpadupper:()=>hl,base32hexupper:()=>ll,base32pad:()=>cl,base32padupper:()=>ul,base32upper:()=>al,base32z:()=>pl});var bm=new Uint8Array(0);function ra(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 Oe(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Ut(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Ut(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function na(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var ta=4096;function oa(t){let e=t.length;if(e<=ta)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=ta));return r}function el(t){return t?.buffer instanceof ArrayBuffer}function Ut(t){return el(t)?t:t.slice()}function tl(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),a=s.charCodeAt(0);if(n[a]!==255)throw new TypeError(s+" is ambiguous");if(n[a]=i,r){var c=s.toLowerCase().charCodeAt(0),f=s.toUpperCase().charCodeAt(0);c!==a&&(n[c]=i),f!==a&&(n[f]=i)}}var u=t.length,l=t.charAt(0),h=Math.log(u)/Math.log(256),m=Math.log(256)/Math.log(u);function C(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 T=0,y=0,R=0,_=S.length;R!==_&&S[R]===0;)R++,T++;for(var $=(_-R)*m+1>>>0,q=new Uint8Array($);R!==_;){for(var b=S[R],E=0,v=$-1;(b!==0||E<y)&&v!==-1;v--,E++)b+=256*q[v]>>>0,q[v]=b%u>>>0,b=b/u>>>0;if(b!==0)throw new Error("Non-zero carry");y=E,R++}for(var N=$-y;N!==$&&q[N]===0;)N++;for(var L=l.repeat(T);N<$;++N)L+=t.charAt(q[N]);return L}function x(S){if(typeof S!="string")throw new TypeError("Expected String");if(S.length===0)return new Uint8Array;var T=0;if(S[T]!==" "){for(var y=0,R=0;S[T]===l;)y++,T++;for(var _=(S.length-T)*h+1>>>0,$=new Uint8Array(_);S[T];){var q=n[S.charCodeAt(T)];if(q===255)return;for(var b=0,E=_-1;(q!==0||b<R)&&E!==-1;E--,b++)q+=u*$[E]>>>0,$[E]=q%256>>>0,q=q/256>>>0;if(q!==0)throw new Error("Non-zero carry");R=b,T++}if(S[T]!==" "){for(var v=_-R;v!==_&&$[v]===0;)v++;for(var N=new Uint8Array(y+(_-v)),L=y;v!==_;)N[L++]=$[v++];return N}}}function g(S){var T=x(S);if(T)return T;throw new Error(`Non-${e} character`)}return{encode:C,decodeUnsafe:x,decode:g}}var rl=tl,nl=rl,sa=nl;var si=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")}},ai=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 aa(this,e)}},ci=class{decoders;constructor(e){this.decoders=e}or(e){return aa(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 aa(t,e){return new ci({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var ui=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 si(e,r,n),this.decoder=new ai(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Gt({name:t,prefix:e,encode:r,decode:n}){return new ui(t,e,r,n)}function ht({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:i}=sa(r,t,n);return Gt({prefix:e,name:t,encode:o,decode:s=>Oe(i(s))})}function ol(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let f=0;f<o;++f){let u=e[t[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 il(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],s+=8;s>r;)s-=r,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function sl(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let o=t[n].toLowerCase(),i=t[n].toUpperCase();o!==t[n]&&(r[o]=n),i!==t[n]&&(r[i]=n)}return r}function ce({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let i=sl(n,o);return Gt({prefix:e,name:t,encode(s){return il(s,n,r)},decode(s){return ol(s,i,r,t)}})}var pt=ce({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),al=ce({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),cl=ce({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),ul=ce({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),fl=ce({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),ll=ce({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),dl=ce({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),hl=ce({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),pl=ce({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var li={};Ce(li,{base36:()=>ve,base36upper:()=>ml});var ve=ht({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),ml=ht({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var di={};Ce(di,{base58btc:()=>re,base58flickr:()=>yl});var re=ht({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),yl=ht({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var gl=fa,ca=128,bl=127,wl=~bl,xl=Math.pow(2,31);function fa(t,e,r){e=e||[],r=r||0;for(var n=r;t>=xl;)e[r++]=t&255|ca,t/=128;for(;t&wl;)e[r++]=t&255|ca,t>>>=7;return e[r]=t|0,fa.bytes=r-n+1,e}var El=hi,Sl=128,ua=127;function hi(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw hi.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&ua)<<o:(s&ua)*Math.pow(2,o),o+=7}while(s>=Sl);return hi.bytes=i-n,r}var vl=Math.pow(2,7),Al=Math.pow(2,14),Tl=Math.pow(2,21),Il=Math.pow(2,28),Bl=Math.pow(2,35),Cl=Math.pow(2,42),_l=Math.pow(2,49),Dl=Math.pow(2,56),Rl=Math.pow(2,63),Ll=function(t){return t<vl?1:t<Al?2:t<Tl?3:t<Il?4:t<Bl?5:t<Cl?6:t<_l?7:t<Dl?8:t<Rl?9:10},Nl={encode:gl,decode:El,encodingLength:Ll},kl=Nl,Br=kl;function Cr(t,e=0){let r=Br.decode(t,e),n=Br.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function Xt(t,e,r=0){return Br.encode(t,e,r),e}function Wt(t){return Br.encodingLength(t)}function Jt(t,e){let r=e.byteLength,n=Wt(t),o=n+Wt(r),i=new Uint8Array(o+r);return Xt(t,i,0),Xt(r,i,n),i.set(e,o),new Qt(t,r,e,i)}function mt(t){let e=Oe(t),[r,n]=Cr(e),[o,i]=Cr(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Qt(r,o,s,e)}function la(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ra(t.bytes,r.bytes)}}var Qt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=Ut(n),this.bytes=Ut(o)}};function da(t,e){let{bytes:r,version:n}=t;return n===0?Fl(r,pi(t),e??re.encoder):Ol(r,pi(t),e??pt.encoder)}var ha=new WeakMap;function pi(t){let e=ha.get(t);if(e==null){let r=new Map;return ha.set(t,r),r}return e}var se=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=Ut(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!==_r)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Pl)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=Jt(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&&la(e.multihash,n.multihash)}toString(e){return da(this,e)}toJSON(){return{"/":da(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??pa(n,o,i.bytes))}else if(r[Ml]===!0){let{version:n,multihash:o,code:i}=r,s=mt(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!==_r)throw new Error(`Version 0 CID must use dag-pb (code: ${_r}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=pa(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,_r,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=Oe(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 Qt(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,h]=Cr(e.subarray(r));return r+=h,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(e,r){let[n,o]=Ul(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 pi(i).set(n,e),i}};function Ul(t,e){switch(t[0]){case"Q":{let r=e??re;return[re.prefix,r.decode(`${re.prefix}${t}`)]}case re.prefix:{let r=e??re;return[re.prefix,r.decode(t)]}case pt.prefix:{let r=e??pt;return[pt.prefix,r.decode(t)]}case ve.prefix:{let r=e??ve;return[ve.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 Fl(t,e,r){let{prefix:n}=r;if(n!==re.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 Ol(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 _r=112,Pl=18;function pa(t,e,r){let n=Wt(t),o=n+Wt(e),i=new Uint8Array(o+r.byteLength);return Xt(t,i,0),Xt(e,i,n),i.set(r,o),i}var Ml=Symbol.for("@ipld/js-cid/CID");var gn=BigInt(6e4)*5000000n,ma=5;var bn=class extends Error{static name="RecordsFailedValidationError";name="RecordsFailedValidationError"},gt=class extends Error{static name="InvalidValueError";name="InvalidValueError"},wn=class extends Error{static name="InvalidTopicError";name="InvalidTopicError"},Dr=class extends Error{static name="RecordNotFoundError";name="RecordNotFoundError"},xn=class extends Error{static name="SignatureCreationError";name="SignatureCreationError"},qe=class extends Error{static name="SignatureVerificationError";name="SignatureVerificationError"},En=class extends Error{static name="RecordExpiredError";name="RecordExpiredError"},er=class extends Error{static name="UnsupportedValidityError";name="UnsupportedValidityError"},Sn=class extends Error{static name="RecordTooLargeError";name="RecordTooLargeError"},vn=class extends Error{static name="InvalidRecordDataError";name="InvalidRecordDataError"},An=class extends Error{static name="InvalidEmbeddedPublicKeyError";name="InvalidEmbeddedPublicKeyError"};function Pe(t=0){return new Uint8Array(t)}function _e(t=0){return new Uint8Array(t)}var Kl=Math.pow(2,7),Vl=Math.pow(2,14),$l=Math.pow(2,21),ya=Math.pow(2,28),ga=Math.pow(2,35),ba=Math.pow(2,42),wa=Math.pow(2,49),Ee=128,bt=127;function Rr(t){if(t<Kl)return 1;if(t<Vl)return 2;if(t<$l)return 3;if(t<ya)return 4;if(t<ga)return 5;if(t<ba)return 6;if(t<wa)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function xa(t,e,r=0){switch(Rr(t)){case 8:e[r++]=t&255|Ee,t/=128;case 7:e[r++]=t&255|Ee,t/=128;case 6:e[r++]=t&255|Ee,t/=128;case 5:e[r++]=t&255|Ee,t/=128;case 4:e[r++]=t&255|Ee,t>>>=7;case 3:e[r++]=t&255|Ee,t>>>=7;case 2:e[r++]=t&255|Ee,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Ea(t,e){let r=t[e],n=0;if(n+=r&bt,r<Ee||(r=t[e+1],n+=(r&bt)<<7,r<Ee)||(r=t[e+2],n+=(r&bt)<<14,r<Ee)||(r=t[e+3],n+=(r&bt)<<21,r<Ee)||(r=t[e+4],n+=(r&bt)*ya,r<Ee)||(r=t[e+5],n+=(r&bt)*ga,r<Ee)||(r=t[e+6],n+=(r&bt)*ba,r<Ee)||(r=t[e+7],n+=(r&bt)*wa,r<Ee))return n;throw new RangeError("Could not decode varint")}function ql(t){return t.buffer instanceof ArrayBuffer}function Ae(t){return ql(t)?t:t.slice()}var mi=new Float32Array([-0]),wt=new Uint8Array(mi.buffer);function Sa(t,e,r){mi[0]=t,e[r]=wt[0],e[r+1]=wt[1],e[r+2]=wt[2],e[r+3]=wt[3]}function va(t,e){return wt[0]=t[e],wt[1]=t[e+1],wt[2]=t[e+2],wt[3]=t[e+3],mi[0]}var yi=new Float64Array([-0]),xe=new Uint8Array(yi.buffer);function Aa(t,e,r){yi[0]=t,e[r]=xe[0],e[r+1]=xe[1],e[r+2]=xe[2],e[r+3]=xe[3],e[r+4]=xe[4],e[r+5]=xe[5],e[r+6]=xe[6],e[r+7]=xe[7]}function Ta(t,e){return xe[0]=t[e],xe[1]=t[e+1],xe[2]=t[e+2],xe[3]=t[e+3],xe[4]=t[e+4],xe[5]=t[e+5],xe[6]=t[e+6],xe[7]=t[e+7],yi[0]}var zl=BigInt(Number.MAX_SAFE_INTEGER),Hl=BigInt(Number.MIN_SAFE_INTEGER),De=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 Ft;if(e<zl&&e>Hl)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>Ia&&(o=0n,++n>Ia&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Ft;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):Ft}},Ft=new De(0,0);Ft.toBigInt=function(){return 0n};Ft.zzEncode=Ft.zzDecode=function(){return this};Ft.length=function(){return 1};var Ia=4294967296n;function Ba(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 Ca(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 gi(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 ze(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Tn(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var bi=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Ae(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,ze(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 ze(this,4);return Tn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ze(this,4);return Tn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ze(this,4);let e=va(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw ze(this,4);let e=Ta(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 ze(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Ca(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw ze(this,e);this.pos+=e}else do if(this.pos>=this.len)throw ze(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 De(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 ze(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 ze(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 ze(this,8);let e=Tn(this.buf,this.pos+=4),r=Tn(this.buf,this.pos+=4);return new De(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=Ea(this.buf,this.pos);return this.pos+=Rr(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 Lr(t){return new bi(t instanceof Uint8Array?t:t.subarray())}function Ze(t,e,r){let n=Lr(t);return e.decode(n,void 0,r)}var wi={};Ce(wi,{base10:()=>jl});var jl=ht({prefix:"9",name:"base10",alphabet:"0123456789"});var xi={};Ce(xi,{base16:()=>Yl,base16upper:()=>Zl});var Yl=ce({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Zl=ce({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Ei={};Ce(Ei,{base2:()=>Gl});var Gl=ce({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Si={};Ce(Si,{base256emoji:()=>ed});var Da=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}"),Xl=Da.reduce((t,e,r)=>(t[r]=e,t),[]),Wl=Da.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Ql(t){return t.reduce((e,r)=>(e+=Xl[r],e),"")}function Jl(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Wl[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var ed=Gt({prefix:"\u{1F680}",name:"base256emoji",encode:Ql,decode:Jl});var Ai={};Ce(Ai,{base64:()=>vi,base64pad:()=>td,base64url:()=>rd,base64urlpad:()=>nd});var vi=ce({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),td=ce({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),rd=ce({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),nd=ce({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ti={};Ce(Ti,{base8:()=>od});var od=ce({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ii={};Ce(Ii,{identity:()=>id});var id=Gt({prefix:"\0",name:"identity",encode:t=>oa(Oe(t)),decode:t=>Oe(na(t))});var o0=new TextEncoder,i0=new TextDecoder;var Bi={};Ce(Bi,{identity:()=>He});var Ra=0,cd="identity",La=Oe;function ud(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 Jt(Ra,La(t))}var He={code:Ra,name:cd,encode:La,digest:ud};var Di={};Ce(Di,{sha256:()=>Nr,sha512:()=>ld});var fd=20;function _i({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Ci(t,e,r,n,o)}var Ci=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??fd,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?Na(n,this.code,r?.truncate):n.then(o=>Na(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Na(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 Jt(e,t)}function Ua(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Nr=_i({name:"sha2-256",code:18,encode:Ua("SHA-256")}),ld=_i({name:"sha2-512",code:19,encode:Ua("SHA-512")});var Ri={...Ii,...Ei,...Ti,...wi,...xi,...fi,...li,...di,...Ai,...Si},b0={...Di,...Bi};function Oa(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Fa=Oa("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Li=Oa("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=_e(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),dd={utf8:Fa,"utf-8":Fa,hex:Ri.base16,latin1:Li,ascii:Li,binary:Li,...Ri},In=dd;function le(t,e="utf8"){let r=In[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Ni(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return _e(s);o+s>e&&(n=_e(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Ot=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function ki(){}var Fi=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},hd=Ni();function pd(t){return globalThis.Buffer!=null?_e(t):hd(t)}var Ur=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ot(ki,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Ot(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Oi((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(Bn,10,De.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=De.fromBigInt(e);return this._push(Bn,r.length(),r)}uint64Number(e){return this._push(xa,Rr(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=De.fromBigInt(e).zzEncode();return this._push(Bn,r.length(),r)}sint64Number(e){let r=De.fromNumber(e).zzEncode();return this._push(Bn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ui,1,e?1:0)}fixed32(e){return this._push(kr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=De.fromBigInt(e);return this._push(kr,4,r.lo)._push(kr,4,r.hi)}fixed64Number(e){let r=De.fromNumber(e);return this._push(kr,4,r.lo)._push(kr,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(Sa,4,e)}double(e){return this._push(Aa,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Ui,1,0):this.uint32(r)._push(yd,r,e)}string(e){let r=Ba(e);return r!==0?this.uint32(r)._push(gi,r,e):this._push(Ui,1,0)}fork(){return this.states=new Fi(this),this.head=this.tail=new Ot(ki,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 Ot(ki,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=pd(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Ui(t,e,r){e[r]=t&255}function md(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Oi=class extends Ot{next;constructor(e,r){super(md,e,r),this.next=void 0}};function Bn(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 kr(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 yd(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Ur.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(gd,e,t),this},Ur.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(bd,e,t),this});function gd(t,e,r){e.set(t,r)}function bd(t,e,r){t.length<40?gi(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(le(t),r)}function Pi(){return new Ur}function Ge(t,e){let r=Pi();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Xe(t,e,r){let n=Lr(t);yield*e.stream(n,".",void 0,r)}var Cn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function _n(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Fr(t){function e(i){if(t[i.toString()]==null)throw new Error("Invalid enum value");return t[i]}let r=function(s,a){let c=e(s);a.int32(c)},n=function(s){let a=s.int32();return e(a)},o=function*(s,a){};return _n("enum",Cn.VARINT,r,n,o)}function We(t,e,r){return _n("message",Cn.LENGTH_DELIMITED,t,e,r)}var te;(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=()=>Fr(r)})(e=t.ValidityType||(t.ValidityType={}));let n;t.codec=()=>(n==null&&(n=We((a,c,f={})=>{f.lengthDelimited!==!1&&c.fork(),a.value!=null&&(c.uint32(10),c.bytes(a.value)),a.signatureV1!=null&&(c.uint32(18),c.bytes(a.signatureV1)),a.validityType!=null&&(c.uint32(24),t.ValidityType.codec().encode(a.validityType,c)),a.validity!=null&&(c.uint32(34),c.bytes(a.validity)),a.sequence!=null&&(c.uint32(40),c.uint64(a.sequence)),a.ttl!=null&&(c.uint32(48),c.uint64(a.ttl)),a.publicKey!=null&&(c.uint32(58),c.bytes(a.publicKey)),a.signatureV2!=null&&(c.uint32(66),c.bytes(a.signatureV2)),a.data!=null&&(c.uint32(74),c.bytes(a.data)),f.lengthDelimited!==!1&&c.ldelim()},(a,c,f={})=>{let u={},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let h=a.uint32();switch(h>>>3){case 1:{u.value=a.bytes();break}case 2:{u.signatureV1=a.bytes();break}case 3:{u.validityType=t.ValidityType.codec().decode(a);break}case 4:{u.validity=a.bytes();break}case 5:{u.sequence=a.uint64();break}case 6:{u.ttl=a.uint64();break}case 7:{u.publicKey=a.bytes();break}case 8:{u.signatureV2=a.bytes();break}case 9:{u.data=a.bytes();break}default:{a.skipType(h&7);break}}}return u},function*(a,c,f,u={}){let l=f==null?a.len:a.pos+f;for(c!=="."&&(yield{field:c.endsWith(".")?c.substring(0,c.length-1):c,type:"start",message:"IPNSEntry"});a.pos<l;){let h=a.uint32();switch(h>>>3){case 1:{yield{field:`${c}value`,value:a.bytes()};break}case 2:{yield{field:`${c}signatureV1`,value:a.bytes()};break}case 3:{yield{field:`${c}validityType`,value:t.ValidityType.codec().decode(a)};break}case 4:{yield{field:`${c}validity`,value:a.bytes()};break}case 5:{yield{field:`${c}sequence`,value:a.uint64()};break}case 6:{yield{field:`${c}ttl`,value:a.uint64()};break}case 7:{yield{field:`${c}publicKey`,value:a.bytes()};break}case 8:{yield{field:`${c}signatureV2`,value:a.bytes()};break}case 9:{yield{field:`${c}data`,value:a.bytes()};break}default:{a.skipType(h&7);break}}}c!=="."&&(yield{field:c.endsWith(".")?c.substring(0,c.length-1):c,type:"end",message:"IPNSEntry"})})),n);function o(a){return Ge(a,t.codec())}t.encode=o;function i(a,c){return Ze(a,t.codec(),c)}t.decode=i;function s(a,c){return Xe(a,t.codec(),c)}t.stream=s})(te||(te={}));var ns=ii(Dn(),1);function ee(t,e="utf8"){let r=In[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}function wd(t){return t?.buffer instanceof ArrayBuffer}function Pa(t){if(wd(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function xt(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=_e(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return Pa(r)}function be(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var Ka=Symbol.for("@achingbrain/uint8arraylist");function Ma(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function Rn(t){return!!t?.[Ka]}var Re=class t{bufs;length;[Ka]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Rn(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Rn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=Ma(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Ma(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(Rn(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return xt(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:xt(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),i=new t;return i.length=o,i.bufs=n,i}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let f=e>=a&&e<c,u=r>a&&r<=c;if(f&&u){if(e===a&&r===c){n.push(s);break}let l=e-a;n.push(s.subarray(l,l+(r-e)));break}if(f){if(e===0){n.push(s);continue}n.push(s.subarray(e-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-e}}indexOf(e,r=0){if(!Rn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=r;l<=c;l+=u){u=0;for(let h=f;h>=0;h--){let m=this.get(l+h);if(n[h]!==m){u=Math.max(1,h-a[m]);break}}if(u===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=_e(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=Pe(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=Pe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=Pe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=_e(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=Pe(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=Pe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=Pe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=Pe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=Pe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!be(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};function Ln(t){return t==null?!1:typeof t.type=="string"&&typeof t.code=="number"&&typeof t.verify=="function"}var xd=["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 Ki(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=Ed(t);return r||"Object"}function Ed(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(xd.includes(e))return e}var d=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}};d.uint=new d(0,"uint",!0);d.negint=new d(1,"negint",!0);d.bytes=new d(2,"bytes",!0);d.string=new d(3,"string",!0);d.array=new d(4,"array",!1);d.map=new d(5,"map",!1);d.tag=new d(6,"tag",!1);d.float=new d(7,"float",!0);d.false=new d(7,"false",!0);d.true=new d(7,"true",!0);d.null=new d(7,"null",!0);d.undefined=new d(7,"undefined",!0);d.break=new d(7,"break",!0);var D=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Or=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Sd=new TextEncoder;function Nn(t){return Or&&globalThis.Buffer.isBuffer(t)}function Pr(t){return t instanceof Uint8Array?Nn(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var vd=24,Ad=200,kn=Or?t=>t.length>=vd?globalThis.Buffer.from(t):Va(t):t=>t.length>=Ad?Sd.encode(t):Va(t),Qe=t=>Uint8Array.from(t),$a=Or?(t,e,r)=>Nn(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),qa=Or?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Pr(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},Vi=Or?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function tr(t,e){if(Nn(t)&&Nn(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 Va(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 Td=256,Mr=class{constructor(e=Td){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)}pushByte(e){let r=this.chunks[this.chunks.length-1];this.cursor>this.maxCursor&&(r=Vi(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r));let n=r.length-(this.maxCursor-this.cursor)-1;r[n]=e,this.cursor++}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=Vi(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=$a(n,0,this.cursor)}else r=qa(this.chunks,this.cursor);return e&&this.reset(),r}},Un=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}pushByte(e){if(this.cursor>=this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest[this.cursor++]=e}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 V="CBOR decode error:",Fn="CBOR encode error:",Kr=[];Kr[23]=1;Kr[24]=2;Kr[25]=3;Kr[26]=5;Kr[27]=9;function it(t,e,r){if(t.length-e<r)throw new Error(`${V} not enough data for type`)}var we=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Le(t,e,r){it(t,e,1);let n=t[e];if(r.strict===!0&&n<we[0])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function Ne(t,e,r){it(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<we[1])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function ke(t,e,r){it(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<we[2])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function Ue(t,e,r){it(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<we[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 za(t,e,r,n){return new D(d.uint,Le(t,e+1,n),2)}function Ha(t,e,r,n){return new D(d.uint,Ne(t,e+1,n),3)}function ja(t,e,r,n){return new D(d.uint,ke(t,e+1,n),5)}function Ya(t,e,r,n){return new D(d.uint,Ue(t,e+1,n),9)}function Je(t,e){return he(t,0,e.value)}function he(t,e,r){if(r<we[0]){let n=Number(r);t.pushByte(e|n)}else if(r<we[1]){let n=Number(r);t.push([e|24,n])}else if(r<we[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<we[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<we[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(`${V} encountered BigInt larger than allowable range`)}}Je.encodedSize=function(e){return he.encodedSize(e.value)};he.encodedSize=function(e){return e<we[0]?1:e<we[1]?2:e<we[2]?3:e<we[3]?5:9};Je.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Za(t,e,r,n){return new D(d.negint,-1-Le(t,e+1,n),2)}function Ga(t,e,r,n){return new D(d.negint,-1-Ne(t,e+1,n),3)}function Xa(t,e,r,n){return new D(d.negint,-1-ke(t,e+1,n),5)}var $i=BigInt(-1),Wa=BigInt(1);function Qa(t,e,r,n){let o=Ue(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new D(d.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${V} integers outside of the safe integer range are not supported`);return new D(d.negint,$i-BigInt(o),9)}function On(t,e){let r=e.value,n=typeof r=="bigint"?r*$i-Wa:r*-1-1;he(t,e.type.majorEncoded,n)}On.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*$i-Wa:r*-1-1;return n<we[0]?1:n<we[1]?2:n<we[2]?3:n<we[3]?5:9};On.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Vr(t,e,r,n){it(t,e,r+n);let o=t.slice(e+r,e+r+n);return new D(d.bytes,o,r+n)}function Ja(t,e,r,n){return Vr(t,e,1,r)}function ec(t,e,r,n){return Vr(t,e,2,Le(t,e+1,n))}function tc(t,e,r,n){return Vr(t,e,3,Ne(t,e+1,n))}function rc(t,e,r,n){return Vr(t,e,5,ke(t,e+1,n))}function nc(t,e,r,n){let o=Ue(t,e+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer bytes lengths not supported`);return Vr(t,e,9,o)}function Pn(t){return t.encodedBytes===void 0&&(t.encodedBytes=d.equals(t.type,d.string)?kn(t.value):t.value),t.encodedBytes}function rr(t,e){let r=Pn(e);he(t,e.type.majorEncoded,r.length),t.push(r)}rr.encodedSize=function(e){let r=Pn(e);return he.encodedSize(r.length)+r.length};rr.compareTokens=function(e,r){return Bd(Pn(e),Pn(r))};function Bd(t,e){return t.length<e.length?-1:t.length>e.length?1:tr(t,e)}var oc=new TextDecoder,_d=32;function Dd(t,e,r){if(r-e<_d){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return oc.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return oc.decode(t.subarray(e,r))}function $r(t,e,r,n,o){let i=r+n;it(t,e,i);let s=new D(d.string,Dd(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function ic(t,e,r,n){return $r(t,e,1,r,n)}function sc(t,e,r,n){return $r(t,e,2,Le(t,e+1,n),n)}function ac(t,e,r,n){return $r(t,e,3,Ne(t,e+1,n),n)}function cc(t,e,r,n){return $r(t,e,5,ke(t,e+1,n),n)}function uc(t,e,r,n){let o=Ue(t,e+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer string lengths not supported`);return $r(t,e,9,o,n)}var fc=rr;function nr(t,e,r,n){return new D(d.array,n,r)}function lc(t,e,r,n){return nr(t,e,1,r)}function dc(t,e,r,n){return nr(t,e,2,Le(t,e+1,n))}function hc(t,e,r,n){return nr(t,e,3,Ne(t,e+1,n))}function pc(t,e,r,n){return nr(t,e,5,ke(t,e+1,n))}function mc(t,e,r,n){let o=Ue(t,e+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer array lengths not supported`);return nr(t,e,9,o)}function yc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return nr(t,e,1,1/0)}function Mn(t,e){he(t,d.array.majorEncoded,e.value)}Mn.compareTokens=Je.compareTokens;Mn.encodedSize=function(e){return he.encodedSize(e.value)};function or(t,e,r,n){return new D(d.map,n,r)}function gc(t,e,r,n){return or(t,e,1,r)}function bc(t,e,r,n){return or(t,e,2,Le(t,e+1,n))}function wc(t,e,r,n){return or(t,e,3,Ne(t,e+1,n))}function xc(t,e,r,n){return or(t,e,5,ke(t,e+1,n))}function Ec(t,e,r,n){let o=Ue(t,e+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer map lengths not supported`);return or(t,e,9,o)}function Sc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return or(t,e,1,1/0)}function Kn(t,e){he(t,d.map.majorEncoded,e.value)}Kn.compareTokens=Je.compareTokens;Kn.encodedSize=function(e){return he.encodedSize(e.value)};function vc(t,e,r,n){return new D(d.tag,r,1)}function Ac(t,e,r,n){return new D(d.tag,Le(t,e+1,n),2)}function Tc(t,e,r,n){return new D(d.tag,Ne(t,e+1,n),3)}function Ic(t,e,r,n){return new D(d.tag,ke(t,e+1,n),5)}function Bc(t,e,r,n){return new D(d.tag,Ue(t,e+1,n),9)}function Vn(t,e){he(t,d.tag.majorEncoded,e.value)}Vn.compareTokens=Je.compareTokens;Vn.encodedSize=function(e){return he.encodedSize(e.value)};var $n=20,qn=21,zn=22,Hn=23;function _c(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${V} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new D(d.null,null,1):new D(d.undefined,void 0,1)}function Dc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return new D(d.break,void 0,1)}function qi(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${V} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${V} Infinity values are not supported`)}return new D(d.float,t,e)}function Rc(t,e,r,n){return qi(jn(t,e+1),3,n)}function Lc(t,e,r,n){return qi(Yn(t,e+1),5,n)}function Nc(t,e,r,n){return qi(Fc(t,e+1),9,n)}function qr(t,e,r){let n=e.value;if(n===!1)t.pushByte(d.float.majorEncoded|$n);else if(n===!0)t.pushByte(d.float.majorEncoded|qn);else if(n===null)t.pushByte(d.float.majorEncoded|zn);else if(n===void 0)t.pushByte(d.float.majorEncoded|Hn);else{let o,i=!1;(!r||r.float64!==!0)&&(zi(n),o=jn(pe,1),n===o||Number.isNaN(n)?(pe[0]=249,t.push(pe.slice(0,3)),i=!0):(Hi(n),o=Yn(pe,1),n===o&&(pe[0]=250,t.push(pe.slice(0,5)),i=!0))),i||(Uc(n),o=Fc(pe,1),pe[0]=251,t.push(pe.slice(0,9)))}}qr.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){zi(n);let o=jn(pe,1);if(n===o||Number.isNaN(n))return 3;if(Hi(n),o=Yn(pe,1),n===o)return 5}return 9};var kc=new ArrayBuffer(9),Me=new DataView(kc,1),pe=new Uint8Array(kc,0);function zi(t){if(t===1/0)Me.setUint16(0,31744,!1);else if(t===-1/0)Me.setUint16(0,64512,!1);else if(Number.isNaN(t))Me.setUint16(0,32256,!1);else{Me.setFloat32(0,t);let e=Me.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)Me.setUint16(0,31744,!1);else if(r===0)Me.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Me.setUint16(0,0):o<-14?Me.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):Me.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function jn(t,e){if(t.length-e<2)throw new Error(`${V} 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 Hi(t){Me.setFloat32(0,t,!1)}function Yn(t,e){if(t.length-e<4)throw new Error(`${V} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Uc(t){Me.setFloat64(0,t,!1)}function Fc(t,e){if(t.length-e<8)throw new Error(`${V} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}function Ud(t,e){let r=t.value;if(r===!1)return Uint8Array.of(d.float.majorEncoded|$n);if(r===!0)return Uint8Array.of(d.float.majorEncoded|qn);if(r===null)return Uint8Array.of(d.float.majorEncoded|zn);if(r===void 0)return Uint8Array.of(d.float.majorEncoded|Hn);if(!e){if(zi(r),r===jn(pe,1)||Number.isNaN(r))return pe[0]=249,pe.slice(0,3);if(Hi(r),r===Yn(pe,1))return pe[0]=250,pe.slice(0,5)}return Uc(r),pe[0]=251,pe.slice(0,9)}function Cc(t,e){let r=t,n=e?.float64===!0,o=n?r._keyBytesFloat64:r._keyBytes;if(o!==void 0)return o;let i=Ud(t,n);return n?r._keyBytesFloat64=i:r._keyBytes=i,i}qr.compareTokens=function(e,r,n){let o=Cc(e,n),i=Cc(r,n);return o.length!==i.length?o.length<i.length?-1:1:tr(o,i)};function G(t,e,r){throw new Error(`${V} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function Zn(t){return()=>{throw new Error(`${V} ${t}`)}}var B=[];for(let t=0;t<=23;t++)B[t]=G;B[24]=za;B[25]=Ha;B[26]=ja;B[27]=Ya;B[28]=G;B[29]=G;B[30]=G;B[31]=G;for(let t=32;t<=55;t++)B[t]=G;B[56]=Za;B[57]=Ga;B[58]=Xa;B[59]=Qa;B[60]=G;B[61]=G;B[62]=G;B[63]=G;for(let t=64;t<=87;t++)B[t]=Ja;B[88]=ec;B[89]=tc;B[90]=rc;B[91]=nc;B[92]=G;B[93]=G;B[94]=G;B[95]=Zn("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)B[t]=ic;B[120]=sc;B[121]=ac;B[122]=cc;B[123]=uc;B[124]=G;B[125]=G;B[126]=G;B[127]=Zn("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)B[t]=lc;B[152]=dc;B[153]=hc;B[154]=pc;B[155]=mc;B[156]=G;B[157]=G;B[158]=G;B[159]=yc;for(let t=160;t<=183;t++)B[t]=gc;B[184]=bc;B[185]=wc;B[186]=xc;B[187]=Ec;B[188]=G;B[189]=G;B[190]=G;B[191]=Sc;for(let t=192;t<=215;t++)B[t]=vc;B[216]=Ac;B[217]=Tc;B[218]=Ic;B[219]=Bc;B[220]=G;B[221]=G;B[222]=G;B[223]=G;for(let t=224;t<=243;t++)B[t]=Zn("simple values are not supported");B[244]=G;B[245]=G;B[246]=G;B[247]=_c;B[248]=Zn("simple values are not supported");B[249]=Rc;B[250]=Lc;B[251]=Nc;B[252]=G;B[253]=G;B[254]=G;B[255]=Dc;var je=[];for(let t=0;t<24;t++)je[t]=new D(d.uint,t,1);for(let t=-1;t>=-24;t--)je[31-t]=new D(d.negint,t,1);je[64]=new D(d.bytes,new Uint8Array(0),1);je[96]=new D(d.string,"",1);je[128]=new D(d.array,0,1);je[160]=new D(d.map,0,1);je[244]=new D(d.false,!1,1);je[245]=new D(d.true,!0,1);je[246]=new D(d.null,null,1);function ji(t){switch(t.type){case d.false:return Qe([244]);case d.true:return Qe([245]);case d.null:return Qe([246]);case d.bytes:return t.value.length?void 0:Qe([64]);case d.string:return t.value===""?Qe([96]):void 0;case d.array:return t.value===0?Qe([128]):void 0;case d.map:return t.value===0?Qe([160]):void 0;case d.uint:return t.value<24?Qe([Number(t.value)]):void 0;case d.negint:if(t.value>=-24)return Qe([31-Number(t.value)])}}var Od={float64:!1,mapSorter:Zi,quickEncodeToken:ji},Vc=Object.freeze({mapSorter:Kd,quickEncodeToken:ji});function Pd(){let t=[];return t[d.uint.major]=Je,t[d.negint.major]=On,t[d.bytes.major]=rr,t[d.string.major]=fc,t[d.array.major]=Mn,t[d.map.major]=Kn,t[d.tag.major]=Vn,t[d.float.major]=qr,t}var Kt=Pd(),Gn=new Mr,sr=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(`${Fn} object contains circular references`);return new t(r,e)}},Et={null:new D(d.null,null),undefined:new D(d.undefined,void 0),true:new D(d.true,!0),false:new D(d.false,!1),emptyArray:new D(d.array,0),emptyMap:new D(d.map,0)},et={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new D(d.float,t):t>=0?new D(d.uint,t):new D(d.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new D(d.uint,t):new D(d.negint,t)},Uint8Array(t,e,r,n){return new D(d.bytes,t)},string(t,e,r,n){return new D(d.string,t)},boolean(t,e,r,n){return t?Et.true:Et.false},null(t,e,r,n){return Et.null},undefined(t,e,r,n){return Et.undefined},ArrayBuffer(t,e,r,n){return new D(d.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new D(d.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Et.emptyArray,new D(d.break)]:Et.emptyArray;n=sr.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=Mt(s,r,n);return r.addBreakTokens?[new D(d.array,t.length),o,new D(d.break)]:[new D(d.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=sr.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,f=0;for(let u of i){let l=o?t.get(u):t[u];c&&l===void 0||(a[f++]=[Mt(u,r,n),Mt(l,r,n)])}f<s&&(a.length=f)}return a?.length?(Md(a,r),r.addBreakTokens?[new D(d.map,a.length),a,new D(d.break)]:[new D(d.map,a.length),a]):r.addBreakTokens===!0?[Et.emptyMap,new D(d.break)]:Et.emptyMap},Tagged(t,e,r,n){return[new D(d.tag,t.tag),Mt(t.value,r,n)]}};et.Map=et.Object;et.Buffer=et.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))et[`${t}Array`]=et.DataView;function Mt(t,e={},r){let n=Ki(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||et[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=et[n];if(!i)throw new Error(`${Fn} unsupported type: ${n}`);return i(t,n,e,r)}function Md(t,e){let r=e.mapSorter;r&&t.sort((n,o)=>r(n,o,e))}function Zi(t,e,r){let n=Array.isArray(t[0])?t[0][0]:t[0],o=Array.isArray(e[0])?e[0][0]:e[0];if(n.type.major!==o.type.major)return n.type.compare(o.type);let i=n.type.major,s=Kt[i].compareTokens(n,o,r);return s===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),s}function Kd(t,e){if(t[0]instanceof D&&e[0]instanceof D){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=Oc(r.value)),n._keyBytes||(n._keyBytes=Oc(n.value)),tr(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Oc(t){return $c(t,Kt,Vc)}function ir(t,e,r,n){if(Array.isArray(e))for(let o of e)ir(t,o,r,n);else r[e.type.major](t,e,n)}var Pc=d.uint.majorEncoded,Mc=d.negint.majorEncoded,Vd=d.bytes.majorEncoded,$d=d.string.majorEncoded,Kc=d.array.majorEncoded,Yi=d.map.majorEncoded,qd=d.float.majorEncoded|$n,zd=d.float.majorEncoded|qn,Hd=d.float.majorEncoded|zn,jd=d.float.majorEncoded|Hn,Yd=BigInt(-1),Zd=BigInt(1);function St(t,e,r){r<24?t.pushByte(e|Number(r)):he(t,e,r)}function Gd(t){return t.addBreakTokens!==!0}function Xd(t,e,r,n,o){let i=r==="Map",s=i?e.keys():Object.keys(e),a=i?e.size:s.length;if(!a){t.pushByte(Yi);return}o=sr.createCheck(o,e);let c=!i&&n.ignoreUndefinedProperties,f=new Array(a),u=0;for(let l of s){let h=i?e.get(l):e[l];c&&h===void 0||(f[u++]=[Mt(l,n,o),h])}if(u===0){t.pushByte(Yi);return}u<a&&(f.length=u),f.sort((l,h)=>Zi(l,h,n)),St(t,Yi,u);for(let[l,h]of f)ir(t,l,Kt,n),Gi(t,h,n,o)}function Gi(t,e,r,n){let o=Ki(e),i=r.typeEncoders&&r.typeEncoders[o];if(i){let s=i(e,o,r,n);if(s!=null){ir(t,s,Kt,r);return}}switch(o){case"null":t.pushByte(Hd);return;case"undefined":t.pushByte(jd);return;case"boolean":t.pushByte(e?zd:qd);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?qr(t,new D(d.float,e),r):e>=0?St(t,Pc,e):St(t,Mc,e*-1-1);return;case"bigint":e>=BigInt(0)?St(t,Pc,e):St(t,Mc,e*Yd-Zd);return;case"string":{let s=kn(e);St(t,$d,s.length),t.push(s);return}case"Uint8Array":St(t,Vd,e.length),t.push(e);return;case"Array":if(!e.length){t.pushByte(Kc);return}n=sr.createCheck(n,e),St(t,Kc,e.length);for(let s of e)Gi(t,s,r,n);return;case"Object":case"Map":if(r.mapSorter===Zi)Xd(t,e,o,r,n);else{let s=et.Object(e,o,r,n);ir(t,s,Kt,r)}return;default:{let s=et[o];if(!s)throw new Error(`${Fn} unsupported type: ${o}`);let a=s(e,o,r,n);ir(t,a,Kt,r)}}}function $c(t,e,r,n){let o=n instanceof Uint8Array,i=o?new Un(n):Gn,s=Mt(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let f=c.encodedSize(s,r);if(o||(i=new Mr(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():Pr(i.chunks[0])}}return i.reset(),ir(i,s,e,r),i.toBytes(!0)}function Xi(t,e){return e=Object.assign({},Od,e),Gd(e)?(Gn.reset(),Gi(Gn,t,e,void 0),Gn.toBytes(!0)):$c(t,Kt,e)}var Wd={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Xn=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=je[e];if(r===void 0){let n=B[e];if(!n)throw new Error(`${V} 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}},vt=Symbol.for("DONE"),ar=Symbol.for("BREAK");function Qd(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=At(e,r);if(i===ar){if(t.value===1/0)break;throw new Error(`${V} got unexpected break to lengthed array`)}if(i===vt)throw new Error(`${V} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Jd(t,e,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=At(e,r);if(c===ar){if(t.value===1/0)break;throw new Error(`${V} got unexpected break to lengthed map`)}if(c===vt)throw new Error(`${V} found map but not enough entries (got ${a} [no key], expected ${t.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=At(e,r);if(f===vt)throw new Error(`${V} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,f):c==="__proto__"?Object.defineProperty(i,c,{value:f,configurable:!0,enumerable:!0,writable:!0}):i[c]=f}return n?s:i}function*eh(t,e,r){for(let n=0;n<t.value;n++){let o=At(e,r);if(o===ar){if(t.value===1/0)break;throw new Error(`${V} got unexpected break to lengthed map`)}if(o===vt)throw new Error(`${V} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let i=At(e,r);if(i===vt)throw new Error(`${V} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,i]}}function th(t,e){let r=function(){if(r._called)throw new Error(`${V} tag decode() may only be called once`);r._called=!0;let n=At(t,e);if(n===vt)throw new Error(`${V} tag content missing`);if(n===ar)throw new Error(`${V} got unexpected break in tag content`);return n};return r.entries=function(){if(r._called)throw new Error(`${V} tag decode() may only be called once`);r._called=!0;let n=t.next();if(!d.equals(n.type,d.map))throw new Error(`${V} entries() requires map content, got ${n.type.name}`);let o=[];for(let i of eh(n,t,e))o.push(i);return o},r._called=!1,r}function At(t,e){if(t.done())return vt;let r=t.next();if(d.equals(r.type,d.break))return ar;if(r.type.terminal)return r.value;if(d.equals(r.type,d.array))return Qd(r,t,e);if(d.equals(r.type,d.map))return Jd(r,t,e);if(d.equals(r.type,d.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=th(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${V} tag decoder must call decode() or entries()`);return o}throw new Error(`${V} tag not supported (${r.value})`)}throw new Error("unsupported")}function qc(t,e){if(!(t instanceof Uint8Array))throw new Error(`${V} data to decode must be a Uint8Array`);e=Object.assign({},Wd,e);let r=Pr(t),n=e.tokenizer||new Xn(r,e),o=At(n,e);if(o===vt)throw new Error(`${V} did not find any content to decode`);if(o===ar)throw new Error(`${V} got unexpected break`);return[o,t.subarray(n.pos())]}function Wi(t,e){let[r,n]=qc(t,e);if(n.length>0)throw new Error(`${V} too many terminals, data makes no sense`);return r}var Wn=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(Wn.prototype,Symbol.toStringTag,{value:"Tagged"});var zc=42;function nh(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function oh(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=se.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new D(d.tag,zc),new D(d.bytes,r)]}function ih(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function sh(t){if(Number.isNaN(t))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(t===1/0||t===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}function ah(t){for(let e of t.keys())if(typeof e!="string"||e.length===0)throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");return null}var Qi={float64:!0,typeEncoders:{Map:ah,Object:oh,undefined:ih,number:sh}},Sg={...Qi,typeEncoders:{...Qi.typeEncoders}};function ch(t){let e=t();if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return se.decode(e.subarray(1))}var Ji={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[zc]:ch}},vg={...Ji,tags:{...Ji.tags}};var Hc=t=>Xi(t,Qi),jc=t=>Wi(nh(t),Ji);var tt=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var st=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Qn=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var zr=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var Jn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Hr=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};function Yc(t){return t==null?!1:(t.type==="RSA"||t.type==="Ed25519"||t.type==="secp256k1"||t.type==="ECDSA")&&t.raw instanceof Uint8Array&&typeof t.equals=="function"&&typeof t.toMultihash=="function"&&typeof t.toCID=="function"&&typeof t.verify=="function"}var es=Symbol.for("@libp2p/peer-id");function fh(t){return typeof t?.handleEvent=="function"}function lh(t){return t===!0||t===!1}function dh(t){return lh(t)?t:t?.capture??!1}function ts(t){let e={capture:dh(t),once:!!t?.once};return t?.passive!=null&&(e.passive=t?.passive),t?.signal!=null&&(e.signal=t?.signal),e}function Zc(t,e){return ts(t).capture===ts(e).capture}var eo=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=ts(n);if(o?.signal?.aborted===!0)return;let i=f=>{o.once&&this.removeEventListener(e,r,o),fh(r)?r.handleEvent(f):r(f)},s=this.#e.get(e);if(s==null&&(s=[],this.#e.set(e,s)),s.some(f=>f.callback!==r?!1:Zc(f.options,o)))return;super.addEventListener(e,i,o);let c=()=>{this.removeEventListener(e,r,o)};o.signal?.addEventListener("abort",c),s.push({callback:r,wrapper:i,options:o,onAbort:c})}removeEventListener(e,r,n){let o=this.#e.get(e);if(o==null){super.removeEventListener(e,r??null,n);return}this.#e.set(e,o.filter(i=>i.callback===r&&Zc(i.options,n)?(super.removeEventListener(e,i.wrapper,n),i.options?.signal?.removeEventListener("abort",i.onAbort),!1):!0))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var at="/",Gc=new TextEncoder().encode(at),to=Gc[0],cr=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=le(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]!==to)throw new Error("Invalid key")}toString(e="utf8"){return ee(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(at))}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=Gc),this._buf[0]!==to){let e=new Uint8Array(this._buf.byteLength+1);e.fill(to,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===to;)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(at).slice(1)}type(){return hh(this.baseNamespace())}name(){return ph(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(at)||(e+=at),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(at):new t(e.slice(0,-1).join(at))}child(e){return this.toString()===at?e:e.toString()===at?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(),...mh(e.map(r=>r.namespaces()))])}};function hh(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function ph(t){let e=t.split(":");return e[e.length-1]}function mh(t){return[].concat(...t)}var Xc=114,Wc=0;var Qc=le("/ipns/"),ro="/ipns/";function Jc(t,e){return t.code===e}var no="/dht/record/",gh="/ipns/metadata/";function jr(t){return new cr(no+ee(t,"base32"),!1)}function oo(t){return new cr(gh+ee(t,"base32"),!1)}function eu(t,e){let r=Date.now();return t.getTime()+1728e5-r<864e5||e.getTime()-r<864e5}function tu(t,e,r){let n=le(e);return xt([t,r,n],t.byteLength+r.byteLength+n.byteLength)}function io(t){let e=le("ipns-signature:");return xt([e,t])}function rs(t){try{return`/ipfs/${se.decode(t)}`}catch{}return ee(t)}function ct(t){return xt([Qc,t.bytes])}function so(t){return mt(t.slice(Qc.length))}function ru(t){return Ae(Hc(t))}function Ke(t){if(t==null)throw new vn("Record data is missing");let e=jc(t);if(e.ValidityType===0&&(e.ValidityType=te.ValidityType.EOL),e.ValidityType!==te.ValidityType.EOL)throw new er("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 ao(t){if(t!=null){if(Ln(t))return`/ipns/${t.toCID().toV1().toString(ve)}`;let e=ou(t);if(e!=null)return e.code===Xc?`/ipns/${e.toV1().toString(ve)}`:`/ipfs/${e.toV1()}`;if(wh(t))return`/ipns/${ve.encode(t.bytes)}`;let r=t.toString().trim();if(r.startsWith("/ipfs/")){let[,n,...o]=r.split("/").filter(i=>i.trim()!=="");return`/ipfs/${se.parse(n).toV1()}${o.length>0?`/${o.join("/")}`:""}`}if(r.startsWith("/")&&r.length>1)return r}throw new gt("Value must be a valid content path starting with /")}function bh(t){return typeof t.code=="number"&&t.digest instanceof Uint8Array&&typeof t.size=="number"&&t.bytes instanceof Uint8Array}function Yr(t){if(t!=null){if(Ln(t))return{digest:t.toMultihash(),path:"/"};let e=ou(t);if(e!=null){if(e.code!==Xc)throw new gt("CIDs must have the `libp2p-key` codec");return{digest:e.multihash,path:"/"}}if(bh(t))return{digest:t,path:"/"};if(t=t.toString(),t.startsWith("/ipns/")){let[,,r,...n]=t.split("/"),o=ve;(r.startsWith("1")||r.startsWith("Q"))&&(r=`z${r}`,o=re);let i=o.decode(r),s;try{s=se.decode(i).multihash}catch{s=mt(i)}return{digest:s,path:`/${n.join("/")}`}}}throw new gt("Value must be a valid IPNS path starting with /")}function nu(t,e){if(!be(e.Value,t.value??new Uint8Array(0)))throw new qe('Field "value" did not match between protobuf and CBOR');if(!be(e.Validity,t.validity??new Uint8Array(0)))throw new qe('Field "validity" did not match between protobuf and CBOR');if(e.ValidityType!==t.validityType)throw new qe('Field "validityType" did not match between protobuf and CBOR');if(e.Sequence!==t.sequence)throw new qe('Field "sequence" did not match between protobuf and CBOR');if(e.TTL!==t.ttl)throw new qe('Field "ttl" did not match between protobuf and CBOR')}function wh(t){return t.bytes instanceof Uint8Array}function xh(t){return typeof t?.toCID=="function"}function ou(t){if(xh(t))return t.toCID();try{return se.parse(t)}catch{}return se.asCID(t)}function Tt(t,e){let r=e.map((n,o)=>({record:n,index:o}));return r.sort((n,o)=>{let i=Ke(n.record.data),s=Ke(o.record.data),a=i.Sequence,c=s.Sequence;if(a>c)return-1;if(a<c)return 1;if(i.ValidityType===te.ValidityType.EOL&&s.ValidityType===te.ValidityType.EOL){let f=ns.default.fromString(ee(i.Validity)).toDate(),u=ns.default.fromString(ee(s.Validity)).toDate();if(f.getTime()>u.getTime())return-1;if(f.getTime()<u.getTime())return 1}return 0}),r[0].index}var iu=ii(Dn(),1);var Eh=1024*10;async function rt(t,e,r,n){if(e.byteLength>Eh)throw new Sn("The record is too large");let o=te.decode(e);if(o.signatureV2==null)throw new qe("Missing signatureV2");let i=Ke(o.data),s=ee(i.Validity),a,c=so(t);if(Jc(c,0)&&(a=await r.loadPublicKeyFromProtobuf(c.digest,n)),a==null&&o.publicKey!=null&&(a=await r.loadPublicKeyFromProtobuf(o.publicKey,n)),a==null)throw new An("Could not extract public key from IPNS record or routing key");let f;try{if(o.data==null)throw new Error("Missing data");let u=io(o.data);f=await a.verify(u,o.signatureV2,n)}catch{f=!1}if(!f)throw new qe("Record signature verification failed");if(i.ValidityType===te.ValidityType.EOL){if(iu.default.fromString(s).toDate().getTime()<Date.now())throw new En("record has expired")}else if(i.ValidityType!=null)throw new er(`The validity type ${i.ValidityType} is unsupported`);return o.value!=null&&o.signatureV1!=null&&nu(o,i),o}var ur=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}=Yr(e);for(;;){let o=ct(n),i=await this.#e(o,r),s="";if(i.data!=null){let a=Ke(i.data);s=rs(a.Value)}else if(i.value!=null)s=rs(i.value);else throw new gt(`Record for key ${ve.encode(n.bytes)} contained no value`);if(yield{record:i,value:s},!s.startsWith(ro))break;({digest:n}=Yr(s))}}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:c,created:f}=await this.localStore.get(e,r);this.log("record retrieved from cache");let u;r.validate===!1?(u=te.decode(c),this.log("skipped validation of record")):(u=await rt(e,c,this.keychain,r),this.log("record was valid"));let l=Ke(u.data),h=Number((l.TTL??gn)/1000000n);if(f.getTime()+h>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(u)}catch(c){this.log("cached record was invalid - %e",c),await this.localStore.delete(e,r)}else this.log("ignoring local cache due to nocache=true option");if(r.offline===!0)throw new Dr("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(e,{...r,validate:!1})}catch(u){this.log.error("error finding IPNS record using router %s - %e",c.toString(),u),s.push(u);return}try{let u;r.validate===!1?u=te.decode(f):u=await rt(e,f,this.keychain,r),n.push(u)}catch(u){i++,this.log.error("error validating IPNS record from router %s - %e",c.toString(),u)}})),n.length===0)throw i>0?new bn(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`):new Dr("Could not find record for routing key");let a=n[Tt(e,n)];return await this.localStore.put(e,te.encode(a),r),a}};var me=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};function co(t,e){if(typeof t=="string")return Sh(t);if(typeof t=="number")return Th(t,e);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}function Sh(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 vh(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 Ah(t){let e=Math.abs(t);return e>=315576e5?Vt(t,e,315576e5,"year"):e>=26298e5?Vt(t,e,26298e5,"month"):e>=6048e5?Vt(t,e,6048e5,"week"):e>=864e5?Vt(t,e,864e5,"day"):e>=36e5?Vt(t,e,36e5,"hour"):e>=6e4?Vt(t,e,6e4,"minute"):e>=1e3?Vt(t,e,1e3,"second"):`${t} ms`}function Th(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?Ah(t):vh(t)}function Vt(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function os(t){r.debug=r,r.default=r,r.coerce=c,r.disable=i,r.enable=o,r.enabled=s,r.humanize=co,r.destroy=f,Object.keys(t).forEach(u=>{r[u]=t[u]}),r.names=[],r.skips=[],r.formatters={};function e(u){let l=0;for(let h=0;h<u.length;h++)l=(l<<5)-l+u.charCodeAt(h),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=e;function r(u,l){let h,m=null,C,x;function g(...S){if(!g.enabled)return;let T=g,y=Number(new Date),R=y-(h||y);T.diff=R,T.prev=h,T.curr=y,h=y,S[0]=r.coerce(S[0]),typeof S[0]!="string"&&S.unshift("%O");let _=0;S[0]=S[0].replace(/%([a-zA-Z%])/g,(q,b)=>{if(q==="%%")return"%";_++;let E=r.formatters[b];if(typeof E=="function"){let v=S[_];q=E.call(T,v),S.splice(_,1),_--}return q}),r.formatArgs.call(T,S),l?.onLog!=null&&l.onLog(...S),(T.log||r.log).apply(T,S)}return g.namespace=u,g.useColors=r.useColors(),g.color=r.selectColor(u),g.extend=n,g.destroy=r.destroy,Object.defineProperty(g,"enabled",{enumerable:!0,configurable:!1,get:()=>m!==null?m:(C!==r.namespaces&&(C=r.namespaces,x=r.enabled(u)),x),set:S=>{m=S}}),typeof r.init=="function"&&r.init(g),g}function n(u,l){let h=r(this.namespace+(typeof l>"u"?":":l)+u);return h.log=this.log,h}function o(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];let l,h=(typeof u=="string"?u:"").split(/[\s,]+/),m=h.length;for(l=0;l<m;l++)h[l]&&(u=h[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,h;for(l=0,h=r.skips.length;l<h;l++)if(r.skips[l].test(u))return!1;for(l=0,h=r.names.length;l<h;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 uo=Lh(),Ih=["#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 Bh(){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 Ch(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+co(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 _h=console.debug??console.log??(()=>{});function Dh(t){try{t?uo?.setItem("debug",t):uo?.removeItem("debug")}catch{}}function Rh(){let t;try{t=uo?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function Lh(){try{return localStorage}catch{}}function Nh(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var su=os({formatArgs:Ch,save:Dh,load:Rh,useColors:Bh,setupFormatters:Nh,colors:Ih,storage:uo,log:_h});var Te=su;Te.formatters.b=t=>t==null?"undefined":re.baseEncode(t);Te.formatters.t=t=>t==null?"undefined":pt.baseEncode(t);Te.formatters.m=t=>t==null?"undefined":vi.baseEncode(t);Te.formatters.p=t=>t==null?"undefined":t.toString();Te.formatters.c=t=>t==null?"undefined":t.toString();Te.formatters.k=t=>t==null?"undefined":t.toString();Te.formatters.a=t=>t==null?"undefined":t.toString();function au(t,e=""){let r=cu(t.message),n=cu(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
4
4
  `).join(`
5
5
  ${e}`)}`:`${r}
6
6
  ${e}${n.split(`
7
7
  `).join(`
8
8
  ${e}`)}`:n!=null?`${n.split(`
9
9
  `).join(`
10
- ${e}`)}`:r!=null?`${r}`:`${t.toString()}`}function Nh(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function uu(t,e=""){if(Nh(t)){let r=au(t,e);return t.errors.length>0?(e=`${e} `,r+=`
10
+ ${e}`)}`:r!=null?`${r}`:`${t.toString()}`}function kh(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function uu(t,e=""){if(kh(t)){let r=au(t,e);return t.errors.length>0?(e=`${e} `,r+=`
11
11
  ${e}${t.errors.map(n=>`${uu(n,`${e}`)}`).join(`
12
12
  ${e}`)}`):r+=`
13
- ${e}[Error list was empty]`,r.trim()}return au(t,e)}Ee.formatters.e=t=>t==null?"undefined":uu(t);function Uh(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 Zr(t,e){let r=Uh(`${t}:trace`);return Ee.enabled(`${t}:trace`)&&Ee.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=Ee(`${t}:trace`,e)),Object.assign(Ee(t,e),{error:Ee(`${t}:error`,e),trace:r,newScope:n=>Zr(`${t}:${n}`,e)})}function cu(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var fu=oi(_n(),1);var kh=Zr("ipns"),Fh=300000000000n;async function ur(t,e,r,n,o){r=BigInt(r),e=so(e);let i=se(e),s=o?.ttlNs??Fh,a=new fu.default((o?.now??Date.now())+Number(n)),c=Q.ValidityType.EOL,f=se(a.toString()),u=ru({...o?.data??{},Value:i,Validity:f,ValidityType:0,Sequence:r,TTL:s}),l=oo(u),h=await t.sign(l,o),m;return o?.v1Compatible===!1?m={signatureV2:h,data:u}:m={value:i,signatureV1:await Oh(t,i,c,f),validityType:c,validity:f,sequence:r,ttl:s,signatureV2:h,data:u},Ph(t.publicKey)&&(m.publicKey=t.publicKey.toProtobuf()),m}var Oh=async(t,e,r,n,o)=>{try{let i=tu(e,r,n);return await t.sign(i,o)}catch(i){throw kh.error("record signature creation failed",i),new wn("Record signature creation failed")}};function Ph(t){return t.toMultihash().code!==Wc}var uo=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=it(i),a=1n;if(await this.localStore.has(s,n)){let{record:l}=await this.localStore.get(s,n),h=Q.decode(l);a=(ke(h.data).Sequence??0n)+1n}let c=n.lifetime??1728e5,f=await ur(o,r,a,c,{...n,ttlNs:n.ttl!=null?BigInt(n.ttl)*1000000n:void 0}),u=Q.encode(f);return n.offline===!0?await this.localStore.put(s,u,{...n,metadata:{keyName:e,lifetime:c}}):await Promise.all(this.routers.map(async l=>{await l.put(s,u,{...n,metadata:{keyName:e,lifetime:c}})})),{record:f,name:`/ipns/${o.publicKey.toCID().toString(we)}`,publicKey:o.publicKey}}catch(o){throw n.onProgress?.(new fe("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=it(o);await this.localStore.delete(i,r)}};function fr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var fo=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}},lr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new fo(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 fo(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 os=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function lu(t={}){return Mh(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function Mh(t,e){e=e??{};let r=e.onEnd,n=new lr,o,i,s,a=fr(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((b,E)=>{i=B=>{i=null,n.push(B);try{b(t(n))}catch(y){E(y)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=fr()})}},f=b=>i!=null?i(b):(n.push(b),o),u=b=>(n=new lr,i!=null?i({error:b}):(n.push({error:b}),o)),l=b=>{if(s)return o;if(e?.objectMode!==!0&&b?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:b})},h=b=>s?o:(s=!0,b!=null?u(b):f({done:!0})),m=()=>(n=new lr,h(),{done:!0}),L=b=>(h(b),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:m,throw:L,push:l,end:h,get readableLength(){return n.size},onEmpty:async b=>{let E=b?.signal;if(E?.throwIfAborted(),n.isEmpty())return;let B,y;E!=null&&(B=new Promise((N,U)=>{y=()=>{U(new os)},E.addEventListener("abort",y)}));try{await Promise.race([a.promise,B])}finally{y!=null&&E!=null&&E?.removeEventListener("abort",y)}}},r==null)return o;let v=o;return o={[Symbol.asyncIterator](){return this},next(){return v.next()},throw(b){return v.throw(b),r!=null&&(r(b),r=void 0),{done:!0}},return(){return v.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(b){return v.end(b),r!=null&&(r(b),r=void 0),o},get readableLength(){return v.readableLength},onEmpty:b=>v.onEmpty(b)},o}var is=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},du=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function ss(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,c,u=new Promise((l,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){h(du(s));return}if(s&&(c=()=>{h(du(s))},s.addEventListener("abort",c,{once:!0})),t.then(l,h),r===Number.POSITIVE_INFINITY)return;let m=new is;a=i.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(L){h(L)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?l():o instanceof Error?h(o):(m.message=o??`Promise timed out after ${r} milliseconds`,h(m))},r)}).finally(()=>{u.clear(),c&&s&&s.removeEventListener("abort",c)});return u.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},u}var Kh=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 Vh(t,e,r){let n,o=new Promise((i,s)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:f,removeListener:u}=Kh(t),l=async(...m)=>{let L=r.multiArgs?m:m[0];if(r.filter)try{if(!await r.filter(L))return}catch(v){n(),s(v);return}c.push(L),r.count===c.length&&(n(),i(c))},h=(...m)=>{n(),s(r.rejectionMultiArgs?m:m[0])};n=()=>{for(let m of a)u(m,l);for(let m of r.rejectionEvents)a.includes(m)||u(m,h)};for(let m of a)f(m,l);for(let m of r.rejectionEvents)a.includes(m)||f(m,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(o.cancel=n,typeof r.timeout=="number"){let i=ss(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function lo(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Vh(t,e,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function Gr(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 ho=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function $h(t){return t.reason}function po(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??$h;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;return Promise.race([t,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})]).finally(()=>{o!=null&&e.removeEventListener("abort",o)})}var mo=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=fr(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new rt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function qh(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var yo=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,r){this.id=qh(),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 rt),this.cleanup())}async join(e){let r=new mo(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 po(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 dr=class extends Jn{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=Gr(this.emitEmpty.bind(this),1),this.emitIdle=Gr(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 ho;let n=new yo(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 rt)}),this.clear()}async onEmpty(e){this.size!==0&&await lo(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await lo(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await lo(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=lu({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 rt("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 Xr(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}var hu=Symbol.for("sindresorhus/unlimited-timeout#brand");function pu(t,e,...r){if(typeof t!="function")throw new TypeError("Expected callback to be a function");e??=0,e=Number(e);let n=!1,o={[hu]:!0,id:void 0,cleared:!1,ref(){return n=!1,o.id?.ref?.(),o},unref(){return n=!0,o.id?.unref?.(),o}};if(e===Number.POSITIVE_INFINITY||e>Number.MAX_SAFE_INTEGER)return o;(!Number.isFinite(e)||e<0)&&(e=0);let i=performance.now()+e,s=a=>{o.cleared||(a<=2147483647?(o.id=globalThis.setTimeout(()=>{o.cleared||t(...r)},a),n&&o.id?.unref?.()):(o.id=globalThis.setTimeout(()=>{let c=performance.now(),f=Math.max(0,i-c);s(f)},2147483647),n&&o.id?.unref?.()))};return s(e),o}function mu(t){!t||typeof t!="object"||!t[hu]||(t.cleared=!0,t.id!==void 0&&(globalThis.clearTimeout(t.id),t.id=void 0))}var zh=new WeakMap;function Hh({clearTimeout:t,setTimeout:e}={}){return(r,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(o.reason);let i,s,a,c=t??clearTimeout,f=()=>{c(i),a(o.reason)},u=()=>{o&&o.removeEventListener("abort",f)},l=new Promise((h,m)=>{s=()=>{u(),h(n)},a=m,i=(e??setTimeout)(s,r)});return o&&o.addEventListener("abort",f,{once:!0}),zh.set(l,()=>{c(i),i=null,s()}),l}}var jh=Hh({setTimeout:pu,clearTimeout:mu}),yu=jh;function gu(t,e,r){let n,o,i=!1;function s(){let f={signal:o.signal},u;r?.timeout!=null&&(u=Xr([o.signal,AbortSignal.timeout(r.timeout)]),f.signal=u),i=!0,Promise.resolve().then(async()=>{await t(f)}).catch(()=>{}).finally(()=>{u!=null&&(u.aborted?u.clear():u.addEventListener("abort",()=>{u.clear()},{once:!0})),i=!1,!o.signal.aborted&&(n=setTimeout(s,e))})}let a=Gr(s,r?.debounce??100),c=!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:()=>{c||(c=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,e))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var go=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||ma,this.started=!1,this.routers=r.routers??[],this.republishTask=gu(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 dr({concurrency:this.republishConcurrency});try{let n=[],o=0;for await(let{routingKey:i,record:s,metadata:a,created:c}of this.localStore.list(e)){if(o++,a==null){this.log("no metadata found for record %b, skipping",i);continue}let f;try{f=Q.decode(s)}catch{this.log.trace("skipping invalid record %b because could not decode",i);continue}if(f.data==null){this.log.trace("skipping record %b because data was missing",i);continue}let u;try{u=ke(f.data)}catch{this.log.trace("skipping record %b because could not decode data",i);continue}if(!eu(c,new Date(W(u.Validity)))){this.log.trace("skipping record %b within republish threshold",i);continue}let l=u.Sequence+1n,h=u.TTL??yn,m;try{m=await this.keychain.exportKey(a.keyName)}catch(L){this.log.error("missing key %s, skipping republishing record - %e",a.keyName,L);continue}try{let L=await ur(m,W(u.Value),l,a.lifetime,{...e,ttlNs:h});n.push({routingKey:i,record:L})}catch(L){this.log.error("error creating updated IPNS record for %s - %e",i,L);continue}}this.log(`found ${n.length}/${o} records to republish`);for(let{routingKey:i,record:s}of n)r.add(async()=>{try{let a=Q.encode(s);await Promise.all(this.routers.map(c=>c.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 Wr;(function(t){let e;t.codec=()=>(e==null&&(e=Ze((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:Ne(0),value:Ne(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}}}})),e);function r(i){return je(i,t.codec())}t.encode=r;function n(i,s){return He(i,t.codec(),s)}t.decode=n;function o(i,s){return Ye(i,t.codec(),s)}t.stream=o})(Wr||(Wr={}));function bu(t){let e=t.getUTCFullYear(),r=String(t.getUTCMonth()+1).padStart(2,"0"),n=String(t.getUTCDate()).padStart(2,"0"),o=String(t.getUTCHours()).padStart(2,"0"),i=String(t.getUTCMinutes()).padStart(2,"0"),s=String(t.getUTCSeconds()).padStart(2,"0"),a=t.getUTCMilliseconds(),c=String(a*1e3*1e3).padStart(9,"0");return`${e}-${r}-${n}T${o}:${i}:${s}.${c}Z`}function wu(t){let e=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),r=String(t).trim().match(e);if(r==null)throw new Error("Invalid format");let n=parseInt(r[1],10),o=parseInt(r[2],10)-1,i=parseInt(r[3],10),s=parseInt(r[4],10),a=parseInt(r[5],10),c=parseInt(r[6],10),f=parseInt(r[7].slice(0,-6),10);return new Date(Date.UTC(n,o,i,s,a,c,f))}var vt=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 Wr.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:bu(this.timeReceived)}}static deserialize(e){let r=Wr.decode(e);return new t(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(e){let r=wu(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)}};async function xu(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,xe(e),xe(r.subarray()));return n?.signal?.throwIfAborted(),i}var Gh=parseInt("11111",2),as=parseInt("10000000",2),Xh=parseInt("01111111",2),Eu={0:Qr,1:Qr,2:Wh,3:ep,4:tp,5:Jh,6:Qh,16:Qr,22:Qr,48:Qr};function cs(t,e={offset:0}){let r=t[e.offset]&Gh;if(e.offset++,Eu[r]!=null)return Eu[r](t,e);throw new Error("No decoder for tag "+r)}function Jr(t,e){let r=0;if((t[e.offset]&as)===as){let n=t[e.offset]&Xh,o="0x";e.offset++;for(let i=0;i<n;i++,e.offset++){if(e.offset>=t.byteLength)throw new Error("invalid DER element length");o+=t[e.offset].toString(16).padStart(2,"0")}r=parseInt(o,16)}else r=t[e.offset],e.offset++;if(!Number.isInteger(r)||r<0||r>t.byteLength-e.offset)throw new Error("invalid DER element length");return r}function Qr(t,e){Jr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=cs(t,e);if(n===null)break;r.push(n)}return r}function Wh(t,e){let r=Jr(t,e),n=e.offset,o=e.offset+r,i=[];for(let s=n;s<o;s++)s===n&&t[s]===0||i.push(t[s]);return e.offset+=r,Uint8Array.from(i)}function Qh(t,e){let r=Jr(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;e.offset<n;){let f=t[e.offset];if(e.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 Jh(t,e){return e.offset++,null}function ep(t,e){let r=Jr(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function tp(t,e){let r=Jr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function rp(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new Ie;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function us(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=rp(t.byteLength);return new Ie(Uint8Array.from([e.byteLength|as]),e)}function Su(t){let e=new Ie,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new Ie(Uint8Array.from([2]),us(e),e)}function vu(t){let e=Uint8Array.from([0]),r=new Ie(e,t);return new Ie(Uint8Array.from([3]),us(r),r)}function bo(t,e=48){let r=new Ie;for(let n of t)r.append(n);return new Ie(Uint8Array.from([e]),us(r),r)}var np=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),op=Uint8Array.from([6,5,43,129,4,0,34]),ip=Uint8Array.from([6,5,43,129,4,0,35]),sp={ext:!0,kty:"EC",crv:"P-256"},ap={ext:!0,kty:"EC",crv:"P-384"},cp={ext:!0,kty:"EC",crv:"P-521"},fs=32,ls=48,ds=66;function Au(t){let e=cs(t);return Tu(e)}function Tu(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===fs*2+1)return n=W(e.subarray(r,r+fs),"base64url"),o=W(e.subarray(r+fs),"base64url"),new hr({...sp,key_ops:["verify"],x:n,y:o});if(e.byteLength===ls*2+1)return n=W(e.subarray(r,r+ls),"base64url"),o=W(e.subarray(r+ls),"base64url"),new hr({...ap,key_ops:["verify"],x:n,y:o});if(e.byteLength===ds*2+1)return n=W(e.subarray(r,r+ds),"base64url"),o=W(e.subarray(r+ds),"base64url"),new hr({...cp,key_ops:["verify"],x:n,y:o});throw new nt(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Bu(t){return bo([Su(Uint8Array.from([1])),bo([up(t.crv)],160),bo([vu(new Ie(Uint8Array.from([4]),se(t.x??"","base64url"),se(t.y??"","base64url")))],161)]).subarray()}function up(t){if(t==="P-256")return np;if(t==="P-384")return op;if(t==="P-521")return ip;throw new nt(`Invalid curve ${t}`)}var hr=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Bu(this.jwk)),this._raw}toMultihash(){return Ke.digest(pr(this))}toCID(){return te.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:de(this.raw,e.raw)}async verify(e,r,n){return xu(this.jwk,r,e,n)}};var wo=BigInt(4294967295),Iu=BigInt(32);function fp(t,e=!1){return e?{h:Number(t&wo),l:Number(t>>Iu&wo)}:{h:Number(t>>Iu&wo)|0,l:Number(t&wo)|0}}function Cu(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let i=0;i<r;i++){let{h:s,l:a}=fp(t[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var lp=t=>t/2**32|0,dp=t=>t>>>0;function _u(t,e,r,n){let o=lp(r),i=dp(r);t.setUint32(e,n?i:o,n),t.setUint32(e+4,n?o:i,n)}var hs=(t,e,r)=>t>>>r,ps=(t,e,r)=>t<<32-r|e>>>r,Kt=(t,e,r)=>t>>>r|e<<32-r,Vt=(t,e,r)=>t<<32-r|e>>>r,en=(t,e,r)=>t<<64-r|e>>>r-32,tn=(t,e,r)=>t>>>r-32|e<<64-r;function Je(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Du=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Ru=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Lu=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Nu=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Uu=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ku=(t,e,r,n,o,i)=>e+r+n+o+i+(t/2**32|0)|0;function xo(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var ms=t=>t?`"${t}" `:"";function st(t,e=""){if(typeof t!="number")throw new TypeError(ms(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(ms(e)+"expected integer >= 0, got "+t);return t}function Fe(t,e,r=""){if(xo(t)&&(e===void 0||t.length===e))return t;e!==void 0&&st(e,"length");let n=xo(t),o=e!==void 0?` of length ${e}`:"",i=n?`length=${t.length}`:`type=${typeof t}`,s=ms(r)+"expected Uint8Array"+o+", got "+i;throw n?new RangeError(s):new TypeError(s)}function Eo(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(st(t.outputLen),st(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Fu=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)};function mr(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function So(t,e){Fe(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function $t(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function vo(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function $e(t,e){return t<<32-e|t>>>e}var Pu=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",pp=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Ao(t){if(Fe(t),Pu)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=pp[t[r]];return e}function Ou(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function To(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Pu)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=Ou(t.charCodeAt(i)),a=Ou(t.charCodeAt(i+1));if(s===void 0||a===void 0){let c=t[i]+t[i+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function ys(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Fe(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let i=t[n];r.set(i,o),o+=i.length}return r}function mp(t,e,r="opts"){return Fu(t,"defaults"),e!==void 0&&Fu(e,r),Object.assign(t,e)}function gs(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=mp({},e,"info");let r=(o,i)=>t(i).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function Mu(t=32){st(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var bs=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Ku(t,e,r){return t&e^~t&r}function Vu(t,e,r){return t&e^t&r^e&r}var rn=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=vo(this.buffer)}update(e){mr(this),Fe(e);let{view:r,buffer:n,blockLen:o}=this,i=e.length,s=!1;for(let a=0;a<i;){let c=Math.min(o-this.pos,i-a);if(c===o){let f=vo(e);for(;o<=i-a;a+=o)this.process(f,a);s=!0;continue}n.set(a===0&&c===i?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,s=!0)}return this.length+=e.length,s&&this.roundClean(),this}digestInto(e){mr(this),So(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,r.fill(0,s),this.padOffset>o-s&&(this.process(n,0),r.fill(0)),_u(n,o-8,this.length*8,i),this.process(n,0),this.roundClean();let a=e===r?n:vo(e),c=this.outputLen,f=c/4,u=this.get();if(c%4||f>u.length)throw new Error("invalid outputLen");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],i)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:o,destroyed:i,pos:s}=this;return e.destroyed=i,e.finished=o,e.length=n,e.pos=s,s&&e.buffer.set(r),e}clone(){return this._cloneInto()}},$u=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var qu=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var yp=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]),At=new Uint32Array(64),ws=class extends rn{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,r){super(64,e,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:e,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,r,n,o,i,s,a,c]}set(e,r,n,o,i,s,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let l=0;l<16;l++,r+=4)At[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let h=At[l-15],m=At[l-2],L=$e(h,7)^$e(h,18)^h>>>3,v=$e(m,17)^$e(m,19)^m>>>10;At[l]=v+At[l-7]+L+At[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 h=$e(a,6)^$e(a,11)^$e(a,25),m=u+h+Ku(a,c,f)+yp[l]+At[l]|0,v=($e(n,2)^$e(n,13)^$e(n,22))+Vu(n,o,i)|0;u=f,f=c,c=a,a=s+m|0,s=i,i=o,o=n,n=m+v|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(){$t(At)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),$t(this.buffer)}},xs=class extends ws{constructor(){super(32,$u)}};var zu=Cu(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),gp=zu[0],bp=zu[1],Tt=new Uint32Array(80),Bt=new Uint32Array(80),Es=class extends rn{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(e,r){super(128,e,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:h,Gh:m,Gl:L,Hh:v,Hl:b}=this;return[e,r,n,o,i,s,a,c,f,u,l,h,m,L,v,b]}set(e,r,n,o,i,s,a,c,f,u,l,h,m,L,v,b){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=h|0,this.Gh=m|0,this.Gl=L|0,this.Hh=v|0,this.Hl=b|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let y=0;y<16;y++,r+=4)Tt[y]=e.getUint32(r),Bt[y]=e.getUint32(r+=4);for(let y=16;y<80;y++){let N=Tt[y-15]|0,U=Bt[y-15]|0,V=Kt(N,U,1)^Kt(N,U,8)^hs(N,U,7),$=Vt(N,U,1)^Vt(N,U,8)^ps(N,U,7),w=Tt[y-2]|0,S=Bt[y-2]|0,I=Kt(w,S,19)^en(w,S,61)^hs(w,S,6),F=Vt(w,S,19)^tn(w,S,61)^ps(w,S,6),x=Lu($,F,Bt[y-7],Bt[y-16]),q=Nu(x,V,I,Tt[y-7],Tt[y-16]);Tt[y]=q|0,Bt[y]=x|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:h,Fh:m,Fl:L,Gh:v,Gl:b,Hh:E,Hl:B}=this;for(let y=0;y<80;y++){let N=Kt(l,h,14)^Kt(l,h,18)^en(l,h,41),U=Vt(l,h,14)^Vt(l,h,18)^tn(l,h,41),V=l&m^~l&v,$=h&L^~h&b,w=Uu(B,U,$,bp[y],Bt[y]),S=ku(w,E,N,V,gp[y],Tt[y]),I=w|0,F=Kt(n,o,28)^en(n,o,34)^en(n,o,39),x=Vt(n,o,28)^tn(n,o,34)^tn(n,o,39),q=n&i^n&a^i&a,C=o&s^o&c^s&c;E=v|0,B=b|0,v=m|0,b=L|0,m=l|0,L=h|0,{h:l,l:h}=Je(f|0,u|0,S|0,I|0),f=a|0,u=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let A=Du(I,x,C);n=Ru(A,S,F,q),o=A|0}({h:n,l:o}=Je(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Je(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Je(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=Je(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:h}=Je(this.Eh|0,this.El|0,l|0,h|0),{h:m,l:L}=Je(this.Fh|0,this.Fl|0,m|0,L|0),{h:v,l:b}=Je(this.Gh|0,this.Gl|0,v|0,b|0),{h:E,l:B}=Je(this.Hh|0,this.Hl|0,E|0,B|0),this.set(n,o,i,s,a,c,f,u,l,h,m,L,v,b,E,B)}roundClean(){$t(Tt,Bt)}destroy(){this.destroyed=!0,$t(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Ss=class extends Es{constructor(){super(64,qu)}};var Hu=gs(()=>new xs,bs(1));var vs=gs(()=>new Ss,bs(3));function Io(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}var G=(t,e,r)=>Fe(t,e,r),As=st;function Yu(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function It(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function qt(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var nn=Ao,Oe=(...t)=>ys(...t),yr=t=>To(t),_t=xo,zt=t=>Mu(t),Bo=BigInt(0),ju=BigInt(1),wp=t=>t?`"${t}" `:"";function Se(t,e=""){if(typeof t!="boolean")throw new TypeError(wp(e)+"expected boolean, got type="+typeof t);return t}function Co(t){if(typeof t=="bigint"){if(!Ct(t))throw new RangeError("positive bigint expected, got "+t)}else As(t);return t}function Dt(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function on(t){let e=Co(t).toString(16);return e.length&1?"0"+e:e}function Zu(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Bo:BigInt("0x"+t)}function et(t){return Zu(Ao(t))}function Ht(t){return Zu(Ao(Do(Fe(t)).reverse()))}function _o(t,e){if(st(e),e===0)throw new Error("zero output length is invalid");t=Co(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return To(n.padStart(r,"0"))}function Ts(t,e){return _o(t,e).reverse()}function Do(t){return Uint8Array.from(G(t))}function Ct(t){return typeof t=="bigint"&&Bo<=t}function Bs(t,e,r){return Ct(t)&&Ct(e)&&Ct(r)&&e<=t&&t<r}function gr(t,e,r,n){if(!Bs(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function br(t){if(t<Bo)throw new Error("expected non-negative bigint, got "+t);return t===Bo?0:t.toString(2).length}var sn=t=>(Dt(t,"n"),(ju<<BigInt(t))-ju);function Gu(t,e,r){if(st(t,"hashLen"),st(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=b=>new Uint8Array(b),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=n(t),f=n(t),u=0,l=()=>{c.fill(1),f.fill(0),u=0},h=(...b)=>r(f,Oe(c,...b)),m=(b=o)=>{f=h(i,b),c=h(),b.length!==0&&(f=h(s,b),c=h())},L=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let b=0,E=[];for(;b<e;){c=h();let B=c.slice();E.push(B),b+=c.length}return Oe(...E)};return(b,E)=>{l(),m(b);let B;for(;(B=E(L()))===void 0;)m();return l(),B}}function ve(t,e={},r={},n="object"){It(t,n),It(e,"fields"),It(r,"optFields");function o(s,a,c){let f=n==="object"?`param "${String(s)}"`:`"${n}.${String(s)}"`,u=t[s];if(!Object.hasOwn(t,s)&&(c?u!==void 0:a!=="function"))throw new TypeError(`${f} is invalid: expected own property`);if(c&&u===void 0)return;let l=typeof u;if(l!==a||u===null)throw new TypeError(`${f} is invalid: expected ${a}, got ${l}`)}let i=(s,a)=>Object.entries(s).forEach(([c,f])=>o(c,f,a));i(e,!1),i(r,!0)}var le=BigInt(0),X=BigInt(1),Rt=BigInt(2),Qu=BigInt(3),Is=BigInt(4),Ju=BigInt(5),xp=BigInt(7),ef=BigInt(8),Ep=BigInt(9),Sp=BigInt(15),tf=BigInt(16),vp=BigInt("0x10000000000000000");function re(t,e){if(e<=le)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=le?r:e+r}function rf(t,e,r){if(r<=X)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<le)throw new Error("invalid exponent, negatives unsupported");if(e===le)return X;if(e===X)return t;let n=t%r;if(n<le&&(n+=r),e<vp){let a=X;for(;e>le;)e&X&&(a=a*n%r),n=n*n%r,e>>=X;return a}let o=[];for(;e>le;)o.push(Number(e&Sp)),e>>=Is;let i=new Array(16);i[0]=X,i[1]=n;for(let a=2;a<16;a++)i[a]=i[a-1]*n%r;let s=i[o[o.length-1]];for(let a=o.length-2;a>=0;a--){s=s*s%r,s=s*s%r,s=s*s%r,s=s*s%r;let c=o[a];c!==0&&(s=s*i[c]%r)}return s}function ee(t,e,r){if(r<=X)throw new Error("pow2: expected modulus > 1, got "+r);if(e<le)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >le;)n*=n,n%=r;return n}function Xu(t,e){if(t===le)throw new Error("invert: expected non-zero number");if(e<=X)throw new Error("invert: expected modulus > 1, got "+e);let r=re(t,e),n=e,o=le,i=X;for(;r!==le;){let a=n/r,c=n-r*a,f=o-i*a;n=r,r=c,o=i,i=f}if(n!==X)throw new Error("invert: does not exist");return re(o,e)}function nf(t,e){if(e<=X)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=re(t,e);if(r===le)throw new Error("invertCt: expected non-zero number");let n=rf(r,e-Rt,e);if(re(r*n,e)!==X)throw new Error("invertCt: does not exist");return n}function Cs(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function _s(t,e){if((t&X)===le)throw new Error(e+": expected odd modulus, got "+t)}function of(t,e){let r=t,n=(r.ORDER+X)/Is,o=r.pow(e,n);return Cs(r,o,e),o}function Ap(t,e){let r=t,n=(r.ORDER-Ju)/ef,o=r.mul(e,Rt),i=r.pow(o,n),s=r.mul(e,i),a=r.mul(r.mul(s,Rt),i),c=r.mul(s,r.sub(a,r.ONE));return Cs(r,c,e),c}function Tp(t){let e=xr(t),r=sf(t),n=r(e,e.neg(e.ONE)),o=r(e,n),i=r(e,e.neg(n)),s=(t+xp)/tf;return((a,c)=>{let f=a,u=f.pow(c,s),l=f.mul(u,n),h=f.mul(u,o),m=f.mul(u,i),L=f.eql(f.sqr(l),c),v=f.eql(f.sqr(h),c);u=f.cmov(u,l,L),l=f.cmov(m,h,v);let b=f.eql(f.sqr(l),c),E=f.cmov(u,l,b);return Cs(f,E,c),E})}function sf(t){if(t<Qu)throw new Error("sqrt is not defined for small field");_s(t,"tonelliShanks");let e=t-X,r=0;for(;e%Rt===le;)e/=Rt,r++;let n=Rt,o=xr(t);for(;an(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return of;let i=o.pow(n,e),s=(e+X)/Rt;return function(c,f){let u=c;if(u.is0(f))return f;if(an(u,f)!==1)throw new Error("Cannot find square root");let l=r,h=u.mul(u.ONE,i),m=u.pow(f,e),L=u.pow(f,s);for(;!u.eql(m,u.ONE);){if(u.is0(m))throw new Error("Cannot find square root: probably non-prime P");let v=1,b=u.sqr(m);for(;!u.eql(b,u.ONE);)if(v++,b=u.sqr(b),v===l)throw new Error("Cannot find square root");let E=X<<BigInt(l-v-1),B=u.pow(h,E);l=v,h=u.sqr(B),m=u.mul(m,h),L=u.mul(L,B)}return L}}function Bp(t){return _s(t,"Fp.sqrt"),t%Is===Qu?of:t%ef===Ju?Ap:t%tf===Ep?Tp(t):sf(t)}var af=(t,e)=>(re(t,e)&X)===X,Ip=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function wr(t){if(It(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);Dt(t.BYTES,"BYTES"),Dt(t.BITS,"BITS");for(let e of Ip)qt(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Lo(t,e,r=!1){wr(t),Io(e,"nums"),Se(r,"passZero");let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),i=e.reduce((a,c,f)=>n.is0(c)?a:(o[f]=a,n.mul(a,c)),n.ONE),s=n.inv(i);return e.reduceRight((a,c,f)=>n.is0(c)?a:(o[f]=n.mul(a,o[f]),n.mul(a,c)),s),o}function an(t,e){wr(t);let r=t;_s(r.ORDER,"FpLegendre");let n=(r.ORDER-X)/Rt,o=r.pow(e,n),i=r.eql(o,r.ONE),s=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!i&&!s&&!a)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function Cp(t,e){if(e!==void 0&&As(e),t<=le)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=br(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Wu=new WeakMap,Ro=class{ORDER;BITS;BYTES;isLE;ZERO=le;ONE=X;_lengths;_mod;constructor(e,r={}){if(e<=X)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:i}=Cp(e,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=i,Object.freeze(this)}create(e){return re(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return le<=e&&e<this.ORDER}is0(e){return e===le}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&X)===X}neg(e){return re(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return re(e*e,this.ORDER)}add(e,r){return re(e+r,this.ORDER)}sub(e,r){return re(e-r,this.ORDER)}mul(e,r){return re(e*r,this.ORDER)}pow(e,r){return rf(e,r,this.ORDER)}div(e,r){return re(e*Xu(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return Xu(e,this.ORDER)}sqrt(e){let r=Wu.get(this);return r||Wu.set(this,r=Bp(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Ts(e,this.BYTES):_o(e,this.BYTES)}fromBytes(e,r=!1){G(e);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let f=new Uint8Array(o);f.set(e,i?0:f.length-e.length),e=f}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=i?Ht(e):et(e);if(a&&(c=re(c,s)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Lo(this,e,!0)}cmov(e,r,n){return Se(n,"condition"),n?r:e}};function xr(t,e={}){return Object.freeze(Ro.prototype),new Ro(t,e)}function cf(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=X)throw new Error("field order must be greater than 1");let e=br(t-X);return Math.ceil(e/8)}function No(t){let e=cf(t);return e+Math.ceil(e/2)}function Uo(t,e,r=!1){G(t);let n=t.length,o=cf(e),i=Math.max(No(e),16);if(n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Ht(t):et(t),a=re(s,e-X)+X;return r?Ts(a,o):_o(a,o)}var Ls=BigInt(0),cn=BigInt(1),_p=BigInt(4),Ds=16,uf=128,Dp=5,ff=2**31;function Lt(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);qt(e.fromAffine,"Point.fromAffine"),qt(e.fromBytes,"Point.fromBytes"),qt(e.fromHex,"Point.fromHex"),It(e.BASE,"Point.BASE"),It(e.ZERO,"Point.ZERO"),wr(e.Fp),wr(e.Fn)}function ko(t,e){Lt(t),df(e,t);let r=Lo(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function Rp(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function Lp(t,e){let r=t*(4*e+128);if(r>ff)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+ff/2**20+" MiB")}function Ns(t,e){if(t!==void 0){qt(t,"randomBytes");try{let r=t(e);if(!_t(r)||r.length!==e)return}catch{return}return t}}function df(t,e){Io(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function Np(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,o)=>{if(!(r===void 0?e.isValid(n):Ct(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var hf=new WeakMap;function Rs(t){return hf.get(t)||1}function Up(t,e){let r=t.double(),n=[t];for(let o=1;o<e;o++)n.push(n[o-1].add(r));return n}function kp(t,e){let r=2**e,n=r/2,o=BigInt(r-1),i=[];for(;t>Ls;){let s=0;t&cn&&(s=Number(t&o),s>=n&&(s-=r),t-=BigInt(s)),i.push(s),t>>=cn}return i}function Fp(t,e,r){let n=2**e,o=n/2,i=BigInt(n-1),s=BigInt(e),a=[];for(let c=0;c<r;c++){let f=Number(t&i);t>>=s,f>o&&(f-=n,t+=cn),a.push(f)}if(t!==Ls)throw new Error("invalid wnaf");return a}function Op(t,e,r){let n=0;for(let i of r)n=Math.max(n,i.length);let o=t;for(let i=n-1;i>=0;i--){i!==n-1&&(o=o.double());for(let s=0;s<r.length;s++){let a=r[s][i];if(a){let c=e[s][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var Er=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){Lt(e),this.randomBytes=Ns(r,Ds),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let o=Math.ceil(n/r)+1,i=2**(r-1),s=[],a=e;for(let c=0;c<o;c++){let f=a;for(let u=0;u<i;u++)s.push(f),f=f.add(a);a=s[s.length-1].double()}return{W:r,bits:n,windows:o,comp:s}}wnafCachedCT(e,r){let{W:n,windows:o,comp:i}=e,s=2**(n-1),a=Fp(r,n,o),c=this.ZERO,f=this.BASE;for(let u=0;u<o;u++){let l=a[u],h=u*s,m=Math.abs(l)-1,L=i[h];for(let b=1;b<s;b++)L=b===m?i[h+b]:L;let v=L.negate();l===0?f=f.add(i[h]):c=c.add(l<0?v:L)}return{p:c,f}}getWnafPrecomputes(e,r,n,o){let i=this.wnafPrecomputes.get(r),s=i?.find(a=>a.W===e&&a.bits===n);return s||(s=this.buildWnafTable(r,e,n),typeof o=="function"&&(s={...s,comp:o(s.comp)}),i||(i=[],this.wnafPrecomputes.set(r,i)),i.push(s)),s}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!Bs(r,cn,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,o){let i=Rs(e);return i===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(i,e,n,o),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+uf,i=this.randomBytes(Ds);if(!_t(i)||i.length!==Ds)throw new Error("randomBytes returned invalid byte array");i[0]=i[0]&63|128;let s=r+et(i)*this.Point.Fn.ORDER;return this.runCT(e,s,o,n)}fixedWindowCT(e,r,n){let o=Dp,i=1<<o,s=sn(o),a=new Array(i);a[0]=this.ZERO;for(let u=1;u<i;u++)a[u]=a[u-1].add(e);let c=Math.ceil(n/o),f=this.ZERO;for(let u=c-1;u>=0;u--){if(u!==c-1)for(let m=0;m<o;m++)f=f.double();let l=Number(r>>BigInt(u*o)&s),h=a[0];for(let m=1;m<i;m++)h=m===l?a[m]:h;f=f.add(h)}return{p:f,f}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===cn?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,o){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,o):this.mulCT(e,r,o)}mulUnsafe(e,r,n){if(this.assertPoint(e),!Ct(r))throw new Error("invalid scalar");let o=Rs(e);if(o===1||r>=this.Point.Fn.ORDER)return Fo(this.Point,[e],[r],!0);let i=this.getWnafPrecomputes(o,e,this.bits,n);return this.wnafCachedCT(i,r).p}setWindowSize(e,r){this.assertPoint(e),Rp(r,this.bits);let n=Math.ceil((this.bits+uf)/r)+1;Lp(n*2**(r-1),this.Point.Fp.BYTES),hf.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Rs(e)!==1}};function Fo(t,e,r,n=!1){if(Lt(t),df(e,t),Se(n,"allowOversized"),Np(r,t.Fn,n?t.Fn.ORDER**_p:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(s=>Up(s,4)),i=r.map(s=>kp(s,4));return Op(t.ZERO,o,i)}function lf(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return wr(e),e}else return xr(t,{isLE:r})}function Oo(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);ve(r);for(let c of["p","n","h"]){let f=e[c];if(!(Ct(f)&&f!==Ls))throw new Error(`CURVE.${c} must be positive bigint`)}let o=lf(e.p,r.Fp,n),i=lf(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:i}}function Po(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var Mo=BigInt(0),Ko=BigInt(1),Vo=BigInt(2),Pp=BigInt(4),pf=BigInt(8);function Mp(t,e,r,n){let o=t.sqr(r),i=t.sqr(n),s=t.add(t.mul(e.a,o),i),a=t.add(t.ONE,t.mul(e.d,t.mul(o,i)));return t.eql(s,a)}function mf(t,e={}){ve(e,{},{},"extraOpts");let r=e,n=Oo("edwards",t,r,r.FpFnLE),{Fp:o,Fn:i}=n,s=n.CURVE,{h:a}=s;if(an(o,s.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(an(o,s.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");ve(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?zt:r.randomBytes,f=Vo<<BigInt(o.BYTES*8)-Ko;function u(B){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(B)}let l=r.uvRatio===void 0?(B,y)=>{try{return{isValid:!0,value:o.sqrt(o.div(B,y))}}catch{return{isValid:!1,value:Mo}}}:r.uvRatio;if(!Mp(o,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");let h=o.eql(s.a,o.neg(o.ONE))?B=>o.neg(B):o.eql(s.a,o.ONE)?B=>B:B=>o.mul(s.a,B);function m(B,y,N=!1){let U=N?Ko:Mo;return gr("coordinate "+B,y,U,f),y}function L(B){if(!(B instanceof v))throw new Error("EdwardsPoint expected")}class v{static BASE=new v(s.Gx,s.Gy,o.ONE,o.mul(s.Gx,s.Gy));static ZERO=new v(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=i;X;Y;Z;T;constructor(y,N,U,V){this.X=m("x",y),this.Y=m("y",N),this.Z=m("z",U,!0),this.T=m("t",V),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){if(y instanceof v)throw new Error("extended point not allowed");let{x:N,y:U}=y||{};return m("x",N),m("y",U),new v(N,U,o.ONE,o.mul(N,U))}static fromBytes(y,N=!1){let U=o.BYTES,{a:V,d:$}=s;y=Do(G(y,U,"point")),Se(N,"zip215");let w=Do(y),S=y[U-1];w[U-1]=S&-129;let I=Ht(w),F=N?f:o.ORDER;gr("point.y",I,Mo,F);let x=o.sqr(I),q=o.sub(x,o.ONE),C=o.sub(o.mulN($,x),V),{isValid:A,value:p}=l(q,C);if(!A)throw new Error("bad point: invalid y coordinate");let T=u(p),_=(S&128)!==0;if(!N&&o.is0(p)&&_)throw new Error("bad point: x=0 and x_0=1");return _!==T&&(p=o.neg(p)),v.fromAffine({x:p,y:I})}static fromHex(y,N=!1){return v.fromBytes(yr(y),N)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=6,N=!0){return E.setWindowSize(this,y),N||this.multiply(Vo),this}assertValidity(){let y=this,{a:N,d:U}=s;if(y.is0())throw new Error("bad point: ZERO");let{X:V,Y:$,Z:w,T:S}=y,I=o.sqr(V),F=o.sqr($),x=o.sqr(w),q=o.sqr(x),C=o.mul(I,N),A=o.mul(o.add(C,F),x),p=o.add(q,o.mul(U,o.mul(I,F)));if(!o.eql(A,p))throw new Error("bad point: equation left != right (1)");let T=o.mul(V,$),_=o.mul(w,S);if(!o.eql(T,_))throw new Error("bad point: equation left != right (2)")}equals(y){L(y);let{X:N,Y:U,Z:V}=this,{X:$,Y:w,Z:S}=y,I=o.mul(N,S),F=o.mul($,V),x=o.mul(U,S),q=o.mul(w,V);return o.eql(I,F)&&o.eql(x,q)}is0(){return this.equals(v.ZERO)}negate(){return new v(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:y,Y:N,Z:U}=this,V=o.sqr(y),$=o.sqr(N),w=o.mul(o.sqr(U),Vo),S=h(V),I=o.addN(y,N),F=o.sub(o.subN(o.sqr(I),V),$),x=o.addN(S,$),q=o.subN(x,w),C=o.subN(S,$),A=o.mul(F,q),p=o.mul(x,C),T=o.mul(F,C),_=o.mul(q,x);return new v(A,p,_,T)}add(y){L(y);let{d:N}=s,{X:U,Y:V,Z:$,T:w}=this,{X:S,Y:I,Z:F,T:x}=y,q=o.mul(U,S),C=o.mul(V,I),A=o.mul(o.mulN(w,N),x),p=o.mul($,F),T=o.sub(o.subN(o.mulN(o.addN(U,V),o.addN(S,I)),q),C),_=o.subN(p,A),M=o.addN(p,A),D=o.sub(C,h(q)),g=o.mul(T,_),O=o.mul(M,D),P=o.mul(T,D),z=o.mul(_,M);return new v(g,O,z,P)}subtract(y){return L(y),this.add(y.negate())}multiply(y){if(!i.isValidNot0(y))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:N,f:U}=E.mulSecret(this,y,a,b);return b([N,U])[0]}multiplyUnsafe(y){if(!i.isValid(y))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return y===Mo?v.ZERO:this.is0()||y===Ko?this:E.mulUnsafe(this,y,b)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return E.mulUnsafe(this,s.n).is0()}toAffine(y){let N=this,U=y;if(U!=null&&typeof U!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof U);let{X:V,Y:$,Z:w}=N,S=N.is0();U==null&&(U=S?o.create(pf):o.inv(w));let I=o.mul(V,U),F=o.mul($,U),x=o.mul(w,U);if(S)return{x:o.ZERO,y:o.ONE};if(!o.eql(x,o.ONE))throw new Error("invZ was invalid");return{x:I,y:F}}clearCofactor(){return a===Ko?this:a===Vo?this.double():a===Pp?this.double().double():a===pf?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:y,y:N}=this.toAffine(),U=o.toBytes(N);return U[U.length-1]|=u(y)?128:0,U}toHex(){return nn(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let b=B=>ko(v,B),E=new Er(v,c);return E.bits>=6&&v.BASE.precompute(6),Object.freeze(v.prototype),Object.freeze(v),v}function yf(t,e,r={}){if(Lt(t),typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;ve(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:i}=o,{BASE:s,Fp:a,Fn:c}=t,f=n.outputLen,u=2*a.BYTES;if(f!==void 0&&(Dt(f,"hash.outputLen"),f!==u))throw new Error(`hash.outputLen must be ${u}, got ${f}`);let l=o.randomBytes===void 0?zt:o.randomBytes,h=o.toMontgomery,m=o.toMontgomerySecret,L=o.adjustScalarBytes===void 0?C=>C:o.adjustScalarBytes,v=o.domain===void 0?(C,A,p)=>{if(Se(p,"phflag"),A.length||p)throw new Error("Contexts/pre-hash are not supported");return C}:o.domain;function b(C){return c.create(Ht(C))}function E(C){let A=S.secretKey;G(C,S.secretKey,"secretKey");let p=G(n(C),2*A,"hashedSecretKey"),T=L(p.slice(0,A)),_=p.slice(A,2*A),M=b(T);return{head:T,prefix:_,scalar:M}}function B(C){let{head:A,prefix:p,scalar:T}=E(C),_=s.multiply(T),M=_.toBytes();return{head:A,prefix:p,scalar:T,point:_,pointBytes:M}}function y(C){return B(C).pointBytes}function N(C=Uint8Array.of(),...A){let p=Oe(...A);return b(n(v(p,G(C,void 0,"context"),!!i)))}function U(C,A,p={}){ve(p,{},{},"options"),C=G(C,void 0,"message"),i&&(C=i(C));let{prefix:T,scalar:_,pointBytes:M}=B(A),D=N(p.context,T,C),g=s.multiply(D).toBytes(),O=N(p.context,g,M,C),P=c.create(D+O*_);if(!c.isValid(P))throw new Error("sign failed: invalid s");let z=Oe(g,c.toBytes(P));return G(z,S.signature,"result")}let V={zip215:o.zip215};function $(C,A,p,T=V){ve(T);let{context:_}=T,M=T.zip215===void 0?!!V.zip215:T.zip215,D=S.signature;C=G(C,D,"signature"),A=G(A,void 0,"message"),p=G(p,S.publicKey,"publicKey"),M!==void 0&&Se(M,"zip215"),i&&(A=i(A));let g=D/2,O=C.subarray(0,g),P=Ht(C.subarray(g,D)),z,H,Z;try{z=t.fromBytes(p,M),H=t.fromBytes(O,M),Z=s.multiplyUnsafe(P)}catch{return!1}if(!M&&z.isSmallOrder())return!1;let Y=N(_,O,p,A);return H.add(z.multiplyUnsafe(Y)).subtract(Z).clearCofactor().is0()}let w=a.BYTES,S={secretKey:w,publicKey:w,signature:2*w,seed:w};function I(C){return C=C===void 0?l(S.seed):C,G(C,S.seed,"seed")}function F(C){return _t(C)&&C.length===S.secretKey}function x(C,A){try{return!!t.fromBytes(C,A===void 0?V.zip215:A)}catch{return!1}}let q={getExtendedPublicKey:B,randomSecretKey:I,isValidSecretKey:F,isValidPublicKey:x,toMontgomery(C){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(t.fromBytes(C))},toMontgomerySecret(C){if(m===void 0)throw new Error("Montgomery conversion is not supported for this curve");return m(C)}};return Object.freeze(S),Object.freeze(q),Object.freeze({keygen:Po(I,y),getPublicKey:y,sign:U,verify:$,utils:q,Point:t,lengths:S})}var Us=BigInt(1),gf=BigInt(2);var Kp=BigInt(5),Vp=BigInt(8),ks=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),$p={p:ks,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Vp,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function qp(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=ks,a=t*t%i*t%i,c=ee(a,gf,i)*a%i,f=ee(c,Us,i)*t%i,u=ee(f,Kp,i)*f%i,l=ee(u,e,i)*u%i,h=ee(l,r,i)*l%i,m=ee(h,n,i)*h%i,L=ee(m,o,i)*m%i,v=ee(L,o,i)*m%i,b=ee(v,e,i)*u%i;return{pow_p_5_8:ee(b,gf,i)*t%i,b2:a}}function xf(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var bf=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function zp(t,e){let r=ks,n=re(e*e*e,r),o=re(n*n*e,r),i=qp(t*o).pow_p_5_8,s=re(t*n*i,r),a=re(e*s*s,r),c=s,f=re(s*bf,r),u=a===t,l=a===re(-t,r),h=a===re(-t*bf,r);return u&&(s=c),(l||h)&&(s=f),af(s,r)&&(s=re(-s,r)),{isValid:u||l,value:s}}var Fs=mf($p,{uvRatio:zp}),wf=Fs.Fp;function Hp(t){let{y:e}=t;return wf.toBytes(wf.div(Us+e,Us-e))}function jp(t){let e=Fs.Fp.BYTES;return Fe(t,e),xf(vs(t.subarray(0,e))).subarray(0,e)}function Yp(t){return yf(Fs,vs,Object.assign({adjustScalarBytes:xf,toMontgomery:Hp,toMontgomerySecret:jp,zip215:!0},t))}var Ef=Yp({});var un=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},$o=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var qo={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new $o("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var zo=32;var Os,Zp=(async()=>{try{return await qo.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Gp(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await qo.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await qo.get().subtle.verify({name:"Ed25519"},n,xe(e),xe(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Xp(t,e,r){return Ef.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function Sf(t,e,r){return Os==null&&(Os=await Zp),Os?Gp(t,e,r):Xp(t,e,r)}function Ho(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var jo=class{type="Ed25519";raw;constructor(e){this.raw=Ps(e,zo)}toMultihash(){return Ke.digest(pr(this))}toCID(){return te.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:de(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=Sf(this.raw,r,e);return Ho(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}};function Af(t){return t=Ps(t,zo),new jo(t)}function Ps(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new nt(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var be;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(be||(be={}));var Ms;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Ms||(Ms={}));(function(t){t.codec=()=>Fr(Ms)})(be||(be={}));var fn;(function(t){let e;t.codec=()=>(e==null&&(e=Ze((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),be.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=be.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:be.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(u&7);break}}}})),e);function r(i){return je(i,t.codec())}t.encode=r;function n(i,s){return He(i,t.codec(),s)}t.decode=n;function o(i,s){return Ye(i,t.codec(),s)}t.stream=o})(fn||(fn={}));var Ks;(function(t){let e;t.codec=()=>(e==null&&(e=Ze((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),be.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=be.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:be.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(u&7);break}}}})),e);function r(i){return je(i,t.codec())}t.encode=r;function n(i,s){return He(i,t.codec(),s)}t.decode=n;function o(i,s){return Ye(i,t.codec(),s)}t.stream=o})(Ks||(Ks={}));var Yo=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(Eo(e),Fe(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=e.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),$t(o)}update(e){return mr(this),this.iHash.update(e),this}digestInto(e){mr(this),So(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a,canXOF:c}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Tf=(()=>{let t=((e,r,n)=>new Yo(e,r).update(n).digest());return t.create=(e,r)=>new Yo(e,r),t})();var Jp=BigInt(0),Vs=class extends Error{constructor(e=""){super(e)}},at={Err:Vs,_tlv:{encode:(t,e)=>{let{Err:r}=at;if(Dt(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(Yu(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=on(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?on(o.length/2|128):"";return on(t)+i+o+e},decode(t,e){let{Err:r}=at;e=G(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=e.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=e.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(t){let{Err:e}=at;if(Co(t),t<Jp)throw new e("integer: negative integers are not allowed");let r=on(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=at;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return et(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=at,o=G(t,void 0,"signature"),{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:f,l:u}=n.decode(2,c);if(u.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(t){let{_tlv:e,_int:r}=at;ve(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),i=n+o;return e.encode(48,i)}},$s=(Object.freeze(at._tlv),Object.freeze(at._int),Object.freeze(at));var Bf=(t,e)=>(t+(t>=0?e:-e)/If)/e;function em(t,e,r){gr("scalar",t,ct,r);let[[n,o],[i,s]]=e,a=Bf(s*t,r),c=Bf(-o*t,r),f=t-a*n-c*i,u=-a*o-c*s,l=f<ct,h=u<ct;l&&(f=-f),h&&(u=-u);let m=sn(Math.ceil(br(r)/2))+jt;if(f<ct||f>=m||u<ct||u>=m)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:f,k2neg:h,k2:u}}function Hs(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function qs(t,e){ve(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Se(r.lowS,"lowS"),Se(r.prehash,"prehash"),r.format!==void 0&&Hs(r.format),r}var ct=BigInt(0),jt=BigInt(1),If=BigInt(2),zs=BigInt(3),tm=BigInt(4);function Cf(t,e={}){let r=Oo("weierstrass",t,e),n=r.Fp,o=r.Fn,i=r.CURVE,{h:s,n:a}=i;ve(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:f}=e,u=e.randomBytes===void 0?zt:e.randomBytes;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 l=Df(n,o);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function m(A,p,T){if(f&&p.is0())return Uint8Array.of(0);let{x:_,y:M}=p.toAffine(),D=n.toBytes(_);if(Se(T,"isCompressed"),T){h();let g=!n.isOdd(M);return Oe(_f(g),D)}else return Oe(Uint8Array.of(4),D,n.toBytes(M))}function L(A){G(A,void 0,"Point");let{publicKey:p,publicKeyUncompressed:T}=l,_=A.length,M=A[0],D=A.subarray(1);if(f&&_===1&&M===0)return{x:n.ZERO,y:n.ZERO};if(_===p&&(M===2||M===3)){let g=n.fromBytes(D);if(!n.isValid(g))throw new Error("bad point: is not on curve, wrong x");let O=y(g),P;try{P=n.sqrt(O)}catch(Z){let Y=Z instanceof Error?": "+Z.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}h();let z=n.isOdd(P);return(M&1)===1!==z&&(P=n.neg(P)),{x:g,y:P}}else if(_===T&&M===4){let g=n.BYTES,O=n.fromBytes(D.subarray(0,g)),P=n.fromBytes(D.subarray(g,g*2));if(!N(O,P))throw new Error("bad point: is not on curve");return{x:O,y:P}}else throw new Error(`bad point: got length ${_}, expected compressed=${p} or uncompressed=${T}`)}let v=e.toBytes===void 0?m:e.toBytes,b=e.fromBytes===void 0?L:e.fromBytes,E=n.mul(i.b,zs),B=n.is0(i.a)?A=>n.ZERO:A=>n.mul(i.a,A);function y(A){let p=n.sqr(A),T=n.mul(p,A);return n.add(n.add(T,n.mul(A,i.a)),i.b)}function N(A,p){let T=n.sqr(p),_=y(A);return n.eql(T,_)}if(!N(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let U=n.mul(n.pow(i.a,zs),tm),V=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(U,V)))throw new Error("bad curve params: a or b");function $(A,p,T=!1){if(!n.isValid(p)||T&&n.is0(p))throw new Error(`bad point coordinate ${A}`);return p}function w(A){if(!(A instanceof x))throw new Error("Weierstrass Point expected")}function S(A){if(!c||!c.basises)throw new Error("no endo");return em(A,c.basises,o.ORDER)}function I(A,p,T,_){if(!o.isValid(_))throw new RangeError("invalid scalar: out of range");if(c){let{k1neg:M,k1:D,k2neg:g,k2:O}=S(_),P=new x(n.mul(T.X,c.beta),T.Y,T.Z);A.push(M?T.negate():T,g?P.negate():P),p.push(D,O)}else A.push(T),p.push(_)}let F=new WeakSet;class x{static BASE=new x(i.Gx,i.Gy,n.ONE);static ZERO=new x(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(p,T,_){this.X=$("x",p),this.Y=$("y",T,!0),this.Z=$("z",_),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){let{x:T,y:_}=p||{};if(!p||!n.isValid(T)||!n.isValid(_))throw new Error("invalid affine point");if(p instanceof x)throw new Error("projective point not allowed");return n.is0(T)&&n.is0(_)?x.ZERO:new x(T,_,n.ONE)}static fromBytes(p){let T=x.fromAffine(b(G(p,void 0,"point")));return T.assertValidity(),T}static fromHex(p){return x.fromBytes(yr(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=6,T=!0){return C.setWindowSize(this,p),T||this.multiply(zs),this}assertValidity(){let p=this;if(p.is0()){if(e.allowInfinityPoint&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}if(F.has(p))return;let{x:T,y:_}=p.toAffine();if(!n.isValid(T)||!n.isValid(_))throw new Error("bad point: x or y not field elements");if(!N(T,_))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");F.add(p)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){w(p);let{X:T,Y:_,Z:M}=this,{X:D,Y:g,Z:O}=p,P=n.eql(n.mul(T,O),n.mul(D,M)),z=n.eql(n.mul(_,O),n.mul(g,M));return P&&z}negate(){return new x(this.X,n.neg(this.Y),this.Z)}double(){let{X:p,Y:T,Z:_}=this,M=n.ZERO,D=n.ZERO,g=n.ZERO,O=n.mul(p,p),P=n.mul(T,T),z=n.mul(_,_),H=n.mul(p,T);return H=n.add(H,H),g=n.mul(p,_),g=n.add(g,g),M=B(g),D=n.mul(E,z),D=n.add(M,D),M=n.sub(P,D),D=n.add(P,D),D=n.mul(M,D),M=n.mul(H,M),g=n.mul(E,g),z=B(z),H=n.sub(O,z),H=B(H),H=n.add(H,g),g=n.add(O,O),O=n.add(g,O),O=n.add(O,z),O=n.mul(O,H),D=n.add(D,O),z=n.mul(T,_),z=n.add(z,z),O=n.mul(z,H),M=n.sub(M,O),g=n.mul(z,P),g=n.add(g,g),g=n.add(g,g),new x(M,D,g)}add(p){w(p);let{X:T,Y:_,Z:M}=this,{X:D,Y:g,Z:O}=p,P=n.ZERO,z=n.ZERO,H=n.ZERO,Z=n.mul(T,D),Y=n.mul(_,g),ne=n.mul(M,O),ye=n.add(T,_),oe=n.add(D,g);ye=n.mul(ye,oe),oe=n.add(Z,Y),ye=n.sub(ye,oe),oe=n.add(T,M);let pe=n.add(D,O);return oe=n.mul(oe,pe),pe=n.add(Z,ne),oe=n.sub(oe,pe),pe=n.add(_,M),P=n.add(g,O),pe=n.mul(pe,P),P=n.add(Y,ne),pe=n.sub(pe,P),H=B(oe),P=n.mul(E,ne),H=n.add(P,H),P=n.sub(Y,H),H=n.add(Y,H),z=n.mul(P,H),Y=n.add(Z,Z),Y=n.add(Y,Z),ne=B(ne),oe=n.mul(E,oe),Y=n.add(Y,ne),ne=n.sub(Z,ne),ne=B(ne),oe=n.add(oe,ne),Z=n.mul(Y,oe),z=n.add(z,Z),Z=n.mul(pe,oe),P=n.mul(ye,P),P=n.sub(P,Z),Z=n.mul(ye,Y),H=n.mul(pe,H),H=n.add(H,Z),new x(P,z,H)}subtract(p){return w(p),this.add(p.negate())}is0(){return this.equals(x.ZERO)}multiply(p){if(!o.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let{p:T,f:_}=C.mulSecret(this,p,s,q);return q([T,_])[0]}multiplyUnsafe(p){let T=this,_=p;if(!o.isValid(_))throw new RangeError("invalid scalar: out of range");if(_===ct||T.is0())return x.ZERO;if(_===jt)return T;if(C.hasWindowSize(this))return C.mulUnsafe(T,_,q);let M=[],D=[];return I(M,D,T,_),Fo(x,M,D)}mulAddUnsafe(p,T,_){w(T);let M=[],D=[];return I(M,D,this,p),I(M,D,T,_),Fo(x,M,D)}toAffine(p){let T=this,_=p;if(_!=null&&!n.isValid(_))throw new RangeError('"invertedZ" expected valid field element');let{X:M,Y:D,Z:g}=T;if(n.eql(g,n.ONE))return{x:M,y:D};let O=T.is0();_==null&&(_=O?n.ONE:n.inv(g));let P=n.mul(M,_),z=n.mul(D,_),H=n.mul(g,_);if(O)return{x:n.ZERO,y:n.ZERO};if(!n.eql(H,n.ONE))throw new Error("invZ was invalid");return{x:P,y:z}}isTorsionFree(){let{isTorsionFree:p}=e;return s===jt?!0:p?p(x,this):C.mulUnsafe(this,a).is0()}clearCofactor(){let{clearCofactor:p}=e;return s===jt?this:p?p(x,this):this.multiplyUnsafe(s)}isSmallOrder(){return s===jt?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return Se(p,"isCompressed"),this.assertValidity(),v(x,this,p)}toHex(p=!0){return nn(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let q=A=>ko(x,A),C=new Er(x,u);return C.bits>=6&&x.BASE.precompute(6),Object.freeze(x.prototype),Object.freeze(x),x}function _f(t){return Uint8Array.of(t?2:3)}function Df(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function rm(t,e={}){Lt(t);let{Fn:r}=t,n=e.randomBytes===void 0?zt:e.randomBytes,o=Object.assign(Df(t.Fp,r),{seed:Math.max(No(r.ORDER),16)});function i(m){try{let L=r.fromBytes(m);return r.isValidNot0(L)}catch{return!1}}function s(m,L){let{publicKey:v,publicKeyUncompressed:b}=o;try{let E=m.length;return L===!0&&E!==v||L===!1&&E!==b?!1:!!t.fromBytes(m)}catch{return!1}}function a(m){return m=m===void 0?n(o.seed):m,Uo(G(m,o.seed,"seed"),r.ORDER)}function c(m,L=!0){return t.BASE.multiply(r.fromBytes(m)).toBytes(L)}function f(m){let{secretKey:L,publicKey:v,publicKeyUncompressed:b}=o,E=r._lengths;if(!_t(m))return;let B=G(m,void 0,"key").length,y=B===v||B===b,N=B===L||!!E?.includes(B);if(!(y&&N))return y}function u(m,L,v=!0){if(f(m)===!0)throw new Error("first arg must be private key");if(f(L)===!1)throw new Error("second arg must be public key");let b=r.fromBytes(m);return t.fromBytes(L).multiply(b).toBytes(v)}let l={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},h=Po(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:h,Point:t,utils:l,lengths:o})}function Rf(t,e,r={}){Lt(t);let n=e;Eo(n),ve(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),i=o.randomBytes===void 0?zt:o.randomBytes,s=o.hmac===void 0?(D,g)=>Tf(n,D,g):o.hmac,{Fp:a,Fn:c}=t,{ORDER:f,BITS:u}=c,l=No(f),h=Ns(i,l),{keygen:m,getPublicKey:L,getSharedSecret:v,utils:b,lengths:E}=rm(t,o),B={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},y=f*If+jt<a.ORDER;function N(D){let g=f>>jt;return D>g}function U(D,g){if(!c.isValidNot0(g))throw new Error(`invalid signature ${D}: out of range 1..Point.Fn.ORDER`);return g}function V(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function $(D,g,O){return V(),(D===O?0:2)|Number(a.isOdd(g))}function w(){if(y)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function S(D,g){Hs(g);let O=E.signature,P=g==="compact"?O:g==="recovered"?O+1:void 0;return G(D,P)}class I{r;s;recovery;constructor(g,O,P){if(this.r=U("r",g),this.s=U("s",O),P!=null){if(w(),![0,1,2,3].includes(P))throw new Error("invalid recovery id");this.recovery=P}Object.freeze(this)}static fromBytes(g,O=B.format){S(g,O);let P;if(O==="der"){let{r:Y,s:ne}=$s.toSig(G(g));return new I(Y,ne)}O==="recovered"&&(P=g[0],O="compact",g=g.subarray(1));let z=E.signature/2,H=g.subarray(0,z),Z=g.subarray(z,z*2);return new I(c.fromBytes(H),c.fromBytes(Z),P)}static fromHex(g,O){return this.fromBytes(yr(g),O)}assertRecovery(){let{recovery:g}=this;if(g==null)throw new Error("invalid recovery id: must be present");return g}addRecoveryBit(g){return new I(this.r,this.s,g)}recoverPublicKey(g){let{r:O,s:P}=this,z=this.assertRecovery(),H=z===2||z===3?O+f:O;if(!a.isValid(H))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let Z=a.toBytes(H),Y=t.fromBytes(Oe(_f((z&1)===0),Z)),ne=c.inv(H),ye=x(G(g,void 0,"msgHash")),oe=c.create(-ye*ne),pe=c.create(P*ne),qe=t.BASE.mulAddUnsafe(oe,Y,pe);if(qe.is0())throw new Error("invalid recovery: point at infinify");return qe.assertValidity(),qe}hasHighS(){return N(this.s)}toBytes(g=B.format){if(Hs(g),g==="der")return yr($s.hexFromSig(this));let{r:O,s:P}=this,z=c.toBytes(O),H=c.toBytes(P);return g==="recovered"?(w(),Oe(Uint8Array.of(this.assertRecovery()),z,H)):Oe(z,H)}toHex(g){return nn(this.toBytes(g))}}Object.freeze(I.prototype),Object.freeze(I);let F=o.bits2int===void 0?function(g){if(g.length>8192)throw new Error("input is too large");let O=et(g),P=g.length*8-u;return P>0?O>>BigInt(P):O}:o.bits2int,x=o.bits2int_modN===void 0?function(g){return c.create(F(g))}:o.bits2int_modN,q=sn(u);function C(D){return gr("num < 2^"+u,D,ct,q),c.toBytes(D)}function A(D,g){return G(D,void 0,"message"),g?G(n(D),void 0,"prehashed message"):D}function p(D,g,O){let{lowS:P,prehash:z,extraEntropy:H}=qs(O,B);D=A(D,z);let Z=x(D),Y=c.fromBytes(g);if(!c.isValidNot0(Y))throw new Error("invalid private key");let ne=[C(Y),C(Z)];if(H!=null&&H!==!1){let qe=H===!0?i(E.secretKey):H;ne.push(G(qe,void 0,"extraEntropy"))}let ye=Oe(...ne),oe=Z;function pe(qe){let Yt=F(qe);if(!c.isValidNot0(Yt))return;let Tr=t.BASE.multiply(Yt).toAffine(),ut=c.create(Tr.x);if(ut===ct)return;let ze;if(h!==void 0){let Br=et(Uo(h(l),f)),qf=c.inv(c.mul(Br,Yt)),zf=c.mul(Br,oe),Hf=c.mul(Br,Y);ze=c.create(qf*c.create(zf+Hf*ut))}else{let Br=nf(Yt,f);ze=c.create(Br*c.create(oe+ut*Y))}if(ze===ct)return;let ni=$(Tr.x,Tr.y,ut),Js=ze;return P&&N(ze)&&(Js=c.neg(ze),ni^=1),new I(ut,Js,y?void 0:ni)}return{seed:ye,k2sig:pe}}function T(D,g,O={}){let{seed:P,k2sig:z}=p(D,g,O);return Gu(n.outputLen,c.BYTES,s)(P,z).toBytes(O.format)}function _(D,g,O,P={}){let{lowS:z,prehash:H,format:Z}=qs(P,B);if(O=G(O,void 0,"publicKey"),g=A(g,H),!_t(D)){let Y=D instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+Y)}S(D,Z);try{let Y=I.fromBytes(D,Z),ne=t.fromBytes(O);if(z&&Y.hasHighS())return!1;let{r:ye,s:oe}=Y,pe=x(g),qe=c.inv(oe),Yt=c.create(pe*qe),Tr=c.create(ye*qe),ut=t.BASE.mulAddUnsafe(Yt,ne,Tr);if(ut.is0())return!1;let ze=ut.toAffine();return!(c.create(ze.x)!==ye||Z==="recovered"&&Y.recovery!==$(ze.x,ze.y,ye))}catch{return!1}}function M(D,g,O={}){let{prehash:P}=qs(O,B);return g=A(g,P),I.fromBytes(D,"recovered").recoverPublicKey(g).toBytes()}return Object.freeze({keygen:m,getPublicKey:L,getSharedSecret:v,utils:b,lengths:E,Point:t,sign:T,verify:_,recoverPublicKey:M,Signature:I,hash:n})}var Ys={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},nm={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Lf=BigInt(2);function om(t){let e=Ys.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=t*t*t%e,u=f*f*t%e,l=ee(u,r,e)*u%e,h=ee(l,r,e)*u%e,m=ee(h,Lf,e)*f%e,L=ee(m,o,e)*m%e,v=ee(L,i,e)*L%e,b=ee(v,a,e)*v%e,E=ee(b,c,e)*b%e,B=ee(E,a,e)*v%e,y=ee(B,r,e)*u%e,N=ee(y,s,e)*L%e,U=ee(N,n,e)*f%e,V=ee(U,Lf,e);if(!js.eql(js.sqr(V),t))throw new Error("Cannot find square root");return V}var js=xr(Ys.p,{sqrt:om}),im=Cf(Ys,{Fp:js,endo:nm}),Sr=Rf(im,Hu);function Nf(t,e,r,n){let o=Nr.digest(r instanceof Uint8Array?r:r.subarray());if(Ho(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Sr.verify(e,i,t,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new un(String(i))});try{return n?.signal?.throwIfAborted(),Sr.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(i){throw new un(String(i))}}var Zo=class{type="secp256k1";raw;_key;constructor(e){this._key=kf(e),this.raw=Uf(this._key)}toMultihash(){return Ke.digest(pr(this))}toCID(){return te.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:de(this.raw,e.raw)}verify(e,r,n){return Nf(this._key,r,e,n)}};function Ff(t){return new Zo(t)}function Uf(t){return Sr.Point.fromBytes(t).toBytes()}function kf(t){try{return Sr.Point.fromBytes(t),t}catch(e){throw new Wn(String(e))}}function Of(t){let{Type:e,Data:r}=fn.decode(t.digest),n=r??new Uint8Array;switch(e){case be.Ed25519:return Af(n);case be.secp256k1:return Ff(n);case be.ECDSA:return Au(n);default:throw new Hr}}function pr(t){return fn.encode({Type:be[t.type],Data:t.raw})}var Pf=Symbol.for("nodejs.util.inspect.custom"),sm=114,ln=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Ji]=!0;toString(){return this.string==null&&(this.string=J.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return te.createV1(sm,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return de(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return de(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Pf](){return`PeerId(${this.toString()})`}},Go=class extends ln{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Xo=class extends ln{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Wo=class extends ln{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},am=2336,Qo=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Ke.digest(se(this.url))}[Pf](){return`PeerId(${this.url})`}[Ji]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return te.createV1(am,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=W(e)),e.toString()===this.toString())}};function Mf(t){if(um(t))return new Go({multihash:t});if(cm(t))try{let e=Of(t);if(e.type==="Ed25519")return new Xo({multihash:t,publicKey:e});if(e.type==="secp256k1")return new Wo({multihash:t,publicKey:e})}catch{let r=W(t.digest);return new Qo(new URL(r))}throw new Qn("Supplied PeerID Multihash is invalid")}function cm(t){return t.code===Ke.code}function um(t){return t.code===Nr.code}function Zs(t,e){let r={[Symbol.iterator]:()=>r,next:()=>{let n=t.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:e(o)}}};return r}function Jo(t){let e=dt(J.decode(`z${t}`));return Mf(e)}var dn=class t{set;constructor(e){if(this.set=new Set,e!=null)for(let r of e)this.set.add(r.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(e){this.set.add(e.toString())}clear(){this.set.clear()}delete(e){this.set.delete(e.toString())}entries(){return Zs(this.set.entries(),e=>{let r=Jo(e[0]);return[r,r]})}forEach(e){this.set.forEach(r=>{let n=Jo(r);e(n,n,this)})}has(e){return this.set.has(e.toString())}values(){return Zs(this.set.values(),e=>Jo(e))}intersection(e){let r=new t;for(let n of e)this.has(n)&&r.add(n);return r}difference(e){let r=new t;for(let n of this)e.has(n)||r.add(n);return r}union(e){let r=new t;for(let n of e)r.add(n);for(let n of this)r.add(n);return r}};var Kf;(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"})(Kf||(Kf={}));var hn;(function(t){let e;t.codec=()=>(e==null&&(e=Ze((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}}}})),e);function r(i){return je(i,t.codec())}t.encode=r;function n(i,s){return He(i,t.codec(),s)}t.decode=n;function o(i,s){return Ye(i,t.codec(),s)}t.stream=o})(hn||(hn={}));function vr(t,e){return{async put(r,n,o={}){try{let i=jr(r);try{let c=await t.get(i),f=vt.deserialize(c);if(de(f.value,n))return}catch(c){if(c.name!=="NotFoundError")throw c}let s=new vt(r,n,new Date);o.onProgress?.(new fe("ipns:routing:datastore:put"));let a=t.batch();a.put(i,s.serialize()),o.metadata!=null&&a.put(no(r),hn.encode(o.metadata)),await a.commit(o)}catch(i){throw o.onProgress?.(new fe("ipns:routing:datastore:error",i)),i}},async get(r,n={}){try{let o=jr(r);n.onProgress?.(new fe("ipns:routing:datastore:get"));let i=await t.get(o,n),s=vt.deserialize(i);return{record:xe(s.value),created:s.timeReceived}}catch(o){throw n.onProgress?.(new fe("ipns:routing:datastore:error",o)),o}},async has(r,n={}){let o=jr(r);return t.has(o,n)},async delete(r,n){let o=jr(r),i=t.batch();i.delete(o),i.delete(no(r)),await i.commit(n)},async*list(r={}){try{r.onProgress?.(new fe("ipns:routing:datastore:list"));for await(let{key:n,value:o}of t.query({prefix:ro},r))try{let i=vt.deserialize(o),a=n.toString().substring(ro.length),c=se(a,"base32"),f=no(c),u;try{let l=await t.get(f,r);u=hn.decode(l)}catch(l){e.error("Error deserializing metadata for %s - %e",a,l)}yield{routingKey:c,metadata:u,record:i.value,created:i.timeReceived}}catch(i){e.error("Error deserializing record - %e",i)}}catch(n){throw r.onProgress?.(new fe("ipns:routing:datastore:error",n)),n}}}}var Gs=class{routing;constructor(e){this.routing=e}async put(e,r,n={}){try{await this.routing.put(e,r,n)}catch(o){throw n.onProgress?.(new fe("ipns:routing:helia:error",o)),o}}async get(e,r={}){try{return await this.routing.get(e,r)}catch(n){throw r.onProgress?.(new fe("ipns:routing:helia:error",n)),n}}toString(){return"HeliaRouting()"}};function Ar(t){return new Gs(t)}var Xs=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 ei(t){return new Xs(t)}var ti=class{routers;publisher;republisher;resolver;localStore;components;started;constructor(e,r={}){this.localStore=vr(e.datastore,e.logger.forComponent("helia:ipns:local-store")),this.components=e,this.started=!1,this.routers=[ei(this.localStore),Ar(e.routing),...r.routers??[]],this.publisher=new uo(e,{...r,routers:this.routers,localStore:this.localStore}),this.republisher=new go(e,{...r,routers:this.routers,localStore:this.localStore}),this.resolver=new cr(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(fm(n))for(let o of Object.values(n.services))lm(o)&&(o.selectors.ipns=async(i,s)=>{let a=s.map(c=>Q.decode(c));return St(i,a)},o.validators.ipns=async(i,s)=>{await Qe(i,s,this.components.keychain)})}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,so(r),n)}async*resolve(e,r={}){let{digest:n}=Yr(e);yield*this.resolver.resolve(n,r)}async unpublish(e,r){return this.publisher.unpublish(e,r)}};function fm(t){return t?.services!=null}function lm(t){return t?.validators!=null&&t?.selectors!=null}var ae=Zr("helia:ipns:routing:pubsub"),Qs=class{subscriptions;localStore;libp2p;fetchConcurrency;fetchTimeout;fetchDelay;fetchQueue;fetchPeers;shutdownController;fetchTopologyId;keychain;constructor(e,r={}){if(this.subscriptions=new Set,this.shutdownController=new AbortController,this.shutdownController.signal,this.fetchPeers=new dn,this.localStore=vr(e.datastore,e.logger.forComponent("helia:ipns:local-store")),this.libp2p=e.libp2p,this.fetchConcurrency=r.fetchConcurrency??8,this.fetchDelay=r.fetchDelay??0,this.keychain=e.keychain,this.fetchTimeout=r.fetchTimeout??2500,this.fetchQueue=new dr({concurrency:this.fetchConcurrency,metrics:e.metrics,metricName:"helia_ipns_pubsub_fetch_queue"}),this.libp2p.services.pubsub.addEventListener("message",n=>{let o=n.detail;this.subscriptions.has(o.topic)&&this.#e(o,{signal:this.shutdownController.signal}).catch(i=>{ae.error("Error processing message - %e",i)})}),this.libp2p.services.fetch!=null)try{this.libp2p.services.pubsub.addEventListener("subscription-change",n=>{let{peerId:o,subscriptions:i}=n.detail;if(this.fetchPeers.has(o))for(let s of i){if(!this.subscriptions.has(s.topic)||s.subscribe===!1)continue;ae("peer %s joined topic %s",o,s.topic);let a=Vf(s.topic);this.#t(s.topic,a,o,{signal:this.shutdownController.signal}).catch(c=>{ae.error("failed to fetch IPNS record for %m from peer %s - %e",a,o,c)})}}),this.libp2p.services.fetch.registerLookupFunction(to,async n=>{try{let{record:o}=await this.localStore.get(n,{signal:this.shutdownController.signal});return o}catch(o){if(o.name!=="NotFoundError")throw o}}),ae("registered lookup function for IPNS with libp2p/fetch service")}catch(n){ae("unable to register lookup function for IPNS with libp2p/fetch service - %e",n)}else ae("no libp2p/fetch service found. Skipping registration of lookup function for IPNS.")}async#e(e,r){if(ae("message received for topic",e.topic),e.type!=="signed"){ae.error("unsigned message received, this module can only work with signed messages");return}if(e.from.equals(this.libp2p.peerId)){ae("not storing record from self");return}await this.#r(e.topic,Vf(e.topic),e.data,!1,r)}async#t(e,r,n,o){let i=await this.fetchQueue.add(async({signal:s})=>{ae("fetching ipns record for %m from peer %s",r,n);let a=Xr([s,AbortSignal.timeout(this.fetchTimeout)]);try{return await this.libp2p.services.fetch?.fetch(n,r,{signal:a})}finally{a.clear()}},o);if(i==null)throw new zr(`Peer ${n} did not have record for routing key ${W(r,"base64")}`);return ae("fetched ipns record for %m from peer %s",r,n),this.#r(e,r,i,!0,o)}async#r(e,r,n,o,i){let s=await Qe(r,n,this.keychain,i);if(this.shutdownController.signal.throwIfAborted(),await this.localStore.has(r)){let{record:a}=await this.localStore.get(r,i),c=await Qe(r,a,this.keychain,i);if(de(a,n))return ae.trace("found identical record for %m",r),a;if(St(r,[c,s])===0)return ae.trace("found old record for %m",r),a}if(ae("found new record for %m",r),await this.localStore.put(r,n,i),o){ae("publish value for topic %s",e);try{let a=await this.libp2p.services.pubsub.publish(e,n);ae("published record on topic %s to %d recipients",e,a.recipients)}catch(a){ae.error("could not publish record on topic %s - %e",a)}}return xe(n)}async put(e,r,n={}){try{let o=Ws(e);ae("publish value for topic %s",o);let i=await this.libp2p.services.pubsub.publish(o,r);n?.signal?.throwIfAborted(),ae("published record on topic %s to %d recipients",o,i.recipients),n.onProgress?.(new fe("ipns:pubsub:publish",{topic:o,result:i}))}catch(o){throw n.onProgress?.(new fe("ipns:pubsub:error",o)),o}}async get(e,r={}){let n=Ws(e);try{this.libp2p.services.pubsub.getTopics().includes(n)||(ae("add subscription for topic",n),this.libp2p.services.pubsub.subscribe(n),this.subscriptions.add(n),r.onProgress?.(new fe("ipns:pubsub:subscribe",{topic:n})))}catch(s){throw r.onProgress?.(new fe("ipns:pubsub:error",s)),s}await po(yu(this.fetchDelay),this.shutdownController.signal);let o=new AbortController,i=[];for(let s of this.libp2p.services.pubsub.getSubscribers(n)){let a=Xr([r?.signal,o.signal]);i.push(this.#t(n,e,s,{...r,signal:a}).finally(()=>{a.clear()}))}if(i.length>0){let s=await Promise.any(i);if(o.abort(),s!=null)return s}throw new zr("Pubsub routing does not actively query peers")}getSubscriptions(){return[...this.subscriptions]}cancel(e){let r=Yc(e)?e.toMultihash():e,n=it(r),o=Ws(n);this.subscriptions.has(o)&&(this.libp2p.services.pubsub.unsubscribe(o),this.subscriptions.delete(o))}toString(){return"PubSubRouting()"}async start(){this.shutdownController=new AbortController,this.shutdownController.signal,this.libp2p.services.fetch!=null&&(this.fetchTopologyId=await this.libp2p.register(this.libp2p.services.fetch.protocol,{onConnect:e=>{this.fetchPeers.add(e)},onDisconnect:e=>{this.fetchPeers.delete(e)}},{signal:this.shutdownController.signal}))}stop(){this.fetchQueue.abort(),this.shutdownController.abort(),this.fetchTopologyId!=null&&this.libp2p.unregister(this.fetchTopologyId)}},ri="/record/";function Ws(t){let e=W(t,"base64url");return`${ri}${e}`}function Vf(t){if(t.substring(0,ri.length)!==ri)throw new bn("Topic received is not from a record");let e=t.substring(ri.length);return se(e,"base64url")}function $f(t,e={}){return new Qs(t,e)}function dm(t,e={}){return new ti(t,e)}function hm(t,e={}){let r=vr(t.datastore,t.logger.forComponent("helia:ipns:local-store")),n=[ei(r),Ar(t.routing),...e.routers??[]];return new cr(t,{routers:n,localStore:r})}return Qf(pm);})();
13
+ ${e}[Error list was empty]`,r.trim()}return au(t,e)}Te.formatters.e=t=>t==null?"undefined":uu(t);function Uh(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 Zr(t,e){let r=Uh(`${t}:trace`);return Te.enabled(`${t}:trace`)&&Te.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=Te(`${t}:trace`,e)),Object.assign(Te(t,e),{error:Te(`${t}:error`,e),trace:r,newScope:n=>Zr(`${t}:${n}`,e)})}function cu(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var fu=ii(Dn(),1);var Fh=Zr("ipns"),Oh=300000000000n;async function fr(t,e,r,n,o){r=BigInt(r),e=ao(e);let i=le(e),s=o?.ttlNs??Oh,a=new fu.default((o?.now??Date.now())+Number(n)),c=te.ValidityType.EOL,f=le(a.toString()),u=ru({...o?.data??{},Value:i,Validity:f,ValidityType:0,Sequence:r,TTL:s}),l=io(u),h=await t.sign(l,o),m;return o?.v1Compatible===!1?m={signatureV2:h,data:u}:m={value:i,signatureV1:await Ph(t,i,c,f),validityType:c,validity:f,sequence:r,ttl:s,signatureV2:h,data:u},Mh(t.publicKey)&&(m.publicKey=t.publicKey.toProtobuf()),m}var Ph=async(t,e,r,n,o)=>{try{let i=tu(e,r,n);return await t.sign(i,o)}catch(i){throw Fh.error("record signature creation failed",i),new xn("Record signature creation failed")}};function Mh(t){return t.toMultihash().code!==Wc}var fo=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=ct(i),a=1n;if(await this.localStore.has(s,n)){let{record:l}=await this.localStore.get(s,n),h=te.decode(l);a=(Ke(h.data).Sequence??0n)+1n}let c=n.lifetime??1728e5,f=await fr(o,r,a,c,{...n,ttlNs:n.ttl!=null?BigInt(n.ttl)*1000000n:void 0}),u=te.encode(f);return n.offline===!0?await this.localStore.put(s,u,{...n,metadata:{keyName:e,lifetime:c}}):await Promise.all(this.routers.map(async l=>{await l.put(s,u,{...n,metadata:{keyName:e,lifetime:c}})})),{record:f,name:`/ipns/${o.publicKey.toCID().toString(ve)}`,publicKey:o.publicKey}}catch(o){throw n.onProgress?.(new me("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=ct(o);await this.localStore.delete(i,r)}};function lr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var lo=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}},dr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new lo(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 lo(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 is=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function lu(t={}){return Kh(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 Kh(t,e){e=e??{};let r=e.onEnd,n=new dr,o,i,s,a=lr(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((g,S)=>{i=T=>{i=null,n.push(T);try{g(t(n))}catch(y){S(y)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=lr()})}},f=g=>i!=null?i(g):(n.push(g),o),u=g=>(n=new dr,i!=null?i({error:g}):(n.push({error:g}),o)),l=g=>{if(s)return o;if(e?.objectMode!==!0&&g?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:g})},h=g=>s?o:(s=!0,g!=null?u(g):f({done:!0})),m=()=>(n=new dr,h(),{done:!0}),C=g=>(h(g),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:m,throw:C,push:l,end:h,get readableLength(){return n.size},onEmpty:async g=>{let S=g?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let T,y;S!=null&&(T=new Promise((R,_)=>{y=()=>{_(new is)},S.addEventListener("abort",y)}));try{await Promise.race([a.promise,T])}finally{y!=null&&S!=null&&S?.removeEventListener("abort",y)}}},r==null)return o;let x=o;return o={[Symbol.asyncIterator](){return this},next(){return x.next()},throw(g){return x.throw(g),r!=null&&(r(g),r=void 0),{done:!0}},return(){return x.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(g){return x.end(g),r!=null&&(r(g),r=void 0),o},get readableLength(){return x.readableLength},onEmpty:g=>x.onEmpty(g)},o}var ss=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},du=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function as(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,c,u=new Promise((l,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){h(du(s));return}if(s&&(c=()=>{h(du(s))},s.addEventListener("abort",c,{once:!0})),t.then(l,h),r===Number.POSITIVE_INFINITY)return;let m=new ss;a=i.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(C){h(C)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?l():o instanceof Error?h(o):(m.message=o??`Promise timed out after ${r} milliseconds`,h(m))},r)}).finally(()=>{u.clear(),c&&s&&s.removeEventListener("abort",c)});return u.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},u}var Vh=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 $h(t,e,r){let n,o=new Promise((i,s)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:f,removeListener:u}=Vh(t),l=async(...m)=>{let C=r.multiArgs?m:m[0];if(r.filter)try{if(!await r.filter(C))return}catch(x){n(),s(x);return}c.push(C),r.count===c.length&&(n(),i(c))},h=(...m)=>{n(),s(r.rejectionMultiArgs?m:m[0])};n=()=>{for(let m of a)u(m,l);for(let m of r.rejectionEvents)a.includes(m)||u(m,h)};for(let m of a)f(m,l);for(let m of r.rejectionEvents)a.includes(m)||f(m,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(o.cancel=n,typeof r.timeout=="number"){let i=as(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function ho(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=$h(t,e,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function Gr(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 po=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function qh(t){return t.reason}function mo(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??qh;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;return Promise.race([t,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})]).finally(()=>{o!=null&&e.removeEventListener("abort",o)})}var yo=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=lr(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new tt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function zh(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var hu=new WeakMap,go=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,r){this.id=zh(),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 tt),this.cleanup())}async join(e){let r=new yo(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 mo(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{if(this.recipients.length!==0&&!this.dispatchingProgress){if(typeof r=="object"&&r!==null){let n=hu.get(r);if(n==null&&(n=new WeakSet,hu.set(r,n)),n.has(this))return;n.add(this)}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.deferred.reject(e.signal?.reason??new tt),e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)}),this.recipients.splice(0,this.recipients.length)}};var hr=class extends eo{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=Gr(this.emitEmpty.bind(this),1),this.emitIdle=Gr(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 po;let n=new go(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 tt)}),this.clear()}async onEmpty(e){this.size!==0&&await ho(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await ho(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await ho(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=lu({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 tt("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 Xr(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}var pu=Symbol.for("sindresorhus/unlimited-timeout#brand");function mu(t,e,...r){if(typeof t!="function")throw new TypeError("Expected callback to be a function");e??=0,e=Number(e);let n=!1,o={[pu]:!0,id:void 0,cleared:!1,ref(){return n=!1,o.id?.ref?.(),o},unref(){return n=!0,o.id?.unref?.(),o}};if(e===Number.POSITIVE_INFINITY||e>Number.MAX_SAFE_INTEGER)return o;(!Number.isFinite(e)||e<0)&&(e=0);let i=performance.now()+e,s=a=>{o.cleared||(a<=2147483647?(o.id=globalThis.setTimeout(()=>{o.cleared||t(...r)},a),n&&o.id?.unref?.()):(o.id=globalThis.setTimeout(()=>{let c=performance.now(),f=Math.max(0,i-c);s(f)},2147483647),n&&o.id?.unref?.()))};return s(e),o}function yu(t){!t||typeof t!="object"||!t[pu]||(t.cleared=!0,t.id!==void 0&&(globalThis.clearTimeout(t.id),t.id=void 0))}var Hh=new WeakMap;function jh({clearTimeout:t,setTimeout:e}={}){return(r,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(o.reason);let i,s,a,c=t??clearTimeout,f=()=>{c(i),a(o.reason)},u=()=>{o&&o.removeEventListener("abort",f)},l=new Promise((h,m)=>{s=()=>{u(),h(n)},a=m,i=(e??setTimeout)(s,r)});return o&&o.addEventListener("abort",f,{once:!0}),Hh.set(l,()=>{c(i),i=null,s()}),l}}var Yh=jh({setTimeout:mu,clearTimeout:yu}),gu=Yh;function bu(t,e,r){let n,o,i=!1;function s(){let f={signal:o.signal},u;r?.timeout!=null&&(u=Xr([o.signal,AbortSignal.timeout(r.timeout)]),f.signal=u),i=!0,Promise.resolve().then(async()=>{await t(f)}).catch(()=>{}).finally(()=>{u!=null&&(u.aborted?u.clear():u.addEventListener("abort",()=>{u.clear()},{once:!0})),i=!1,!o.signal.aborted&&(n=setTimeout(s,e))})}let a=Gr(s,r?.debounce??100),c=!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:()=>{c||(c=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,e))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var bo=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||ma,this.started=!1,this.routers=r.routers??[],this.republishTask=bu(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 hr({concurrency:this.republishConcurrency});try{let n=[],o=0;for await(let{routingKey:i,record:s,metadata:a,created:c}of this.localStore.list(e)){if(o++,a==null){this.log("no metadata found for record %b, skipping",i);continue}let f;try{f=te.decode(s)}catch{this.log.trace("skipping invalid record %b because could not decode",i);continue}if(f.data==null){this.log.trace("skipping record %b because data was missing",i);continue}let u;try{u=Ke(f.data)}catch{this.log.trace("skipping record %b because could not decode data",i);continue}if(!eu(c,new Date(ee(u.Validity)))){this.log.trace("skipping record %b within republish threshold",i);continue}let l=u.Sequence+1n,h=u.TTL??gn,m;try{m=await this.keychain.exportKey(a.keyName)}catch(C){this.log.error("missing key %s, skipping republishing record - %e",a.keyName,C);continue}try{let C=await fr(m,ee(u.Value),l,a.lifetime,{...e,ttlNs:h});n.push({routingKey:i,record:C})}catch(C){this.log.error("error creating updated IPNS record for %s - %e",i,C);continue}}this.log(`found ${n.length}/${o} records to republish`);for(let{routingKey:i,record:s}of n)r.add(async()=>{try{let a=te.encode(s);await Promise.all(this.routers.map(c=>c.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 Wr;(function(t){let e;t.codec=()=>(e==null&&(e=We((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:Pe(0),value:Pe(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}}}})),e);function r(i){return Ge(i,t.codec())}t.encode=r;function n(i,s){return Ze(i,t.codec(),s)}t.decode=n;function o(i,s){return Xe(i,t.codec(),s)}t.stream=o})(Wr||(Wr={}));function wu(t){let e=t.getUTCFullYear(),r=String(t.getUTCMonth()+1).padStart(2,"0"),n=String(t.getUTCDate()).padStart(2,"0"),o=String(t.getUTCHours()).padStart(2,"0"),i=String(t.getUTCMinutes()).padStart(2,"0"),s=String(t.getUTCSeconds()).padStart(2,"0"),a=t.getUTCMilliseconds(),c=String(a*1e3*1e3).padStart(9,"0");return`${e}-${r}-${n}T${o}:${i}:${s}.${c}Z`}function xu(t){let e=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),r=String(t).trim().match(e);if(r==null)throw new Error("Invalid format");let n=parseInt(r[1],10),o=parseInt(r[2],10)-1,i=parseInt(r[3],10),s=parseInt(r[4],10),a=parseInt(r[5],10),c=parseInt(r[6],10),f=parseInt(r[7].slice(0,-6),10);return new Date(Date.UTC(n,o,i,s,a,c,f))}var It=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 Wr.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:wu(this.timeReceived)}}static deserialize(e){let r=Wr.decode(e);return new t(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(e){let r=xu(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)}};async function Eu(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,Ae(e),Ae(r.subarray()));return n?.signal?.throwIfAborted(),i}var Xh=parseInt("11111",2),cs=parseInt("10000000",2),Wh=parseInt("01111111",2),Su={0:Qr,1:Qr,2:Qh,3:tp,4:rp,5:ep,6:Jh,16:Qr,22:Qr,48:Qr};function us(t,e={offset:0}){let r=t[e.offset]&Xh;if(e.offset++,Su[r]!=null)return Su[r](t,e);throw new Error("No decoder for tag "+r)}function Jr(t,e){let r=0;if((t[e.offset]&cs)===cs){let n=t[e.offset]&Wh,o="0x";e.offset++;for(let i=0;i<n;i++,e.offset++){if(e.offset>=t.byteLength)throw new Error("invalid DER element length");o+=t[e.offset].toString(16).padStart(2,"0")}r=parseInt(o,16)}else r=t[e.offset],e.offset++;if(!Number.isInteger(r)||r<0||r>t.byteLength-e.offset)throw new Error("invalid DER element length");return r}function Qr(t,e){Jr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=us(t,e);if(n===null)break;r.push(n)}return r}function Qh(t,e){let r=Jr(t,e),n=e.offset,o=e.offset+r,i=[];for(let s=n;s<o;s++)s===n&&t[s]===0||i.push(t[s]);return e.offset+=r,Uint8Array.from(i)}function Jh(t,e){let r=Jr(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;e.offset<n;){let f=t[e.offset];if(e.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 ep(t,e){return e.offset++,null}function tp(t,e){let r=Jr(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function rp(t,e){let r=Jr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function np(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new Re;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function fs(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=np(t.byteLength);return new Re(Uint8Array.from([e.byteLength|cs]),e)}function vu(t){let e=new Re,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new Re(Uint8Array.from([2]),fs(e),e)}function Au(t){let e=Uint8Array.from([0]),r=new Re(e,t);return new Re(Uint8Array.from([3]),fs(r),r)}function wo(t,e=48){let r=new Re;for(let n of t)r.append(n);return new Re(Uint8Array.from([e]),fs(r),r)}var op=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),ip=Uint8Array.from([6,5,43,129,4,0,34]),sp=Uint8Array.from([6,5,43,129,4,0,35]),ap={ext:!0,kty:"EC",crv:"P-256"},cp={ext:!0,kty:"EC",crv:"P-384"},up={ext:!0,kty:"EC",crv:"P-521"},ls=32,ds=48,hs=66;function Tu(t){let e=us(t);return Iu(e)}function Iu(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===ls*2+1)return n=ee(e.subarray(r,r+ls),"base64url"),o=ee(e.subarray(r+ls),"base64url"),new pr({...ap,key_ops:["verify"],x:n,y:o});if(e.byteLength===ds*2+1)return n=ee(e.subarray(r,r+ds),"base64url"),o=ee(e.subarray(r+ds),"base64url"),new pr({...cp,key_ops:["verify"],x:n,y:o});if(e.byteLength===hs*2+1)return n=ee(e.subarray(r,r+hs),"base64url"),o=ee(e.subarray(r+hs),"base64url"),new pr({...up,key_ops:["verify"],x:n,y:o});throw new st(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Bu(t){return wo([vu(Uint8Array.from([1])),wo([fp(t.crv)],160),wo([Au(new Re(Uint8Array.from([4]),le(t.x??"","base64url"),le(t.y??"","base64url")))],161)]).subarray()}function fp(t){if(t==="P-256")return op;if(t==="P-384")return ip;if(t==="P-521")return sp;throw new st(`Invalid curve ${t}`)}var pr=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Bu(this.jwk)),this._raw}toMultihash(){return He.digest(mr(this))}toCID(){return se.createV1(114,this.toMultihash())}toString(){return re.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:be(this.raw,e.raw)}async verify(e,r,n){return Eu(this.jwk,r,e,n)}};var xo=BigInt(4294967295),Cu=BigInt(32);function lp(t,e=!1){return e?{h:Number(t&xo),l:Number(t>>Cu&xo)}:{h:Number(t>>Cu&xo)|0,l:Number(t&xo)|0}}function _u(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let i=0;i<r;i++){let{h:s,l:a}=lp(t[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var dp=t=>t/2**32|0,hp=t=>t>>>0;function Du(t,e,r,n){let o=dp(r),i=hp(r);t.setUint32(e,n?i:o,n),t.setUint32(e+4,n?o:i,n)}var ps=(t,e,r)=>t>>>r,ms=(t,e,r)=>t<<32-r|e>>>r,$t=(t,e,r)=>t>>>r|e<<32-r,qt=(t,e,r)=>t<<32-r|e>>>r,en=(t,e,r)=>t<<64-r|e>>>r-32,tn=(t,e,r)=>t>>>r-32|e<<64-r;function nt(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Ru=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Lu=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Nu=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),ku=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Uu=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Fu=(t,e,r,n,o,i)=>e+r+n+o+i+(t/2**32|0)|0;function Eo(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var ys=t=>t?`"${t}" `:"";function ut(t,e=""){if(typeof t!="number")throw new TypeError(ys(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(ys(e)+"expected integer >= 0, got "+t);return t}function Ve(t,e,r=""){if(Eo(t)&&(e===void 0||t.length===e))return t;e!==void 0&&ut(e,"length");let n=Eo(t),o=e!==void 0?` of length ${e}`:"",i=n?`length=${t.length}`:`type=${typeof t}`,s=ys(r)+"expected Uint8Array"+o+", got "+i;throw n?new RangeError(s):new TypeError(s)}function So(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(ut(t.outputLen),ut(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var mp=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)},Ou=(t,e)=>{mp(t,e);let r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${e}" expected plain object`);if(Object.hasOwn(t,"__proto__"))throw new TypeError(`"${e}.__proto__" is not allowed`)};function yr(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function vo(t,e){Ve(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function zt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Ao(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Ye(t,e){return t<<32-e|t>>>e}var Mu=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",yp=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function To(t){if(Ve(t),Mu)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=yp[t[r]];return e}function Pu(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function Io(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Mu)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=Pu(t.charCodeAt(i)),a=Pu(t.charCodeAt(i+1));if(s===void 0||a===void 0){let c=t[i]+t[i+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function gs(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Ve(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let i=t[n];r.set(i,o),o+=i.length}return r}function gp(t,e,r="opts"){return Ou(t,"defaults"),e!==void 0&&Ou(e,r),Object.assign(Object.create(null),t,e)}function bs(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=gp({},e,"info");let r=(o,i)=>t(i).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function Ku(t=32){ut(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var ws=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Vu(t,e,r){return t&e^~t&r}function $u(t,e,r){return t&e^t&r^e&r}var rn=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Ao(this.buffer)}update(e){yr(this),Ve(e);let{view:r,buffer:n,blockLen:o}=this,i=e.length,s=!1;for(let a=0;a<i;){let c=Math.min(o-this.pos,i-a);if(c===o){let f=Ao(e);for(;o<=i-a;a+=o)this.process(f,a);s=!0;continue}n.set(a===0&&c===i?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,s=!0)}return this.length+=e.length,s&&this.roundClean(),this}digestInto(e){yr(this),vo(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,r.fill(0,s),this.padOffset>o-s&&(this.process(n,0),r.fill(0)),Du(n,o-8,this.length*8,i),this.process(n,0),this.roundClean();let a=e===r?n:Ao(e),c=this.outputLen,f=c/4,u=this.get();if(c%4||f>u.length)throw new Error("invalid outputLen");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],i)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:o,destroyed:i,pos:s}=this;return e.destroyed=i,e.finished=o,e.length=n,e.pos=s,s&&e.buffer.set(r),e}clone(){return this._cloneInto()}},qu=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var zu=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var bp=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]),Bt=new Uint32Array(64),xs=class extends rn{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,r){super(64,e,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:e,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,r,n,o,i,s,a,c]}set(e,r,n,o,i,s,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let l=0;l<16;l++,r+=4)Bt[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let h=Bt[l-15],m=Bt[l-2],C=Ye(h,7)^Ye(h,18)^h>>>3,x=Ye(m,17)^Ye(m,19)^m>>>10;Bt[l]=x+Bt[l-7]+C+Bt[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 h=Ye(a,6)^Ye(a,11)^Ye(a,25),m=u+h+Vu(a,c,f)+bp[l]+Bt[l]|0,x=(Ye(n,2)^Ye(n,13)^Ye(n,22))+$u(n,o,i)|0;u=f,f=c,c=a,a=s+m|0,s=i,i=o,o=n,n=m+x|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(){zt(Bt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),zt(this.buffer)}},Es=class extends xs{constructor(){super(32,qu)}};var Hu=_u(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),wp=Hu[0],xp=Hu[1],Ct=new Uint32Array(80),_t=new Uint32Array(80),Ss=class extends rn{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(e,r){super(128,e,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:h,Gh:m,Gl:C,Hh:x,Hl:g}=this;return[e,r,n,o,i,s,a,c,f,u,l,h,m,C,x,g]}set(e,r,n,o,i,s,a,c,f,u,l,h,m,C,x,g){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=h|0,this.Gh=m|0,this.Gl=C|0,this.Hh=x|0,this.Hl=g|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let y=0;y<16;y++,r+=4)Ct[y]=e.getUint32(r),_t[y]=e.getUint32(r+=4);for(let y=16;y<80;y++){let R=Ct[y-15]|0,_=_t[y-15]|0,$=$t(R,_,1)^$t(R,_,8)^ps(R,_,7),q=qt(R,_,1)^qt(R,_,8)^ms(R,_,7),b=Ct[y-2]|0,E=_t[y-2]|0,v=$t(b,E,19)^en(b,E,61)^ps(b,E,6),N=qt(b,E,19)^tn(b,E,61)^ms(b,E,6),L=Nu(q,N,_t[y-7],_t[y-16]),z=ku(L,$,v,Ct[y-7],Ct[y-16]);Ct[y]=z|0,_t[y]=L|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:h,Fh:m,Fl:C,Gh:x,Gl:g,Hh:S,Hl:T}=this;for(let y=0;y<80;y++){let R=$t(l,h,14)^$t(l,h,18)^en(l,h,41),_=qt(l,h,14)^qt(l,h,18)^tn(l,h,41),$=l&m^~l&x,q=h&C^~h&g,b=Uu(T,_,q,xp[y],_t[y]),E=Fu(b,S,R,$,wp[y],Ct[y]),v=b|0,N=$t(n,o,28)^en(n,o,34)^en(n,o,39),L=qt(n,o,28)^tn(n,o,34)^tn(n,o,39),z=n&i^n&a^i&a,I=o&s^o&c^s&c;S=x|0,T=g|0,x=m|0,g=C|0,m=l|0,C=h|0,{h:l,l:h}=nt(f|0,u|0,E|0,v|0),f=a|0,u=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let k=Ru(v,L,I);n=Lu(k,E,N,z),o=k|0}({h:n,l:o}=nt(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=nt(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=nt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=nt(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:h}=nt(this.Eh|0,this.El|0,l|0,h|0),{h:m,l:C}=nt(this.Fh|0,this.Fl|0,m|0,C|0),{h:x,l:g}=nt(this.Gh|0,this.Gl|0,x|0,g|0),{h:S,l:T}=nt(this.Hh|0,this.Hl|0,S|0,T|0),this.set(n,o,i,s,a,c,f,u,l,h,m,C,x,g,S,T)}roundClean(){zt(Ct,_t)}destroy(){this.destroyed=!0,zt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},vs=class extends Ss{constructor(){super(64,zu)}};var ju=bs(()=>new Es,ws(1));var As=bs(()=>new vs,ws(3));function Co(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}var Q=(t,e,r)=>Ve(t,e,r),Ts=ut;function Zu(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function Dt(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Ht(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var nn=To,$e=(...t)=>gs(...t),gr=t=>Io(t),Lt=Eo,jt=t=>Ku(t),Bo=BigInt(0),Yu=BigInt(1),Ep=t=>t?`"${t}" `:"";function Ie(t,e=""){if(typeof t!="boolean")throw new TypeError(Ep(e)+"expected boolean, got type="+typeof t);return t}function _o(t){if(typeof t=="bigint"){if(!Rt(t))throw new RangeError("positive bigint expected, got "+t)}else Ts(t);return t}function ft(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function on(t){let e=_o(t).toString(16);return e.length&1?"0"+e:e}function Gu(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Bo:BigInt("0x"+t)}function ot(t){return Gu(To(t))}function Yt(t){return Gu(To(sn(Ve(t)).reverse()))}function Do(t,e){if(ut(e),e===0)throw new Error("zero output length is invalid");t=_o(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return Io(n.padStart(r,"0"))}function Is(t,e){return Do(t,e).reverse()}function sn(t){return Uint8Array.from(Q(t))}function Rt(t){return typeof t=="bigint"&&Bo<=t}function Bs(t,e,r){return Rt(t)&&Rt(e)&&Rt(r)&&e<=t&&t<r}function br(t,e,r,n){if(!Bs(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function wr(t){if(t<Bo)throw new Error("expected non-negative bigint, got "+t);return t===Bo?0:t.toString(2).length}var an=t=>(ft(t,"n"),(Yu<<BigInt(t))-Yu);function Xu(t,e,r){if(ut(t,"hashLen"),ut(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=g=>new Uint8Array(g),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=n(t),f=n(t),u=0,l=()=>{c.fill(1),f.fill(0),u=0},h=(...g)=>r(f,$e(c,...g)),m=(g=o)=>{f=h(i,g),c=h(),g.length!==0&&(f=h(s,g),c=h())},C=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let g=0,S=[];for(;g<e;){c=h();let T=c.slice();S.push(T),g+=c.length}return $e(...S)};return(g,S)=>{l(),m(g);let T;for(;(T=S(C()))===void 0;)m();return l(),T}}function Be(t,e={},r={},n="object"){Dt(t,n),Dt(e,"fields"),Dt(r,"optFields");function o(s,a,c){let f=n==="object"?`param "${String(s)}"`:`"${n}.${String(s)}"`,u=t[s];if(!Object.hasOwn(t,s)&&(c?u!==void 0:a!=="function"))throw new TypeError(`${f} is invalid: expected own property`);if(c&&u===void 0)return;let l=typeof u;if(l!==a||u===null)throw new TypeError(`${f} is invalid: expected ${a}, got ${l}`)}let i=(s,a)=>Object.entries(s).forEach(([c,f])=>o(c,f,a));i(e,!1),i(r,!0)}var ye=BigInt(0),J=BigInt(1),Nt=BigInt(2),Ju=BigInt(3),Cs=BigInt(4),ef=BigInt(5),Sp=BigInt(7),tf=BigInt(8),vp=BigInt(9),Ap=BigInt(15),rf=BigInt(16),Tp=BigInt("0x10000000000000000");function ae(t,e){if(e<=ye)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=ye?r:e+r}function nf(t,e,r){if(r<=J)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<ye)throw new Error("invalid exponent, negatives unsupported");if(e===ye)return J;if(e===J)return t;let n=t%r;if(n<ye&&(n+=r),e<Tp){let a=J;for(;e>ye;)e&J&&(a=a*n%r),n=n*n%r,e>>=J;return a}let o=[];for(;e>ye;)o.push(Number(e&Ap)),e>>=Cs;let i=new Array(16);i[0]=J,i[1]=n;for(let a=2;a<16;a++)i[a]=i[a-1]*n%r;let s=i[o[o.length-1]];for(let a=o.length-2;a>=0;a--){s=s*s%r,s=s*s%r,s=s*s%r,s=s*s%r;let c=o[a];c!==0&&(s=s*i[c]%r)}return s}function ie(t,e,r){if(r<=J)throw new Error("pow2: expected modulus > 1, got "+r);if(e<ye)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >ye;)n*=n,n%=r;return n}function Wu(t,e){if(t===ye)throw new Error("invert: expected non-zero number");if(e<=J)throw new Error("invert: expected modulus > 1, got "+e);let r=ae(t,e),n=e,o=ye,i=J;for(;r!==ye;){let a=n/r,c=n-r*a,f=o-i*a;n=r,r=c,o=i,i=f}if(n!==J)throw new Error("invert: does not exist");return ae(o,e)}function of(t,e){if(e<=J)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=ae(t,e);if(r===ye)throw new Error("invertCt: expected non-zero number");let n=nf(r,e-Nt,e);if(ae(r*n,e)!==J)throw new Error("invertCt: does not exist");return n}function _s(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Ds(t,e){if((t&J)===ye)throw new Error(e+": expected odd modulus, got "+t)}function sf(t,e){let r=t,n=(r.ORDER+J)/Cs,o=r.pow(e,n);return _s(r,o,e),o}function Ip(t,e){let r=t,n=(r.ORDER-ef)/tf,o=r.mul(e,Nt),i=r.pow(o,n),s=r.mul(e,i),a=r.mul(r.mul(s,Nt),i),c=r.mul(s,r.sub(a,r.ONE));return _s(r,c,e),c}function Bp(t){let e=Er(t),r=af(t),n=r(e,e.neg(e.ONE)),o=r(e,n),i=r(e,e.neg(n)),s=(t+Sp)/rf;return((a,c)=>{let f=a,u=f.pow(c,s),l=f.mul(u,n),h=f.mul(u,o),m=f.mul(u,i),C=f.eql(f.sqr(l),c),x=f.eql(f.sqr(h),c);u=f.cmov(u,l,C),l=f.cmov(m,h,x);let g=f.eql(f.sqr(l),c),S=f.cmov(u,l,g);return _s(f,S,c),S})}function af(t){if(t<Ju)throw new Error("sqrt is not defined for small field");Ds(t,"tonelliShanks");let e=t-J,r=0;for(;e%Nt===ye;)e/=Nt,r++;let n=Nt,o=Er(t);for(;cn(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return sf;let i=o.pow(n,e),s=(e+J)/Nt;return function(c,f){let u=c;if(u.is0(f))return f;if(cn(u,f)!==1)throw new Error("Cannot find square root");let l=r,h=u.mul(u.ONE,i),m=u.pow(f,e),C=u.pow(f,s);for(;!u.eql(m,u.ONE);){if(u.is0(m))throw new Error("Cannot find square root: probably non-prime P");let x=1,g=u.sqr(m);for(;!u.eql(g,u.ONE);)if(x++,g=u.sqr(g),x===l)throw new Error("Cannot find square root");let S=J<<BigInt(l-x-1),T=u.pow(h,S);l=x,h=u.sqr(T),m=u.mul(m,h),C=u.mul(C,T)}return C}}function Cp(t){return Ds(t,"Fp.sqrt"),t%Cs===Ju?sf:t%tf===ef?Ip:t%rf===vp?Bp(t):af(t)}var cf=(t,e)=>(ae(t,e)&J)===J,_p=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function xr(t){if(Dt(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);ft(t.BYTES,"BYTES"),ft(t.BITS,"BITS");for(let e of _p)Ht(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=J)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Lo(t,e,r=!1){xr(t),Co(e,"nums"),Ie(r,"passZero");let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),i=e.reduce((a,c,f)=>n.is0(c)?a:(o[f]=a,n.mul(a,c)),n.ONE),s=n.inv(i);return e.reduceRight((a,c,f)=>n.is0(c)?a:(o[f]=n.mul(a,o[f]),n.mul(a,c)),s),o}function cn(t,e){xr(t);let r=t;Ds(r.ORDER,"FpLegendre");let n=(r.ORDER-J)/Nt,o=r.pow(e,n),i=r.eql(o,r.ONE),s=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!i&&!s&&!a)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function Dp(t,e){if(e!==void 0&&Ts(e),t<=ye)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=wr(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Qu=new WeakMap,Ro=class{ORDER;BITS;BYTES;isLE;ZERO=ye;ONE=J;_lengths;_mod;constructor(e,r={}){if(e<=J)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:i}=Dp(e,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=i,Object.freeze(this)}create(e){return ae(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return ye<=e&&e<this.ORDER}is0(e){return e===ye}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&J)===J}neg(e){return ae(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ae(e*e,this.ORDER)}add(e,r){return ae(e+r,this.ORDER)}sub(e,r){return ae(e-r,this.ORDER)}mul(e,r){return ae(e*r,this.ORDER)}pow(e,r){return nf(e,r,this.ORDER)}div(e,r){return ae(e*Wu(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return Wu(e,this.ORDER)}sqrt(e){let r=Qu.get(this);return r||Qu.set(this,r=Cp(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Is(e,this.BYTES):Do(e,this.BYTES)}fromBytes(e,r=!1){Q(e);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let f=new Uint8Array(o);f.set(e,i?0:f.length-e.length),e=f}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=i?Yt(e):ot(e);if(a&&(c=ae(c,s)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Lo(this,e,!0)}cmov(e,r,n){return Ie(n,"condition"),n?r:e}};function Er(t,e={}){return Object.freeze(Ro.prototype),new Ro(t,e)}function uf(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=J)throw new Error("field order must be greater than 1");let e=wr(t-J);return Math.ceil(e/8)}function No(t){let e=uf(t);return e+Math.ceil(e/2)}function ko(t,e,r=!1){Q(t);let n=t.length,o=uf(e),i=Math.max(No(e),16);if(n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Yt(t):ot(t),a=ae(s,e-J)+J;return r?Is(a,o):Do(a,o)}var Ns=BigInt(0),un=BigInt(1),Rp=BigInt(4),Rs=16,ff=128,Lp=5,lf=2**31;function kt(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Ht(e.fromAffine,"Point.fromAffine"),Ht(e.fromBytes,"Point.fromBytes"),Ht(e.fromHex,"Point.fromHex"),Dt(e.BASE,"Point.BASE"),Dt(e.ZERO,"Point.ZERO"),xr(e.Fp),xr(e.Fn)}function Uo(t,e){kt(t),hf(e,t);let r=Lo(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function Np(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function kp(t,e){let r=t*(4*e+128);if(r>lf)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+lf/2**20+" MiB")}function ks(t,e){if(t!==void 0){Ht(t,"randomBytes");try{let r=t(e);if(!Lt(r)||r.length!==e)return}catch{return}return t}}function hf(t,e){Co(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function Up(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,o)=>{if(!(r===void 0?e.isValid(n):Rt(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var pf=new WeakMap;function Ls(t){return pf.get(t)||1}function Fp(t,e){let r=t.double(),n=[t];for(let o=1;o<e;o++)n.push(n[o-1].add(r));return n}function Op(t,e){let r=2**e,n=r/2,o=BigInt(r-1),i=[];for(;t>Ns;){let s=0;t&un&&(s=Number(t&o),s>=n&&(s-=r),t-=BigInt(s)),i.push(s),t>>=un}return i}function Pp(t,e,r){let n=2**e,o=n/2,i=BigInt(n-1),s=BigInt(e),a=[];for(let c=0;c<r;c++){let f=Number(t&i);t>>=s,f>o&&(f-=n,t+=un),a.push(f)}if(t!==Ns)throw new Error("invalid wnaf");return a}function Mp(t,e,r){let n=0;for(let i of r)n=Math.max(n,i.length);let o=t;for(let i=n-1;i>=0;i--){i!==n-1&&(o=o.double());for(let s=0;s<r.length;s++){let a=r[s][i];if(a){let c=e[s][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var Sr=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){kt(e),this.randomBytes=ks(r,Rs),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let o=Math.ceil(n/r)+1,i=2**(r-1),s=[],a=e;for(let c=0;c<o;c++){let f=a;for(let u=0;u<i;u++)s.push(f),f=f.add(a);a=s[s.length-1].double()}return{W:r,bits:n,windows:o,comp:s}}wnafCachedCT(e,r){let{W:n,windows:o,comp:i}=e,s=2**(n-1),a=Pp(r,n,o),c=this.ZERO,f=this.BASE;for(let u=0;u<o;u++){let l=a[u],h=u*s,m=Math.abs(l)-1,C=i[h];for(let g=1;g<s;g++)C=g===m?i[h+g]:C;let x=C.negate();l===0?f=f.add(i[h]):c=c.add(l<0?x:C)}return{p:c,f}}getWnafPrecomputes(e,r,n,o){let i=this.wnafPrecomputes.get(r),s=i?.find(a=>a.W===e&&a.bits===n);return s||(s=this.buildWnafTable(r,e,n),typeof o=="function"&&(s={...s,comp:o(s.comp)}),i||(i=[],this.wnafPrecomputes.set(r,i)),i.push(s)),s}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!Bs(r,un,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,o){let i=Ls(e);return i===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(i,e,n,o),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+ff,i=this.randomBytes(Rs);if(!Lt(i)||i.length!==Rs)throw new Error("randomBytes returned invalid byte array");i[0]=i[0]&63|128;let s=r+ot(i)*this.Point.Fn.ORDER;return this.runCT(e,s,o,n)}fixedWindowCT(e,r,n){let o=Lp,i=1<<o,s=an(o),a=new Array(i);a[0]=this.ZERO;for(let u=1;u<i;u++)a[u]=a[u-1].add(e);let c=Math.ceil(n/o),f=this.ZERO;for(let u=c-1;u>=0;u--){if(u!==c-1)for(let m=0;m<o;m++)f=f.double();let l=Number(r>>BigInt(u*o)&s),h=a[0];for(let m=1;m<i;m++)h=m===l?a[m]:h;f=f.add(h)}return{p:f,f}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===un?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,o){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,o):this.mulCT(e,r,o)}mulUnsafe(e,r,n){if(this.assertPoint(e),!Rt(r))throw new Error("invalid scalar");let o=Ls(e);if(o===1||r>=this.Point.Fn.ORDER)return Fo(this.Point,[e],[r],!0);let i=this.getWnafPrecomputes(o,e,this.bits,n);return this.wnafCachedCT(i,r).p}setWindowSize(e,r){this.assertPoint(e),Np(r,this.bits);let n=Math.ceil((this.bits+ff)/r)+1;kp(n*2**(r-1),this.Point.Fp.BYTES),pf.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Ls(e)!==1}};function Fo(t,e,r,n=!1){if(kt(t),hf(e,t),Ie(n,"allowOversized"),Up(r,t.Fn,n?t.Fn.ORDER**Rp:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(s=>Fp(s,4)),i=r.map(s=>Op(s,4));return Mp(t.ZERO,o,i)}function df(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return xr(e),e}else return Er(t,{isLE:r})}function Oo(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);Be(r);for(let c of["p","n","h"]){let f=e[c];if(!(Rt(f)&&f!==Ns))throw new Error(`CURVE.${c} must be positive bigint`)}let o=df(e.p,r.Fp,n),i=df(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:i}}function Po(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var Mo=BigInt(0),Ko=BigInt(1),Vo=BigInt(2),Kp=BigInt(4),mf=BigInt(8);function Vp(t,e,r,n){let o=t.sqr(r),i=t.sqr(n),s=t.add(t.mul(e.a,o),i),a=t.add(t.ONE,t.mul(e.d,t.mul(o,i)));return t.eql(s,a)}function yf(t,e={}){Be(e,{},{},"extraOpts");let r=e,n=Oo("edwards",t,r,r.FpFnLE),{Fp:o,Fn:i}=n,s=n.CURVE,{h:a}=s;if(cn(o,s.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(cn(o,s.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Be(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?jt:r.randomBytes,f=Vo<<BigInt(o.BYTES*8)-Ko;function u(T){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(T)}let l=r.uvRatio===void 0?(T,y)=>{try{return{isValid:!0,value:o.sqrt(o.div(T,y))}}catch{return{isValid:!1,value:Mo}}}:r.uvRatio;if(!Vp(o,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");let h=o.eql(s.a,o.neg(o.ONE))?T=>o.neg(T):o.eql(s.a,o.ONE)?T=>T:T=>o.mul(s.a,T);function m(T,y,R=!1){let _=R?Ko:Mo;return br("coordinate "+T,y,_,f),y}function C(T){if(!(T instanceof x))throw new Error("EdwardsPoint expected")}class x{static BASE=new x(s.Gx,s.Gy,o.ONE,o.mul(s.Gx,s.Gy));static ZERO=new x(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=i;X;Y;Z;T;constructor(y,R,_,$){this.X=m("x",y),this.Y=m("y",R),this.Z=m("z",_,!0),this.T=m("t",$),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){if(y instanceof x)throw new Error("extended point not allowed");let{x:R,y:_}=y||{};return m("x",R),m("y",_),new x(R,_,o.ONE,o.mul(R,_))}static fromBytes(y,R=!1){let _=o.BYTES,{a:$,d:q}=s;y=sn(Q(y,_,"point")),Ie(R,"zip215");let b=sn(y),E=y[_-1];b[_-1]=E&-129;let v=Yt(b),N=R?f:o.ORDER;br("point.y",v,Mo,N);let L=o.sqr(v),z=o.sub(L,o.ONE),I=o.sub(o.mulN(q,L),$),{isValid:k,value:O}=l(z,I);if(!k)throw new Error("bad point: invalid y coordinate");let P=u(O),Y=(E&128)!==0;if(!R&&o.is0(O)&&Y)throw new Error("bad point: x=0 and x_0=1");return Y!==P&&(O=o.neg(O)),x.fromAffine({x:O,y:v})}static fromHex(y,R=!1){return x.fromBytes(gr(y),R)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=6,R=!0){return S.setWindowSize(this,y),R||this.multiply(Vo),this}assertValidity(){let y=this,{a:R,d:_}=s;if(y.is0())throw new Error("bad point: ZERO");let{X:$,Y:q,Z:b,T:E}=y,v=o.sqr($),N=o.sqr(q),L=o.sqr(b),z=o.sqr(L),I=o.mul(v,R),k=o.mul(o.add(I,N),L),O=o.add(z,o.mul(_,o.mul(v,N)));if(!o.eql(k,O))throw new Error("bad point: equation left != right (1)");let P=o.mul($,q),Y=o.mul(b,E);if(!o.eql(P,Y))throw new Error("bad point: equation left != right (2)")}equals(y){C(y);let{X:R,Y:_,Z:$}=this,{X:q,Y:b,Z:E}=y,v=o.mul(R,E),N=o.mul(q,$),L=o.mul(_,E),z=o.mul(b,$);return o.eql(v,N)&&o.eql(L,z)}is0(){return this.equals(x.ZERO)}negate(){return new x(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:y,Y:R,Z:_}=this,$=o.sqr(y),q=o.sqr(R),b=o.mul(o.sqr(_),Vo),E=h($),v=o.addN(y,R),N=o.sub(o.subN(o.sqr(v),$),q),L=o.addN(E,q),z=o.subN(L,b),I=o.subN(E,q),k=o.mul(N,z),O=o.mul(L,I),P=o.mul(N,I),Y=o.mul(z,L);return new x(k,O,Y,P)}add(y){C(y);let{d:R}=s,{X:_,Y:$,Z:q,T:b}=this,{X:E,Y:v,Z:N,T:L}=y,z=o.mul(_,E),I=o.mul($,v),k=o.mul(o.mulN(b,R),L),O=o.mul(q,N),P=o.sub(o.subN(o.mulN(o.addN(_,$),o.addN(E,v)),z),I),Y=o.subN(O,k),W=o.addN(O,k),U=o.sub(I,h(z)),p=o.mul(P,Y),w=o.mul(W,U),A=o.mul(P,U),F=o.mul(Y,W);return new x(p,w,F,A)}subtract(y){return C(y),this.add(y.negate())}multiply(y){if(!i.isValidNot0(y))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:R,f:_}=S.mulSecret(this,y,a,g);return g([R,_])[0]}multiplyUnsafe(y){if(!i.isValid(y))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return y===Mo?x.ZERO:this.is0()||y===Ko?this:S.mulUnsafe(this,y,g)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return S.mulUnsafe(this,s.n).is0()}toAffine(y){let R=this,_=y;if(_!=null&&typeof _!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof _);let{X:$,Y:q,Z:b}=R,E=R.is0();_==null&&(_=E?o.create(mf):o.inv(b));let v=o.mul($,_),N=o.mul(q,_),L=o.mul(b,_);if(E)return{x:o.ZERO,y:o.ONE};if(!o.eql(L,o.ONE))throw new Error("invZ was invalid");return{x:v,y:N}}clearCofactor(){return a===Ko?this:a===Vo?this.double():a===Kp?this.double().double():a===mf?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:y,y:R}=this.toAffine(),_=o.toBytes(R);return _[_.length-1]|=u(y)?128:0,_}toHex(){return nn(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let g=T=>Uo(x,T),S=new Sr(x,c);return S.bits>=6&&x.BASE.precompute(6),Object.freeze(x.prototype),Object.freeze(x),x}function gf(t,e,r={}){if(kt(t),typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Be(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:i}=o,{BASE:s,Fp:a,Fn:c}=t,f=n.outputLen,u=2*a.BYTES;if(f!==void 0&&(ft(f,"hash.outputLen"),f!==u))throw new Error(`hash.outputLen must be ${u}, got ${f}`);let l=o.randomBytes===void 0?jt:o.randomBytes,h=o.toMontgomery,m=o.toMontgomerySecret,C=o.adjustScalarBytes===void 0?I=>I:o.adjustScalarBytes,x=o.domain===void 0?(I,k,O)=>{if(Ie(O,"phflag"),k.length||O)throw new Error("Contexts/pre-hash are not supported");return I}:o.domain;function g(I){return c.create(Yt(I))}function S(I){let k=E.secretKey;Q(I,E.secretKey,"secretKey");let O=Q(n(I),2*k,"hashedSecretKey"),P=C(O.slice(0,k)),Y=O.slice(k,2*k),W=g(P);return{head:P,prefix:Y,scalar:W}}function T(I){let{head:k,prefix:O,scalar:P}=S(I),Y=s.multiply(P),W=Y.toBytes();return{head:k,prefix:O,scalar:P,point:Y,pointBytes:W}}function y(I){return T(I).pointBytes}function R(I=Uint8Array.of(),...k){let O=$e(...k);return g(n(x(O,Q(I,void 0,"context"),!!i)))}function _(I,k,O={}){Be(O,{},{},"options"),I=sn(Q(I,void 0,"message")),i&&(I=i(I));let{prefix:P,scalar:Y,pointBytes:W}=T(k),U=R(O.context,P,I),p=s.multiply(U).toBytes(),w=R(O.context,p,W,I),A=c.create(U+w*Y);if(!c.isValid(A))throw new Error("sign failed: invalid s");let F=$e(p,c.toBytes(A));return Q(F,E.signature,"result")}let $={zip215:o.zip215};function q(I,k,O,P=$){Be(P);let{context:Y}=P,W=P.zip215===void 0?!!$.zip215:P.zip215,U=E.signature;I=Q(I,U,"signature"),k=Q(k,void 0,"message"),O=Q(O,E.publicKey,"publicKey"),W!==void 0&&Ie(W,"zip215"),i&&(k=i(k));let p=U/2,w=I.subarray(0,p),A=Yt(I.subarray(p,U)),F,M,K;try{F=t.fromBytes(O,W),M=t.fromBytes(w,W),K=s.multiplyUnsafe(A)}catch{return!1}if(!W&&F.isSmallOrder())return!1;let H=R(Y,w,O,k);return M.add(F.multiplyUnsafe(H)).subtract(K).clearCofactor().is0()}let b=a.BYTES,E={secretKey:b,publicKey:b,signature:2*b,seed:b};function v(I){return I=I===void 0?l(E.seed):I,Q(I,E.seed,"seed")}function N(I){return Lt(I)&&I.length===E.secretKey}function L(I,k){try{return!!t.fromBytes(I,k===void 0?$.zip215:k)}catch{return!1}}let z={getExtendedPublicKey:T,randomSecretKey:v,isValidSecretKey:N,isValidPublicKey:L,toMontgomery(I){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(t.fromBytes(I))},toMontgomerySecret(I){if(m===void 0)throw new Error("Montgomery conversion is not supported for this curve");return m(I)}};return Object.freeze(E),Object.freeze(z),Object.freeze({keygen:Po(v,y),getPublicKey:y,sign:_,verify:q,utils:z,Point:t,lengths:E})}var Us=BigInt(1),bf=BigInt(2);var $p=BigInt(5),qp=BigInt(8),Fs=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),zp={p:Fs,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:qp,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Hp(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=Fs,a=t*t%i*t%i,c=ie(a,bf,i)*a%i,f=ie(c,Us,i)*t%i,u=ie(f,$p,i)*f%i,l=ie(u,e,i)*u%i,h=ie(l,r,i)*l%i,m=ie(h,n,i)*h%i,C=ie(m,o,i)*m%i,x=ie(C,o,i)*m%i,g=ie(x,e,i)*u%i;return{pow_p_5_8:ie(g,bf,i)*t%i,b2:a}}function Ef(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var wf=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function jp(t,e){let r=Fs,n=ae(e*e*e,r),o=ae(n*n*e,r),i=Hp(t*o).pow_p_5_8,s=ae(t*n*i,r),a=ae(e*s*s,r),c=s,f=ae(s*wf,r),u=a===t,l=a===ae(-t,r),h=a===ae(-t*wf,r);return u&&(s=c),(l||h)&&(s=f),cf(s,r)&&(s=ae(-s,r)),{isValid:u||l,value:s}}var Os=yf(zp,{uvRatio:jp}),xf=Os.Fp;function Yp(t){let{y:e}=t;return xf.toBytes(xf.div(Us+e,Us-e))}function Zp(t){let e=Os.Fp.BYTES;return Ve(t,e),Ef(As(t.subarray(0,e))).subarray(0,e)}function Gp(t){return gf(Os,As,Object.assign({adjustScalarBytes:Ef,toMontgomery:Yp,toMontgomerySecret:Zp,zip215:!0},t))}var Sf=Gp({});var fn=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},$o=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var qo={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new $o("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var zo=32;var Ps,Xp=(async()=>{try{return await qo.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Wp(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await qo.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await qo.get().subtle.verify({name:"Ed25519"},n,Ae(e),Ae(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Qp(t,e,r){return Sf.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function vf(t,e,r){return Ps==null&&(Ps=await Xp),Ps?Wp(t,e,r):Qp(t,e,r)}function Ho(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var jo=class{type="Ed25519";raw;constructor(e){this.raw=Ms(e,zo)}toMultihash(){return He.digest(mr(this))}toCID(){return se.createV1(114,this.toMultihash())}toString(){return re.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:be(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=vf(this.raw,r,e);return Ho(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}};function Tf(t){return t=Ms(t,zo),new jo(t)}function Ms(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new st(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var Se;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(Se||(Se={}));var Ks;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Ks||(Ks={}));(function(t){t.codec=()=>Fr(Ks)})(Se||(Se={}));var ln;(function(t){let e;t.codec=()=>(e==null&&(e=We((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),Se.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=Se.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:Se.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(u&7);break}}}})),e);function r(i){return Ge(i,t.codec())}t.encode=r;function n(i,s){return Ze(i,t.codec(),s)}t.decode=n;function o(i,s){return Xe(i,t.codec(),s)}t.stream=o})(ln||(ln={}));var Vs;(function(t){let e;t.codec=()=>(e==null&&(e=We((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),Se.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=Se.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:Se.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(u&7);break}}}})),e);function r(i){return Ge(i,t.codec())}t.encode=r;function n(i,s){return Ze(i,t.codec(),s)}t.decode=n;function o(i,s){return Xe(i,t.codec(),s)}t.stream=o})(Vs||(Vs={}));var Yo=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(So(e),Ve(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=e.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),zt(o)}update(e){return yr(this),this.iHash.update(e),this}digestInto(e){yr(this),vo(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a,canXOF:c}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},If=(()=>{let t=((e,r,n)=>new Yo(e,r).update(n).digest());return t.create=(e,r)=>new Yo(e,r),t})();var tm=BigInt(0),$s=class extends Error{constructor(e=""){super(e)}},lt={Err:$s,_tlv:{encode:(t,e)=>{let{Err:r}=lt;if(ft(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(Zu(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=on(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?on(o.length/2|128):"";return on(t)+i+o+e},decode(t,e){let{Err:r}=lt;e=Q(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=e.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=e.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(t){let{Err:e}=lt;if(_o(t),t<tm)throw new e("integer: negative integers are not allowed");let r=on(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=lt;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return ot(t)}},toSig(t,e){let{Err:r,_int:n,_tlv:o}=lt;if(e!==void 0&&(ft(e,"maxScalarBytes"),e<1))throw new r("invalid signature: maxScalarBytes must be positive");let i=Q(t,void 0,"signature"),{v:s,l:a}=o.decode(48,i);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:f}=o.decode(2,s),{v:u,l}=o.decode(2,f);if(l.length)throw new r("invalid signature: left bytes after parsing");if(e!==void 0&&(c.length>e||u.length>e))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=lt;Be(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),i=n+o;return e.encode(48,i)}},Zo=(Object.freeze(lt._tlv),Object.freeze(lt._int),Object.freeze(lt));var Bf=(t,e)=>(t+(t>=0?e:-e)/Cf)/e;function rm(t,e,r){br("scalar",t,dt,r);let[[n,o],[i,s]]=e,a=Bf(s*t,r),c=Bf(-o*t,r),f=t-a*n-c*i,u=-a*o-c*s,l=f<dt,h=u<dt;l&&(f=-f),h&&(u=-u);let m=an(Math.ceil(wr(r)/2))+Zt;if(f<dt||f>=m||u<dt||u>=m)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:f,k2neg:h,k2:u}}function Hs(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function qs(t,e){Be(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Ie(r.lowS,"lowS"),Ie(r.prehash,"prehash"),r.format!==void 0&&Hs(r.format),r}var dt=BigInt(0),Zt=BigInt(1),Cf=BigInt(2),zs=BigInt(3),nm=BigInt(4);function _f(t,e={}){let r=Oo("weierstrass",t,e),n=r.Fp,o=r.Fn,i=r.CURVE,{h:s,n:a}=i;Be(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:f,clearCofactor:u,isTorsionFree:l,fromBytes:h,toBytes:m}=e,C=e.randomBytes===void 0?jt:e.randomBytes;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 x=c?{beta:c.beta,basises:c.basises.map(U=>[...U])}:void 0,g=Rf(n,o);function S(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function T(U,p,w){if(p.is0()){if(!f)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:A,y:F}=p.toAffine(),M=n.toBytes(A);if(Ie(w,"isCompressed"),w){S();let K=!n.isOdd(F);return $e(Df(K),M)}else return $e(Uint8Array.of(4),M,n.toBytes(F))}function y(U){Q(U,void 0,"Point");let{publicKey:p,publicKeyUncompressed:w}=g,A=U.length,F=U[0],M=U.subarray(1);if(f&&A===1&&F===0)return{x:n.ZERO,y:n.ZERO};if(A===p&&(F===2||F===3)){let K=n.fromBytes(M);if(!n.isValid(K))throw new Error("bad point: is not on curve, wrong x");let H=b(K),j;try{j=n.sqrt(H)}catch(ue){let ne=ue instanceof Error?": "+ue.message:"";throw new Error("bad point: is not on curve, sqrt error"+ne)}S();let X=n.isOdd(j);return(F&1)===1!==X&&(j=n.neg(j)),{x:K,y:j}}else if(A===w&&F===4){let K=n.BYTES,H=n.fromBytes(M.subarray(0,K)),j=n.fromBytes(M.subarray(K,K*2));if(!E(H,j))throw new Error("bad point: is not on curve");return{x:H,y:j}}else throw new Error(`bad point: got length ${A}, expected compressed=${p} or uncompressed=${w}`)}let R=m===void 0?T:m,_=h===void 0?y:h,$=n.mul(i.b,zs),q=n.is0(i.a)?U=>n.ZERO:U=>n.mul(i.a,U);function b(U){let p=n.sqr(U),w=n.mul(p,U);return n.add(n.add(w,n.mul(U,i.a)),i.b)}function E(U,p){let w=n.sqr(p),A=b(U);return n.eql(w,A)}if(!E(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(i.a,zs),nm),N=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(v,N)))throw new Error("bad curve params: a or b");function L(U,p,w=!1){if(!n.isValid(p)||w&&n.is0(p))throw new Error(`bad point coordinate ${U}`);return typeof p=="object"&&p!==null?n.create(p):p}function z(U){if(!(U instanceof P))throw new Error("Weierstrass Point expected")}function I(U){if(!x||!x.basises)throw new Error("no endo");return rm(U,x.basises,o.ORDER)}function k(U,p,w,A){if(!o.isValid(A))throw new RangeError("invalid scalar: out of range");if(x){let{k1neg:F,k1:M,k2neg:K,k2:H}=I(A),j=new P(n.mul(w.X,x.beta),w.Y,w.Z);U.push(F?w.negate():w,K?j.negate():j),p.push(M,H)}else U.push(w),p.push(A)}let O=new WeakSet;class P{static BASE=new P(i.Gx,i.Gy,n.ONE);static ZERO=new P(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(p,w,A){this.X=L("x",p),this.Y=L("y",w,!0),this.Z=L("z",A),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){let{x:w,y:A}=p||{};if(!p||!n.isValid(w)||!n.isValid(A))throw new Error("invalid affine point");if(p instanceof P)throw new Error("projective point not allowed");return n.is0(w)&&n.is0(A)?P.ZERO:new P(w,A,n.ONE)}static fromBytes(p){let w=P.fromAffine(_(Q(p,void 0,"point")));return w.assertValidity(),w}static fromHex(p){return P.fromBytes(gr(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=6,w=!0){return W.setWindowSize(this,p),w||this.multiply(zs),this}assertValidity(){let p=this;if(p.is0()){if(f&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}if(O.has(p))return;let{x:w,y:A}=p.toAffine();if(!n.isValid(w)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!E(w,A))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");O.add(p)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){z(p);let{X:w,Y:A,Z:F}=this,{X:M,Y:K,Z:H}=p,j=n.eql(n.mul(w,H),n.mul(M,F)),X=n.eql(n.mul(A,H),n.mul(K,F));return j&&X}negate(){return new P(this.X,n.neg(this.Y),this.Z)}double(){let{X:p,Y:w,Z:A}=this,F=n.ZERO,M=n.ZERO,K=n.ZERO,H=n.mul(p,p),j=n.mul(w,w),X=n.mul(A,A),Z=n.mul(p,w);return Z=n.add(Z,Z),K=n.mul(p,A),K=n.add(K,K),F=q(K),M=n.mul($,X),M=n.add(F,M),F=n.sub(j,M),M=n.add(j,M),M=n.mul(F,M),F=n.mul(Z,F),K=n.mul($,K),X=q(X),Z=n.sub(H,X),Z=q(Z),Z=n.add(Z,K),K=n.add(H,H),H=n.add(K,H),H=n.add(H,X),H=n.mul(H,Z),M=n.add(M,H),X=n.mul(w,A),X=n.add(X,X),H=n.mul(X,Z),F=n.sub(F,H),K=n.mul(X,j),K=n.add(K,K),K=n.add(K,K),new P(F,M,K)}add(p){z(p);let{X:w,Y:A,Z:F}=this,{X:M,Y:K,Z:H}=p,j=n.ZERO,X=n.ZERO,Z=n.ZERO,ue=n.mul(w,M),ne=n.mul(A,K),ge=n.mul(F,H),Fe=n.add(w,A),oe=n.add(M,K);Fe=n.mul(Fe,oe),oe=n.add(ue,ne),Fe=n.sub(Fe,oe),oe=n.add(w,F);let fe=n.add(M,H);return oe=n.mul(oe,fe),fe=n.add(ue,ge),oe=n.sub(oe,fe),fe=n.add(A,F),j=n.add(K,H),fe=n.mul(fe,j),j=n.add(ne,ge),fe=n.sub(fe,j),Z=q(oe),j=n.mul($,ge),Z=n.add(j,Z),j=n.sub(ne,Z),Z=n.add(ne,Z),X=n.mul(j,Z),ne=n.add(ue,ue),ne=n.add(ne,ue),ge=q(ge),oe=n.mul($,oe),ne=n.add(ne,ge),ge=n.sub(ue,ge),ge=q(ge),oe=n.add(oe,ge),ue=n.mul(ne,oe),X=n.add(X,ue),ue=n.mul(fe,oe),j=n.mul(Fe,j),j=n.sub(j,ue),ue=n.mul(Fe,ne),Z=n.mul(fe,Z),Z=n.add(Z,ue),new P(j,X,Z)}subtract(p){return z(p),this.add(p.negate())}is0(){return this.equals(P.ZERO)}multiply(p){if(!o.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let{p:w,f:A}=W.mulSecret(this,p,s,Y);return Y([w,A])[0]}multiplyUnsafe(p){let w=this,A=p;if(!o.isValid(A))throw new RangeError("invalid scalar: out of range");if(A===dt||w.is0())return P.ZERO;if(A===Zt)return w;if(W.hasWindowSize(this))return W.mulUnsafe(w,A,Y);let F=[],M=[];return k(F,M,w,A),Fo(P,F,M)}mulAddUnsafe(p,w,A){z(w);let F=[],M=[];return k(F,M,this,p),k(F,M,w,A),Fo(P,F,M)}toAffine(p){let w=this,A=p;if(A!=null&&!n.isValid(A))throw new RangeError('"invertedZ" expected valid field element');let{X:F,Y:M,Z:K}=w;if(n.eql(K,n.ONE))return{x:F,y:M};let H=w.is0();A==null&&(A=H?n.ONE:n.inv(K));let j=n.mul(F,A),X=n.mul(M,A),Z=n.mul(K,A);if(H)return{x:n.ZERO,y:n.ZERO};if(!n.eql(Z,n.ONE))throw new Error("invZ was invalid");return{x:j,y:X}}isTorsionFree(){return s===Zt?!0:l?l(P,this):W.mulUnsafe(this,a).is0()}clearCofactor(){return s===Zt?this:u?u(P,this):this.multiplyUnsafe(s)}isSmallOrder(){return s===Zt?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return Ie(p,"isCompressed"),this.assertValidity(),R(P,this,p)}toHex(p=!0){return nn(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let Y=U=>Uo(P,U),W=new Sr(P,C);return W.bits>=6&&P.BASE.precompute(6),Object.freeze(P.prototype),Object.freeze(P),P}function Df(t){return Uint8Array.of(t?2:3)}function Rf(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function om(t,e={}){kt(t);let{Fn:r}=t,n=e.randomBytes===void 0?jt:e.randomBytes,o=Object.assign(Rf(t.Fp,r),{seed:Math.max(No(r.ORDER),16)});function i(m){try{let C=r.fromBytes(m);return r.isValidNot0(C)}catch{return!1}}function s(m,C){let{publicKey:x,publicKeyUncompressed:g}=o;try{let S=m.length;return C===!0&&S!==x||C===!1&&S!==g?!1:!t.fromBytes(m).is0()}catch{return!1}}function a(m){return m=m===void 0?n(o.seed):m,ko(Q(m,o.seed,"seed"),r.ORDER)}function c(m,C=!0){return t.BASE.multiply(r.fromBytes(m)).toBytes(C)}function f(m){let{secretKey:C,publicKey:x,publicKeyUncompressed:g}=o,S=r._lengths;if(!Lt(m))return;let T=Q(m,void 0,"key").length,y=T===x||T===g,R=T===C||!!S?.includes(T);if(!(y&&R))return y}function u(m,C,x=!0){if(f(m)===!0)throw new Error("first arg must be private key");if(f(C)===!1)throw new Error("second arg must be public key");let g=r.fromBytes(m),S=t.fromBytes(C);if(S.is0())throw new Error("invalid public key: point at infinity");return S.multiply(g).toBytes(x)}let l={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},h=Po(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:h,Point:t,utils:l,lengths:o})}function Lf(t,e,r={}){kt(t);let n=e;So(n),Be(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),i=o.randomBytes===void 0?jt:o.randomBytes,s=o.hmac===void 0?(U,p)=>If(n,U,p):o.hmac,{Fp:a,Fn:c}=t,{ORDER:f,BITS:u}=c,l=No(f),h=ks(i,l),{keygen:m,getPublicKey:C,getSharedSecret:x,utils:g,lengths:S}=om(t,o),T={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},y=f*Cf+Zt<a.ORDER;function R(U){let p=f>>Zt;return U>p}function _(U,p){if(!c.isValidNot0(p))throw new Error(`invalid signature ${U}: out of range 1..Point.Fn.ORDER`);return p}function $(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function q(U,p,w){return $(),(U===w?0:2)|Number(a.isOdd(p))}function b(){if(y)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function E(U,p){Hs(p);let w=S.signature,A=p==="compact"?w:p==="recovered"?w+1:void 0;return Q(U,A)}class v{r;s;recovery;constructor(p,w,A){if(this.r=_("r",p),this.s=_("s",w),A!=null){if(b(),![0,1,2,3].includes(A))throw new Error("invalid recovery id");this.recovery=A}Object.freeze(this)}static fromBytes(p,w=T.format){E(p,w);let A;if(w==="der"){if(p.length>2*c.BYTES+16)throw new Zo.Err("invalid signature: DER signature too long");let{r:H,s:j}=Zo.toSig(Q(p),c.BYTES+1);return new v(H,j)}w==="recovered"&&(A=p[0],w="compact",p=p.subarray(1));let F=S.signature/2,M=p.subarray(0,F),K=p.subarray(F,F*2);return new v(c.fromBytes(M),c.fromBytes(K),A)}static fromHex(p,w){return this.fromBytes(gr(p),w)}assertRecovery(){let{recovery:p}=this;if(p==null)throw new Error("invalid recovery id: must be present");return p}addRecoveryBit(p){return new v(this.r,this.s,p)}recoverPublicKey(p){let{r:w,s:A}=this,F=this.assertRecovery(),M=F===2||F===3?w+f:w;if(!a.isValid(M))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let K=a.toBytes(M),H=t.fromBytes($e(Df((F&1)===0),K)),j=c.inv(M),X=L(Q(p,void 0,"msgHash")),Z=c.create(-X*j),ue=c.create(A*j),ne=t.BASE.mulAddUnsafe(Z,H,ue);if(ne.is0())throw new Error("invalid recovery: point at infinify");return ne.assertValidity(),ne}hasHighS(){return R(this.s)}toBytes(p=T.format){if(Hs(p),p==="der")return gr(Zo.hexFromSig(this));let{r:w,s:A}=this,F=c.toBytes(w),M=c.toBytes(A);return p==="recovered"?(b(),$e(Uint8Array.of(this.assertRecovery()),F,M)):$e(F,M)}toHex(p){return nn(this.toBytes(p))}}Object.freeze(v.prototype),Object.freeze(v);let N=o.bits2int===void 0?function(p){if(p.length>8192)throw new Error("input is too large");let w=ot(p),A=p.length*8-u;return A>0?w>>BigInt(A):w}:o.bits2int,L=o.bits2int_modN===void 0?function(p){return c.create(N(p))}:o.bits2int_modN,z=an(u);function I(U){return br("num < 2^"+u,U,dt,z),c.toBytes(U)}function k(U,p){return Q(U,void 0,"message"),p?Q(n(U),void 0,"prehashed message"):U}function O(U,p,w){let{lowS:A,prehash:F,extraEntropy:M}=qs(w,T);U=k(U,F);let K=L(U),H=c.fromBytes(p);if(!c.isValidNot0(H))throw new Error("invalid private key");let j=[I(H),I(K)];if(M!=null&&M!==!1){let ne=M===!0?i(S.secretKey):M;j.push(Q(ne,void 0,"extraEntropy"))}let X=$e(...j),Z=K;function ue(ne){let ge=N(ne);if(!c.isValidNot0(ge))return;let Fe=t.BASE.multiply(ge).toAffine(),oe=c.create(Fe.x);if(oe===dt)return;let fe;if(h!==void 0){let Ir=ot(ko(h(l),f)),zf=c.inv(c.mul(Ir,ge)),Hf=c.mul(Ir,Z),jf=c.mul(Ir,H);fe=c.create(zf*c.create(Hf+jf*oe))}else{let Ir=of(ge,f);fe=c.create(Ir*c.create(Z+oe*H))}if(fe===dt)return;let oi=q(Fe.x,Fe.y,oe),Js=fe;return A&&R(fe)&&(Js=c.neg(fe),oi^=1),new v(oe,Js,y?void 0:oi)}return{seed:X,k2sig:ue}}function P(U,p,w={}){let{seed:A,k2sig:F}=O(U,p,w);return Xu(n.outputLen,c.BYTES,s)(A,F).toBytes(w.format)}function Y(U,p,w,A={}){let{lowS:F,prehash:M,format:K}=qs(A,T);if(w=Q(w,void 0,"publicKey"),p=k(p,M),!Lt(U)){let H=U instanceof v?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+H)}E(U,K);try{let H=v.fromBytes(U,K),j=t.fromBytes(w);if(j.is0()||F&&H.hasHighS())return!1;let{r:X,s:Z}=H,ue=L(p),ne=c.inv(Z),ge=c.create(ue*ne),Fe=c.create(X*ne),oe=t.BASE.mulAddUnsafe(ge,j,Fe);if(oe.is0())return!1;let fe=oe.toAffine();return!(c.create(fe.x)!==X||K==="recovered"&&H.recovery!==q(fe.x,fe.y,X))}catch{return!1}}function W(U,p,w={}){let{prehash:A}=qs(w,T);return p=k(p,A),v.fromBytes(U,"recovered").recoverPublicKey(p).toBytes()}return Object.freeze({keygen:m,getPublicKey:C,getSharedSecret:x,utils:g,lengths:S,Point:t,sign:P,verify:Y,recoverPublicKey:W,Signature:v,hash:n})}var Ys={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},im={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Nf=BigInt(2);function sm(t){let e=Ys.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=t*t*t%e,u=f*f*t%e,l=ie(u,r,e)*u%e,h=ie(l,r,e)*u%e,m=ie(h,Nf,e)*f%e,C=ie(m,o,e)*m%e,x=ie(C,i,e)*C%e,g=ie(x,a,e)*x%e,S=ie(g,c,e)*g%e,T=ie(S,a,e)*x%e,y=ie(T,r,e)*u%e,R=ie(y,s,e)*C%e,_=ie(R,n,e)*f%e,$=ie(_,Nf,e);if(!js.eql(js.sqr($),t))throw new Error("Cannot find square root");return $}var js=Er(Ys.p,{sqrt:sm}),am=_f(Ys,{Fp:js,endo:im}),vr=Lf(am,ju);function kf(t,e,r,n){let o=Nr.digest(r instanceof Uint8Array?r:r.subarray());if(Ho(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),vr.verify(e,i,t,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new fn(String(i))});try{return n?.signal?.throwIfAborted(),vr.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(i){throw new fn(String(i))}}var Go=class{type="secp256k1";raw;_key;constructor(e){this._key=Ff(e),this.raw=Uf(this._key)}toMultihash(){return He.digest(mr(this))}toCID(){return se.createV1(114,this.toMultihash())}toString(){return re.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:be(this.raw,e.raw)}verify(e,r,n){return kf(this._key,r,e,n)}};function Of(t){return new Go(t)}function Uf(t){return vr.Point.fromBytes(t).toBytes()}function Ff(t){try{return vr.Point.fromBytes(t),t}catch(e){throw new Qn(String(e))}}function Pf(t){let{Type:e,Data:r}=ln.decode(t.digest),n=r??new Uint8Array;switch(e){case Se.Ed25519:return Tf(n);case Se.secp256k1:return Of(n);case Se.ECDSA:return Tu(n);default:throw new Hr}}function mr(t){return ln.encode({Type:Se[t.type],Data:t.raw})}var Mf=Symbol.for("nodejs.util.inspect.custom"),cm=114,dn=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[es]=!0;toString(){return this.string==null&&(this.string=re.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return se.createV1(cm,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return be(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return be(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Mf](){return`PeerId(${this.toString()})`}},Xo=class extends dn{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Wo=class extends dn{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Qo=class extends dn{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},um=2336,Jo=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=He.digest(le(this.url))}[Mf](){return`PeerId(${this.url})`}[es]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return se.createV1(um,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ee(e)),e.toString()===this.toString())}};function Kf(t){if(lm(t))return new Xo({multihash:t});if(fm(t))try{let e=Pf(t);if(e.type==="Ed25519")return new Wo({multihash:t,publicKey:e});if(e.type==="secp256k1")return new Qo({multihash:t,publicKey:e})}catch{let r=ee(t.digest);return new Jo(new URL(r))}throw new Jn("Supplied PeerID Multihash is invalid")}function fm(t){return t.code===He.code}function lm(t){return t.code===Nr.code}function Zs(t,e){let r={[Symbol.iterator]:()=>r,next:()=>{let n=t.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:e(o)}}};return r}function ei(t){let e=mt(re.decode(`z${t}`));return Kf(e)}var hn=class t{set;constructor(e){if(this.set=new Set,e!=null)for(let r of e)this.set.add(r.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(e){this.set.add(e.toString())}clear(){this.set.clear()}delete(e){this.set.delete(e.toString())}entries(){return Zs(this.set.entries(),e=>{let r=ei(e[0]);return[r,r]})}forEach(e){this.set.forEach(r=>{let n=ei(r);e(n,n,this)})}has(e){return this.set.has(e.toString())}values(){return Zs(this.set.values(),e=>ei(e))}intersection(e){let r=new t;for(let n of e)this.has(n)&&r.add(n);return r}difference(e){let r=new t;for(let n of this)e.has(n)||r.add(n);return r}union(e){let r=new t;for(let n of e)r.add(n);for(let n of this)r.add(n);return r}};var Vf;(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"})(Vf||(Vf={}));var pn;(function(t){let e;t.codec=()=>(e==null&&(e=We((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=a==null?i.len:i.pos+a;for(s!=="."&&(yield{field:s.endsWith(".")?s.substring(0,s.length-1):s,type:"start",message:"IPNSPublishMetadata"});i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{yield{field:`${s}keyName`,value:i.string()};break}case 2:{yield{field:`${s}lifetime`,value:i.uint32()};break}default:{i.skipType(u&7);break}}}s!=="."&&(yield{field:s.endsWith(".")?s.substring(0,s.length-1):s,type:"end",message:"IPNSPublishMetadata"})})),e);function r(i){return Ge(i,t.codec())}t.encode=r;function n(i,s){return Ze(i,t.codec(),s)}t.decode=n;function o(i,s){return Xe(i,t.codec(),s)}t.stream=o})(pn||(pn={}));function Ar(t,e){return{async put(r,n,o={}){try{let i=jr(r);try{let c=await t.get(i),f=It.deserialize(c);if(be(f.value,n))return}catch(c){if(c.name!=="NotFoundError")throw c}let s=new It(r,n,new Date);o.onProgress?.(new me("ipns:routing:datastore:put"));let a=t.batch();a.put(i,s.serialize()),o.metadata!=null&&a.put(oo(r),pn.encode(o.metadata)),await a.commit(o)}catch(i){throw o.onProgress?.(new me("ipns:routing:datastore:error",i)),i}},async get(r,n={}){try{let o=jr(r);n.onProgress?.(new me("ipns:routing:datastore:get"));let i=await t.get(o,n),s=It.deserialize(i);return{record:Ae(s.value),created:s.timeReceived}}catch(o){throw n.onProgress?.(new me("ipns:routing:datastore:error",o)),o}},async has(r,n={}){let o=jr(r);return t.has(o,n)},async delete(r,n){let o=jr(r),i=t.batch();i.delete(o),i.delete(oo(r)),await i.commit(n)},async*list(r={}){try{r.onProgress?.(new me("ipns:routing:datastore:list"));for await(let{key:n,value:o}of t.query({prefix:no},r))try{let i=It.deserialize(o),a=n.toString().substring(no.length),c=le(a,"base32"),f=oo(c),u;try{let l=await t.get(f,r);u=pn.decode(l)}catch(l){e.error("Error deserializing metadata for %s - %e",a,l)}yield{routingKey:c,metadata:u,record:i.value,created:i.timeReceived}}catch(i){e.error("Error deserializing record - %e",i)}}catch(n){throw r.onProgress?.(new me("ipns:routing:datastore:error",n)),n}}}}var Gs=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 me("ipns:routing:helia:error",o)),o}}async get(e,r={}){try{return await this.routing.get(e,r)}catch(n){throw r.onProgress?.(new me("ipns:routing:helia:error",n)),n}}toString(){return"HeliaRouting()"}};function Tr(t){return new Gs(t)}var Xs=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 ti(t){return new Xs(t)}var ri=class{routers;publisher;republisher;resolver;localStore;components;started;constructor(e,r={}){this.localStore=Ar(e.datastore,e.logger.forComponent("helia:ipns:local-store")),this.components=e,this.started=!1,this.routers=[ti(this.localStore),Tr(e.routing),...r.routers??[]],this.publisher=new fo(e,{...r,routers:this.routers,localStore:this.localStore}),this.republisher=new bo(e,{...r,routers:this.routers,localStore:this.localStore}),this.resolver=new ur(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(dm(n))for(let o of Object.values(n.services))hm(o)&&(o.selectors.ipns=async(i,s)=>{let a=s.map(c=>te.decode(c));return Tt(i,a)},o.validators.ipns=async(i,s)=>{await rt(i,s,this.components.keychain)})}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,ao(r),n)}async*resolve(e,r={}){let{digest:n}=Yr(e);yield*this.resolver.resolve(n,r)}async unpublish(e,r){return this.publisher.unpublish(e,r)}};function dm(t){return t?.services!=null}function hm(t){return t?.validators!=null&&t?.selectors!=null}var de=Zr("helia:ipns:routing:pubsub"),Qs=class{subscriptions;localStore;libp2p;fetchConcurrency;fetchTimeout;fetchDelay;fetchQueue;fetchPeers;shutdownController;fetchTopologyId;keychain;constructor(e,r={}){if(this.subscriptions=new Set,this.shutdownController=new AbortController,this.shutdownController.signal,this.fetchPeers=new hn,this.localStore=Ar(e.datastore,e.logger.forComponent("helia:ipns:local-store")),this.libp2p=e.libp2p,this.fetchConcurrency=r.fetchConcurrency??8,this.fetchDelay=r.fetchDelay??0,this.keychain=e.keychain,this.fetchTimeout=r.fetchTimeout??2500,this.fetchQueue=new hr({concurrency:this.fetchConcurrency,metrics:e.metrics,metricName:"helia_ipns_pubsub_fetch_queue"}),this.libp2p.services.pubsub.addEventListener("message",n=>{let o=n.detail;this.subscriptions.has(o.topic)&&this.#e(o,{signal:this.shutdownController.signal}).catch(i=>{de.error("Error processing message - %e",i)})}),this.libp2p.services.fetch!=null)try{this.libp2p.services.pubsub.addEventListener("subscription-change",n=>{let{peerId:o,subscriptions:i}=n.detail;if(this.fetchPeers.has(o))for(let s of i){if(!this.subscriptions.has(s.topic)||s.subscribe===!1)continue;de("peer %s joined topic %s",o,s.topic);let a=$f(s.topic);this.#t(s.topic,a,o,{signal:this.shutdownController.signal}).catch(c=>{de.error("failed to fetch IPNS record for %m from peer %s - %e",a,o,c)})}}),this.libp2p.services.fetch.registerLookupFunction(ro,async n=>{try{let{record:o}=await this.localStore.get(n,{signal:this.shutdownController.signal});return o}catch(o){if(o.name!=="NotFoundError")throw o}}),de("registered lookup function for IPNS with libp2p/fetch service")}catch(n){de("unable to register lookup function for IPNS with libp2p/fetch service - %e",n)}else de("no libp2p/fetch service found. Skipping registration of lookup function for IPNS.")}async#e(e,r){if(de("message received for topic",e.topic),e.type!=="signed"){de.error("unsigned message received, this module can only work with signed messages");return}if(e.from.equals(this.libp2p.peerId)){de("not storing record from self");return}await this.#r(e.topic,$f(e.topic),e.data,!1,r)}async#t(e,r,n,o){let i=await this.fetchQueue.add(async({signal:s})=>{de("fetching ipns record for %m from peer %s",r,n);let a=Xr([s,AbortSignal.timeout(this.fetchTimeout)]);try{return await this.libp2p.services.fetch?.fetch(n,r,{signal:a})}finally{a.clear()}},o);if(i==null)throw new zr(`Peer ${n} did not have record for routing key ${ee(r,"base64")}`);return de("fetched ipns record for %m from peer %s",r,n),this.#r(e,r,i,!0,o)}async#r(e,r,n,o,i){let s=await rt(r,n,this.keychain,i);if(this.shutdownController.signal.throwIfAborted(),await this.localStore.has(r)){let{record:a}=await this.localStore.get(r,i),c=await rt(r,a,this.keychain,i);if(be(a,n))return de.trace("found identical record for %m",r),a;if(Tt(r,[c,s])===0)return de.trace("found old record for %m",r),a}if(de("found new record for %m",r),await this.localStore.put(r,n,i),o){de("publish value for topic %s",e);try{let a=await this.libp2p.services.pubsub.publish(e,n);de("published record on topic %s to %d recipients",e,a.recipients)}catch(a){de.error("could not publish record on topic %s - %e",a)}}return Ae(n)}async put(e,r,n={}){try{let o=Ws(e);de("publish value for topic %s",o);let i=await this.libp2p.services.pubsub.publish(o,r);n?.signal?.throwIfAborted(),de("published record on topic %s to %d recipients",o,i.recipients),n.onProgress?.(new me("ipns:pubsub:publish",{topic:o,result:i}))}catch(o){throw n.onProgress?.(new me("ipns:pubsub:error",o)),o}}async get(e,r={}){let n=Ws(e);try{this.libp2p.services.pubsub.getTopics().includes(n)||(de("add subscription for topic",n),this.libp2p.services.pubsub.subscribe(n),this.subscriptions.add(n),r.onProgress?.(new me("ipns:pubsub:subscribe",{topic:n})))}catch(s){throw r.onProgress?.(new me("ipns:pubsub:error",s)),s}await mo(gu(this.fetchDelay),this.shutdownController.signal);let o=new AbortController,i=[];for(let s of this.libp2p.services.pubsub.getSubscribers(n)){let a=Xr([r?.signal,o.signal]);i.push(this.#t(n,e,s,{...r,signal:a}).finally(()=>{a.clear()}))}if(i.length>0){let s=await Promise.any(i);if(o.abort(),s!=null)return s}throw new zr("Pubsub routing does not actively query peers")}getSubscriptions(){return[...this.subscriptions]}cancel(e){let r=Yc(e)?e.toMultihash():e,n=ct(r),o=Ws(n);this.subscriptions.has(o)&&(this.libp2p.services.pubsub.unsubscribe(o),this.subscriptions.delete(o))}toString(){return"PubSubRouting()"}async start(){this.shutdownController=new AbortController,this.shutdownController.signal,this.libp2p.services.fetch!=null&&(this.fetchTopologyId=await this.libp2p.register(this.libp2p.services.fetch.protocol,{onConnect:e=>{this.fetchPeers.add(e)},onDisconnect:e=>{this.fetchPeers.delete(e)}},{signal:this.shutdownController.signal}))}stop(){this.fetchQueue.abort(),this.shutdownController.abort(),this.fetchTopologyId!=null&&this.libp2p.unregister(this.fetchTopologyId)}},ni="/record/";function Ws(t){let e=ee(t,"base64url");return`${ni}${e}`}function $f(t){if(t.substring(0,ni.length)!==ni)throw new wn("Topic received is not from a record");let e=t.substring(ni.length);return le(e,"base64url")}function qf(t,e={}){return new Qs(t,e)}function pm(t,e={}){return new ri(t,e)}function mm(t,e={}){let r=Ar(t.datastore,t.logger.forComponent("helia:ipns:local-store")),n=[ti(r),Tr(t.routing),...e.routers??[]];return new ur(t,{routers:n,localStore:r})}return Jf(ym);})();
14
14
  /*! Bundled license information:
15
15
 
16
16
  @noble/curves/utils.js: