@helia/ipns 10.0.6 → 10.0.7

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 Ff=Object.create;var wn=Object.defineProperty;var Uf=Object.getOwnPropertyDescriptor;var Nf=Object.getOwnPropertyNames;var kf=Object.getPrototypeOf,Of=Object.prototype.hasOwnProperty;var Pf=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},Se=(t,e)=>{for(var r in e)wn(t,r,{get:e[r],enumerable:!0})},Ys=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Nf(e))!Of.call(t,o)&&o!==r&&wn(t,o,{get:()=>e[o],enumerable:!(n=Uf(e,o))||n.enumerable});return t};var Go=(t,e,r)=>(r=t!=null?Ff(kf(t)):{},Ys(e||!t||!t.__esModule?wn(r,"default",{value:t,enumerable:!0}):r,t)),Mf=t=>Ys(wn({},"__esModule",{value:!0}),t);var Un=Pf((Dm,_i)=>{var _m=(function(){typeof _i<"u"&&(_i.exports=A);var t=86400,e=3200,r=146097*e/400,n=t*r,o=1e3*n,i=864e13,s=4294967296,a=1e6,c="000000000",u=Math.trunc||function(E){var B=E-E%1;return B==0&&(E<0||E===0&&1/E!=1/0)?-0:B},f=A.prototype,l=(A.fromDate=function(E){return new A(+E)},A.fromInt64BE=O(0,1,2,3,0,4),A.fromInt64LE=O(3,2,1,0,4,0),A.fromString=function(_){var B,U=new A,_=(_+="").replace(/^\s*[+\-]?\d+/,function(b){var b=+b,S=1970+(b-1970)%400;return U.year=b-S,S}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(d,b,S){return b<0&&(S*=-1),B=6e4*(60*+b+ +S),""}).replace(/\.\d+$/,function(d){return U.nano=+(d+c).substr(1,9),""}).split(/\D+/);if(1<_.length?_[1]--:_[1]=0,U.time=B=Date.UTC.apply(Date,_)-(B||0),isNaN(B))throw new TypeError("Invalid Date");return h(U)},A.fromTimeT=function(E){return v(E,0)},f.year=0,f.time=0,f.nano=0,f.addNano=function(E){return this.nano+=+E||0,this},f.getNano=function(){var E=h(this);return(E.time%1e3*a+ +E.nano+1e9)%1e9},f.getTimeT=function(){var B=h(this),E=Math.floor(B.time/1e3),B=B.year;return B&&(E+=B*r*t/e),E},f.getYear=function(){return this.toDate().getUTCFullYear()+this.year},f.toDate=function(){return g(h(this).time)},f.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},f.toString=function(E){var B=this,U=B.toDate(),_={H:function(){return K(U.getUTCHours())},L:function(){return k(U.getUTCMilliseconds(),3)},M:function(){return K(U.getUTCMinutes())},N:function(){return k(B.getNano(),9)},S:function(){return K(U.getUTCSeconds())},Y:function(){var d=B.getYear();return 999999<d?"+"+d:9999<d?"+"+k(d,6):0<=d?k(d,4):-999999<=d?"-"+k(-d,6):d},a:function(){return p[U.getUTCDay()]},b:function(){return y[U.getUTCMonth()]},d:function(){return K(U.getUTCDate())},e:function(){return(function(d){return(9<d?"":" ")+(0|d)})(U.getUTCDate())},m:function(){return K(U.getUTCMonth()+1)}};return(function d(b){return b.replace(/%./g,function(S){var x=S[1],w=T[x],x=_[x];return w?d(w):x?x():S})})(E||l)},f.writeInt64BE=C(0,1,2,3,0,4),f.writeInt64LE=C(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),y=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],p=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],T={"%":"%",F:"%Y-%m-%d",n:`
3
- `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return A;function A(E,B,U){var _=this;if(!(_ instanceof A))return new A(E,B,U);_.time=+E||0,_.nano=+B||0,_.year=+U||0,h(_)}function h(E){var B,U,_,d=E.year,b=E.time,S=E.nano,w=((S<0||a<=S)&&(S-=(U=Math.floor(S/a))*a,b+=U,U=1),d%e);return(b<-i||i<b||w)&&((B=u(b/o))&&(d+=B*e,b-=B*o),(_=g(b)).setUTCFullYear(w+_.getUTCFullYear()),_=(b=+_)+(B=u((d-=w)/e))*o,B&&-i<=_&&_<=i&&(d-=B*e,b=_),U=1),U&&(E.year=d,E.time=b,E.nano=S),E}function g(E){var B=new Date(0);return B.setTime(E),B}function v(d,_){d=+d||0;var U=u((_=(_|0)*s)/n)+u(d/n),_=_%n+d%n,d=u(_/n);return d&&(U+=d,_-=d*n),new A(1e3*_,0,U*e)}function C(E,B,U,_,d,b){return function(w,x){var L=h(this);w=w||new Array(8),N(w,x|=0);var R=Math.floor(L.time/1e3),L=L.year*(r*t/e),I=u(L/s)+u(R/s),L=L%s+R%s,R=Math.floor(L/s);return R&&(I+=R,L-=R*s),S(w,x+d,I),S(w,x+b,L),w};function S(w,x,I){w[x+E]=I>>24&255,w[x+B]=I>>16&255,w[x+U]=I>>8&255,w[x+_]=255&I}}function O(E,B,U,_,d,b){return function(w,x){N(w,x|=0);var I=S(w,x+d);return v(S(w,x+b),I)};function S(w,x){return 16777216*w[x+E]+(w[x+B]<<16|w[x+U]<<8|w[x+_])}}function N(E,B){if(E=E&&E.length,E==null)throw new TypeError("Invalid Buffer");if(E<B+8)throw new RangeError("Out of range")}function K(E){return(9<E?"":"0")+(0|E)}function k(E,B){return(c+(0|E)).substr(-B)}})()});var jp={};Se(jp,{IPNSEntry:()=>Z,createIPNSRecord:()=>ar,heliaIPNSRouting:()=>Ar,ipns:()=>Hp,ipnsResolver:()=>zp,multihashFromIPNSRoutingKey:()=>io,multihashToIPNSRoutingKey:()=>it,pubSubIPNSRouting:()=>Rf});var ei={};Se(ei,{base32:()=>dt,base32hex:()=>Xf,base32hexpad:()=>Qf,base32hexpadupper:()=>Jf,base32hexupper:()=>Wf,base32pad:()=>Zf,base32padupper:()=>Gf,base32upper:()=>Yf,base32z:()=>el});var Zp=new Uint8Array(0);function Gs(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 Ft(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Ft(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Xs(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var Zs=4096;function Ws(t){let e=t.length;if(e<=Zs)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=Zs));return r}function Kf(t){return t?.buffer instanceof ArrayBuffer}function Ft(t){return Kf(t)?t:t.slice()}function Vf(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),u=s.toUpperCase().charCodeAt(0);c!==a&&(n[c]=i),u!==a&&(n[u]=i)}}var f=t.length,l=t.charAt(0),y=Math.log(f)/Math.log(256),p=Math.log(256)/Math.log(f);function T(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var v=0,C=0,O=0,N=g.length;O!==N&&g[O]===0;)O++,v++;for(var K=(N-O)*p+1>>>0,k=new Uint8Array(K);O!==N;){for(var E=g[O],B=0,U=K-1;(E!==0||B<C)&&U!==-1;U--,B++)E+=256*k[U]>>>0,k[U]=E%f>>>0,E=E/f>>>0;if(E!==0)throw new Error("Non-zero carry");C=B,O++}for(var _=K-C;_!==K&&k[_]===0;)_++;for(var d=l.repeat(v);_<K;++_)d+=t.charAt(k[_]);return d}function A(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var v=0;if(g[v]!==" "){for(var C=0,O=0;g[v]===l;)C++,v++;for(var N=(g.length-v)*y+1>>>0,K=new Uint8Array(N);g[v];){var k=n[g.charCodeAt(v)];if(k===255)return;for(var E=0,B=N-1;(k!==0||E<O)&&B!==-1;B--,E++)k+=f*K[B]>>>0,K[B]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");O=E,v++}if(g[v]!==" "){for(var U=N-O;U!==N&&K[U]===0;)U++;for(var _=new Uint8Array(C+(N-U)),d=C;U!==N;)_[d++]=K[U++];return _}}}function h(g){var v=A(g);if(v)return v;throw new Error(`Non-${e} character`)}return{encode:T,decodeUnsafe:A,decode:h}}var $f=Vf,qf=$f,Js=qf;var Xo=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")}},Wo=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 ea(this,e)}},Qo=class{decoders;constructor(e){this.decoders=e}or(e){return ea(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 ea(t,e){return new Qo({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Jo=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 Xo(e,r,n),this.decoder=new Wo(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function jt({name:t,prefix:e,encode:r,decode:n}){return new Jo(t,e,r,n)}function lt({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:i}=Js(r,t,n);return jt({prefix:e,name:t,encode:o,decode:s=>Le(i(s))})}function Hf(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function zf(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 jf(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 J({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let i=jf(n,o);return jt({prefix:e,name:t,encode(s){return zf(s,n,r)},decode(s){return Hf(s,i,r,t)}})}var dt=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Yf=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Zf=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Gf=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Xf=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Wf=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Qf=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Jf=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),el=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ti={};Se(ti,{base36:()=>we,base36upper:()=>tl});var we=lt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),tl=lt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var ri={};Se(ri,{base58btc:()=>G,base58flickr:()=>rl});var G=lt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),rl=lt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var nl=na,ta=128,ol=127,il=~ol,sl=Math.pow(2,31);function na(t,e,r){e=e||[],r=r||0;for(var n=r;t>=sl;)e[r++]=t&255|ta,t/=128;for(;t&il;)e[r++]=t&255|ta,t>>>=7;return e[r]=t|0,na.bytes=r-n+1,e}var al=ni,cl=128,ra=127;function ni(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw ni.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&ra)<<o:(s&ra)*Math.pow(2,o),o+=7}while(s>=cl);return ni.bytes=i-n,r}var ul=Math.pow(2,7),fl=Math.pow(2,14),ll=Math.pow(2,21),dl=Math.pow(2,28),hl=Math.pow(2,35),pl=Math.pow(2,42),ml=Math.pow(2,49),yl=Math.pow(2,56),gl=Math.pow(2,63),bl=function(t){return t<ul?1:t<fl?2:t<ll?3:t<dl?4:t<hl?5:t<pl?6:t<ml?7:t<yl?8:t<gl?9:10},wl={encode:nl,decode:al,encodingLength:bl},xl=wl,Ir=xl;function Br(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 Yt(t,e,r=0){return Ir.encode(t,e,r),e}function Zt(t){return Ir.encodingLength(t)}function Xt(t,e){let r=e.byteLength,n=Zt(t),o=n+Zt(r),i=new Uint8Array(o+r);return Yt(t,i,0),Yt(r,i,n),i.set(e,o),new Gt(t,r,e,i)}function ht(t){let e=Le(t),[r,n]=Br(e),[o,i]=Br(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Gt(r,o,s,e)}function oa(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Gs(t.bytes,r.bytes)}}var Gt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=Ft(n),this.bytes=Ft(o)}};function ia(t,e){let{bytes:r,version:n}=t;return n===0?Sl(r,oi(t),e??G.encoder):vl(r,oi(t),e??dt.encoder)}var sa=new WeakMap;function oi(t){let e=sa.get(t);if(e==null){let r=new Map;return sa.set(t,r),r}return e}var Q=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=Ft(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!==Cr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Al)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=Xt(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&&oa(e.multihash,n.multihash)}toString(e){return ia(this,e)}toJSON(){return{"/":ia(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??aa(n,o,i.bytes))}else if(r[Tl]===!0){let{version:n,multihash:o,code:i}=r,s=ht(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!==Cr)throw new Error(`Version 0 CID must use dag-pb (code: ${Cr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=aa(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Cr,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 Gt(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,y]=Br(e.subarray(r));return r+=y,l},o=n(),i=Cr;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),u=r+c,f=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=El(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 oi(i).set(n,e),i}};function El(t,e){switch(t[0]){case"Q":{let r=e??G;return[G.prefix,r.decode(`${G.prefix}${t}`)]}case G.prefix:{let r=e??G;return[G.prefix,r.decode(t)]}case dt.prefix:{let r=e??dt;return[dt.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 Sl(t,e,r){let{prefix:n}=r;if(n!==G.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 vl(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 Cr=112,Al=18;function aa(t,e,r){let n=Zt(t),o=n+Zt(e),i=new Uint8Array(o+r.byteLength);return Yt(t,i,0),Yt(e,i,n),i.set(r,o),i}var Tl=Symbol.for("@ipld/js-cid/CID");var En=BigInt(6e4)*5000000n,ca=5;var Sn=class extends Error{static name="RecordsFailedValidationError";name="RecordsFailedValidationError"},mt=class extends Error{static name="InvalidValueError";name="InvalidValueError"},vn=class extends Error{static name="InvalidTopicError";name="InvalidTopicError"},_r=class extends Error{static name="RecordNotFoundError";name="RecordNotFoundError"},An=class extends Error{static name="SignatureCreationError";name="SignatureCreationError"},ke=class extends Error{static name="SignatureVerificationError";name="SignatureVerificationError"},Tn=class extends Error{static name="RecordExpiredError";name="RecordExpiredError"},Wt=class extends Error{static name="UnsupportedValidityError";name="UnsupportedValidityError"},In=class extends Error{static name="RecordTooLargeError";name="RecordTooLargeError"},Bn=class extends Error{static name="InvalidRecordDataError";name="InvalidRecordDataError"},Cn=class extends Error{static name="InvalidEmbeddedPublicKeyError";name="InvalidEmbeddedPublicKeyError"};function Re(t=0){return new Uint8Array(t)}function ve(t=0){return new Uint8Array(t)}var Il=Math.pow(2,7),Bl=Math.pow(2,14),Cl=Math.pow(2,21),ua=Math.pow(2,28),fa=Math.pow(2,35),la=Math.pow(2,42),da=Math.pow(2,49),ye=128,yt=127;function Dr(t){if(t<Il)return 1;if(t<Bl)return 2;if(t<Cl)return 3;if(t<ua)return 4;if(t<fa)return 5;if(t<la)return 6;if(t<da)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ha(t,e,r=0){switch(Dr(t)){case 8:e[r++]=t&255|ye,t/=128;case 7:e[r++]=t&255|ye,t/=128;case 6:e[r++]=t&255|ye,t/=128;case 5:e[r++]=t&255|ye,t/=128;case 4:e[r++]=t&255|ye,t>>>=7;case 3:e[r++]=t&255|ye,t>>>=7;case 2:e[r++]=t&255|ye,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function pa(t,e){let r=t[e],n=0;if(n+=r&yt,r<ye||(r=t[e+1],n+=(r&yt)<<7,r<ye)||(r=t[e+2],n+=(r&yt)<<14,r<ye)||(r=t[e+3],n+=(r&yt)<<21,r<ye)||(r=t[e+4],n+=(r&yt)*ua,r<ye)||(r=t[e+5],n+=(r&yt)*fa,r<ye)||(r=t[e+6],n+=(r&yt)*la,r<ye)||(r=t[e+7],n+=(r&yt)*da,r<ye))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 ii=new Float32Array([-0]),gt=new Uint8Array(ii.buffer);function ma(t,e,r){ii[0]=t,e[r]=gt[0],e[r+1]=gt[1],e[r+2]=gt[2],e[r+3]=gt[3]}function ya(t,e){return gt[0]=t[e],gt[1]=t[e+1],gt[2]=t[e+2],gt[3]=t[e+3],ii[0]}var si=new Float64Array([-0]),me=new Uint8Array(si.buffer);function ga(t,e,r){si[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 ba(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],si[0]}var Dl=BigInt(Number.MAX_SAFE_INTEGER),Ll=BigInt(Number.MIN_SAFE_INTEGER),Ae=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<Dl&&e>Ll)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>wa&&(o=0n,++n>wa&&(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 Ae(0,0);Ut.toBigInt=function(){return 0n};Ut.zzEncode=Ut.zzDecode=function(){return this};Ut.length=function(){return 1};var wa=4294967296n;function xa(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 Ea(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 ai(t,e,r){let n=r,o,i;for(let s=0;s<t.length;++s)o=t.charCodeAt(s),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((i=t.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function Oe(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function _n(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var ci=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,Oe(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Oe(this,4);return _n(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Oe(this,4);return _n(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Oe(this,4);let e=ya(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Oe(this,4);let e=ba(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Oe(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Ea(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Oe(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Oe(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Ae(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Oe(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Oe(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Oe(this,8);let e=_n(this.buf,this.pos+=4),r=_n(this.buf,this.pos+=4);return new Ae(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=pa(this.buf,this.pos);return this.pos+=Dr(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 ci(t instanceof Uint8Array?t:t.subarray())}function je(t,e,r){let n=Lr(t);return e.decode(n,void 0,r)}var ui={};Se(ui,{base10:()=>Rl});var Rl=lt({prefix:"9",name:"base10",alphabet:"0123456789"});var fi={};Se(fi,{base16:()=>Fl,base16upper:()=>Ul});var Fl=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Ul=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var li={};Se(li,{base2:()=>Nl});var Nl=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var di={};Se(di,{base256emoji:()=>Kl});var va=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}"),kl=va.reduce((t,e,r)=>(t[r]=e,t),[]),Ol=va.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Pl(t){return t.reduce((e,r)=>(e+=kl[r],e),"")}function Ml(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ol[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Kl=jt({prefix:"\u{1F680}",name:"base256emoji",encode:Pl,decode:Ml});var pi={};Se(pi,{base64:()=>hi,base64pad:()=>Vl,base64url:()=>$l,base64urlpad:()=>ql});var hi=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Vl=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),$l=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ql=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var mi={};Se(mi,{base8:()=>Hl});var Hl=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var yi={};Se(yi,{identity:()=>zl});var zl=jt({prefix:"\0",name:"identity",encode:t=>Ws(Le(t)),decode:t=>Le(Xs(t))});var U0=new TextEncoder,N0=new TextDecoder;var gi={};Se(gi,{identity:()=>Pe});var Aa=0,Zl="identity",Ta=Le;function Gl(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 Xt(Aa,Ta(t))}var Pe={code:Aa,name:Zl,encode:Ta,digest:Gl};var xi={};Se(xi,{sha256:()=>Rr,sha512:()=>Wl});var Xl=20;function wi({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new bi(t,e,r,n,o)}var bi=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Xl,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?Ia(n,this.code,r?.truncate):n.then(o=>Ia(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ia(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 Xt(e,t)}function Ca(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Rr=wi({name:"sha2-256",code:18,encode:Ca("SHA-256")}),Wl=wi({name:"sha2-512",code:19,encode:Ca("SHA-512")});var Ei={...yi,...li,...mi,...ui,...fi,...ei,...ti,...ri,...pi,...di},Z0={...xi,...gi};function Da(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var _a=Da("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Si=Da("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=ve(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Ql={utf8:_a,"utf-8":_a,hex:Ei.base16,latin1:Si,ascii:Si,binary:Si,...Ei},Dn=Ql;function re(t,e="utf8"){let r=Dn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function vi(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return ve(s);o+s>e&&(n=ve(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Nt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Ai(){}var Ii=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Jl=vi();function ed(t){return globalThis.Buffer!=null?ve(t):Jl(t)}var Ur=class{len;head;tail;states;constructor(){this.len=0,this.head=new Nt(Ai,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Nt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Bi((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(Ln,10,Ae.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Ae.fromBigInt(e);return this._push(Ln,r.length(),r)}uint64Number(e){return this._push(ha,Dr(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=Ae.fromBigInt(e).zzEncode();return this._push(Ln,r.length(),r)}sint64Number(e){let r=Ae.fromNumber(e).zzEncode();return this._push(Ln,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ti,1,e?1:0)}fixed32(e){return this._push(Fr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Ae.fromBigInt(e);return this._push(Fr,4,r.lo)._push(Fr,4,r.hi)}fixed64Number(e){let r=Ae.fromNumber(e);return this._push(Fr,4,r.lo)._push(Fr,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(ma,4,e)}double(e){return this._push(ga,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Ti,1,0):this.uint32(r)._push(rd,r,e)}string(e){let r=xa(e);return r!==0?this.uint32(r)._push(ai,r,e):this._push(Ti,1,0)}fork(){return this.states=new Ii(this),this.head=this.tail=new Nt(Ai,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 Nt(Ai,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=ed(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Ti(t,e,r){e[r]=t&255}function td(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Bi=class extends Nt{next;constructor(e,r){super(td,e,r),this.next=void 0}};function Ln(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 Fr(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 rd(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(nd,e,t),this},Ur.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(od,e,t),this});function nd(t,e,r){e.set(t,r)}function od(t,e,r){t.length<40?ai(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(re(t),r)}function Ci(){return new Ur}function Ye(t,e){let r=Ci();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Ze(t,e,r){let n=Lr(t);yield*e.stream(n,void 0,"$",r)}var Rn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Fn(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Nr(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 Fn("enum",Rn.VARINT,r,n,o)}function Ge(t,e,r){return Fn("message",Rn.LENGTH_DELIMITED,t,e,r)}var Z;(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=()=>Nr(r)})(e=t.ValidityType||(t.ValidityType={}));let n;t.codec=()=>(n==null&&(n=Ge((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.value!=null&&(c.uint32(10),c.bytes(a.value)),a.signatureV1!=null&&(c.uint32(18),c.bytes(a.signatureV1)),a.validityType!=null&&(c.uint32(24),t.ValidityType.codec().encode(a.validityType,c)),a.validity!=null&&(c.uint32(34),c.bytes(a.validity)),a.sequence!=null&&(c.uint32(40),c.uint64(a.sequence)),a.ttl!=null&&(c.uint32(48),c.uint64(a.ttl)),a.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)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let y=a.uint32();switch(y>>>3){case 1:{f.value=a.bytes();break}case 2:{f.signatureV1=a.bytes();break}case 3:{f.validityType=t.ValidityType.codec().decode(a);break}case 4:{f.validity=a.bytes();break}case 5:{f.sequence=a.uint64();break}case 6:{f.ttl=a.uint64();break}case 7:{f.publicKey=a.bytes();break}case 8:{f.signatureV2=a.bytes();break}case 9:{f.data=a.bytes();break}default:{a.skipType(y&7);break}}}return f},function*(a,c,u,f={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let y=a.uint32();switch(y>>>3){case 1:{yield{field:`${u}.value`,value:a.bytes()};break}case 2:{yield{field:`${u}.signatureV1`,value:a.bytes()};break}case 3:{yield{field:`${u}.validityType`,value:t.ValidityType.codec().decode(a)};break}case 4:{yield{field:`${u}.validity`,value:a.bytes()};break}case 5:{yield{field:`${u}.sequence`,value:a.uint64()};break}case 6:{yield{field:`${u}.ttl`,value:a.uint64()};break}case 7:{yield{field:`${u}.publicKey`,value:a.bytes()};break}case 8:{yield{field:`${u}.signatureV2`,value:a.bytes()};break}case 9:{yield{field:`${u}.data`,value:a.bytes()};break}default:{a.skipType(y&7);break}}}})),n);function o(a){return Ye(a,t.codec())}t.encode=o;function i(a,c){return je(a,t.codec(),c)}t.decode=i;function s(a,c){return Ze(a,t.codec(),c)}t.stream=s})(Z||(Z={}));var ji=Go(Un(),1);function Y(t,e="utf8"){let r=Dn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}function id(t){return t?.buffer instanceof ArrayBuffer}function La(t){if(id(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function bt(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=ve(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return La(r)}function fe(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 Fa=Symbol.for("@achingbrain/uint8arraylist");function Ra(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 Nn(t){return!!t?.[Fa]}var Te=class t{bufs;length;[Fa]=!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(Nn(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(Nn(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=Ra(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Ra(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(Nn(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 bt(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:bt(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),i=new t;return i.length=o,i.bufs=n,i}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(s);break}let l=e-a;n.push(s.subarray(l,l+(r-e)));break}if(u){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(f){if(r===c){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Nn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let y=u;y>=0;y--){let p=this.get(l+y);if(n[y]!==p){f=Math.max(1,y-a[p]);break}}if(f===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=ve(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=Re(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=Re(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=Re(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=ve(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=Re(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=Re(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=Re(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=Re(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=Re(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(!fe(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 kn(t){return t==null?!1:typeof t.type=="string"&&typeof t.code=="number"&&typeof t.verify=="function"}var sd=["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 Di(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=ad(t);return r||"Object"}function ad(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(sd.includes(e))return e}var m=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}};m.uint=new m(0,"uint",!0);m.negint=new m(1,"negint",!0);m.bytes=new m(2,"bytes",!0);m.string=new m(3,"string",!0);m.array=new m(4,"array",!1);m.map=new m(5,"map",!1);m.tag=new m(6,"tag",!1);m.float=new m(7,"float",!0);m.false=new m(7,"false",!0);m.true=new m(7,"true",!0);m.null=new m(7,"null",!0);m.undefined=new m(7,"undefined",!0);m.break=new m(7,"break",!0);var F=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 kr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",cd=new TextEncoder;function On(t){return kr&&globalThis.Buffer.isBuffer(t)}function Or(t){return t instanceof Uint8Array?On(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var ud=24,fd=200,Pn=kr?t=>t.length>=ud?globalThis.Buffer.from(t):Ua(t):t=>t.length>=fd?cd.encode(t):Ua(t),Xe=t=>Uint8Array.from(t),Na=kr?(t,e,r)=>On(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),ka=kr?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Or(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},Oa=kr?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function Mn(t,e){if(On(t)&&On(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 Ua(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 ld=256,Pr=class{constructor(e=ld){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=Oa(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=Na(n,0,this.cursor)}else r=ka(this.chunks,this.cursor);return e&&this.reset(),r}},Kn=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var M="CBOR decode error:",Vn="CBOR encode error:",Mr=[];Mr[23]=1;Mr[24]=2;Mr[25]=3;Mr[26]=5;Mr[27]=9;function tt(t,e,r){if(t.length-e<r)throw new Error(`${M} not enough data for type`)}var le=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Ie(t,e,r){tt(t,e,1);let n=t[e];if(r.strict===!0&&n<le[0])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);return n}function Be(t,e,r){tt(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<le[1])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);return n}function Ce(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<le[2])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);return n}function _e(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<le[3])throw new Error(`${M} 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(`${M} integers outside of the safe integer range are not supported`)}function Pa(t,e,r,n){return new F(m.uint,Ie(t,e+1,n),2)}function Ma(t,e,r,n){return new F(m.uint,Be(t,e+1,n),3)}function Ka(t,e,r,n){return new F(m.uint,Ce(t,e+1,n),5)}function Va(t,e,r,n){return new F(m.uint,_e(t,e+1,n),9)}function Fe(t,e){return X(t,0,e.value)}function X(t,e,r){if(r<le[0]){let n=Number(r);t.push([e|n])}else if(r<le[1]){let n=Number(r);t.push([e|24,n])}else if(r<le[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<le[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<le[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(`${M} encountered BigInt larger than allowable range`)}}Fe.encodedSize=function(e){return X.encodedSize(e.value)};X.encodedSize=function(e){return e<le[0]?1:e<le[1]?2:e<le[2]?3:e<le[3]?5:9};Fe.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function $a(t,e,r,n){return new F(m.negint,-1-Ie(t,e+1,n),2)}function qa(t,e,r,n){return new F(m.negint,-1-Be(t,e+1,n),3)}function Ha(t,e,r,n){return new F(m.negint,-1-Ce(t,e+1,n),5)}var Li=BigInt(-1),za=BigInt(1);function ja(t,e,r,n){let o=_e(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new F(m.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${M} integers outside of the safe integer range are not supported`);return new F(m.negint,Li-BigInt(o),9)}function $n(t,e){let r=e.value,n=typeof r=="bigint"?r*Li-za:r*-1-1;X(t,e.type.majorEncoded,n)}$n.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Li-za:r*-1-1;return n<le[0]?1:n<le[1]?2:n<le[2]?3:n<le[3]?5:9};$n.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Kr(t,e,r,n){tt(t,e,r+n);let o=t.slice(e+r,e+r+n);return new F(m.bytes,o,r+n)}function Ya(t,e,r,n){return Kr(t,e,1,r)}function Za(t,e,r,n){return Kr(t,e,2,Ie(t,e+1,n))}function Ga(t,e,r,n){return Kr(t,e,3,Be(t,e+1,n))}function Xa(t,e,r,n){return Kr(t,e,5,Ce(t,e+1,n))}function Wa(t,e,r,n){let o=_e(t,e+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer bytes lengths not supported`);return Kr(t,e,9,o)}function qn(t){return t.encodedBytes===void 0&&(t.encodedBytes=m.equals(t.type,m.string)?Pn(t.value):t.value),t.encodedBytes}function Qt(t,e){let r=qn(e);X(t,e.type.majorEncoded,r.length),t.push(r)}Qt.encodedSize=function(e){let r=qn(e);return X.encodedSize(r.length)+r.length};Qt.compareTokens=function(e,r){return hd(qn(e),qn(r))};function hd(t,e){return t.length<e.length?-1:t.length>e.length?1:Mn(t,e)}var Qa=new TextDecoder,md=32;function yd(t,e,r){if(r-e<md){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return Qa.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return Qa.decode(t.subarray(e,r))}function Vr(t,e,r,n,o){let i=r+n;tt(t,e,i);let s=new F(m.string,yd(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function Ja(t,e,r,n){return Vr(t,e,1,r,n)}function ec(t,e,r,n){return Vr(t,e,2,Ie(t,e+1,n),n)}function tc(t,e,r,n){return Vr(t,e,3,Be(t,e+1,n),n)}function rc(t,e,r,n){return Vr(t,e,5,Ce(t,e+1,n),n)}function nc(t,e,r,n){let o=_e(t,e+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer string lengths not supported`);return Vr(t,e,9,o,n)}var oc=Qt;function Jt(t,e,r,n){return new F(m.array,n,r)}function ic(t,e,r,n){return Jt(t,e,1,r)}function sc(t,e,r,n){return Jt(t,e,2,Ie(t,e+1,n))}function ac(t,e,r,n){return Jt(t,e,3,Be(t,e+1,n))}function cc(t,e,r,n){return Jt(t,e,5,Ce(t,e+1,n))}function uc(t,e,r,n){let o=_e(t,e+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer array lengths not supported`);return Jt(t,e,9,o)}function fc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${M} indefinite length items not allowed`);return Jt(t,e,1,1/0)}function Hn(t,e){X(t,m.array.majorEncoded,e.value)}Hn.compareTokens=Fe.compareTokens;Hn.encodedSize=function(e){return X.encodedSize(e.value)};function er(t,e,r,n){return new F(m.map,n,r)}function lc(t,e,r,n){return er(t,e,1,r)}function dc(t,e,r,n){return er(t,e,2,Ie(t,e+1,n))}function hc(t,e,r,n){return er(t,e,3,Be(t,e+1,n))}function pc(t,e,r,n){return er(t,e,5,Ce(t,e+1,n))}function mc(t,e,r,n){let o=_e(t,e+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer map lengths not supported`);return er(t,e,9,o)}function yc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${M} indefinite length items not allowed`);return er(t,e,1,1/0)}function zn(t,e){X(t,m.map.majorEncoded,e.value)}zn.compareTokens=Fe.compareTokens;zn.encodedSize=function(e){return X.encodedSize(e.value)};function gc(t,e,r,n){return new F(m.tag,r,1)}function bc(t,e,r,n){return new F(m.tag,Ie(t,e+1,n),2)}function wc(t,e,r,n){return new F(m.tag,Be(t,e+1,n),3)}function xc(t,e,r,n){return new F(m.tag,Ce(t,e+1,n),5)}function Ec(t,e,r,n){return new F(m.tag,_e(t,e+1,n),9)}function jn(t,e){X(t,m.tag.majorEncoded,e.value)}jn.compareTokens=Fe.compareTokens;jn.encodedSize=function(e){return X.encodedSize(e.value)};var Ri=20,Fi=21,Ui=22,Ni=23;function Sc(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${M} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new F(m.null,null,1):new F(m.undefined,void 0,1)}function vc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${M} indefinite length items not allowed`);return new F(m.break,void 0,1)}function ki(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${M} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${M} Infinity values are not supported`)}return new F(m.float,t,e)}function Ac(t,e,r,n){return ki(Oi(t,e+1),3,n)}function Tc(t,e,r,n){return ki(Pi(t,e+1),5,n)}function Ic(t,e,r,n){return ki(Dc(t,e+1),9,n)}function $r(t,e,r){let n=e.value;if(n===!1)t.push([m.float.majorEncoded|Ri]);else if(n===!0)t.push([m.float.majorEncoded|Fi]);else if(n===null)t.push([m.float.majorEncoded|Ui]);else if(n===void 0)t.push([m.float.majorEncoded|Ni]);else{let o,i=!1;(!r||r.float64!==!0)&&(Cc(n),o=Oi(Me,1),n===o||Number.isNaN(n)?(Me[0]=249,t.push(Me.slice(0,3)),i=!0):(_c(n),o=Pi(Me,1),n===o&&(Me[0]=250,t.push(Me.slice(0,5)),i=!0))),i||(Ed(n),o=Dc(Me,1),Me[0]=251,t.push(Me.slice(0,9)))}}$r.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){Cc(n);let o=Oi(Me,1);if(n===o||Number.isNaN(n))return 3;if(_c(n),o=Pi(Me,1),n===o)return 5}return 9};var Bc=new ArrayBuffer(9),Ue=new DataView(Bc,1),Me=new Uint8Array(Bc,0);function Cc(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 Oi(t,e){if(t.length-e<2)throw new Error(`${M} 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 _c(t){Ue.setFloat32(0,t,!1)}function Pi(t,e){if(t.length-e<4)throw new Error(`${M} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Ed(t){Ue.setFloat64(0,t,!1)}function Dc(t,e){if(t.length-e<8)throw new Error(`${M} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}$r.compareTokens=Fe.compareTokens;function z(t,e,r){throw new Error(`${M} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function Yn(t){return()=>{throw new Error(`${M} ${t}`)}}var D=[];for(let t=0;t<=23;t++)D[t]=z;D[24]=Pa;D[25]=Ma;D[26]=Ka;D[27]=Va;D[28]=z;D[29]=z;D[30]=z;D[31]=z;for(let t=32;t<=55;t++)D[t]=z;D[56]=$a;D[57]=qa;D[58]=Ha;D[59]=ja;D[60]=z;D[61]=z;D[62]=z;D[63]=z;for(let t=64;t<=87;t++)D[t]=Ya;D[88]=Za;D[89]=Ga;D[90]=Xa;D[91]=Wa;D[92]=z;D[93]=z;D[94]=z;D[95]=Yn("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)D[t]=Ja;D[120]=ec;D[121]=tc;D[122]=rc;D[123]=nc;D[124]=z;D[125]=z;D[126]=z;D[127]=Yn("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)D[t]=ic;D[152]=sc;D[153]=ac;D[154]=cc;D[155]=uc;D[156]=z;D[157]=z;D[158]=z;D[159]=fc;for(let t=160;t<=183;t++)D[t]=lc;D[184]=dc;D[185]=hc;D[186]=pc;D[187]=mc;D[188]=z;D[189]=z;D[190]=z;D[191]=yc;for(let t=192;t<=215;t++)D[t]=gc;D[216]=bc;D[217]=wc;D[218]=xc;D[219]=Ec;D[220]=z;D[221]=z;D[222]=z;D[223]=z;for(let t=224;t<=243;t++)D[t]=Yn("simple values are not supported");D[244]=z;D[245]=z;D[246]=z;D[247]=Sc;D[248]=Yn("simple values are not supported");D[249]=Ac;D[250]=Tc;D[251]=Ic;D[252]=z;D[253]=z;D[254]=z;D[255]=vc;var Ke=[];for(let t=0;t<24;t++)Ke[t]=new F(m.uint,t,1);for(let t=-1;t>=-24;t--)Ke[31-t]=new F(m.negint,t,1);Ke[64]=new F(m.bytes,new Uint8Array(0),1);Ke[96]=new F(m.string,"",1);Ke[128]=new F(m.array,0,1);Ke[160]=new F(m.map,0,1);Ke[244]=new F(m.false,!1,1);Ke[245]=new F(m.true,!0,1);Ke[246]=new F(m.null,null,1);function Mi(t){switch(t.type){case m.false:return Xe([244]);case m.true:return Xe([245]);case m.null:return Xe([246]);case m.bytes:return t.value.length?void 0:Xe([64]);case m.string:return t.value===""?Xe([96]):void 0;case m.array:return t.value===0?Xe([128]):void 0;case m.map:return t.value===0?Xe([160]):void 0;case m.uint:return t.value<24?Xe([Number(t.value)]):void 0;case m.negint:if(t.value>=-24)return Xe([31-Number(t.value)])}}var vd={float64:!1,mapSorter:Id,quickEncodeToken:Mi},Nc=Object.freeze({mapSorter:Bd,quickEncodeToken:Mi});function Ad(){let t=[];return t[m.uint.major]=Fe,t[m.negint.major]=$n,t[m.bytes.major]=Qt,t[m.string.major]=oc,t[m.array.major]=Hn,t[m.map.major]=zn,t[m.tag.major]=jn,t[m.float.major]=$r,t}var rr=Ad(),Zn=new Pr,Hr=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(`${Vn} object contains circular references`);return new t(r,e)}},wt={null:new F(m.null,null),undefined:new F(m.undefined,void 0),true:new F(m.true,!0),false:new F(m.false,!1),emptyArray:new F(m.array,0),emptyMap:new F(m.map,0)},We={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new F(m.float,t):t>=0?new F(m.uint,t):new F(m.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new F(m.uint,t):new F(m.negint,t)},Uint8Array(t,e,r,n){return new F(m.bytes,t)},string(t,e,r,n){return new F(m.string,t)},boolean(t,e,r,n){return t?wt.true:wt.false},null(t,e,r,n){return wt.null},undefined(t,e,r,n){return wt.undefined},ArrayBuffer(t,e,r,n){return new F(m.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new F(m.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[wt.emptyArray,new F(m.break)]:wt.emptyArray;n=Hr.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=tr(s,r,n);return r.addBreakTokens?[new F(m.array,t.length),o,new F(m.break)]:[new F(m.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=Hr.createCheck(n,t);let c=!o&&r.ignoreUndefinedProperties,u=0;for(let f of i){let l=o?t.get(f):t[f];c&&l===void 0||(a[u++]=[tr(f,r,n),tr(l,r,n)])}u<s&&(a.length=u)}return a?.length?(Td(a,r),r.addBreakTokens?[new F(m.map,a.length),a,new F(m.break)]:[new F(m.map,a.length),a]):r.addBreakTokens===!0?[wt.emptyMap,new F(m.break)]:wt.emptyMap},Tagged(t,e,r,n){return[new F(m.tag,t.tag),tr(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 tr(t,e={},r){let n=Di(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(`${Vn} unsupported type: ${n}`);return i(t,n,e,r)}function Td(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Id(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=rr[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Bd(t,e){if(t[0]instanceof F&&e[0]instanceof F){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=Lc(r.value)),n._keyBytes||(n._keyBytes=Lc(n.value)),Mn(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Lc(t){return Oc(t,rr,Nc)}function qr(t,e,r,n){if(Array.isArray(e))for(let o of e)qr(t,o,r,n);else r[e.type.major](t,e,n)}var Rc=m.uint.majorEncoded,Fc=m.negint.majorEncoded,Cd=m.bytes.majorEncoded,_d=m.string.majorEncoded,Uc=m.array.majorEncoded,Dd=m.float.majorEncoded|Ri,Ld=m.float.majorEncoded|Fi,Rd=m.float.majorEncoded|Ui,Fd=m.float.majorEncoded|Ni,Ud=BigInt(-1),Nd=BigInt(1);function kd(t){return t.addBreakTokens!==!0}function kc(t,e,r,n){let o=Di(e),i=r.typeEncoders&&r.typeEncoders[o];if(i){let s=i(e,o,r,n);if(s!=null){qr(t,s,rr,r);return}}switch(o){case"null":t.push([Rd]);return;case"undefined":t.push([Fd]);return;case"boolean":t.push([e?Ld:Dd]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?$r(t,new F(m.float,e),r):e>=0?X(t,Rc,e):X(t,Fc,e*-1-1);return;case"bigint":e>=BigInt(0)?X(t,Rc,e):X(t,Fc,e*Ud-Nd);return;case"string":{let s=Pn(e);X(t,_d,s.length),t.push(s);return}case"Uint8Array":X(t,Cd,e.length),t.push(e);return;case"Array":if(!e.length){t.push([Uc]);return}n=Hr.createCheck(n,e),X(t,Uc,e.length);for(let s of e)kc(t,s,r,n);return;case"Object":case"Map":{let s=We.Object(e,o,r,n);qr(t,s,rr,r)}return;default:{let s=We[o];if(!s)throw new Error(`${Vn} unsupported type: ${o}`);let a=s(e,o,r,n);qr(t,a,rr,r)}}}function Oc(t,e,r,n){let o=n instanceof Uint8Array,i=o?new Kn(n):Zn,s=tr(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let u=c.encodedSize(s,r);if(o||(i=new Pr(u)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():Or(i.chunks[0])}}return i.reset(),qr(i,s,e,r),i.toBytes(!0)}function Ki(t,e){return e=Object.assign({},vd,e),kd(e)?(Zn.reset(),kc(Zn,t,e,void 0),Zn.toBytes(!0)):Oc(t,rr,e)}var Od={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=Ke[e];if(r===void 0){let n=D[e];if(!n)throw new Error(`${M} 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"),nr=Symbol.for("BREAK");function Pd(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=Et(e,r);if(i===nr){if(t.value===1/0)break;throw new Error(`${M} got unexpected break to lengthed array`)}if(i===xt)throw new Error(`${M} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Md(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===nr){if(t.value===1/0)break;throw new Error(`${M} got unexpected break to lengthed map`)}if(c===xt)throw new Error(`${M} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${M} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${M} found repeat map key "${c}"`);let u=Et(e,r);if(u===xt)throw new Error(`${M} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,u):i[c]=u}return n?s:i}function*Kd(t,e,r){for(let n=0;n<t.value;n++){let o=Et(e,r);if(o===nr){if(t.value===1/0)break;throw new Error(`${M} got unexpected break to lengthed map`)}if(o===xt)throw new Error(`${M} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let i=Et(e,r);if(i===xt)throw new Error(`${M} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,i]}}function Vd(t,e){let r=!1,n=function(){if(r)throw new Error(`${M} tag decode() may only be called once`);r=!0;let o=Et(t,e);if(o===xt)throw new Error(`${M} tag content missing`);if(o===nr)throw new Error(`${M} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${M} tag decode() may only be called once`);r=!0;let o=t.next();if(!m.equals(o.type,m.map))throw new Error(`${M} entries() requires map content, got ${o.type.name}`);let i=[];for(let s of Kd(o,t,e))i.push(s);return i},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function Et(t,e){if(t.done())return xt;let r=t.next();if(m.equals(r.type,m.break))return nr;if(r.type.terminal)return r.value;if(m.equals(r.type,m.array))return Pd(r,t,e);if(m.equals(r.type,m.map))return Md(r,t,e);if(m.equals(r.type,m.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=Vd(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${M} tag decoder must call decode() or entries()`);return o}throw new Error(`${M} tag not supported (${r.value})`)}throw new Error("unsupported")}function Pc(t,e){if(!(t instanceof Uint8Array))throw new Error(`${M} data to decode must be a Uint8Array`);e=Object.assign({},Od,e);let r=Or(t),n=e.tokenizer||new Gn(r,e),o=Et(n,e);if(o===xt)throw new Error(`${M} did not find any content to decode`);if(o===nr)throw new Error(`${M} got unexpected break`);return[o,t.subarray(n.pos())]}function Vi(t,e){let[r,n]=Pc(t,e);if(n.length>0)throw new Error(`${M} 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 Mc=42;function qd(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function Hd(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=Q.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new F(m.tag,Mc),new F(m.bytes,r)]}function zd(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function jd(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 Yd(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 $i={float64:!0,typeEncoders:{Map:Yd,Object:Hd,undefined:zd,number:jd}},Qy={...$i,typeEncoders:{...$i.typeEncoders}};function Zd(t){let e=t();if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return Q.decode(e.subarray(1))}var qi={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[Mc]:Zd}},Jy={...qi,tags:{...qi.tags}};var Kc=t=>Ki(t,$i),Vc=t=>Vi(qd(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 jr=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};function $c(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 Hi=Symbol.for("@libp2p/peer-id");function Xd(t){return typeof t?.handleEvent=="function"}function Wd(t){return(t!==!0&&t!==!1&&t?.once)??!1}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=Wd(n);super.addEventListener(e,s=>{if(o){let a=this.#e.get(s.type);a!=null&&(a=a.filter(({callback:c})=>c!==r),this.#e.set(s.type,a))}Xd(r)?r.handleEvent(s):r(s)},n);let i=this.#e.get(e);i==null&&(i=[],this.#e.set(e,i)),i.push({callback:r,once:o})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==r),this.#e.set(e,o))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var ot="/",qc=new TextEncoder().encode(ot),eo=qc[0],or=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=re(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 Y(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=qc),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 Qd(this.baseNamespace())}name(){return Jd(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(),...eh(e.map(r=>r.namespaces()))])}};function Qd(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function Jd(t){let e=t.split(":");return e[e.length-1]}function eh(t){return[].concat(...t)}var Hc=114,zc=0;var jc=re("/ipns/"),to="/ipns/";function Yc(t,e){return t.code===e}var ro="/dht/record/",rh="/ipns/metadata/";function Yr(t){return new or(ro+Y(t,"base32"),!1)}function no(t){return new or(rh+Y(t,"base32"),!1)}function Zc(t,e){let r=Date.now();return t.getTime()+1728e5-r<864e5||e.getTime()-r<864e5}function Gc(t,e,r){let n=re(e);return bt([t,r,n],t.byteLength+r.byteLength+n.byteLength)}function oo(t){let e=re("ipns-signature:");return bt([e,t])}function zi(t){try{return`/ipfs/${Q.decode(t)}`}catch{}return Y(t)}function it(t){return bt([jc,t.bytes])}function io(t){return ht(t.slice(jc.length))}function Xc(t){return xe(Kc(t))}function Ne(t){if(t==null)throw new Bn("Record data is missing");let e=Vc(t);if(e.ValidityType===0&&(e.ValidityType=Z.ValidityType.EOL),e.ValidityType!==Z.ValidityType.EOL)throw new Wt("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 Wc(t){if(t!=null){if(kn(t))return`/ipns/${t.toCID().toV1().toString(we)}`;let e=Jc(t);if(e!=null)return e.code===Hc?`/ipns/${e.toV1().toString(we)}`:`/ipfs/${e.toV1()}`;if(oh(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/${Q.parse(n).toV1()}${o.length>0?`/${o.join("/")}`:""}`}if(r.startsWith("/")&&r.length>1)return r}throw new mt("Value must be a valid content path starting with /")}function nh(t){return typeof t.code=="number"&&t.digest instanceof Uint8Array&&typeof t.size=="number"&&t.bytes instanceof Uint8Array}function Zr(t){if(t!=null){if(kn(t))return{digest:t.toMultihash(),path:"/"};let e=Jc(t);if(e!=null){if(e.code!==Hc)throw new mt("CIDs must have the `libp2p-key` codec");return{digest:e.multihash,path:"/"}}if(nh(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=G);let i=o.decode(r),s;try{s=Q.decode(i).multihash}catch{s=ht(i)}return{digest:s,path:`/${n.join("/")}`}}}throw new mt("Value must be a valid IPNS path starting with /")}function Qc(t,e){if(!fe(e.Value,t.value??new Uint8Array(0)))throw new ke('Field "value" did not match between protobuf and CBOR');if(!fe(e.Validity,t.validity??new Uint8Array(0)))throw new ke('Field "validity" did not match between protobuf and CBOR');if(e.ValidityType!==t.validityType)throw new ke('Field "validityType" did not match between protobuf and CBOR');if(e.Sequence!==t.sequence)throw new ke('Field "sequence" did not match between protobuf and CBOR');if(e.TTL!==t.ttl)throw new ke('Field "ttl" did not match between protobuf and CBOR')}function oh(t){return t.bytes instanceof Uint8Array}function ih(t){return typeof t?.toCID=="function"}function Jc(t){if(ih(t))return t.toCID();try{return Q.parse(t)}catch{}return Q.asCID(t)}function ir(t,e){let r=e.map((n,o)=>({record:n,index:o}));return r.sort((n,o)=>{let i=Ne(n.record.data),s=Ne(o.record.data),a=i.Sequence,c=s.Sequence;if(a>c)return-1;if(a<c)return 1;if(i.ValidityType===Z.ValidityType.EOL&&s.ValidityType===Z.ValidityType.EOL){let u=ji.default.fromString(Y(i.Validity)).toDate(),f=ji.default.fromString(Y(s.Validity)).toDate();if(u.getTime()>f.getTime())return-1;if(u.getTime()<f.getTime())return 1}return 0}),r[0].index}var eu=Go(Un(),1);var sh=1024*10;async function St(t,e,r,n){if(e.byteLength>sh)throw new In("The record is too large");let o=Z.decode(e);if(o.signatureV2==null)throw new ke("Missing signatureV2");let i=Ne(o.data),s=Y(i.Validity),a,c=io(t);if(Yc(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 Cn("Could not extract public key from IPNS record or routing key");let u;try{if(o.data==null)throw new Error("Missing data");let f=oo(o.data);u=await a.verify(f,o.signatureV2,n)}catch{u=!1}if(!u)throw new ke("Record signature verification failed");if(i.ValidityType===Z.ValidityType.EOL){if(eu.default.fromString(s).toDate().getTime()<Date.now())throw new Tn("record has expired")}else if(i.ValidityType!=null)throw new Wt(`The validity type ${i.ValidityType} is unsupported`);return o.value!=null&&o.signatureV1!=null&&Qc(o,i),o}var sr=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}=Zr(e);for(;;){let o=it(n),i=await this.#e(o,r),s="";if(i.data!=null){let a=Ne(i.data);s=zi(a.Value)}else if(i.value!=null)s=zi(i.value);else throw new mt(`Record for key ${we.encode(n.bytes)} contained no value`);if(yield{record:i,value:s},!s.startsWith(to))break;({digest:n}=Zr(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:u}=await this.localStore.get(e,r);this.log("record retrieved from cache");let f;r.validate===!1?(f=Z.decode(c),this.log("skipped validation of record")):(f=await St(e,c,this.keychain,r),this.log("record was valid"));let l=Ne(f.data),y=Number((l.TTL??En)/1000000n);if(u.getTime()+y>Date.now())return this.log("record TTL was valid"),f;if(r.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),f;this.log("record TTL has been reached, searching routing for updates"),n.push(f)}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 _r("Record was not present in the cache or has expired");this.log("did not have record locally");let i=0,s=[];if(await Promise.all(this.routers.map(async c=>{let u;try{u=await c.get(e,{...r,validate:!1})}catch(f){this.log.error("error finding IPNS record using router %s - %e",c.toString(),f),s.push(f);return}try{let f;r.validate===!1?f=Z.decode(u):f=await St(e,u,this.keychain,r),n.push(f)}catch(f){i++,this.log.error("error validating IPNS record from router %s - %e",c.toString(),f)}})),n.length===0)throw i>0?new Sn(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`):new _r("Could not find record for routing key");let a=n[ir(e,n)];return await this.localStore.put(e,Z.encode(a),r),a}};var se=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};function so(t,e){if(typeof t=="string")return ah(t);if(typeof t=="number")return fh(t,e);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}function ah(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 ch(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 uh(t){let e=Math.abs(t);return e>=315576e5?Ot(t,e,315576e5,"year"):e>=26298e5?Ot(t,e,26298e5,"month"):e>=6048e5?Ot(t,e,6048e5,"week"):e>=864e5?Ot(t,e,864e5,"day"):e>=36e5?Ot(t,e,36e5,"hour"):e>=6e4?Ot(t,e,6e4,"minute"):e>=1e3?Ot(t,e,1e3,"second"):`${t} ms`}function fh(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?uh(t):ch(t)}function Ot(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function Yi(t){r.debug=r,r.default=r,r.coerce=c,r.disable=i,r.enable=o,r.enabled=s,r.humanize=so,r.destroy=u,Object.keys(t).forEach(f=>{r[f]=t[f]}),r.names=[],r.skips=[],r.formatters={};function e(f){let l=0;for(let y=0;y<f.length;y++)l=(l<<5)-l+f.charCodeAt(y),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=e;function r(f,l){let y,p=null,T,A;function h(...g){if(!h.enabled)return;let v=h,C=Number(new Date),O=C-(y||C);v.diff=O,v.prev=y,v.curr=C,y=C,g[0]=r.coerce(g[0]),typeof g[0]!="string"&&g.unshift("%O");let N=0;g[0]=g[0].replace(/%([a-zA-Z%])/g,(k,E)=>{if(k==="%%")return"%";N++;let B=r.formatters[E];if(typeof B=="function"){let U=g[N];k=B.call(v,U),g.splice(N,1),N--}return k}),r.formatArgs.call(v,g),l?.onLog!=null&&l.onLog(...g),(v.log||r.log).apply(v,g)}return h.namespace=f,h.useColors=r.useColors(),h.color=r.selectColor(f),h.extend=n,h.destroy=r.destroy,Object.defineProperty(h,"enabled",{enumerable:!0,configurable:!1,get:()=>p!==null?p:(T!==r.namespaces&&(T=r.namespaces,A=r.enabled(f)),A),set:g=>{p=g}}),typeof r.init=="function"&&r.init(h),h}function n(f,l){let y=r(this.namespace+(typeof l>"u"?":":l)+f);return y.log=this.log,y}function o(f){r.save(f),r.namespaces=f,r.names=[],r.skips=[];let l,y=(typeof f=="string"?f:"").split(/[\s,]+/),p=y.length;for(l=0;l<p;l++)y[l]&&(f=y[l].replace(/\*/g,".*?"),f[0]==="-"?r.skips.push(new RegExp("^"+f.substr(1)+"$")):r.names.push(new RegExp("^"+f+"$")))}function i(){let f=[...r.names.map(a),...r.skips.map(a).map(l=>"-"+l)].join(",");return r.enable(""),f}function s(f){if(f[f.length-1]==="*")return!0;let l,y;for(l=0,y=r.skips.length;l<y;l++)if(r.skips[l].test(f))return!1;for(l=0,y=r.names.length;l<y;l++)if(r.names[l].test(f))return!0;return!1}function a(f){return f.toString().substring(2,f.toString().length-2).replace(/\.\*\?$/,"*")}function c(f){return f instanceof Error?f.stack??f.message:f}function u(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var ao=gh(),lh=["#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 dh(){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 hh(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+so(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 ph=console.debug??console.log??(()=>{});function mh(t){try{t?ao?.setItem("debug",t):ao?.removeItem("debug")}catch{}}function yh(){let t;try{t=ao?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function gh(){try{return localStorage}catch{}}function bh(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var tu=Yi({formatArgs:hh,save:mh,load:yh,useColors:dh,setupFormatters:bh,colors:lh,storage:ao,log:ph});var Ee=tu;Ee.formatters.b=t=>t==null?"undefined":G.baseEncode(t);Ee.formatters.t=t=>t==null?"undefined":dt.baseEncode(t);Ee.formatters.m=t=>t==null?"undefined":hi.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 ru(t,e=""){let r=nu(t.message),n=nu(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
2
+ "use strict";var HeliaIpns=(()=>{var Pf=Object.create;var En=Object.defineProperty;var Mf=Object.getOwnPropertyDescriptor;var Kf=Object.getOwnPropertyNames;var Vf=Object.getPrototypeOf,$f=Object.prototype.hasOwnProperty;var qf=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},ve=(t,e)=>{for(var r in e)En(t,r,{get:e[r],enumerable:!0})},ea=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Kf(e))!$f.call(t,o)&&o!==r&&En(t,o,{get:()=>e[o],enumerable:!(n=Mf(e,o))||n.enumerable});return t};var ri=(t,e,r)=>(r=t!=null?Pf(Vf(t)):{},ea(e||!t||!t.__esModule?En(r,"default",{value:t,enumerable:!0}):r,t)),Hf=t=>ea(En({},"__esModule",{value:!0}),t);var Nn=qf((km,Ni)=>{var Um=(function(){typeof Ni<"u"&&(Ni.exports=A);var t=86400,e=3200,r=146097*e/400,n=t*r,o=1e3*n,i=864e13,s=4294967296,a=1e6,c="000000000",u=Math.trunc||function(E){var B=E-E%1;return B==0&&(E<0||E===0&&1/E!=1/0)?-0:B},f=A.prototype,l=(A.fromDate=function(E){return new A(+E)},A.fromInt64BE=O(0,1,2,3,0,4),A.fromInt64LE=O(3,2,1,0,4,0),A.fromString=function(_){var B,U=new A,_=(_+="").replace(/^\s*[+\-]?\d+/,function(b){var b=+b,S=1970+(b-1970)%400;return U.year=b-S,S}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(d,b,S){return b<0&&(S*=-1),B=6e4*(60*+b+ +S),""}).replace(/\.\d+$/,function(d){return U.nano=+(d+c).substr(1,9),""}).split(/\D+/);if(1<_.length?_[1]--:_[1]=0,U.time=B=Date.UTC.apply(Date,_)-(B||0),isNaN(B))throw new TypeError("Invalid Date");return h(U)},A.fromTimeT=function(E){return v(E,0)},f.year=0,f.time=0,f.nano=0,f.addNano=function(E){return this.nano+=+E||0,this},f.getNano=function(){var E=h(this);return(E.time%1e3*a+ +E.nano+1e9)%1e9},f.getTimeT=function(){var B=h(this),E=Math.floor(B.time/1e3),B=B.year;return B&&(E+=B*r*t/e),E},f.getYear=function(){return this.toDate().getUTCFullYear()+this.year},f.toDate=function(){return g(h(this).time)},f.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},f.toString=function(E){var B=this,U=B.toDate(),_={H:function(){return K(U.getUTCHours())},L:function(){return N(U.getUTCMilliseconds(),3)},M:function(){return K(U.getUTCMinutes())},N:function(){return N(B.getNano(),9)},S:function(){return K(U.getUTCSeconds())},Y:function(){var d=B.getYear();return 999999<d?"+"+d:9999<d?"+"+N(d,6):0<=d?N(d,4):-999999<=d?"-"+N(-d,6):d},a:function(){return m[U.getUTCDay()]},b:function(){return y[U.getUTCMonth()]},d:function(){return K(U.getUTCDate())},e:function(){return(function(d){return(9<d?"":" ")+(0|d)})(U.getUTCDate())},m:function(){return K(U.getUTCMonth()+1)}};return(function d(b){return b.replace(/%./g,function(S){var x=S[1],w=T[x],x=_[x];return w?d(w):x?x():S})})(E||l)},f.writeInt64BE=C(0,1,2,3,0,4),f.writeInt64LE=C(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),y=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],m=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],T={"%":"%",F:"%Y-%m-%d",n:`
3
+ `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return A;function A(E,B,U){var _=this;if(!(_ instanceof A))return new A(E,B,U);_.time=+E||0,_.nano=+B||0,_.year=+U||0,h(_)}function h(E){var B,U,_,d=E.year,b=E.time,S=E.nano,w=((S<0||a<=S)&&(S-=(U=Math.floor(S/a))*a,b+=U,U=1),d%e);return(b<-i||i<b||w)&&((B=u(b/o))&&(d+=B*e,b-=B*o),(_=g(b)).setUTCFullYear(w+_.getUTCFullYear()),_=(b=+_)+(B=u((d-=w)/e))*o,B&&-i<=_&&_<=i&&(d-=B*e,b=_),U=1),U&&(E.year=d,E.time=b,E.nano=S),E}function g(E){var B=new Date(0);return B.setTime(E),B}function v(d,_){d=+d||0;var U=u((_=(_|0)*s)/n)+u(d/n),_=_%n+d%n,d=u(_/n);return d&&(U+=d,_-=d*n),new A(1e3*_,0,U*e)}function C(E,B,U,_,d,b){return function(w,x){var R=h(this);w=w||new Array(8),k(w,x|=0);var L=Math.floor(R.time/1e3),R=R.year*(r*t/e),I=u(R/s)+u(L/s),R=R%s+L%s,L=Math.floor(R/s);return L&&(I+=L,R-=L*s),S(w,x+d,I),S(w,x+b,R),w};function S(w,x,I){w[x+E]=I>>24&255,w[x+B]=I>>16&255,w[x+U]=I>>8&255,w[x+_]=255&I}}function O(E,B,U,_,d,b){return function(w,x){k(w,x|=0);var I=S(w,x+d);return v(S(w,x+b),I)};function S(w,x){return 16777216*w[x+E]+(w[x+B]<<16|w[x+U]<<8|w[x+_])}}function k(E,B){if(E=E&&E.length,E==null)throw new TypeError("Invalid Buffer");if(E<B+8)throw new RangeError("Out of range")}function K(E){return(9<E?"":"0")+(0|E)}function N(E,B){return(c+(0|E)).substr(-B)}})()});var Wp={};ve(Wp,{IPNSEntry:()=>Z,createIPNSRecord:()=>lr,heliaIPNSRouting:()=>Cr,ipns:()=>Gp,ipnsResolver:()=>Xp,multihashFromIPNSRoutingKey:()=>ho,multihashToIPNSRoutingKey:()=>it,pubSubIPNSRouting:()=>Of});var ai={};ve(ai,{base32:()=>dt,base32hex:()=>tl,base32hexpad:()=>nl,base32hexpadupper:()=>ol,base32hexupper:()=>rl,base32pad:()=>Jf,base32padupper:()=>el,base32upper:()=>Qf,base32z:()=>il});var Jp=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 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 zf(t){return t?.buffer instanceof ArrayBuffer}function Ut(t){return zf(t)?t:t.slice()}function jf(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),u=s.toUpperCase().charCodeAt(0);c!==a&&(n[c]=i),u!==a&&(n[u]=i)}}var f=t.length,l=t.charAt(0),y=Math.log(f)/Math.log(256),m=Math.log(256)/Math.log(f);function T(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var v=0,C=0,O=0,k=g.length;O!==k&&g[O]===0;)O++,v++;for(var K=(k-O)*m+1>>>0,N=new Uint8Array(K);O!==k;){for(var E=g[O],B=0,U=K-1;(E!==0||B<C)&&U!==-1;U--,B++)E+=256*N[U]>>>0,N[U]=E%f>>>0,E=E/f>>>0;if(E!==0)throw new Error("Non-zero carry");C=B,O++}for(var _=K-C;_!==K&&N[_]===0;)_++;for(var d=l.repeat(v);_<K;++_)d+=t.charAt(N[_]);return d}function A(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var v=0;if(g[v]!==" "){for(var C=0,O=0;g[v]===l;)C++,v++;for(var k=(g.length-v)*y+1>>>0,K=new Uint8Array(k);g[v];){var N=n[g.charCodeAt(v)];if(N===255)return;for(var E=0,B=k-1;(N!==0||E<O)&&B!==-1;B--,E++)N+=f*K[B]>>>0,K[B]=N%256>>>0,N=N/256>>>0;if(N!==0)throw new Error("Non-zero carry");O=E,v++}if(g[v]!==" "){for(var U=k-O;U!==k&&K[U]===0;)U++;for(var _=new Uint8Array(C+(k-U)),d=C;U!==k;)_[d++]=K[U++];return _}}}function h(g){var v=A(g);if(v)return v;throw new Error(`Non-${e} character`)}return{encode:T,decodeUnsafe:A,decode:h}}var Yf=jf,Zf=Yf,sa=Zf;var ni=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")}},oi=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)}},ii=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 ii({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var si=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 ni(e,r,n),this.decoder=new oi(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 si(t,e,r,n)}function lt({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=>Le(i(s))})}function Gf(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Xf(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 Wf(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 Q({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let i=Wf(n,o);return Gt({prefix:e,name:t,encode(s){return Xf(s,n,r)},decode(s){return Gf(s,i,r,t)}})}var dt=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Qf=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Jf=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),el=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),tl=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),rl=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),nl=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),ol=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),il=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ci={};ve(ci,{base36:()=>xe,base36upper:()=>sl});var xe=lt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),sl=lt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var ui={};ve(ui,{base58btc:()=>G,base58flickr:()=>al});var G=lt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),al=lt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var cl=fa,ca=128,ul=127,fl=~ul,ll=Math.pow(2,31);function fa(t,e,r){e=e||[],r=r||0;for(var n=r;t>=ll;)e[r++]=t&255|ca,t/=128;for(;t&fl;)e[r++]=t&255|ca,t>>>=7;return e[r]=t|0,fa.bytes=r-n+1,e}var dl=fi,hl=128,ua=127;function fi(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw fi.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>=hl);return fi.bytes=i-n,r}var pl=Math.pow(2,7),ml=Math.pow(2,14),yl=Math.pow(2,21),gl=Math.pow(2,28),bl=Math.pow(2,35),wl=Math.pow(2,42),xl=Math.pow(2,49),El=Math.pow(2,56),Sl=Math.pow(2,63),vl=function(t){return t<pl?1:t<ml?2:t<yl?3:t<gl?4:t<bl?5:t<wl?6:t<xl?7:t<El?8:t<Sl?9:10},Al={encode:cl,decode:dl,encodingLength:vl},Tl=Al,Dr=Tl;function Rr(t,e=0){let r=Dr.decode(t,e),n=Dr.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 Dr.encode(t,e,r),e}function Wt(t){return Dr.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 ht(t){let e=Le(t),[r,n]=Rr(e),[o,i]=Rr(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?Bl(r,li(t),e??G.encoder):Cl(r,li(t),e??dt.encoder)}var ha=new WeakMap;function li(t){let e=ha.get(t);if(e==null){let r=new Map;return ha.set(t,r),r}return e}var W=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!==Lr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==_l)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[Dl]===!0){let{version:n,multihash:o,code:i}=r,s=ht(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!==Lr)throw new Error(`Version 0 CID must use dag-pb (code: ${Lr}) 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,Lr,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 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,y]=Rr(e.subarray(r));return r+=y,l},o=n(),i=Lr;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),u=r+c,f=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=Il(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 li(i).set(n,e),i}};function Il(t,e){switch(t[0]){case"Q":{let r=e??G;return[G.prefix,r.decode(`${G.prefix}${t}`)]}case G.prefix:{let r=e??G;return[G.prefix,r.decode(t)]}case dt.prefix:{let r=e??dt;return[dt.prefix,r.decode(t)]}case xe.prefix:{let r=e??xe;return[xe.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 Bl(t,e,r){let{prefix:n}=r;if(n!==G.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 Cl(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 Lr=112,_l=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 Dl=Symbol.for("@ipld/js-cid/CID");var vn=BigInt(6e4)*5000000n,ma=5;var An=class extends Error{static name="RecordsFailedValidationError";name="RecordsFailedValidationError"},mt=class extends Error{static name="InvalidValueError";name="InvalidValueError"},Tn=class extends Error{static name="InvalidTopicError";name="InvalidTopicError"},Fr=class extends Error{static name="RecordNotFoundError";name="RecordNotFoundError"},In=class extends Error{static name="SignatureCreationError";name="SignatureCreationError"},Ne=class extends Error{static name="SignatureVerificationError";name="SignatureVerificationError"},Bn=class extends Error{static name="RecordExpiredError";name="RecordExpiredError"},er=class extends Error{static name="UnsupportedValidityError";name="UnsupportedValidityError"},Cn=class extends Error{static name="RecordTooLargeError";name="RecordTooLargeError"},_n=class extends Error{static name="InvalidRecordDataError";name="InvalidRecordDataError"},Dn=class extends Error{static name="InvalidEmbeddedPublicKeyError";name="InvalidEmbeddedPublicKeyError"};function Fe(t=0){return new Uint8Array(t)}function Ae(t=0){return new Uint8Array(t)}var Rl=Math.pow(2,7),Ll=Math.pow(2,14),Fl=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,yt=127;function Ur(t){if(t<Rl)return 1;if(t<Ll)return 2;if(t<Fl)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(Ur(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&yt,r<ge||(r=t[e+1],n+=(r&yt)<<7,r<ge)||(r=t[e+2],n+=(r&yt)<<14,r<ge)||(r=t[e+3],n+=(r&yt)<<21,r<ge)||(r=t[e+4],n+=(r&yt)*ya,r<ge)||(r=t[e+5],n+=(r&yt)*ga,r<ge)||(r=t[e+6],n+=(r&yt)*ba,r<ge)||(r=t[e+7],n+=(r&yt)*wa,r<ge))return n;throw new RangeError("Could not decode varint")}function Ul(t){return t.buffer instanceof ArrayBuffer}function Ee(t){return Ul(t)?t:t.slice()}var di=new Float32Array([-0]),gt=new Uint8Array(di.buffer);function Sa(t,e,r){di[0]=t,e[r]=gt[0],e[r+1]=gt[1],e[r+2]=gt[2],e[r+3]=gt[3]}function va(t,e){return gt[0]=t[e],gt[1]=t[e+1],gt[2]=t[e+2],gt[3]=t[e+3],di[0]}var hi=new Float64Array([-0]),ye=new Uint8Array(hi.buffer);function Aa(t,e,r){hi[0]=t,e[r]=ye[0],e[r+1]=ye[1],e[r+2]=ye[2],e[r+3]=ye[3],e[r+4]=ye[4],e[r+5]=ye[5],e[r+6]=ye[6],e[r+7]=ye[7]}function Ta(t,e){return ye[0]=t[e],ye[1]=t[e+1],ye[2]=t[e+2],ye[3]=t[e+3],ye[4]=t[e+4],ye[5]=t[e+5],ye[6]=t[e+6],ye[7]=t[e+7],hi[0]}var kl=BigInt(Number.MAX_SAFE_INTEGER),Nl=BigInt(Number.MIN_SAFE_INTEGER),Te=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 kt;if(e<kl&&e>Nl)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 kt;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):kt}},kt=new Te(0,0);kt.toBigInt=function(){return 0n};kt.zzEncode=kt.zzDecode=function(){return this};kt.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 pi(t,e,r){let n=r,o,i;for(let s=0;s<t.length;++s)o=t.charCodeAt(s),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((i=t.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function Oe(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Rn(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var mi=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Ee(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Oe(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Oe(this,4);return Rn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Oe(this,4);return Rn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Oe(this,4);let e=va(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Oe(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 Oe(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 Oe(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Oe(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Te(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Oe(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Oe(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Oe(this,8);let e=Rn(this.buf,this.pos+=4),r=Rn(this.buf,this.pos+=4);return new Te(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+=Ur(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 kr(t){return new mi(t instanceof Uint8Array?t:t.subarray())}function ze(t,e,r){let n=kr(t);return e.decode(n,void 0,r)}var yi={};ve(yi,{base10:()=>Ol});var Ol=lt({prefix:"9",name:"base10",alphabet:"0123456789"});var gi={};ve(gi,{base16:()=>Pl,base16upper:()=>Ml});var Pl=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Ml=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var bi={};ve(bi,{base2:()=>Kl});var Kl=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var wi={};ve(wi,{base256emoji:()=>zl});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}"),Vl=Da.reduce((t,e,r)=>(t[r]=e,t),[]),$l=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+=Vl[r],e),"")}function Hl(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=$l[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var zl=Gt({prefix:"\u{1F680}",name:"base256emoji",encode:ql,decode:Hl});var Ei={};ve(Ei,{base64:()=>xi,base64pad:()=>jl,base64url:()=>Yl,base64urlpad:()=>Zl});var xi=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),jl=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Yl=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Zl=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Si={};ve(Si,{base8:()=>Gl});var Gl=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var vi={};ve(vi,{identity:()=>Xl});var Xl=Gt({prefix:"\0",name:"identity",encode:t=>oa(Le(t)),decode:t=>Le(na(t))});var M0=new TextEncoder,K0=new TextDecoder;var Ai={};ve(Ai,{identity:()=>Pe});var Ra=0,Jl="identity",La=Le;function ed(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 Pe={code:Ra,name:Jl,encode:La,digest:ed};var Bi={};ve(Bi,{sha256:()=>Nr,sha512:()=>rd});var td=20;function Ii({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Ti(t,e,r,n,o)}var Ti=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??td,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?Fa(n,this.code,r?.truncate):n.then(o=>Fa(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Fa(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 ka(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Nr=Ii({name:"sha2-256",code:18,encode:ka("SHA-256")}),rd=Ii({name:"sha2-512",code:19,encode:ka("SHA-512")});var Ci={...vi,...bi,...Si,...yi,...gi,...ai,...ci,...ui,...Ei,...wi},J0={...Bi,...Ai};function Oa(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Na=Oa("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),_i=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=Ae(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),nd={utf8:Na,"utf-8":Na,hex:Ci.base16,latin1:_i,ascii:_i,binary:_i,...Ci},Ln=nd;function te(t,e="utf8"){let r=Ln[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Di(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return Ae(s);o+s>e&&(n=Ae(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Nt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Ri(){}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}},od=Di();function id(t){return globalThis.Buffer!=null?Ae(t):od(t)}var Pr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Nt(Ri,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Nt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Ui((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(Fn,10,Te.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Te.fromBigInt(e);return this._push(Fn,r.length(),r)}uint64Number(e){return this._push(xa,Ur(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=Te.fromBigInt(e).zzEncode();return this._push(Fn,r.length(),r)}sint64Number(e){let r=Te.fromNumber(e).zzEncode();return this._push(Fn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Li,1,e?1:0)}fixed32(e){return this._push(Or,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Te.fromBigInt(e);return this._push(Or,4,r.lo)._push(Or,4,r.hi)}fixed64Number(e){let r=Te.fromNumber(e);return this._push(Or,4,r.lo)._push(Or,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(Li,1,0):this.uint32(r)._push(ad,r,e)}string(e){let r=Ba(e);return r!==0?this.uint32(r)._push(pi,r,e):this._push(Li,1,0)}fork(){return this.states=new Fi(this),this.head=this.tail=new Nt(Ri,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 Nt(Ri,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=id(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Li(t,e,r){e[r]=t&255}function sd(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Ui=class extends Nt{next;constructor(e,r){super(sd,e,r),this.next=void 0}};function Fn(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 Or(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 ad(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Pr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(cd,e,t),this},Pr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(ud,e,t),this});function cd(t,e,r){e.set(t,r)}function ud(t,e,r){t.length<40?pi(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(te(t),r)}function ki(){return new Pr}function je(t,e){let r=ki();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Ye(t,e,r){let n=kr(t);yield*e.stream(n,void 0,"$",r)}var Un={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function kn(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Mr(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 kn("enum",Un.VARINT,r,n,o)}function Ze(t,e,r){return kn("message",Un.LENGTH_DELIMITED,t,e,r)}var Z;(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=()=>Mr(r)})(e=t.ValidityType||(t.ValidityType={}));let n;t.codec=()=>(n==null&&(n=Ze((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.value!=null&&(c.uint32(10),c.bytes(a.value)),a.signatureV1!=null&&(c.uint32(18),c.bytes(a.signatureV1)),a.validityType!=null&&(c.uint32(24),t.ValidityType.codec().encode(a.validityType,c)),a.validity!=null&&(c.uint32(34),c.bytes(a.validity)),a.sequence!=null&&(c.uint32(40),c.uint64(a.sequence)),a.ttl!=null&&(c.uint32(48),c.uint64(a.ttl)),a.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)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let y=a.uint32();switch(y>>>3){case 1:{f.value=a.bytes();break}case 2:{f.signatureV1=a.bytes();break}case 3:{f.validityType=t.ValidityType.codec().decode(a);break}case 4:{f.validity=a.bytes();break}case 5:{f.sequence=a.uint64();break}case 6:{f.ttl=a.uint64();break}case 7:{f.publicKey=a.bytes();break}case 8:{f.signatureV2=a.bytes();break}case 9:{f.data=a.bytes();break}default:{a.skipType(y&7);break}}}return f},function*(a,c,u,f={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let y=a.uint32();switch(y>>>3){case 1:{yield{field:`${u}.value`,value:a.bytes()};break}case 2:{yield{field:`${u}.signatureV1`,value:a.bytes()};break}case 3:{yield{field:`${u}.validityType`,value:t.ValidityType.codec().decode(a)};break}case 4:{yield{field:`${u}.validity`,value:a.bytes()};break}case 5:{yield{field:`${u}.sequence`,value:a.uint64()};break}case 6:{yield{field:`${u}.ttl`,value:a.uint64()};break}case 7:{yield{field:`${u}.publicKey`,value:a.bytes()};break}case 8:{yield{field:`${u}.signatureV2`,value:a.bytes()};break}case 9:{yield{field:`${u}.data`,value:a.bytes()};break}default:{a.skipType(y&7);break}}}})),n);function o(a){return je(a,t.codec())}t.encode=o;function i(a,c){return ze(a,t.codec(),c)}t.decode=i;function s(a,c){return Ye(a,t.codec(),c)}t.stream=s})(Z||(Z={}));var Ji=ri(Nn(),1);function Y(t,e="utf8"){let r=Ln[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}function fd(t){return t?.buffer instanceof ArrayBuffer}function Pa(t){if(fd(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function bt(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=Ae(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return Pa(r)}function le(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 On(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(On(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(On(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(On(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 bt(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:bt(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),i=new t;return i.length=o,i.bufs=n,i}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(s);break}let l=e-a;n.push(s.subarray(l,l+(r-e)));break}if(u){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(f){if(r===c){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!On(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let y=u;y>=0;y--){let m=this.get(l+y);if(n[y]!==m){f=Math.max(1,y-a[m]);break}}if(f===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Ae(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=Fe(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=Fe(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=Fe(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=Ae(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=Fe(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=Fe(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=Fe(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=Fe(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=Fe(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(!le(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 Pn(t){return t==null?!1:typeof t.type=="string"&&typeof t.code=="number"&&typeof t.verify=="function"}var ld=["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 Oi(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=dd(t);return r||"Object"}function dd(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(ld.includes(e))return e}var p=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}};p.uint=new p(0,"uint",!0);p.negint=new p(1,"negint",!0);p.bytes=new p(2,"bytes",!0);p.string=new p(3,"string",!0);p.array=new p(4,"array",!1);p.map=new p(5,"map",!1);p.tag=new p(6,"tag",!1);p.float=new p(7,"float",!0);p.false=new p(7,"false",!0);p.true=new p(7,"true",!0);p.null=new p(7,"null",!0);p.undefined=new p(7,"undefined",!0);p.break=new p(7,"break",!0);var F=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 Kr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",hd=new TextEncoder;function Mn(t){return Kr&&globalThis.Buffer.isBuffer(t)}function Vr(t){return t instanceof Uint8Array?Mn(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var pd=24,md=200,Kn=Kr?t=>t.length>=pd?globalThis.Buffer.from(t):Va(t):t=>t.length>=md?hd.encode(t):Va(t),Ge=t=>Uint8Array.from(t),$a=Kr?(t,e,r)=>Mn(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),qa=Kr?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Vr(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},Pi=Kr?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function tr(t,e){if(Mn(t)&&Mn(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 yd=256,$r=class{constructor(e=yd){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=Pi(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=Pi(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}},Vn=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 M="CBOR decode error:",$n="CBOR encode error:",qr=[];qr[23]=1;qr[24]=2;qr[25]=3;qr[26]=5;qr[27]=9;function tt(t,e,r){if(t.length-e<r)throw new Error(`${M} not enough data for type`)}var de=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Be(t,e,r){tt(t,e,1);let n=t[e];if(r.strict===!0&&n<de[0])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);return n}function Ce(t,e,r){tt(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<de[1])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);return n}function _e(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<de[2])throw new Error(`${M} integer encoded in more bytes than necessary (strict decode)`);return n}function De(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<de[3])throw new Error(`${M} 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(`${M} integers outside of the safe integer range are not supported`)}function Ha(t,e,r,n){return new F(p.uint,Be(t,e+1,n),2)}function za(t,e,r,n){return new F(p.uint,Ce(t,e+1,n),3)}function ja(t,e,r,n){return new F(p.uint,_e(t,e+1,n),5)}function Ya(t,e,r,n){return new F(p.uint,De(t,e+1,n),9)}function Xe(t,e){return ie(t,0,e.value)}function ie(t,e,r){if(r<de[0]){let n=Number(r);t.pushByte(e|n)}else if(r<de[1]){let n=Number(r);t.push([e|24,n])}else if(r<de[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<de[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<de[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(`${M} encountered BigInt larger than allowable range`)}}Xe.encodedSize=function(e){return ie.encodedSize(e.value)};ie.encodedSize=function(e){return e<de[0]?1:e<de[1]?2:e<de[2]?3:e<de[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 F(p.negint,-1-Be(t,e+1,n),2)}function Ga(t,e,r,n){return new F(p.negint,-1-Ce(t,e+1,n),3)}function Xa(t,e,r,n){return new F(p.negint,-1-_e(t,e+1,n),5)}var Mi=BigInt(-1),Wa=BigInt(1);function Qa(t,e,r,n){let o=De(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new F(p.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${M} integers outside of the safe integer range are not supported`);return new F(p.negint,Mi-BigInt(o),9)}function qn(t,e){let r=e.value,n=typeof r=="bigint"?r*Mi-Wa:r*-1-1;ie(t,e.type.majorEncoded,n)}qn.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Mi-Wa:r*-1-1;return n<de[0]?1:n<de[1]?2:n<de[2]?3:n<de[3]?5:9};qn.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Hr(t,e,r,n){tt(t,e,r+n);let o=t.slice(e+r,e+r+n);return new F(p.bytes,o,r+n)}function Ja(t,e,r,n){return Hr(t,e,1,r)}function ec(t,e,r,n){return Hr(t,e,2,Be(t,e+1,n))}function tc(t,e,r,n){return Hr(t,e,3,Ce(t,e+1,n))}function rc(t,e,r,n){return Hr(t,e,5,_e(t,e+1,n))}function nc(t,e,r,n){let o=De(t,e+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer bytes lengths not supported`);return Hr(t,e,9,o)}function Hn(t){return t.encodedBytes===void 0&&(t.encodedBytes=p.equals(t.type,p.string)?Kn(t.value):t.value),t.encodedBytes}function rr(t,e){let r=Hn(e);ie(t,e.type.majorEncoded,r.length),t.push(r)}rr.encodedSize=function(e){let r=Hn(e);return ie.encodedSize(r.length)+r.length};rr.compareTokens=function(e,r){return bd(Hn(e),Hn(r))};function bd(t,e){return t.length<e.length?-1:t.length>e.length?1:tr(t,e)}var oc=new TextDecoder,xd=32;function Ed(t,e,r){if(r-e<xd){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 zr(t,e,r,n,o){let i=r+n;tt(t,e,i);let s=new F(p.string,Ed(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 zr(t,e,1,r,n)}function sc(t,e,r,n){return zr(t,e,2,Be(t,e+1,n),n)}function ac(t,e,r,n){return zr(t,e,3,Ce(t,e+1,n),n)}function cc(t,e,r,n){return zr(t,e,5,_e(t,e+1,n),n)}function uc(t,e,r,n){let o=De(t,e+1,n);if(typeof o=="bigint")throw new Error(`${M} 64-bit integer string lengths not supported`);return zr(t,e,9,o,n)}var fc=rr;function nr(t,e,r,n){return new F(p.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,Be(t,e+1,n))}function hc(t,e,r,n){return nr(t,e,3,Ce(t,e+1,n))}function pc(t,e,r,n){return nr(t,e,5,_e(t,e+1,n))}function mc(t,e,r,n){let o=De(t,e+1,n);if(typeof o=="bigint")throw new Error(`${M} 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(`${M} indefinite length items not allowed`);return nr(t,e,1,1/0)}function zn(t,e){ie(t,p.array.majorEncoded,e.value)}zn.compareTokens=Xe.compareTokens;zn.encodedSize=function(e){return ie.encodedSize(e.value)};function or(t,e,r,n){return new F(p.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,Be(t,e+1,n))}function wc(t,e,r,n){return or(t,e,3,Ce(t,e+1,n))}function xc(t,e,r,n){return or(t,e,5,_e(t,e+1,n))}function Ec(t,e,r,n){let o=De(t,e+1,n);if(typeof o=="bigint")throw new Error(`${M} 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(`${M} indefinite length items not allowed`);return or(t,e,1,1/0)}function jn(t,e){ie(t,p.map.majorEncoded,e.value)}jn.compareTokens=Xe.compareTokens;jn.encodedSize=function(e){return ie.encodedSize(e.value)};function vc(t,e,r,n){return new F(p.tag,r,1)}function Ac(t,e,r,n){return new F(p.tag,Be(t,e+1,n),2)}function Tc(t,e,r,n){return new F(p.tag,Ce(t,e+1,n),3)}function Ic(t,e,r,n){return new F(p.tag,_e(t,e+1,n),5)}function Bc(t,e,r,n){return new F(p.tag,De(t,e+1,n),9)}function Yn(t,e){ie(t,p.tag.majorEncoded,e.value)}Yn.compareTokens=Xe.compareTokens;Yn.encodedSize=function(e){return ie.encodedSize(e.value)};var Zn=20,Gn=21,Xn=22,Wn=23;function _c(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${M} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new F(p.null,null,1):new F(p.undefined,void 0,1)}function Dc(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${M} indefinite length items not allowed`);return new F(p.break,void 0,1)}function Ki(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${M} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${M} Infinity values are not supported`)}return new F(p.float,t,e)}function Rc(t,e,r,n){return Ki(Qn(t,e+1),3,n)}function Lc(t,e,r,n){return Ki(Jn(t,e+1),5,n)}function Fc(t,e,r,n){return Ki(Nc(t,e+1),9,n)}function jr(t,e,r){let n=e.value;if(n===!1)t.pushByte(p.float.majorEncoded|Zn);else if(n===!0)t.pushByte(p.float.majorEncoded|Gn);else if(n===null)t.pushByte(p.float.majorEncoded|Xn);else if(n===void 0)t.pushByte(p.float.majorEncoded|Wn);else{let o,i=!1;(!r||r.float64!==!0)&&(Vi(n),o=Qn(se,1),n===o||Number.isNaN(n)?(se[0]=249,t.push(se.slice(0,3)),i=!0):($i(n),o=Jn(se,1),n===o&&(se[0]=250,t.push(se.slice(0,5)),i=!0))),i||(kc(n),o=Nc(se,1),se[0]=251,t.push(se.slice(0,9)))}}jr.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){Vi(n);let o=Qn(se,1);if(n===o||Number.isNaN(n))return 3;if($i(n),o=Jn(se,1),n===o)return 5}return 9};var Uc=new ArrayBuffer(9),Ue=new DataView(Uc,1),se=new Uint8Array(Uc,0);function Vi(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 Qn(t,e){if(t.length-e<2)throw new Error(`${M} 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 $i(t){Ue.setFloat32(0,t,!1)}function Jn(t,e){if(t.length-e<4)throw new Error(`${M} 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 Nc(t,e){if(t.length-e<8)throw new Error(`${M} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}function Id(t,e){let r=t.value;if(r===!1)return Uint8Array.of(p.float.majorEncoded|Zn);if(r===!0)return Uint8Array.of(p.float.majorEncoded|Gn);if(r===null)return Uint8Array.of(p.float.majorEncoded|Xn);if(r===void 0)return Uint8Array.of(p.float.majorEncoded|Wn);if(!e){if(Vi(r),r===Qn(se,1)||Number.isNaN(r))return se[0]=249,se.slice(0,3);if($i(r),r===Jn(se,1))return se[0]=250,se.slice(0,5)}return kc(r),se[0]=251,se.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=Id(t,n);return n?r._keyBytesFloat64=i:r._keyBytes=i,i}jr.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 z(t,e,r){throw new Error(`${M} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function eo(t){return()=>{throw new Error(`${M} ${t}`)}}var D=[];for(let t=0;t<=23;t++)D[t]=z;D[24]=Ha;D[25]=za;D[26]=ja;D[27]=Ya;D[28]=z;D[29]=z;D[30]=z;D[31]=z;for(let t=32;t<=55;t++)D[t]=z;D[56]=Za;D[57]=Ga;D[58]=Xa;D[59]=Qa;D[60]=z;D[61]=z;D[62]=z;D[63]=z;for(let t=64;t<=87;t++)D[t]=Ja;D[88]=ec;D[89]=tc;D[90]=rc;D[91]=nc;D[92]=z;D[93]=z;D[94]=z;D[95]=eo("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)D[t]=ic;D[120]=sc;D[121]=ac;D[122]=cc;D[123]=uc;D[124]=z;D[125]=z;D[126]=z;D[127]=eo("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)D[t]=lc;D[152]=dc;D[153]=hc;D[154]=pc;D[155]=mc;D[156]=z;D[157]=z;D[158]=z;D[159]=yc;for(let t=160;t<=183;t++)D[t]=gc;D[184]=bc;D[185]=wc;D[186]=xc;D[187]=Ec;D[188]=z;D[189]=z;D[190]=z;D[191]=Sc;for(let t=192;t<=215;t++)D[t]=vc;D[216]=Ac;D[217]=Tc;D[218]=Ic;D[219]=Bc;D[220]=z;D[221]=z;D[222]=z;D[223]=z;for(let t=224;t<=243;t++)D[t]=eo("simple values are not supported");D[244]=z;D[245]=z;D[246]=z;D[247]=_c;D[248]=eo("simple values are not supported");D[249]=Rc;D[250]=Lc;D[251]=Fc;D[252]=z;D[253]=z;D[254]=z;D[255]=Dc;var Me=[];for(let t=0;t<24;t++)Me[t]=new F(p.uint,t,1);for(let t=-1;t>=-24;t--)Me[31-t]=new F(p.negint,t,1);Me[64]=new F(p.bytes,new Uint8Array(0),1);Me[96]=new F(p.string,"",1);Me[128]=new F(p.array,0,1);Me[160]=new F(p.map,0,1);Me[244]=new F(p.false,!1,1);Me[245]=new F(p.true,!0,1);Me[246]=new F(p.null,null,1);function qi(t){switch(t.type){case p.false:return Ge([244]);case p.true:return Ge([245]);case p.null:return Ge([246]);case p.bytes:return t.value.length?void 0:Ge([64]);case p.string:return t.value===""?Ge([96]):void 0;case p.array:return t.value===0?Ge([128]):void 0;case p.map:return t.value===0?Ge([160]):void 0;case p.uint:return t.value<24?Ge([Number(t.value)]):void 0;case p.negint:if(t.value>=-24)return Ge([31-Number(t.value)])}}var Cd={float64:!1,mapSorter:zi,quickEncodeToken:qi},Vc=Object.freeze({mapSorter:Rd,quickEncodeToken:qi});function _d(){let t=[];return t[p.uint.major]=Xe,t[p.negint.major]=qn,t[p.bytes.major]=rr,t[p.string.major]=fc,t[p.array.major]=zn,t[p.map.major]=jn,t[p.tag.major]=Yn,t[p.float.major]=jr,t}var Mt=_d(),to=new $r,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(`${$n} object contains circular references`);return new t(r,e)}},wt={null:new F(p.null,null),undefined:new F(p.undefined,void 0),true:new F(p.true,!0),false:new F(p.false,!1),emptyArray:new F(p.array,0),emptyMap:new F(p.map,0)},We={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new F(p.float,t):t>=0?new F(p.uint,t):new F(p.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new F(p.uint,t):new F(p.negint,t)},Uint8Array(t,e,r,n){return new F(p.bytes,t)},string(t,e,r,n){return new F(p.string,t)},boolean(t,e,r,n){return t?wt.true:wt.false},null(t,e,r,n){return wt.null},undefined(t,e,r,n){return wt.undefined},ArrayBuffer(t,e,r,n){return new F(p.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new F(p.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[wt.emptyArray,new F(p.break)]:wt.emptyArray;n=sr.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=Pt(s,r,n);return r.addBreakTokens?[new F(p.array,t.length),o,new F(p.break)]:[new F(p.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,u=0;for(let f of i){let l=o?t.get(f):t[f];c&&l===void 0||(a[u++]=[Pt(f,r,n),Pt(l,r,n)])}u<s&&(a.length=u)}return a?.length?(Dd(a,r),r.addBreakTokens?[new F(p.map,a.length),a,new F(p.break)]:[new F(p.map,a.length),a]):r.addBreakTokens===!0?[wt.emptyMap,new F(p.break)]:wt.emptyMap},Tagged(t,e,r,n){return[new F(p.tag,t.tag),Pt(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 Pt(t,e={},r){let n=Oi(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(`${$n} unsupported type: ${n}`);return i(t,n,e,r)}function Dd(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=Mt[i].compareTokens(n,o,r);return s===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),s}function Rd(t,e){if(t[0]instanceof F&&e[0]instanceof F){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,Mt,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=p.uint.majorEncoded,Mc=p.negint.majorEncoded,Ld=p.bytes.majorEncoded,Fd=p.string.majorEncoded,Kc=p.array.majorEncoded,Hi=p.map.majorEncoded,Ud=p.float.majorEncoded|Zn,kd=p.float.majorEncoded|Gn,Nd=p.float.majorEncoded|Xn,Od=p.float.majorEncoded|Wn,Pd=BigInt(-1),Md=BigInt(1);function xt(t,e,r){r<24?t.pushByte(e|Number(r)):ie(t,e,r)}function Kd(t){return t.addBreakTokens!==!0}function Vd(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(Hi);return}o=sr.createCheck(o,e);let c=!i&&n.ignoreUndefinedProperties,u=new Array(a),f=0;for(let l of s){let y=i?e.get(l):e[l];c&&y===void 0||(u[f++]=[Pt(l,n,o),y])}if(f===0){t.pushByte(Hi);return}f<a&&(u.length=f),u.sort((l,y)=>zi(l,y,n)),xt(t,Hi,f);for(let[l,y]of u)ir(t,l,Mt,n),ji(t,y,n,o)}function ji(t,e,r,n){let o=Oi(e),i=r.typeEncoders&&r.typeEncoders[o];if(i){let s=i(e,o,r,n);if(s!=null){ir(t,s,Mt,r);return}}switch(o){case"null":t.pushByte(Nd);return;case"undefined":t.pushByte(Od);return;case"boolean":t.pushByte(e?kd:Ud);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?jr(t,new F(p.float,e),r):e>=0?xt(t,Pc,e):xt(t,Mc,e*-1-1);return;case"bigint":e>=BigInt(0)?xt(t,Pc,e):xt(t,Mc,e*Pd-Md);return;case"string":{let s=Kn(e);xt(t,Fd,s.length),t.push(s);return}case"Uint8Array":xt(t,Ld,e.length),t.push(e);return;case"Array":if(!e.length){t.pushByte(Kc);return}n=sr.createCheck(n,e),xt(t,Kc,e.length);for(let s of e)ji(t,s,r,n);return;case"Object":case"Map":if(r.mapSorter===zi)Vd(t,e,o,r,n);else{let s=We.Object(e,o,r,n);ir(t,s,Mt,r)}return;default:{let s=We[o];if(!s)throw new Error(`${$n} unsupported type: ${o}`);let a=s(e,o,r,n);ir(t,a,Mt,r)}}}function $c(t,e,r,n){let o=n instanceof Uint8Array,i=o?new Vn(n):to,s=Pt(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return o?(i.push(a),i.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let u=c.encodedSize(s,r);if(o||(i=new $r(u)),c(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():Vr(i.chunks[0])}}return i.reset(),ir(i,s,e,r),i.toBytes(!0)}function Yi(t,e){return e=Object.assign({},Cd,e),Kd(e)?(to.reset(),ji(to,t,e,void 0),to.toBytes(!0)):$c(t,Mt,e)}var $d={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},ro=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=Me[e];if(r===void 0){let n=D[e];if(!n)throw new Error(`${M} 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}},Et=Symbol.for("DONE"),ar=Symbol.for("BREAK");function qd(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=St(e,r);if(i===ar){if(t.value===1/0)break;throw new Error(`${M} got unexpected break to lengthed array`)}if(i===Et)throw new Error(`${M} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Hd(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=St(e,r);if(c===ar){if(t.value===1/0)break;throw new Error(`${M} got unexpected break to lengthed map`)}if(c===Et)throw new Error(`${M} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${M} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${M} found repeat map key "${c}"`);let u=St(e,r);if(u===Et)throw new Error(`${M} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,u):i[c]=u}return n?s:i}function*zd(t,e,r){for(let n=0;n<t.value;n++){let o=St(e,r);if(o===ar){if(t.value===1/0)break;throw new Error(`${M} got unexpected break to lengthed map`)}if(o===Et)throw new Error(`${M} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let i=St(e,r);if(i===Et)throw new Error(`${M} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,i]}}function jd(t,e){let r=function(){if(r._called)throw new Error(`${M} tag decode() may only be called once`);r._called=!0;let n=St(t,e);if(n===Et)throw new Error(`${M} tag content missing`);if(n===ar)throw new Error(`${M} got unexpected break in tag content`);return n};return r.entries=function(){if(r._called)throw new Error(`${M} tag decode() may only be called once`);r._called=!0;let n=t.next();if(!p.equals(n.type,p.map))throw new Error(`${M} entries() requires map content, got ${n.type.name}`);let o=[];for(let i of zd(n,t,e))o.push(i);return o},r._called=!1,r}function St(t,e){if(t.done())return Et;let r=t.next();if(p.equals(r.type,p.break))return ar;if(r.type.terminal)return r.value;if(p.equals(r.type,p.array))return qd(r,t,e);if(p.equals(r.type,p.map))return Hd(r,t,e);if(p.equals(r.type,p.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=jd(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${M} tag decoder must call decode() or entries()`);return o}throw new Error(`${M} tag not supported (${r.value})`)}throw new Error("unsupported")}function qc(t,e){if(!(t instanceof Uint8Array))throw new Error(`${M} data to decode must be a Uint8Array`);e=Object.assign({},$d,e);let r=Vr(t),n=e.tokenizer||new ro(r,e),o=St(n,e);if(o===Et)throw new Error(`${M} did not find any content to decode`);if(o===ar)throw new Error(`${M} got unexpected break`);return[o,t.subarray(n.pos())]}function Zi(t,e){let[r,n]=qc(t,e);if(n.length>0)throw new Error(`${M} too many terminals, data makes no sense`);return r}var no=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(no.prototype,Symbol.toStringTag,{value:"Tagged"});var Hc=42;function Zd(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function Gd(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=W.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new F(p.tag,Hc),new F(p.bytes,r)]}function Xd(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Wd(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 Qd(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 Gi={float64:!0,typeEncoders:{Map:Qd,Object:Gd,undefined:Xd,number:Wd}},ng={...Gi,typeEncoders:{...Gi.typeEncoders}};function Jd(t){let e=t();if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return W.decode(e.subarray(1))}var Xi={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[Hc]:Jd}},og={...Xi,tags:{...Xi.tags}};var zc=t=>Yi(t,Gi),jc=t=>Zi(Zd(t),Xi);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"}},oo=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var Yr=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var io=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Zr=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 Wi=Symbol.for("@libp2p/peer-id");function th(t){return typeof t?.handleEvent=="function"}function rh(t){return(t!==!0&&t!==!1&&t?.once)??!1}var so=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=rh(n);super.addEventListener(e,s=>{if(o){let a=this.#e.get(s.type);a!=null&&(a=a.filter(({callback:c})=>c!==r),this.#e.set(s.type,a))}th(r)?r.handleEvent(s):r(s)},n);let i=this.#e.get(e);i==null&&(i=[],this.#e.set(e,i)),i.push({callback:r,once:o})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==r),this.#e.set(e,o))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var ot="/",Zc=new TextEncoder().encode(ot),ao=Zc[0],cr=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=te(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]!==ao)throw new Error("Invalid key")}toString(e="utf8"){return Y(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=Zc),this._buf[0]!==ao){let e=new Uint8Array(this._buf.byteLength+1);e.fill(ao,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===ao;)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 nh(this.baseNamespace())}name(){return oh(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(),...ih(e.map(r=>r.namespaces()))])}};function nh(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function oh(t){let e=t.split(":");return e[e.length-1]}function ih(t){return[].concat(...t)}var Gc=114,Xc=0;var Wc=te("/ipns/"),co="/ipns/";function Qc(t,e){return t.code===e}var uo="/dht/record/",ah="/ipns/metadata/";function Gr(t){return new cr(uo+Y(t,"base32"),!1)}function fo(t){return new cr(ah+Y(t,"base32"),!1)}function Jc(t,e){let r=Date.now();return t.getTime()+1728e5-r<864e5||e.getTime()-r<864e5}function eu(t,e,r){let n=te(e);return bt([t,r,n],t.byteLength+r.byteLength+n.byteLength)}function lo(t){let e=te("ipns-signature:");return bt([e,t])}function Qi(t){try{return`/ipfs/${W.decode(t)}`}catch{}return Y(t)}function it(t){return bt([Wc,t.bytes])}function ho(t){return ht(t.slice(Wc.length))}function tu(t){return Ee(zc(t))}function ke(t){if(t==null)throw new _n("Record data is missing");let e=jc(t);if(e.ValidityType===0&&(e.ValidityType=Z.ValidityType.EOL),e.ValidityType!==Z.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 ru(t){if(t!=null){if(Pn(t))return`/ipns/${t.toCID().toV1().toString(xe)}`;let e=ou(t);if(e!=null)return e.code===Gc?`/ipns/${e.toV1().toString(xe)}`:`/ipfs/${e.toV1()}`;if(uh(t))return`/ipns/${xe.encode(t.bytes)}`;let r=t.toString().trim();if(r.startsWith("/ipfs/")){let[,n,...o]=r.split("/").filter(i=>i.trim()!=="");return`/ipfs/${W.parse(n).toV1()}${o.length>0?`/${o.join("/")}`:""}`}if(r.startsWith("/")&&r.length>1)return r}throw new mt("Value must be a valid content path starting with /")}function ch(t){return typeof t.code=="number"&&t.digest instanceof Uint8Array&&typeof t.size=="number"&&t.bytes instanceof Uint8Array}function Xr(t){if(t!=null){if(Pn(t))return{digest:t.toMultihash(),path:"/"};let e=ou(t);if(e!=null){if(e.code!==Gc)throw new mt("CIDs must have the `libp2p-key` codec");return{digest:e.multihash,path:"/"}}if(ch(t))return{digest:t,path:"/"};if(t=t.toString(),t.startsWith("/ipns/")){let[,,r,...n]=t.split("/"),o=xe;(r.startsWith("1")||r.startsWith("Q"))&&(r=`z${r}`,o=G);let i=o.decode(r),s;try{s=W.decode(i).multihash}catch{s=ht(i)}return{digest:s,path:`/${n.join("/")}`}}}throw new mt("Value must be a valid IPNS path starting with /")}function nu(t,e){if(!le(e.Value,t.value??new Uint8Array(0)))throw new Ne('Field "value" did not match between protobuf and CBOR');if(!le(e.Validity,t.validity??new Uint8Array(0)))throw new Ne('Field "validity" did not match between protobuf and CBOR');if(e.ValidityType!==t.validityType)throw new Ne('Field "validityType" did not match between protobuf and CBOR');if(e.Sequence!==t.sequence)throw new Ne('Field "sequence" did not match between protobuf and CBOR');if(e.TTL!==t.ttl)throw new Ne('Field "ttl" did not match between protobuf and CBOR')}function uh(t){return t.bytes instanceof Uint8Array}function fh(t){return typeof t?.toCID=="function"}function ou(t){if(fh(t))return t.toCID();try{return W.parse(t)}catch{}return W.asCID(t)}function ur(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===Z.ValidityType.EOL&&s.ValidityType===Z.ValidityType.EOL){let u=Ji.default.fromString(Y(i.Validity)).toDate(),f=Ji.default.fromString(Y(s.Validity)).toDate();if(u.getTime()>f.getTime())return-1;if(u.getTime()<f.getTime())return 1}return 0}),r[0].index}var iu=ri(Nn(),1);var lh=1024*10;async function vt(t,e,r,n){if(e.byteLength>lh)throw new Cn("The record is too large");let o=Z.decode(e);if(o.signatureV2==null)throw new Ne("Missing signatureV2");let i=ke(o.data),s=Y(i.Validity),a,c=ho(t);if(Qc(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 Dn("Could not extract public key from IPNS record or routing key");let u;try{if(o.data==null)throw new Error("Missing data");let f=lo(o.data);u=await a.verify(f,o.signatureV2,n)}catch{u=!1}if(!u)throw new Ne("Record signature verification failed");if(i.ValidityType===Z.ValidityType.EOL){if(iu.default.fromString(s).toDate().getTime()<Date.now())throw new Bn("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 fr=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}=Xr(e);for(;;){let o=it(n),i=await this.#e(o,r),s="";if(i.data!=null){let a=ke(i.data);s=Qi(a.Value)}else if(i.value!=null)s=Qi(i.value);else throw new mt(`Record for key ${xe.encode(n.bytes)} contained no value`);if(yield{record:i,value:s},!s.startsWith(co))break;({digest:n}=Xr(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:u}=await this.localStore.get(e,r);this.log("record retrieved from cache");let f;r.validate===!1?(f=Z.decode(c),this.log("skipped validation of record")):(f=await vt(e,c,this.keychain,r),this.log("record was valid"));let l=ke(f.data),y=Number((l.TTL??vn)/1000000n);if(u.getTime()+y>Date.now())return this.log("record TTL was valid"),f;if(r.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),f;this.log("record TTL has been reached, searching routing for updates"),n.push(f)}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 Fr("Record was not present in the cache or has expired");this.log("did not have record locally");let i=0,s=[];if(await Promise.all(this.routers.map(async c=>{let u;try{u=await c.get(e,{...r,validate:!1})}catch(f){this.log.error("error finding IPNS record using router %s - %e",c.toString(),f),s.push(f);return}try{let f;r.validate===!1?f=Z.decode(u):f=await vt(e,u,this.keychain,r),n.push(f)}catch(f){i++,this.log.error("error validating IPNS record from router %s - %e",c.toString(),f)}})),n.length===0)throw i>0?new An(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`):new Fr("Could not find record for routing key");let a=n[ur(e,n)];return await this.localStore.put(e,Z.encode(a),r),a}};var ae=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};function po(t,e){if(typeof t=="string")return dh(t);if(typeof t=="number")return mh(t,e);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}function dh(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 hh(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 ph(t){let e=Math.abs(t);return e>=315576e5?Kt(t,e,315576e5,"year"):e>=26298e5?Kt(t,e,26298e5,"month"):e>=6048e5?Kt(t,e,6048e5,"week"):e>=864e5?Kt(t,e,864e5,"day"):e>=36e5?Kt(t,e,36e5,"hour"):e>=6e4?Kt(t,e,6e4,"minute"):e>=1e3?Kt(t,e,1e3,"second"):`${t} ms`}function mh(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?ph(t):hh(t)}function Kt(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function es(t){r.debug=r,r.default=r,r.coerce=c,r.disable=i,r.enable=o,r.enabled=s,r.humanize=po,r.destroy=u,Object.keys(t).forEach(f=>{r[f]=t[f]}),r.names=[],r.skips=[],r.formatters={};function e(f){let l=0;for(let y=0;y<f.length;y++)l=(l<<5)-l+f.charCodeAt(y),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=e;function r(f,l){let y,m=null,T,A;function h(...g){if(!h.enabled)return;let v=h,C=Number(new Date),O=C-(y||C);v.diff=O,v.prev=y,v.curr=C,y=C,g[0]=r.coerce(g[0]),typeof g[0]!="string"&&g.unshift("%O");let k=0;g[0]=g[0].replace(/%([a-zA-Z%])/g,(N,E)=>{if(N==="%%")return"%";k++;let B=r.formatters[E];if(typeof B=="function"){let U=g[k];N=B.call(v,U),g.splice(k,1),k--}return N}),r.formatArgs.call(v,g),l?.onLog!=null&&l.onLog(...g),(v.log||r.log).apply(v,g)}return h.namespace=f,h.useColors=r.useColors(),h.color=r.selectColor(f),h.extend=n,h.destroy=r.destroy,Object.defineProperty(h,"enabled",{enumerable:!0,configurable:!1,get:()=>m!==null?m:(T!==r.namespaces&&(T=r.namespaces,A=r.enabled(f)),A),set:g=>{m=g}}),typeof r.init=="function"&&r.init(h),h}function n(f,l){let y=r(this.namespace+(typeof l>"u"?":":l)+f);return y.log=this.log,y}function o(f){r.save(f),r.namespaces=f,r.names=[],r.skips=[];let l,y=(typeof f=="string"?f:"").split(/[\s,]+/),m=y.length;for(l=0;l<m;l++)y[l]&&(f=y[l].replace(/\*/g,".*?"),f[0]==="-"?r.skips.push(new RegExp("^"+f.substr(1)+"$")):r.names.push(new RegExp("^"+f+"$")))}function i(){let f=[...r.names.map(a),...r.skips.map(a).map(l=>"-"+l)].join(",");return r.enable(""),f}function s(f){if(f[f.length-1]==="*")return!0;let l,y;for(l=0,y=r.skips.length;l<y;l++)if(r.skips[l].test(f))return!1;for(l=0,y=r.names.length;l<y;l++)if(r.names[l].test(f))return!0;return!1}function a(f){return f.toString().substring(2,f.toString().length-2).replace(/\.\*\?$/,"*")}function c(f){return f instanceof Error?f.stack??f.message:f}function u(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var mo=Sh(),yh=["#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 gh(){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 bh(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+po(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 wh=console.debug??console.log??(()=>{});function xh(t){try{t?mo?.setItem("debug",t):mo?.removeItem("debug")}catch{}}function Eh(){let t;try{t=mo?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function Sh(){try{return localStorage}catch{}}function vh(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var su=es({formatArgs:bh,save:xh,load:Eh,useColors:gh,setupFormatters:vh,colors:yh,storage:mo,log:wh});var Se=su;Se.formatters.b=t=>t==null?"undefined":G.baseEncode(t);Se.formatters.t=t=>t==null?"undefined":dt.baseEncode(t);Se.formatters.m=t=>t==null?"undefined":xi.baseEncode(t);Se.formatters.p=t=>t==null?"undefined":t.toString();Se.formatters.c=t=>t==null?"undefined":t.toString();Se.formatters.k=t=>t==null?"undefined":t.toString();Se.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 wh(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function ou(t,e=""){if(wh(t)){let r=ru(t,e);return t.errors.length>0?(e=`${e} `,r+=`
11
- ${e}${t.errors.map(n=>`${ou(n,`${e}`)}`).join(`
10
+ ${e}`)}`:r!=null?`${r}`:`${t.toString()}`}function Ah(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function uu(t,e=""){if(Ah(t)){let r=au(t,e);return t.errors.length>0?(e=`${e} `,r+=`
11
+ ${e}${t.errors.map(n=>`${uu(n,`${e}`)}`).join(`
12
12
  ${e}`)}`):r+=`
13
- ${e}[Error list was empty]`,r.trim()}return ru(t,e)}Ee.formatters.e=t=>t==null?"undefined":ou(t);function xh(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 Gr(t,e){let r=xh(`${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=>Gr(`${t}:${n}`,e)})}function nu(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var iu=Go(Un(),1);var Eh=Gr("ipns"),Sh=300000000000n;async function ar(t,e,r,n,o){r=BigInt(r);let i=re(e),s=o?.ttlNs??Sh,a=new iu.default(Date.now()+Number(n)),c=Z.ValidityType.EOL,u=re(a.toString()),f=Xc({...o?.data??{},Value:i,Validity:u,ValidityType:0,Sequence:r,TTL:s}),l=oo(f),y=await t.sign(l,o),p;return o?.v1Compatible===!1?p={signatureV2:y,data:f}:p={value:i,signatureV1:await vh(t,i,c,u),validityType:c,validity:u,sequence:r,ttl:s,signatureV2:y,data:f},Ah(t.publicKey)&&(p.publicKey=t.publicKey.toProtobuf()),p}var vh=async(t,e,r,n,o)=>{try{let i=Gc(e,r,n);return await t.sign(i,o)}catch(i){throw Eh.error("record signature creation failed",i),new An("Record signature creation failed")}};function Ah(t){return t.toMultihash().code!==zc}var co=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),y=Z.decode(l);a=(Ne(y.data).Sequence??0n)+1n}let c=n.lifetime??1728e5,u=await ar(o,r,a,c,{...n,ttlNs:n.ttl!=null?BigInt(n.ttl)*1000000n:void 0}),f=Z.encode(u);return n.offline===!0?await this.localStore.put(s,f,{...n,metadata:{keyName:e,lifetime:c}}):await Promise.all(this.routers.map(async l=>{await l.put(s,f,{...n,metadata:{keyName:e,lifetime:c}})})),{record:u,name:`/ipns/${o.publicKey.toCID().toString(we)}`,publicKey:o.publicKey}}catch(o){throw n.onProgress?.(new se("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 cr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var uo=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}},ur=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new uo(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 uo(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 Zi=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function su(t={}){return Th(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 Th(t,e){e=e??{};let r=e.onEnd,n=new ur,o,i,s,a=cr(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((h,g)=>{i=v=>{i=null,n.push(v);try{h(t(n))}catch(C){g(C)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=cr()})}},u=h=>i!=null?i(h):(n.push(h),o),f=h=>(n=new ur,i!=null?i({error:h}):(n.push({error:h}),o)),l=h=>{if(s)return o;if(e?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:h})},y=h=>s?o:(s=!0,h!=null?f(h):u({done:!0})),p=()=>(n=new ur,y(),{done:!0}),T=h=>(y(h),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:T,push:l,end:y,get readableLength(){return n.size},onEmpty:async h=>{let g=h?.signal;if(g?.throwIfAborted(),n.isEmpty())return;let v,C;g!=null&&(v=new Promise((O,N)=>{C=()=>{N(new Zi)},g.addEventListener("abort",C)}));try{await Promise.race([a.promise,v])}finally{C!=null&&g!=null&&g?.removeEventListener("abort",C)}}},r==null)return o;let A=o;return o={[Symbol.asyncIterator](){return this},next(){return A.next()},throw(h){return A.throw(h),r!=null&&(r(h),r=void 0),{done:!0}},return(){return A.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(h){return A.end(h),r!=null&&(r(h),r=void 0),o},get readableLength(){return A.readableLength},onEmpty:h=>A.onEmpty(h)},o}var Gi=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},au=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Xi(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,c,f=new Promise((l,y)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){y(au(s));return}if(s&&(c=()=>{y(au(s))},s.addEventListener("abort",c,{once:!0})),t.then(l,y),r===Number.POSITIVE_INFINITY)return;let p=new Gi;a=i.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(T){y(T)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?l():o instanceof Error?y(o):(p.message=o??`Promise timed out after ${r} milliseconds`,y(p))},r)}).finally(()=>{f.clear(),c&&s&&s.removeEventListener("abort",c)});return f.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},f}var Ih=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 Bh(t,e,r){let n,o=new Promise((i,s)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:u,removeListener:f}=Ih(t),l=async(...p)=>{let T=r.multiArgs?p:p[0];if(r.filter)try{if(!await r.filter(T))return}catch(A){n(),s(A);return}c.push(T),r.count===c.length&&(n(),i(c))},y=(...p)=>{n(),s(r.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)f(p,l);for(let p of r.rejectionEvents)a.includes(p)||f(p,y)};for(let p of a)u(p,l);for(let p of r.rejectionEvents)a.includes(p)||u(p,y);r.signal&&r.signal.addEventListener("abort",()=>{y(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(o.cancel=n,typeof r.timeout=="number"){let i=Xi(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function fo(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Bh(t,e,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function Xr(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 lo=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function Ch(t){return t.reason}async function ho(t,e,r){if(e==null)return t;let n=r?.translateError??Ch;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var po=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=cr(),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 _h(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var mo=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,r){this.id=_h(),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 po(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 ho(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 fr=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=Xr(this.emitEmpty.bind(this),1),this.emitIdle=Xr(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 lo;let n=new mo(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 fo(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await fo(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await fo(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=su({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 Wr(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 cu=Symbol.for("sindresorhus/unlimited-timeout#brand");function uu(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={[cu]:!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(),u=Math.max(0,i-c);s(u)},2147483647),n&&o.id?.unref?.()))};return s(e),o}function fu(t){!t||typeof t!="object"||!t[cu]||(t.cleared=!0,t.id!==void 0&&(globalThis.clearTimeout(t.id),t.id=void 0))}var Dh=new WeakMap;function Lh({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,u=()=>{c(i),a(o.reason)},f=()=>{o&&o.removeEventListener("abort",u)},l=new Promise((y,p)=>{s=()=>{f(),y(n)},a=p,i=(e??setTimeout)(s,r)});return o&&o.addEventListener("abort",u,{once:!0}),Dh.set(l,()=>{c(i),i=null,s()}),l}}var Rh=Lh({setTimeout:uu,clearTimeout:fu}),lu=Rh;function du(t,e,r){let n,o,i=!1;function s(){let u={signal:o.signal},f;r?.timeout!=null&&(f=Wr([o.signal,AbortSignal.timeout(r.timeout)]),u.signal=f),i=!0,Promise.resolve().then(async()=>{await t(u)}).catch(()=>{}).finally(()=>{f!=null&&(f.aborted?f.clear():f.addEventListener("abort",()=>{f.clear()},{once:!0})),i=!1,!o.signal.aborted&&(n=setTimeout(s,e))})}let a=Xr(s,r?.debounce??100),c=!1;return{setInterval:u=>{e!==u&&(e=u,n!=null&&(clearTimeout(n),n=setTimeout(s,e)))},setTimeout:u=>{r??={},r.timeout=u},run:()=>{i||(clearTimeout(n),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,e))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var yo=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||ca,this.started=!1,this.routers=r.routers??[],this.republishTask=du(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 fr({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 u;try{u=Z.decode(s)}catch{this.log.trace("skipping invalid record %b because could not decode",i);continue}if(u.data==null){this.log.trace("skipping record %b because data was missing",i);continue}let f;try{f=Ne(u.data)}catch{this.log.trace("skipping record %b because could not decode data",i);continue}if(!Zc(c,new Date(Y(f.Validity)))){this.log.trace("skipping record %b within republish threshold",i);continue}let l=f.Sequence+1n,y=f.TTL??En,p;try{p=await this.keychain.exportKey(a.keyName)}catch(T){this.log.error("missing key %s, skipping republishing record - %e",a.keyName,T);continue}try{let T=await ar(p,Y(f.Value),l,a.lifetime,{...e,ttlNs:y});n.push({routingKey:i,record:T})}catch(T){this.log.error("error creating updated IPNS record for %s - %e",i,T);continue}}this.log(`found ${n.length}/${o} records to republish`);for(let{routingKey:i,record:s}of n)r.add(async()=>{try{let a=Z.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 Qr;(function(t){let e;t.codec=()=>(e==null&&(e=Ge((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:Re(0),value:Re(0),timeReceived:""},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.key=i.bytes();break}case 2:{c.value=i.bytes();break}case 5:{c.timeReceived=i.string();break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.key`,value:i.bytes()};break}case 2:{yield{field:`${a}.value`,value:i.bytes()};break}case 5:{yield{field:`${a}.timeReceived`,value:i.string()};break}default:{i.skipType(f&7);break}}}})),e);function r(i){return Ye(i,t.codec())}t.encode=r;function n(i,s){return je(i,t.codec(),s)}t.decode=n;function o(i,s){return Ze(i,t.codec(),s)}t.stream=o})(Qr||(Qr={}));function hu(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 pu(t){let e=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),r=String(t).trim().match(e);if(r==null)throw new Error("Invalid format");let n=parseInt(r[1],10),o=parseInt(r[2],10)-1,i=parseInt(r[3],10),s=parseInt(r[4],10),a=parseInt(r[5],10),c=parseInt(r[6],10),u=parseInt(r[7].slice(0,-6),10);return new Date(Date.UTC(n,o,i,s,a,c,u))}var 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 Qr.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:hu(this.timeReceived)}}static deserialize(e){let r=Qr.decode(e);return new t(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(e){let r=pu(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 mu(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 Nh=parseInt("11111",2),Wi=parseInt("10000000",2),kh=parseInt("01111111",2),yu={0:Jr,1:Jr,2:Oh,3:Kh,4:Vh,5:Mh,6:Ph,16:Jr,22:Jr,48:Jr};function Qi(t,e={offset:0}){let r=t[e.offset]&Nh;if(e.offset++,yu[r]!=null)return yu[r](t,e);throw new Error("No decoder for tag "+r)}function en(t,e){let r=0;if((t[e.offset]&Wi)===Wi){let n=t[e.offset]&kh,o="0x";e.offset++;for(let i=0;i<n;i++,e.offset++)o+=t[e.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=t[e.offset],e.offset++;return r}function Jr(t,e){en(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=Qi(t,e);if(n===null)break;r.push(n)}return r}function Oh(t,e){let r=en(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 Ph(t,e){let r=en(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function Mh(t,e){return e.offset++,null}function Kh(t,e){let r=en(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 Vh(t,e){let r=en(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function $h(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new Te;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Ji(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=$h(t.byteLength);return new Te(Uint8Array.from([e.byteLength|Wi]),e)}function gu(t){let e=new Te,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new Te(Uint8Array.from([2]),Ji(e),e)}function bu(t){let e=Uint8Array.from([0]),r=new Te(e,t);return new Te(Uint8Array.from([3]),Ji(r),r)}function go(t,e=48){let r=new Te;for(let n of t)r.append(n);return new Te(Uint8Array.from([e]),Ji(r),r)}var qh=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Hh=Uint8Array.from([6,5,43,129,4,0,34]),zh=Uint8Array.from([6,5,43,129,4,0,35]),jh={ext:!0,kty:"EC",crv:"P-256"},Yh={ext:!0,kty:"EC",crv:"P-384"},Zh={ext:!0,kty:"EC",crv:"P-521"},es=32,ts=48,rs=66;function wu(t){let e=Qi(t);return xu(e)}function xu(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===es*2+1)return n=Y(e.subarray(r,r+es),"base64url"),o=Y(e.subarray(r+es),"base64url"),new lr({...jh,key_ops:["verify"],x:n,y:o});if(e.byteLength===ts*2+1)return n=Y(e.subarray(r,r+ts),"base64url"),o=Y(e.subarray(r+ts),"base64url"),new lr({...Yh,key_ops:["verify"],x:n,y:o});if(e.byteLength===rs*2+1)return n=Y(e.subarray(r,r+rs),"base64url"),o=Y(e.subarray(r+rs),"base64url"),new lr({...Zh,key_ops:["verify"],x:n,y:o});throw new nt(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Eu(t){return go([gu(Uint8Array.from([1])),go([Gh(t.crv)],160),go([bu(new Te(Uint8Array.from([4]),re(t.x??"","base64url"),re(t.y??"","base64url")))],161)]).subarray()}function Gh(t){if(t==="P-256")return qh;if(t==="P-384")return Hh;if(t==="P-521")return zh;throw new nt(`Invalid curve ${t}`)}var lr=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Eu(this.jwk)),this._raw}toMultihash(){return Pe.digest(dr(this))}toCID(){return Q.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:fe(this.raw,e.raw)}async verify(e,r,n){return mu(this.jwk,r,e,n)}};function ns(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function At(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(`${r}expected number, got ${typeof t}`)}if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new RangeError(`${r}expected integer >= 0, got ${t}`)}}function De(t,e,r=""){let n=ns(t),o=t?.length,i=e!==void 0;if(!n||i&&o!==e){let s=r&&`"${r}" `,a=i?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof t}`,u=s+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return t}function bo(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(At(t.outputLen),At(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function hr(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function wo(t,e){De(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function at(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function xo(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Ve(t,e){return t<<32-e|t>>>e}var vu=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Xh=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Eo(t){if(De(t),vu)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Xh[t[r]];return e}var st={_0:48,_9:57,A:65,F:70,a:97,f:102};function Su(t){if(t>=st._0&&t<=st._9)return t-st._0;if(t>=st.A&&t<=st.F)return t-(st.A-10);if(t>=st.a&&t<=st.f)return t-(st.a-10)}function tn(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(vu)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=Su(t.charCodeAt(i)),a=Su(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 os(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];De(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 is(t,e={}){let r=(o,i)=>t(i).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function Au(t=32){At(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 ss=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Tu(t,e,r){return t&e^~t&r}function Iu(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=xo(this.buffer)}update(e){hr(this),De(e);let{view:r,buffer:n,blockLen:o}=this,i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=xo(e);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){hr(this),wo(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,at(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),i),this.process(n,0);let a=xo(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],i)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return e.destroyed=s,e.finished=i,e.length=o,e.pos=a,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},ct=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var he=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var So=BigInt(4294967295),Bu=BigInt(32);function Wh(t,e=!1){return e?{h:Number(t&So),l:Number(t>>Bu&So)}:{h:Number(t>>Bu&So)|0,l:Number(t&So)|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}=Wh(t[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var as=(t,e,r)=>t>>>r,cs=(t,e,r)=>t<<32-r|e>>>r,Pt=(t,e,r)=>t>>>r|e<<32-r,Mt=(t,e,r)=>t<<32-r|e>>>r,nn=(t,e,r)=>t<<64-r|e>>>r-32,on=(t,e,r)=>t>>>r-32|e<<64-r;function Qe(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var _u=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Du=(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),Ru=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Fu=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Uu=(t,e,r,n,o,i)=>e+r+n+o+i+(t/2**32|0)|0;var Jh=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]),Tt=new Uint32Array(64),us=class extends rn{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,r,n,o,i,s,a,c]}set(e,r,n,o,i,s,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,r){for(let l=0;l<16;l++,r+=4)Tt[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let y=Tt[l-15],p=Tt[l-2],T=Ve(y,7)^Ve(y,18)^y>>>3,A=Ve(p,17)^Ve(p,19)^p>>>10;Tt[l]=A+Tt[l-7]+T+Tt[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let y=Ve(a,6)^Ve(a,11)^Ve(a,25),p=f+y+Tu(a,c,u)+Jh[l]+Tt[l]|0,A=(Ve(n,2)^Ve(n,13)^Ve(n,22))+Iu(n,o,i)|0;f=u,u=c,c=a,a=s+p|0,s=i,i=o,o=n,n=p+A|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,i,s,a,c,u,f)}roundClean(){at(Tt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),at(this.buffer)}},fs=class extends us{A=ct[0]|0;B=ct[1]|0;C=ct[2]|0;D=ct[3]|0;E=ct[4]|0;F=ct[5]|0;G=ct[6]|0;H=ct[7]|0;constructor(){super(32)}};var Nu=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))),ep=Nu[0],tp=Nu[1],It=new Uint32Array(80),Bt=new Uint32Array(80),ls=class extends rn{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:y,Gh:p,Gl:T,Hh:A,Hl:h}=this;return[e,r,n,o,i,s,a,c,u,f,l,y,p,T,A,h]}set(e,r,n,o,i,s,a,c,u,f,l,y,p,T,A,h){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=y|0,this.Gh=p|0,this.Gl=T|0,this.Hh=A|0,this.Hl=h|0}process(e,r){for(let C=0;C<16;C++,r+=4)It[C]=e.getUint32(r),Bt[C]=e.getUint32(r+=4);for(let C=16;C<80;C++){let O=It[C-15]|0,N=Bt[C-15]|0,K=Pt(O,N,1)^Pt(O,N,8)^as(O,N,7),k=Mt(O,N,1)^Mt(O,N,8)^cs(O,N,7),E=It[C-2]|0,B=Bt[C-2]|0,U=Pt(E,B,19)^nn(E,B,61)^as(E,B,6),_=Mt(E,B,19)^on(E,B,61)^cs(E,B,6),d=Lu(k,_,Bt[C-7],Bt[C-16]),b=Ru(d,K,U,It[C-7],It[C-16]);It[C]=b|0,Bt[C]=d|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:y,Fh:p,Fl:T,Gh:A,Gl:h,Hh:g,Hl:v}=this;for(let C=0;C<80;C++){let O=Pt(l,y,14)^Pt(l,y,18)^nn(l,y,41),N=Mt(l,y,14)^Mt(l,y,18)^on(l,y,41),K=l&p^~l&A,k=y&T^~y&h,E=Fu(v,N,k,tp[C],Bt[C]),B=Uu(E,g,O,K,ep[C],It[C]),U=E|0,_=Pt(n,o,28)^nn(n,o,34)^nn(n,o,39),d=Mt(n,o,28)^on(n,o,34)^on(n,o,39),b=n&i^n&a^i&a,S=o&s^o&c^s&c;g=A|0,v=h|0,A=p|0,h=T|0,p=l|0,T=y|0,{h:l,l:y}=Qe(u|0,f|0,B|0,U|0),u=a|0,f=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let w=_u(U,d,S);n=Du(w,B,_,b),o=w|0}({h:n,l:o}=Qe(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Qe(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Qe(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Qe(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:y}=Qe(this.Eh|0,this.El|0,l|0,y|0),{h:p,l:T}=Qe(this.Fh|0,this.Fl|0,p|0,T|0),{h:A,l:h}=Qe(this.Gh|0,this.Gl|0,A|0,h|0),{h:g,l:v}=Qe(this.Hh|0,this.Hl|0,g|0,v|0),this.set(n,o,i,s,a,c,u,f,l,y,p,T,A,h,g,v)}roundClean(){at(It,Bt)}destroy(){this.destroyed=!0,at(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ds=class extends ls{Ah=he[0]|0;Al=he[1]|0;Bh=he[2]|0;Bl=he[3]|0;Ch=he[4]|0;Cl=he[5]|0;Dh=he[6]|0;Dl=he[7]|0;Eh=he[8]|0;El=he[9]|0;Fh=he[10]|0;Fl=he[11]|0;Gh=he[12]|0;Gl=he[13]|0;Hh=he[14]|0;Hl=he[15]|0;constructor(){super(64)}};var ku=is(()=>new fs,ss(1));var vo=is(()=>new ds,ss(3));var H=(t,e,r)=>De(t,e,r),ps=At,pr=Eo,ae=(...t)=>os(...t),mr=t=>tn(t),Kt=ns,sn=t=>Au(t),To=BigInt(0),hs=BigInt(1);function $e(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function Io(t){if(typeof t=="bigint"){if(!Ao(t))throw new RangeError("positive bigint expected, got "+t)}else ps(t);return t}function qe(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 an(t){let e=Io(t).toString(16);return e.length&1?"0"+e:e}function Ou(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?To:BigInt("0x"+t)}function Vt(t){return Ou(Eo(t))}function Je(t){return Ou(Eo(cn(De(t)).reverse()))}function Bo(t,e){if(At(e),e===0)throw new RangeError("zero length");t=Io(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return tn(r.padStart(e*2,"0"))}function ms(t,e){return Bo(t,e).reverse()}function Pu(t,e){if(t=H(t),e=H(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function cn(t){return Uint8Array.from(H(t))}function Co(t){if(typeof t!="string")throw new TypeError("ascii string expected, got "+typeof t);return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var Ao=t=>typeof t=="bigint"&&To<=t;function rp(t,e,r){return Ao(t)&&Ao(e)&&Ao(r)&&e<=t&&t<r}function yr(t,e,r,n){if(!rp(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function gr(t){if(t<To)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>To;t>>=hs,e+=1);return e}var un=t=>(hs<<BigInt(t))-hs;function Mu(t,e,r){if(At(t,"hashLen"),At(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=h=>new Uint8Array(h),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,l=()=>{c.fill(1),u.fill(0),f=0},y=(...h)=>r(u,ae(c,...h)),p=(h=o)=>{u=y(i,h),c=y(),h.length!==0&&(u=y(s,h),c=y())},T=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let h=0,g=[];for(;h<e;){c=y();let v=c.slice();g.push(v),h+=c.length}return ae(...g)};return(h,g)=>{l(),p(h);let v;for(;(v=g(T()))===void 0;)p();return l(),v}}function He(t,e={},r={}){if(Object.prototype.toString.call(t)!=="[object Object]")throw new TypeError("expected valid options object");function n(i,s,a){if(!a&&s!=="function"&&!Object.hasOwn(t,i))throw new TypeError(`param "${i}" is invalid: expected own property`);let c=t[i];if(a&&c===void 0)return;let u=typeof c;if(u!==s||c===null)throw new TypeError(`param "${i}" is invalid: expected ${s}, got ${u}`)}let o=(i,s)=>Object.entries(i).forEach(([a,c])=>n(a,c,s));o(e,!1),o(r,!0)}var ys=()=>{throw new Error("not implemented")};var pe=BigInt(0),ee=BigInt(1),$t=BigInt(2),qu=BigInt(3),Hu=BigInt(4),zu=BigInt(5),np=BigInt(7),ju=BigInt(8),op=BigInt(9),Yu=BigInt(16);function ne(t,e){if(e<=pe)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=pe?r:e+r}function W(t,e,r){if(e<pe)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >pe;)n*=n,n%=r;return n}function Ku(t,e){if(t===pe)throw new Error("invert: expected non-zero number");if(e<=pe)throw new Error("invert: expected positive modulus, got "+e);let r=ne(t,e),n=e,o=pe,i=ee,s=ee,a=pe;for(;r!==pe;){let u=n/r,f=n-r*u,l=o-s*u,y=i-a*u;n=r,r=f,o=s,i=a,s=l,a=y}if(n!==ee)throw new Error("invert: does not exist");return ne(o,e)}function gs(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Zu(t,e){let r=t,n=(r.ORDER+ee)/Hu,o=r.pow(e,n);return gs(r,o,e),o}function ip(t,e){let r=t,n=(r.ORDER-zu)/ju,o=r.mul(e,$t),i=r.pow(o,n),s=r.mul(e,i),a=r.mul(r.mul(s,$t),i),c=r.mul(s,r.sub(a,r.ONE));return gs(r,c,e),c}function sp(t){let e=br(t),r=Gu(t),n=r(e,e.neg(e.ONE)),o=r(e,n),i=r(e,e.neg(n)),s=(t+np)/Yu;return((a,c)=>{let u=a,f=u.pow(c,s),l=u.mul(f,n),y=u.mul(f,o),p=u.mul(f,i),T=u.eql(u.sqr(l),c),A=u.eql(u.sqr(y),c);f=u.cmov(f,l,T),l=u.cmov(p,y,A);let h=u.eql(u.sqr(l),c),g=u.cmov(f,l,h);return gs(u,g,c),g})}function Gu(t){if(t<qu)throw new Error("sqrt is not defined for small field");let e=t-ee,r=0;for(;e%$t===pe;)e/=$t,r++;let n=$t,o=br(t);for(;Vu(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Zu;let i=o.pow(n,e),s=(e+ee)/$t;return function(c,u){let f=c;if(f.is0(u))return u;if(Vu(f,u)!==1)throw new Error("Cannot find square root");let l=r,y=f.mul(f.ONE,i),p=f.pow(u,e),T=f.pow(u,s);for(;!f.eql(p,f.ONE);){if(f.is0(p))return f.ZERO;let A=1,h=f.sqr(p);for(;!f.eql(h,f.ONE);)if(A++,h=f.sqr(h),A===l)throw new Error("Cannot find square root");let g=ee<<BigInt(l-A-1),v=f.pow(y,g);l=A,y=f.sqr(v),p=f.mul(p,y),T=f.mul(T,v)}return T}}function ap(t){return t%Hu===qu?Zu:t%ju===zu?ip:t%Yu===op?sp(t):Gu(t)}var ut=(t,e)=>(ne(t,e)&ee)===ee,cp=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function bs(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=cp.reduce((n,o)=>(n[o]="function",n),e);if(He(t,r),qe(t.BYTES,"BYTES"),qe(t.BITS,"BITS"),t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=ee)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function up(t,e,r){let n=t;if(r<pe)throw new Error("invalid exponent, negatives unsupported");if(r===pe)return n.ONE;if(r===ee)return e;let o=n.ONE,i=e;for(;r>pe;)r&ee&&(o=n.mul(o,i)),i=n.sqr(i),r>>=ee;return o}function fn(t,e,r=!1){let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),i=e.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),s=n.inv(i);return e.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),s),o}function Vu(t,e){let r=t,n=(r.ORDER-ee)/$t,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 fp(t,e){if(e!==void 0&&ps(e),t<=pe)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=gr(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${e})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var $u=new WeakMap,_o=class{ORDER;BITS;BYTES;isLE;ZERO=pe;ONE=ee;_lengths;_mod;constructor(e,r={}){if(e<=ee)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:i}=fp(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 ne(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return pe<=e&&e<this.ORDER}is0(e){return e===pe}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&ee)===ee}neg(e){return ne(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ne(e*e,this.ORDER)}add(e,r){return ne(e+r,this.ORDER)}sub(e,r){return ne(e-r,this.ORDER)}mul(e,r){return ne(e*r,this.ORDER)}pow(e,r){return up(this,e,r)}div(e,r){return ne(e*Ku(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 Ku(e,this.ORDER)}sqrt(e){let r=$u.get(this);return r||$u.set(this,r=ap(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?ms(e,this.BYTES):Bo(e,this.BYTES)}fromBytes(e,r=!1){H(e);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,i?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=i?Je(e):Vt(e);if(a&&(c=ne(c,s)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return fn(this,e)}cmov(e,r,n){return $e(n,"condition"),n?r:e}};Object.freeze(_o.prototype);function br(t,e={}){return new _o(t,e)}function Xu(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=ee)throw new Error("field order must be greater than 1");let e=gr(t-ee);return Math.ceil(e/8)}function ws(t){let e=Xu(t);return e+Math.ceil(e/2)}function xs(t,e,r=!1){H(t);let n=t.length,o=Xu(e),i=Math.max(ws(e),16);if(n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Je(t):Vt(t),a=ne(s,e-ee)+ee;return r?ms(a,o):Bo(a,o)}var wr=BigInt(0),qt=BigInt(1);function ln(t,e){let r=e.negate();return t?r:e}function Ht(t,e){let r=fn(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function ef(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Es(t,e){ef(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,i=un(t),s=BigInt(t);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function Wu(t,e,r){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r,a=Number(t&o),c=t>>s;a>n&&(a-=i,c+=qt);let u=e*n,f=u+Math.abs(a)-1,l=a===0,y=a<0,p=e%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:y,isNegF:p,offsetF:u}}var Ss=new WeakMap,tf=new WeakMap;function vs(t){return tf.get(t)||1}function Qu(t){if(t!==wr)throw new Error("invalid wNAF")}var xr=class{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let o=e;for(;r>wr;)r&qt&&(n=n.add(o)),o=o.double(),r>>=qt;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=Es(r,this.bits),i=[],s=e,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let u=1;u<o;u++)a=a.add(s),i.push(a);s=a.double()}return i}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=Es(e,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:y,offsetF:p}=Wu(n,a,s);n=c,f?i=i.add(ln(y,r[p])):o=o.add(ln(l,r[u]))}return Qu(n),{p:o,f:i}}wNAFUnsafe(e,r,n,o=this.ZERO){let i=Es(e,this.bits);for(let s=0;s<i.windows&&n!==wr;s++){let{nextN:a,offset:c,isZero:u,isNeg:f}=Wu(n,s,i);if(n=a,!u){let l=r[c];o=o.add(f?l.negate():l)}}return Qu(n),o}getPrecomputes(e,r,n){let o=Ss.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),Ss.set(r,o))),o}cached(e,r,n){let o=vs(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let i=vs(e);return i===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),r,o)}createCache(e,r){ef(r,this.bits),tf.set(e,r),Ss.delete(e)}hasCache(e){return vs(e)!==1}};function rf(t,e,r,n){let o=e,i=t.ZERO,s=t.ZERO;for(;r>wr||n>wr;)r&qt&&(i=i.add(o)),n&qt&&(s=s.add(o)),o=o.double(),r>>=qt,n>>=qt;return{p1:i,p2:s}}function Ju(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return bs(e),e}else return br(t,{isLE:r})}function Do(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let c of["p","n","h"]){let u=e[c];if(!(typeof u=="bigint"&&u>wr))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Ju(e.p,r.Fp,n),i=Ju(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 Lo(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var Ct=BigInt(0),de=BigInt(1),As=BigInt(2),lp=BigInt(8);function dp(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 nf(t,e={}){let r=e,n=Do("edwards",t,r,r.FpFnLE),{Fp:o,Fn:i}=n,s=n.CURVE,{h:a}=s;He(r,{},{uvRatio:"function"});let c=As<<BigInt(i.BYTES*8)-de,u=A=>o.create(A),f=r.uvRatio===void 0?(A,h)=>{try{return{isValid:!0,value:o.sqrt(o.div(A,h))}}catch{return{isValid:!1,value:Ct}}}:r.uvRatio;if(!dp(o,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function l(A,h,g=!1){let v=g?de:Ct;return yr("coordinate "+A,h,v,c),h}function y(A){if(!(A instanceof p))throw new Error("EdwardsPoint expected")}class p{static BASE=new p(s.Gx,s.Gy,de,u(s.Gx*s.Gy));static ZERO=new p(Ct,de,de,Ct);static Fp=o;static Fn=i;X;Y;Z;T;constructor(h,g,v,C){this.X=l("x",h),this.Y=l("y",g),this.Z=l("z",v,!0),this.T=l("t",C),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){if(h instanceof p)throw new Error("extended point not allowed");let{x:g,y:v}=h||{};return l("x",g),l("y",v),new p(g,v,de,u(g*v))}static fromBytes(h,g=!1){let v=o.BYTES,{a:C,d:O}=s;h=cn(H(h,v,"point")),$e(g,"zip215");let N=cn(h),K=h[v-1];N[v-1]=K&-129;let k=Je(N),E=g?c:o.ORDER;yr("point.y",k,Ct,E);let B=u(k*k),U=u(B-de),_=u(O*B-C),{isValid:d,value:b}=f(U,_);if(!d)throw new Error("bad point: invalid y coordinate");let S=(b&de)===de,w=(K&128)!==0;if(!g&&b===Ct&&w)throw new Error("bad point: x=0 and x_0=1");return w!==S&&(b=u(-b)),p.fromAffine({x:b,y:k})}static fromHex(h,g=!1){return p.fromBytes(mr(h),g)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,g=!0){return T.createCache(this,h),g||this.multiply(As),this}assertValidity(){let h=this,{a:g,d:v}=s;if(h.is0())throw new Error("bad point: ZERO");let{X:C,Y:O,Z:N,T:K}=h,k=u(C*C),E=u(O*O),B=u(N*N),U=u(B*B),_=u(k*g),d=u(B*u(_+E)),b=u(U+u(v*u(k*E)));if(d!==b)throw new Error("bad point: equation left != right (1)");let S=u(C*O),w=u(N*K);if(S!==w)throw new Error("bad point: equation left != right (2)")}equals(h){y(h);let{X:g,Y:v,Z:C}=this,{X:O,Y:N,Z:K}=h,k=u(g*K),E=u(O*C),B=u(v*K),U=u(N*C);return k===E&&B===U}is0(){return this.equals(p.ZERO)}negate(){return new p(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:h}=s,{X:g,Y:v,Z:C}=this,O=u(g*g),N=u(v*v),K=u(As*u(C*C)),k=u(h*O),E=g+v,B=u(u(E*E)-O-N),U=k+N,_=U-K,d=k-N,b=u(B*_),S=u(U*d),w=u(B*d),x=u(_*U);return new p(b,S,x,w)}add(h){y(h);let{a:g,d:v}=s,{X:C,Y:O,Z:N,T:K}=this,{X:k,Y:E,Z:B,T:U}=h,_=u(C*k),d=u(O*E),b=u(K*v*U),S=u(N*B),w=u((C+O)*(k+E)-_-d),x=S-b,I=S+b,L=u(d-g*_),R=u(w*x),P=u(I*L),V=u(w*L),q=u(x*I);return new p(R,P,q,V)}subtract(h){return y(h),this.add(h.negate())}multiply(h){if(!i.isValidNot0(h))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:g,f:v}=T.cached(this,h,C=>Ht(p,C));return Ht(p,[g,v])[0]}multiplyUnsafe(h){if(!i.isValid(h))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return h===Ct?p.ZERO:this.is0()||h===de?this:T.unsafe(this,h,g=>Ht(p,g))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return T.unsafe(this,s.n).is0()}toAffine(h){let g=this,v=h,{X:C,Y:O,Z:N}=g,K=g.is0();v==null&&(v=K?lp:o.inv(N));let k=u(C*v),E=u(O*v),B=o.mul(N,v);if(K)return{x:Ct,y:de};if(B!==de)throw new Error("invZ was invalid");return{x:k,y:E}}clearCofactor(){return a===de?this:this.multiplyUnsafe(a)}toBytes(){let{x:h,y:g}=this.toAffine(),v=o.toBytes(g);return v[v.length-1]|=h&de?128:0,v}toHex(){return pr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let T=new xr(p,i.BITS);return i.BITS>=8&&p.BASE.precompute(8),Object.freeze(p.prototype),Object.freeze(p),p}var Ro=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){ys()}static fromHex(e){ys()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return pr(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,r){return this.ep.precompute(e,r),this}};function of(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;He(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:i}=o,{BASE:s,Fp:a,Fn:c}=t,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(qe(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?sn:o.randomBytes,y=o.adjustScalarBytes===void 0?d=>d:o.adjustScalarBytes,p=o.domain===void 0?(d,b,S)=>{if($e(S,"phflag"),b.length||S)throw new Error("Contexts/pre-hash are not supported");return d}:o.domain;function T(d){return c.create(Je(d))}function A(d){let b=k.secretKey;H(d,k.secretKey,"secretKey");let S=H(n(d),2*b,"hashedSecretKey"),w=y(S.slice(0,b)),x=S.slice(b,2*b),I=T(w);return{head:w,prefix:x,scalar:I}}function h(d){let{head:b,prefix:S,scalar:w}=A(d),x=s.multiply(w),I=x.toBytes();return{head:b,prefix:S,scalar:w,point:x,pointBytes:I}}function g(d){return h(d).pointBytes}function v(d=Uint8Array.of(),...b){let S=ae(...b);return T(n(p(S,H(d,void 0,"context"),!!i)))}function C(d,b,S={}){d=H(d,void 0,"message"),i&&(d=i(d));let{prefix:w,scalar:x,pointBytes:I}=h(b),L=v(S.context,w,d),R=s.multiply(L).toBytes(),P=v(S.context,R,I,d),V=c.create(L+P*x);if(!c.isValid(V))throw new Error("sign failed: invalid s");let q=ae(R,c.toBytes(V));return H(q,k.signature,"result")}let O={zip215:o.zip215};function N(d,b,S,w=O){let{context:x}=w,I=w.zip215===void 0?!!O.zip215:w.zip215,L=k.signature;d=H(d,L,"signature"),b=H(b,void 0,"message"),S=H(S,k.publicKey,"publicKey"),I!==void 0&&$e(I,"zip215"),i&&(b=i(b));let R=L/2,P=d.subarray(0,R),V=Je(d.subarray(R,L)),q,j,$;try{q=t.fromBytes(S,I),j=t.fromBytes(P,I),$=s.multiplyUnsafe(V)}catch{return!1}if(!I&&q.isSmallOrder())return!1;let ie=v(x,P,S,b);return j.add(q.multiplyUnsafe(ie)).subtract($).clearCofactor().is0()}let K=a.BYTES,k={secretKey:K,publicKey:K,signature:2*K,seed:K};function E(d){return d=d===void 0?l(k.seed):d,H(d,k.seed,"seed")}function B(d){return Kt(d)&&d.length===k.secretKey}function U(d,b){try{return!!t.fromBytes(d,b===void 0?O.zip215:b)}catch{return!1}}let _={getExtendedPublicKey:h,randomSecretKey:E,isValidSecretKey:B,isValidPublicKey:U,toMontgomery(d){let{y:b}=t.fromBytes(d),S=k.publicKey,w=S===32;if(!w&&S!==57)throw new Error("only defined for 25519 and 448");let x=w?a.div(de+b,de-b):a.div(b-de,b+de);return a.toBytes(x)},toMontgomerySecret(d){let b=k.secretKey;H(d,b);let S=n(d.subarray(0,b));return y(S).subarray(0,b)}};return Object.freeze(k),Object.freeze(_),Object.freeze({keygen:Lo(E,g),getPublicKey:g,sign:C,verify:N,utils:_,Point:t,lengths:k})}function dn(t,e){if(qe(t),qe(e),e<0||e>4)throw new Error("invalid I2OSP length: "+e);if(t<0||t>2**(8*e)-1)throw new Error("invalid I2OSP input: "+t);let r=Array.from({length:e}).fill(0);for(let n=e-1;n>=0;n--)r[n]=t&255,t>>>=8;return new Uint8Array(r)}function hp(t,e){let r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function pp(t){if(!Kt(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?Co(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function Ts(t,e,r,n){H(t),qe(r),e=pp(e),e.length>255&&(e=n(ae(Co("H2C-OVERSIZE-DST-"),e)));let{outputLen:o,blockLen:i}=n,s=Math.ceil(r/o);if(r>65535||s>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=ae(e,dn(e.length,1)),c=new Uint8Array(i),u=dn(r,2),f=new Array(s),l=n(ae(c,t,u,dn(0,1),a));f[0]=n(ae(l,dn(1,1),a));for(let p=1;p<s;p++){let T=[hp(l,f[p-1]),dn(p+1,1),a];f[p]=n(ae(...T))}return ae(...f).slice(0,r)}var sf="HashToScalar-";var mp=BigInt(0),ft=BigInt(1),af=BigInt(2);var yp=BigInt(5),gp=BigInt(8),Er=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),_s={p:Er,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:gp,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function bp(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=Er,a=t*t%i*t%i,c=W(a,af,i)*a%i,u=W(c,ft,i)*t%i,f=W(u,yp,i)*u%i,l=W(f,e,i)*f%i,y=W(l,r,i)*l%i,p=W(y,n,i)*y%i,T=W(p,o,i)*p%i,A=W(T,o,i)*p%i,h=W(A,e,i)*f%i;return{pow_p_5_8:W(h,af,i)*t%i,b2:a}}function wp(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var Is=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Ds(t,e){let r=Er,n=ne(e*e*e,r),o=ne(n*n*e,r),i=bp(t*o).pow_p_5_8,s=ne(t*n*i,r),a=ne(e*s*s,r),c=s,u=ne(s*Is,r),f=a===t,l=a===ne(-t,r),y=a===ne(-t*Is,r);return f&&(s=c),(l||y)&&(s=u),ut(s,r)&&(s=ne(-s,r)),{isValid:f||l,value:s}}var Dt=nf(_s,{uvRatio:Ds}),_t=Dt.Fp,ff=Dt.Fn;function xp(t){return of(Dt,vo,Object.assign({adjustScalarBytes:wp,zip215:!0},t))}var lf=xp({});var Bs=Is,Ep=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Sp=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),vp=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Ap=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),cf=t=>Ds(ft,t),Tp=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Cs=t=>_t.create(Je(t)&Tp);function uf(t){let{d:e}=_s,r=Er,n=g=>_t.create(g),o=n(Bs*t*t),i=n((o+ft)*vp),s=BigInt(-1),a=n((s-e*o)*n(o+e)),{isValid:c,value:u}=Ds(i,a),f=n(u*t);ut(f,r)||(f=n(-f)),c||(u=f),c||(s=o);let l=n(s*(o-ft)*Ap-a),y=u*u,p=n((u+u)*a),T=n(l*Ep),A=n(ft-y),h=n(ft+y);return new Dt(n(p*h),n(A*T),n(T*h),n(p*A))}var Lt=class t extends Ro{static BASE=new t(Dt.BASE);static ZERO=new t(Dt.ZERO);static Fp=_t;static Fn=ff;constructor(e){super(e)}static fromAffine(e){return new t(Dt.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static fromBytes(e){De(e,32);let{a:r,d:n}=_s,o=Er,i=O=>_t.create(O),s=Cs(e);if(!Pu(_t.toBytes(s),e)||ut(s,o))throw new Error("invalid ristretto255 encoding 1");let a=i(s*s),c=i(ft+r*a),u=i(ft-r*a),f=i(c*c),l=i(u*u),y=i(r*n*f-l),{isValid:p,value:T}=cf(i(y*l)),A=i(T*u),h=i(T*A*y),g=i((s+s)*A);ut(g,o)&&(g=i(-g));let v=i(c*h),C=i(g*v);if(!p||ut(C,o)||v===mp)throw new Error("invalid ristretto255 encoding 2");return new t(new Dt(g,v,ft,C))}static fromHex(e){return t.fromBytes(tn(e))}toBytes(){let{X:e,Y:r,Z:n,T:o}=this.ep,i=Er,s=h=>_t.create(h),a=s(s(n+r)*s(n-r)),c=s(e*r),u=s(c*c),{value:f}=cf(s(a*u)),l=s(f*a),y=s(f*c),p=s(l*y*o),T;if(ut(o*p,i)){let h=s(r*Bs),g=s(e*Bs);e=h,r=g,T=s(l*Sp)}else T=y;ut(e*p,i)&&(r=s(-r));let A=s((n-r)*T);return ut(A,i)&&(A=s(-A)),_t.toBytes(A)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:o,Y:i}=e.ep,s=u=>_t.create(u),a=s(r*i)===s(n*o),c=s(n*i)===s(r*o);return a||c}is0(){return this.equals(t.ZERO)}};Object.freeze(Lt.BASE);Object.freeze(Lt.ZERO);Object.freeze(Lt.prototype);Object.freeze(Lt);var Ip=Object.freeze({Point:Lt,hashToCurve(t,e){let r=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=Ts(t,r,64,vo);return Ip.deriveToCurve(n)},hashToScalar(t,e={DST:sf}){let r=Ts(t,e.DST,64,vo);return ff.create(Je(r))},deriveToCurve(t){De(t,64);let e=Cs(t.subarray(0,32)),r=uf(e),n=Cs(t.subarray(32,64)),o=uf(n);return new Lt(r.add(o))}});var hn=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Fo=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Uo={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Fo("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 No=32;var Ls,Bp=(async()=>{try{return await Uo.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Cp(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Uo.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Uo.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 _p(t,e,r){return lf.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function df(t,e,r){return Ls==null&&(Ls=await Bp),Ls?Cp(t,e,r):_p(t,e,r)}function ko(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Oo=class{type="Ed25519";raw;constructor(e){this.raw=Rs(e,No)}toMultihash(){return Pe.digest(dr(this))}toCID(){return Q.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:fe(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=df(this.raw,r,e);return ko(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}};function pf(t){return t=Rs(t,No),new Oo(t)}function Rs(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 ge;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(ge||(ge={}));var Fs;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Fs||(Fs={}));(function(t){t.codec=()=>Nr(Fs)})(ge||(ge={}));var pn;(function(t){let e;t.codec=()=>(e==null&&(e=Ge((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),ge.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=ge.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:ge.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(f&7);break}}}})),e);function r(i){return Ye(i,t.codec())}t.encode=r;function n(i,s){return je(i,t.codec(),s)}t.decode=n;function o(i,s){return Ze(i,t.codec(),s)}t.stream=o})(pn||(pn={}));var Us;(function(t){let e;t.codec=()=>(e==null&&(e=Ge((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),ge.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=ge.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:ge.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(f&7);break}}}})),e);function r(i){return Ye(i,t.codec())}t.encode=r;function n(i,s){return je(i,t.codec(),s)}t.decode=n;function o(i,s){return Ze(i,t.codec(),s)}t.stream=o})(Us||(Us={}));var Po=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(bo(e),De(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=e.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),at(o)}update(e){return hr(this),this.iHash.update(e),this}digestInto(e){hr(this),wo(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},mf=(()=>{let t=((e,r,n)=>new Po(e,r).update(n).digest());return t.create=(e,r)=>new Po(e,r),t})();var yf=(t,e)=>(t+(t>=0?e:-e)/gf)/e;function Rp(t,e,r){yr("scalar",t,et,r);let[[n,o],[i,s]]=e,a=yf(s*t,r),c=yf(-o*t,r),u=t-a*n-c*i,f=-a*o-c*s,l=u<et,y=f<et;l&&(u=-u),y&&(f=-f);let p=un(Math.ceil(gr(r)/2))+Rt;if(u<et||u>=p||f<et||f>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:y,k2:f}}function ks(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Ns(t,e){He(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return $e(r.lowS,"lowS"),$e(r.prehash,"prehash"),r.format!==void 0&&ks(r.format),r}var Os=class extends Error{constructor(e=""){super(e)}},ze={Err:Os,_tlv:{encode:(t,e)=>{let{Err:r}=ze;if(qe(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(typeof e!="string")throw new TypeError('"data" expected string, got type='+typeof e);if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=an(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?an(o.length/2|128):"";return an(t)+i+o+e},decode(t,e){let{Err:r}=ze;e=H(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)s=s<<8|f;if(n+=c,s<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(t){let{Err:e}=ze;if(Io(t),t<et)throw new e("integer: negative integers are not allowed");let r=an(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}=ze;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 Vt(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=ze,o=H(t,void 0,"signature"),{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:u,l:f}=n.decode(2,c);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=ze,n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),i=n+o;return e.encode(48,i)}};Object.freeze(ze._tlv);Object.freeze(ze._int);Object.freeze(ze);var et=BigInt(0),Rt=BigInt(1),gf=BigInt(2),Mo=BigInt(3),Fp=BigInt(4);function bf(t,e={}){let r=Do("weierstrass",t,e),n=r.Fp,o=r.Fn,i=r.CURVE,{h:s,n:a}=i;He(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=e;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=xf(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function y(_,d,b){if(u&&d.is0())return Uint8Array.of(0);let{x:S,y:w}=d.toAffine(),x=n.toBytes(S);if($e(b,"isCompressed"),b){l();let I=!n.isOdd(w);return ae(wf(I),x)}else return ae(Uint8Array.of(4),x,n.toBytes(w))}function p(_){H(_,void 0,"Point");let{publicKey:d,publicKeyUncompressed:b}=f,S=_.length,w=_[0],x=_.subarray(1);if(u&&S===1&&w===0)return{x:n.ZERO,y:n.ZERO};if(S===d&&(w===2||w===3)){let I=n.fromBytes(x);if(!n.isValid(I))throw new Error("bad point: is not on curve, wrong x");let L=h(I),R;try{R=n.sqrt(L)}catch(q){let j=q instanceof Error?": "+q.message:"";throw new Error("bad point: is not on curve, sqrt error"+j)}l();let P=n.isOdd(R);return(w&1)===1!==P&&(R=n.neg(R)),{x:I,y:R}}else if(S===b&&w===4){let I=n.BYTES,L=n.fromBytes(x.subarray(0,I)),R=n.fromBytes(x.subarray(I,I*2));if(!g(L,R))throw new Error("bad point: is not on curve");return{x:L,y:R}}else throw new Error(`bad point: got length ${S}, expected compressed=${d} or uncompressed=${b}`)}let T=e.toBytes===void 0?y:e.toBytes,A=e.fromBytes===void 0?p:e.fromBytes;function h(_){let d=n.sqr(_),b=n.mul(d,_);return n.add(n.add(b,n.mul(_,i.a)),i.b)}function g(_,d){let b=n.sqr(d),S=h(_);return n.eql(b,S)}if(!g(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(i.a,Mo),Fp),C=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(v,C)))throw new Error("bad curve params: a or b");function O(_,d,b=!1){if(!n.isValid(d)||b&&n.is0(d))throw new Error(`bad point coordinate ${_}`);return d}function N(_){if(!(_ instanceof E))throw new Error("Weierstrass Point expected")}function K(_){if(!c||!c.basises)throw new Error("no endo");return Rp(_,c.basises,o.ORDER)}function k(_,d,b,S,w){return b=new E(n.mul(b.X,_),b.Y,b.Z),d=ln(S,d),b=ln(w,b),d.add(b)}class E{static BASE=new E(i.Gx,i.Gy,n.ONE);static ZERO=new E(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(d,b,S){this.X=O("x",d),this.Y=O("y",b,!0),this.Z=O("z",S),Object.freeze(this)}static CURVE(){return i}static fromAffine(d){let{x:b,y:S}=d||{};if(!d||!n.isValid(b)||!n.isValid(S))throw new Error("invalid affine point");if(d instanceof E)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(S)?E.ZERO:new E(b,S,n.ONE)}static fromBytes(d){let b=E.fromAffine(A(H(d,void 0,"point")));return b.assertValidity(),b}static fromHex(d){return E.fromBytes(mr(d))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=8,b=!0){return U.createCache(this,d),b||this.multiply(Mo),this}assertValidity(){let d=this;if(d.is0()){if(e.allowInfinityPoint&&n.is0(d.X)&&n.eql(d.Y,n.ONE)&&n.is0(d.Z))return;throw new Error("bad point: ZERO")}let{x:b,y:S}=d.toAffine();if(!n.isValid(b)||!n.isValid(S))throw new Error("bad point: x or y not field elements");if(!g(b,S))throw new Error("bad point: equation left != right");if(!d.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:d}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(d)}equals(d){N(d);let{X:b,Y:S,Z:w}=this,{X:x,Y:I,Z:L}=d,R=n.eql(n.mul(b,L),n.mul(x,w)),P=n.eql(n.mul(S,L),n.mul(I,w));return R&&P}negate(){return new E(this.X,n.neg(this.Y),this.Z)}double(){let{a:d,b}=i,S=n.mul(b,Mo),{X:w,Y:x,Z:I}=this,L=n.ZERO,R=n.ZERO,P=n.ZERO,V=n.mul(w,w),q=n.mul(x,x),j=n.mul(I,I),$=n.mul(w,x);return $=n.add($,$),P=n.mul(w,I),P=n.add(P,P),L=n.mul(d,P),R=n.mul(S,j),R=n.add(L,R),L=n.sub(q,R),R=n.add(q,R),R=n.mul(L,R),L=n.mul($,L),P=n.mul(S,P),j=n.mul(d,j),$=n.sub(V,j),$=n.mul(d,$),$=n.add($,P),P=n.add(V,V),V=n.add(P,V),V=n.add(V,j),V=n.mul(V,$),R=n.add(R,V),j=n.mul(x,I),j=n.add(j,j),V=n.mul(j,$),L=n.sub(L,V),P=n.mul(j,q),P=n.add(P,P),P=n.add(P,P),new E(L,R,P)}add(d){N(d);let{X:b,Y:S,Z:w}=this,{X:x,Y:I,Z:L}=d,R=n.ZERO,P=n.ZERO,V=n.ZERO,q=i.a,j=n.mul(i.b,Mo),$=n.mul(b,x),ie=n.mul(S,I),ce=n.mul(w,L),ue=n.add(b,S),te=n.add(x,I);ue=n.mul(ue,te),te=n.add($,ie),ue=n.sub(ue,te),te=n.add(b,w);let be=n.add(x,L);return te=n.mul(te,be),be=n.add($,ce),te=n.sub(te,be),be=n.add(S,w),R=n.add(I,L),be=n.mul(be,R),R=n.add(ie,ce),be=n.sub(be,R),V=n.mul(q,te),R=n.mul(j,ce),V=n.add(R,V),R=n.sub(ie,V),V=n.add(ie,V),P=n.mul(R,V),ie=n.add($,$),ie=n.add(ie,$),ce=n.mul(q,ce),te=n.mul(j,te),ie=n.add(ie,ce),ce=n.sub($,ce),ce=n.mul(q,ce),te=n.add(te,ce),$=n.mul(ie,te),P=n.add(P,$),$=n.mul(be,te),R=n.mul(ue,R),R=n.sub(R,$),$=n.mul(ue,ie),V=n.mul(be,V),V=n.add(V,$),new E(R,P,V)}subtract(d){return N(d),this.add(d.negate())}is0(){return this.equals(E.ZERO)}multiply(d){let{endo:b}=e;if(!o.isValidNot0(d))throw new RangeError("invalid scalar: out of range");let S,w,x=I=>U.cached(this,I,L=>Ht(E,L));if(b){let{k1neg:I,k1:L,k2neg:R,k2:P}=K(d),{p:V,f:q}=x(L),{p:j,f:$}=x(P);w=q.add($),S=k(b.beta,V,j,I,R)}else{let{p:I,f:L}=x(d);S=I,w=L}return Ht(E,[S,w])[0]}multiplyUnsafe(d){let{endo:b}=e,S=this,w=d;if(!o.isValid(w))throw new RangeError("invalid scalar: out of range");if(w===et||S.is0())return E.ZERO;if(w===Rt)return S;if(U.hasCache(this))return this.multiply(w);if(b){let{k1neg:x,k1:I,k2neg:L,k2:R}=K(w),{p1:P,p2:V}=rf(E,S,I,R);return k(b.beta,P,V,x,L)}else return U.unsafe(S,w)}toAffine(d){let b=this,S=d,{X:w,Y:x,Z:I}=b;if(n.eql(I,n.ONE))return{x:w,y:x};let L=b.is0();S==null&&(S=L?n.ONE:n.inv(I));let R=n.mul(w,S),P=n.mul(x,S),V=n.mul(I,S);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(V,n.ONE))throw new Error("invZ was invalid");return{x:R,y:P}}isTorsionFree(){let{isTorsionFree:d}=e;return s===Rt?!0:d?d(E,this):U.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:d}=e;return s===Rt?this:d?d(E,this):this.multiplyUnsafe(s)}isSmallOrder(){return s===Rt?this.is0():this.clearCofactor().is0()}toBytes(d=!0){return $e(d,"isCompressed"),this.assertValidity(),T(E,this,d)}toHex(d=!0){return pr(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let B=o.BITS,U=new xr(E,e.endo?Math.ceil(B/2):B);return B>=8&&E.BASE.precompute(8),Object.freeze(E.prototype),Object.freeze(E),E}function wf(t){return Uint8Array.of(t?2:3)}function xf(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Up(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?sn:e.randomBytes,o=Object.assign(xf(t.Fp,r),{seed:Math.max(ws(r.ORDER),16)});function i(p){try{let T=r.fromBytes(p);return r.isValidNot0(T)}catch{return!1}}function s(p,T){let{publicKey:A,publicKeyUncompressed:h}=o;try{let g=p.length;return T===!0&&g!==A||T===!1&&g!==h?!1:!!t.fromBytes(p)}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,xs(H(p,o.seed,"seed"),r.ORDER)}function c(p,T=!0){return t.BASE.multiply(r.fromBytes(p)).toBytes(T)}function u(p){let{secretKey:T,publicKey:A,publicKeyUncompressed:h}=o,g=r._lengths;if(!Kt(p))return;let v=H(p,void 0,"key").length,C=v===A||v===h,O=v===T||!!g?.includes(v);if(!(C&&O))return C}function f(p,T,A=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(T)===!1)throw new Error("second arg must be public key");let h=r.fromBytes(p);return t.fromBytes(T).multiply(h).toBytes(A)}let l={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},y=Lo(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:y,Point:t,utils:l,lengths:o})}function Ef(t,e,r={}){let n=e;bo(n),He(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?sn:r.randomBytes,i=r.hmac===void 0?(w,x)=>mf(n,w,x):r.hmac,{Fp:s,Fn:a}=t,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:y,utils:p,lengths:T}=Up(t,r),A={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},h=c*gf+Rt<s.ORDER;function g(w){let x=c>>Rt;return w>x}function v(w,x){if(!a.isValidNot0(x))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return x}function C(){if(h)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function O(w,x){ks(x);let I=T.signature,L=x==="compact"?I:x==="recovered"?I+1:void 0;return H(w,L)}class N{r;s;recovery;constructor(x,I,L){if(this.r=v("r",x),this.s=v("s",I),L!=null){if(C(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(x,I=A.format){O(x,I);let L;if(I==="der"){let{r:q,s:j}=ze.toSig(H(x));return new N(q,j)}I==="recovered"&&(L=x[0],I="compact",x=x.subarray(1));let R=T.signature/2,P=x.subarray(0,R),V=x.subarray(R,R*2);return new N(a.fromBytes(P),a.fromBytes(V),L)}static fromHex(x,I){return this.fromBytes(mr(x),I)}assertRecovery(){let{recovery:x}=this;if(x==null)throw new Error("invalid recovery id: must be present");return x}addRecoveryBit(x){return new N(this.r,this.s,x)}recoverPublicKey(x){let{r:I,s:L}=this,R=this.assertRecovery(),P=R===2||R===3?I+c:I;if(!s.isValid(P))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let V=s.toBytes(P),q=t.fromBytes(ae(wf((R&1)===0),V)),j=a.inv(P),$=k(H(x,void 0,"msgHash")),ie=a.create(-$*j),ce=a.create(L*j),ue=t.BASE.multiplyUnsafe(ie).add(q.multiplyUnsafe(ce));if(ue.is0())throw new Error("invalid recovery: point at infinify");return ue.assertValidity(),ue}hasHighS(){return g(this.s)}toBytes(x=A.format){if(ks(x),x==="der")return mr(ze.hexFromSig(this));let{r:I,s:L}=this,R=a.toBytes(I),P=a.toBytes(L);return x==="recovered"?(C(),ae(Uint8Array.of(this.assertRecovery()),R,P)):ae(R,P)}toHex(x){return pr(this.toBytes(x))}}Object.freeze(N.prototype),Object.freeze(N);let K=r.bits2int===void 0?function(x){if(x.length>8192)throw new Error("input is too large");let I=Vt(x),L=x.length*8-u;return L>0?I>>BigInt(L):I}:r.bits2int,k=r.bits2int_modN===void 0?function(x){return a.create(K(x))}:r.bits2int_modN,E=un(u);function B(w){return yr("num < 2^"+u,w,et,E),a.toBytes(w)}function U(w,x){return H(w,void 0,"message"),x?H(n(w),void 0,"prehashed message"):w}function _(w,x,I){let{lowS:L,prehash:R,extraEntropy:P}=Ns(I,A);w=U(w,R);let V=k(w),q=a.fromBytes(x);if(!a.isValidNot0(q))throw new Error("invalid private key");let j=[B(q),B(V)];if(P!=null&&P!==!1){let ue=P===!0?o(T.secretKey):P;j.push(H(ue,void 0,"extraEntropy"))}let $=ae(...j),ie=V;function ce(ue){let te=K(ue);if(!a.isValidNot0(te))return;let be=a.inv(te),zt=t.BASE.multiply(te).toAffine(),Tr=a.create(zt.x);if(Tr===et)return;let bn=a.create(be*a.create(ie+Tr*q));if(bn===et)return;let zs=(zt.x===Tr?0:2)|Number(zt.y&Rt),js=bn;return L&&g(bn)&&(js=a.neg(bn),zs^=1),new N(Tr,js,h?void 0:zs)}return{seed:$,k2sig:ce}}function d(w,x,I={}){let{seed:L,k2sig:R}=_(w,x,I);return Mu(n.outputLen,a.BYTES,i)(L,R).toBytes(I.format)}function b(w,x,I,L={}){let{lowS:R,prehash:P,format:V}=Ns(L,A);if(I=H(I,void 0,"publicKey"),x=U(x,P),!Kt(w)){let q=w instanceof N?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+q)}O(w,V);try{let q=N.fromBytes(w,V),j=t.fromBytes(I);if(R&&q.hasHighS())return!1;let{r:$,s:ie}=q,ce=k(x),ue=a.inv(ie),te=a.create(ce*ue),be=a.create($*ue),zt=t.BASE.multiplyUnsafe(te).add(j.multiplyUnsafe(be));return zt.is0()?!1:a.create(zt.x)===$}catch{return!1}}function S(w,x,I={}){let{prehash:L}=Ns(I,A);return x=U(x,L),N.fromBytes(w,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:y,utils:p,lengths:T,Point:t,sign:d,verify:b,recoverPublicKey:S,Signature:N,hash:n})}var Ms={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Np={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Sf=BigInt(2);function kp(t){let e=Ms.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,l=W(f,r,e)*f%e,y=W(l,r,e)*f%e,p=W(y,Sf,e)*u%e,T=W(p,o,e)*p%e,A=W(T,i,e)*T%e,h=W(A,a,e)*A%e,g=W(h,c,e)*h%e,v=W(g,a,e)*A%e,C=W(v,r,e)*f%e,O=W(C,s,e)*T%e,N=W(O,n,e)*u%e,K=W(N,Sf,e);if(!Ps.eql(Ps.sqr(K),t))throw new Error("Cannot find square root");return K}var Ps=br(Ms.p,{sqrt:kp}),Op=bf(Ms,{Fp:Ps,endo:Np}),Sr=Ef(Op,ku);function vf(t,e,r,n){let o=Rr.digest(r instanceof Uint8Array?r:r.subarray());if(ko(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 hn(String(i))});try{return n?.signal?.throwIfAborted(),Sr.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(i){throw new hn(String(i))}}var Ko=class{type="secp256k1";raw;_key;constructor(e){this._key=Tf(e),this.raw=Af(this._key)}toMultihash(){return Pe.digest(dr(this))}toCID(){return Q.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:fe(this.raw,e.raw)}verify(e,r,n){return vf(this._key,r,e,n)}};function If(t){return new Ko(t)}function Af(t){return Sr.Point.fromBytes(t).toBytes()}function Tf(t){try{return Sr.Point.fromBytes(t),t}catch(e){throw new Wn(String(e))}}function Bf(t){let{Type:e,Data:r}=pn.decode(t.digest),n=r??new Uint8Array;switch(e){case ge.Ed25519:return pf(n);case ge.secp256k1:return If(n);case ge.ECDSA:return wu(n);default:throw new jr}}function dr(t){return pn.encode({Type:ge[t.type],Data:t.raw})}var Cf=Symbol.for("nodejs.util.inspect.custom"),Pp=114,mn=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()})`}[Hi]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return Q.createV1(Pp,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return fe(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return fe(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Cf](){return`PeerId(${this.toString()})`}},Vo=class extends mn{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},$o=class extends mn{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},qo=class extends mn{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Mp=2336,Ho=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Pe.digest(re(this.url))}[Cf](){return`PeerId(${this.url})`}[Hi]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return Q.createV1(Mp,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=Y(e)),e.toString()===this.toString())}};function _f(t){if(Vp(t))return new Vo({multihash:t});if(Kp(t))try{let e=Bf(t);if(e.type==="Ed25519")return new $o({multihash:t,publicKey:e});if(e.type==="secp256k1")return new qo({multihash:t,publicKey:e})}catch{let r=Y(t.digest);return new Ho(new URL(r))}throw new Qn("Supplied PeerID Multihash is invalid")}function Kp(t){return t.code===Pe.code}function Vp(t){return t.code===Rr.code}function Ks(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 zo(t){let e=ht(G.decode(`z${t}`));return _f(e)}var yn=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 Ks(this.set.entries(),e=>{let r=zo(e[0]);return[r,r]})}forEach(e){this.set.forEach(r=>{let n=zo(r);e(n,n,this)})}has(e){return this.set.has(e.toString())}values(){return Ks(this.set.values(),e=>zo(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 Df;(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"})(Df||(Df={}));var gn;(function(t){let e;t.codec=()=>(e==null&&(e=Ge((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.keyName!=null&&i.keyName!==""&&(s.uint32(10),s.string(i.keyName)),i.lifetime!=null&&i.lifetime!==0&&(s.uint32(16),s.uint32(i.lifetime)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={keyName:"",lifetime:0},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.keyName=i.string();break}case 2:{c.lifetime=i.uint32();break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.keyName`,value:i.string()};break}case 2:{yield{field:`${a}.lifetime`,value:i.uint32()};break}default:{i.skipType(f&7);break}}}})),e);function r(i){return Ye(i,t.codec())}t.encode=r;function n(i,s){return je(i,t.codec(),s)}t.decode=n;function o(i,s){return Ze(i,t.codec(),s)}t.stream=o})(gn||(gn={}));function vr(t,e){return{async put(r,n,o={}){try{let i=Yr(r);try{let c=await t.get(i),u=vt.deserialize(c);if(fe(u.value,n))return}catch(c){if(c.name!=="NotFoundError")throw c}let s=new vt(r,n,new Date);o.onProgress?.(new se("ipns:routing:datastore:put"));let a=t.batch();a.put(i,s.serialize()),o.metadata!=null&&a.put(no(r),gn.encode(o.metadata)),await a.commit(o)}catch(i){throw o.onProgress?.(new se("ipns:routing:datastore:error",i)),i}},async get(r,n={}){try{let o=Yr(r);n.onProgress?.(new se("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 se("ipns:routing:datastore:error",o)),o}},async has(r,n={}){let o=Yr(r);return t.has(o,n)},async delete(r,n){let o=Yr(r),i=t.batch();i.delete(o),i.delete(no(r)),await i.commit(n)},async*list(r={}){try{r.onProgress?.(new se("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=re(a,"base32"),u=no(c),f;try{let l=await t.get(u,r);f=gn.decode(l)}catch(l){e.error("Error deserializing metadata for %s - %e",a,l)}yield{routingKey:c,metadata:f,record:i.value,created:i.timeReceived}}catch(i){e.error("Error deserializing record - %e",i)}}catch(n){throw r.onProgress?.(new se("ipns:routing:datastore:error",n)),n}}}}var Vs=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 se("ipns:routing:helia:error",o)),o}}async get(e,r={}){try{return await this.routing.get(e,r)}catch(n){throw r.onProgress?.(new se("ipns:routing:helia:error",n)),n}}toString(){return"HeliaRouting()"}};function Ar(t){return new Vs(t)}var $s=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 jo(t){return new $s(t)}var Yo=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=[jo(this.localStore),Ar(e.routing),...r.routers??[]],this.publisher=new co(e,{...r,routers:this.routers,localStore:this.localStore}),this.republisher=new yo(e,{...r,routers:this.routers,localStore:this.localStore}),this.resolver=new sr(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($p(n))for(let o of Object.values(n.services))qp(o)&&(o.selectors.ipns=async(i,s)=>{let a=s.map(c=>Z.decode(c));return ir(i,a)},o.validators.ipns=async(i,s)=>{await St(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,Wc(r),n)}async*resolve(e,r={}){let{digest:n}=Zr(e);yield*this.resolver.resolve(n,r)}async unpublish(e,r){return this.publisher.unpublish(e,r)}};function $p(t){return t?.services!=null}function qp(t){return t?.validators!=null&&t?.selectors!=null}var oe=Gr("helia:ipns:routing:pubsub"),Hs=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 yn,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 fr({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=>{oe.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;oe("peer %s joined topic %s",o,s.topic);let a=Lf(s.topic);this.#t(s.topic,a,o,{signal:this.shutdownController.signal}).catch(c=>{oe.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}}),oe("registered lookup function for IPNS with libp2p/fetch service")}catch(n){oe("unable to register lookup function for IPNS with libp2p/fetch service - %e",n)}else oe("no libp2p/fetch service found. Skipping registration of lookup function for IPNS.")}async#e(e,r){if(oe("message received for topic",e.topic),e.type!=="signed"){oe.error("unsigned message received, this module can only work with signed messages");return}if(e.from.equals(this.libp2p.peerId)){oe("not storing record from self");return}await this.#r(e.topic,Lf(e.topic),e.data,!1,r)}async#t(e,r,n,o){let i=await this.fetchQueue.add(async({signal:s})=>{oe("fetching ipns record for %m from peer %s",r,n);let a=Wr([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 ${Y(r,"base64")}`);return oe("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 St(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 St(r,a,this.keychain,i);if(fe(a,n))return oe.trace("found identical record for %m",r),a;if(ir(r,[c,s])===0)return oe.trace("found old record for %m",r),a}if(oe("found new record for %m",r),await this.localStore.put(r,n,i),o){oe("publish value for topic %s",e);try{let a=await this.libp2p.services.pubsub.publish(e,n);oe("published record on topic %s to %d recipients",e,a.recipients)}catch(a){oe.error("could not publish record on topic %s - %e",a)}}return xe(n)}async put(e,r,n={}){try{let o=qs(e);oe("publish value for topic %s",o);let i=await this.libp2p.services.pubsub.publish(o,r);n?.signal?.throwIfAborted(),oe("published record on topic %s to %d recipients",o,i.recipients),n.onProgress?.(new se("ipns:pubsub:publish",{topic:o,result:i}))}catch(o){throw n.onProgress?.(new se("ipns:pubsub:error",o)),o}}async get(e,r={}){let n=qs(e);try{this.libp2p.services.pubsub.getTopics().includes(n)||(oe("add subscription for topic",n),this.libp2p.services.pubsub.subscribe(n),this.subscriptions.add(n),r.onProgress?.(new se("ipns:pubsub:subscribe",{topic:n})))}catch(s){throw r.onProgress?.(new se("ipns:pubsub:error",s)),s}await ho(lu(this.fetchDelay),this.shutdownController.signal);let o=new AbortController,i=[];for(let s of this.libp2p.services.pubsub.getSubscribers(n)){let a=Wr([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=$c(e)?e.toMultihash():e,n=it(r),o=qs(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)}},Zo="/record/";function qs(t){let e=Y(t,"base64url");return`${Zo}${e}`}function Lf(t){if(t.substring(0,Zo.length)!==Zo)throw new vn("Topic received is not from a record");let e=t.substring(Zo.length);return re(e,"base64url")}function Rf(t,e={}){return new Hs(t,e)}function Hp(t,e={}){return new Yo(t,e)}function zp(t,e={}){let r=vr(t.datastore,t.logger.forComponent("helia:ipns:local-store")),n=[jo(r),Ar(t.routing),...e.routers??[]];return new sr(t,{routers:n,localStore:r})}return Mf(jp);})();
13
+ ${e}[Error list was empty]`,r.trim()}return au(t,e)}Se.formatters.e=t=>t==null?"undefined":uu(t);function Th(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 Wr(t,e){let r=Th(`${t}:trace`);return Se.enabled(`${t}:trace`)&&Se.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=Se(`${t}:trace`,e)),Object.assign(Se(t,e),{error:Se(`${t}:error`,e),trace:r,newScope:n=>Wr(`${t}:${n}`,e)})}function cu(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var fu=ri(Nn(),1);var Ih=Wr("ipns"),Bh=300000000000n;async function lr(t,e,r,n,o){r=BigInt(r);let i=te(e),s=o?.ttlNs??Bh,a=new fu.default(Date.now()+Number(n)),c=Z.ValidityType.EOL,u=te(a.toString()),f=tu({...o?.data??{},Value:i,Validity:u,ValidityType:0,Sequence:r,TTL:s}),l=lo(f),y=await t.sign(l,o),m;return o?.v1Compatible===!1?m={signatureV2:y,data:f}:m={value:i,signatureV1:await Ch(t,i,c,u),validityType:c,validity:u,sequence:r,ttl:s,signatureV2:y,data:f},_h(t.publicKey)&&(m.publicKey=t.publicKey.toProtobuf()),m}var Ch=async(t,e,r,n,o)=>{try{let i=eu(e,r,n);return await t.sign(i,o)}catch(i){throw Ih.error("record signature creation failed",i),new In("Record signature creation failed")}};function _h(t){return t.toMultihash().code!==Xc}var yo=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),y=Z.decode(l);a=(ke(y.data).Sequence??0n)+1n}let c=n.lifetime??1728e5,u=await lr(o,r,a,c,{...n,ttlNs:n.ttl!=null?BigInt(n.ttl)*1000000n:void 0}),f=Z.encode(u);return n.offline===!0?await this.localStore.put(s,f,{...n,metadata:{keyName:e,lifetime:c}}):await Promise.all(this.routers.map(async l=>{await l.put(s,f,{...n,metadata:{keyName:e,lifetime:c}})})),{record:u,name:`/ipns/${o.publicKey.toCID().toString(xe)}`,publicKey:o.publicKey}}catch(o){throw n.onProgress?.(new ae("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 dr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var go=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}},hr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new go(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 go(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 ts=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 Dh(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 Dh(t,e){e=e??{};let r=e.onEnd,n=new hr,o,i,s,a=dr(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((h,g)=>{i=v=>{i=null,n.push(v);try{h(t(n))}catch(C){g(C)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=dr()})}},u=h=>i!=null?i(h):(n.push(h),o),f=h=>(n=new hr,i!=null?i({error:h}):(n.push({error:h}),o)),l=h=>{if(s)return o;if(e?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:h})},y=h=>s?o:(s=!0,h!=null?f(h):u({done:!0})),m=()=>(n=new hr,y(),{done:!0}),T=h=>(y(h),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:m,throw:T,push:l,end:y,get readableLength(){return n.size},onEmpty:async h=>{let g=h?.signal;if(g?.throwIfAborted(),n.isEmpty())return;let v,C;g!=null&&(v=new Promise((O,k)=>{C=()=>{k(new ts)},g.addEventListener("abort",C)}));try{await Promise.race([a.promise,v])}finally{C!=null&&g!=null&&g?.removeEventListener("abort",C)}}},r==null)return o;let A=o;return o={[Symbol.asyncIterator](){return this},next(){return A.next()},throw(h){return A.throw(h),r!=null&&(r(h),r=void 0),{done:!0}},return(){return A.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(h){return A.end(h),r!=null&&(r(h),r=void 0),o},get readableLength(){return A.readableLength},onEmpty:h=>A.onEmpty(h)},o}var rs=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 ns(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,c,f=new Promise((l,y)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){y(du(s));return}if(s&&(c=()=>{y(du(s))},s.addEventListener("abort",c,{once:!0})),t.then(l,y),r===Number.POSITIVE_INFINITY)return;let m=new rs;a=i.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(T){y(T)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?l():o instanceof Error?y(o):(m.message=o??`Promise timed out after ${r} milliseconds`,y(m))},r)}).finally(()=>{f.clear(),c&&s&&s.removeEventListener("abort",c)});return f.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},f}var Rh=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 Lh(t,e,r){let n,o=new Promise((i,s)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:u,removeListener:f}=Rh(t),l=async(...m)=>{let T=r.multiArgs?m:m[0];if(r.filter)try{if(!await r.filter(T))return}catch(A){n(),s(A);return}c.push(T),r.count===c.length&&(n(),i(c))},y=(...m)=>{n(),s(r.rejectionMultiArgs?m:m[0])};n=()=>{for(let m of a)f(m,l);for(let m of r.rejectionEvents)a.includes(m)||f(m,y)};for(let m of a)u(m,l);for(let m of r.rejectionEvents)a.includes(m)||u(m,y);r.signal&&r.signal.addEventListener("abort",()=>{y(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(o.cancel=n,typeof r.timeout=="number"){let i=ns(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function bo(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Lh(t,e,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function Qr(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 wo=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function Fh(t){return t.reason}async function xo(t,e,r){if(e==null)return t;let n=r?.translateError??Fh;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var Eo=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=dr(),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 Uh(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var So=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,r){this.id=Uh(),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 Eo(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 xo(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 pr=class extends so{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=Qr(this.emitEmpty.bind(this),1),this.emitIdle=Qr(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 wo;let n=new So(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 bo(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await bo(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await bo(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 Jr(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(),u=Math.max(0,i-c);s(u)},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 kh=new WeakMap;function Nh({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,u=()=>{c(i),a(o.reason)},f=()=>{o&&o.removeEventListener("abort",u)},l=new Promise((y,m)=>{s=()=>{f(),y(n)},a=m,i=(e??setTimeout)(s,r)});return o&&o.addEventListener("abort",u,{once:!0}),kh.set(l,()=>{c(i),i=null,s()}),l}}var Oh=Nh({setTimeout:pu,clearTimeout:mu}),yu=Oh;function gu(t,e,r){let n,o,i=!1;function s(){let u={signal:o.signal},f;r?.timeout!=null&&(f=Jr([o.signal,AbortSignal.timeout(r.timeout)]),u.signal=f),i=!0,Promise.resolve().then(async()=>{await t(u)}).catch(()=>{}).finally(()=>{f!=null&&(f.aborted?f.clear():f.addEventListener("abort",()=>{f.clear()},{once:!0})),i=!1,!o.signal.aborted&&(n=setTimeout(s,e))})}let a=Qr(s,r?.debounce??100),c=!1;return{setInterval:u=>{e!==u&&(e=u,n!=null&&(clearTimeout(n),n=setTimeout(s,e)))},setTimeout:u=>{r??={},r.timeout=u},run:()=>{i||(clearTimeout(n),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,r?.runImmediately===!0?queueMicrotask(()=>{s()}):n=setTimeout(s,e))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var vo=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 pr({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 u;try{u=Z.decode(s)}catch{this.log.trace("skipping invalid record %b because could not decode",i);continue}if(u.data==null){this.log.trace("skipping record %b because data was missing",i);continue}let f;try{f=ke(u.data)}catch{this.log.trace("skipping record %b because could not decode data",i);continue}if(!Jc(c,new Date(Y(f.Validity)))){this.log.trace("skipping record %b within republish threshold",i);continue}let l=f.Sequence+1n,y=f.TTL??vn,m;try{m=await this.keychain.exportKey(a.keyName)}catch(T){this.log.error("missing key %s, skipping republishing record - %e",a.keyName,T);continue}try{let T=await lr(m,Y(f.Value),l,a.lifetime,{...e,ttlNs:y});n.push({routingKey:i,record:T})}catch(T){this.log.error("error creating updated IPNS record for %s - %e",i,T);continue}}this.log(`found ${n.length}/${o} records to republish`);for(let{routingKey:i,record:s}of n)r.add(async()=>{try{let a=Z.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 en;(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:Fe(0),value:Fe(0),timeReceived:""},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.key=i.bytes();break}case 2:{c.value=i.bytes();break}case 5:{c.timeReceived=i.string();break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.key`,value:i.bytes()};break}case 2:{yield{field:`${a}.value`,value:i.bytes()};break}case 5:{yield{field:`${a}.timeReceived`,value:i.string()};break}default:{i.skipType(f&7);break}}}})),e);function r(i){return je(i,t.codec())}t.encode=r;function n(i,s){return ze(i,t.codec(),s)}t.decode=n;function o(i,s){return Ye(i,t.codec(),s)}t.stream=o})(en||(en={}));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),u=parseInt(r[7].slice(0,-6),10);return new Date(Date.UTC(n,o,i,s,a,c,u))}var At=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 en.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:bu(this.timeReceived)}}static deserialize(e){let r=en.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,Ee(e),Ee(r.subarray()));return n?.signal?.throwIfAborted(),i}var Kh=parseInt("11111",2),os=parseInt("10000000",2),Vh=parseInt("01111111",2),Eu={0:tn,1:tn,2:$h,3:zh,4:jh,5:Hh,6:qh,16:tn,22:tn,48:tn};function is(t,e={offset:0}){let r=t[e.offset]&Kh;if(e.offset++,Eu[r]!=null)return Eu[r](t,e);throw new Error("No decoder for tag "+r)}function rn(t,e){let r=0;if((t[e.offset]&os)===os){let n=t[e.offset]&Vh,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 tn(t,e){rn(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=is(t,e);if(n===null)break;r.push(n)}return r}function $h(t,e){let r=rn(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=rn(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function Hh(t,e){return e.offset++,null}function zh(t,e){let r=rn(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 jh(t,e){let r=rn(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function Yh(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 ss(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=Yh(t.byteLength);return new Ie(Uint8Array.from([e.byteLength|os]),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]),ss(e),e)}function vu(t){let e=Uint8Array.from([0]),r=new Ie(e,t);return new Ie(Uint8Array.from([3]),ss(r),r)}function Ao(t,e=48){let r=new Ie;for(let n of t)r.append(n);return new Ie(Uint8Array.from([e]),ss(r),r)}var Zh=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Gh=Uint8Array.from([6,5,43,129,4,0,34]),Xh=Uint8Array.from([6,5,43,129,4,0,35]),Wh={ext:!0,kty:"EC",crv:"P-256"},Qh={ext:!0,kty:"EC",crv:"P-384"},Jh={ext:!0,kty:"EC",crv:"P-521"},as=32,cs=48,us=66;function Au(t){let e=is(t);return Tu(e)}function Tu(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===as*2+1)return n=Y(e.subarray(r,r+as),"base64url"),o=Y(e.subarray(r+as),"base64url"),new mr({...Wh,key_ops:["verify"],x:n,y:o});if(e.byteLength===cs*2+1)return n=Y(e.subarray(r,r+cs),"base64url"),o=Y(e.subarray(r+cs),"base64url"),new mr({...Qh,key_ops:["verify"],x:n,y:o});if(e.byteLength===us*2+1)return n=Y(e.subarray(r,r+us),"base64url"),o=Y(e.subarray(r+us),"base64url"),new mr({...Jh,key_ops:["verify"],x:n,y:o});throw new nt(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Iu(t){return Ao([Su(Uint8Array.from([1])),Ao([ep(t.crv)],160),Ao([vu(new Ie(Uint8Array.from([4]),te(t.x??"","base64url"),te(t.y??"","base64url")))],161)]).subarray()}function ep(t){if(t==="P-256")return Zh;if(t==="P-384")return Gh;if(t==="P-521")return Xh;throw new nt(`Invalid curve ${t}`)}var mr=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Iu(this.jwk)),this._raw}toMultihash(){return Pe.digest(yr(this))}toCID(){return W.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:le(this.raw,e.raw)}async verify(e,r,n){return xu(this.jwk,r,e,n)}};function fs(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function Tt(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(`${r}expected number, got ${typeof t}`)}if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new RangeError(`${r}expected integer >= 0, got ${t}`)}}function Re(t,e,r=""){let n=fs(t),o=t?.length,i=e!==void 0;if(!n||i&&o!==e){let s=r&&`"${r}" `,a=i?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof t}`,u=s+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return t}function To(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Tt(t.outputLen),Tt(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function gr(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Io(t,e){Re(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function at(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Bo(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Ke(t,e){return t<<32-e|t>>>e}var Cu=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",tp=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Co(t){if(Re(t),Cu)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=tp[t[r]];return e}var st={_0:48,_9:57,A:65,F:70,a:97,f:102};function Bu(t){if(t>=st._0&&t<=st._9)return t-st._0;if(t>=st.A&&t<=st.F)return t-(st.A-10);if(t>=st.a&&t<=st.f)return t-(st.a-10)}function nn(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Cu)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=Bu(t.charCodeAt(i)),a=Bu(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 ls(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Re(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 ds(t,e={}){let r=(o,i)=>t(i).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function _u(t=32){Tt(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 hs=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Du(t,e,r){return t&e^~t&r}function Ru(t,e,r){return t&e^t&r^e&r}var on=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=Bo(this.buffer)}update(e){gr(this),Re(e);let{view:r,buffer:n,blockLen:o}=this,i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=Bo(e);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){gr(this),Io(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,at(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),i),this.process(n,0);let a=Bo(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],i)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return e.destroyed=s,e.finished=i,e.length=o,e.pos=a,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},ct=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var pe=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var _o=BigInt(4294967295),Lu=BigInt(32);function rp(t,e=!1){return e?{h:Number(t&_o),l:Number(t>>Lu&_o)}:{h:Number(t>>Lu&_o)|0,l:Number(t&_o)|0}}function Fu(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}=rp(t[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var ps=(t,e,r)=>t>>>r,ms=(t,e,r)=>t<<32-r|e>>>r,Vt=(t,e,r)=>t>>>r|e<<32-r,$t=(t,e,r)=>t<<32-r|e>>>r,sn=(t,e,r)=>t<<64-r|e>>>r-32,an=(t,e,r)=>t>>>r-32|e<<64-r;function Qe(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Uu=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),ku=(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),Ou=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Pu=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Mu=(t,e,r,n,o,i)=>e+r+n+o+i+(t/2**32|0)|0;var op=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]),It=new Uint32Array(64),ys=class extends on{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,r,n,o,i,s,a,c]}set(e,r,n,o,i,s,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,r){for(let l=0;l<16;l++,r+=4)It[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let y=It[l-15],m=It[l-2],T=Ke(y,7)^Ke(y,18)^y>>>3,A=Ke(m,17)^Ke(m,19)^m>>>10;It[l]=A+It[l-7]+T+It[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let y=Ke(a,6)^Ke(a,11)^Ke(a,25),m=f+y+Du(a,c,u)+op[l]+It[l]|0,A=(Ke(n,2)^Ke(n,13)^Ke(n,22))+Ru(n,o,i)|0;f=u,u=c,c=a,a=s+m|0,s=i,i=o,o=n,n=m+A|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,i,s,a,c,u,f)}roundClean(){at(It)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),at(this.buffer)}},gs=class extends ys{A=ct[0]|0;B=ct[1]|0;C=ct[2]|0;D=ct[3]|0;E=ct[4]|0;F=ct[5]|0;G=ct[6]|0;H=ct[7]|0;constructor(){super(32)}};var Ku=Fu(["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))),ip=Ku[0],sp=Ku[1],Bt=new Uint32Array(80),Ct=new Uint32Array(80),bs=class extends on{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:y,Gh:m,Gl:T,Hh:A,Hl:h}=this;return[e,r,n,o,i,s,a,c,u,f,l,y,m,T,A,h]}set(e,r,n,o,i,s,a,c,u,f,l,y,m,T,A,h){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=y|0,this.Gh=m|0,this.Gl=T|0,this.Hh=A|0,this.Hl=h|0}process(e,r){for(let C=0;C<16;C++,r+=4)Bt[C]=e.getUint32(r),Ct[C]=e.getUint32(r+=4);for(let C=16;C<80;C++){let O=Bt[C-15]|0,k=Ct[C-15]|0,K=Vt(O,k,1)^Vt(O,k,8)^ps(O,k,7),N=$t(O,k,1)^$t(O,k,8)^ms(O,k,7),E=Bt[C-2]|0,B=Ct[C-2]|0,U=Vt(E,B,19)^sn(E,B,61)^ps(E,B,6),_=$t(E,B,19)^an(E,B,61)^ms(E,B,6),d=Nu(N,_,Ct[C-7],Ct[C-16]),b=Ou(d,K,U,Bt[C-7],Bt[C-16]);Bt[C]=b|0,Ct[C]=d|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:y,Fh:m,Fl:T,Gh:A,Gl:h,Hh:g,Hl:v}=this;for(let C=0;C<80;C++){let O=Vt(l,y,14)^Vt(l,y,18)^sn(l,y,41),k=$t(l,y,14)^$t(l,y,18)^an(l,y,41),K=l&m^~l&A,N=y&T^~y&h,E=Pu(v,k,N,sp[C],Ct[C]),B=Mu(E,g,O,K,ip[C],Bt[C]),U=E|0,_=Vt(n,o,28)^sn(n,o,34)^sn(n,o,39),d=$t(n,o,28)^an(n,o,34)^an(n,o,39),b=n&i^n&a^i&a,S=o&s^o&c^s&c;g=A|0,v=h|0,A=m|0,h=T|0,m=l|0,T=y|0,{h:l,l:y}=Qe(u|0,f|0,B|0,U|0),u=a|0,f=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let w=Uu(U,d,S);n=ku(w,B,_,b),o=w|0}({h:n,l:o}=Qe(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Qe(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Qe(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Qe(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:y}=Qe(this.Eh|0,this.El|0,l|0,y|0),{h:m,l:T}=Qe(this.Fh|0,this.Fl|0,m|0,T|0),{h:A,l:h}=Qe(this.Gh|0,this.Gl|0,A|0,h|0),{h:g,l:v}=Qe(this.Hh|0,this.Hl|0,g|0,v|0),this.set(n,o,i,s,a,c,u,f,l,y,m,T,A,h,g,v)}roundClean(){at(Bt,Ct)}destroy(){this.destroyed=!0,at(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ws=class extends bs{Ah=pe[0]|0;Al=pe[1]|0;Bh=pe[2]|0;Bl=pe[3]|0;Ch=pe[4]|0;Cl=pe[5]|0;Dh=pe[6]|0;Dl=pe[7]|0;Eh=pe[8]|0;El=pe[9]|0;Fh=pe[10]|0;Fl=pe[11]|0;Gh=pe[12]|0;Gl=pe[13]|0;Hh=pe[14]|0;Hl=pe[15]|0;constructor(){super(64)}};var Vu=ds(()=>new gs,hs(1));var Do=ds(()=>new ws,hs(3));var H=(t,e,r)=>Re(t,e,r),Es=Tt,br=Co,ce=(...t)=>ls(...t),wr=t=>nn(t),qt=fs,cn=t=>_u(t),Lo=BigInt(0),xs=BigInt(1);function Ve(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function Fo(t){if(typeof t=="bigint"){if(!Ro(t))throw new RangeError("positive bigint expected, got "+t)}else Es(t);return t}function $e(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 un(t){let e=Fo(t).toString(16);return e.length&1?"0"+e:e}function $u(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Lo:BigInt("0x"+t)}function Ht(t){return $u(Co(t))}function Je(t){return $u(Co(fn(Re(t)).reverse()))}function Uo(t,e){if(Tt(e),e===0)throw new RangeError("zero length");t=Fo(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return nn(r.padStart(e*2,"0"))}function Ss(t,e){return Uo(t,e).reverse()}function qu(t,e){if(t=H(t),e=H(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function fn(t){return Uint8Array.from(H(t))}function ko(t){if(typeof t!="string")throw new TypeError("ascii string expected, got "+typeof t);return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var Ro=t=>typeof t=="bigint"&&Lo<=t;function ap(t,e,r){return Ro(t)&&Ro(e)&&Ro(r)&&e<=t&&t<r}function xr(t,e,r,n){if(!ap(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Er(t){if(t<Lo)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>Lo;t>>=xs,e+=1);return e}var ln=t=>(xs<<BigInt(t))-xs;function Hu(t,e,r){if(Tt(t,"hashLen"),Tt(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=h=>new Uint8Array(h),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,l=()=>{c.fill(1),u.fill(0),f=0},y=(...h)=>r(u,ce(c,...h)),m=(h=o)=>{u=y(i,h),c=y(),h.length!==0&&(u=y(s,h),c=y())},T=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let h=0,g=[];for(;h<e;){c=y();let v=c.slice();g.push(v),h+=c.length}return ce(...g)};return(h,g)=>{l(),m(h);let v;for(;(v=g(T()))===void 0;)m();return l(),v}}function qe(t,e={},r={}){if(Object.prototype.toString.call(t)!=="[object Object]")throw new TypeError("expected valid options object");function n(i,s,a){if(!a&&s!=="function"&&!Object.hasOwn(t,i))throw new TypeError(`param "${i}" is invalid: expected own property`);let c=t[i];if(a&&c===void 0)return;let u=typeof c;if(u!==s||c===null)throw new TypeError(`param "${i}" is invalid: expected ${s}, got ${u}`)}let o=(i,s)=>Object.entries(i).forEach(([a,c])=>n(a,c,s));o(e,!1),o(r,!0)}var vs=()=>{throw new Error("not implemented")};var me=BigInt(0),J=BigInt(1),zt=BigInt(2),Zu=BigInt(3),Gu=BigInt(4),Xu=BigInt(5),cp=BigInt(7),Wu=BigInt(8),up=BigInt(9),Qu=BigInt(16);function re(t,e){if(e<=me)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=me?r:e+r}function X(t,e,r){if(e<me)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >me;)n*=n,n%=r;return n}function zu(t,e){if(t===me)throw new Error("invert: expected non-zero number");if(e<=me)throw new Error("invert: expected positive modulus, got "+e);let r=re(t,e),n=e,o=me,i=J,s=J,a=me;for(;r!==me;){let u=n/r,f=n-r*u,l=o-s*u,y=i-a*u;n=r,r=f,o=s,i=a,s=l,a=y}if(n!==J)throw new Error("invert: does not exist");return re(o,e)}function As(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Ju(t,e){let r=t,n=(r.ORDER+J)/Gu,o=r.pow(e,n);return As(r,o,e),o}function fp(t,e){let r=t,n=(r.ORDER-Xu)/Wu,o=r.mul(e,zt),i=r.pow(o,n),s=r.mul(e,i),a=r.mul(r.mul(s,zt),i),c=r.mul(s,r.sub(a,r.ONE));return As(r,c,e),c}function lp(t){let e=Sr(t),r=ef(t),n=r(e,e.neg(e.ONE)),o=r(e,n),i=r(e,e.neg(n)),s=(t+cp)/Qu;return((a,c)=>{let u=a,f=u.pow(c,s),l=u.mul(f,n),y=u.mul(f,o),m=u.mul(f,i),T=u.eql(u.sqr(l),c),A=u.eql(u.sqr(y),c);f=u.cmov(f,l,T),l=u.cmov(m,y,A);let h=u.eql(u.sqr(l),c),g=u.cmov(f,l,h);return As(u,g,c),g})}function ef(t){if(t<Zu)throw new Error("sqrt is not defined for small field");let e=t-J,r=0;for(;e%zt===me;)e/=zt,r++;let n=zt,o=Sr(t);for(;ju(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ju;let i=o.pow(n,e),s=(e+J)/zt;return function(c,u){let f=c;if(f.is0(u))return u;if(ju(f,u)!==1)throw new Error("Cannot find square root");let l=r,y=f.mul(f.ONE,i),m=f.pow(u,e),T=f.pow(u,s);for(;!f.eql(m,f.ONE);){if(f.is0(m))return f.ZERO;let A=1,h=f.sqr(m);for(;!f.eql(h,f.ONE);)if(A++,h=f.sqr(h),A===l)throw new Error("Cannot find square root");let g=J<<BigInt(l-A-1),v=f.pow(y,g);l=A,y=f.sqr(v),m=f.mul(m,y),T=f.mul(T,v)}return T}}function dp(t){return t%Gu===Zu?Ju:t%Wu===Xu?fp:t%Qu===up?lp(t):ef(t)}var ut=(t,e)=>(re(t,e)&J)===J,hp=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ts(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=hp.reduce((n,o)=>(n[o]="function",n),e);if(qe(t,r),$e(t.BYTES,"BYTES"),$e(t.BITS,"BITS"),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 pp(t,e,r){let n=t;if(r<me)throw new Error("invalid exponent, negatives unsupported");if(r===me)return n.ONE;if(r===J)return e;let o=n.ONE,i=e;for(;r>me;)r&J&&(o=n.mul(o,i)),i=n.sqr(i),r>>=J;return o}function dn(t,e,r=!1){let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),i=e.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),s=n.inv(i);return e.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),s),o}function ju(t,e){let r=t,n=(r.ORDER-J)/zt,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 mp(t,e){if(e!==void 0&&Es(e),t<=me)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=Er(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${e})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Yu=new WeakMap,No=class{ORDER;BITS;BYTES;isLE;ZERO=me;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}=mp(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 me<=e&&e<this.ORDER}is0(e){return e===me}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&J)===J}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 pp(this,e,r)}div(e,r){return re(e*zu(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 zu(e,this.ORDER)}sqrt(e){let r=Yu.get(this);return r||Yu.set(this,r=dp(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Ss(e,this.BYTES):Uo(e,this.BYTES)}fromBytes(e,r=!1){H(e);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,i?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=i?Je(e):Ht(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 dn(this,e)}cmov(e,r,n){return Ve(n,"condition"),n?r:e}};Object.freeze(No.prototype);function Sr(t,e={}){return new No(t,e)}function tf(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=Er(t-J);return Math.ceil(e/8)}function Is(t){let e=tf(t);return e+Math.ceil(e/2)}function Bs(t,e,r=!1){H(t);let n=t.length,o=tf(e),i=Math.max(Is(e),16);if(n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Je(t):Ht(t),a=re(s,e-J)+J;return r?Ss(a,o):Uo(a,o)}var vr=BigInt(0),jt=BigInt(1);function hn(t,e){let r=e.negate();return t?r:e}function Yt(t,e){let r=dn(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function sf(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Cs(t,e){sf(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,i=ln(t),s=BigInt(t);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function rf(t,e,r){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r,a=Number(t&o),c=t>>s;a>n&&(a-=i,c+=jt);let u=e*n,f=u+Math.abs(a)-1,l=a===0,y=a<0,m=e%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:y,isNegF:m,offsetF:u}}var _s=new WeakMap,af=new WeakMap;function Ds(t){return af.get(t)||1}function nf(t){if(t!==vr)throw new Error("invalid wNAF")}var Ar=class{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let o=e;for(;r>vr;)r&jt&&(n=n.add(o)),o=o.double(),r>>=jt;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=Cs(r,this.bits),i=[],s=e,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let u=1;u<o;u++)a=a.add(s),i.push(a);s=a.double()}return i}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=Cs(e,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:y,offsetF:m}=rf(n,a,s);n=c,f?i=i.add(hn(y,r[m])):o=o.add(hn(l,r[u]))}return nf(n),{p:o,f:i}}wNAFUnsafe(e,r,n,o=this.ZERO){let i=Cs(e,this.bits);for(let s=0;s<i.windows&&n!==vr;s++){let{nextN:a,offset:c,isZero:u,isNeg:f}=rf(n,s,i);if(n=a,!u){let l=r[c];o=o.add(f?l.negate():l)}}return nf(n),o}getPrecomputes(e,r,n){let o=_s.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),_s.set(r,o))),o}cached(e,r,n){let o=Ds(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let i=Ds(e);return i===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),r,o)}createCache(e,r){sf(r,this.bits),af.set(e,r),_s.delete(e)}hasCache(e){return Ds(e)!==1}};function cf(t,e,r,n){let o=e,i=t.ZERO,s=t.ZERO;for(;r>vr||n>vr;)r&jt&&(i=i.add(o)),n&jt&&(s=s.add(o)),o=o.double(),r>>=jt,n>>=jt;return{p1:i,p2:s}}function of(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ts(e),e}else return Sr(t,{isLE:r})}function Oo(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let c of["p","n","h"]){let u=e[c];if(!(typeof u=="bigint"&&u>vr))throw new Error(`CURVE.${c} must be positive bigint`)}let o=of(e.p,r.Fp,n),i=of(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 _t=BigInt(0),he=BigInt(1),Rs=BigInt(2),yp=BigInt(8);function gp(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 uf(t,e={}){let r=e,n=Oo("edwards",t,r,r.FpFnLE),{Fp:o,Fn:i}=n,s=n.CURVE,{h:a}=s;qe(r,{},{uvRatio:"function"});let c=Rs<<BigInt(i.BYTES*8)-he,u=A=>o.create(A),f=r.uvRatio===void 0?(A,h)=>{try{return{isValid:!0,value:o.sqrt(o.div(A,h))}}catch{return{isValid:!1,value:_t}}}:r.uvRatio;if(!gp(o,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function l(A,h,g=!1){let v=g?he:_t;return xr("coordinate "+A,h,v,c),h}function y(A){if(!(A instanceof m))throw new Error("EdwardsPoint expected")}class m{static BASE=new m(s.Gx,s.Gy,he,u(s.Gx*s.Gy));static ZERO=new m(_t,he,he,_t);static Fp=o;static Fn=i;X;Y;Z;T;constructor(h,g,v,C){this.X=l("x",h),this.Y=l("y",g),this.Z=l("z",v,!0),this.T=l("t",C),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){if(h instanceof m)throw new Error("extended point not allowed");let{x:g,y:v}=h||{};return l("x",g),l("y",v),new m(g,v,he,u(g*v))}static fromBytes(h,g=!1){let v=o.BYTES,{a:C,d:O}=s;h=fn(H(h,v,"point")),Ve(g,"zip215");let k=fn(h),K=h[v-1];k[v-1]=K&-129;let N=Je(k),E=g?c:o.ORDER;xr("point.y",N,_t,E);let B=u(N*N),U=u(B-he),_=u(O*B-C),{isValid:d,value:b}=f(U,_);if(!d)throw new Error("bad point: invalid y coordinate");let S=(b&he)===he,w=(K&128)!==0;if(!g&&b===_t&&w)throw new Error("bad point: x=0 and x_0=1");return w!==S&&(b=u(-b)),m.fromAffine({x:b,y:N})}static fromHex(h,g=!1){return m.fromBytes(wr(h),g)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,g=!0){return T.createCache(this,h),g||this.multiply(Rs),this}assertValidity(){let h=this,{a:g,d:v}=s;if(h.is0())throw new Error("bad point: ZERO");let{X:C,Y:O,Z:k,T:K}=h,N=u(C*C),E=u(O*O),B=u(k*k),U=u(B*B),_=u(N*g),d=u(B*u(_+E)),b=u(U+u(v*u(N*E)));if(d!==b)throw new Error("bad point: equation left != right (1)");let S=u(C*O),w=u(k*K);if(S!==w)throw new Error("bad point: equation left != right (2)")}equals(h){y(h);let{X:g,Y:v,Z:C}=this,{X:O,Y:k,Z:K}=h,N=u(g*K),E=u(O*C),B=u(v*K),U=u(k*C);return N===E&&B===U}is0(){return this.equals(m.ZERO)}negate(){return new m(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:h}=s,{X:g,Y:v,Z:C}=this,O=u(g*g),k=u(v*v),K=u(Rs*u(C*C)),N=u(h*O),E=g+v,B=u(u(E*E)-O-k),U=N+k,_=U-K,d=N-k,b=u(B*_),S=u(U*d),w=u(B*d),x=u(_*U);return new m(b,S,x,w)}add(h){y(h);let{a:g,d:v}=s,{X:C,Y:O,Z:k,T:K}=this,{X:N,Y:E,Z:B,T:U}=h,_=u(C*N),d=u(O*E),b=u(K*v*U),S=u(k*B),w=u((C+O)*(N+E)-_-d),x=S-b,I=S+b,R=u(d-g*_),L=u(w*x),P=u(I*R),V=u(w*R),q=u(x*I);return new m(L,P,q,V)}subtract(h){return y(h),this.add(h.negate())}multiply(h){if(!i.isValidNot0(h))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:g,f:v}=T.cached(this,h,C=>Yt(m,C));return Yt(m,[g,v])[0]}multiplyUnsafe(h){if(!i.isValid(h))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return h===_t?m.ZERO:this.is0()||h===he?this:T.unsafe(this,h,g=>Yt(m,g))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return T.unsafe(this,s.n).is0()}toAffine(h){let g=this,v=h,{X:C,Y:O,Z:k}=g,K=g.is0();v==null&&(v=K?yp:o.inv(k));let N=u(C*v),E=u(O*v),B=o.mul(k,v);if(K)return{x:_t,y:he};if(B!==he)throw new Error("invZ was invalid");return{x:N,y:E}}clearCofactor(){return a===he?this:this.multiplyUnsafe(a)}toBytes(){let{x:h,y:g}=this.toAffine(),v=o.toBytes(g);return v[v.length-1]|=h&he?128:0,v}toHex(){return br(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let T=new Ar(m,i.BITS);return i.BITS>=8&&m.BASE.precompute(8),Object.freeze(m.prototype),Object.freeze(m),m}var Mo=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){vs()}static fromHex(e){vs()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return br(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,r){return this.ep.precompute(e,r),this}};function ff(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;qe(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:i}=o,{BASE:s,Fp:a,Fn:c}=t,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&($e(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?cn:o.randomBytes,y=o.adjustScalarBytes===void 0?d=>d:o.adjustScalarBytes,m=o.domain===void 0?(d,b,S)=>{if(Ve(S,"phflag"),b.length||S)throw new Error("Contexts/pre-hash are not supported");return d}:o.domain;function T(d){return c.create(Je(d))}function A(d){let b=N.secretKey;H(d,N.secretKey,"secretKey");let S=H(n(d),2*b,"hashedSecretKey"),w=y(S.slice(0,b)),x=S.slice(b,2*b),I=T(w);return{head:w,prefix:x,scalar:I}}function h(d){let{head:b,prefix:S,scalar:w}=A(d),x=s.multiply(w),I=x.toBytes();return{head:b,prefix:S,scalar:w,point:x,pointBytes:I}}function g(d){return h(d).pointBytes}function v(d=Uint8Array.of(),...b){let S=ce(...b);return T(n(m(S,H(d,void 0,"context"),!!i)))}function C(d,b,S={}){d=H(d,void 0,"message"),i&&(d=i(d));let{prefix:w,scalar:x,pointBytes:I}=h(b),R=v(S.context,w,d),L=s.multiply(R).toBytes(),P=v(S.context,L,I,d),V=c.create(R+P*x);if(!c.isValid(V))throw new Error("sign failed: invalid s");let q=ce(L,c.toBytes(V));return H(q,N.signature,"result")}let O={zip215:o.zip215};function k(d,b,S,w=O){let{context:x}=w,I=w.zip215===void 0?!!O.zip215:w.zip215,R=N.signature;d=H(d,R,"signature"),b=H(b,void 0,"message"),S=H(S,N.publicKey,"publicKey"),I!==void 0&&Ve(I,"zip215"),i&&(b=i(b));let L=R/2,P=d.subarray(0,L),V=Je(d.subarray(L,R)),q,j,$;try{q=t.fromBytes(S,I),j=t.fromBytes(P,I),$=s.multiplyUnsafe(V)}catch{return!1}if(!I&&q.isSmallOrder())return!1;let oe=v(x,P,S,b);return j.add(q.multiplyUnsafe(oe)).subtract($).clearCofactor().is0()}let K=a.BYTES,N={secretKey:K,publicKey:K,signature:2*K,seed:K};function E(d){return d=d===void 0?l(N.seed):d,H(d,N.seed,"seed")}function B(d){return qt(d)&&d.length===N.secretKey}function U(d,b){try{return!!t.fromBytes(d,b===void 0?O.zip215:b)}catch{return!1}}let _={getExtendedPublicKey:h,randomSecretKey:E,isValidSecretKey:B,isValidPublicKey:U,toMontgomery(d){let{y:b}=t.fromBytes(d),S=N.publicKey,w=S===32;if(!w&&S!==57)throw new Error("only defined for 25519 and 448");let x=w?a.div(he+b,he-b):a.div(b-he,b+he);return a.toBytes(x)},toMontgomerySecret(d){let b=N.secretKey;H(d,b);let S=n(d.subarray(0,b));return y(S).subarray(0,b)}};return Object.freeze(N),Object.freeze(_),Object.freeze({keygen:Po(E,g),getPublicKey:g,sign:C,verify:k,utils:_,Point:t,lengths:N})}function pn(t,e){if($e(t),$e(e),e<0||e>4)throw new Error("invalid I2OSP length: "+e);if(t<0||t>2**(8*e)-1)throw new Error("invalid I2OSP input: "+t);let r=Array.from({length:e}).fill(0);for(let n=e-1;n>=0;n--)r[n]=t&255,t>>>=8;return new Uint8Array(r)}function bp(t,e){let r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function wp(t){if(!qt(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?ko(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function Ls(t,e,r,n){H(t),$e(r),e=wp(e),e.length>255&&(e=n(ce(ko("H2C-OVERSIZE-DST-"),e)));let{outputLen:o,blockLen:i}=n,s=Math.ceil(r/o);if(r>65535||s>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=ce(e,pn(e.length,1)),c=new Uint8Array(i),u=pn(r,2),f=new Array(s),l=n(ce(c,t,u,pn(0,1),a));f[0]=n(ce(l,pn(1,1),a));for(let m=1;m<s;m++){let T=[bp(l,f[m-1]),pn(m+1,1),a];f[m]=n(ce(...T))}return ce(...f).slice(0,r)}var lf="HashToScalar-";var xp=BigInt(0),ft=BigInt(1),df=BigInt(2);var Ep=BigInt(5),Sp=BigInt(8),Tr=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Ns={p:Tr,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Sp,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function vp(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=Tr,a=t*t%i*t%i,c=X(a,df,i)*a%i,u=X(c,ft,i)*t%i,f=X(u,Ep,i)*u%i,l=X(f,e,i)*f%i,y=X(l,r,i)*l%i,m=X(y,n,i)*y%i,T=X(m,o,i)*m%i,A=X(T,o,i)*m%i,h=X(A,e,i)*f%i;return{pow_p_5_8:X(h,df,i)*t%i,b2:a}}function Ap(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var Fs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Os(t,e){let r=Tr,n=re(e*e*e,r),o=re(n*n*e,r),i=vp(t*o).pow_p_5_8,s=re(t*n*i,r),a=re(e*s*s,r),c=s,u=re(s*Fs,r),f=a===t,l=a===re(-t,r),y=a===re(-t*Fs,r);return f&&(s=c),(l||y)&&(s=u),ut(s,r)&&(s=re(-s,r)),{isValid:f||l,value:s}}var Rt=uf(Ns,{uvRatio:Os}),Dt=Rt.Fp,mf=Rt.Fn;function Tp(t){return ff(Rt,Do,Object.assign({adjustScalarBytes:Ap,zip215:!0},t))}var yf=Tp({});var Us=Fs,Ip=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Bp=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Cp=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),_p=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),hf=t=>Os(ft,t),Dp=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),ks=t=>Dt.create(Je(t)&Dp);function pf(t){let{d:e}=Ns,r=Tr,n=g=>Dt.create(g),o=n(Us*t*t),i=n((o+ft)*Cp),s=BigInt(-1),a=n((s-e*o)*n(o+e)),{isValid:c,value:u}=Os(i,a),f=n(u*t);ut(f,r)||(f=n(-f)),c||(u=f),c||(s=o);let l=n(s*(o-ft)*_p-a),y=u*u,m=n((u+u)*a),T=n(l*Ip),A=n(ft-y),h=n(ft+y);return new Rt(n(m*h),n(A*T),n(T*h),n(m*A))}var Lt=class t extends Mo{static BASE=new t(Rt.BASE);static ZERO=new t(Rt.ZERO);static Fp=Dt;static Fn=mf;constructor(e){super(e)}static fromAffine(e){return new t(Rt.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static fromBytes(e){Re(e,32);let{a:r,d:n}=Ns,o=Tr,i=O=>Dt.create(O),s=ks(e);if(!qu(Dt.toBytes(s),e)||ut(s,o))throw new Error("invalid ristretto255 encoding 1");let a=i(s*s),c=i(ft+r*a),u=i(ft-r*a),f=i(c*c),l=i(u*u),y=i(r*n*f-l),{isValid:m,value:T}=hf(i(y*l)),A=i(T*u),h=i(T*A*y),g=i((s+s)*A);ut(g,o)&&(g=i(-g));let v=i(c*h),C=i(g*v);if(!m||ut(C,o)||v===xp)throw new Error("invalid ristretto255 encoding 2");return new t(new Rt(g,v,ft,C))}static fromHex(e){return t.fromBytes(nn(e))}toBytes(){let{X:e,Y:r,Z:n,T:o}=this.ep,i=Tr,s=h=>Dt.create(h),a=s(s(n+r)*s(n-r)),c=s(e*r),u=s(c*c),{value:f}=hf(s(a*u)),l=s(f*a),y=s(f*c),m=s(l*y*o),T;if(ut(o*m,i)){let h=s(r*Us),g=s(e*Us);e=h,r=g,T=s(l*Bp)}else T=y;ut(e*m,i)&&(r=s(-r));let A=s((n-r)*T);return ut(A,i)&&(A=s(-A)),Dt.toBytes(A)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:o,Y:i}=e.ep,s=u=>Dt.create(u),a=s(r*i)===s(n*o),c=s(n*i)===s(r*o);return a||c}is0(){return this.equals(t.ZERO)}};Object.freeze(Lt.BASE);Object.freeze(Lt.ZERO);Object.freeze(Lt.prototype);Object.freeze(Lt);var Rp=Object.freeze({Point:Lt,hashToCurve(t,e){let r=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=Ls(t,r,64,Do);return Rp.deriveToCurve(n)},hashToScalar(t,e={DST:lf}){let r=Ls(t,e.DST,64,Do);return mf.create(Je(r))},deriveToCurve(t){Re(t,64);let e=ks(t.subarray(0,32)),r=pf(e),n=ks(t.subarray(32,64)),o=pf(n);return new Lt(r.add(o))}});var mn=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Ko=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Vo={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Ko("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 $o=32;var Ps,Lp=(async()=>{try{return await Vo.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Fp(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Vo.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Vo.get().subtle.verify({name:"Ed25519"},n,Ee(e),Ee(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Up(t,e,r){return yf.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function gf(t,e,r){return Ps==null&&(Ps=await Lp),Ps?Fp(t,e,r):Up(t,e,r)}function qo(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Ho=class{type="Ed25519";raw;constructor(e){this.raw=Ms(e,$o)}toMultihash(){return Pe.digest(yr(this))}toCID(){return W.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:le(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=gf(this.raw,r,e);return qo(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}};function wf(t){return t=Ms(t,$o),new Ho(t)}function Ms(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 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=()=>Mr(Ks)})(be||(be={}));var yn;(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={},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=be.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:be.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(f&7);break}}}})),e);function r(i){return je(i,t.codec())}t.encode=r;function n(i,s){return ze(i,t.codec(),s)}t.decode=n;function o(i,s){return Ye(i,t.codec(),s)}t.stream=o})(yn||(yn={}));var Vs;(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={},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=be.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:be.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(f&7);break}}}})),e);function r(i){return je(i,t.codec())}t.encode=r;function n(i,s){return ze(i,t.codec(),s)}t.decode=n;function o(i,s){return Ye(i,t.codec(),s)}t.stream=o})(Vs||(Vs={}));var zo=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(To(e),Re(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=e.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),at(o)}update(e){return gr(this),this.iHash.update(e),this}digestInto(e){gr(this),Io(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},xf=(()=>{let t=((e,r,n)=>new zo(e,r).update(n).digest());return t.create=(e,r)=>new zo(e,r),t})();var Ef=(t,e)=>(t+(t>=0?e:-e)/Sf)/e;function Op(t,e,r){xr("scalar",t,et,r);let[[n,o],[i,s]]=e,a=Ef(s*t,r),c=Ef(-o*t,r),u=t-a*n-c*i,f=-a*o-c*s,l=u<et,y=f<et;l&&(u=-u),y&&(f=-f);let m=ln(Math.ceil(Er(r)/2))+Ft;if(u<et||u>=m||f<et||f>=m)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:y,k2:f}}function qs(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function $s(t,e){qe(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Ve(r.lowS,"lowS"),Ve(r.prehash,"prehash"),r.format!==void 0&&qs(r.format),r}var Hs=class extends Error{constructor(e=""){super(e)}},He={Err:Hs,_tlv:{encode:(t,e)=>{let{Err:r}=He;if($e(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(typeof e!="string")throw new TypeError('"data" expected string, got type='+typeof e);if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=un(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?un(o.length/2|128):"";return un(t)+i+o+e},decode(t,e){let{Err:r}=He;e=H(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)s=s<<8|f;if(n+=c,s<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(t){let{Err:e}=He;if(Fo(t),t<et)throw new e("integer: negative integers are not allowed");let r=un(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}=He;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 Ht(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=He,o=H(t,void 0,"signature"),{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:u,l:f}=n.decode(2,c);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=He,n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),i=n+o;return e.encode(48,i)}};Object.freeze(He._tlv);Object.freeze(He._int);Object.freeze(He);var et=BigInt(0),Ft=BigInt(1),Sf=BigInt(2),jo=BigInt(3),Pp=BigInt(4);function vf(t,e={}){let r=Oo("weierstrass",t,e),n=r.Fp,o=r.Fn,i=r.CURVE,{h:s,n:a}=i;qe(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=e;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=Tf(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function y(_,d,b){if(u&&d.is0())return Uint8Array.of(0);let{x:S,y:w}=d.toAffine(),x=n.toBytes(S);if(Ve(b,"isCompressed"),b){l();let I=!n.isOdd(w);return ce(Af(I),x)}else return ce(Uint8Array.of(4),x,n.toBytes(w))}function m(_){H(_,void 0,"Point");let{publicKey:d,publicKeyUncompressed:b}=f,S=_.length,w=_[0],x=_.subarray(1);if(u&&S===1&&w===0)return{x:n.ZERO,y:n.ZERO};if(S===d&&(w===2||w===3)){let I=n.fromBytes(x);if(!n.isValid(I))throw new Error("bad point: is not on curve, wrong x");let R=h(I),L;try{L=n.sqrt(R)}catch(q){let j=q instanceof Error?": "+q.message:"";throw new Error("bad point: is not on curve, sqrt error"+j)}l();let P=n.isOdd(L);return(w&1)===1!==P&&(L=n.neg(L)),{x:I,y:L}}else if(S===b&&w===4){let I=n.BYTES,R=n.fromBytes(x.subarray(0,I)),L=n.fromBytes(x.subarray(I,I*2));if(!g(R,L))throw new Error("bad point: is not on curve");return{x:R,y:L}}else throw new Error(`bad point: got length ${S}, expected compressed=${d} or uncompressed=${b}`)}let T=e.toBytes===void 0?y:e.toBytes,A=e.fromBytes===void 0?m:e.fromBytes;function h(_){let d=n.sqr(_),b=n.mul(d,_);return n.add(n.add(b,n.mul(_,i.a)),i.b)}function g(_,d){let b=n.sqr(d),S=h(_);return n.eql(b,S)}if(!g(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(i.a,jo),Pp),C=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(v,C)))throw new Error("bad curve params: a or b");function O(_,d,b=!1){if(!n.isValid(d)||b&&n.is0(d))throw new Error(`bad point coordinate ${_}`);return d}function k(_){if(!(_ instanceof E))throw new Error("Weierstrass Point expected")}function K(_){if(!c||!c.basises)throw new Error("no endo");return Op(_,c.basises,o.ORDER)}function N(_,d,b,S,w){return b=new E(n.mul(b.X,_),b.Y,b.Z),d=hn(S,d),b=hn(w,b),d.add(b)}class E{static BASE=new E(i.Gx,i.Gy,n.ONE);static ZERO=new E(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(d,b,S){this.X=O("x",d),this.Y=O("y",b,!0),this.Z=O("z",S),Object.freeze(this)}static CURVE(){return i}static fromAffine(d){let{x:b,y:S}=d||{};if(!d||!n.isValid(b)||!n.isValid(S))throw new Error("invalid affine point");if(d instanceof E)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(S)?E.ZERO:new E(b,S,n.ONE)}static fromBytes(d){let b=E.fromAffine(A(H(d,void 0,"point")));return b.assertValidity(),b}static fromHex(d){return E.fromBytes(wr(d))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=8,b=!0){return U.createCache(this,d),b||this.multiply(jo),this}assertValidity(){let d=this;if(d.is0()){if(e.allowInfinityPoint&&n.is0(d.X)&&n.eql(d.Y,n.ONE)&&n.is0(d.Z))return;throw new Error("bad point: ZERO")}let{x:b,y:S}=d.toAffine();if(!n.isValid(b)||!n.isValid(S))throw new Error("bad point: x or y not field elements");if(!g(b,S))throw new Error("bad point: equation left != right");if(!d.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:d}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(d)}equals(d){k(d);let{X:b,Y:S,Z:w}=this,{X:x,Y:I,Z:R}=d,L=n.eql(n.mul(b,R),n.mul(x,w)),P=n.eql(n.mul(S,R),n.mul(I,w));return L&&P}negate(){return new E(this.X,n.neg(this.Y),this.Z)}double(){let{a:d,b}=i,S=n.mul(b,jo),{X:w,Y:x,Z:I}=this,R=n.ZERO,L=n.ZERO,P=n.ZERO,V=n.mul(w,w),q=n.mul(x,x),j=n.mul(I,I),$=n.mul(w,x);return $=n.add($,$),P=n.mul(w,I),P=n.add(P,P),R=n.mul(d,P),L=n.mul(S,j),L=n.add(R,L),R=n.sub(q,L),L=n.add(q,L),L=n.mul(R,L),R=n.mul($,R),P=n.mul(S,P),j=n.mul(d,j),$=n.sub(V,j),$=n.mul(d,$),$=n.add($,P),P=n.add(V,V),V=n.add(P,V),V=n.add(V,j),V=n.mul(V,$),L=n.add(L,V),j=n.mul(x,I),j=n.add(j,j),V=n.mul(j,$),R=n.sub(R,V),P=n.mul(j,q),P=n.add(P,P),P=n.add(P,P),new E(R,L,P)}add(d){k(d);let{X:b,Y:S,Z:w}=this,{X:x,Y:I,Z:R}=d,L=n.ZERO,P=n.ZERO,V=n.ZERO,q=i.a,j=n.mul(i.b,jo),$=n.mul(b,x),oe=n.mul(S,I),ue=n.mul(w,R),fe=n.add(b,S),ee=n.add(x,I);fe=n.mul(fe,ee),ee=n.add($,oe),fe=n.sub(fe,ee),ee=n.add(b,w);let we=n.add(x,R);return ee=n.mul(ee,we),we=n.add($,ue),ee=n.sub(ee,we),we=n.add(S,w),L=n.add(I,R),we=n.mul(we,L),L=n.add(oe,ue),we=n.sub(we,L),V=n.mul(q,ee),L=n.mul(j,ue),V=n.add(L,V),L=n.sub(oe,V),V=n.add(oe,V),P=n.mul(L,V),oe=n.add($,$),oe=n.add(oe,$),ue=n.mul(q,ue),ee=n.mul(j,ee),oe=n.add(oe,ue),ue=n.sub($,ue),ue=n.mul(q,ue),ee=n.add(ee,ue),$=n.mul(oe,ee),P=n.add(P,$),$=n.mul(we,ee),L=n.mul(fe,L),L=n.sub(L,$),$=n.mul(fe,oe),V=n.mul(we,V),V=n.add(V,$),new E(L,P,V)}subtract(d){return k(d),this.add(d.negate())}is0(){return this.equals(E.ZERO)}multiply(d){let{endo:b}=e;if(!o.isValidNot0(d))throw new RangeError("invalid scalar: out of range");let S,w,x=I=>U.cached(this,I,R=>Yt(E,R));if(b){let{k1neg:I,k1:R,k2neg:L,k2:P}=K(d),{p:V,f:q}=x(R),{p:j,f:$}=x(P);w=q.add($),S=N(b.beta,V,j,I,L)}else{let{p:I,f:R}=x(d);S=I,w=R}return Yt(E,[S,w])[0]}multiplyUnsafe(d){let{endo:b}=e,S=this,w=d;if(!o.isValid(w))throw new RangeError("invalid scalar: out of range");if(w===et||S.is0())return E.ZERO;if(w===Ft)return S;if(U.hasCache(this))return this.multiply(w);if(b){let{k1neg:x,k1:I,k2neg:R,k2:L}=K(w),{p1:P,p2:V}=cf(E,S,I,L);return N(b.beta,P,V,x,R)}else return U.unsafe(S,w)}toAffine(d){let b=this,S=d,{X:w,Y:x,Z:I}=b;if(n.eql(I,n.ONE))return{x:w,y:x};let R=b.is0();S==null&&(S=R?n.ONE:n.inv(I));let L=n.mul(w,S),P=n.mul(x,S),V=n.mul(I,S);if(R)return{x:n.ZERO,y:n.ZERO};if(!n.eql(V,n.ONE))throw new Error("invZ was invalid");return{x:L,y:P}}isTorsionFree(){let{isTorsionFree:d}=e;return s===Ft?!0:d?d(E,this):U.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:d}=e;return s===Ft?this:d?d(E,this):this.multiplyUnsafe(s)}isSmallOrder(){return s===Ft?this.is0():this.clearCofactor().is0()}toBytes(d=!0){return Ve(d,"isCompressed"),this.assertValidity(),T(E,this,d)}toHex(d=!0){return br(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let B=o.BITS,U=new Ar(E,e.endo?Math.ceil(B/2):B);return B>=8&&E.BASE.precompute(8),Object.freeze(E.prototype),Object.freeze(E),E}function Af(t){return Uint8Array.of(t?2:3)}function Tf(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Mp(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?cn:e.randomBytes,o=Object.assign(Tf(t.Fp,r),{seed:Math.max(Is(r.ORDER),16)});function i(m){try{let T=r.fromBytes(m);return r.isValidNot0(T)}catch{return!1}}function s(m,T){let{publicKey:A,publicKeyUncompressed:h}=o;try{let g=m.length;return T===!0&&g!==A||T===!1&&g!==h?!1:!!t.fromBytes(m)}catch{return!1}}function a(m){return m=m===void 0?n(o.seed):m,Bs(H(m,o.seed,"seed"),r.ORDER)}function c(m,T=!0){return t.BASE.multiply(r.fromBytes(m)).toBytes(T)}function u(m){let{secretKey:T,publicKey:A,publicKeyUncompressed:h}=o,g=r._lengths;if(!qt(m))return;let v=H(m,void 0,"key").length,C=v===A||v===h,O=v===T||!!g?.includes(v);if(!(C&&O))return C}function f(m,T,A=!0){if(u(m)===!0)throw new Error("first arg must be private key");if(u(T)===!1)throw new Error("second arg must be public key");let h=r.fromBytes(m);return t.fromBytes(T).multiply(h).toBytes(A)}let l={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},y=Po(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:y,Point:t,utils:l,lengths:o})}function If(t,e,r={}){let n=e;To(n),qe(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?cn:r.randomBytes,i=r.hmac===void 0?(w,x)=>xf(n,w,x):r.hmac,{Fp:s,Fn:a}=t,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:y,utils:m,lengths:T}=Mp(t,r),A={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},h=c*Sf+Ft<s.ORDER;function g(w){let x=c>>Ft;return w>x}function v(w,x){if(!a.isValidNot0(x))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return x}function C(){if(h)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function O(w,x){qs(x);let I=T.signature,R=x==="compact"?I:x==="recovered"?I+1:void 0;return H(w,R)}class k{r;s;recovery;constructor(x,I,R){if(this.r=v("r",x),this.s=v("s",I),R!=null){if(C(),![0,1,2,3].includes(R))throw new Error("invalid recovery id");this.recovery=R}Object.freeze(this)}static fromBytes(x,I=A.format){O(x,I);let R;if(I==="der"){let{r:q,s:j}=He.toSig(H(x));return new k(q,j)}I==="recovered"&&(R=x[0],I="compact",x=x.subarray(1));let L=T.signature/2,P=x.subarray(0,L),V=x.subarray(L,L*2);return new k(a.fromBytes(P),a.fromBytes(V),R)}static fromHex(x,I){return this.fromBytes(wr(x),I)}assertRecovery(){let{recovery:x}=this;if(x==null)throw new Error("invalid recovery id: must be present");return x}addRecoveryBit(x){return new k(this.r,this.s,x)}recoverPublicKey(x){let{r:I,s:R}=this,L=this.assertRecovery(),P=L===2||L===3?I+c:I;if(!s.isValid(P))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let V=s.toBytes(P),q=t.fromBytes(ce(Af((L&1)===0),V)),j=a.inv(P),$=N(H(x,void 0,"msgHash")),oe=a.create(-$*j),ue=a.create(R*j),fe=t.BASE.multiplyUnsafe(oe).add(q.multiplyUnsafe(ue));if(fe.is0())throw new Error("invalid recovery: point at infinify");return fe.assertValidity(),fe}hasHighS(){return g(this.s)}toBytes(x=A.format){if(qs(x),x==="der")return wr(He.hexFromSig(this));let{r:I,s:R}=this,L=a.toBytes(I),P=a.toBytes(R);return x==="recovered"?(C(),ce(Uint8Array.of(this.assertRecovery()),L,P)):ce(L,P)}toHex(x){return br(this.toBytes(x))}}Object.freeze(k.prototype),Object.freeze(k);let K=r.bits2int===void 0?function(x){if(x.length>8192)throw new Error("input is too large");let I=Ht(x),R=x.length*8-u;return R>0?I>>BigInt(R):I}:r.bits2int,N=r.bits2int_modN===void 0?function(x){return a.create(K(x))}:r.bits2int_modN,E=ln(u);function B(w){return xr("num < 2^"+u,w,et,E),a.toBytes(w)}function U(w,x){return H(w,void 0,"message"),x?H(n(w),void 0,"prehashed message"):w}function _(w,x,I){let{lowS:R,prehash:L,extraEntropy:P}=$s(I,A);w=U(w,L);let V=N(w),q=a.fromBytes(x);if(!a.isValidNot0(q))throw new Error("invalid private key");let j=[B(q),B(V)];if(P!=null&&P!==!1){let fe=P===!0?o(T.secretKey):P;j.push(H(fe,void 0,"extraEntropy"))}let $=ce(...j),oe=V;function ue(fe){let ee=K(fe);if(!a.isValidNot0(ee))return;let we=a.inv(ee),Zt=t.BASE.multiply(ee).toAffine(),_r=a.create(Zt.x);if(_r===et)return;let xn=a.create(we*a.create(oe+_r*q));if(xn===et)return;let Qs=(Zt.x===_r?0:2)|Number(Zt.y&Ft),Js=xn;return R&&g(xn)&&(Js=a.neg(xn),Qs^=1),new k(_r,Js,h?void 0:Qs)}return{seed:$,k2sig:ue}}function d(w,x,I={}){let{seed:R,k2sig:L}=_(w,x,I);return Hu(n.outputLen,a.BYTES,i)(R,L).toBytes(I.format)}function b(w,x,I,R={}){let{lowS:L,prehash:P,format:V}=$s(R,A);if(I=H(I,void 0,"publicKey"),x=U(x,P),!qt(w)){let q=w instanceof k?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+q)}O(w,V);try{let q=k.fromBytes(w,V),j=t.fromBytes(I);if(L&&q.hasHighS())return!1;let{r:$,s:oe}=q,ue=N(x),fe=a.inv(oe),ee=a.create(ue*fe),we=a.create($*fe),Zt=t.BASE.multiplyUnsafe(ee).add(j.multiplyUnsafe(we));return Zt.is0()?!1:a.create(Zt.x)===$}catch{return!1}}function S(w,x,I={}){let{prehash:R}=$s(I,A);return x=U(x,R),k.fromBytes(w,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:y,utils:m,lengths:T,Point:t,sign:d,verify:b,recoverPublicKey:S,Signature:k,hash:n})}var js={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Kp={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Bf=BigInt(2);function Vp(t){let e=js.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,l=X(f,r,e)*f%e,y=X(l,r,e)*f%e,m=X(y,Bf,e)*u%e,T=X(m,o,e)*m%e,A=X(T,i,e)*T%e,h=X(A,a,e)*A%e,g=X(h,c,e)*h%e,v=X(g,a,e)*A%e,C=X(v,r,e)*f%e,O=X(C,s,e)*T%e,k=X(O,n,e)*u%e,K=X(k,Bf,e);if(!zs.eql(zs.sqr(K),t))throw new Error("Cannot find square root");return K}var zs=Sr(js.p,{sqrt:Vp}),$p=vf(js,{Fp:zs,endo:Kp}),Ir=If($p,Vu);function Cf(t,e,r,n){let o=Nr.digest(r instanceof Uint8Array?r:r.subarray());if(qo(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Ir.verify(e,i,t,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new mn(String(i))});try{return n?.signal?.throwIfAborted(),Ir.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(i){throw new mn(String(i))}}var Yo=class{type="secp256k1";raw;_key;constructor(e){this._key=Df(e),this.raw=_f(this._key)}toMultihash(){return Pe.digest(yr(this))}toCID(){return W.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:le(this.raw,e.raw)}verify(e,r,n){return Cf(this._key,r,e,n)}};function Rf(t){return new Yo(t)}function _f(t){return Ir.Point.fromBytes(t).toBytes()}function Df(t){try{return Ir.Point.fromBytes(t),t}catch(e){throw new oo(String(e))}}function Lf(t){let{Type:e,Data:r}=yn.decode(t.digest),n=r??new Uint8Array;switch(e){case be.Ed25519:return wf(n);case be.secp256k1:return Rf(n);case be.ECDSA:return Au(n);default:throw new Zr}}function yr(t){return yn.encode({Type:be[t.type],Data:t.raw})}var Ff=Symbol.for("nodejs.util.inspect.custom"),qp=114,gn=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()})`}[Wi]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return W.createV1(qp,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return le(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return le(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Ff](){return`PeerId(${this.toString()})`}},Zo=class extends gn{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Go=class extends gn{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Xo=class extends gn{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Hp=2336,Wo=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Pe.digest(te(this.url))}[Ff](){return`PeerId(${this.url})`}[Wi]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return W.createV1(Hp,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=Y(e)),e.toString()===this.toString())}};function Uf(t){if(jp(t))return new Zo({multihash:t});if(zp(t))try{let e=Lf(t);if(e.type==="Ed25519")return new Go({multihash:t,publicKey:e});if(e.type==="secp256k1")return new Xo({multihash:t,publicKey:e})}catch{let r=Y(t.digest);return new Wo(new URL(r))}throw new io("Supplied PeerID Multihash is invalid")}function zp(t){return t.code===Pe.code}function jp(t){return t.code===Nr.code}function Ys(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 Qo(t){let e=ht(G.decode(`z${t}`));return Uf(e)}var bn=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 Ys(this.set.entries(),e=>{let r=Qo(e[0]);return[r,r]})}forEach(e){this.set.forEach(r=>{let n=Qo(r);e(n,n,this)})}has(e){return this.set.has(e.toString())}values(){return Ys(this.set.values(),e=>Qo(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 wn;(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},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.keyName=i.string();break}case 2:{c.lifetime=i.uint32();break}default:{i.skipType(f&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.keyName`,value:i.string()};break}case 2:{yield{field:`${a}.lifetime`,value:i.uint32()};break}default:{i.skipType(f&7);break}}}})),e);function r(i){return je(i,t.codec())}t.encode=r;function n(i,s){return ze(i,t.codec(),s)}t.decode=n;function o(i,s){return Ye(i,t.codec(),s)}t.stream=o})(wn||(wn={}));function Br(t,e){return{async put(r,n,o={}){try{let i=Gr(r);try{let c=await t.get(i),u=At.deserialize(c);if(le(u.value,n))return}catch(c){if(c.name!=="NotFoundError")throw c}let s=new At(r,n,new Date);o.onProgress?.(new ae("ipns:routing:datastore:put"));let a=t.batch();a.put(i,s.serialize()),o.metadata!=null&&a.put(fo(r),wn.encode(o.metadata)),await a.commit(o)}catch(i){throw o.onProgress?.(new ae("ipns:routing:datastore:error",i)),i}},async get(r,n={}){try{let o=Gr(r);n.onProgress?.(new ae("ipns:routing:datastore:get"));let i=await t.get(o,n),s=At.deserialize(i);return{record:Ee(s.value),created:s.timeReceived}}catch(o){throw n.onProgress?.(new ae("ipns:routing:datastore:error",o)),o}},async has(r,n={}){let o=Gr(r);return t.has(o,n)},async delete(r,n){let o=Gr(r),i=t.batch();i.delete(o),i.delete(fo(r)),await i.commit(n)},async*list(r={}){try{r.onProgress?.(new ae("ipns:routing:datastore:list"));for await(let{key:n,value:o}of t.query({prefix:uo},r))try{let i=At.deserialize(o),a=n.toString().substring(uo.length),c=te(a,"base32"),u=fo(c),f;try{let l=await t.get(u,r);f=wn.decode(l)}catch(l){e.error("Error deserializing metadata for %s - %e",a,l)}yield{routingKey:c,metadata:f,record:i.value,created:i.timeReceived}}catch(i){e.error("Error deserializing record - %e",i)}}catch(n){throw r.onProgress?.(new ae("ipns:routing:datastore:error",n)),n}}}}var Zs=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 ae("ipns:routing:helia:error",o)),o}}async get(e,r={}){try{return await this.routing.get(e,r)}catch(n){throw r.onProgress?.(new ae("ipns:routing:helia:error",n)),n}}toString(){return"HeliaRouting()"}};function Cr(t){return new Zs(t)}var Gs=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 Jo(t){return new Gs(t)}var ei=class{routers;publisher;republisher;resolver;localStore;components;started;constructor(e,r={}){this.localStore=Br(e.datastore,e.logger.forComponent("helia:ipns:local-store")),this.components=e,this.started=!1,this.routers=[Jo(this.localStore),Cr(e.routing),...r.routers??[]],this.publisher=new yo(e,{...r,routers:this.routers,localStore:this.localStore}),this.republisher=new vo(e,{...r,routers:this.routers,localStore:this.localStore}),this.resolver=new fr(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(Yp(n))for(let o of Object.values(n.services))Zp(o)&&(o.selectors.ipns=async(i,s)=>{let a=s.map(c=>Z.decode(c));return ur(i,a)},o.validators.ipns=async(i,s)=>{await vt(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,ru(r),n)}async*resolve(e,r={}){let{digest:n}=Xr(e);yield*this.resolver.resolve(n,r)}async unpublish(e,r){return this.publisher.unpublish(e,r)}};function Yp(t){return t?.services!=null}function Zp(t){return t?.validators!=null&&t?.selectors!=null}var ne=Wr("helia:ipns:routing:pubsub"),Ws=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 bn,this.localStore=Br(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 pr({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=>{ne.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;ne("peer %s joined topic %s",o,s.topic);let a=Nf(s.topic);this.#t(s.topic,a,o,{signal:this.shutdownController.signal}).catch(c=>{ne.error("failed to fetch IPNS record for %m from peer %s - %e",a,o,c)})}}),this.libp2p.services.fetch.registerLookupFunction(co,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}}),ne("registered lookup function for IPNS with libp2p/fetch service")}catch(n){ne("unable to register lookup function for IPNS with libp2p/fetch service - %e",n)}else ne("no libp2p/fetch service found. Skipping registration of lookup function for IPNS.")}async#e(e,r){if(ne("message received for topic",e.topic),e.type!=="signed"){ne.error("unsigned message received, this module can only work with signed messages");return}if(e.from.equals(this.libp2p.peerId)){ne("not storing record from self");return}await this.#r(e.topic,Nf(e.topic),e.data,!1,r)}async#t(e,r,n,o){let i=await this.fetchQueue.add(async({signal:s})=>{ne("fetching ipns record for %m from peer %s",r,n);let a=Jr([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 Yr(`Peer ${n} did not have record for routing key ${Y(r,"base64")}`);return ne("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 vt(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 vt(r,a,this.keychain,i);if(le(a,n))return ne.trace("found identical record for %m",r),a;if(ur(r,[c,s])===0)return ne.trace("found old record for %m",r),a}if(ne("found new record for %m",r),await this.localStore.put(r,n,i),o){ne("publish value for topic %s",e);try{let a=await this.libp2p.services.pubsub.publish(e,n);ne("published record on topic %s to %d recipients",e,a.recipients)}catch(a){ne.error("could not publish record on topic %s - %e",a)}}return Ee(n)}async put(e,r,n={}){try{let o=Xs(e);ne("publish value for topic %s",o);let i=await this.libp2p.services.pubsub.publish(o,r);n?.signal?.throwIfAborted(),ne("published record on topic %s to %d recipients",o,i.recipients),n.onProgress?.(new ae("ipns:pubsub:publish",{topic:o,result:i}))}catch(o){throw n.onProgress?.(new ae("ipns:pubsub:error",o)),o}}async get(e,r={}){let n=Xs(e);try{this.libp2p.services.pubsub.getTopics().includes(n)||(ne("add subscription for topic",n),this.libp2p.services.pubsub.subscribe(n),this.subscriptions.add(n),r.onProgress?.(new ae("ipns:pubsub:subscribe",{topic:n})))}catch(s){throw r.onProgress?.(new ae("ipns:pubsub:error",s)),s}await xo(yu(this.fetchDelay),this.shutdownController.signal);let o=new AbortController,i=[];for(let s of this.libp2p.services.pubsub.getSubscribers(n)){let a=Jr([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 Yr("Pubsub routing does not actively query peers")}getSubscriptions(){return[...this.subscriptions]}cancel(e){let r=Yc(e)?e.toMultihash():e,n=it(r),o=Xs(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)}},ti="/record/";function Xs(t){let e=Y(t,"base64url");return`${ti}${e}`}function Nf(t){if(t.substring(0,ti.length)!==ti)throw new Tn("Topic received is not from a record");let e=t.substring(ti.length);return te(e,"base64url")}function Of(t,e={}){return new Ws(t,e)}function Gp(t,e={}){return new ei(t,e)}function Xp(t,e={}){let r=Br(t.datastore,t.logger.forComponent("helia:ipns:local-store")),n=[Jo(r),Cr(t.routing),...e.routers??[]];return new fr(t,{routers:n,localStore:r})}return Hf(Wp);})();
14
14
  /*! Bundled license information:
15
15
 
16
16
  @noble/curves/utils.js: