@helia/ipns 9.2.1-35b081c7 → 9.2.1-ae98a4f4

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,6 +1,6 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaIpns = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
2
  "use strict";var HeliaIpns=(()=>{var Jf=Object.create;var Bn=Object.defineProperty;var Qf=Object.getOwnPropertyDescriptor;var el=Object.getOwnPropertyNames;var tl=Object.getPrototypeOf,rl=Object.prototype.hasOwnProperty;var nl=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),we=(t,e)=>{for(var r in e)Bn(t,r,{get:e[r],enumerable:!0})},oa=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of el(e))!rl.call(t,o)&&o!==r&&Bn(t,o,{get:()=>e[o],enumerable:!(n=Qf(e,o))||n.enumerable});return t};var ei=(t,e,r)=>(r=t!=null?Jf(tl(t)):{},oa(e||!t||!t.__esModule?Bn(r,"default",{value:t,enumerable:!0}):r,t)),ol=t=>oa(Bn({},"__esModule",{value:!0}),t);var lo=nl((qb,Fs)=>{var Vb=(function(){typeof Fs<"u"&&(Fs.exports=v);var t=86400,e=3200,r=146097*e/400,n=t*r,o=1e3*n,i=864e13,s=4294967296,a=1e6,c="000000000",u=Math.trunc||function(E){var _=E-E%1;return _==0&&(E<0||E===0&&1/E!=1/0)?-0:_},f=v.prototype,l=(v.fromDate=function(E){return new v(+E)},v.fromInt64BE=O(0,1,2,3,0,4),v.fromInt64LE=O(3,2,1,0,4,0),v.fromString=function(L){var _,k=new v,L=(L+="").replace(/^\s*[+\-]?\d+/,function(g){var g=+g,A=1970+(g-1970)%400;return k.year=g-A,A}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(d,g,A){return g<0&&(A*=-1),_=6e4*(60*+g+ +A),""}).replace(/\.\d+$/,function(d){return k.nano=+(d+c).substr(1,9),""}).split(/\D+/);if(1<L.length?L[1]--:L[1]=0,k.time=_=Date.UTC.apply(Date,L)-(_||0),isNaN(_))throw new TypeError("Invalid Date");return h(k)},v.fromTimeT=function(E){return T(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 _=h(this),E=Math.floor(_.time/1e3),_=_.year;return _&&(E+=_*r*t/e),E},f.getYear=function(){return this.toDate().getUTCFullYear()+this.year},f.toDate=function(){return w(h(this).time)},f.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},f.toString=function(E){var _=this,k=_.toDate(),L={H:function(){return V(k.getUTCHours())},L:function(){return N(k.getUTCMilliseconds(),3)},M:function(){return V(k.getUTCMinutes())},N:function(){return N(_.getNano(),9)},S:function(){return V(k.getUTCSeconds())},Y:function(){var d=_.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[k.getUTCDay()]},b:function(){return p[k.getUTCMonth()]},d:function(){return V(k.getUTCDate())},e:function(){return(function(d){return(9<d?"":" ")+(0|d)})(k.getUTCDate())},m:function(){return V(k.getUTCMonth()+1)}};return(function d(g){return g.replace(/%./g,function(A){var x=A[1],b=S[x],x=L[x];return b?d(b):x?x():A})})(E||l)},f.writeInt64BE=B(0,1,2,3,0,4),f.writeInt64LE=B(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),p=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],m=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],S={"%":"%",F:"%Y-%m-%d",n:`
3
- `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return v;function v(E,_,k){var L=this;if(!(L instanceof v))return new v(E,_,k);L.time=+E||0,L.nano=+_||0,L.year=+k||0,h(L)}function h(E){var _,k,L,d=E.year,g=E.time,A=E.nano,b=((A<0||a<=A)&&(A-=(k=Math.floor(A/a))*a,g+=k,k=1),d%e);return(g<-i||i<g||b)&&((_=u(g/o))&&(d+=_*e,g-=_*o),(L=w(g)).setUTCFullYear(b+L.getUTCFullYear()),L=(g=+L)+(_=u((d-=b)/e))*o,_&&-i<=L&&L<=i&&(d-=_*e,g=L),k=1),k&&(E.year=d,E.time=g,E.nano=A),E}function w(E){var _=new Date(0);return _.setTime(E),_}function T(d,L){d=+d||0;var k=u((L=(L|0)*s)/n)+u(d/n),L=L%n+d%n,d=u(L/n);return d&&(k+=d,L-=d*n),new v(1e3*L,0,k*e)}function B(E,_,k,L,d,g){return function(b,x){var R=h(this);b=b||new Array(8),F(b,x|=0);var D=Math.floor(R.time/1e3),R=R.year*(r*t/e),I=u(R/s)+u(D/s),R=R%s+D%s,D=Math.floor(R/s);return D&&(I+=D,R-=D*s),A(b,x+d,I),A(b,x+g,R),b};function A(b,x,I){b[x+E]=I>>24&255,b[x+_]=I>>16&255,b[x+k]=I>>8&255,b[x+L]=255&I}}function O(E,_,k,L,d,g){return function(b,x){F(b,x|=0);var I=A(b,x+d);return T(A(b,x+g),I)};function A(b,x){return 16777216*b[x+E]+(b[x+_]<<16|b[x+k]<<8|b[x+L])}}function F(E,_){if(E=E&&E.length,E==null)throw new TypeError("Invalid Buffer");if(E<_+8)throw new RangeError("Out of range")}function V(E){return(9<E?"":"0")+(0|E)}function N(E,_){return(c+(0|E)).substr(-_)}})()});var d0={};we(d0,{ipns:()=>f0,ipnsResolver:()=>l0,ipnsSelector:()=>No,ipnsValidator:()=>xn});var ot=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var Q=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Wt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},Cr=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var _n=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Jt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};function ia(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 il=Symbol.for("@libp2p/peer-id");function Cn(t){return!!t?.[il]}function sl(t){return typeof t?.handleEvent=="function"}function al(t){return(t!==!0&&t!==!1&&t?.once)??!1}var Rn=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=al(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))}sl(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 ii={};we(ii,{base58btc:()=>X,base58flickr:()=>pl});var b0=new Uint8Array(0);function sa(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 it(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function aa(t){return new TextEncoder().encode(t)}function ca(t){return new TextDecoder().decode(t)}function cl(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(S){if(S instanceof Uint8Array||(ArrayBuffer.isView(S)?S=new Uint8Array(S.buffer,S.byteOffset,S.byteLength):Array.isArray(S)&&(S=Uint8Array.from(S))),!(S instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(S.length===0)return"";for(var v=0,h=0,w=0,T=S.length;w!==T&&S[w]===0;)w++,v++;for(var B=(T-w)*f+1>>>0,O=new Uint8Array(B);w!==T;){for(var F=S[w],V=0,N=B-1;(F!==0||V<h)&&N!==-1;N--,V++)F+=256*O[N]>>>0,O[N]=F%a>>>0,F=F/a>>>0;if(F!==0)throw new Error("Non-zero carry");h=V,w++}for(var E=B-h;E!==B&&O[E]===0;)E++;for(var _=c.repeat(v);E<B;++E)_+=t.charAt(O[E]);return _}function p(S){if(typeof S!="string")throw new TypeError("Expected String");if(S.length===0)return new Uint8Array;var v=0;if(S[v]!==" "){for(var h=0,w=0;S[v]===c;)h++,v++;for(var T=(S.length-v)*u+1>>>0,B=new Uint8Array(T);S[v];){var O=r[S.charCodeAt(v)];if(O===255)return;for(var F=0,V=T-1;(O!==0||F<w)&&V!==-1;V--,F++)O+=a*B[V]>>>0,B[V]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");w=F,v++}if(S[v]!==" "){for(var N=T-w;N!==T&&B[N]===0;)N++;for(var E=new Uint8Array(h+(T-N)),_=h;N!==T;)E[_++]=B[N++];return E}}}function m(S){var v=p(S);if(v)return v;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:p,decode:m}}var ul=cl,fl=ul,fa=fl;var ti=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")}},ri=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 la(this,e)}},ni=class{decoders;constructor(e){this.decoders=e}or(e){return la(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 la(t,e){return new ni({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var oi=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 ti(e,r,n),this.decoder=new ri(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Qt({name:t,prefix:e,encode:r,decode:n}){return new oi(t,e,r,n)}function pt({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=fa(r,t);return Qt({prefix:e,name:t,encode:n,decode:i=>it(o(i))})}function ll(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 dl(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 hl(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function ee({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=hl(n);return Qt({prefix:e,name:t,encode(i){return dl(i,n,r)},decode(i){return ll(i,o,r,t)}})}var X=pt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),pl=pt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var si={};we(si,{base32:()=>mt,base32hex:()=>bl,base32hexpad:()=>wl,base32hexpadupper:()=>El,base32hexupper:()=>xl,base32pad:()=>yl,base32padupper:()=>gl,base32upper:()=>ml,base32z:()=>Sl});var mt=ee({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ml=ee({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),yl=ee({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),gl=ee({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),bl=ee({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),xl=ee({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),wl=ee({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),El=ee({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Sl=ee({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ai={};we(ai,{base36:()=>Ne,base36upper:()=>vl});var Ne=pt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),vl=pt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Al=pa,da=128,Tl=127,Il=~Tl,Bl=Math.pow(2,31);function pa(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Bl;)e[r++]=t&255|da,t/=128;for(;t&Il;)e[r++]=t&255|da,t>>>=7;return e[r]=t|0,pa.bytes=r-n+1,e}var _l=ci,Cl=128,ha=127;function ci(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw ci.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&ha)<<o:(s&ha)*Math.pow(2,o),o+=7}while(s>=Cl);return ci.bytes=i-n,r}var Rl=Math.pow(2,7),Dl=Math.pow(2,14),Ll=Math.pow(2,21),Ul=Math.pow(2,28),Fl=Math.pow(2,35),Nl=Math.pow(2,42),kl=Math.pow(2,49),Ol=Math.pow(2,56),Pl=Math.pow(2,63),Kl=function(t){return t<Rl?1:t<Dl?2:t<Ll?3:t<Ul?4:t<Fl?5:t<Nl?6:t<kl?7:t<Ol?8:t<Pl?9:10},Ml={encode:Al,decode:_l,encodingLength:Kl},Vl=Ml,Rr=Vl;function Dr(t,e=0){return[Rr.decode(t,e),Rr.decode.bytes]}function er(t,e,r=0){return Rr.encode(t,e,r),e}function tr(t){return Rr.encodingLength(t)}function Ye(t,e){let r=e.byteLength,n=tr(t),o=n+tr(r),i=new Uint8Array(o+r);return er(t,i,0),er(r,i,n),i.set(e,o),new rr(t,r,e,i)}function nr(t){let e=it(t),[r,n]=Dr(e),[o,i]=Dr(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new rr(r,o,s,e)}function ma(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&sa(t.bytes,r.bytes)}}var rr=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function ya(t,e){let{bytes:r,version:n}=t;return n===0?$l(r,ui(t),e??X.encoder):Hl(r,ui(t),e??mt.encoder)}var ga=new WeakMap;function ui(t){let e=ga.get(t);if(e==null){let r=new Map;return ga.set(t,r),r}return e}var ie=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Lr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==zl)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=Ye(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&&ma(e.multihash,n.multihash)}toString(e){return ya(this,e)}toJSON(){return{"/":ya(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??ba(n,o,i.bytes))}else if(r[jl]===!0){let{version:n,multihash:o,code:i}=r,s=nr(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=ba(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=it(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 rr(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,p]=Dr(e.subarray(r));return r+=p,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]=ql(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 ui(i).set(n,e),i}};function ql(t,e){switch(t[0]){case"Q":{let r=e??X;return[X.prefix,r.decode(`${X.prefix}${t}`)]}case X.prefix:{let r=e??X;return[X.prefix,r.decode(t)]}case mt.prefix:{let r=e??mt;return[mt.prefix,r.decode(t)]}case Ne.prefix:{let r=e??Ne;return[Ne.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function $l(t,e,r){let{prefix:n}=r;if(n!==X.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 Hl(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,zl=18;function ba(t,e,r){let n=tr(t),o=n+tr(e),i=new Uint8Array(o+r.byteLength);return er(t,i,0),er(e,i,n),i.set(r,o),i}var jl=Symbol.for("@ipld/js-cid/CID");var fi={};we(fi,{identity:()=>Nt});var xa=0,Yl="identity",wa=it;function Zl(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 Ye(xa,wa(t))}var Nt={code:xa,name:Yl,encode:wa,digest:Zl};function ne(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=0){return new Uint8Array(t)}function Ae(t=0){return new Uint8Array(t)}function yt(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 r}var Sa=Symbol.for("@achingbrain/uint8arraylist");function Ea(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 Ln(t){return!!t?.[Sa]}var ye=class t{bufs;length;[Sa]=!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(Ln(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(Ln(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=Ea(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Ea(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(Ln(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 yt(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:yt(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(!Ln(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 p=u;p>=0;p--){let m=this.get(l+p);if(n[p]!==m){f=Math.max(1,p-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=Le(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=Le(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=Le(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=Le(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=Le(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=Le(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=Le(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=Le(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(!ne(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};var li={};we(li,{base10:()=>Gl});var Gl=pt({prefix:"9",name:"base10",alphabet:"0123456789"});var di={};we(di,{base16:()=>Xl,base16upper:()=>Wl});var Xl=ee({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Wl=ee({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var hi={};we(hi,{base2:()=>Jl});var Jl=ee({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var pi={};we(pi,{base256emoji:()=>nd});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}"),Ql=va.reduce((t,e,r)=>(t[r]=e,t),[]),ed=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 td(t){return t.reduce((e,r)=>(e+=Ql[r],e),"")}function rd(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=ed[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var nd=Qt({prefix:"\u{1F680}",name:"base256emoji",encode:td,decode:rd});var yi={};we(yi,{base64:()=>mi,base64pad:()=>od,base64url:()=>id,base64urlpad:()=>sd});var mi=ee({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),od=ee({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),id=ee({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),sd=ee({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var gi={};we(gi,{base8:()=>ad});var ad=ee({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var bi={};we(bi,{identity:()=>cd});var cd=Qt({prefix:"\0",name:"identity",encode:t=>ca(t),decode:t=>aa(t)});var tm=new TextEncoder,rm=new TextDecoder;var Ei={};we(Ei,{sha256:()=>Un,sha512:()=>dd});var ld=20;function wi({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new xi(t,e,r,n,o)}var xi=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??ld,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?Aa(n,this.code,r?.truncate):n.then(o=>Aa(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Aa(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 Ye(e,t)}function Ia(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Un=wi({name:"sha2-256",code:18,encode:Ia("SHA-256")}),dd=wi({name:"sha2-512",code:19,encode:Ia("SHA-512")});var Si={...bi,...hi,...gi,...li,...di,...si,...ai,...ii,...yi,...pi},pm={...Ei,...fi};function _a(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Ba=_a("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),vi=_a("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}),hd={utf8:Ba,"utf-8":Ba,hex:Si.base16,latin1:vi,ascii:vi,binary:vi,...Si},Fn=hd;function $(t,e="utf8"){let r=Fn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Z(t,e="utf8"){let r=Fn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var pd=parseInt("11111",2),Ai=parseInt("10000000",2),md=parseInt("01111111",2),Ca={0:Ur,1:Ur,2:yd,3:xd,4:wd,5:bd,6:gd,16:Ur,22:Ur,48:Ur};function st(t,e={offset:0}){let r=t[e.offset]&pd;if(e.offset++,Ca[r]!=null)return Ca[r](t,e);throw new Error("No decoder for tag "+r)}function Fr(t,e){let r=0;if((t[e.offset]&Ai)===Ai){let n=t[e.offset]&md,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 Ur(t,e){Fr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=st(t,e);if(n===null)break;r.push(n)}return r}function yd(t,e){let r=Fr(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 gd(t,e){let r=Fr(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 bd(t,e){return e.offset++,null}function xd(t,e){let r=Fr(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 wd(t,e){let r=Fr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function Ed(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new ye;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Nn(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=Ed(t.byteLength);return new ye(Uint8Array.from([e.byteLength|Ai]),e)}function ge(t){let e=new ye,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new ye(Uint8Array.from([2]),Nn(e),e)}function Nr(t){let e=Uint8Array.from([0]),r=new ye(e,t);return new ye(Uint8Array.from([3]),Nn(r),r)}function Ra(t){return new ye(Uint8Array.from([4]),Nn(t),t)}function ke(t,e=48){let r=new ye;for(let n of t)r.append(n);return new ye(Uint8Array.from([e]),Nn(r),r)}async function Da(t="P-256"){let e=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:t},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",e.publicKey),privateKey:await crypto.subtle.exportKey("jwk",e.privateKey)}}async function La(t,e,r){let n=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["sign"]);r?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,e.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Ua(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,e,r.subarray());return n?.signal?.throwIfAborted(),i}var Sd=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),vd=Uint8Array.from([6,5,43,129,4,0,34]),Ad=Uint8Array.from([6,5,43,129,4,0,35]),Td={ext:!0,kty:"EC",crv:"P-256"},Id={ext:!0,kty:"EC",crv:"P-384"},Bd={ext:!0,kty:"EC",crv:"P-521"},Ti=32,Ii=48,Bi=66;function _i(t){let e=st(t);return Fa(e)}function Fa(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===Ti*2+1)return n=Z(e.subarray(r,r+Ti),"base64url"),o=Z(e.subarray(r+Ti),"base64url"),new kt({...Td,key_ops:["verify"],x:n,y:o});if(e.byteLength===Ii*2+1)return n=Z(e.subarray(r,r+Ii),"base64url"),o=Z(e.subarray(r+Ii),"base64url"),new kt({...Id,key_ops:["verify"],x:n,y:o});if(e.byteLength===Bi*2+1)return n=Z(e.subarray(r,r+Bi),"base64url"),o=Z(e.subarray(r+Bi),"base64url"),new kt({...Bd,key_ops:["verify"],x:n,y:o});throw new Q(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Na(t){return ke([ge(Uint8Array.from([1])),Ra($(t.d??"","base64url")),ke([Oa(t.crv)],160),ke([Nr(new ye(Uint8Array.from([4]),$(t.x??"","base64url"),$(t.y??"","base64url")))],161)]).subarray()}function ka(t){return ke([ge(Uint8Array.from([1])),ke([Oa(t.crv)],160),ke([Nr(new ye(Uint8Array.from([4]),$(t.x??"","base64url"),$(t.y??"","base64url")))],161)]).subarray()}function Oa(t){if(t==="P-256")return Sd;if(t==="P-384")return vd;if(t==="P-521")return Ad;throw new Q(`Invalid curve ${t}`)}async function Pa(t="P-256"){let e=await Da(t);return new kn(e.privateKey)}var kt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=ka(this.jwk)),this._raw}toMultihash(){return Nt.digest(gt(this))}toCID(){return ie.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ne(this.raw,e.raw)}async verify(e,r,n){return Ua(this.jwk,r,e,n)}},kn=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new kt({crv:e.crv,ext:e.ext,key_ops:["verify"],kty:"EC",x:e.x,y:e.y})}get raw(){return this._raw==null&&(this._raw=Na(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ne(this.raw,e.raw)}async sign(e,r){return La(this.jwk,e,r)}};function Ci(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function bt(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 Te(t,e,r=""){let n=Ci(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 On(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(bt(t.outputLen),bt(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function or(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 Pn(t,e){Te(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 ct(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Kn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Oe(t,e){return t<<32-e|t>>>e}var Ma=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",_d=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Mn(t){if(Te(t),Ma)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=_d[t[r]];return e}var at={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ka(t){if(t>=at._0&&t<=at._9)return t-at._0;if(t>=at.A&&t<=at.F)return t-(at.A-10);if(t>=at.a&&t<=at.f)return t-(at.a-10)}function kr(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Ma)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=Ka(t.charCodeAt(i)),a=Ka(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 Ri(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Te(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 Di(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 Va(t=32){bt(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 Li=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function qa(t,e,r){return t&e^~t&r}function $a(t,e,r){return t&e^t&r^e&r}var Or=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=Kn(this.buffer)}update(e){or(this),Te(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=Kn(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){or(this),Pn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,ct(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=Kn(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()}},ut=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var de=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Vn=BigInt(4294967295),Ha=BigInt(32);function Cd(t,e=!1){return e?{h:Number(t&Vn),l:Number(t>>Ha&Vn)}:{h:Number(t>>Ha&Vn)|0,l:Number(t&Vn)|0}}function za(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}=Cd(t[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var Ui=(t,e,r)=>t>>>r,Fi=(t,e,r)=>t<<32-r|e>>>r,Ot=(t,e,r)=>t>>>r|e<<32-r,Pt=(t,e,r)=>t<<32-r|e>>>r,Pr=(t,e,r)=>t<<64-r|e>>>r-32,Kr=(t,e,r)=>t>>>r-32|e<<64-r;function Ze(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var ja=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Ya=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Za=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Ga=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Xa=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Wa=(t,e,r,n,o,i)=>e+r+n+o+i+(t/2**32|0)|0;var Dd=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]),xt=new Uint32Array(64),Ni=class extends Or{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)xt[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let p=xt[l-15],m=xt[l-2],S=Oe(p,7)^Oe(p,18)^p>>>3,v=Oe(m,17)^Oe(m,19)^m>>>10;xt[l]=v+xt[l-7]+S+xt[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 p=Oe(a,6)^Oe(a,11)^Oe(a,25),m=f+p+qa(a,c,u)+Dd[l]+xt[l]|0,v=(Oe(n,2)^Oe(n,13)^Oe(n,22))+$a(n,o,i)|0;f=u,u=c,c=a,a=s+m|0,s=i,i=o,o=n,n=m+v|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,i,s,a,c,u,f)}roundClean(){ct(xt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),ct(this.buffer)}},ki=class extends Ni{A=ut[0]|0;B=ut[1]|0;C=ut[2]|0;D=ut[3]|0;E=ut[4]|0;F=ut[5]|0;G=ut[6]|0;H=ut[7]|0;constructor(){super(32)}};var Ja=za(["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))),Ld=Ja[0],Ud=Ja[1],wt=new Uint32Array(80),Et=new Uint32Array(80),Oi=class extends Or{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:p,Gh:m,Gl:S,Hh:v,Hl:h}=this;return[e,r,n,o,i,s,a,c,u,f,l,p,m,S,v,h]}set(e,r,n,o,i,s,a,c,u,f,l,p,m,S,v,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=p|0,this.Gh=m|0,this.Gl=S|0,this.Hh=v|0,this.Hl=h|0}process(e,r){for(let B=0;B<16;B++,r+=4)wt[B]=e.getUint32(r),Et[B]=e.getUint32(r+=4);for(let B=16;B<80;B++){let O=wt[B-15]|0,F=Et[B-15]|0,V=Ot(O,F,1)^Ot(O,F,8)^Ui(O,F,7),N=Pt(O,F,1)^Pt(O,F,8)^Fi(O,F,7),E=wt[B-2]|0,_=Et[B-2]|0,k=Ot(E,_,19)^Pr(E,_,61)^Ui(E,_,6),L=Pt(E,_,19)^Kr(E,_,61)^Fi(E,_,6),d=Za(N,L,Et[B-7],Et[B-16]),g=Ga(d,V,k,wt[B-7],wt[B-16]);wt[B]=g|0,Et[B]=d|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:p,Fh:m,Fl:S,Gh:v,Gl:h,Hh:w,Hl:T}=this;for(let B=0;B<80;B++){let O=Ot(l,p,14)^Ot(l,p,18)^Pr(l,p,41),F=Pt(l,p,14)^Pt(l,p,18)^Kr(l,p,41),V=l&m^~l&v,N=p&S^~p&h,E=Xa(T,F,N,Ud[B],Et[B]),_=Wa(E,w,O,V,Ld[B],wt[B]),k=E|0,L=Ot(n,o,28)^Pr(n,o,34)^Pr(n,o,39),d=Pt(n,o,28)^Kr(n,o,34)^Kr(n,o,39),g=n&i^n&a^i&a,A=o&s^o&c^s&c;w=v|0,T=h|0,v=m|0,h=S|0,m=l|0,S=p|0,{h:l,l:p}=Ze(u|0,f|0,_|0,k|0),u=a|0,f=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let b=ja(k,d,A);n=Ya(b,_,L,g),o=b|0}({h:n,l:o}=Ze(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Ze(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Ze(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Ze(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:p}=Ze(this.Eh|0,this.El|0,l|0,p|0),{h:m,l:S}=Ze(this.Fh|0,this.Fl|0,m|0,S|0),{h:v,l:h}=Ze(this.Gh|0,this.Gl|0,v|0,h|0),{h:w,l:T}=Ze(this.Hh|0,this.Hl|0,w|0,T|0),this.set(n,o,i,s,a,c,u,f,l,p,m,S,v,h,w,T)}roundClean(){ct(wt,Et)}destroy(){this.destroyed=!0,ct(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Pi=class extends Oi{Ah=de[0]|0;Al=de[1]|0;Bh=de[2]|0;Bl=de[3]|0;Ch=de[4]|0;Cl=de[5]|0;Dh=de[6]|0;Dl=de[7]|0;Eh=de[8]|0;El=de[9]|0;Fh=de[10]|0;Fl=de[11]|0;Gh=de[12]|0;Gl=de[13]|0;Hh=de[14]|0;Hl=de[15]|0;constructor(){super(64)}};var ir=Di(()=>new ki,Li(1));var qn=Di(()=>new Pi,Li(3));var z=(t,e,r)=>Te(t,e,r),Mi=bt,sr=Mn,ae=(...t)=>Ri(...t),ar=t=>kr(t),Kt=Ci,Mr=t=>Va(t),Hn=BigInt(0),Ki=BigInt(1);function Pe(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function zn(t){if(typeof t=="bigint"){if(!$n(t))throw new RangeError("positive bigint expected, got "+t)}else Mi(t);return t}function Ke(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 Vr(t){let e=zn(t).toString(16);return e.length&1?"0"+e:e}function Qa(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Hn:BigInt("0x"+t)}function Mt(t){return Qa(Mn(t))}function Ge(t){return Qa(Mn(qr(Te(t)).reverse()))}function jn(t,e){if(bt(e),e===0)throw new RangeError("zero length");t=zn(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return kr(r.padStart(e*2,"0"))}function Vi(t,e){return jn(t,e).reverse()}function ec(t,e){if(t=z(t),e=z(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 qr(t){return Uint8Array.from(z(t))}function Yn(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 $n=t=>typeof t=="bigint"&&Hn<=t;function Fd(t,e,r){return $n(t)&&$n(e)&&$n(r)&&e<=t&&t<r}function cr(t,e,r,n){if(!Fd(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function ur(t){if(t<Hn)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>Hn;t>>=Ki,e+=1);return e}var $r=t=>(Ki<<BigInt(t))-Ki;function tc(t,e,r){if(bt(t,"hashLen"),bt(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},p=(...h)=>r(u,ae(c,...h)),m=(h=o)=>{u=p(i,h),c=p(),h.length!==0&&(u=p(s,h),c=p())},S=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let h=0,w=[];for(;h<e;){c=p();let T=c.slice();w.push(T),h+=c.length}return ae(...w)};return(h,w)=>{l(),m(h);let T;for(;(T=w(S()))===void 0;)m();return l(),T}}function Me(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 qi=()=>{throw new Error("not implemented")};var he=BigInt(0),te=BigInt(1),Vt=BigInt(2),ic=BigInt(3),sc=BigInt(4),ac=BigInt(5),Nd=BigInt(7),cc=BigInt(8),kd=BigInt(9),uc=BigInt(16);function oe(t,e){if(e<=he)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=he?r:e+r}function W(t,e,r){if(e<he)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >he;)n*=n,n%=r;return n}function rc(t,e){if(t===he)throw new Error("invert: expected non-zero number");if(e<=he)throw new Error("invert: expected positive modulus, got "+e);let r=oe(t,e),n=e,o=he,i=te,s=te,a=he;for(;r!==he;){let u=n/r,f=n-r*u,l=o-s*u,p=i-a*u;n=r,r=f,o=s,i=a,s=l,a=p}if(n!==te)throw new Error("invert: does not exist");return oe(o,e)}function $i(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function fc(t,e){let r=t,n=(r.ORDER+te)/sc,o=r.pow(e,n);return $i(r,o,e),o}function Od(t,e){let r=t,n=(r.ORDER-ac)/cc,o=r.mul(e,Vt),i=r.pow(o,n),s=r.mul(e,i),a=r.mul(r.mul(s,Vt),i),c=r.mul(s,r.sub(a,r.ONE));return $i(r,c,e),c}function Pd(t){let e=fr(t),r=lc(t),n=r(e,e.neg(e.ONE)),o=r(e,n),i=r(e,e.neg(n)),s=(t+Nd)/uc;return((a,c)=>{let u=a,f=u.pow(c,s),l=u.mul(f,n),p=u.mul(f,o),m=u.mul(f,i),S=u.eql(u.sqr(l),c),v=u.eql(u.sqr(p),c);f=u.cmov(f,l,S),l=u.cmov(m,p,v);let h=u.eql(u.sqr(l),c),w=u.cmov(f,l,h);return $i(u,w,c),w})}function lc(t){if(t<ic)throw new Error("sqrt is not defined for small field");let e=t-te,r=0;for(;e%Vt===he;)e/=Vt,r++;let n=Vt,o=fr(t);for(;nc(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return fc;let i=o.pow(n,e),s=(e+te)/Vt;return function(c,u){let f=c;if(f.is0(u))return u;if(nc(f,u)!==1)throw new Error("Cannot find square root");let l=r,p=f.mul(f.ONE,i),m=f.pow(u,e),S=f.pow(u,s);for(;!f.eql(m,f.ONE);){if(f.is0(m))return f.ZERO;let v=1,h=f.sqr(m);for(;!f.eql(h,f.ONE);)if(v++,h=f.sqr(h),v===l)throw new Error("Cannot find square root");let w=te<<BigInt(l-v-1),T=f.pow(p,w);l=v,p=f.sqr(T),m=f.mul(m,p),S=f.mul(S,T)}return S}}function Kd(t){return t%sc===ic?fc:t%cc===ac?Od:t%uc===kd?Pd(t):lc(t)}var ft=(t,e)=>(oe(t,e)&te)===te,Md=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Hi(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Md.reduce((n,o)=>(n[o]="function",n),e);if(Me(t,r),Ke(t.BYTES,"BYTES"),Ke(t.BITS,"BITS"),t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=te)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Vd(t,e,r){let n=t;if(r<he)throw new Error("invalid exponent, negatives unsupported");if(r===he)return n.ONE;if(r===te)return e;let o=n.ONE,i=e;for(;r>he;)r&te&&(o=n.mul(o,i)),i=n.sqr(i),r>>=te;return o}function Hr(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 nc(t,e){let r=t,n=(r.ORDER-te)/Vt,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 qd(t,e){if(e!==void 0&&Mi(e),t<=he)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=ur(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 oc=new WeakMap,Zn=class{ORDER;BITS;BYTES;isLE;ZERO=he;ONE=te;_lengths;_mod;constructor(e,r={}){if(e<=te)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}=qd(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 oe(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return he<=e&&e<this.ORDER}is0(e){return e===he}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&te)===te}neg(e){return oe(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return oe(e*e,this.ORDER)}add(e,r){return oe(e+r,this.ORDER)}sub(e,r){return oe(e-r,this.ORDER)}mul(e,r){return oe(e*r,this.ORDER)}pow(e,r){return Vd(this,e,r)}div(e,r){return oe(e*rc(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 rc(e,this.ORDER)}sqrt(e){let r=oc.get(this);return r||oc.set(this,r=Kd(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Vi(e,this.BYTES):jn(e,this.BYTES)}fromBytes(e,r=!1){z(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?Ge(e):Mt(e);if(a&&(c=oe(c,s)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Hr(this,e)}cmov(e,r,n){return Pe(n,"condition"),n?r:e}};Object.freeze(Zn.prototype);function fr(t,e={}){return new Zn(t,e)}function dc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=te)throw new Error("field order must be greater than 1");let e=ur(t-te);return Math.ceil(e/8)}function zi(t){let e=dc(t);return e+Math.ceil(e/2)}function ji(t,e,r=!1){z(t);let n=t.length,o=dc(e),i=Math.max(zi(e),16);if(n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Ge(t):Mt(t),a=oe(s,e-te)+te;return r?Vi(a,o):jn(a,o)}var lr=BigInt(0),qt=BigInt(1);function zr(t,e){let r=e.negate();return t?r:e}function $t(t,e){let r=Hr(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function yc(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Yi(t,e){yc(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,i=$r(t),s=BigInt(t);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function hc(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,p=a<0,m=e%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:p,isNegF:m,offsetF:u}}var Zi=new WeakMap,gc=new WeakMap;function Gi(t){return gc.get(t)||1}function pc(t){if(t!==lr)throw new Error("invalid wNAF")}var dr=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>lr;)r&qt&&(n=n.add(o)),o=o.double(),r>>=qt;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=Yi(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=Yi(e,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:p,offsetF:m}=hc(n,a,s);n=c,f?i=i.add(zr(p,r[m])):o=o.add(zr(l,r[u]))}return pc(n),{p:o,f:i}}wNAFUnsafe(e,r,n,o=this.ZERO){let i=Yi(e,this.bits);for(let s=0;s<i.windows&&n!==lr;s++){let{nextN:a,offset:c,isZero:u,isNeg:f}=hc(n,s,i);if(n=a,!u){let l=r[c];o=o.add(f?l.negate():l)}}return pc(n),o}getPrecomputes(e,r,n){let o=Zi.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),Zi.set(r,o))),o}cached(e,r,n){let o=Gi(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let i=Gi(e);return i===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),r,o)}createCache(e,r){yc(r,this.bits),gc.set(e,r),Zi.delete(e)}hasCache(e){return Gi(e)!==1}};function bc(t,e,r,n){let o=e,i=t.ZERO,s=t.ZERO;for(;r>lr||n>lr;)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 mc(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Hi(e),e}else return fr(t,{isLE:r})}function Gn(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>lr))throw new Error(`CURVE.${c} must be positive bigint`)}let o=mc(e.p,r.Fp,n),i=mc(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 Xn(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var St=BigInt(0),fe=BigInt(1),Xi=BigInt(2),$d=BigInt(8);function Hd(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 xc(t,e={}){let r=e,n=Gn("edwards",t,r,r.FpFnLE),{Fp:o,Fn:i}=n,s=n.CURVE,{h:a}=s;Me(r,{},{uvRatio:"function"});let c=Xi<<BigInt(i.BYTES*8)-fe,u=v=>o.create(v),f=r.uvRatio===void 0?(v,h)=>{try{return{isValid:!0,value:o.sqrt(o.div(v,h))}}catch{return{isValid:!1,value:St}}}:r.uvRatio;if(!Hd(o,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function l(v,h,w=!1){let T=w?fe:St;return cr("coordinate "+v,h,T,c),h}function p(v){if(!(v instanceof m))throw new Error("EdwardsPoint expected")}class m{static BASE=new m(s.Gx,s.Gy,fe,u(s.Gx*s.Gy));static ZERO=new m(St,fe,fe,St);static Fp=o;static Fn=i;X;Y;Z;T;constructor(h,w,T,B){this.X=l("x",h),this.Y=l("y",w),this.Z=l("z",T,!0),this.T=l("t",B),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){if(h instanceof m)throw new Error("extended point not allowed");let{x:w,y:T}=h||{};return l("x",w),l("y",T),new m(w,T,fe,u(w*T))}static fromBytes(h,w=!1){let T=o.BYTES,{a:B,d:O}=s;h=qr(z(h,T,"point")),Pe(w,"zip215");let F=qr(h),V=h[T-1];F[T-1]=V&-129;let N=Ge(F),E=w?c:o.ORDER;cr("point.y",N,St,E);let _=u(N*N),k=u(_-fe),L=u(O*_-B),{isValid:d,value:g}=f(k,L);if(!d)throw new Error("bad point: invalid y coordinate");let A=(g&fe)===fe,b=(V&128)!==0;if(!w&&g===St&&b)throw new Error("bad point: x=0 and x_0=1");return b!==A&&(g=u(-g)),m.fromAffine({x:g,y:N})}static fromHex(h,w=!1){return m.fromBytes(ar(h),w)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,w=!0){return S.createCache(this,h),w||this.multiply(Xi),this}assertValidity(){let h=this,{a:w,d:T}=s;if(h.is0())throw new Error("bad point: ZERO");let{X:B,Y:O,Z:F,T:V}=h,N=u(B*B),E=u(O*O),_=u(F*F),k=u(_*_),L=u(N*w),d=u(_*u(L+E)),g=u(k+u(T*u(N*E)));if(d!==g)throw new Error("bad point: equation left != right (1)");let A=u(B*O),b=u(F*V);if(A!==b)throw new Error("bad point: equation left != right (2)")}equals(h){p(h);let{X:w,Y:T,Z:B}=this,{X:O,Y:F,Z:V}=h,N=u(w*V),E=u(O*B),_=u(T*V),k=u(F*B);return N===E&&_===k}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:w,Y:T,Z:B}=this,O=u(w*w),F=u(T*T),V=u(Xi*u(B*B)),N=u(h*O),E=w+T,_=u(u(E*E)-O-F),k=N+F,L=k-V,d=N-F,g=u(_*L),A=u(k*d),b=u(_*d),x=u(L*k);return new m(g,A,x,b)}add(h){p(h);let{a:w,d:T}=s,{X:B,Y:O,Z:F,T:V}=this,{X:N,Y:E,Z:_,T:k}=h,L=u(B*N),d=u(O*E),g=u(V*T*k),A=u(F*_),b=u((B+O)*(N+E)-L-d),x=A-g,I=A+g,R=u(d-w*L),D=u(b*x),P=u(I*R),M=u(b*R),H=u(x*I);return new m(D,P,H,M)}subtract(h){return p(h),this.add(h.negate())}multiply(h){if(!i.isValidNot0(h))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:w,f:T}=S.cached(this,h,B=>$t(m,B));return $t(m,[w,T])[0]}multiplyUnsafe(h){if(!i.isValid(h))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return h===St?m.ZERO:this.is0()||h===fe?this:S.unsafe(this,h,w=>$t(m,w))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return S.unsafe(this,s.n).is0()}toAffine(h){let w=this,T=h,{X:B,Y:O,Z:F}=w,V=w.is0();T==null&&(T=V?$d:o.inv(F));let N=u(B*T),E=u(O*T),_=o.mul(F,T);if(V)return{x:St,y:fe};if(_!==fe)throw new Error("invZ was invalid");return{x:N,y:E}}clearCofactor(){return a===fe?this:this.multiplyUnsafe(a)}toBytes(){let{x:h,y:w}=this.toAffine(),T=o.toBytes(w);return T[T.length-1]|=h&fe?128:0,T}toHex(){return sr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let S=new dr(m,i.BITS);return i.BITS>=8&&m.BASE.precompute(8),Object.freeze(m.prototype),Object.freeze(m),m}var Wn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){qi()}static fromHex(e){qi()}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 sr(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 wc(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Me(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&&(Ke(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?Mr:o.randomBytes,p=o.adjustScalarBytes===void 0?d=>d:o.adjustScalarBytes,m=o.domain===void 0?(d,g,A)=>{if(Pe(A,"phflag"),g.length||A)throw new Error("Contexts/pre-hash are not supported");return d}:o.domain;function S(d){return c.create(Ge(d))}function v(d){let g=N.secretKey;z(d,N.secretKey,"secretKey");let A=z(n(d),2*g,"hashedSecretKey"),b=p(A.slice(0,g)),x=A.slice(g,2*g),I=S(b);return{head:b,prefix:x,scalar:I}}function h(d){let{head:g,prefix:A,scalar:b}=v(d),x=s.multiply(b),I=x.toBytes();return{head:g,prefix:A,scalar:b,point:x,pointBytes:I}}function w(d){return h(d).pointBytes}function T(d=Uint8Array.of(),...g){let A=ae(...g);return S(n(m(A,z(d,void 0,"context"),!!i)))}function B(d,g,A={}){d=z(d,void 0,"message"),i&&(d=i(d));let{prefix:b,scalar:x,pointBytes:I}=h(g),R=T(A.context,b,d),D=s.multiply(R).toBytes(),P=T(A.context,D,I,d),M=c.create(R+P*x);if(!c.isValid(M))throw new Error("sign failed: invalid s");let H=ae(D,c.toBytes(M));return z(H,N.signature,"result")}let O={zip215:o.zip215};function F(d,g,A,b=O){let{context:x}=b,I=b.zip215===void 0?!!O.zip215:b.zip215,R=N.signature;d=z(d,R,"signature"),g=z(g,void 0,"message"),A=z(A,N.publicKey,"publicKey"),I!==void 0&&Pe(I,"zip215"),i&&(g=i(g));let D=R/2,P=d.subarray(0,D),M=Ge(d.subarray(D,R)),H,Y,q;try{H=t.fromBytes(A,I),Y=t.fromBytes(P,I),q=s.multiplyUnsafe(M)}catch{return!1}if(!I&&H.isSmallOrder())return!1;let se=T(x,P,A,g);return Y.add(H.multiplyUnsafe(se)).subtract(q).clearCofactor().is0()}let V=a.BYTES,N={secretKey:V,publicKey:V,signature:2*V,seed:V};function E(d){return d=d===void 0?l(N.seed):d,z(d,N.seed,"seed")}function _(d){return Kt(d)&&d.length===N.secretKey}function k(d,g){try{return!!t.fromBytes(d,g===void 0?O.zip215:g)}catch{return!1}}let L={getExtendedPublicKey:h,randomSecretKey:E,isValidSecretKey:_,isValidPublicKey:k,toMontgomery(d){let{y:g}=t.fromBytes(d),A=N.publicKey,b=A===32;if(!b&&A!==57)throw new Error("only defined for 25519 and 448");let x=b?a.div(fe+g,fe-g):a.div(g-fe,g+fe);return a.toBytes(x)},toMontgomerySecret(d){let g=N.secretKey;z(d,g);let A=n(d.subarray(0,g));return p(A).subarray(0,g)}};return Object.freeze(N),Object.freeze(L),Object.freeze({keygen:Xn(E,w),getPublicKey:w,sign:B,verify:F,utils:L,Point:t,lengths:N})}function jr(t,e){if(Ke(t),Ke(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 zd(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 jd(t){if(!Kt(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?Yn(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function Wi(t,e,r,n){z(t),Ke(r),e=jd(e),e.length>255&&(e=n(ae(Yn("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,jr(e.length,1)),c=new Uint8Array(i),u=jr(r,2),f=new Array(s),l=n(ae(c,t,u,jr(0,1),a));f[0]=n(ae(l,jr(1,1),a));for(let m=1;m<s;m++){let S=[zd(l,f[m-1]),jr(m+1,1),a];f[m]=n(ae(...S))}return ae(...f).slice(0,r)}var Ec="HashToScalar-";var Yd=BigInt(0),lt=BigInt(1),Sc=BigInt(2);var Zd=BigInt(5),Gd=BigInt(8),hr=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ts={p:hr,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Gd,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Xd(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=hr,a=t*t%i*t%i,c=W(a,Sc,i)*a%i,u=W(c,lt,i)*t%i,f=W(u,Zd,i)*u%i,l=W(f,e,i)*f%i,p=W(l,r,i)*l%i,m=W(p,n,i)*p%i,S=W(m,o,i)*m%i,v=W(S,o,i)*m%i,h=W(v,e,i)*f%i;return{pow_p_5_8:W(h,Sc,i)*t%i,b2:a}}function Wd(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var Ji=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function rs(t,e){let r=hr,n=oe(e*e*e,r),o=oe(n*n*e,r),i=Xd(t*o).pow_p_5_8,s=oe(t*n*i,r),a=oe(e*s*s,r),c=s,u=oe(s*Ji,r),f=a===t,l=a===oe(-t,r),p=a===oe(-t*Ji,r);return f&&(s=c),(l||p)&&(s=u),ft(s,r)&&(s=oe(-s,r)),{isValid:f||l,value:s}}var At=xc(ts,{uvRatio:rs}),vt=At.Fp,Tc=At.Fn;function Jd(t){return wc(At,qn,Object.assign({adjustScalarBytes:Wd,zip215:!0},t))}var Yr=Jd({});var Qi=Ji,Qd=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),eh=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),th=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),rh=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),vc=t=>rs(lt,t),nh=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),es=t=>vt.create(Ge(t)&nh);function Ac(t){let{d:e}=ts,r=hr,n=w=>vt.create(w),o=n(Qi*t*t),i=n((o+lt)*th),s=BigInt(-1),a=n((s-e*o)*n(o+e)),{isValid:c,value:u}=rs(i,a),f=n(u*t);ft(f,r)||(f=n(-f)),c||(u=f),c||(s=o);let l=n(s*(o-lt)*rh-a),p=u*u,m=n((u+u)*a),S=n(l*Qd),v=n(lt-p),h=n(lt+p);return new At(n(m*h),n(v*S),n(S*h),n(m*v))}var Tt=class t extends Wn{static BASE=new t(At.BASE);static ZERO=new t(At.ZERO);static Fp=vt;static Fn=Tc;constructor(e){super(e)}static fromAffine(e){return new t(At.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static fromBytes(e){Te(e,32);let{a:r,d:n}=ts,o=hr,i=O=>vt.create(O),s=es(e);if(!ec(vt.toBytes(s),e)||ft(s,o))throw new Error("invalid ristretto255 encoding 1");let a=i(s*s),c=i(lt+r*a),u=i(lt-r*a),f=i(c*c),l=i(u*u),p=i(r*n*f-l),{isValid:m,value:S}=vc(i(p*l)),v=i(S*u),h=i(S*v*p),w=i((s+s)*v);ft(w,o)&&(w=i(-w));let T=i(c*h),B=i(w*T);if(!m||ft(B,o)||T===Yd)throw new Error("invalid ristretto255 encoding 2");return new t(new At(w,T,lt,B))}static fromHex(e){return t.fromBytes(kr(e))}toBytes(){let{X:e,Y:r,Z:n,T:o}=this.ep,i=hr,s=h=>vt.create(h),a=s(s(n+r)*s(n-r)),c=s(e*r),u=s(c*c),{value:f}=vc(s(a*u)),l=s(f*a),p=s(f*c),m=s(l*p*o),S;if(ft(o*m,i)){let h=s(r*Qi),w=s(e*Qi);e=h,r=w,S=s(l*eh)}else S=p;ft(e*m,i)&&(r=s(-r));let v=s((n-r)*S);return ft(v,i)&&(v=s(-v)),vt.toBytes(v)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:o,Y:i}=e.ep,s=u=>vt.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(Tt.BASE);Object.freeze(Tt.ZERO);Object.freeze(Tt.prototype);Object.freeze(Tt);var oh=Object.freeze({Point:Tt,hashToCurve(t,e){let r=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=Wi(t,r,64,qn);return oh.deriveToCurve(n)},hashToScalar(t,e={DST:Ec}){let r=Wi(t,e.DST,64,qn);return Tc.create(Ge(r))},deriveToCurve(t){Te(t,64);let e=es(t.subarray(0,32)),r=Ac(e),n=es(t.subarray(32,64)),o=Ac(n);return new Tt(r.add(o))}});var Zr=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},Gr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Jn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Ic={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Jn("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 Ee=Ic;var Qn=32,Xr=64,ns=32;var pr,Bc=(async()=>{try{return await Ee.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function _c(){let t=Yr.utils.randomSecretKey(),e=Yr.getPublicKey(t);return{privateKey:uh(t,e),publicKey:e}}async function ih(t,e){let r;t.length===Xr?r=t.subarray(0,32):r=t;let n={crv:"Ed25519",kty:"OKP",x:Z(t.subarray(32),"base64url"),d:Z(r,"base64url"),ext:!0,key_ops:["sign"]},o=await Ee.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),i=await Ee.get().subtle.sign({name:"Ed25519"},o,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(i,0,i.byteLength)}function sh(t,e){let r=t.subarray(0,ns);return Yr.sign(e instanceof Uint8Array?e:e.subarray(),r)}async function Cc(t,e){return pr==null&&(pr=await Bc),pr?ih(t,e):sh(t,e)}async function ah(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Ee.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Ee.get().subtle.verify({name:"Ed25519"},n,e,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function ch(t,e,r){return Yr.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function Rc(t,e,r){return pr==null&&(pr=await Bc),pr?ah(t,e,r):ch(t,e,r)}function uh(t,e){let r=new Uint8Array(Xr);for(let n=0;n<ns;n++)r[n]=t[n],r[ns+n]=e[n];return r}function mr(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Wr=class{type="Ed25519";raw;constructor(e){this.raw=to(e,Qn)}toMultihash(){return Nt.digest(gt(this))}toCID(){return ie.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ne(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=Rc(this.raw,r,e);return mr(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}},eo=class{type="Ed25519";raw;publicKey;constructor(e,r){this.raw=to(e,Xr),this.publicKey=new Wr(r)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ne(this.raw,e.raw)}sign(e,r){r?.signal?.throwIfAborted();let n=Cc(this.raw,e);return mr(n)?n.then(o=>(r?.signal?.throwIfAborted(),o)):(r?.signal?.throwIfAborted(),n)}};function os(t){return t=to(t,Qn),new Wr(t)}async function Lc(){let{privateKey:t,publicKey:e}=_c();return new eo(t,e)}function to(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new Q(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var fh=Math.pow(2,7),lh=Math.pow(2,14),dh=Math.pow(2,21),Uc=Math.pow(2,28),Fc=Math.pow(2,35),Nc=Math.pow(2,42),kc=Math.pow(2,49),be=128,It=127;function Jr(t){if(t<fh)return 1;if(t<lh)return 2;if(t<dh)return 3;if(t<Uc)return 4;if(t<Fc)return 5;if(t<Nc)return 6;if(t<kc)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Oc(t,e,r=0){switch(Jr(t)){case 8:e[r++]=t&255|be,t/=128;case 7:e[r++]=t&255|be,t/=128;case 6:e[r++]=t&255|be,t/=128;case 5:e[r++]=t&255|be,t/=128;case 4:e[r++]=t&255|be,t>>>=7;case 3:e[r++]=t&255|be,t>>>=7;case 2:e[r++]=t&255|be,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Pc(t,e){let r=t[e],n=0;if(n+=r&It,r<be||(r=t[e+1],n+=(r&It)<<7,r<be)||(r=t[e+2],n+=(r&It)<<14,r<be)||(r=t[e+3],n+=(r&It)<<21,r<be)||(r=t[e+4],n+=(r&It)*Uc,r<be)||(r=t[e+5],n+=(r&It)*Fc,r<be)||(r=t[e+6],n+=(r&It)*Nc,r<be)||(r=t[e+7],n+=(r&It)*kc,r<be))return n;throw new RangeError("Could not decode varint")}var is=new Float32Array([-0]),Bt=new Uint8Array(is.buffer);function Kc(t,e,r){is[0]=t,e[r]=Bt[0],e[r+1]=Bt[1],e[r+2]=Bt[2],e[r+3]=Bt[3]}function Mc(t,e){return Bt[0]=t[e],Bt[1]=t[e+1],Bt[2]=t[e+2],Bt[3]=t[e+3],is[0]}var ss=new Float64Array([-0]),me=new Uint8Array(ss.buffer);function Vc(t,e,r){ss[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 qc(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],ss[0]}var hh=BigInt(Number.MAX_SAFE_INTEGER),ph=BigInt(Number.MIN_SAFE_INTEGER),Ie=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 Ht;if(e<hh&&e>ph)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>$c&&(o=0n,++n>$c&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Ht;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):Ht}},Ht=new Ie(0,0);Ht.toBigInt=function(){return 0n};Ht.zzEncode=Ht.zzDecode=function(){return this};Ht.length=function(){return 1};var $c=4294967296n;function Hc(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 zc(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 as(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 Ve(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function ro(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var cs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ve(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 Ve(this,4);return ro(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ve(this,4);return ro(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ve(this,4);let e=Mc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ve(this,4);let e=qc(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 Ve(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return zc(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ve(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ve(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 Ie(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 Ve(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 Ve(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 Ve(this,8);let e=ro(this.buf,this.pos+=4),r=ro(this.buf,this.pos+=4);return new Ie(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=Pc(this.buf,this.pos);return this.pos+=Jr(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 Qr(t){return new cs(t instanceof Uint8Array?t:t.subarray())}function Xe(t,e,r){let n=Qr(t);return e.decode(n,void 0,r)}function us(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 zt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function fs(){}var ds=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},mh=us();function yh(t){return globalThis.Buffer!=null?Ae(t):mh(t)}var tn=class{len;head;tail;states;constructor(){this.len=0,this.head=new zt(fs,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new zt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new hs((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(no,10,Ie.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Ie.fromBigInt(e);return this._push(no,r.length(),r)}uint64Number(e){return this._push(Oc,Jr(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=Ie.fromBigInt(e).zzEncode();return this._push(no,r.length(),r)}sint64Number(e){let r=Ie.fromNumber(e).zzEncode();return this._push(no,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(ls,1,e?1:0)}fixed32(e){return this._push(en,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Ie.fromBigInt(e);return this._push(en,4,r.lo)._push(en,4,r.hi)}fixed64Number(e){let r=Ie.fromNumber(e);return this._push(en,4,r.lo)._push(en,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(Kc,4,e)}double(e){return this._push(Vc,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(ls,1,0):this.uint32(r)._push(bh,r,e)}string(e){let r=Hc(e);return r!==0?this.uint32(r)._push(as,r,e):this._push(ls,1,0)}fork(){return this.states=new ds(this),this.head=this.tail=new zt(fs,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 zt(fs,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=yh(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function ls(t,e,r){e[r]=t&255}function gh(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var hs=class extends zt{next;constructor(e,r){super(gh,e,r),this.next=void 0}};function no(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 en(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 bh(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(tn.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(xh,e,t),this},tn.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(wh,e,t),this});function xh(t,e,r){e.set(t,r)}function wh(t,e,r){t.length<40?as(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set($(t),r)}function ps(){return new tn}function We(t,e){let r=ps();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Je(t,e,r){let n=Qr(t);yield*e.stream(n,void 0,"$",r)}var oo={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function io(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function rn(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 io("enum",oo.VARINT,r,n,o)}function Qe(t,e,r){return io("message",oo.LENGTH_DELIMITED,t,e,r)}var J;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(J||(J={}));var ms;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(ms||(ms={}));(function(t){t.codec=()=>rn(ms)})(J||(J={}));var et;(function(t){let e;t.codec=()=>(e==null&&(e=Qe((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),J.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=J.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:J.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 We(i,t.codec())}t.encode=r;function n(i,s){return Xe(i,t.codec(),s)}t.decode=n;function o(i,s){return Je(i,t.codec(),s)}t.stream=o})(et||(et={}));var ys;(function(t){let e;t.codec=()=>(e==null&&(e=Qe((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),J.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=J.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:J.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 We(i,t.codec())}t.encode=r;function n(i,s){return Xe(i,t.codec(),s)}t.decode=n;function o(i,s){return Je(i,t.codec(),s)}t.stream=o})(ys||(ys={}));var on={};we(on,{MAX_RSA_KEY_SIZE:()=>gs,generateRSAKeyPair:()=>Is,jwkToJWKKeyPair:()=>Wc,jwkToPkcs1:()=>Ah,jwkToPkix:()=>Es,jwkToRSAPrivateKey:()=>Ts,pkcs1MessageToJwk:()=>xs,pkcs1MessageToRSAPrivateKey:()=>Ss,pkcs1ToJwk:()=>vh,pkcs1ToRSAPrivateKey:()=>Xc,pkixMessageToJwk:()=>ws,pkixMessageToRSAPublicKey:()=>As,pkixToJwk:()=>Th,pkixToRSAPublicKey:()=>vs});var yr=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=on.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ie.createV1(114,this._multihash)}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ne(this.raw,e.raw)}verify(e,r,n){return Gc(this.jwk,r,e,n)}},nn=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=on.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ne(this.raw,e.raw)}sign(e,r){return Zc(this.jwk,e,r)}};var gs=8192,bs=18,Eh=1062,Sh=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function vh(t){let e=st(t);return xs(e)}function xs(t){return{n:Z(t[1],"base64url"),e:Z(t[2],"base64url"),d:Z(t[3],"base64url"),p:Z(t[4],"base64url"),q:Z(t[5],"base64url"),dp:Z(t[6],"base64url"),dq:Z(t[7],"base64url"),qi:Z(t[8],"base64url"),kty:"RSA"}}function Ah(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new Q("JWK was missing components");return ke([ge(Uint8Array.from([0])),ge($(t.n,"base64url")),ge($(t.e,"base64url")),ge($(t.d,"base64url")),ge($(t.p,"base64url")),ge($(t.q,"base64url")),ge($(t.dp,"base64url")),ge($(t.dq,"base64url")),ge($(t.qi,"base64url"))]).subarray()}function Th(t){let e=st(t,{offset:0});return ws(e)}function ws(t){let e=st(t[1],{offset:0});return{kty:"RSA",n:Z(e[0],"base64url"),e:Z(e[1],"base64url")}}function Es(t){if(t.n==null||t.e==null)throw new Q("JWK was missing components");return ke([Sh,Nr(ke([ge($(t.n,"base64url")),ge($(t.e,"base64url"))]))]).subarray()}function Xc(t){let e=st(t);return Ss(e)}function Ss(t){let e=xs(t);return Ts(e)}function vs(t,e){if(t.byteLength>=Eh)throw new Wt("Key size is too large");let r=st(t,{offset:0});return As(r,t,e)}function As(t,e,r){let n=ws(t);if(r==null){let o=ir(et.encode({Type:J.RSA,Data:e}));r=Ye(bs,o)}return new yr(n,r)}function Ts(t){if(Qc(t)>gs)throw new Q("Key size is too large");let e=Wc(t),r=ir(et.encode({Type:J.RSA,Data:Es(e.publicKey)})),n=Ye(bs,r);return new nn(e.privateKey,new yr(e.publicKey,n))}async function Is(t){if(t>gs)throw new Q("Key size is too large");let e=await Jc(t),r=ir(et.encode({Type:J.RSA,Data:Es(e.publicKey)})),n=Ye(bs,r);return new nn(e.privateKey,new yr(e.publicKey,n))}function Wc(t){if(t==null)throw new Q("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function Jc(t,e){let r=await Ee.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await Ih(r,e);return{privateKey:n[0],publicKey:n[1]}}async function Zc(t,e,r){let n=await Ee.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Ee.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,e instanceof Uint8Array?e:e.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Gc(t,e,r,n){let o=await Ee.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Ee.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),i}async function Ih(t,e){if(t.privateKey==null||t.publicKey==null)throw new Q("Private and public key are required");let r=await Promise.all([Ee.get().subtle.exportKey("jwk",t.privateKey),Ee.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Qc(t){if(t.kty!=="RSA")throw new Q("invalid key type");if(t.n==null)throw new Q("invalid key modulus");return $(t.n,"base64url").length*8}var so=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(On(e),Te(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),ct(o)}update(e){return or(this),this.iHash.update(e),this}digestInto(e){or(this),Pn(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()}},eu=(()=>{let t=((e,r,n)=>new so(e,r).update(n).digest());return t.create=(e,r)=>new so(e,r),t})();var tu=(t,e)=>(t+(t>=0?e:-e)/ru)/e;function Bh(t,e,r){cr("scalar",t,tt,r);let[[n,o],[i,s]]=e,a=tu(s*t,r),c=tu(-o*t,r),u=t-a*n-c*i,f=-a*o-c*s,l=u<tt,p=f<tt;l&&(u=-u),p&&(f=-f);let m=$r(Math.ceil(ur(r)/2))+_t;if(u<tt||u>=m||f<tt||f>=m)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:p,k2:f}}function _s(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Bs(t,e){Me(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Pe(r.lowS,"lowS"),Pe(r.prehash,"prehash"),r.format!==void 0&&_s(r.format),r}var Cs=class extends Error{constructor(e=""){super(e)}},qe={Err:Cs,_tlv:{encode:(t,e)=>{let{Err:r}=qe;if(Ke(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=Vr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?Vr(o.length/2|128):"";return Vr(t)+i+o+e},decode(t,e){let{Err:r}=qe;e=z(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}=qe;if(zn(t),t<tt)throw new e("integer: negative integers are not allowed");let r=Vr(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}=qe;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 Mt(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=qe,o=z(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}=qe,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(qe._tlv);Object.freeze(qe._int);Object.freeze(qe);var tt=BigInt(0),_t=BigInt(1),ru=BigInt(2),ao=BigInt(3),_h=BigInt(4);function nu(t,e={}){let r=Gn("weierstrass",t,e),n=r.Fp,o=r.Fn,i=r.CURVE,{h:s,n:a}=i;Me(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=iu(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function p(L,d,g){if(u&&d.is0())return Uint8Array.of(0);let{x:A,y:b}=d.toAffine(),x=n.toBytes(A);if(Pe(g,"isCompressed"),g){l();let I=!n.isOdd(b);return ae(ou(I),x)}else return ae(Uint8Array.of(4),x,n.toBytes(b))}function m(L){z(L,void 0,"Point");let{publicKey:d,publicKeyUncompressed:g}=f,A=L.length,b=L[0],x=L.subarray(1);if(u&&A===1&&b===0)return{x:n.ZERO,y:n.ZERO};if(A===d&&(b===2||b===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),D;try{D=n.sqrt(R)}catch(H){let Y=H instanceof Error?": "+H.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}l();let P=n.isOdd(D);return(b&1)===1!==P&&(D=n.neg(D)),{x:I,y:D}}else if(A===g&&b===4){let I=n.BYTES,R=n.fromBytes(x.subarray(0,I)),D=n.fromBytes(x.subarray(I,I*2));if(!w(R,D))throw new Error("bad point: is not on curve");return{x:R,y:D}}else throw new Error(`bad point: got length ${A}, expected compressed=${d} or uncompressed=${g}`)}let S=e.toBytes===void 0?p:e.toBytes,v=e.fromBytes===void 0?m:e.fromBytes;function h(L){let d=n.sqr(L),g=n.mul(d,L);return n.add(n.add(g,n.mul(L,i.a)),i.b)}function w(L,d){let g=n.sqr(d),A=h(L);return n.eql(g,A)}if(!w(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let T=n.mul(n.pow(i.a,ao),_h),B=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(T,B)))throw new Error("bad curve params: a or b");function O(L,d,g=!1){if(!n.isValid(d)||g&&n.is0(d))throw new Error(`bad point coordinate ${L}`);return d}function F(L){if(!(L instanceof E))throw new Error("Weierstrass Point expected")}function V(L){if(!c||!c.basises)throw new Error("no endo");return Bh(L,c.basises,o.ORDER)}function N(L,d,g,A,b){return g=new E(n.mul(g.X,L),g.Y,g.Z),d=zr(A,d),g=zr(b,g),d.add(g)}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,g,A){this.X=O("x",d),this.Y=O("y",g,!0),this.Z=O("z",A),Object.freeze(this)}static CURVE(){return i}static fromAffine(d){let{x:g,y:A}=d||{};if(!d||!n.isValid(g)||!n.isValid(A))throw new Error("invalid affine point");if(d instanceof E)throw new Error("projective point not allowed");return n.is0(g)&&n.is0(A)?E.ZERO:new E(g,A,n.ONE)}static fromBytes(d){let g=E.fromAffine(v(z(d,void 0,"point")));return g.assertValidity(),g}static fromHex(d){return E.fromBytes(ar(d))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=8,g=!0){return k.createCache(this,d),g||this.multiply(ao),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:g,y:A}=d.toAffine();if(!n.isValid(g)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!w(g,A))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){F(d);let{X:g,Y:A,Z:b}=this,{X:x,Y:I,Z:R}=d,D=n.eql(n.mul(g,R),n.mul(x,b)),P=n.eql(n.mul(A,R),n.mul(I,b));return D&&P}negate(){return new E(this.X,n.neg(this.Y),this.Z)}double(){let{a:d,b:g}=i,A=n.mul(g,ao),{X:b,Y:x,Z:I}=this,R=n.ZERO,D=n.ZERO,P=n.ZERO,M=n.mul(b,b),H=n.mul(x,x),Y=n.mul(I,I),q=n.mul(b,x);return q=n.add(q,q),P=n.mul(b,I),P=n.add(P,P),R=n.mul(d,P),D=n.mul(A,Y),D=n.add(R,D),R=n.sub(H,D),D=n.add(H,D),D=n.mul(R,D),R=n.mul(q,R),P=n.mul(A,P),Y=n.mul(d,Y),q=n.sub(M,Y),q=n.mul(d,q),q=n.add(q,P),P=n.add(M,M),M=n.add(P,M),M=n.add(M,Y),M=n.mul(M,q),D=n.add(D,M),Y=n.mul(x,I),Y=n.add(Y,Y),M=n.mul(Y,q),R=n.sub(R,M),P=n.mul(Y,H),P=n.add(P,P),P=n.add(P,P),new E(R,D,P)}add(d){F(d);let{X:g,Y:A,Z:b}=this,{X:x,Y:I,Z:R}=d,D=n.ZERO,P=n.ZERO,M=n.ZERO,H=i.a,Y=n.mul(i.b,ao),q=n.mul(g,x),se=n.mul(A,I),ce=n.mul(b,R),ue=n.add(g,A),re=n.add(x,I);ue=n.mul(ue,re),re=n.add(q,se),ue=n.sub(ue,re),re=n.add(g,b);let xe=n.add(x,R);return re=n.mul(re,xe),xe=n.add(q,ce),re=n.sub(re,xe),xe=n.add(A,b),D=n.add(I,R),xe=n.mul(xe,D),D=n.add(se,ce),xe=n.sub(xe,D),M=n.mul(H,re),D=n.mul(Y,ce),M=n.add(D,M),D=n.sub(se,M),M=n.add(se,M),P=n.mul(D,M),se=n.add(q,q),se=n.add(se,q),ce=n.mul(H,ce),re=n.mul(Y,re),se=n.add(se,ce),ce=n.sub(q,ce),ce=n.mul(H,ce),re=n.add(re,ce),q=n.mul(se,re),P=n.add(P,q),q=n.mul(xe,re),D=n.mul(ue,D),D=n.sub(D,q),q=n.mul(ue,se),M=n.mul(xe,M),M=n.add(M,q),new E(D,P,M)}subtract(d){return F(d),this.add(d.negate())}is0(){return this.equals(E.ZERO)}multiply(d){let{endo:g}=e;if(!o.isValidNot0(d))throw new RangeError("invalid scalar: out of range");let A,b,x=I=>k.cached(this,I,R=>$t(E,R));if(g){let{k1neg:I,k1:R,k2neg:D,k2:P}=V(d),{p:M,f:H}=x(R),{p:Y,f:q}=x(P);b=H.add(q),A=N(g.beta,M,Y,I,D)}else{let{p:I,f:R}=x(d);A=I,b=R}return $t(E,[A,b])[0]}multiplyUnsafe(d){let{endo:g}=e,A=this,b=d;if(!o.isValid(b))throw new RangeError("invalid scalar: out of range");if(b===tt||A.is0())return E.ZERO;if(b===_t)return A;if(k.hasCache(this))return this.multiply(b);if(g){let{k1neg:x,k1:I,k2neg:R,k2:D}=V(b),{p1:P,p2:M}=bc(E,A,I,D);return N(g.beta,P,M,x,R)}else return k.unsafe(A,b)}toAffine(d){let g=this,A=d,{X:b,Y:x,Z:I}=g;if(n.eql(I,n.ONE))return{x:b,y:x};let R=g.is0();A==null&&(A=R?n.ONE:n.inv(I));let D=n.mul(b,A),P=n.mul(x,A),M=n.mul(I,A);if(R)return{x:n.ZERO,y:n.ZERO};if(!n.eql(M,n.ONE))throw new Error("invZ was invalid");return{x:D,y:P}}isTorsionFree(){let{isTorsionFree:d}=e;return s===_t?!0:d?d(E,this):k.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:d}=e;return s===_t?this:d?d(E,this):this.multiplyUnsafe(s)}isSmallOrder(){return s===_t?this.is0():this.clearCofactor().is0()}toBytes(d=!0){return Pe(d,"isCompressed"),this.assertValidity(),S(E,this,d)}toHex(d=!0){return sr(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let _=o.BITS,k=new dr(E,e.endo?Math.ceil(_/2):_);return _>=8&&E.BASE.precompute(8),Object.freeze(E.prototype),Object.freeze(E),E}function ou(t){return Uint8Array.of(t?2:3)}function iu(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Ch(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?Mr:e.randomBytes,o=Object.assign(iu(t.Fp,r),{seed:Math.max(zi(r.ORDER),16)});function i(m){try{let S=r.fromBytes(m);return r.isValidNot0(S)}catch{return!1}}function s(m,S){let{publicKey:v,publicKeyUncompressed:h}=o;try{let w=m.length;return S===!0&&w!==v||S===!1&&w!==h?!1:!!t.fromBytes(m)}catch{return!1}}function a(m){return m=m===void 0?n(o.seed):m,ji(z(m,o.seed,"seed"),r.ORDER)}function c(m,S=!0){return t.BASE.multiply(r.fromBytes(m)).toBytes(S)}function u(m){let{secretKey:S,publicKey:v,publicKeyUncompressed:h}=o,w=r._lengths;if(!Kt(m))return;let T=z(m,void 0,"key").length,B=T===v||T===h,O=T===S||!!w?.includes(T);if(!(B&&O))return B}function f(m,S,v=!0){if(u(m)===!0)throw new Error("first arg must be private key");if(u(S)===!1)throw new Error("second arg must be public key");let h=r.fromBytes(m);return t.fromBytes(S).multiply(h).toBytes(v)}let l={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},p=Xn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:p,Point:t,utils:l,lengths:o})}function su(t,e,r={}){let n=e;On(n),Me(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?Mr:r.randomBytes,i=r.hmac===void 0?(b,x)=>eu(n,b,x):r.hmac,{Fp:s,Fn:a}=t,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:p,utils:m,lengths:S}=Ch(t,r),v={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},h=c*ru+_t<s.ORDER;function w(b){let x=c>>_t;return b>x}function T(b,x){if(!a.isValidNot0(x))throw new Error(`invalid signature ${b}: out of range 1..Point.Fn.ORDER`);return x}function B(){if(h)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function O(b,x){_s(x);let I=S.signature,R=x==="compact"?I:x==="recovered"?I+1:void 0;return z(b,R)}class F{r;s;recovery;constructor(x,I,R){if(this.r=T("r",x),this.s=T("s",I),R!=null){if(B(),![0,1,2,3].includes(R))throw new Error("invalid recovery id");this.recovery=R}Object.freeze(this)}static fromBytes(x,I=v.format){O(x,I);let R;if(I==="der"){let{r:H,s:Y}=qe.toSig(z(x));return new F(H,Y)}I==="recovered"&&(R=x[0],I="compact",x=x.subarray(1));let D=S.signature/2,P=x.subarray(0,D),M=x.subarray(D,D*2);return new F(a.fromBytes(P),a.fromBytes(M),R)}static fromHex(x,I){return this.fromBytes(ar(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 F(this.r,this.s,x)}recoverPublicKey(x){let{r:I,s:R}=this,D=this.assertRecovery(),P=D===2||D===3?I+c:I;if(!s.isValid(P))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let M=s.toBytes(P),H=t.fromBytes(ae(ou((D&1)===0),M)),Y=a.inv(P),q=N(z(x,void 0,"msgHash")),se=a.create(-q*Y),ce=a.create(R*Y),ue=t.BASE.multiplyUnsafe(se).add(H.multiplyUnsafe(ce));if(ue.is0())throw new Error("invalid recovery: point at infinify");return ue.assertValidity(),ue}hasHighS(){return w(this.s)}toBytes(x=v.format){if(_s(x),x==="der")return ar(qe.hexFromSig(this));let{r:I,s:R}=this,D=a.toBytes(I),P=a.toBytes(R);return x==="recovered"?(B(),ae(Uint8Array.of(this.assertRecovery()),D,P)):ae(D,P)}toHex(x){return sr(this.toBytes(x))}}Object.freeze(F.prototype),Object.freeze(F);let V=r.bits2int===void 0?function(x){if(x.length>8192)throw new Error("input is too large");let I=Mt(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(V(x))}:r.bits2int_modN,E=$r(u);function _(b){return cr("num < 2^"+u,b,tt,E),a.toBytes(b)}function k(b,x){return z(b,void 0,"message"),x?z(n(b),void 0,"prehashed message"):b}function L(b,x,I){let{lowS:R,prehash:D,extraEntropy:P}=Bs(I,v);b=k(b,D);let M=N(b),H=a.fromBytes(x);if(!a.isValidNot0(H))throw new Error("invalid private key");let Y=[_(H),_(M)];if(P!=null&&P!==!1){let ue=P===!0?o(S.secretKey):P;Y.push(z(ue,void 0,"extraEntropy"))}let q=ae(...Y),se=M;function ce(ue){let re=V(ue);if(!a.isValidNot0(re))return;let xe=a.inv(re),Xt=t.BASE.multiply(re).toAffine(),_r=a.create(Xt.x);if(_r===tt)return;let In=a.create(xe*a.create(se+_r*H));if(In===tt)return;let ra=(Xt.x===_r?0:2)|Number(Xt.y&_t),na=In;return R&&w(In)&&(na=a.neg(In),ra^=1),new F(_r,na,h?void 0:ra)}return{seed:q,k2sig:ce}}function d(b,x,I={}){let{seed:R,k2sig:D}=L(b,x,I);return tc(n.outputLen,a.BYTES,i)(R,D).toBytes(I.format)}function g(b,x,I,R={}){let{lowS:D,prehash:P,format:M}=Bs(R,v);if(I=z(I,void 0,"publicKey"),x=k(x,P),!Kt(b)){let H=b instanceof F?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+H)}O(b,M);try{let H=F.fromBytes(b,M),Y=t.fromBytes(I);if(D&&H.hasHighS())return!1;let{r:q,s:se}=H,ce=N(x),ue=a.inv(se),re=a.create(ce*ue),xe=a.create(q*ue),Xt=t.BASE.multiplyUnsafe(re).add(Y.multiplyUnsafe(xe));return Xt.is0()?!1:a.create(Xt.x)===q}catch{return!1}}function A(b,x,I={}){let{prehash:R}=Bs(I,v);return x=k(x,R),F.fromBytes(b,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:p,utils:m,lengths:S,Point:t,sign:d,verify:g,recoverPublicKey:A,Signature:F,hash:n})}var Ds={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Rh={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var au=BigInt(2);function Dh(t){let e=Ds.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,p=W(l,r,e)*f%e,m=W(p,au,e)*u%e,S=W(m,o,e)*m%e,v=W(S,i,e)*S%e,h=W(v,a,e)*v%e,w=W(h,c,e)*h%e,T=W(w,a,e)*v%e,B=W(T,r,e)*f%e,O=W(B,s,e)*S%e,F=W(O,n,e)*u%e,V=W(F,au,e);if(!Rs.eql(Rs.sqr(V),t))throw new Error("Cannot find square root");return V}var Rs=fr(Ds.p,{sqrt:Dh}),Lh=nu(Ds,{Fp:Rs,endo:Rh}),$e=su(Lh,ir);function cu(t,e,r){let n=Un.digest(e instanceof Uint8Array?e:e.subarray());if(mr(n))return n.then(({digest:o})=>(r?.signal?.throwIfAborted(),$e.sign(o,t,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new Zr(String(o))});try{return $e.sign(n.digest,t,{prehash:!1,format:"der"})}catch(o){throw new Zr(String(o))}}function uu(t,e,r,n){let o=Un.digest(r instanceof Uint8Array?r:r.subarray());if(mr(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),$e.verify(e,i,t,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new Gr(String(i))});try{return n?.signal?.throwIfAborted(),$e.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(i){throw new Gr(String(i))}}var sn=class{type="secp256k1";raw;_key;constructor(e){this._key=du(e),this.raw=fu(this._key)}toMultihash(){return Nt.digest(gt(this))}toCID(){return ie.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ne(this.raw,e.raw)}verify(e,r,n){return uu(this._key,r,e,n)}},co=class{type="secp256k1";raw;publicKey;constructor(e,r){this.raw=lu(e),this.publicKey=new sn(r??hu(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ne(this.raw,e.raw)}sign(e,r){return cu(this.raw,e,r)}};function Ls(t){return new sn(t)}async function pu(){let t=Uh();return new co(t)}function fu(t){return $e.Point.fromBytes(t).toBytes()}function lu(t){try{return $e.getPublicKey(t,!0),t}catch(e){throw new Cr(String(e))}}function du(t){try{return $e.Point.fromBytes(t),t}catch(e){throw new Wt(String(e))}}function hu(t){try{return $e.getPublicKey(t,!0)}catch(e){throw new Cr(String(e))}}function Uh(){return $e.utils.randomSecretKey()}async function mu(t,e){if(t==="Ed25519")return Lc();if(t==="secp256k1")return pu();if(t==="RSA")return Is(Fh(e));if(t==="ECDSA")return Pa(Nh(e));throw new Jt}function yu(t,e){let{Type:r,Data:n}=et.decode(t),o=n??new Uint8Array;switch(r){case J.RSA:return vs(o,e);case J.Ed25519:return os(o);case J.secp256k1:return Ls(o);case J.ECDSA:return _i(o);default:throw new Jt}}function gu(t){let{Type:e,Data:r}=et.decode(t.digest),n=r??new Uint8Array;switch(e){case J.Ed25519:return os(n);case J.secp256k1:return Ls(n);case J.ECDSA:return _i(n);default:throw new Jt}}function gt(t){return et.encode({Type:J[t.type],Data:t.raw})}function Fh(t){return t==null?2048:parseInt(t,10)}function Nh(t){if(t==="P-256"||t==null)return"P-256";if(t==="P-384")return"P-384";if(t==="P-521")return"P-521";throw new Q("Unsupported curve, should be P-256, P-384 or P-521")}function kh(t,e){if(typeof t=="string")return Oh(t);if(typeof t=="number")return Mh(t,e);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}var uo=kh;function Oh(t){if(typeof t!="string"||t.length===0||t.length>100)throw Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(t)}`);let e=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(t);if(!e?.groups)return NaN;let{value:r,unit:n="ms"}=e.groups,o=parseFloat(r),i=n.toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw Error(`Unknown unit "${i}" provided to ms.parse(). value=${JSON.stringify(t)}`)}}function Ph(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 Kh(t){let e=Math.abs(t);return e>=315576e5?jt(t,e,315576e5,"year"):e>=26298e5?jt(t,e,26298e5,"month"):e>=6048e5?jt(t,e,6048e5,"week"):e>=864e5?jt(t,e,864e5,"day"):e>=36e5?jt(t,e,36e5,"hour"):e>=6e4?jt(t,e,6e4,"minute"):e>=1e3?jt(t,e,1e3,"second"):`${t} ms`}function Mh(t,e){if(typeof t!="number"||!Number.isFinite(t))throw Error("Value provided to ms.format() must be of type number.");return e?.long?Kh(t):Ph(t)}function jt(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function Us(t){r.debug=r,r.default=r,r.coerce=c,r.disable=i,r.enable=o,r.enabled=s,r.humanize=uo,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 p=0;p<f.length;p++)l=(l<<5)-l+f.charCodeAt(p),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=e;function r(f,l){let p,m=null,S,v;function h(...w){if(!h.enabled)return;let T=h,B=Number(new Date),O=B-(p||B);T.diff=O,T.prev=p,T.curr=B,p=B,w[0]=r.coerce(w[0]),typeof w[0]!="string"&&w.unshift("%O");let F=0;w[0]=w[0].replace(/%([a-zA-Z%])/g,(N,E)=>{if(N==="%%")return"%";F++;let _=r.formatters[E];if(typeof _=="function"){let k=w[F];N=_.call(T,k),w.splice(F,1),F--}return N}),r.formatArgs.call(T,w),l?.onLog!=null&&l.onLog(...w),(T.log||r.log).apply(T,w)}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:(S!==r.namespaces&&(S=r.namespaces,v=r.enabled(f)),v),set:w=>{m=w}}),typeof r.init=="function"&&r.init(h),h}function n(f,l){let p=r(this.namespace+(typeof l>"u"?":":l)+f);return p.log=this.log,p}function o(f){r.save(f),r.namespaces=f,r.names=[],r.skips=[];let l,p=(typeof f=="string"?f:"").split(/[\s,]+/),m=p.length;for(l=0;l<m;l++)p[l]&&(f=p[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,p;for(l=0,p=r.skips.length;l<p;l++)if(r.skips[l].test(f))return!1;for(l=0,p=r.names.length;l<p;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 fo=Yh(),Vh=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function qh(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function $h(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+uo(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 Hh=console.debug??console.log??(()=>{});function zh(t){try{t?fo?.setItem("debug",t):fo?.removeItem("debug")}catch{}}function jh(){let t;try{t=fo?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function Yh(){try{return localStorage}catch{}}function Zh(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var bu=Us({formatArgs:$h,save:zh,load:jh,useColors:qh,setupFormatters:Zh,colors:Vh,storage:fo,log:Hh});var Se=bu;Se.formatters.b=t=>t==null?"undefined":X.baseEncode(t);Se.formatters.t=t=>t==null?"undefined":mt.baseEncode(t);Se.formatters.m=t=>t==null?"undefined":mi.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 xu(t,e=""){let r=wu(t.message),n=wu(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
3
+ `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return v;function v(E,_,k){var L=this;if(!(L instanceof v))return new v(E,_,k);L.time=+E||0,L.nano=+_||0,L.year=+k||0,h(L)}function h(E){var _,k,L,d=E.year,g=E.time,A=E.nano,b=((A<0||a<=A)&&(A-=(k=Math.floor(A/a))*a,g+=k,k=1),d%e);return(g<-i||i<g||b)&&((_=u(g/o))&&(d+=_*e,g-=_*o),(L=w(g)).setUTCFullYear(b+L.getUTCFullYear()),L=(g=+L)+(_=u((d-=b)/e))*o,_&&-i<=L&&L<=i&&(d-=_*e,g=L),k=1),k&&(E.year=d,E.time=g,E.nano=A),E}function w(E){var _=new Date(0);return _.setTime(E),_}function T(d,L){d=+d||0;var k=u((L=(L|0)*s)/n)+u(d/n),L=L%n+d%n,d=u(L/n);return d&&(k+=d,L-=d*n),new v(1e3*L,0,k*e)}function B(E,_,k,L,d,g){return function(b,x){var R=h(this);b=b||new Array(8),F(b,x|=0);var D=Math.floor(R.time/1e3),R=R.year*(r*t/e),I=u(R/s)+u(D/s),R=R%s+D%s,D=Math.floor(R/s);return D&&(I+=D,R-=D*s),A(b,x+d,I),A(b,x+g,R),b};function A(b,x,I){b[x+E]=I>>24&255,b[x+_]=I>>16&255,b[x+k]=I>>8&255,b[x+L]=255&I}}function O(E,_,k,L,d,g){return function(b,x){F(b,x|=0);var I=A(b,x+d);return T(A(b,x+g),I)};function A(b,x){return 16777216*b[x+E]+(b[x+_]<<16|b[x+k]<<8|b[x+L])}}function F(E,_){if(E=E&&E.length,E==null)throw new TypeError("Invalid Buffer");if(E<_+8)throw new RangeError("Out of range")}function V(E){return(9<E?"":"0")+(0|E)}function N(E,_){return(c+(0|E)).substr(-_)}})()});var d0={};we(d0,{ipns:()=>f0,ipnsResolver:()=>l0,ipnsSelector:()=>No,ipnsValidator:()=>xn});var ot=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var Q=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Wt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},Cr=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var _n=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Jt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};function ia(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 il=Symbol.for("@libp2p/peer-id");function Cn(t){return!!t?.[il]}function sl(t){return typeof t?.handleEvent=="function"}function al(t){return(t!==!0&&t!==!1&&t?.once)??!1}var Rn=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=al(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))}sl(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 ii={};we(ii,{base58btc:()=>X,base58flickr:()=>pl});var b0=new Uint8Array(0);function sa(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 it(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function aa(t){return new TextEncoder().encode(t)}function ca(t){return new TextDecoder().decode(t)}function cl(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(S){if(S instanceof Uint8Array||(ArrayBuffer.isView(S)?S=new Uint8Array(S.buffer,S.byteOffset,S.byteLength):Array.isArray(S)&&(S=Uint8Array.from(S))),!(S instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(S.length===0)return"";for(var v=0,h=0,w=0,T=S.length;w!==T&&S[w]===0;)w++,v++;for(var B=(T-w)*f+1>>>0,O=new Uint8Array(B);w!==T;){for(var F=S[w],V=0,N=B-1;(F!==0||V<h)&&N!==-1;N--,V++)F+=256*O[N]>>>0,O[N]=F%a>>>0,F=F/a>>>0;if(F!==0)throw new Error("Non-zero carry");h=V,w++}for(var E=B-h;E!==B&&O[E]===0;)E++;for(var _=c.repeat(v);E<B;++E)_+=t.charAt(O[E]);return _}function p(S){if(typeof S!="string")throw new TypeError("Expected String");if(S.length===0)return new Uint8Array;var v=0;if(S[v]!==" "){for(var h=0,w=0;S[v]===c;)h++,v++;for(var T=(S.length-v)*u+1>>>0,B=new Uint8Array(T);S[v];){var O=r[S.charCodeAt(v)];if(O===255)return;for(var F=0,V=T-1;(O!==0||F<w)&&V!==-1;V--,F++)O+=a*B[V]>>>0,B[V]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");w=F,v++}if(S[v]!==" "){for(var N=T-w;N!==T&&B[N]===0;)N++;for(var E=new Uint8Array(h+(T-N)),_=h;N!==T;)E[_++]=B[N++];return E}}}function m(S){var v=p(S);if(v)return v;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:p,decode:m}}var ul=cl,fl=ul,fa=fl;var ti=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")}},ri=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 la(this,e)}},ni=class{decoders;constructor(e){this.decoders=e}or(e){return la(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 la(t,e){return new ni({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var oi=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 ti(e,r,n),this.decoder=new ri(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Qt({name:t,prefix:e,encode:r,decode:n}){return new oi(t,e,r,n)}function pt({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=fa(r,t);return Qt({prefix:e,name:t,encode:n,decode:i=>it(o(i))})}function ll(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 dl(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 hl(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function ee({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=hl(n);return Qt({prefix:e,name:t,encode(i){return dl(i,n,r)},decode(i){return ll(i,o,r,t)}})}var X=pt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),pl=pt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var si={};we(si,{base32:()=>mt,base32hex:()=>bl,base32hexpad:()=>wl,base32hexpadupper:()=>El,base32hexupper:()=>xl,base32pad:()=>yl,base32padupper:()=>gl,base32upper:()=>ml,base32z:()=>Sl});var mt=ee({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ml=ee({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),yl=ee({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),gl=ee({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),bl=ee({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),xl=ee({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),wl=ee({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),El=ee({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Sl=ee({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ai={};we(ai,{base36:()=>Ne,base36upper:()=>vl});var Ne=pt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),vl=pt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Al=pa,da=128,Tl=127,Il=~Tl,Bl=Math.pow(2,31);function pa(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Bl;)e[r++]=t&255|da,t/=128;for(;t&Il;)e[r++]=t&255|da,t>>>=7;return e[r]=t|0,pa.bytes=r-n+1,e}var _l=ci,Cl=128,ha=127;function ci(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw ci.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&ha)<<o:(s&ha)*Math.pow(2,o),o+=7}while(s>=Cl);return ci.bytes=i-n,r}var Rl=Math.pow(2,7),Dl=Math.pow(2,14),Ll=Math.pow(2,21),Ul=Math.pow(2,28),Fl=Math.pow(2,35),Nl=Math.pow(2,42),kl=Math.pow(2,49),Ol=Math.pow(2,56),Pl=Math.pow(2,63),Kl=function(t){return t<Rl?1:t<Dl?2:t<Ll?3:t<Ul?4:t<Fl?5:t<Nl?6:t<kl?7:t<Ol?8:t<Pl?9:10},Ml={encode:Al,decode:_l,encodingLength:Kl},Vl=Ml,Rr=Vl;function Dr(t,e=0){return[Rr.decode(t,e),Rr.decode.bytes]}function er(t,e,r=0){return Rr.encode(t,e,r),e}function tr(t){return Rr.encodingLength(t)}function Ye(t,e){let r=e.byteLength,n=tr(t),o=n+tr(r),i=new Uint8Array(o+r);return er(t,i,0),er(r,i,n),i.set(e,o),new rr(t,r,e,i)}function nr(t){let e=it(t),[r,n]=Dr(e),[o,i]=Dr(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new rr(r,o,s,e)}function ma(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&sa(t.bytes,r.bytes)}}var rr=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function ya(t,e){let{bytes:r,version:n}=t;return n===0?$l(r,ui(t),e??X.encoder):Hl(r,ui(t),e??mt.encoder)}var ga=new WeakMap;function ui(t){let e=ga.get(t);if(e==null){let r=new Map;return ga.set(t,r),r}return e}var ie=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Lr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==zl)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=Ye(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&&ma(e.multihash,n.multihash)}toString(e){return ya(this,e)}toJSON(){return{"/":ya(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??ba(n,o,i.bytes))}else if(r[jl]===!0){let{version:n,multihash:o,code:i}=r,s=nr(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=ba(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=it(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 rr(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,p]=Dr(e.subarray(r));return r+=p,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]=ql(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 ui(i).set(n,e),i}};function ql(t,e){switch(t[0]){case"Q":{let r=e??X;return[X.prefix,r.decode(`${X.prefix}${t}`)]}case X.prefix:{let r=e??X;return[X.prefix,r.decode(t)]}case mt.prefix:{let r=e??mt;return[mt.prefix,r.decode(t)]}case Ne.prefix:{let r=e??Ne;return[Ne.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function $l(t,e,r){let{prefix:n}=r;if(n!==X.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 Hl(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,zl=18;function ba(t,e,r){let n=tr(t),o=n+tr(e),i=new Uint8Array(o+r.byteLength);return er(t,i,0),er(e,i,n),i.set(r,o),i}var jl=Symbol.for("@ipld/js-cid/CID");var fi={};we(fi,{identity:()=>Nt});var xa=0,Yl="identity",wa=it;function Zl(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 Ye(xa,wa(t))}var Nt={code:xa,name:Yl,encode:wa,digest:Zl};function ne(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}async function Ea(t="P-256"){let e=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:t},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",e.publicKey),privateKey:await crypto.subtle.exportKey("jwk",e.privateKey)}}async function Sa(t,e,r){let n=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["sign"]);r?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,e.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function va(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,e,r.subarray());return n?.signal?.throwIfAborted(),i}function Le(t=0){return new Uint8Array(t)}function Ae(t=0){return new Uint8Array(t)}function yt(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 r}var Ta=Symbol.for("@achingbrain/uint8arraylist");function Aa(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 Ln(t){return!!t?.[Ta]}var ye=class t{bufs;length;[Ta]=!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(Ln(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(Ln(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=Aa(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Aa(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(Ln(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 yt(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:yt(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(!Ln(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 p=u;p>=0;p--){let m=this.get(l+p);if(n[p]!==m){f=Math.max(1,p-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=Le(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=Le(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=Le(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=Le(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=Le(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=Le(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=Le(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=Le(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(!ne(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};var li={};we(li,{base10:()=>Gl});var Gl=pt({prefix:"9",name:"base10",alphabet:"0123456789"});var di={};we(di,{base16:()=>Xl,base16upper:()=>Wl});var Xl=ee({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Wl=ee({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var hi={};we(hi,{base2:()=>Jl});var Jl=ee({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var pi={};we(pi,{base256emoji:()=>nd});var Ia=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}"),Ql=Ia.reduce((t,e,r)=>(t[r]=e,t),[]),ed=Ia.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function td(t){return t.reduce((e,r)=>(e+=Ql[r],e),"")}function rd(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=ed[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var nd=Qt({prefix:"\u{1F680}",name:"base256emoji",encode:td,decode:rd});var yi={};we(yi,{base64:()=>mi,base64pad:()=>od,base64url:()=>id,base64urlpad:()=>sd});var mi=ee({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),od=ee({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),id=ee({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),sd=ee({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var gi={};we(gi,{base8:()=>ad});var ad=ee({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var bi={};we(bi,{identity:()=>cd});var cd=Qt({prefix:"\0",name:"identity",encode:t=>ca(t),decode:t=>aa(t)});var rm=new TextEncoder,nm=new TextDecoder;var Ei={};we(Ei,{sha256:()=>Un,sha512:()=>dd});var ld=20;function wi({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new xi(t,e,r,n,o)}var xi=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??ld,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?Ba(n,this.code,r?.truncate):n.then(o=>Ba(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ba(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 Ye(e,t)}function Ca(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Un=wi({name:"sha2-256",code:18,encode:Ca("SHA-256")}),dd=wi({name:"sha2-512",code:19,encode:Ca("SHA-512")});var Si={...bi,...hi,...gi,...li,...di,...si,...ai,...ii,...yi,...pi},mm={...Ei,...fi};function Da(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Ra=Da("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),vi=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=Ae(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),hd={utf8:Ra,"utf-8":Ra,hex:Si.base16,latin1:vi,ascii:vi,binary:vi,...Si},Fn=hd;function $(t,e="utf8"){let r=Fn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Z(t,e="utf8"){let r=Fn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var pd=parseInt("11111",2),Ai=parseInt("10000000",2),md=parseInt("01111111",2),La={0:Ur,1:Ur,2:yd,3:xd,4:wd,5:bd,6:gd,16:Ur,22:Ur,48:Ur};function st(t,e={offset:0}){let r=t[e.offset]&pd;if(e.offset++,La[r]!=null)return La[r](t,e);throw new Error("No decoder for tag "+r)}function Fr(t,e){let r=0;if((t[e.offset]&Ai)===Ai){let n=t[e.offset]&md,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 Ur(t,e){Fr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=st(t,e);if(n===null)break;r.push(n)}return r}function yd(t,e){let r=Fr(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 gd(t,e){let r=Fr(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 bd(t,e){return e.offset++,null}function xd(t,e){let r=Fr(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 wd(t,e){let r=Fr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function Ed(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new ye;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Nn(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=Ed(t.byteLength);return new ye(Uint8Array.from([e.byteLength|Ai]),e)}function ge(t){let e=new ye,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new ye(Uint8Array.from([2]),Nn(e),e)}function Nr(t){let e=Uint8Array.from([0]),r=new ye(e,t);return new ye(Uint8Array.from([3]),Nn(r),r)}function Ua(t){return new ye(Uint8Array.from([4]),Nn(t),t)}function ke(t,e=48){let r=new ye;for(let n of t)r.append(n);return new ye(Uint8Array.from([e]),Nn(r),r)}var Sd=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),vd=Uint8Array.from([6,5,43,129,4,0,34]),Ad=Uint8Array.from([6,5,43,129,4,0,35]),Td={ext:!0,kty:"EC",crv:"P-256"},Id={ext:!0,kty:"EC",crv:"P-384"},Bd={ext:!0,kty:"EC",crv:"P-521"},Ti=32,Ii=48,Bi=66;function _i(t){let e=st(t);return Fa(e)}function Fa(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===Ti*2+1)return n=Z(e.subarray(r,r+Ti),"base64url"),o=Z(e.subarray(r+Ti),"base64url"),new kt({...Td,key_ops:["verify"],x:n,y:o});if(e.byteLength===Ii*2+1)return n=Z(e.subarray(r,r+Ii),"base64url"),o=Z(e.subarray(r+Ii),"base64url"),new kt({...Id,key_ops:["verify"],x:n,y:o});if(e.byteLength===Bi*2+1)return n=Z(e.subarray(r,r+Bi),"base64url"),o=Z(e.subarray(r+Bi),"base64url"),new kt({...Bd,key_ops:["verify"],x:n,y:o});throw new Q(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Na(t){return ke([ge(Uint8Array.from([1])),Ua($(t.d??"","base64url")),ke([Oa(t.crv)],160),ke([Nr(new ye(Uint8Array.from([4]),$(t.x??"","base64url"),$(t.y??"","base64url")))],161)]).subarray()}function ka(t){return ke([ge(Uint8Array.from([1])),ke([Oa(t.crv)],160),ke([Nr(new ye(Uint8Array.from([4]),$(t.x??"","base64url"),$(t.y??"","base64url")))],161)]).subarray()}function Oa(t){if(t==="P-256")return Sd;if(t==="P-384")return vd;if(t==="P-521")return Ad;throw new Q(`Invalid curve ${t}`)}async function Pa(t="P-256"){let e=await Ea(t);return new kn(e.privateKey)}var kt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=ka(this.jwk)),this._raw}toMultihash(){return Nt.digest(gt(this))}toCID(){return ie.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ne(this.raw,e.raw)}async verify(e,r,n){return va(this.jwk,r,e,n)}},kn=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new kt({crv:e.crv,ext:e.ext,key_ops:["verify"],kty:"EC",x:e.x,y:e.y})}get raw(){return this._raw==null&&(this._raw=Na(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ne(this.raw,e.raw)}async sign(e,r){return Sa(this.jwk,e,r)}};function Ci(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function bt(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 Te(t,e,r=""){let n=Ci(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 On(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(bt(t.outputLen),bt(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function or(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 Pn(t,e){Te(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 ct(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Kn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Oe(t,e){return t<<32-e|t>>>e}var Ma=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",_d=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Mn(t){if(Te(t),Ma)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=_d[t[r]];return e}var at={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ka(t){if(t>=at._0&&t<=at._9)return t-at._0;if(t>=at.A&&t<=at.F)return t-(at.A-10);if(t>=at.a&&t<=at.f)return t-(at.a-10)}function kr(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Ma)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=Ka(t.charCodeAt(i)),a=Ka(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 Ri(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Te(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 Di(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 Va(t=32){bt(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 Li=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function qa(t,e,r){return t&e^~t&r}function $a(t,e,r){return t&e^t&r^e&r}var Or=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=Kn(this.buffer)}update(e){or(this),Te(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=Kn(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){or(this),Pn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,ct(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=Kn(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()}},ut=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var de=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Vn=BigInt(4294967295),Ha=BigInt(32);function Cd(t,e=!1){return e?{h:Number(t&Vn),l:Number(t>>Ha&Vn)}:{h:Number(t>>Ha&Vn)|0,l:Number(t&Vn)|0}}function za(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}=Cd(t[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var Ui=(t,e,r)=>t>>>r,Fi=(t,e,r)=>t<<32-r|e>>>r,Ot=(t,e,r)=>t>>>r|e<<32-r,Pt=(t,e,r)=>t<<32-r|e>>>r,Pr=(t,e,r)=>t<<64-r|e>>>r-32,Kr=(t,e,r)=>t>>>r-32|e<<64-r;function Ze(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var ja=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Ya=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Za=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Ga=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Xa=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Wa=(t,e,r,n,o,i)=>e+r+n+o+i+(t/2**32|0)|0;var Dd=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]),xt=new Uint32Array(64),Ni=class extends Or{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)xt[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let p=xt[l-15],m=xt[l-2],S=Oe(p,7)^Oe(p,18)^p>>>3,v=Oe(m,17)^Oe(m,19)^m>>>10;xt[l]=v+xt[l-7]+S+xt[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 p=Oe(a,6)^Oe(a,11)^Oe(a,25),m=f+p+qa(a,c,u)+Dd[l]+xt[l]|0,v=(Oe(n,2)^Oe(n,13)^Oe(n,22))+$a(n,o,i)|0;f=u,u=c,c=a,a=s+m|0,s=i,i=o,o=n,n=m+v|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,i,s,a,c,u,f)}roundClean(){ct(xt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),ct(this.buffer)}},ki=class extends Ni{A=ut[0]|0;B=ut[1]|0;C=ut[2]|0;D=ut[3]|0;E=ut[4]|0;F=ut[5]|0;G=ut[6]|0;H=ut[7]|0;constructor(){super(32)}};var Ja=za(["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))),Ld=Ja[0],Ud=Ja[1],wt=new Uint32Array(80),Et=new Uint32Array(80),Oi=class extends Or{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:p,Gh:m,Gl:S,Hh:v,Hl:h}=this;return[e,r,n,o,i,s,a,c,u,f,l,p,m,S,v,h]}set(e,r,n,o,i,s,a,c,u,f,l,p,m,S,v,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=p|0,this.Gh=m|0,this.Gl=S|0,this.Hh=v|0,this.Hl=h|0}process(e,r){for(let B=0;B<16;B++,r+=4)wt[B]=e.getUint32(r),Et[B]=e.getUint32(r+=4);for(let B=16;B<80;B++){let O=wt[B-15]|0,F=Et[B-15]|0,V=Ot(O,F,1)^Ot(O,F,8)^Ui(O,F,7),N=Pt(O,F,1)^Pt(O,F,8)^Fi(O,F,7),E=wt[B-2]|0,_=Et[B-2]|0,k=Ot(E,_,19)^Pr(E,_,61)^Ui(E,_,6),L=Pt(E,_,19)^Kr(E,_,61)^Fi(E,_,6),d=Za(N,L,Et[B-7],Et[B-16]),g=Ga(d,V,k,wt[B-7],wt[B-16]);wt[B]=g|0,Et[B]=d|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:p,Fh:m,Fl:S,Gh:v,Gl:h,Hh:w,Hl:T}=this;for(let B=0;B<80;B++){let O=Ot(l,p,14)^Ot(l,p,18)^Pr(l,p,41),F=Pt(l,p,14)^Pt(l,p,18)^Kr(l,p,41),V=l&m^~l&v,N=p&S^~p&h,E=Xa(T,F,N,Ud[B],Et[B]),_=Wa(E,w,O,V,Ld[B],wt[B]),k=E|0,L=Ot(n,o,28)^Pr(n,o,34)^Pr(n,o,39),d=Pt(n,o,28)^Kr(n,o,34)^Kr(n,o,39),g=n&i^n&a^i&a,A=o&s^o&c^s&c;w=v|0,T=h|0,v=m|0,h=S|0,m=l|0,S=p|0,{h:l,l:p}=Ze(u|0,f|0,_|0,k|0),u=a|0,f=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let b=ja(k,d,A);n=Ya(b,_,L,g),o=b|0}({h:n,l:o}=Ze(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Ze(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Ze(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Ze(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:p}=Ze(this.Eh|0,this.El|0,l|0,p|0),{h:m,l:S}=Ze(this.Fh|0,this.Fl|0,m|0,S|0),{h:v,l:h}=Ze(this.Gh|0,this.Gl|0,v|0,h|0),{h:w,l:T}=Ze(this.Hh|0,this.Hl|0,w|0,T|0),this.set(n,o,i,s,a,c,u,f,l,p,m,S,v,h,w,T)}roundClean(){ct(wt,Et)}destroy(){this.destroyed=!0,ct(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Pi=class extends Oi{Ah=de[0]|0;Al=de[1]|0;Bh=de[2]|0;Bl=de[3]|0;Ch=de[4]|0;Cl=de[5]|0;Dh=de[6]|0;Dl=de[7]|0;Eh=de[8]|0;El=de[9]|0;Fh=de[10]|0;Fl=de[11]|0;Gh=de[12]|0;Gl=de[13]|0;Hh=de[14]|0;Hl=de[15]|0;constructor(){super(64)}};var ir=Di(()=>new ki,Li(1));var qn=Di(()=>new Pi,Li(3));var z=(t,e,r)=>Te(t,e,r),Mi=bt,sr=Mn,ae=(...t)=>Ri(...t),ar=t=>kr(t),Kt=Ci,Mr=t=>Va(t),Hn=BigInt(0),Ki=BigInt(1);function Pe(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function zn(t){if(typeof t=="bigint"){if(!$n(t))throw new RangeError("positive bigint expected, got "+t)}else Mi(t);return t}function Ke(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 Vr(t){let e=zn(t).toString(16);return e.length&1?"0"+e:e}function Qa(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Hn:BigInt("0x"+t)}function Mt(t){return Qa(Mn(t))}function Ge(t){return Qa(Mn(qr(Te(t)).reverse()))}function jn(t,e){if(bt(e),e===0)throw new RangeError("zero length");t=zn(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return kr(r.padStart(e*2,"0"))}function Vi(t,e){return jn(t,e).reverse()}function ec(t,e){if(t=z(t),e=z(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 qr(t){return Uint8Array.from(z(t))}function Yn(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 $n=t=>typeof t=="bigint"&&Hn<=t;function Fd(t,e,r){return $n(t)&&$n(e)&&$n(r)&&e<=t&&t<r}function cr(t,e,r,n){if(!Fd(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function ur(t){if(t<Hn)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>Hn;t>>=Ki,e+=1);return e}var $r=t=>(Ki<<BigInt(t))-Ki;function tc(t,e,r){if(bt(t,"hashLen"),bt(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},p=(...h)=>r(u,ae(c,...h)),m=(h=o)=>{u=p(i,h),c=p(),h.length!==0&&(u=p(s,h),c=p())},S=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let h=0,w=[];for(;h<e;){c=p();let T=c.slice();w.push(T),h+=c.length}return ae(...w)};return(h,w)=>{l(),m(h);let T;for(;(T=w(S()))===void 0;)m();return l(),T}}function Me(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 qi=()=>{throw new Error("not implemented")};var he=BigInt(0),te=BigInt(1),Vt=BigInt(2),ic=BigInt(3),sc=BigInt(4),ac=BigInt(5),Nd=BigInt(7),cc=BigInt(8),kd=BigInt(9),uc=BigInt(16);function oe(t,e){if(e<=he)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=he?r:e+r}function W(t,e,r){if(e<he)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >he;)n*=n,n%=r;return n}function rc(t,e){if(t===he)throw new Error("invert: expected non-zero number");if(e<=he)throw new Error("invert: expected positive modulus, got "+e);let r=oe(t,e),n=e,o=he,i=te,s=te,a=he;for(;r!==he;){let u=n/r,f=n-r*u,l=o-s*u,p=i-a*u;n=r,r=f,o=s,i=a,s=l,a=p}if(n!==te)throw new Error("invert: does not exist");return oe(o,e)}function $i(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function fc(t,e){let r=t,n=(r.ORDER+te)/sc,o=r.pow(e,n);return $i(r,o,e),o}function Od(t,e){let r=t,n=(r.ORDER-ac)/cc,o=r.mul(e,Vt),i=r.pow(o,n),s=r.mul(e,i),a=r.mul(r.mul(s,Vt),i),c=r.mul(s,r.sub(a,r.ONE));return $i(r,c,e),c}function Pd(t){let e=fr(t),r=lc(t),n=r(e,e.neg(e.ONE)),o=r(e,n),i=r(e,e.neg(n)),s=(t+Nd)/uc;return((a,c)=>{let u=a,f=u.pow(c,s),l=u.mul(f,n),p=u.mul(f,o),m=u.mul(f,i),S=u.eql(u.sqr(l),c),v=u.eql(u.sqr(p),c);f=u.cmov(f,l,S),l=u.cmov(m,p,v);let h=u.eql(u.sqr(l),c),w=u.cmov(f,l,h);return $i(u,w,c),w})}function lc(t){if(t<ic)throw new Error("sqrt is not defined for small field");let e=t-te,r=0;for(;e%Vt===he;)e/=Vt,r++;let n=Vt,o=fr(t);for(;nc(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return fc;let i=o.pow(n,e),s=(e+te)/Vt;return function(c,u){let f=c;if(f.is0(u))return u;if(nc(f,u)!==1)throw new Error("Cannot find square root");let l=r,p=f.mul(f.ONE,i),m=f.pow(u,e),S=f.pow(u,s);for(;!f.eql(m,f.ONE);){if(f.is0(m))return f.ZERO;let v=1,h=f.sqr(m);for(;!f.eql(h,f.ONE);)if(v++,h=f.sqr(h),v===l)throw new Error("Cannot find square root");let w=te<<BigInt(l-v-1),T=f.pow(p,w);l=v,p=f.sqr(T),m=f.mul(m,p),S=f.mul(S,T)}return S}}function Kd(t){return t%sc===ic?fc:t%cc===ac?Od:t%uc===kd?Pd(t):lc(t)}var ft=(t,e)=>(oe(t,e)&te)===te,Md=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Hi(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Md.reduce((n,o)=>(n[o]="function",n),e);if(Me(t,r),Ke(t.BYTES,"BYTES"),Ke(t.BITS,"BITS"),t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=te)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Vd(t,e,r){let n=t;if(r<he)throw new Error("invalid exponent, negatives unsupported");if(r===he)return n.ONE;if(r===te)return e;let o=n.ONE,i=e;for(;r>he;)r&te&&(o=n.mul(o,i)),i=n.sqr(i),r>>=te;return o}function Hr(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 nc(t,e){let r=t,n=(r.ORDER-te)/Vt,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 qd(t,e){if(e!==void 0&&Mi(e),t<=he)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=ur(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 oc=new WeakMap,Zn=class{ORDER;BITS;BYTES;isLE;ZERO=he;ONE=te;_lengths;_mod;constructor(e,r={}){if(e<=te)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}=qd(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 oe(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return he<=e&&e<this.ORDER}is0(e){return e===he}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&te)===te}neg(e){return oe(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return oe(e*e,this.ORDER)}add(e,r){return oe(e+r,this.ORDER)}sub(e,r){return oe(e-r,this.ORDER)}mul(e,r){return oe(e*r,this.ORDER)}pow(e,r){return Vd(this,e,r)}div(e,r){return oe(e*rc(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 rc(e,this.ORDER)}sqrt(e){let r=oc.get(this);return r||oc.set(this,r=Kd(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Vi(e,this.BYTES):jn(e,this.BYTES)}fromBytes(e,r=!1){z(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?Ge(e):Mt(e);if(a&&(c=oe(c,s)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Hr(this,e)}cmov(e,r,n){return Pe(n,"condition"),n?r:e}};Object.freeze(Zn.prototype);function fr(t,e={}){return new Zn(t,e)}function dc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=te)throw new Error("field order must be greater than 1");let e=ur(t-te);return Math.ceil(e/8)}function zi(t){let e=dc(t);return e+Math.ceil(e/2)}function ji(t,e,r=!1){z(t);let n=t.length,o=dc(e),i=Math.max(zi(e),16);if(n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Ge(t):Mt(t),a=oe(s,e-te)+te;return r?Vi(a,o):jn(a,o)}var lr=BigInt(0),qt=BigInt(1);function zr(t,e){let r=e.negate();return t?r:e}function $t(t,e){let r=Hr(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function yc(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Yi(t,e){yc(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,i=$r(t),s=BigInt(t);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function hc(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,p=a<0,m=e%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:p,isNegF:m,offsetF:u}}var Zi=new WeakMap,gc=new WeakMap;function Gi(t){return gc.get(t)||1}function pc(t){if(t!==lr)throw new Error("invalid wNAF")}var dr=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>lr;)r&qt&&(n=n.add(o)),o=o.double(),r>>=qt;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=Yi(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=Yi(e,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:p,offsetF:m}=hc(n,a,s);n=c,f?i=i.add(zr(p,r[m])):o=o.add(zr(l,r[u]))}return pc(n),{p:o,f:i}}wNAFUnsafe(e,r,n,o=this.ZERO){let i=Yi(e,this.bits);for(let s=0;s<i.windows&&n!==lr;s++){let{nextN:a,offset:c,isZero:u,isNeg:f}=hc(n,s,i);if(n=a,!u){let l=r[c];o=o.add(f?l.negate():l)}}return pc(n),o}getPrecomputes(e,r,n){let o=Zi.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),Zi.set(r,o))),o}cached(e,r,n){let o=Gi(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let i=Gi(e);return i===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),r,o)}createCache(e,r){yc(r,this.bits),gc.set(e,r),Zi.delete(e)}hasCache(e){return Gi(e)!==1}};function bc(t,e,r,n){let o=e,i=t.ZERO,s=t.ZERO;for(;r>lr||n>lr;)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 mc(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Hi(e),e}else return fr(t,{isLE:r})}function Gn(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>lr))throw new Error(`CURVE.${c} must be positive bigint`)}let o=mc(e.p,r.Fp,n),i=mc(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 Xn(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var St=BigInt(0),fe=BigInt(1),Xi=BigInt(2),$d=BigInt(8);function Hd(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 xc(t,e={}){let r=e,n=Gn("edwards",t,r,r.FpFnLE),{Fp:o,Fn:i}=n,s=n.CURVE,{h:a}=s;Me(r,{},{uvRatio:"function"});let c=Xi<<BigInt(i.BYTES*8)-fe,u=v=>o.create(v),f=r.uvRatio===void 0?(v,h)=>{try{return{isValid:!0,value:o.sqrt(o.div(v,h))}}catch{return{isValid:!1,value:St}}}:r.uvRatio;if(!Hd(o,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function l(v,h,w=!1){let T=w?fe:St;return cr("coordinate "+v,h,T,c),h}function p(v){if(!(v instanceof m))throw new Error("EdwardsPoint expected")}class m{static BASE=new m(s.Gx,s.Gy,fe,u(s.Gx*s.Gy));static ZERO=new m(St,fe,fe,St);static Fp=o;static Fn=i;X;Y;Z;T;constructor(h,w,T,B){this.X=l("x",h),this.Y=l("y",w),this.Z=l("z",T,!0),this.T=l("t",B),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){if(h instanceof m)throw new Error("extended point not allowed");let{x:w,y:T}=h||{};return l("x",w),l("y",T),new m(w,T,fe,u(w*T))}static fromBytes(h,w=!1){let T=o.BYTES,{a:B,d:O}=s;h=qr(z(h,T,"point")),Pe(w,"zip215");let F=qr(h),V=h[T-1];F[T-1]=V&-129;let N=Ge(F),E=w?c:o.ORDER;cr("point.y",N,St,E);let _=u(N*N),k=u(_-fe),L=u(O*_-B),{isValid:d,value:g}=f(k,L);if(!d)throw new Error("bad point: invalid y coordinate");let A=(g&fe)===fe,b=(V&128)!==0;if(!w&&g===St&&b)throw new Error("bad point: x=0 and x_0=1");return b!==A&&(g=u(-g)),m.fromAffine({x:g,y:N})}static fromHex(h,w=!1){return m.fromBytes(ar(h),w)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,w=!0){return S.createCache(this,h),w||this.multiply(Xi),this}assertValidity(){let h=this,{a:w,d:T}=s;if(h.is0())throw new Error("bad point: ZERO");let{X:B,Y:O,Z:F,T:V}=h,N=u(B*B),E=u(O*O),_=u(F*F),k=u(_*_),L=u(N*w),d=u(_*u(L+E)),g=u(k+u(T*u(N*E)));if(d!==g)throw new Error("bad point: equation left != right (1)");let A=u(B*O),b=u(F*V);if(A!==b)throw new Error("bad point: equation left != right (2)")}equals(h){p(h);let{X:w,Y:T,Z:B}=this,{X:O,Y:F,Z:V}=h,N=u(w*V),E=u(O*B),_=u(T*V),k=u(F*B);return N===E&&_===k}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:w,Y:T,Z:B}=this,O=u(w*w),F=u(T*T),V=u(Xi*u(B*B)),N=u(h*O),E=w+T,_=u(u(E*E)-O-F),k=N+F,L=k-V,d=N-F,g=u(_*L),A=u(k*d),b=u(_*d),x=u(L*k);return new m(g,A,x,b)}add(h){p(h);let{a:w,d:T}=s,{X:B,Y:O,Z:F,T:V}=this,{X:N,Y:E,Z:_,T:k}=h,L=u(B*N),d=u(O*E),g=u(V*T*k),A=u(F*_),b=u((B+O)*(N+E)-L-d),x=A-g,I=A+g,R=u(d-w*L),D=u(b*x),P=u(I*R),M=u(b*R),H=u(x*I);return new m(D,P,H,M)}subtract(h){return p(h),this.add(h.negate())}multiply(h){if(!i.isValidNot0(h))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:w,f:T}=S.cached(this,h,B=>$t(m,B));return $t(m,[w,T])[0]}multiplyUnsafe(h){if(!i.isValid(h))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return h===St?m.ZERO:this.is0()||h===fe?this:S.unsafe(this,h,w=>$t(m,w))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return S.unsafe(this,s.n).is0()}toAffine(h){let w=this,T=h,{X:B,Y:O,Z:F}=w,V=w.is0();T==null&&(T=V?$d:o.inv(F));let N=u(B*T),E=u(O*T),_=o.mul(F,T);if(V)return{x:St,y:fe};if(_!==fe)throw new Error("invZ was invalid");return{x:N,y:E}}clearCofactor(){return a===fe?this:this.multiplyUnsafe(a)}toBytes(){let{x:h,y:w}=this.toAffine(),T=o.toBytes(w);return T[T.length-1]|=h&fe?128:0,T}toHex(){return sr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let S=new dr(m,i.BITS);return i.BITS>=8&&m.BASE.precompute(8),Object.freeze(m.prototype),Object.freeze(m),m}var Wn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){qi()}static fromHex(e){qi()}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 sr(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 wc(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Me(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&&(Ke(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?Mr:o.randomBytes,p=o.adjustScalarBytes===void 0?d=>d:o.adjustScalarBytes,m=o.domain===void 0?(d,g,A)=>{if(Pe(A,"phflag"),g.length||A)throw new Error("Contexts/pre-hash are not supported");return d}:o.domain;function S(d){return c.create(Ge(d))}function v(d){let g=N.secretKey;z(d,N.secretKey,"secretKey");let A=z(n(d),2*g,"hashedSecretKey"),b=p(A.slice(0,g)),x=A.slice(g,2*g),I=S(b);return{head:b,prefix:x,scalar:I}}function h(d){let{head:g,prefix:A,scalar:b}=v(d),x=s.multiply(b),I=x.toBytes();return{head:g,prefix:A,scalar:b,point:x,pointBytes:I}}function w(d){return h(d).pointBytes}function T(d=Uint8Array.of(),...g){let A=ae(...g);return S(n(m(A,z(d,void 0,"context"),!!i)))}function B(d,g,A={}){d=z(d,void 0,"message"),i&&(d=i(d));let{prefix:b,scalar:x,pointBytes:I}=h(g),R=T(A.context,b,d),D=s.multiply(R).toBytes(),P=T(A.context,D,I,d),M=c.create(R+P*x);if(!c.isValid(M))throw new Error("sign failed: invalid s");let H=ae(D,c.toBytes(M));return z(H,N.signature,"result")}let O={zip215:o.zip215};function F(d,g,A,b=O){let{context:x}=b,I=b.zip215===void 0?!!O.zip215:b.zip215,R=N.signature;d=z(d,R,"signature"),g=z(g,void 0,"message"),A=z(A,N.publicKey,"publicKey"),I!==void 0&&Pe(I,"zip215"),i&&(g=i(g));let D=R/2,P=d.subarray(0,D),M=Ge(d.subarray(D,R)),H,Y,q;try{H=t.fromBytes(A,I),Y=t.fromBytes(P,I),q=s.multiplyUnsafe(M)}catch{return!1}if(!I&&H.isSmallOrder())return!1;let se=T(x,P,A,g);return Y.add(H.multiplyUnsafe(se)).subtract(q).clearCofactor().is0()}let V=a.BYTES,N={secretKey:V,publicKey:V,signature:2*V,seed:V};function E(d){return d=d===void 0?l(N.seed):d,z(d,N.seed,"seed")}function _(d){return Kt(d)&&d.length===N.secretKey}function k(d,g){try{return!!t.fromBytes(d,g===void 0?O.zip215:g)}catch{return!1}}let L={getExtendedPublicKey:h,randomSecretKey:E,isValidSecretKey:_,isValidPublicKey:k,toMontgomery(d){let{y:g}=t.fromBytes(d),A=N.publicKey,b=A===32;if(!b&&A!==57)throw new Error("only defined for 25519 and 448");let x=b?a.div(fe+g,fe-g):a.div(g-fe,g+fe);return a.toBytes(x)},toMontgomerySecret(d){let g=N.secretKey;z(d,g);let A=n(d.subarray(0,g));return p(A).subarray(0,g)}};return Object.freeze(N),Object.freeze(L),Object.freeze({keygen:Xn(E,w),getPublicKey:w,sign:B,verify:F,utils:L,Point:t,lengths:N})}function jr(t,e){if(Ke(t),Ke(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 zd(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 jd(t){if(!Kt(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?Yn(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function Wi(t,e,r,n){z(t),Ke(r),e=jd(e),e.length>255&&(e=n(ae(Yn("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,jr(e.length,1)),c=new Uint8Array(i),u=jr(r,2),f=new Array(s),l=n(ae(c,t,u,jr(0,1),a));f[0]=n(ae(l,jr(1,1),a));for(let m=1;m<s;m++){let S=[zd(l,f[m-1]),jr(m+1,1),a];f[m]=n(ae(...S))}return ae(...f).slice(0,r)}var Ec="HashToScalar-";var Yd=BigInt(0),lt=BigInt(1),Sc=BigInt(2);var Zd=BigInt(5),Gd=BigInt(8),hr=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ts={p:hr,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Gd,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Xd(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=hr,a=t*t%i*t%i,c=W(a,Sc,i)*a%i,u=W(c,lt,i)*t%i,f=W(u,Zd,i)*u%i,l=W(f,e,i)*f%i,p=W(l,r,i)*l%i,m=W(p,n,i)*p%i,S=W(m,o,i)*m%i,v=W(S,o,i)*m%i,h=W(v,e,i)*f%i;return{pow_p_5_8:W(h,Sc,i)*t%i,b2:a}}function Wd(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var Ji=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function rs(t,e){let r=hr,n=oe(e*e*e,r),o=oe(n*n*e,r),i=Xd(t*o).pow_p_5_8,s=oe(t*n*i,r),a=oe(e*s*s,r),c=s,u=oe(s*Ji,r),f=a===t,l=a===oe(-t,r),p=a===oe(-t*Ji,r);return f&&(s=c),(l||p)&&(s=u),ft(s,r)&&(s=oe(-s,r)),{isValid:f||l,value:s}}var At=xc(ts,{uvRatio:rs}),vt=At.Fp,Tc=At.Fn;function Jd(t){return wc(At,qn,Object.assign({adjustScalarBytes:Wd,zip215:!0},t))}var Yr=Jd({});var Qi=Ji,Qd=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),eh=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),th=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),rh=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),vc=t=>rs(lt,t),nh=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),es=t=>vt.create(Ge(t)&nh);function Ac(t){let{d:e}=ts,r=hr,n=w=>vt.create(w),o=n(Qi*t*t),i=n((o+lt)*th),s=BigInt(-1),a=n((s-e*o)*n(o+e)),{isValid:c,value:u}=rs(i,a),f=n(u*t);ft(f,r)||(f=n(-f)),c||(u=f),c||(s=o);let l=n(s*(o-lt)*rh-a),p=u*u,m=n((u+u)*a),S=n(l*Qd),v=n(lt-p),h=n(lt+p);return new At(n(m*h),n(v*S),n(S*h),n(m*v))}var Tt=class t extends Wn{static BASE=new t(At.BASE);static ZERO=new t(At.ZERO);static Fp=vt;static Fn=Tc;constructor(e){super(e)}static fromAffine(e){return new t(At.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static fromBytes(e){Te(e,32);let{a:r,d:n}=ts,o=hr,i=O=>vt.create(O),s=es(e);if(!ec(vt.toBytes(s),e)||ft(s,o))throw new Error("invalid ristretto255 encoding 1");let a=i(s*s),c=i(lt+r*a),u=i(lt-r*a),f=i(c*c),l=i(u*u),p=i(r*n*f-l),{isValid:m,value:S}=vc(i(p*l)),v=i(S*u),h=i(S*v*p),w=i((s+s)*v);ft(w,o)&&(w=i(-w));let T=i(c*h),B=i(w*T);if(!m||ft(B,o)||T===Yd)throw new Error("invalid ristretto255 encoding 2");return new t(new At(w,T,lt,B))}static fromHex(e){return t.fromBytes(kr(e))}toBytes(){let{X:e,Y:r,Z:n,T:o}=this.ep,i=hr,s=h=>vt.create(h),a=s(s(n+r)*s(n-r)),c=s(e*r),u=s(c*c),{value:f}=vc(s(a*u)),l=s(f*a),p=s(f*c),m=s(l*p*o),S;if(ft(o*m,i)){let h=s(r*Qi),w=s(e*Qi);e=h,r=w,S=s(l*eh)}else S=p;ft(e*m,i)&&(r=s(-r));let v=s((n-r)*S);return ft(v,i)&&(v=s(-v)),vt.toBytes(v)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:o,Y:i}=e.ep,s=u=>vt.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(Tt.BASE);Object.freeze(Tt.ZERO);Object.freeze(Tt.prototype);Object.freeze(Tt);var oh=Object.freeze({Point:Tt,hashToCurve(t,e){let r=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=Wi(t,r,64,qn);return oh.deriveToCurve(n)},hashToScalar(t,e={DST:Ec}){let r=Wi(t,e.DST,64,qn);return Tc.create(Ge(r))},deriveToCurve(t){Te(t,64);let e=es(t.subarray(0,32)),r=Ac(e),n=es(t.subarray(32,64)),o=Ac(n);return new Tt(r.add(o))}});var Zr=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},Gr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Jn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Ic={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Jn("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 Ee=Ic;var Qn=32,Xr=64,ns=32;var pr,Bc=(async()=>{try{return await Ee.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function _c(){let t=Yr.utils.randomSecretKey(),e=Yr.getPublicKey(t);return{privateKey:uh(t,e),publicKey:e}}async function ih(t,e){let r;t.length===Xr?r=t.subarray(0,32):r=t;let n={crv:"Ed25519",kty:"OKP",x:Z(t.subarray(32),"base64url"),d:Z(r,"base64url"),ext:!0,key_ops:["sign"]},o=await Ee.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),i=await Ee.get().subtle.sign({name:"Ed25519"},o,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(i,0,i.byteLength)}function sh(t,e){let r=t.subarray(0,ns);return Yr.sign(e instanceof Uint8Array?e:e.subarray(),r)}async function Cc(t,e){return pr==null&&(pr=await Bc),pr?ih(t,e):sh(t,e)}async function ah(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Ee.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Ee.get().subtle.verify({name:"Ed25519"},n,e,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function ch(t,e,r){return Yr.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function Rc(t,e,r){return pr==null&&(pr=await Bc),pr?ah(t,e,r):ch(t,e,r)}function uh(t,e){let r=new Uint8Array(Xr);for(let n=0;n<ns;n++)r[n]=t[n],r[ns+n]=e[n];return r}function mr(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Wr=class{type="Ed25519";raw;constructor(e){this.raw=to(e,Qn)}toMultihash(){return Nt.digest(gt(this))}toCID(){return ie.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ne(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=Rc(this.raw,r,e);return mr(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}},eo=class{type="Ed25519";raw;publicKey;constructor(e,r){this.raw=to(e,Xr),this.publicKey=new Wr(r)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ne(this.raw,e.raw)}sign(e,r){r?.signal?.throwIfAborted();let n=Cc(this.raw,e);return mr(n)?n.then(o=>(r?.signal?.throwIfAborted(),o)):(r?.signal?.throwIfAborted(),n)}};function os(t){return t=to(t,Qn),new Wr(t)}async function Lc(){let{privateKey:t,publicKey:e}=_c();return new eo(t,e)}function to(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new Q(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var fh=Math.pow(2,7),lh=Math.pow(2,14),dh=Math.pow(2,21),Uc=Math.pow(2,28),Fc=Math.pow(2,35),Nc=Math.pow(2,42),kc=Math.pow(2,49),be=128,It=127;function Jr(t){if(t<fh)return 1;if(t<lh)return 2;if(t<dh)return 3;if(t<Uc)return 4;if(t<Fc)return 5;if(t<Nc)return 6;if(t<kc)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Oc(t,e,r=0){switch(Jr(t)){case 8:e[r++]=t&255|be,t/=128;case 7:e[r++]=t&255|be,t/=128;case 6:e[r++]=t&255|be,t/=128;case 5:e[r++]=t&255|be,t/=128;case 4:e[r++]=t&255|be,t>>>=7;case 3:e[r++]=t&255|be,t>>>=7;case 2:e[r++]=t&255|be,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Pc(t,e){let r=t[e],n=0;if(n+=r&It,r<be||(r=t[e+1],n+=(r&It)<<7,r<be)||(r=t[e+2],n+=(r&It)<<14,r<be)||(r=t[e+3],n+=(r&It)<<21,r<be)||(r=t[e+4],n+=(r&It)*Uc,r<be)||(r=t[e+5],n+=(r&It)*Fc,r<be)||(r=t[e+6],n+=(r&It)*Nc,r<be)||(r=t[e+7],n+=(r&It)*kc,r<be))return n;throw new RangeError("Could not decode varint")}var is=new Float32Array([-0]),Bt=new Uint8Array(is.buffer);function Kc(t,e,r){is[0]=t,e[r]=Bt[0],e[r+1]=Bt[1],e[r+2]=Bt[2],e[r+3]=Bt[3]}function Mc(t,e){return Bt[0]=t[e],Bt[1]=t[e+1],Bt[2]=t[e+2],Bt[3]=t[e+3],is[0]}var ss=new Float64Array([-0]),me=new Uint8Array(ss.buffer);function Vc(t,e,r){ss[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 qc(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],ss[0]}var hh=BigInt(Number.MAX_SAFE_INTEGER),ph=BigInt(Number.MIN_SAFE_INTEGER),Ie=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 Ht;if(e<hh&&e>ph)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>$c&&(o=0n,++n>$c&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Ht;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):Ht}},Ht=new Ie(0,0);Ht.toBigInt=function(){return 0n};Ht.zzEncode=Ht.zzDecode=function(){return this};Ht.length=function(){return 1};var $c=4294967296n;function Hc(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 zc(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 as(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 Ve(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function ro(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var cs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ve(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 Ve(this,4);return ro(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ve(this,4);return ro(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ve(this,4);let e=Mc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ve(this,4);let e=qc(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 Ve(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return zc(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ve(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ve(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 Ie(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 Ve(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 Ve(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 Ve(this,8);let e=ro(this.buf,this.pos+=4),r=ro(this.buf,this.pos+=4);return new Ie(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=Pc(this.buf,this.pos);return this.pos+=Jr(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 Qr(t){return new cs(t instanceof Uint8Array?t:t.subarray())}function Xe(t,e,r){let n=Qr(t);return e.decode(n,void 0,r)}function us(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 zt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function fs(){}var ds=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},mh=us();function yh(t){return globalThis.Buffer!=null?Ae(t):mh(t)}var tn=class{len;head;tail;states;constructor(){this.len=0,this.head=new zt(fs,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new zt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new hs((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(no,10,Ie.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Ie.fromBigInt(e);return this._push(no,r.length(),r)}uint64Number(e){return this._push(Oc,Jr(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=Ie.fromBigInt(e).zzEncode();return this._push(no,r.length(),r)}sint64Number(e){let r=Ie.fromNumber(e).zzEncode();return this._push(no,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(ls,1,e?1:0)}fixed32(e){return this._push(en,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Ie.fromBigInt(e);return this._push(en,4,r.lo)._push(en,4,r.hi)}fixed64Number(e){let r=Ie.fromNumber(e);return this._push(en,4,r.lo)._push(en,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(Kc,4,e)}double(e){return this._push(Vc,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(ls,1,0):this.uint32(r)._push(bh,r,e)}string(e){let r=Hc(e);return r!==0?this.uint32(r)._push(as,r,e):this._push(ls,1,0)}fork(){return this.states=new ds(this),this.head=this.tail=new zt(fs,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 zt(fs,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=yh(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function ls(t,e,r){e[r]=t&255}function gh(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var hs=class extends zt{next;constructor(e,r){super(gh,e,r),this.next=void 0}};function no(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 en(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 bh(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(tn.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(xh,e,t),this},tn.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(wh,e,t),this});function xh(t,e,r){e.set(t,r)}function wh(t,e,r){t.length<40?as(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set($(t),r)}function ps(){return new tn}function We(t,e){let r=ps();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Je(t,e,r){let n=Qr(t);yield*e.stream(n,void 0,"$",r)}var oo={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function io(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function rn(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 io("enum",oo.VARINT,r,n,o)}function Qe(t,e,r){return io("message",oo.LENGTH_DELIMITED,t,e,r)}var J;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(J||(J={}));var ms;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(ms||(ms={}));(function(t){t.codec=()=>rn(ms)})(J||(J={}));var et;(function(t){let e;t.codec=()=>(e==null&&(e=Qe((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),J.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=J.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:J.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 We(i,t.codec())}t.encode=r;function n(i,s){return Xe(i,t.codec(),s)}t.decode=n;function o(i,s){return Je(i,t.codec(),s)}t.stream=o})(et||(et={}));var ys;(function(t){let e;t.codec=()=>(e==null&&(e=Qe((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),J.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=J.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:J.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 We(i,t.codec())}t.encode=r;function n(i,s){return Xe(i,t.codec(),s)}t.decode=n;function o(i,s){return Je(i,t.codec(),s)}t.stream=o})(ys||(ys={}));var on={};we(on,{MAX_RSA_KEY_SIZE:()=>gs,generateRSAKeyPair:()=>Is,jwkToJWKKeyPair:()=>Wc,jwkToPkcs1:()=>Ah,jwkToPkix:()=>Es,jwkToRSAPrivateKey:()=>Ts,pkcs1MessageToJwk:()=>xs,pkcs1MessageToRSAPrivateKey:()=>Ss,pkcs1ToJwk:()=>vh,pkcs1ToRSAPrivateKey:()=>Xc,pkixMessageToJwk:()=>ws,pkixMessageToRSAPublicKey:()=>As,pkixToJwk:()=>Th,pkixToRSAPublicKey:()=>vs});var yr=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=on.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ie.createV1(114,this._multihash)}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ne(this.raw,e.raw)}verify(e,r,n){return Gc(this.jwk,r,e,n)}},nn=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=on.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ne(this.raw,e.raw)}sign(e,r){return Zc(this.jwk,e,r)}};var gs=8192,bs=18,Eh=1062,Sh=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function vh(t){let e=st(t);return xs(e)}function xs(t){return{n:Z(t[1],"base64url"),e:Z(t[2],"base64url"),d:Z(t[3],"base64url"),p:Z(t[4],"base64url"),q:Z(t[5],"base64url"),dp:Z(t[6],"base64url"),dq:Z(t[7],"base64url"),qi:Z(t[8],"base64url"),kty:"RSA"}}function Ah(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new Q("JWK was missing components");return ke([ge(Uint8Array.from([0])),ge($(t.n,"base64url")),ge($(t.e,"base64url")),ge($(t.d,"base64url")),ge($(t.p,"base64url")),ge($(t.q,"base64url")),ge($(t.dp,"base64url")),ge($(t.dq,"base64url")),ge($(t.qi,"base64url"))]).subarray()}function Th(t){let e=st(t,{offset:0});return ws(e)}function ws(t){let e=st(t[1],{offset:0});return{kty:"RSA",n:Z(e[0],"base64url"),e:Z(e[1],"base64url")}}function Es(t){if(t.n==null||t.e==null)throw new Q("JWK was missing components");return ke([Sh,Nr(ke([ge($(t.n,"base64url")),ge($(t.e,"base64url"))]))]).subarray()}function Xc(t){let e=st(t);return Ss(e)}function Ss(t){let e=xs(t);return Ts(e)}function vs(t,e){if(t.byteLength>=Eh)throw new Wt("Key size is too large");let r=st(t,{offset:0});return As(r,t,e)}function As(t,e,r){let n=ws(t);if(r==null){let o=ir(et.encode({Type:J.RSA,Data:e}));r=Ye(bs,o)}return new yr(n,r)}function Ts(t){if(Qc(t)>gs)throw new Q("Key size is too large");let e=Wc(t),r=ir(et.encode({Type:J.RSA,Data:Es(e.publicKey)})),n=Ye(bs,r);return new nn(e.privateKey,new yr(e.publicKey,n))}async function Is(t){if(t>gs)throw new Q("Key size is too large");let e=await Jc(t),r=ir(et.encode({Type:J.RSA,Data:Es(e.publicKey)})),n=Ye(bs,r);return new nn(e.privateKey,new yr(e.publicKey,n))}function Wc(t){if(t==null)throw new Q("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function Jc(t,e){let r=await Ee.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await Ih(r,e);return{privateKey:n[0],publicKey:n[1]}}async function Zc(t,e,r){let n=await Ee.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Ee.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,e instanceof Uint8Array?e:e.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Gc(t,e,r,n){let o=await Ee.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Ee.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),i}async function Ih(t,e){if(t.privateKey==null||t.publicKey==null)throw new Q("Private and public key are required");let r=await Promise.all([Ee.get().subtle.exportKey("jwk",t.privateKey),Ee.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Qc(t){if(t.kty!=="RSA")throw new Q("invalid key type");if(t.n==null)throw new Q("invalid key modulus");return $(t.n,"base64url").length*8}var so=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(On(e),Te(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),ct(o)}update(e){return or(this),this.iHash.update(e),this}digestInto(e){or(this),Pn(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()}},eu=(()=>{let t=((e,r,n)=>new so(e,r).update(n).digest());return t.create=(e,r)=>new so(e,r),t})();var tu=(t,e)=>(t+(t>=0?e:-e)/ru)/e;function Bh(t,e,r){cr("scalar",t,tt,r);let[[n,o],[i,s]]=e,a=tu(s*t,r),c=tu(-o*t,r),u=t-a*n-c*i,f=-a*o-c*s,l=u<tt,p=f<tt;l&&(u=-u),p&&(f=-f);let m=$r(Math.ceil(ur(r)/2))+_t;if(u<tt||u>=m||f<tt||f>=m)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:p,k2:f}}function _s(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Bs(t,e){Me(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Pe(r.lowS,"lowS"),Pe(r.prehash,"prehash"),r.format!==void 0&&_s(r.format),r}var Cs=class extends Error{constructor(e=""){super(e)}},qe={Err:Cs,_tlv:{encode:(t,e)=>{let{Err:r}=qe;if(Ke(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=Vr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?Vr(o.length/2|128):"";return Vr(t)+i+o+e},decode(t,e){let{Err:r}=qe;e=z(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}=qe;if(zn(t),t<tt)throw new e("integer: negative integers are not allowed");let r=Vr(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}=qe;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 Mt(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=qe,o=z(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}=qe,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(qe._tlv);Object.freeze(qe._int);Object.freeze(qe);var tt=BigInt(0),_t=BigInt(1),ru=BigInt(2),ao=BigInt(3),_h=BigInt(4);function nu(t,e={}){let r=Gn("weierstrass",t,e),n=r.Fp,o=r.Fn,i=r.CURVE,{h:s,n:a}=i;Me(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=iu(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function p(L,d,g){if(u&&d.is0())return Uint8Array.of(0);let{x:A,y:b}=d.toAffine(),x=n.toBytes(A);if(Pe(g,"isCompressed"),g){l();let I=!n.isOdd(b);return ae(ou(I),x)}else return ae(Uint8Array.of(4),x,n.toBytes(b))}function m(L){z(L,void 0,"Point");let{publicKey:d,publicKeyUncompressed:g}=f,A=L.length,b=L[0],x=L.subarray(1);if(u&&A===1&&b===0)return{x:n.ZERO,y:n.ZERO};if(A===d&&(b===2||b===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),D;try{D=n.sqrt(R)}catch(H){let Y=H instanceof Error?": "+H.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}l();let P=n.isOdd(D);return(b&1)===1!==P&&(D=n.neg(D)),{x:I,y:D}}else if(A===g&&b===4){let I=n.BYTES,R=n.fromBytes(x.subarray(0,I)),D=n.fromBytes(x.subarray(I,I*2));if(!w(R,D))throw new Error("bad point: is not on curve");return{x:R,y:D}}else throw new Error(`bad point: got length ${A}, expected compressed=${d} or uncompressed=${g}`)}let S=e.toBytes===void 0?p:e.toBytes,v=e.fromBytes===void 0?m:e.fromBytes;function h(L){let d=n.sqr(L),g=n.mul(d,L);return n.add(n.add(g,n.mul(L,i.a)),i.b)}function w(L,d){let g=n.sqr(d),A=h(L);return n.eql(g,A)}if(!w(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let T=n.mul(n.pow(i.a,ao),_h),B=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(T,B)))throw new Error("bad curve params: a or b");function O(L,d,g=!1){if(!n.isValid(d)||g&&n.is0(d))throw new Error(`bad point coordinate ${L}`);return d}function F(L){if(!(L instanceof E))throw new Error("Weierstrass Point expected")}function V(L){if(!c||!c.basises)throw new Error("no endo");return Bh(L,c.basises,o.ORDER)}function N(L,d,g,A,b){return g=new E(n.mul(g.X,L),g.Y,g.Z),d=zr(A,d),g=zr(b,g),d.add(g)}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,g,A){this.X=O("x",d),this.Y=O("y",g,!0),this.Z=O("z",A),Object.freeze(this)}static CURVE(){return i}static fromAffine(d){let{x:g,y:A}=d||{};if(!d||!n.isValid(g)||!n.isValid(A))throw new Error("invalid affine point");if(d instanceof E)throw new Error("projective point not allowed");return n.is0(g)&&n.is0(A)?E.ZERO:new E(g,A,n.ONE)}static fromBytes(d){let g=E.fromAffine(v(z(d,void 0,"point")));return g.assertValidity(),g}static fromHex(d){return E.fromBytes(ar(d))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=8,g=!0){return k.createCache(this,d),g||this.multiply(ao),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:g,y:A}=d.toAffine();if(!n.isValid(g)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!w(g,A))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){F(d);let{X:g,Y:A,Z:b}=this,{X:x,Y:I,Z:R}=d,D=n.eql(n.mul(g,R),n.mul(x,b)),P=n.eql(n.mul(A,R),n.mul(I,b));return D&&P}negate(){return new E(this.X,n.neg(this.Y),this.Z)}double(){let{a:d,b:g}=i,A=n.mul(g,ao),{X:b,Y:x,Z:I}=this,R=n.ZERO,D=n.ZERO,P=n.ZERO,M=n.mul(b,b),H=n.mul(x,x),Y=n.mul(I,I),q=n.mul(b,x);return q=n.add(q,q),P=n.mul(b,I),P=n.add(P,P),R=n.mul(d,P),D=n.mul(A,Y),D=n.add(R,D),R=n.sub(H,D),D=n.add(H,D),D=n.mul(R,D),R=n.mul(q,R),P=n.mul(A,P),Y=n.mul(d,Y),q=n.sub(M,Y),q=n.mul(d,q),q=n.add(q,P),P=n.add(M,M),M=n.add(P,M),M=n.add(M,Y),M=n.mul(M,q),D=n.add(D,M),Y=n.mul(x,I),Y=n.add(Y,Y),M=n.mul(Y,q),R=n.sub(R,M),P=n.mul(Y,H),P=n.add(P,P),P=n.add(P,P),new E(R,D,P)}add(d){F(d);let{X:g,Y:A,Z:b}=this,{X:x,Y:I,Z:R}=d,D=n.ZERO,P=n.ZERO,M=n.ZERO,H=i.a,Y=n.mul(i.b,ao),q=n.mul(g,x),se=n.mul(A,I),ce=n.mul(b,R),ue=n.add(g,A),re=n.add(x,I);ue=n.mul(ue,re),re=n.add(q,se),ue=n.sub(ue,re),re=n.add(g,b);let xe=n.add(x,R);return re=n.mul(re,xe),xe=n.add(q,ce),re=n.sub(re,xe),xe=n.add(A,b),D=n.add(I,R),xe=n.mul(xe,D),D=n.add(se,ce),xe=n.sub(xe,D),M=n.mul(H,re),D=n.mul(Y,ce),M=n.add(D,M),D=n.sub(se,M),M=n.add(se,M),P=n.mul(D,M),se=n.add(q,q),se=n.add(se,q),ce=n.mul(H,ce),re=n.mul(Y,re),se=n.add(se,ce),ce=n.sub(q,ce),ce=n.mul(H,ce),re=n.add(re,ce),q=n.mul(se,re),P=n.add(P,q),q=n.mul(xe,re),D=n.mul(ue,D),D=n.sub(D,q),q=n.mul(ue,se),M=n.mul(xe,M),M=n.add(M,q),new E(D,P,M)}subtract(d){return F(d),this.add(d.negate())}is0(){return this.equals(E.ZERO)}multiply(d){let{endo:g}=e;if(!o.isValidNot0(d))throw new RangeError("invalid scalar: out of range");let A,b,x=I=>k.cached(this,I,R=>$t(E,R));if(g){let{k1neg:I,k1:R,k2neg:D,k2:P}=V(d),{p:M,f:H}=x(R),{p:Y,f:q}=x(P);b=H.add(q),A=N(g.beta,M,Y,I,D)}else{let{p:I,f:R}=x(d);A=I,b=R}return $t(E,[A,b])[0]}multiplyUnsafe(d){let{endo:g}=e,A=this,b=d;if(!o.isValid(b))throw new RangeError("invalid scalar: out of range");if(b===tt||A.is0())return E.ZERO;if(b===_t)return A;if(k.hasCache(this))return this.multiply(b);if(g){let{k1neg:x,k1:I,k2neg:R,k2:D}=V(b),{p1:P,p2:M}=bc(E,A,I,D);return N(g.beta,P,M,x,R)}else return k.unsafe(A,b)}toAffine(d){let g=this,A=d,{X:b,Y:x,Z:I}=g;if(n.eql(I,n.ONE))return{x:b,y:x};let R=g.is0();A==null&&(A=R?n.ONE:n.inv(I));let D=n.mul(b,A),P=n.mul(x,A),M=n.mul(I,A);if(R)return{x:n.ZERO,y:n.ZERO};if(!n.eql(M,n.ONE))throw new Error("invZ was invalid");return{x:D,y:P}}isTorsionFree(){let{isTorsionFree:d}=e;return s===_t?!0:d?d(E,this):k.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:d}=e;return s===_t?this:d?d(E,this):this.multiplyUnsafe(s)}isSmallOrder(){return s===_t?this.is0():this.clearCofactor().is0()}toBytes(d=!0){return Pe(d,"isCompressed"),this.assertValidity(),S(E,this,d)}toHex(d=!0){return sr(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let _=o.BITS,k=new dr(E,e.endo?Math.ceil(_/2):_);return _>=8&&E.BASE.precompute(8),Object.freeze(E.prototype),Object.freeze(E),E}function ou(t){return Uint8Array.of(t?2:3)}function iu(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Ch(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?Mr:e.randomBytes,o=Object.assign(iu(t.Fp,r),{seed:Math.max(zi(r.ORDER),16)});function i(m){try{let S=r.fromBytes(m);return r.isValidNot0(S)}catch{return!1}}function s(m,S){let{publicKey:v,publicKeyUncompressed:h}=o;try{let w=m.length;return S===!0&&w!==v||S===!1&&w!==h?!1:!!t.fromBytes(m)}catch{return!1}}function a(m){return m=m===void 0?n(o.seed):m,ji(z(m,o.seed,"seed"),r.ORDER)}function c(m,S=!0){return t.BASE.multiply(r.fromBytes(m)).toBytes(S)}function u(m){let{secretKey:S,publicKey:v,publicKeyUncompressed:h}=o,w=r._lengths;if(!Kt(m))return;let T=z(m,void 0,"key").length,B=T===v||T===h,O=T===S||!!w?.includes(T);if(!(B&&O))return B}function f(m,S,v=!0){if(u(m)===!0)throw new Error("first arg must be private key");if(u(S)===!1)throw new Error("second arg must be public key");let h=r.fromBytes(m);return t.fromBytes(S).multiply(h).toBytes(v)}let l={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},p=Xn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:p,Point:t,utils:l,lengths:o})}function su(t,e,r={}){let n=e;On(n),Me(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?Mr:r.randomBytes,i=r.hmac===void 0?(b,x)=>eu(n,b,x):r.hmac,{Fp:s,Fn:a}=t,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:p,utils:m,lengths:S}=Ch(t,r),v={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},h=c*ru+_t<s.ORDER;function w(b){let x=c>>_t;return b>x}function T(b,x){if(!a.isValidNot0(x))throw new Error(`invalid signature ${b}: out of range 1..Point.Fn.ORDER`);return x}function B(){if(h)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function O(b,x){_s(x);let I=S.signature,R=x==="compact"?I:x==="recovered"?I+1:void 0;return z(b,R)}class F{r;s;recovery;constructor(x,I,R){if(this.r=T("r",x),this.s=T("s",I),R!=null){if(B(),![0,1,2,3].includes(R))throw new Error("invalid recovery id");this.recovery=R}Object.freeze(this)}static fromBytes(x,I=v.format){O(x,I);let R;if(I==="der"){let{r:H,s:Y}=qe.toSig(z(x));return new F(H,Y)}I==="recovered"&&(R=x[0],I="compact",x=x.subarray(1));let D=S.signature/2,P=x.subarray(0,D),M=x.subarray(D,D*2);return new F(a.fromBytes(P),a.fromBytes(M),R)}static fromHex(x,I){return this.fromBytes(ar(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 F(this.r,this.s,x)}recoverPublicKey(x){let{r:I,s:R}=this,D=this.assertRecovery(),P=D===2||D===3?I+c:I;if(!s.isValid(P))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let M=s.toBytes(P),H=t.fromBytes(ae(ou((D&1)===0),M)),Y=a.inv(P),q=N(z(x,void 0,"msgHash")),se=a.create(-q*Y),ce=a.create(R*Y),ue=t.BASE.multiplyUnsafe(se).add(H.multiplyUnsafe(ce));if(ue.is0())throw new Error("invalid recovery: point at infinify");return ue.assertValidity(),ue}hasHighS(){return w(this.s)}toBytes(x=v.format){if(_s(x),x==="der")return ar(qe.hexFromSig(this));let{r:I,s:R}=this,D=a.toBytes(I),P=a.toBytes(R);return x==="recovered"?(B(),ae(Uint8Array.of(this.assertRecovery()),D,P)):ae(D,P)}toHex(x){return sr(this.toBytes(x))}}Object.freeze(F.prototype),Object.freeze(F);let V=r.bits2int===void 0?function(x){if(x.length>8192)throw new Error("input is too large");let I=Mt(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(V(x))}:r.bits2int_modN,E=$r(u);function _(b){return cr("num < 2^"+u,b,tt,E),a.toBytes(b)}function k(b,x){return z(b,void 0,"message"),x?z(n(b),void 0,"prehashed message"):b}function L(b,x,I){let{lowS:R,prehash:D,extraEntropy:P}=Bs(I,v);b=k(b,D);let M=N(b),H=a.fromBytes(x);if(!a.isValidNot0(H))throw new Error("invalid private key");let Y=[_(H),_(M)];if(P!=null&&P!==!1){let ue=P===!0?o(S.secretKey):P;Y.push(z(ue,void 0,"extraEntropy"))}let q=ae(...Y),se=M;function ce(ue){let re=V(ue);if(!a.isValidNot0(re))return;let xe=a.inv(re),Xt=t.BASE.multiply(re).toAffine(),_r=a.create(Xt.x);if(_r===tt)return;let In=a.create(xe*a.create(se+_r*H));if(In===tt)return;let ra=(Xt.x===_r?0:2)|Number(Xt.y&_t),na=In;return R&&w(In)&&(na=a.neg(In),ra^=1),new F(_r,na,h?void 0:ra)}return{seed:q,k2sig:ce}}function d(b,x,I={}){let{seed:R,k2sig:D}=L(b,x,I);return tc(n.outputLen,a.BYTES,i)(R,D).toBytes(I.format)}function g(b,x,I,R={}){let{lowS:D,prehash:P,format:M}=Bs(R,v);if(I=z(I,void 0,"publicKey"),x=k(x,P),!Kt(b)){let H=b instanceof F?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+H)}O(b,M);try{let H=F.fromBytes(b,M),Y=t.fromBytes(I);if(D&&H.hasHighS())return!1;let{r:q,s:se}=H,ce=N(x),ue=a.inv(se),re=a.create(ce*ue),xe=a.create(q*ue),Xt=t.BASE.multiplyUnsafe(re).add(Y.multiplyUnsafe(xe));return Xt.is0()?!1:a.create(Xt.x)===q}catch{return!1}}function A(b,x,I={}){let{prehash:R}=Bs(I,v);return x=k(x,R),F.fromBytes(b,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:p,utils:m,lengths:S,Point:t,sign:d,verify:g,recoverPublicKey:A,Signature:F,hash:n})}var Ds={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Rh={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var au=BigInt(2);function Dh(t){let e=Ds.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,p=W(l,r,e)*f%e,m=W(p,au,e)*u%e,S=W(m,o,e)*m%e,v=W(S,i,e)*S%e,h=W(v,a,e)*v%e,w=W(h,c,e)*h%e,T=W(w,a,e)*v%e,B=W(T,r,e)*f%e,O=W(B,s,e)*S%e,F=W(O,n,e)*u%e,V=W(F,au,e);if(!Rs.eql(Rs.sqr(V),t))throw new Error("Cannot find square root");return V}var Rs=fr(Ds.p,{sqrt:Dh}),Lh=nu(Ds,{Fp:Rs,endo:Rh}),$e=su(Lh,ir);function cu(t,e,r){let n=Un.digest(e instanceof Uint8Array?e:e.subarray());if(mr(n))return n.then(({digest:o})=>(r?.signal?.throwIfAborted(),$e.sign(o,t,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new Zr(String(o))});try{return $e.sign(n.digest,t,{prehash:!1,format:"der"})}catch(o){throw new Zr(String(o))}}function uu(t,e,r,n){let o=Un.digest(r instanceof Uint8Array?r:r.subarray());if(mr(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),$e.verify(e,i,t,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new Gr(String(i))});try{return n?.signal?.throwIfAborted(),$e.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(i){throw new Gr(String(i))}}var sn=class{type="secp256k1";raw;_key;constructor(e){this._key=du(e),this.raw=fu(this._key)}toMultihash(){return Nt.digest(gt(this))}toCID(){return ie.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ne(this.raw,e.raw)}verify(e,r,n){return uu(this._key,r,e,n)}},co=class{type="secp256k1";raw;publicKey;constructor(e,r){this.raw=lu(e),this.publicKey=new sn(r??hu(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ne(this.raw,e.raw)}sign(e,r){return cu(this.raw,e,r)}};function Ls(t){return new sn(t)}async function pu(){let t=Uh();return new co(t)}function fu(t){return $e.Point.fromBytes(t).toBytes()}function lu(t){try{return $e.getPublicKey(t,!0),t}catch(e){throw new Cr(String(e))}}function du(t){try{return $e.Point.fromBytes(t),t}catch(e){throw new Wt(String(e))}}function hu(t){try{return $e.getPublicKey(t,!0)}catch(e){throw new Cr(String(e))}}function Uh(){return $e.utils.randomSecretKey()}async function mu(t,e){if(t==="Ed25519")return Lc();if(t==="secp256k1")return pu();if(t==="RSA")return Is(Fh(e));if(t==="ECDSA")return Pa(Nh(e));throw new Jt}function yu(t,e){let{Type:r,Data:n}=et.decode(t),o=n??new Uint8Array;switch(r){case J.RSA:return vs(o,e);case J.Ed25519:return os(o);case J.secp256k1:return Ls(o);case J.ECDSA:return _i(o);default:throw new Jt}}function gu(t){let{Type:e,Data:r}=et.decode(t.digest),n=r??new Uint8Array;switch(e){case J.Ed25519:return os(n);case J.secp256k1:return Ls(n);case J.ECDSA:return _i(n);default:throw new Jt}}function gt(t){return et.encode({Type:J[t.type],Data:t.raw})}function Fh(t){return t==null?2048:parseInt(t,10)}function Nh(t){if(t==="P-256"||t==null)return"P-256";if(t==="P-384")return"P-384";if(t==="P-521")return"P-521";throw new Q("Unsupported curve, should be P-256, P-384 or P-521")}function kh(t,e){if(typeof t=="string")return Oh(t);if(typeof t=="number")return Mh(t,e);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}var uo=kh;function Oh(t){if(typeof t!="string"||t.length===0||t.length>100)throw Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(t)}`);let e=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(t);if(!e?.groups)return NaN;let{value:r,unit:n="ms"}=e.groups,o=parseFloat(r),i=n.toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw Error(`Unknown unit "${i}" provided to ms.parse(). value=${JSON.stringify(t)}`)}}function Ph(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 Kh(t){let e=Math.abs(t);return e>=315576e5?jt(t,e,315576e5,"year"):e>=26298e5?jt(t,e,26298e5,"month"):e>=6048e5?jt(t,e,6048e5,"week"):e>=864e5?jt(t,e,864e5,"day"):e>=36e5?jt(t,e,36e5,"hour"):e>=6e4?jt(t,e,6e4,"minute"):e>=1e3?jt(t,e,1e3,"second"):`${t} ms`}function Mh(t,e){if(typeof t!="number"||!Number.isFinite(t))throw Error("Value provided to ms.format() must be of type number.");return e?.long?Kh(t):Ph(t)}function jt(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function Us(t){r.debug=r,r.default=r,r.coerce=c,r.disable=i,r.enable=o,r.enabled=s,r.humanize=uo,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 p=0;p<f.length;p++)l=(l<<5)-l+f.charCodeAt(p),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=e;function r(f,l){let p,m=null,S,v;function h(...w){if(!h.enabled)return;let T=h,B=Number(new Date),O=B-(p||B);T.diff=O,T.prev=p,T.curr=B,p=B,w[0]=r.coerce(w[0]),typeof w[0]!="string"&&w.unshift("%O");let F=0;w[0]=w[0].replace(/%([a-zA-Z%])/g,(N,E)=>{if(N==="%%")return"%";F++;let _=r.formatters[E];if(typeof _=="function"){let k=w[F];N=_.call(T,k),w.splice(F,1),F--}return N}),r.formatArgs.call(T,w),l?.onLog!=null&&l.onLog(...w),(T.log||r.log).apply(T,w)}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:(S!==r.namespaces&&(S=r.namespaces,v=r.enabled(f)),v),set:w=>{m=w}}),typeof r.init=="function"&&r.init(h),h}function n(f,l){let p=r(this.namespace+(typeof l>"u"?":":l)+f);return p.log=this.log,p}function o(f){r.save(f),r.namespaces=f,r.names=[],r.skips=[];let l,p=(typeof f=="string"?f:"").split(/[\s,]+/),m=p.length;for(l=0;l<m;l++)p[l]&&(f=p[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,p;for(l=0,p=r.skips.length;l<p;l++)if(r.skips[l].test(f))return!1;for(l=0,p=r.names.length;l<p;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 fo=Yh(),Vh=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function qh(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function $h(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+uo(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 Hh=console.debug??console.log??(()=>{});function zh(t){try{t?fo?.setItem("debug",t):fo?.removeItem("debug")}catch{}}function jh(){let t;try{t=fo?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function Yh(){try{return localStorage}catch{}}function Zh(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var bu=Us({formatArgs:$h,save:zh,load:jh,useColors:qh,setupFormatters:Zh,colors:Vh,storage:fo,log:Hh});var Se=bu;Se.formatters.b=t=>t==null?"undefined":X.baseEncode(t);Se.formatters.t=t=>t==null?"undefined":mt.baseEncode(t);Se.formatters.m=t=>t==null?"undefined":mi.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 xu(t,e=""){let r=wu(t.message),n=wu(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
4
4
  `).join(`
5
5
  ${e}`)}`:`${r}
6
6
  ${e}${n.split(`
@@ -10,7 +10,7 @@ ${e}`)}`:n!=null?`${n.split(`
10
10
  ${e}`)}`:r!=null?`${r}`:`${t.toString()}`}function Gh(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function Eu(t,e=""){if(Gh(t)){let r=xu(t,e);return t.errors.length>0?(e=`${e} `,r+=`
11
11
  ${e}${t.errors.map(n=>`${Eu(n,`${e}`)}`).join(`
12
12
  ${e}`)}`):r+=`
13
- ${e}[Error list was empty]`,r.trim()}return xu(t,e)}Se.formatters.e=t=>t==null?"undefined":Eu(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}function Yt(t,e){let r=Xh(`${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=>Yt(`${t}:${n}`,e)})}function wu(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var Nf=ei(lo(),1);var ho=class extends Error{static name="SignatureCreationError";constructor(e="Record signature creation failed"){super(e),this.name="SignatureCreationError"}},He=class extends Error{static name="SignatureVerificationError";constructor(e="Record signature verification failed"){super(e),this.name="SignatureVerificationError"}},po=class extends Error{static name="RecordExpiredError";constructor(e="Record has expired"){super(e),this.name="RecordExpiredError"}},Zt=class extends Error{static name="UnsupportedValidityError";constructor(e="The validity type is unsupported"){super(e),this.name="UnsupportedValidityError"}},mo=class extends Error{static name="RecordTooLargeError";constructor(e="The record is too large"){super(e),this.name="RecordTooLargeError"}},an=class extends Error{static name="InvalidValueError";constructor(e="Value must be a valid content path starting with /"){super(e),this.name="InvalidValueError"}},yo=class extends Error{static name="InvalidRecordDataError";constructor(e="Invalid record data"){super(e),this.name="InvalidRecordDataError"}},cn=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(e="Invalid embedded public key"){super(e),this.name="InvalidEmbeddedPublicKeyError"}};var pe;(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=()=>rn(r)})(e=t.ValidityType||(t.ValidityType={}));let n;t.codec=()=>(n==null&&(n=Qe((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.value!=null&&(c.uint32(10),c.bytes(a.value)),a.signatureV1!=null&&(c.uint32(18),c.bytes(a.signatureV1)),a.validityType!=null&&(c.uint32(24),t.ValidityType.codec().encode(a.validityType,c)),a.validity!=null&&(c.uint32(34),c.bytes(a.validity)),a.sequence!=null&&(c.uint32(40),c.uint64(a.sequence)),a.ttl!=null&&(c.uint32(48),c.uint64(a.ttl)),a.pubKey!=null&&(c.uint32(58),c.bytes(a.pubKey)),a.signatureV2!=null&&(c.uint32(66),c.bytes(a.signatureV2)),a.data!=null&&(c.uint32(74),c.bytes(a.data)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let p=a.uint32();switch(p>>>3){case 1:{f.value=a.bytes();break}case 2:{f.signatureV1=a.bytes();break}case 3:{f.validityType=t.ValidityType.codec().decode(a);break}case 4:{f.validity=a.bytes();break}case 5:{f.sequence=a.uint64();break}case 6:{f.ttl=a.uint64();break}case 7:{f.pubKey=a.bytes();break}case 8:{f.signatureV2=a.bytes();break}case 9:{f.data=a.bytes();break}default:{a.skipType(p&7);break}}}return f},function*(a,c,u,f={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let p=a.uint32();switch(p>>>3){case 1:{yield{field:`${u}.value`,value:a.bytes()};break}case 2:{yield{field:`${u}.signatureV1`,value:a.bytes()};break}case 3:{yield{field:`${u}.validityType`,value:t.ValidityType.codec().decode(a)};break}case 4:{yield{field:`${u}.validity`,value:a.bytes()};break}case 5:{yield{field:`${u}.sequence`,value:a.uint64()};break}case 6:{yield{field:`${u}.ttl`,value:a.uint64()};break}case 7:{yield{field:`${u}.pubKey`,value:a.bytes()};break}case 8:{yield{field:`${u}.signatureV2`,value:a.bytes()};break}case 9:{yield{field:`${u}.data`,value:a.bytes()};break}default:{a.skipType(p&7);break}}}})),n);function o(a){return We(a,t.codec())}t.encode=o;function i(a,c){return Xe(a,t.codec(),c)}t.decode=i;function s(a,c){return Je(a,t.codec(),c)}t.stream=s})(pe||(pe={}));var Wh=["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 Ns(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=Jh(t);return r||"Object"}function Jh(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Wh.includes(e))return e}var y=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}};y.uint=new y(0,"uint",!0);y.negint=new y(1,"negint",!0);y.bytes=new y(2,"bytes",!0);y.string=new y(3,"string",!0);y.array=new y(4,"array",!1);y.map=new y(5,"map",!1);y.tag=new y(6,"tag",!1);y.float=new y(7,"float",!0);y.false=new y(7,"false",!0);y.true=new y(7,"true",!0);y.null=new y(7,"null",!0);y.undefined=new y(7,"undefined",!0);y.break=new y(7,"break",!0);var U=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 un=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Qh=new TextEncoder;function go(t){return un&&globalThis.Buffer.isBuffer(t)}function fn(t){return t instanceof Uint8Array?go(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var ep=24,tp=200,bo=un?t=>t.length>=ep?globalThis.Buffer.from(t):Su(t):t=>t.length>=tp?Qh.encode(t):Su(t),rt=t=>Uint8Array.from(t),vu=un?(t,e,r)=>go(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),Au=un?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),fn(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},Tu=un?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function xo(t,e){if(go(t)&&go(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 Su(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 rp=256,ln=class{constructor(e=rp){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=Tu(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=vu(n,0,this.cursor)}else r=Au(this.chunks,this.cursor);return e&&this.reset(),r}},wo=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var K="CBOR decode error:",Eo="CBOR encode error:",dn=[];dn[23]=1;dn[24]=2;dn[25]=3;dn[26]=5;dn[27]=9;function dt(t,e,r){if(t.length-e<r)throw new Error(`${K} not enough data for type`)}var le=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Be(t,e,r){dt(t,e,1);let n=t[e];if(r.strict===!0&&n<le[0])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function _e(t,e,r){dt(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<le[1])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Ce(t,e,r){dt(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(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Re(t,e,r){dt(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(`${K} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${K} integers outside of the safe integer range are not supported`)}function Iu(t,e,r,n){return new U(y.uint,Be(t,e+1,n),2)}function Bu(t,e,r,n){return new U(y.uint,_e(t,e+1,n),3)}function _u(t,e,r,n){return new U(y.uint,Ce(t,e+1,n),5)}function Cu(t,e,r,n){return new U(y.uint,Re(t,e+1,n),9)}function Ue(t,e){return G(t,0,e.value)}function G(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(`${K} encountered BigInt larger than allowable range`)}}Ue.encodedSize=function(e){return G.encodedSize(e.value)};G.encodedSize=function(e){return e<le[0]?1:e<le[1]?2:e<le[2]?3:e<le[3]?5:9};Ue.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Ru(t,e,r,n){return new U(y.negint,-1-Be(t,e+1,n),2)}function Du(t,e,r,n){return new U(y.negint,-1-_e(t,e+1,n),3)}function Lu(t,e,r,n){return new U(y.negint,-1-Ce(t,e+1,n),5)}var ks=BigInt(-1),Uu=BigInt(1);function Fu(t,e,r,n){let o=Re(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new U(y.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${K} integers outside of the safe integer range are not supported`);return new U(y.negint,ks-BigInt(o),9)}function So(t,e){let r=e.value,n=typeof r=="bigint"?r*ks-Uu:r*-1-1;G(t,e.type.majorEncoded,n)}So.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*ks-Uu:r*-1-1;return n<le[0]?1:n<le[1]?2:n<le[2]?3:n<le[3]?5:9};So.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function hn(t,e,r,n){dt(t,e,r+n);let o=t.slice(e+r,e+r+n);return new U(y.bytes,o,r+n)}function Nu(t,e,r,n){return hn(t,e,1,r)}function ku(t,e,r,n){return hn(t,e,2,Be(t,e+1,n))}function Ou(t,e,r,n){return hn(t,e,3,_e(t,e+1,n))}function Pu(t,e,r,n){return hn(t,e,5,Ce(t,e+1,n))}function Ku(t,e,r,n){let o=Re(t,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer bytes lengths not supported`);return hn(t,e,9,o)}function vo(t){return t.encodedBytes===void 0&&(t.encodedBytes=y.equals(t.type,y.string)?bo(t.value):t.value),t.encodedBytes}function gr(t,e){let r=vo(e);G(t,e.type.majorEncoded,r.length),t.push(r)}gr.encodedSize=function(e){let r=vo(e);return G.encodedSize(r.length)+r.length};gr.compareTokens=function(e,r){return op(vo(e),vo(r))};function op(t,e){return t.length<e.length?-1:t.length>e.length?1:xo(t,e)}var Mu=new TextDecoder,sp=32;function ap(t,e,r){if(r-e<sp){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return Mu.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return Mu.decode(t.subarray(e,r))}function pn(t,e,r,n,o){let i=r+n;dt(t,e,i);let s=new U(y.string,ap(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function Vu(t,e,r,n){return pn(t,e,1,r,n)}function qu(t,e,r,n){return pn(t,e,2,Be(t,e+1,n),n)}function $u(t,e,r,n){return pn(t,e,3,_e(t,e+1,n),n)}function Hu(t,e,r,n){return pn(t,e,5,Ce(t,e+1,n),n)}function zu(t,e,r,n){let o=Re(t,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer string lengths not supported`);return pn(t,e,9,o,n)}var ju=gr;function br(t,e,r,n){return new U(y.array,n,r)}function Yu(t,e,r,n){return br(t,e,1,r)}function Zu(t,e,r,n){return br(t,e,2,Be(t,e+1,n))}function Gu(t,e,r,n){return br(t,e,3,_e(t,e+1,n))}function Xu(t,e,r,n){return br(t,e,5,Ce(t,e+1,n))}function Wu(t,e,r,n){let o=Re(t,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer array lengths not supported`);return br(t,e,9,o)}function Ju(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return br(t,e,1,1/0)}function Ao(t,e){G(t,y.array.majorEncoded,e.value)}Ao.compareTokens=Ue.compareTokens;Ao.encodedSize=function(e){return G.encodedSize(e.value)};function xr(t,e,r,n){return new U(y.map,n,r)}function Qu(t,e,r,n){return xr(t,e,1,r)}function ef(t,e,r,n){return xr(t,e,2,Be(t,e+1,n))}function tf(t,e,r,n){return xr(t,e,3,_e(t,e+1,n))}function rf(t,e,r,n){return xr(t,e,5,Ce(t,e+1,n))}function nf(t,e,r,n){let o=Re(t,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer map lengths not supported`);return xr(t,e,9,o)}function of(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return xr(t,e,1,1/0)}function To(t,e){G(t,y.map.majorEncoded,e.value)}To.compareTokens=Ue.compareTokens;To.encodedSize=function(e){return G.encodedSize(e.value)};function sf(t,e,r,n){return new U(y.tag,r,1)}function af(t,e,r,n){return new U(y.tag,Be(t,e+1,n),2)}function cf(t,e,r,n){return new U(y.tag,_e(t,e+1,n),3)}function uf(t,e,r,n){return new U(y.tag,Ce(t,e+1,n),5)}function ff(t,e,r,n){return new U(y.tag,Re(t,e+1,n),9)}function Io(t,e){G(t,y.tag.majorEncoded,e.value)}Io.compareTokens=Ue.compareTokens;Io.encodedSize=function(e){return G.encodedSize(e.value)};var Os=20,Ps=21,Ks=22,Ms=23;function lf(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${K} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new U(y.null,null,1):new U(y.undefined,void 0,1)}function df(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return new U(y.break,void 0,1)}function Vs(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${K} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${K} Infinity values are not supported`)}return new U(y.float,t,e)}function hf(t,e,r,n){return Vs(qs(t,e+1),3,n)}function pf(t,e,r,n){return Vs($s(t,e+1),5,n)}function mf(t,e,r,n){return Vs(xf(t,e+1),9,n)}function mn(t,e,r){let n=e.value;if(n===!1)t.push([y.float.majorEncoded|Os]);else if(n===!0)t.push([y.float.majorEncoded|Ps]);else if(n===null)t.push([y.float.majorEncoded|Ks]);else if(n===void 0)t.push([y.float.majorEncoded|Ms]);else{let o,i=!1;(!r||r.float64!==!0)&&(gf(n),o=qs(ze,1),n===o||Number.isNaN(n)?(ze[0]=249,t.push(ze.slice(0,3)),i=!0):(bf(n),o=$s(ze,1),n===o&&(ze[0]=250,t.push(ze.slice(0,5)),i=!0))),i||(dp(n),o=xf(ze,1),ze[0]=251,t.push(ze.slice(0,9)))}}mn.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){gf(n);let o=qs(ze,1);if(n===o||Number.isNaN(n))return 3;if(bf(n),o=$s(ze,1),n===o)return 5}return 9};var yf=new ArrayBuffer(9),Fe=new DataView(yf,1),ze=new Uint8Array(yf,0);function gf(t){if(t===1/0)Fe.setUint16(0,31744,!1);else if(t===-1/0)Fe.setUint16(0,64512,!1);else if(Number.isNaN(t))Fe.setUint16(0,32256,!1);else{Fe.setFloat32(0,t);let e=Fe.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)Fe.setUint16(0,31744,!1);else if(r===0)Fe.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Fe.setUint16(0,0):o<-14?Fe.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):Fe.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function qs(t,e){if(t.length-e<2)throw new Error(`${K} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function bf(t){Fe.setFloat32(0,t,!1)}function $s(t,e){if(t.length-e<4)throw new Error(`${K} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function dp(t){Fe.setFloat64(0,t,!1)}function xf(t,e){if(t.length-e<8)throw new Error(`${K} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}mn.compareTokens=Ue.compareTokens;function j(t,e,r){throw new Error(`${K} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function Bo(t){return()=>{throw new Error(`${K} ${t}`)}}var C=[];for(let t=0;t<=23;t++)C[t]=j;C[24]=Iu;C[25]=Bu;C[26]=_u;C[27]=Cu;C[28]=j;C[29]=j;C[30]=j;C[31]=j;for(let t=32;t<=55;t++)C[t]=j;C[56]=Ru;C[57]=Du;C[58]=Lu;C[59]=Fu;C[60]=j;C[61]=j;C[62]=j;C[63]=j;for(let t=64;t<=87;t++)C[t]=Nu;C[88]=ku;C[89]=Ou;C[90]=Pu;C[91]=Ku;C[92]=j;C[93]=j;C[94]=j;C[95]=Bo("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)C[t]=Vu;C[120]=qu;C[121]=$u;C[122]=Hu;C[123]=zu;C[124]=j;C[125]=j;C[126]=j;C[127]=Bo("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)C[t]=Yu;C[152]=Zu;C[153]=Gu;C[154]=Xu;C[155]=Wu;C[156]=j;C[157]=j;C[158]=j;C[159]=Ju;for(let t=160;t<=183;t++)C[t]=Qu;C[184]=ef;C[185]=tf;C[186]=rf;C[187]=nf;C[188]=j;C[189]=j;C[190]=j;C[191]=of;for(let t=192;t<=215;t++)C[t]=sf;C[216]=af;C[217]=cf;C[218]=uf;C[219]=ff;C[220]=j;C[221]=j;C[222]=j;C[223]=j;for(let t=224;t<=243;t++)C[t]=Bo("simple values are not supported");C[244]=j;C[245]=j;C[246]=j;C[247]=lf;C[248]=Bo("simple values are not supported");C[249]=hf;C[250]=pf;C[251]=mf;C[252]=j;C[253]=j;C[254]=j;C[255]=df;var je=[];for(let t=0;t<24;t++)je[t]=new U(y.uint,t,1);for(let t=-1;t>=-24;t--)je[31-t]=new U(y.negint,t,1);je[64]=new U(y.bytes,new Uint8Array(0),1);je[96]=new U(y.string,"",1);je[128]=new U(y.array,0,1);je[160]=new U(y.map,0,1);je[244]=new U(y.false,!1,1);je[245]=new U(y.true,!0,1);je[246]=new U(y.null,null,1);function Hs(t){switch(t.type){case y.false:return rt([244]);case y.true:return rt([245]);case y.null:return rt([246]);case y.bytes:return t.value.length?void 0:rt([64]);case y.string:return t.value===""?rt([96]):void 0;case y.array:return t.value===0?rt([128]):void 0;case y.map:return t.value===0?rt([160]):void 0;case y.uint:return t.value<24?rt([Number(t.value)]):void 0;case y.negint:if(t.value>=-24)return rt([31-Number(t.value)])}}var pp={float64:!1,mapSorter:gp,quickEncodeToken:Hs},Af=Object.freeze({float64:!0,mapSorter:bp,quickEncodeToken:Hs});function mp(){let t=[];return t[y.uint.major]=Ue,t[y.negint.major]=So,t[y.bytes.major]=gr,t[y.string.major]=ju,t[y.array.major]=Ao,t[y.map.major]=To,t[y.tag.major]=Io,t[y.float.major]=mn,t}var Er=mp(),_o=new ln,gn=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(`${Eo} object contains circular references`);return new t(r,e)}},Ct={null:new U(y.null,null),undefined:new U(y.undefined,void 0),true:new U(y.true,!0),false:new U(y.false,!1),emptyArray:new U(y.array,0),emptyMap:new U(y.map,0)},nt={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new U(y.float,t):t>=0?new U(y.uint,t):new U(y.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new U(y.uint,t):new U(y.negint,t)},Uint8Array(t,e,r,n){return new U(y.bytes,t)},string(t,e,r,n){return new U(y.string,t)},boolean(t,e,r,n){return t?Ct.true:Ct.false},null(t,e,r,n){return Ct.null},undefined(t,e,r,n){return Ct.undefined},ArrayBuffer(t,e,r,n){return new U(y.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new U(y.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Ct.emptyArray,new U(y.break)]:Ct.emptyArray;n=gn.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=wr(s,r,n);return r.addBreakTokens?[new U(y.array,t.length),o,new U(y.break)]:[new U(y.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=gn.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++]=[wr(f,r,n),wr(l,r,n)])}u<s&&(a.length=u)}return a?.length?(yp(a,r),r.addBreakTokens?[new U(y.map,a.length),a,new U(y.break)]:[new U(y.map,a.length),a]):r.addBreakTokens===!0?[Ct.emptyMap,new U(y.break)]:Ct.emptyMap},Tagged(t,e,r,n){return[new U(y.tag,t.tag),wr(t.value,r,n)]}};nt.Map=nt.Object;nt.Buffer=nt.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))nt[`${t}Array`]=nt.DataView;function wr(t,e={},r){let n=Ns(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||nt[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=nt[n];if(!i)throw new Error(`${Eo} unsupported type: ${n}`);return i(t,n,e,r)}function yp(t,e){e.mapSorter&&t.sort(e.mapSorter)}function gp(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=Er[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function bp(t,e){if(t[0]instanceof U&&e[0]instanceof U){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=wf(r.value)),n._keyBytes||(n._keyBytes=wf(n.value)),xo(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function wf(t){return If(t,Er,Af)}function yn(t,e,r,n){if(Array.isArray(e))for(let o of e)yn(t,o,r,n);else r[e.type.major](t,e,n)}var Ef=y.uint.majorEncoded,Sf=y.negint.majorEncoded,xp=y.bytes.majorEncoded,wp=y.string.majorEncoded,vf=y.array.majorEncoded,Ep=y.float.majorEncoded|Os,Sp=y.float.majorEncoded|Ps,vp=y.float.majorEncoded|Ks,Ap=y.float.majorEncoded|Ms,Tp=BigInt(-1),Ip=BigInt(1);function Bp(t){return t.addBreakTokens!==!0}function Tf(t,e,r,n){let o=Ns(e),i=r.typeEncoders&&r.typeEncoders[o];if(i){let s=i(e,o,r,n);if(s!=null){yn(t,s,Er,r);return}}switch(o){case"null":t.push([vp]);return;case"undefined":t.push([Ap]);return;case"boolean":t.push([e?Sp:Ep]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?mn(t,new U(y.float,e),r):e>=0?G(t,Ef,e):G(t,Sf,e*-1-1);return;case"bigint":e>=BigInt(0)?G(t,Ef,e):G(t,Sf,e*Tp-Ip);return;case"string":{let s=bo(e);G(t,wp,s.length),t.push(s);return}case"Uint8Array":G(t,xp,e.length),t.push(e);return;case"Array":if(!e.length){t.push([vf]);return}n=gn.createCheck(n,e),G(t,vf,e.length);for(let s of e)Tf(t,s,r,n);return;case"Object":case"Map":{let s=nt.Object(e,o,r,n);yn(t,s,Er,r)}return;default:{let s=nt[o];if(!s)throw new Error(`${Eo} unsupported type: ${o}`);let a=s(e,o,r,n);yn(t,a,Er,r)}}}function If(t,e,r,n){let o=n instanceof Uint8Array,i=o?new wo(n):_o,s=wr(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 ln(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():fn(i.chunks[0])}}return i.reset(),yn(i,s,e,r),i.toBytes(!0)}function zs(t,e){return e=Object.assign({},pp,e),Bp(e)?(_o.reset(),Tf(_o,t,e,void 0),_o.toBytes(!0)):If(t,Er,e)}var _p={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Co=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=je[e];if(r===void 0){let n=C[e];if(!n)throw new Error(`${K} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},Rt=Symbol.for("DONE"),Sr=Symbol.for("BREAK");function Cp(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=Dt(e,r);if(i===Sr){if(t.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed array`)}if(i===Rt)throw new Error(`${K} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Rp(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=Dt(e,r);if(c===Sr){if(t.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed map`)}if(c===Rt)throw new Error(`${K} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${K} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${K} found repeat map key "${c}"`);let u=Dt(e,r);if(u===Rt)throw new Error(`${K} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,u):i[c]=u}return n?s:i}function*Dp(t,e,r){for(let n=0;n<t.value;n++){let o=Dt(e,r);if(o===Sr){if(t.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed map`)}if(o===Rt)throw new Error(`${K} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let i=Dt(e,r);if(i===Rt)throw new Error(`${K} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,i]}}function Lp(t,e){let r=!1,n=function(){if(r)throw new Error(`${K} tag decode() may only be called once`);r=!0;let o=Dt(t,e);if(o===Rt)throw new Error(`${K} tag content missing`);if(o===Sr)throw new Error(`${K} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${K} tag decode() may only be called once`);r=!0;let o=t.next();if(!y.equals(o.type,y.map))throw new Error(`${K} entries() requires map content, got ${o.type.name}`);let i=[];for(let s of Dp(o,t,e))i.push(s);return i},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function Dt(t,e){if(t.done())return Rt;let r=t.next();if(y.equals(r.type,y.break))return Sr;if(r.type.terminal)return r.value;if(y.equals(r.type,y.array))return Cp(r,t,e);if(y.equals(r.type,y.map))return Rp(r,t,e);if(y.equals(r.type,y.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=Lp(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${K} tag decoder must call decode() or entries()`);return o}throw new Error(`${K} tag not supported (${r.value})`)}throw new Error("unsupported")}function Bf(t,e){if(!(t instanceof Uint8Array))throw new Error(`${K} data to decode must be a Uint8Array`);e=Object.assign({},_p,e);let r=fn(t),n=e.tokenizer||new Co(r,e),o=Dt(n,e);if(o===Rt)throw new Error(`${K} did not find any content to decode`);if(o===Sr)throw new Error(`${K} got unexpected break`);return[o,t.subarray(n.pos())]}function js(t,e){let[r,n]=Bf(t,e);if(n.length>0)throw new Error(`${K} too many terminals, data makes no sense`);return r}var Ro=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(Ro.prototype,Symbol.toStringTag,{value:"Tagged"});var Fp=Yt("ipns:utils"),_f=$("/ipns/"),Np=114,kp=0,Op=18;function Cf(t){let e;if(t.pubKey!=null)try{e=yu(t.pubKey)}catch(r){throw Fp.error(r),r}if(e!=null)return e}function Rf(t,e,r){let n=$(e);return yt([t,r,n])}function Lo(t){let e=$("ipns-signature:");return yt([e,t])}function bn(t){return"signatureV1"in t?pe.encode({value:$(t.value),signatureV1:t.signatureV1,validityType:t.validityType,validity:$(t.validity),sequence:t.sequence,ttl:t.ttl,pubKey:t.pubKey,signatureV2:t.signatureV2,data:t.data}):pe.encode({pubKey:t.pubKey,signatureV2:t.signatureV2,data:t.data})}function De(t){let e=pe.decode(t);if(e.sequence!=null&&(e.sequence=BigInt(e.sequence)),e.ttl!=null&&(e.ttl=BigInt(e.ttl)),e.signatureV2==null||e.data==null)throw new He("Missing data or signatureV2");let r=Uf(e.data),n=Pp(r.Value),o=Z(r.Validity);if(e.value!=null&&e.signatureV1!=null)return Kp(e),{value:n,validityType:pe.ValidityType.EOL,validity:o,sequence:r.Sequence,ttl:r.TTL,pubKey:e.pubKey,signatureV1:e.signatureV1,signatureV2:e.signatureV2,data:e.data};if(e.signatureV2!=null)return{value:n,validityType:pe.ValidityType.EOL,validity:o,sequence:r.Sequence,ttl:r.TTL,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}function Lt(t){return yt([_f,t.bytes])}function Df(t){let e=nr(t.slice(_f.length));if(!Do(e,kp)&&!Do(e,Op))throw new _n("Multihash in IPNS key was not identity or sha2-256");return e}function Lf(t,e,r,n,o){let i;if(e===pe.ValidityType.EOL)i=0;else throw new Zt("The validity type is unsupported");return zs({Value:t,Validity:r,ValidityType:i,Sequence:n,TTL:o})}function Uf(t){let e=js(t);if(e.ValidityType===0)e.ValidityType=pe.ValidityType.EOL;else throw new Zt("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 Pp(t){let e=Z(t).trim();if(e.startsWith("/"))return e;try{return`/ipfs/${ie.decode(t).toV1().toString()}`}catch{}try{return`/ipfs/${ie.parse(e).toV1().toString()}`}catch{}throw new an("Value must be a valid content path starting with /")}function Ff(t){if(t!=null){let e=qp(t);if(e!=null)return e.code===Np?`/ipns/${e.toString(Ne)}`:`/ipfs/${e.toV1().toString()}`;if(Mp(t))return`/ipns/${Ne.encode(t.bytes)}`;let r=t.toString().trim();if(r.startsWith("/")&&r.length>1)return r}throw new an("Value must be a valid content path starting with /")}function Kp(t){if(t.data==null)throw new yo("Record data is missing");let e=Uf(t.data);if(!ne(e.Value,t.value??new Uint8Array(0)))throw new He('Field "value" did not match between protobuf and CBOR');if(!ne(e.Validity,t.validity??new Uint8Array(0)))throw new He('Field "validity" did not match between protobuf and CBOR');if(e.ValidityType!==t.validityType)throw new He('Field "validityType" did not match between protobuf and CBOR');if(e.Sequence!==t.sequence)throw new He('Field "sequence" did not match between protobuf and CBOR');if(e.TTL!==t.ttl)throw new He('Field "ttl" did not match between protobuf and CBOR')}function Mp(t){return t.bytes instanceof Uint8Array}function Vp(t){return typeof t?.toCID=="function"}function qp(t){if(Vp(t))return t.toCID();try{return ie.parse(t)}catch{}return ie.asCID(t)}function Do(t,e){return t.code===e}var Uo=Yt("ipns:validator"),$p=1024*10;async function Hp(t,e){let r=De(e),n;try{let o=Lo(r.data);n=await t.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw Uo.error("record signature verification failed"),new He("Record signature verification failed");if(r.validityType===pe.ValidityType.EOL){if(Nf.default.fromString(r.validity).toDate().getTime()<Date.now())throw Uo.error("record has expired"),new po("record has expired")}else if(r.validityType!=null)throw Uo.error("the validity type is unsupported"),new Zt("The validity type is unsupported");Uo("ipns record for %s is valid",r.value)}async function xn(t,e){if(e.byteLength>$p)throw new mo("The record is too large");let r=Df(t),n;Do(r,0)&&(n=gu(r));let o=De(e),i=Cf(o)??n;if(i==null)throw new cn("Could not extract public key from IPNS record or routing key");let s=Lt(i.toMultihash());if(!ne(s,t))throw new cn("Embedded public key did not match routing key");await Hp(i,e)}var kf=ei(lo(),1);var zp=Yt("ipns"),Of=300*1e9,jp="/ipns/",gw=jp.length,Pf={v1Compatible:!0,ttlNs:Of};async function Fo(t,e,r,n,o=Pf){let i=new kf.default(Date.now()+Number(n)),s=pe.ValidityType.EOL,a=BigInt(o.ttlNs??Of);return Yp(t,e,r,s,i.toString(),a,o)}var Yp=async(t,e,r,n,o,i,s=Pf)=>{r=BigInt(r);let a=$(o),c=Ff(e),u=$(c),f=Lf(u,n,a,r,i),l=Lo(f),p=await t.sign(l),m;if(t.type==="RSA"&&(m=gt(t.publicKey)),s.v1Compatible===!0){let S=await Zp(t,u,n,a),v={value:c,signatureV1:S,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:p,data:f};return m!=null&&(v.pubKey=m),v}else{let S={value:c,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:p,data:f};return m!=null&&(S.pubKey=m),S}},Zp=async(t,e,r,n)=>{try{let o=Rf(e,r,n);return await t.sign(o)}catch(o){throw zp.error("record signature creation failed",o),new ho("Record signature creation failed")}};var Ys=ei(lo(),1);function No(t,e){let r=e.map((n,o)=>({record:De(n),index:o}));return r.sort((n,o)=>{let i=n.record.sequence,s=o.record.sequence;if(i>s)return-1;if(i<s)return 1;if(n.record.validityType===pe.ValidityType.EOL&&o.record.validityType===pe.ValidityType.EOL){let a=Ys.default.fromString(n.record.validity).toDate(),c=Ys.default.fromString(o.record.validity).toDate();if(a.getTime()>c.getTime())return-1;if(a.getTime()<c.getTime())return 1}return 0}),r[0].index}var vr=BigInt(6e4)*5000000n,Kf=5;var ko=class extends Error{static name="RecordsFailedValidationError";constructor(e="Records failed validation"){super(e),this.name="RecordsFailedValidationError"}},Oo=class extends Error{static name="UnsupportedMultibasePrefixError";constructor(e="Unsupported multibase prefix"){super(e),this.name="UnsupportedMultibasePrefixError"}},Po=class extends Error{static name="UnsupportedMultihashCodecError";constructor(e="Unsupported multihash codec"){super(e),this.name="UnsupportedMultihashCodecError"}},Ko=class extends Error{static name="InvalidValueError";constructor(e="Invalid value"){super(e),this.name="InvalidValueError"}};var wn=class extends Error{static name="RecordNotFoundError";name="RecordNotFoundError"};var ht="/",Mf=new TextEncoder().encode(ht),Mo=Mf[0],Ar=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=$(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Mo)throw new Error("Invalid key")}toString(e="utf8"){return Z(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(ht))}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=Mf),this._buf[0]!==Mo){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Mo,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Mo;)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(ht).slice(1)}type(){return Gp(this.baseNamespace())}name(){return Xp(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(ht)||(e+=ht),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(ht):new t(e.slice(0,-1).join(ht))}child(e){return this.toString()===ht?e:e.toString()===ht?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(),...Wp(e.map(r=>r.namespaces()))])}};function Gp(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function Xp(t){let e=t.split(":");return e[e.length-1]}function Wp(t){return[].concat(...t)}var Qp=114,Zs=0,Gs=18;function Xs(t,e){return t.code===e}var Vo="/dht/record/",e0="/ipns/metadata/";function En(t){return new Ar(Vo+Z(t,"base32"),!1)}function qo(t){return new Ar(e0+Z(t,"base32"),!1)}function Vf(t,e){let r=Date.now(),n=e.getTime()+1728e5,o=new Date(t.validity).getTime();return n-r<864e5||o-r<864e5}function t0(t){return t?.asCID===t}function qf(t){if(!t0(t))return!1;if(t.code!==Qp)throw new Q(`CID codec ${t.code} was not libp2p-key`);if(t.multihash.code!==Zs&&t.multihash.code!==Gs)throw new Q(`Multihash algorithm codec ${t.multihash.code} was not Identity or SHA256 hash`);return!0}var $f={[Ne.prefix]:Ne,[X.prefix]:X},Tr=class{routers;localStore;log;constructor(e,r){this.log=e.logger.forComponent("helia:ipns"),this.localStore=r.localStore,this.routers=r.routers}async resolve(e,r={}){let n=ia(e)||Cn(e)?e.toMultihash():qf(e)?e.multihash:e,o=Lt(n),i=await this.#t(o,r);return{...await this.#e(i.value,r),record:i}}async#e(e,r={}){let n=e.split("/");try{let o=n[1];if(o==="ipns"){let i=n[2],s=i.substring(0,1),a;if(s==="1"||s==="Q")a=X.decode(`z${i}`);else if($f[s]!=null)a=$f[s].decode(i);else throw new Oo(`Unsupported multibase prefix "${s}"`);let c;try{c=nr(a)}catch{c=ie.decode(a).multihash}if(!Xs(c,Zs)&&!Xs(c,Gs))throw new Po(`Unsupported multihash codec "${c.code}"`);let{cid:u}=await this.resolve(c,r),f=n.slice(3).join("/");return{cid:u,path:f===""?void 0:f}}else if(o==="ipfs"){let i=ie.parse(n[2]),s=n.slice(3).join("/");return{cid:i,path:s===""?void 0:s}}}catch(o){this.log.error("error parsing ipfs path - %e",o)}throw this.log.error("invalid ipfs path %s",e),new Ko("Invalid value")}async#t(e,r={}){let n=[];if(await this.localStore.has(e,r))if(this.log("record is present in the cache"),r.nocache!==!0)try{let{record:c,created:u}=await this.localStore.get(e,r);this.log("record retrieved from cache"),await xn(e,c),this.log("record was valid");let f=De(c),l=Number((f.ttl??vr)/1000000n);if(u.getTime()+l>Date.now())return this.log("record TTL was valid"),f;if(r.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),f;this.log("record TTL has been reached, searching routing for updates"),n.push(c)}catch(c){this.log("cached record was invalid - %e",c),await this.localStore.delete(e,r)}else this.log("ignoring local cache due to nocache=true option");if(r.offline===!0)throw new wn("Record was not present in the cache or has expired");this.log("did not have record locally");let i=0,s=[];if(await Promise.all(this.routers.map(async c=>{let u;try{u=await c.get(e,{...r,validate:!1})}catch(f){this.log.error("error finding IPNS record using router %s - %e",c.toString(),f),s.push(f);return}try{await xn(e,u),n.push(u)}catch(f){i++,this.log.error("error validating IPNS record from router %s - %e",c.toString(),f)}})),n.length===0)throw i>0?new ko(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`):new wn("Could not find record for routing key");let a=n[No(e,n)];return await this.localStore.put(e,a,r),De(a)}};var ve=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};var $o=class{routers;localStore;keychain;constructor(e,r){this.keychain=e.libp2p.services.keychain,this.localStore=r.localStore,this.routers=r.routers}async publish(e,r,n={}){try{let o=await this.#e(e),i=1n,s=Lt(o.publicKey.toMultihash());if(await this.localStore.has(s,n)){let{record:l}=await this.localStore.get(s,n);i=De(l).sequence+1n}Cn(r)&&(r=r.toCID());let a=n.ttl!=null?BigInt(n.ttl)*1000000n:vr,c=n.lifetime??1728e5,u=await Fo(o,r,i,c,{...n,ttlNs:a}),f=bn(u);return n.offline===!0?await this.localStore.put(s,f,{...n,metadata:{keyName:e,lifetime:c}}):await Promise.all(this.routers.map(async l=>{await l.put(s,f,{...n,metadata:{keyName:e,lifetime:c}})})),{record:u,publicKey:o.publicKey}}catch(o){throw n.onProgress?.(new ve("ipns:publish:error",o)),o}}async#e(e){try{return await this.keychain.exportKey(e)}catch{let n=await mu("Ed25519");return await this.keychain.importKey(e,n),n}}async unpublish(e,r){let{publicKey:n}=await this.keychain.exportKey(e),o=n.toMultihash(),i=Lt(o);await this.localStore.delete(i,r)}};function Ir(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Ho=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}},Br=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Ho(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 Ho(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 Ws=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Hf(t={}){return n0(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 n0(t,e){e=e??{};let r=e.onEnd,n=new Br,o,i,s,a=Ir(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((h,w)=>{i=T=>{i=null,n.push(T);try{h(t(n))}catch(B){w(B)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ir()})}},u=h=>i!=null?i(h):(n.push(h),o),f=h=>(n=new Br,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})},p=h=>s?o:(s=!0,h!=null?f(h):u({done:!0})),m=()=>(n=new Br,p(),{done:!0}),S=h=>(p(h),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:m,throw:S,push:l,end:p,get readableLength(){return n.size},onEmpty:async h=>{let w=h?.signal;if(w?.throwIfAborted(),n.isEmpty())return;let T,B;w!=null&&(T=new Promise((O,F)=>{B=()=>{F(new Ws)},w.addEventListener("abort",B)}));try{await Promise.race([a.promise,T])}finally{B!=null&&w!=null&&w?.removeEventListener("abort",B)}}},r==null)return o;let v=o;return o={[Symbol.asyncIterator](){return this},next(){return v.next()},throw(h){return v.throw(h),r!=null&&(r(h),r=void 0),{done:!0}},return(){return v.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(h){return v.end(h),r!=null&&(r(h),r=void 0),o},get readableLength(){return v.readableLength},onEmpty:h=>v.onEmpty(h)},o}var Js=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},zf=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Qs(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,c,f=new Promise((l,p)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){p(zf(s));return}if(s&&(c=()=>{p(zf(s))},s.addEventListener("abort",c,{once:!0})),t.then(l,p),r===Number.POSITIVE_INFINITY)return;let m=new Js;a=i.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(S){p(S)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?l():o instanceof Error?p(o):(m.message=o??`Promise timed out after ${r} milliseconds`,p(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 o0=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 i0(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}=o0(t),l=async(...m)=>{let S=r.multiArgs?m:m[0];if(r.filter)try{if(!await r.filter(S))return}catch(v){n(),s(v);return}c.push(S),r.count===c.length&&(n(),i(c))},p=(...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,p)};for(let m of a)u(m,l);for(let m of r.rejectionEvents)a.includes(m)||u(m,p);r.signal&&r.signal.addEventListener("abort",()=>{p(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(o.cancel=n,typeof r.timeout=="number"){let i=Qs(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function zo(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=i0(t,e,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function Sn(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 jo=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function s0(t){return t.reason}async function jf(t,e,r){if(e==null)return t;let n=r?.translateError??s0;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 Yo=class{deferred;signal;constructor(e){this.signal=e,this.deferred=Ir(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new ot)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function a0(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Zo=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=a0(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,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 ot),this.cleanup())}async join(e={}){let r=new Yo(e.signal);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 jf(this.fn({...this.options??{},signal:this.controller.signal}),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 Go=class extends Rn{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=Sn(this.emitEmpty.bind(this),1),this.emitIdle=Sn(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 jo;let n=new Zo(e,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("completed",{detail:o}),this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new ot)}),this.clear()}async onEmpty(e){this.size!==0&&await zo(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await zo(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await zo(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=Hf({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 ot("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 Yf(t){let e=new globalThis.AbortController;function r(){let i=t.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();e.abort(i);for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let i of t){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=e.signal;return o.clear=n,o}function Zf(t,e,r){let n,o,i=!1;function s(){let u={signal:o.signal},f;r?.timeout!=null&&(f=Yf([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=Sn(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 Xo=class{routers;localStore;republishTask;log;keychain;started=!1;republishConcurrency;constructor(e,r){this.log=e.logger.forComponent("helia:ipns"),this.localStore=r.localStore,this.keychain=e.libp2p.services.keychain,this.republishConcurrency=r.republishConcurrency||Kf,this.started=e.libp2p.status==="started",this.routers=r.routers??[],this.republishTask=Zf(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 Go({concurrency:this.republishConcurrency});try{let n=[];for await(let{routingKey:o,record:i,metadata:s,created:a}of this.localStore.list(e)){if(s==null){this.log(`no metadata found for record ${o.toString()}, skipping`);continue}let c;try{c=De(i)}catch(p){this.log.error("error unmarshaling record - %e",p);continue}if(!Vf(c,a)){this.log.trace(`skipping record ${o.toString()}within republish threshold`);continue}let u=c.sequence+1n,f=c.ttl??vr,l;try{l=await this.keychain.exportKey(s.keyName)}catch(p){this.log.error("missing key %s, skipping republishing record - %e",s.keyName,p);continue}try{let p=await Fo(l,c.value,u,s.lifetime,{...e,ttlNs:f});n.push({routingKey:o,record:p})}catch(p){this.log.error("error creating updated IPNS record for %s - %e",o,p);continue}}this.log(`found ${n.length} records to republish`);for(let{routingKey:o,record:i}of n)r.add(async()=>{try{let s=bn(i);await Promise.all(this.routers.map(a=>a.put(o,s,e)))}catch(s){this.log.error("error republishing record - %e",s)}},e)}catch(n){this.log.error("error during republish - %e",n)}await r.onIdle(e)}};var vn;(function(t){let e;t.codec=()=>(e==null&&(e=Qe((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:Le(0),value:Le(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 We(i,t.codec())}t.encode=r;function n(i,s){return Xe(i,t.codec(),s)}t.decode=n;function o(i,s){return Je(i,t.codec(),s)}t.stream=o})(vn||(vn={}));function Gf(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 Xf(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 Ut=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 vn.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:Gf(this.timeReceived)}}static deserialize(e){let r=vn.decode(e);return new t(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(e){let r=Xf(e.timeReceived);if(e.key==null)throw new Error("key missing from deserialized object");if(e.value==null)throw new Error("value missing from deserialized object");return new t(e.key,e.value,r)}};var Wf;(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"})(Wf||(Wf={}));var An;(function(t){let e;t.codec=()=>(e==null&&(e=Qe((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 We(i,t.codec())}t.encode=r;function n(i,s){return Xe(i,t.codec(),s)}t.decode=n;function o(i,s){return Je(i,t.codec(),s)}t.stream=o})(An||(An={}));function Wo(t,e){return{async put(r,n,o={}){try{let i=En(r);try{let c=await t.get(i),u=Ut.deserialize(c);if(ne(u.value,n))return}catch(c){if(c.name!=="NotFoundError")throw c}let s=new Ut(r,n,new Date);o.onProgress?.(new ve("ipns:routing:datastore:put"));let a=t.batch();a.put(i,s.serialize()),o.metadata!=null&&a.put(qo(r),An.encode(o.metadata)),await a.commit(o)}catch(i){throw o.onProgress?.(new ve("ipns:routing:datastore:error",i)),i}},async get(r,n={}){try{let o=En(r);n.onProgress?.(new ve("ipns:routing:datastore:get"));let i=await t.get(o,n),s=Ut.deserialize(i);return{record:s.value,created:s.timeReceived}}catch(o){throw n.onProgress?.(new ve("ipns:routing:datastore:error",o)),o}},async has(r,n={}){let o=En(r);return t.has(o,n)},async delete(r,n){let o=En(r),i=t.batch();i.delete(o),i.delete(qo(r)),await i.commit(n)},async*list(r={}){try{r.onProgress?.(new ve("ipns:routing:datastore:list"));for await(let{key:n,value:o}of t.query({prefix:Vo},r))try{let i=Ut.deserialize(o),a=n.toString().substring(Vo.length),c=$(a,"base32"),u=qo(c),f;try{let l=await t.get(u,r);f=An.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 ve("ipns:routing:datastore:error",n)),n}}}}var ea=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 ve("ipns:routing:helia:error",o)),o}}async get(e,r={}){try{return await this.routing.get(e,r)}catch(n){throw r.onProgress?.(new ve("ipns:routing:helia:error",n)),n}}toString(){return"HeliaRouting()"}};function Tn(t){return new ea(t)}var ta=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 ta(t)}var Qo=class{routers;publisher;republisher;resolver;localStore;started;constructor(e,r={}){this.localStore=Wo(e.datastore,e.logger.forComponent("helia:ipns:local-store")),this.started=e.libp2p.status==="started",this.routers=[Jo(this.localStore),Tn(e.routing),...r.routers??[]],this.publisher=new $o(e,{...r,routers:this.routers,localStore:this.localStore}),this.republisher=new Xo(e,{...r,routers:this.routers,localStore:this.localStore}),this.resolver=new Tr(e,{...r,routers:this.routers,localStore:this.localStore}),e.events.addEventListener("start",this.start.bind(this)),e.events.addEventListener("stop",this.stop.bind(this)),this.started&&this.republisher.start()}start(){this.started||(this.started=!0,this.republisher.start())}stop(){this.started&&(this.started=!1,this.republisher.stop())}async publish(e,r,n={}){return this.publisher.publish(e,r,n)}async resolve(e,r={}){return this.resolver.resolve(e,r)}async unpublish(e,r){return this.publisher.unpublish(e,r)}};function f0(t,e={}){return new Qo(t,e)}function l0(t,e={}){let r=Wo(t.datastore,t.logger.forComponent("helia:ipns:local-store")),n=[Jo(r),Tn(t.routing),...e.routers??[]];return new Tr(t,{routers:n,localStore:r})}return ol(d0);})();
13
+ ${e}[Error list was empty]`,r.trim()}return xu(t,e)}Se.formatters.e=t=>t==null?"undefined":Eu(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}function Yt(t,e){let r=Xh(`${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=>Yt(`${t}:${n}`,e)})}function wu(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var Nf=ei(lo(),1);var ho=class extends Error{static name="SignatureCreationError";constructor(e="Record signature creation failed"){super(e),this.name="SignatureCreationError"}},He=class extends Error{static name="SignatureVerificationError";constructor(e="Record signature verification failed"){super(e),this.name="SignatureVerificationError"}},po=class extends Error{static name="RecordExpiredError";constructor(e="Record has expired"){super(e),this.name="RecordExpiredError"}},Zt=class extends Error{static name="UnsupportedValidityError";constructor(e="The validity type is unsupported"){super(e),this.name="UnsupportedValidityError"}},mo=class extends Error{static name="RecordTooLargeError";constructor(e="The record is too large"){super(e),this.name="RecordTooLargeError"}},an=class extends Error{static name="InvalidValueError";constructor(e="Value must be a valid content path starting with /"){super(e),this.name="InvalidValueError"}},yo=class extends Error{static name="InvalidRecordDataError";constructor(e="Invalid record data"){super(e),this.name="InvalidRecordDataError"}},cn=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(e="Invalid embedded public key"){super(e),this.name="InvalidEmbeddedPublicKeyError"}};var pe;(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=()=>rn(r)})(e=t.ValidityType||(t.ValidityType={}));let n;t.codec=()=>(n==null&&(n=Qe((a,c,u={})=>{u.lengthDelimited!==!1&&c.fork(),a.value!=null&&(c.uint32(10),c.bytes(a.value)),a.signatureV1!=null&&(c.uint32(18),c.bytes(a.signatureV1)),a.validityType!=null&&(c.uint32(24),t.ValidityType.codec().encode(a.validityType,c)),a.validity!=null&&(c.uint32(34),c.bytes(a.validity)),a.sequence!=null&&(c.uint32(40),c.uint64(a.sequence)),a.ttl!=null&&(c.uint32(48),c.uint64(a.ttl)),a.pubKey!=null&&(c.uint32(58),c.bytes(a.pubKey)),a.signatureV2!=null&&(c.uint32(66),c.bytes(a.signatureV2)),a.data!=null&&(c.uint32(74),c.bytes(a.data)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let p=a.uint32();switch(p>>>3){case 1:{f.value=a.bytes();break}case 2:{f.signatureV1=a.bytes();break}case 3:{f.validityType=t.ValidityType.codec().decode(a);break}case 4:{f.validity=a.bytes();break}case 5:{f.sequence=a.uint64();break}case 6:{f.ttl=a.uint64();break}case 7:{f.pubKey=a.bytes();break}case 8:{f.signatureV2=a.bytes();break}case 9:{f.data=a.bytes();break}default:{a.skipType(p&7);break}}}return f},function*(a,c,u,f={}){let l=c==null?a.len:a.pos+c;for(;a.pos<l;){let p=a.uint32();switch(p>>>3){case 1:{yield{field:`${u}.value`,value:a.bytes()};break}case 2:{yield{field:`${u}.signatureV1`,value:a.bytes()};break}case 3:{yield{field:`${u}.validityType`,value:t.ValidityType.codec().decode(a)};break}case 4:{yield{field:`${u}.validity`,value:a.bytes()};break}case 5:{yield{field:`${u}.sequence`,value:a.uint64()};break}case 6:{yield{field:`${u}.ttl`,value:a.uint64()};break}case 7:{yield{field:`${u}.pubKey`,value:a.bytes()};break}case 8:{yield{field:`${u}.signatureV2`,value:a.bytes()};break}case 9:{yield{field:`${u}.data`,value:a.bytes()};break}default:{a.skipType(p&7);break}}}})),n);function o(a){return We(a,t.codec())}t.encode=o;function i(a,c){return Xe(a,t.codec(),c)}t.decode=i;function s(a,c){return Je(a,t.codec(),c)}t.stream=s})(pe||(pe={}));var Wh=["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 Ns(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=Jh(t);return r||"Object"}function Jh(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Wh.includes(e))return e}var y=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}};y.uint=new y(0,"uint",!0);y.negint=new y(1,"negint",!0);y.bytes=new y(2,"bytes",!0);y.string=new y(3,"string",!0);y.array=new y(4,"array",!1);y.map=new y(5,"map",!1);y.tag=new y(6,"tag",!1);y.float=new y(7,"float",!0);y.false=new y(7,"false",!0);y.true=new y(7,"true",!0);y.null=new y(7,"null",!0);y.undefined=new y(7,"undefined",!0);y.break=new y(7,"break",!0);var U=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 un=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Qh=new TextEncoder;function go(t){return un&&globalThis.Buffer.isBuffer(t)}function fn(t){return t instanceof Uint8Array?go(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var ep=24,tp=200,bo=un?t=>t.length>=ep?globalThis.Buffer.from(t):Su(t):t=>t.length>=tp?Qh.encode(t):Su(t),rt=t=>Uint8Array.from(t),vu=un?(t,e,r)=>go(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),Au=un?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),fn(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},Tu=un?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function xo(t,e){if(go(t)&&go(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 Su(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 rp=256,ln=class{constructor(e=rp){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=Tu(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=vu(n,0,this.cursor)}else r=Au(this.chunks,this.cursor);return e&&this.reset(),r}},wo=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var K="CBOR decode error:",Eo="CBOR encode error:",dn=[];dn[23]=1;dn[24]=2;dn[25]=3;dn[26]=5;dn[27]=9;function dt(t,e,r){if(t.length-e<r)throw new Error(`${K} not enough data for type`)}var le=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Be(t,e,r){dt(t,e,1);let n=t[e];if(r.strict===!0&&n<le[0])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function _e(t,e,r){dt(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<le[1])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Ce(t,e,r){dt(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(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Re(t,e,r){dt(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(`${K} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${K} integers outside of the safe integer range are not supported`)}function Iu(t,e,r,n){return new U(y.uint,Be(t,e+1,n),2)}function Bu(t,e,r,n){return new U(y.uint,_e(t,e+1,n),3)}function _u(t,e,r,n){return new U(y.uint,Ce(t,e+1,n),5)}function Cu(t,e,r,n){return new U(y.uint,Re(t,e+1,n),9)}function Ue(t,e){return G(t,0,e.value)}function G(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(`${K} encountered BigInt larger than allowable range`)}}Ue.encodedSize=function(e){return G.encodedSize(e.value)};G.encodedSize=function(e){return e<le[0]?1:e<le[1]?2:e<le[2]?3:e<le[3]?5:9};Ue.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Ru(t,e,r,n){return new U(y.negint,-1-Be(t,e+1,n),2)}function Du(t,e,r,n){return new U(y.negint,-1-_e(t,e+1,n),3)}function Lu(t,e,r,n){return new U(y.negint,-1-Ce(t,e+1,n),5)}var ks=BigInt(-1),Uu=BigInt(1);function Fu(t,e,r,n){let o=Re(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new U(y.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${K} integers outside of the safe integer range are not supported`);return new U(y.negint,ks-BigInt(o),9)}function So(t,e){let r=e.value,n=typeof r=="bigint"?r*ks-Uu:r*-1-1;G(t,e.type.majorEncoded,n)}So.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*ks-Uu:r*-1-1;return n<le[0]?1:n<le[1]?2:n<le[2]?3:n<le[3]?5:9};So.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function hn(t,e,r,n){dt(t,e,r+n);let o=t.slice(e+r,e+r+n);return new U(y.bytes,o,r+n)}function Nu(t,e,r,n){return hn(t,e,1,r)}function ku(t,e,r,n){return hn(t,e,2,Be(t,e+1,n))}function Ou(t,e,r,n){return hn(t,e,3,_e(t,e+1,n))}function Pu(t,e,r,n){return hn(t,e,5,Ce(t,e+1,n))}function Ku(t,e,r,n){let o=Re(t,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer bytes lengths not supported`);return hn(t,e,9,o)}function vo(t){return t.encodedBytes===void 0&&(t.encodedBytes=y.equals(t.type,y.string)?bo(t.value):t.value),t.encodedBytes}function gr(t,e){let r=vo(e);G(t,e.type.majorEncoded,r.length),t.push(r)}gr.encodedSize=function(e){let r=vo(e);return G.encodedSize(r.length)+r.length};gr.compareTokens=function(e,r){return op(vo(e),vo(r))};function op(t,e){return t.length<e.length?-1:t.length>e.length?1:xo(t,e)}var Mu=new TextDecoder,sp=32;function ap(t,e,r){if(r-e<sp){let o="";for(let i=e;i<r;i++){let s=t[i];if(s&128)return Mu.decode(t.subarray(e,r));o+=String.fromCharCode(s)}return o}return Mu.decode(t.subarray(e,r))}function pn(t,e,r,n,o){let i=r+n;dt(t,e,i);let s=new U(y.string,ap(t,e+r,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+i)),s}function Vu(t,e,r,n){return pn(t,e,1,r,n)}function qu(t,e,r,n){return pn(t,e,2,Be(t,e+1,n),n)}function $u(t,e,r,n){return pn(t,e,3,_e(t,e+1,n),n)}function Hu(t,e,r,n){return pn(t,e,5,Ce(t,e+1,n),n)}function zu(t,e,r,n){let o=Re(t,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer string lengths not supported`);return pn(t,e,9,o,n)}var ju=gr;function br(t,e,r,n){return new U(y.array,n,r)}function Yu(t,e,r,n){return br(t,e,1,r)}function Zu(t,e,r,n){return br(t,e,2,Be(t,e+1,n))}function Gu(t,e,r,n){return br(t,e,3,_e(t,e+1,n))}function Xu(t,e,r,n){return br(t,e,5,Ce(t,e+1,n))}function Wu(t,e,r,n){let o=Re(t,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer array lengths not supported`);return br(t,e,9,o)}function Ju(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return br(t,e,1,1/0)}function Ao(t,e){G(t,y.array.majorEncoded,e.value)}Ao.compareTokens=Ue.compareTokens;Ao.encodedSize=function(e){return G.encodedSize(e.value)};function xr(t,e,r,n){return new U(y.map,n,r)}function Qu(t,e,r,n){return xr(t,e,1,r)}function ef(t,e,r,n){return xr(t,e,2,Be(t,e+1,n))}function tf(t,e,r,n){return xr(t,e,3,_e(t,e+1,n))}function rf(t,e,r,n){return xr(t,e,5,Ce(t,e+1,n))}function nf(t,e,r,n){let o=Re(t,e+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer map lengths not supported`);return xr(t,e,9,o)}function of(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return xr(t,e,1,1/0)}function To(t,e){G(t,y.map.majorEncoded,e.value)}To.compareTokens=Ue.compareTokens;To.encodedSize=function(e){return G.encodedSize(e.value)};function sf(t,e,r,n){return new U(y.tag,r,1)}function af(t,e,r,n){return new U(y.tag,Be(t,e+1,n),2)}function cf(t,e,r,n){return new U(y.tag,_e(t,e+1,n),3)}function uf(t,e,r,n){return new U(y.tag,Ce(t,e+1,n),5)}function ff(t,e,r,n){return new U(y.tag,Re(t,e+1,n),9)}function Io(t,e){G(t,y.tag.majorEncoded,e.value)}Io.compareTokens=Ue.compareTokens;Io.encodedSize=function(e){return G.encodedSize(e.value)};var Os=20,Ps=21,Ks=22,Ms=23;function lf(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${K} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new U(y.null,null,1):new U(y.undefined,void 0,1)}function df(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return new U(y.break,void 0,1)}function Vs(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${K} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${K} Infinity values are not supported`)}return new U(y.float,t,e)}function hf(t,e,r,n){return Vs(qs(t,e+1),3,n)}function pf(t,e,r,n){return Vs($s(t,e+1),5,n)}function mf(t,e,r,n){return Vs(xf(t,e+1),9,n)}function mn(t,e,r){let n=e.value;if(n===!1)t.push([y.float.majorEncoded|Os]);else if(n===!0)t.push([y.float.majorEncoded|Ps]);else if(n===null)t.push([y.float.majorEncoded|Ks]);else if(n===void 0)t.push([y.float.majorEncoded|Ms]);else{let o,i=!1;(!r||r.float64!==!0)&&(gf(n),o=qs(ze,1),n===o||Number.isNaN(n)?(ze[0]=249,t.push(ze.slice(0,3)),i=!0):(bf(n),o=$s(ze,1),n===o&&(ze[0]=250,t.push(ze.slice(0,5)),i=!0))),i||(dp(n),o=xf(ze,1),ze[0]=251,t.push(ze.slice(0,9)))}}mn.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){gf(n);let o=qs(ze,1);if(n===o||Number.isNaN(n))return 3;if(bf(n),o=$s(ze,1),n===o)return 5}return 9};var yf=new ArrayBuffer(9),Fe=new DataView(yf,1),ze=new Uint8Array(yf,0);function gf(t){if(t===1/0)Fe.setUint16(0,31744,!1);else if(t===-1/0)Fe.setUint16(0,64512,!1);else if(Number.isNaN(t))Fe.setUint16(0,32256,!1);else{Fe.setFloat32(0,t);let e=Fe.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)Fe.setUint16(0,31744,!1);else if(r===0)Fe.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Fe.setUint16(0,0):o<-14?Fe.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):Fe.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function qs(t,e){if(t.length-e<2)throw new Error(`${K} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function bf(t){Fe.setFloat32(0,t,!1)}function $s(t,e){if(t.length-e<4)throw new Error(`${K} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function dp(t){Fe.setFloat64(0,t,!1)}function xf(t,e){if(t.length-e<8)throw new Error(`${K} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}mn.compareTokens=Ue.compareTokens;function j(t,e,r){throw new Error(`${K} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function Bo(t){return()=>{throw new Error(`${K} ${t}`)}}var C=[];for(let t=0;t<=23;t++)C[t]=j;C[24]=Iu;C[25]=Bu;C[26]=_u;C[27]=Cu;C[28]=j;C[29]=j;C[30]=j;C[31]=j;for(let t=32;t<=55;t++)C[t]=j;C[56]=Ru;C[57]=Du;C[58]=Lu;C[59]=Fu;C[60]=j;C[61]=j;C[62]=j;C[63]=j;for(let t=64;t<=87;t++)C[t]=Nu;C[88]=ku;C[89]=Ou;C[90]=Pu;C[91]=Ku;C[92]=j;C[93]=j;C[94]=j;C[95]=Bo("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)C[t]=Vu;C[120]=qu;C[121]=$u;C[122]=Hu;C[123]=zu;C[124]=j;C[125]=j;C[126]=j;C[127]=Bo("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)C[t]=Yu;C[152]=Zu;C[153]=Gu;C[154]=Xu;C[155]=Wu;C[156]=j;C[157]=j;C[158]=j;C[159]=Ju;for(let t=160;t<=183;t++)C[t]=Qu;C[184]=ef;C[185]=tf;C[186]=rf;C[187]=nf;C[188]=j;C[189]=j;C[190]=j;C[191]=of;for(let t=192;t<=215;t++)C[t]=sf;C[216]=af;C[217]=cf;C[218]=uf;C[219]=ff;C[220]=j;C[221]=j;C[222]=j;C[223]=j;for(let t=224;t<=243;t++)C[t]=Bo("simple values are not supported");C[244]=j;C[245]=j;C[246]=j;C[247]=lf;C[248]=Bo("simple values are not supported");C[249]=hf;C[250]=pf;C[251]=mf;C[252]=j;C[253]=j;C[254]=j;C[255]=df;var je=[];for(let t=0;t<24;t++)je[t]=new U(y.uint,t,1);for(let t=-1;t>=-24;t--)je[31-t]=new U(y.negint,t,1);je[64]=new U(y.bytes,new Uint8Array(0),1);je[96]=new U(y.string,"",1);je[128]=new U(y.array,0,1);je[160]=new U(y.map,0,1);je[244]=new U(y.false,!1,1);je[245]=new U(y.true,!0,1);je[246]=new U(y.null,null,1);function Hs(t){switch(t.type){case y.false:return rt([244]);case y.true:return rt([245]);case y.null:return rt([246]);case y.bytes:return t.value.length?void 0:rt([64]);case y.string:return t.value===""?rt([96]):void 0;case y.array:return t.value===0?rt([128]):void 0;case y.map:return t.value===0?rt([160]):void 0;case y.uint:return t.value<24?rt([Number(t.value)]):void 0;case y.negint:if(t.value>=-24)return rt([31-Number(t.value)])}}var pp={float64:!1,mapSorter:gp,quickEncodeToken:Hs},Af=Object.freeze({float64:!0,mapSorter:bp,quickEncodeToken:Hs});function mp(){let t=[];return t[y.uint.major]=Ue,t[y.negint.major]=So,t[y.bytes.major]=gr,t[y.string.major]=ju,t[y.array.major]=Ao,t[y.map.major]=To,t[y.tag.major]=Io,t[y.float.major]=mn,t}var Er=mp(),_o=new ln,gn=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(`${Eo} object contains circular references`);return new t(r,e)}},Ct={null:new U(y.null,null),undefined:new U(y.undefined,void 0),true:new U(y.true,!0),false:new U(y.false,!1),emptyArray:new U(y.array,0),emptyMap:new U(y.map,0)},nt={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new U(y.float,t):t>=0?new U(y.uint,t):new U(y.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new U(y.uint,t):new U(y.negint,t)},Uint8Array(t,e,r,n){return new U(y.bytes,t)},string(t,e,r,n){return new U(y.string,t)},boolean(t,e,r,n){return t?Ct.true:Ct.false},null(t,e,r,n){return Ct.null},undefined(t,e,r,n){return Ct.undefined},ArrayBuffer(t,e,r,n){return new U(y.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new U(y.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Ct.emptyArray,new U(y.break)]:Ct.emptyArray;n=gn.createCheck(n,t);let o=[],i=0;for(let s of t)o[i++]=wr(s,r,n);return r.addBreakTokens?[new U(y.array,t.length),o,new U(y.break)]:[new U(y.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=gn.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++]=[wr(f,r,n),wr(l,r,n)])}u<s&&(a.length=u)}return a?.length?(yp(a,r),r.addBreakTokens?[new U(y.map,a.length),a,new U(y.break)]:[new U(y.map,a.length),a]):r.addBreakTokens===!0?[Ct.emptyMap,new U(y.break)]:Ct.emptyMap},Tagged(t,e,r,n){return[new U(y.tag,t.tag),wr(t.value,r,n)]}};nt.Map=nt.Object;nt.Buffer=nt.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))nt[`${t}Array`]=nt.DataView;function wr(t,e={},r){let n=Ns(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||nt[n];if(typeof o=="function"){let s=o(t,n,e,r);if(s!=null)return s}let i=nt[n];if(!i)throw new Error(`${Eo} unsupported type: ${n}`);return i(t,n,e,r)}function yp(t,e){e.mapSorter&&t.sort(e.mapSorter)}function gp(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=Er[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function bp(t,e){if(t[0]instanceof U&&e[0]instanceof U){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=wf(r.value)),n._keyBytes||(n._keyBytes=wf(n.value)),xo(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function wf(t){return If(t,Er,Af)}function yn(t,e,r,n){if(Array.isArray(e))for(let o of e)yn(t,o,r,n);else r[e.type.major](t,e,n)}var Ef=y.uint.majorEncoded,Sf=y.negint.majorEncoded,xp=y.bytes.majorEncoded,wp=y.string.majorEncoded,vf=y.array.majorEncoded,Ep=y.float.majorEncoded|Os,Sp=y.float.majorEncoded|Ps,vp=y.float.majorEncoded|Ks,Ap=y.float.majorEncoded|Ms,Tp=BigInt(-1),Ip=BigInt(1);function Bp(t){return t.addBreakTokens!==!0}function Tf(t,e,r,n){let o=Ns(e),i=r.typeEncoders&&r.typeEncoders[o];if(i){let s=i(e,o,r,n);if(s!=null){yn(t,s,Er,r);return}}switch(o){case"null":t.push([vp]);return;case"undefined":t.push([Ap]);return;case"boolean":t.push([e?Sp:Ep]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?mn(t,new U(y.float,e),r):e>=0?G(t,Ef,e):G(t,Sf,e*-1-1);return;case"bigint":e>=BigInt(0)?G(t,Ef,e):G(t,Sf,e*Tp-Ip);return;case"string":{let s=bo(e);G(t,wp,s.length),t.push(s);return}case"Uint8Array":G(t,xp,e.length),t.push(e);return;case"Array":if(!e.length){t.push([vf]);return}n=gn.createCheck(n,e),G(t,vf,e.length);for(let s of e)Tf(t,s,r,n);return;case"Object":case"Map":{let s=nt.Object(e,o,r,n);yn(t,s,Er,r)}return;default:{let s=nt[o];if(!s)throw new Error(`${Eo} unsupported type: ${o}`);let a=s(e,o,r,n);yn(t,a,Er,r)}}}function If(t,e,r,n){let o=n instanceof Uint8Array,i=o?new wo(n):_o,s=wr(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 ln(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():fn(i.chunks[0])}}return i.reset(),yn(i,s,e,r),i.toBytes(!0)}function zs(t,e){return e=Object.assign({},pp,e),Bp(e)?(_o.reset(),Tf(_o,t,e,void 0),_o.toBytes(!0)):If(t,Er,e)}var _p={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Co=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=je[e];if(r===void 0){let n=C[e];if(!n)throw new Error(`${K} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},Rt=Symbol.for("DONE"),Sr=Symbol.for("BREAK");function Cp(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=Dt(e,r);if(i===Sr){if(t.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed array`)}if(i===Rt)throw new Error(`${K} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function Rp(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=Dt(e,r);if(c===Sr){if(t.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed map`)}if(c===Rt)throw new Error(`${K} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${K} non-string keys not supported (got ${typeof c})`);if(o&&(n&&s.has(c)||!n&&Object.hasOwn(i,c)))throw new Error(`${K} found repeat map key "${c}"`);let u=Dt(e,r);if(u===Rt)throw new Error(`${K} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,u):i[c]=u}return n?s:i}function*Dp(t,e,r){for(let n=0;n<t.value;n++){let o=Dt(e,r);if(o===Sr){if(t.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed map`)}if(o===Rt)throw new Error(`${K} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let i=Dt(e,r);if(i===Rt)throw new Error(`${K} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[o,i]}}function Lp(t,e){let r=!1,n=function(){if(r)throw new Error(`${K} tag decode() may only be called once`);r=!0;let o=Dt(t,e);if(o===Rt)throw new Error(`${K} tag content missing`);if(o===Sr)throw new Error(`${K} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${K} tag decode() may only be called once`);r=!0;let o=t.next();if(!y.equals(o.type,y.map))throw new Error(`${K} entries() requires map content, got ${o.type.name}`);let i=[];for(let s of Dp(o,t,e))i.push(s);return i},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function Dt(t,e){if(t.done())return Rt;let r=t.next();if(y.equals(r.type,y.break))return Sr;if(r.type.terminal)return r.value;if(y.equals(r.type,y.array))return Cp(r,t,e);if(y.equals(r.type,y.map))return Rp(r,t,e);if(y.equals(r.type,y.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=Lp(t,e),o=e.tags[r.value](n);if(!n._called)throw new Error(`${K} tag decoder must call decode() or entries()`);return o}throw new Error(`${K} tag not supported (${r.value})`)}throw new Error("unsupported")}function Bf(t,e){if(!(t instanceof Uint8Array))throw new Error(`${K} data to decode must be a Uint8Array`);e=Object.assign({},_p,e);let r=fn(t),n=e.tokenizer||new Co(r,e),o=Dt(n,e);if(o===Rt)throw new Error(`${K} did not find any content to decode`);if(o===Sr)throw new Error(`${K} got unexpected break`);return[o,t.subarray(n.pos())]}function js(t,e){let[r,n]=Bf(t,e);if(n.length>0)throw new Error(`${K} too many terminals, data makes no sense`);return r}var Ro=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(Ro.prototype,Symbol.toStringTag,{value:"Tagged"});var Fp=Yt("ipns:utils"),_f=$("/ipns/"),Np=114,kp=0,Op=18;function Cf(t){let e;if(t.pubKey!=null)try{e=yu(t.pubKey)}catch(r){throw Fp.error(r),r}if(e!=null)return e}function Rf(t,e,r){let n=$(e);return yt([t,r,n])}function Lo(t){let e=$("ipns-signature:");return yt([e,t])}function bn(t){return"signatureV1"in t?pe.encode({value:$(t.value),signatureV1:t.signatureV1,validityType:t.validityType,validity:$(t.validity),sequence:t.sequence,ttl:t.ttl,pubKey:t.pubKey,signatureV2:t.signatureV2,data:t.data}):pe.encode({pubKey:t.pubKey,signatureV2:t.signatureV2,data:t.data})}function De(t){let e=pe.decode(t);if(e.sequence!=null&&(e.sequence=BigInt(e.sequence)),e.ttl!=null&&(e.ttl=BigInt(e.ttl)),e.signatureV2==null||e.data==null)throw new He("Missing data or signatureV2");let r=Uf(e.data),n=Pp(r.Value),o=Z(r.Validity);if(e.value!=null&&e.signatureV1!=null)return Kp(e),{value:n,validityType:pe.ValidityType.EOL,validity:o,sequence:r.Sequence,ttl:r.TTL,pubKey:e.pubKey,signatureV1:e.signatureV1,signatureV2:e.signatureV2,data:e.data};if(e.signatureV2!=null)return{value:n,validityType:pe.ValidityType.EOL,validity:o,sequence:r.Sequence,ttl:r.TTL,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}function Lt(t){return yt([_f,t.bytes])}function Df(t){let e=nr(t.slice(_f.length));if(!Do(e,kp)&&!Do(e,Op))throw new _n("Multihash in IPNS key was not identity or sha2-256");return e}function Lf(t,e,r,n,o){let i;if(e===pe.ValidityType.EOL)i=0;else throw new Zt("The validity type is unsupported");return zs({Value:t,Validity:r,ValidityType:i,Sequence:n,TTL:o})}function Uf(t){let e=js(t);if(e.ValidityType===0)e.ValidityType=pe.ValidityType.EOL;else throw new Zt("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 Pp(t){let e=Z(t).trim();if(e.startsWith("/"))return e;try{return`/ipfs/${ie.decode(t).toV1().toString()}`}catch{}try{return`/ipfs/${ie.parse(e).toV1().toString()}`}catch{}throw new an("Value must be a valid content path starting with /")}function Ff(t){if(t!=null){let e=qp(t);if(e!=null)return e.code===Np?`/ipns/${e.toString(Ne)}`:`/ipfs/${e.toV1().toString()}`;if(Mp(t))return`/ipns/${Ne.encode(t.bytes)}`;let r=t.toString().trim();if(r.startsWith("/")&&r.length>1)return r}throw new an("Value must be a valid content path starting with /")}function Kp(t){if(t.data==null)throw new yo("Record data is missing");let e=Uf(t.data);if(!ne(e.Value,t.value??new Uint8Array(0)))throw new He('Field "value" did not match between protobuf and CBOR');if(!ne(e.Validity,t.validity??new Uint8Array(0)))throw new He('Field "validity" did not match between protobuf and CBOR');if(e.ValidityType!==t.validityType)throw new He('Field "validityType" did not match between protobuf and CBOR');if(e.Sequence!==t.sequence)throw new He('Field "sequence" did not match between protobuf and CBOR');if(e.TTL!==t.ttl)throw new He('Field "ttl" did not match between protobuf and CBOR')}function Mp(t){return t.bytes instanceof Uint8Array}function Vp(t){return typeof t?.toCID=="function"}function qp(t){if(Vp(t))return t.toCID();try{return ie.parse(t)}catch{}return ie.asCID(t)}function Do(t,e){return t.code===e}var Uo=Yt("ipns:validator"),$p=1024*10;async function Hp(t,e){let r=De(e),n;try{let o=Lo(r.data);n=await t.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw Uo.error("record signature verification failed"),new He("Record signature verification failed");if(r.validityType===pe.ValidityType.EOL){if(Nf.default.fromString(r.validity).toDate().getTime()<Date.now())throw Uo.error("record has expired"),new po("record has expired")}else if(r.validityType!=null)throw Uo.error("the validity type is unsupported"),new Zt("The validity type is unsupported");Uo("ipns record for %s is valid",r.value)}async function xn(t,e){if(e.byteLength>$p)throw new mo("The record is too large");let r=Df(t),n;Do(r,0)&&(n=gu(r));let o=De(e),i=Cf(o)??n;if(i==null)throw new cn("Could not extract public key from IPNS record or routing key");let s=Lt(i.toMultihash());if(!ne(s,t))throw new cn("Embedded public key did not match routing key");await Hp(i,e)}var kf=ei(lo(),1);var zp=Yt("ipns"),Of=300*1e9,jp="/ipns/",gw=jp.length,Pf={v1Compatible:!0,ttlNs:Of};async function Fo(t,e,r,n,o=Pf){let i=new kf.default(Date.now()+Number(n)),s=pe.ValidityType.EOL,a=BigInt(o.ttlNs??Of);return Yp(t,e,r,s,i.toString(),a,o)}var Yp=async(t,e,r,n,o,i,s=Pf)=>{r=BigInt(r);let a=$(o),c=Ff(e),u=$(c),f=Lf(u,n,a,r,i),l=Lo(f),p=await t.sign(l),m;if(t.type==="RSA"&&(m=gt(t.publicKey)),s.v1Compatible===!0){let S=await Zp(t,u,n,a),v={value:c,signatureV1:S,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:p,data:f};return m!=null&&(v.pubKey=m),v}else{let S={value:c,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:p,data:f};return m!=null&&(S.pubKey=m),S}},Zp=async(t,e,r,n)=>{try{let o=Rf(e,r,n);return await t.sign(o)}catch(o){throw zp.error("record signature creation failed",o),new ho("Record signature creation failed")}};var Ys=ei(lo(),1);function No(t,e){let r=e.map((n,o)=>({record:De(n),index:o}));return r.sort((n,o)=>{let i=n.record.sequence,s=o.record.sequence;if(i>s)return-1;if(i<s)return 1;if(n.record.validityType===pe.ValidityType.EOL&&o.record.validityType===pe.ValidityType.EOL){let a=Ys.default.fromString(n.record.validity).toDate(),c=Ys.default.fromString(o.record.validity).toDate();if(a.getTime()>c.getTime())return-1;if(a.getTime()<c.getTime())return 1}return 0}),r[0].index}var vr=BigInt(6e4)*5000000n,Kf=5;var ko=class extends Error{static name="RecordsFailedValidationError";constructor(e="Records failed validation"){super(e),this.name="RecordsFailedValidationError"}},Oo=class extends Error{static name="UnsupportedMultibasePrefixError";constructor(e="Unsupported multibase prefix"){super(e),this.name="UnsupportedMultibasePrefixError"}},Po=class extends Error{static name="UnsupportedMultihashCodecError";constructor(e="Unsupported multihash codec"){super(e),this.name="UnsupportedMultihashCodecError"}},Ko=class extends Error{static name="InvalidValueError";constructor(e="Invalid value"){super(e),this.name="InvalidValueError"}};var wn=class extends Error{static name="RecordNotFoundError";name="RecordNotFoundError"};var ht="/",Mf=new TextEncoder().encode(ht),Mo=Mf[0],Ar=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=$(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Mo)throw new Error("Invalid key")}toString(e="utf8"){return Z(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(ht))}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=Mf),this._buf[0]!==Mo){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Mo,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Mo;)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(ht).slice(1)}type(){return Gp(this.baseNamespace())}name(){return Xp(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(ht)||(e+=ht),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(ht):new t(e.slice(0,-1).join(ht))}child(e){return this.toString()===ht?e:e.toString()===ht?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(),...Wp(e.map(r=>r.namespaces()))])}};function Gp(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function Xp(t){let e=t.split(":");return e[e.length-1]}function Wp(t){return[].concat(...t)}var Qp=114,Zs=0,Gs=18;function Xs(t,e){return t.code===e}var Vo="/dht/record/",e0="/ipns/metadata/";function En(t){return new Ar(Vo+Z(t,"base32"),!1)}function qo(t){return new Ar(e0+Z(t,"base32"),!1)}function Vf(t,e){let r=Date.now(),n=e.getTime()+1728e5,o=new Date(t.validity).getTime();return n-r<864e5||o-r<864e5}function t0(t){return t?.asCID===t}function qf(t){if(!t0(t))return!1;if(t.code!==Qp)throw new Q(`CID codec ${t.code} was not libp2p-key`);if(t.multihash.code!==Zs&&t.multihash.code!==Gs)throw new Q(`Multihash algorithm codec ${t.multihash.code} was not Identity or SHA256 hash`);return!0}var $f={[Ne.prefix]:Ne,[X.prefix]:X},Tr=class{routers;localStore;log;constructor(e,r){this.log=e.logger.forComponent("helia:ipns"),this.localStore=r.localStore,this.routers=r.routers}async resolve(e,r={}){let n=ia(e)||Cn(e)?e.toMultihash():qf(e)?e.multihash:e,o=Lt(n),i=await this.#t(o,r);return{...await this.#e(i.value,r),record:i}}async#e(e,r={}){let n=e.split("/");try{let o=n[1];if(o==="ipns"){let i=n[2],s=i.substring(0,1),a;if(s==="1"||s==="Q")a=X.decode(`z${i}`);else if($f[s]!=null)a=$f[s].decode(i);else throw new Oo(`Unsupported multibase prefix "${s}"`);let c;try{c=nr(a)}catch{c=ie.decode(a).multihash}if(!Xs(c,Zs)&&!Xs(c,Gs))throw new Po(`Unsupported multihash codec "${c.code}"`);let{cid:u}=await this.resolve(c,r),f=n.slice(3).join("/");return{cid:u,path:f===""?void 0:f}}else if(o==="ipfs"){let i=ie.parse(n[2]),s=n.slice(3).join("/");return{cid:i,path:s===""?void 0:s}}}catch(o){this.log.error("error parsing ipfs path - %e",o)}throw this.log.error("invalid ipfs path %s",e),new Ko("Invalid value")}async#t(e,r={}){let n=[];if(await this.localStore.has(e,r))if(this.log("record is present in the cache"),r.nocache!==!0)try{let{record:c,created:u}=await this.localStore.get(e,r);this.log("record retrieved from cache"),await xn(e,c),this.log("record was valid");let f=De(c),l=Number((f.ttl??vr)/1000000n);if(u.getTime()+l>Date.now())return this.log("record TTL was valid"),f;if(r.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),f;this.log("record TTL has been reached, searching routing for updates"),n.push(c)}catch(c){this.log("cached record was invalid - %e",c),await this.localStore.delete(e,r)}else this.log("ignoring local cache due to nocache=true option");if(r.offline===!0)throw new wn("Record was not present in the cache or has expired");this.log("did not have record locally");let i=0,s=[];if(await Promise.all(this.routers.map(async c=>{let u;try{u=await c.get(e,{...r,validate:!1})}catch(f){this.log.error("error finding IPNS record using router %s - %e",c.toString(),f),s.push(f);return}try{await xn(e,u),n.push(u)}catch(f){i++,this.log.error("error validating IPNS record from router %s - %e",c.toString(),f)}})),n.length===0)throw i>0?new ko(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`):new wn("Could not find record for routing key");let a=n[No(e,n)];return await this.localStore.put(e,a,r),De(a)}};var ve=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};var $o=class{routers;localStore;keychain;constructor(e,r){this.keychain=e.libp2p.services.keychain,this.localStore=r.localStore,this.routers=r.routers}async publish(e,r,n={}){try{let o=await this.#e(e),i=1n,s=Lt(o.publicKey.toMultihash());if(await this.localStore.has(s,n)){let{record:l}=await this.localStore.get(s,n);i=De(l).sequence+1n}Cn(r)&&(r=r.toCID());let a=n.ttl!=null?BigInt(n.ttl)*1000000n:vr,c=n.lifetime??1728e5,u=await Fo(o,r,i,c,{...n,ttlNs:a}),f=bn(u);return n.offline===!0?await this.localStore.put(s,f,{...n,metadata:{keyName:e,lifetime:c}}):await Promise.all(this.routers.map(async l=>{await l.put(s,f,{...n,metadata:{keyName:e,lifetime:c}})})),{record:u,publicKey:o.publicKey}}catch(o){throw n.onProgress?.(new ve("ipns:publish:error",o)),o}}async#e(e){try{return await this.keychain.exportKey(e)}catch{let n=await mu("Ed25519");return await this.keychain.importKey(e,n),n}}async unpublish(e,r){let{publicKey:n}=await this.keychain.exportKey(e),o=n.toMultihash(),i=Lt(o);await this.localStore.delete(i,r)}};function Ir(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Ho=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}},Br=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Ho(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 Ho(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 Ws=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Hf(t={}){return n0(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 n0(t,e){e=e??{};let r=e.onEnd,n=new Br,o,i,s,a=Ir(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((h,w)=>{i=T=>{i=null,n.push(T);try{h(t(n))}catch(B){w(B)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ir()})}},u=h=>i!=null?i(h):(n.push(h),o),f=h=>(n=new Br,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})},p=h=>s?o:(s=!0,h!=null?f(h):u({done:!0})),m=()=>(n=new Br,p(),{done:!0}),S=h=>(p(h),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:m,throw:S,push:l,end:p,get readableLength(){return n.size},onEmpty:async h=>{let w=h?.signal;if(w?.throwIfAborted(),n.isEmpty())return;let T,B;w!=null&&(T=new Promise((O,F)=>{B=()=>{F(new Ws)},w.addEventListener("abort",B)}));try{await Promise.race([a.promise,T])}finally{B!=null&&w!=null&&w?.removeEventListener("abort",B)}}},r==null)return o;let v=o;return o={[Symbol.asyncIterator](){return this},next(){return v.next()},throw(h){return v.throw(h),r!=null&&(r(h),r=void 0),{done:!0}},return(){return v.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(h){return v.end(h),r!=null&&(r(h),r=void 0),o},get readableLength(){return v.readableLength},onEmpty:h=>v.onEmpty(h)},o}var Js=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},zf=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Qs(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=e,a,c,f=new Promise((l,p)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){p(zf(s));return}if(s&&(c=()=>{p(zf(s))},s.addEventListener("abort",c,{once:!0})),t.then(l,p),r===Number.POSITIVE_INFINITY)return;let m=new Js;a=i.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(S){p(S)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?l():o instanceof Error?p(o):(m.message=o??`Promise timed out after ${r} milliseconds`,p(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 o0=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 i0(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}=o0(t),l=async(...m)=>{let S=r.multiArgs?m:m[0];if(r.filter)try{if(!await r.filter(S))return}catch(v){n(),s(v);return}c.push(S),r.count===c.length&&(n(),i(c))},p=(...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,p)};for(let m of a)u(m,l);for(let m of r.rejectionEvents)a.includes(m)||u(m,p);r.signal&&r.signal.addEventListener("abort",()=>{p(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(o.cancel=n,typeof r.timeout=="number"){let i=Qs(o,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function zo(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=i0(t,e,r),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}function Sn(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 jo=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function s0(t){return t.reason}async function jf(t,e,r){if(e==null)return t;let n=r?.translateError??s0;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 Yo=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=Ir(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new ot)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function a0(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Zo=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=a0(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,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 ot),this.cleanup())}async join(e){let r=new Yo(e);return this.recipients.push(r),e?.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await jf(this.fn({...this.options??{},signal:this.controller.signal,onProgress:r=>{this.recipients.forEach(n=>{n.onProgress?.(r)})}}),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 Go=class extends Rn{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=Sn(this.emitEmpty.bind(this),1),this.emitIdle=Sn(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 jo;let n=new Zo(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 ot)}),this.clear()}async onEmpty(e){this.size!==0&&await zo(this,"empty",e)}async onSizeLessThan(e,r){this.size<e||await zo(this,"next",{...r,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await zo(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=Hf({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 ot("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 Yf(t){let e=new globalThis.AbortController;function r(){let i=t.filter(s=>s?.aborted===!0).map(s=>s?.reason).pop();e.abort(i);for(let s of t)s?.removeEventListener!=null&&s.removeEventListener("abort",r)}for(let i of t){if(i?.aborted===!0){r();break}i?.addEventListener!=null&&i.addEventListener("abort",r)}function n(){for(let i of t)i?.removeEventListener!=null&&i.removeEventListener("abort",r)}let o=e.signal;return o.clear=n,o}function Zf(t,e,r){let n,o,i=!1;function s(){let u={signal:o.signal},f;r?.timeout!=null&&(f=Yf([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=Sn(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 Xo=class{routers;localStore;republishTask;log;keychain;started=!1;republishConcurrency;constructor(e,r){this.log=e.logger.forComponent("helia:ipns"),this.localStore=r.localStore,this.keychain=e.libp2p.services.keychain,this.republishConcurrency=r.republishConcurrency||Kf,this.started=e.libp2p.status==="started",this.routers=r.routers??[],this.republishTask=Zf(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 Go({concurrency:this.republishConcurrency});try{let n=[];for await(let{routingKey:o,record:i,metadata:s,created:a}of this.localStore.list(e)){if(s==null){this.log(`no metadata found for record ${o.toString()}, skipping`);continue}let c;try{c=De(i)}catch(p){this.log.error("error unmarshaling record - %e",p);continue}if(!Vf(c,a)){this.log.trace(`skipping record ${o.toString()}within republish threshold`);continue}let u=c.sequence+1n,f=c.ttl??vr,l;try{l=await this.keychain.exportKey(s.keyName)}catch(p){this.log.error("missing key %s, skipping republishing record - %e",s.keyName,p);continue}try{let p=await Fo(l,c.value,u,s.lifetime,{...e,ttlNs:f});n.push({routingKey:o,record:p})}catch(p){this.log.error("error creating updated IPNS record for %s - %e",o,p);continue}}this.log(`found ${n.length} records to republish`);for(let{routingKey:o,record:i}of n)r.add(async()=>{try{let s=bn(i);await Promise.all(this.routers.map(a=>a.put(o,s,e)))}catch(s){this.log.error("error republishing record - %e",s)}},e)}catch(n){this.log.error("error during republish - %e",n)}await r.onIdle(e)}};var vn;(function(t){let e;t.codec=()=>(e==null&&(e=Qe((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:Le(0),value:Le(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 We(i,t.codec())}t.encode=r;function n(i,s){return Xe(i,t.codec(),s)}t.decode=n;function o(i,s){return Je(i,t.codec(),s)}t.stream=o})(vn||(vn={}));function Gf(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 Xf(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 Ut=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 vn.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:Gf(this.timeReceived)}}static deserialize(e){let r=vn.decode(e);return new t(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(e){let r=Xf(e.timeReceived);if(e.key==null)throw new Error("key missing from deserialized object");if(e.value==null)throw new Error("value missing from deserialized object");return new t(e.key,e.value,r)}};var Wf;(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"})(Wf||(Wf={}));var An;(function(t){let e;t.codec=()=>(e==null&&(e=Qe((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 We(i,t.codec())}t.encode=r;function n(i,s){return Xe(i,t.codec(),s)}t.decode=n;function o(i,s){return Je(i,t.codec(),s)}t.stream=o})(An||(An={}));function Wo(t,e){return{async put(r,n,o={}){try{let i=En(r);try{let c=await t.get(i),u=Ut.deserialize(c);if(ne(u.value,n))return}catch(c){if(c.name!=="NotFoundError")throw c}let s=new Ut(r,n,new Date);o.onProgress?.(new ve("ipns:routing:datastore:put"));let a=t.batch();a.put(i,s.serialize()),o.metadata!=null&&a.put(qo(r),An.encode(o.metadata)),await a.commit(o)}catch(i){throw o.onProgress?.(new ve("ipns:routing:datastore:error",i)),i}},async get(r,n={}){try{let o=En(r);n.onProgress?.(new ve("ipns:routing:datastore:get"));let i=await t.get(o,n),s=Ut.deserialize(i);return{record:s.value,created:s.timeReceived}}catch(o){throw n.onProgress?.(new ve("ipns:routing:datastore:error",o)),o}},async has(r,n={}){let o=En(r);return t.has(o,n)},async delete(r,n){let o=En(r),i=t.batch();i.delete(o),i.delete(qo(r)),await i.commit(n)},async*list(r={}){try{r.onProgress?.(new ve("ipns:routing:datastore:list"));for await(let{key:n,value:o}of t.query({prefix:Vo},r))try{let i=Ut.deserialize(o),a=n.toString().substring(Vo.length),c=$(a,"base32"),u=qo(c),f;try{let l=await t.get(u,r);f=An.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 ve("ipns:routing:datastore:error",n)),n}}}}var ea=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 ve("ipns:routing:helia:error",o)),o}}async get(e,r={}){try{return await this.routing.get(e,r)}catch(n){throw r.onProgress?.(new ve("ipns:routing:helia:error",n)),n}}toString(){return"HeliaRouting()"}};function Tn(t){return new ea(t)}var ta=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 ta(t)}var Qo=class{routers;publisher;republisher;resolver;localStore;started;constructor(e,r={}){this.localStore=Wo(e.datastore,e.logger.forComponent("helia:ipns:local-store")),this.started=e.libp2p.status==="started",this.routers=[Jo(this.localStore),Tn(e.routing),...r.routers??[]],this.publisher=new $o(e,{...r,routers:this.routers,localStore:this.localStore}),this.republisher=new Xo(e,{...r,routers:this.routers,localStore:this.localStore}),this.resolver=new Tr(e,{...r,routers:this.routers,localStore:this.localStore}),e.events.addEventListener("start",this.start.bind(this)),e.events.addEventListener("stop",this.stop.bind(this)),this.started&&this.republisher.start()}start(){this.started||(this.started=!0,this.republisher.start())}stop(){this.started&&(this.started=!1,this.republisher.stop())}async publish(e,r,n={}){return this.publisher.publish(e,r,n)}async resolve(e,r={}){return this.resolver.resolve(e,r)}async unpublish(e,r){return this.publisher.unpublish(e,r)}};function f0(t,e={}){return new Qo(t,e)}function l0(t,e={}){let r=Wo(t.datastore,t.logger.forComponent("helia:ipns:local-store")),n=[Jo(r),Tn(t.routing),...e.routers??[]];return new Tr(t,{routers:n,localStore:r})}return ol(d0);})();
14
14
  /*! Bundled license information:
15
15
 
16
16
  @noble/curves/utils.js: