@smartledger/keys 3.1.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- "use strict";var LumenKeys=(()=>{var sn=Object.defineProperty;var jf=Object.getOwnPropertyDescriptor;var Pf=Object.getOwnPropertyNames;var zf=Object.prototype.hasOwnProperty;var qf=(t,e,r)=>e in t?sn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var Ue=(t,e)=>()=>(t&&(e=t(t=0)),e);var yi=(t,e)=>{for(var r in e)sn(t,r,{get:e[r],enumerable:!0})},Gf=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Pf(e))!zf.call(t,o)&&o!==r&&sn(t,o,{get:()=>e[o],enumerable:!(n=jf(e,o))||n.enumerable});return t};var Wf=t=>Gf(sn({},"__esModule",{value:!0}),t);var u=(t,e,r)=>qf(t,typeof e!="symbol"?e+"":e,r);function En(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function Ye(t,e=""){if(typeof t!="number")throw new TypeError(Oo(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Oo(e)+"expected integer >= 0, got "+t);return t}function Me(t,e,r=""){if(En(t)&&(e===void 0||t.length===e))return t;e!==void 0&&Ye(e,"length");let n=En(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=Oo(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function An(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Ye(t.outputLen),Ye(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}function Qt(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function Sn(t,e){Me(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Ir(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function vn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Le(t,e){return t<<32-e|t>>>e}function Bn(t){if(Me(t),bc)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=P0[t[r]];return e}function gc(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function Io(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(bc)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,s=0;o<r;o++,s+=2){let i=gc(t.charCodeAt(s)),a=gc(t.charCodeAt(s+1));if(i===void 0||a===void 0){let c=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function mc(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Me(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function z0(t,e,r="opts"){return xc(t,"defaults"),e!==void 0&&xc(e,r),Object.assign(t,e)}function wc(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=z0({},e,"info");let r=(o,s)=>t(s).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 Ec(t=32){Ye(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 Oo,xc,bc,P0,Ac,er=Ue(()=>{Oo=t=>t?`"${t}" `:"";xc=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)};bc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",P0=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));Ac=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])})});function Ur(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}function Lc(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function dt(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Rt(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}function Be(t,e=""){if(typeof t!="boolean")throw new TypeError(G0(e)+"expected boolean, got type="+typeof t);return t}function _n(t){if(typeof t=="bigint"){if(!ht(t))throw new RangeError("positive bigint expected, got "+t)}else Ko(t);return t}function rr(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 Rr(t){let e=_n(t).toString(16);return e.length&1?"0"+e:e}function Hc(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Tn:BigInt("0x"+t)}function Ne(t){return Hc(Bn(t))}function Co(t){return Hc(Bn(W0(Me(t)).reverse()))}function On(t,e){if(Ye(e),e===0)throw new Error("zero output length is invalid");t=_n(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return Io(n.padStart(r,"0"))}function Do(t,e){return On(t,e).reverse()}function W0(t){return Uint8Array.from(le(t))}function ht(t){return typeof t=="bigint"&&Tn<=t}function Mo(t,e,r){return ht(t)&&ht(e)&&ht(r)&&e<=t&&t<r}function No(t,e,r,n){if(!Mo(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function nr(t){if(t<Tn)throw new Error("expected non-negative bigint, got "+t);return t===Tn?0:t.toString(2).length}function _c(t,e,r){if(Ye(t,"hashLen"),Ye(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=m=>new Uint8Array(m),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),f=n(t),d=0,h=()=>{c.fill(1),f.fill(0),d=0},l=(...m)=>r(f,Ze(c,...m)),p=(m=o)=>{f=l(s,m),c=l(),m.length!==0&&(f=l(i,m),c=l())},y=()=>{if(d++>=a)throw new Error("drbg: tried max amount of iterations");let m=0,v=[];for(;m<e;){c=l();let T=c.slice();v.push(T),m+=c.length}return Ze(...v)};return(m,v)=>{h(),p(m);let T;for(;(T=v(y()))===void 0;)p();return h(),T}}function $e(t,e={},r={},n="object"){dt(t,n),dt(e,"fields"),dt(r,"optFields");function o(i,a,c){let f=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,d=t[i];if(!Object.hasOwn(t,i)&&(c?d!==void 0:a!=="function"))throw new TypeError(`${f} is invalid: expected own property`);if(c&&d===void 0)return;let h=typeof d;if(h!==a||d===null)throw new TypeError(`${f} is invalid: expected ${a}, got ${h}`)}let s=(i,a)=>Object.entries(i).forEach(([c,f])=>o(c,f,a));s(e,!1),s(r,!0)}var le,Ko,Fo,Ze,Ln,tr,Hn,Tn,Tc,G0,Kr,Kt=Ue(()=>{er();le=(t,e,r)=>Me(t,e,r),Ko=Ye;Fo=Bn,Ze=(...t)=>mc(...t),Ln=t=>Io(t),tr=En,Hn=t=>Ec(t),Tn=BigInt(0),Tc=BigInt(1),G0=t=>t?`"${t}" `:"";Kr=t=>(rr(t,"n"),(Tc<<BigInt(t))-Tc)});function we(t,e){if(e<=de)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=de?r:e+r}function Dc(t,e,r){if(r<=Z)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<de)throw new Error("invalid exponent, negatives unsupported");if(e===de)return Z;if(e===Z)return t;let n=t%r;if(n<de&&(n+=r),e<Z0){let a=Z;for(;e>de;)e&Z&&(a=a*n%r),n=n*n%r,e>>=Z;return a}let o=[];for(;e>de;)o.push(Number(e&Y0)),e>>=$o;let s=new Array(16);s[0]=Z,s[1]=n;for(let a=2;a<16;a++)s[a]=s[a-1]*n%r;let i=s[o[o.length-1]];for(let a=o.length-2;a>=0;a--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let c=o[a];c!==0&&(i=i*s[c]%r)}return i}function Ee(t,e,r){if(r<=Z)throw new Error("pow2: expected modulus > 1, got "+r);if(e<de)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >de;)n*=n,n%=r;return n}function Oc(t,e){if(t===de)throw new Error("invert: expected non-zero number");if(e<=Z)throw new Error("invert: expected modulus > 1, got "+e);let r=we(t,e),n=e,o=de,s=Z;for(;r!==de;){let a=n/r,c=n-r*a,f=o-s*a;n=r,r=c,o=s,s=f}if(n!==Z)throw new Error("invert: does not exist");return we(o,e)}function Mc(t,e){if(e<=Z)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=we(t,e);if(r===de)throw new Error("invertCt: expected non-zero number");let n=Dc(r,e-pt,e);if(we(r*n,e)!==Z)throw new Error("invertCt: does not exist");return n}function jo(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Po(t,e){if((t&Z)===de)throw new Error(e+": expected odd modulus, got "+t)}function Nc(t,e){let r=t,n=(r.ORDER+Z)/$o,o=r.pow(e,n);return jo(r,o,e),o}function J0(t,e){let r=t,n=(r.ORDER-Kc)/Fc,o=r.mul(e,pt),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,pt),s),c=r.mul(i,r.sub(a,r.ONE));return jo(r,c,e),c}function Q0(t){let e=sr(t),r=$c(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+V0)/Cc;return((a,c)=>{let f=a,d=f.pow(c,i),h=f.mul(d,n),l=f.mul(d,o),p=f.mul(d,s),y=f.eql(f.sqr(h),c),g=f.eql(f.sqr(l),c);d=f.cmov(d,h,y),h=f.cmov(p,l,g);let m=f.eql(f.sqr(h),c),v=f.cmov(d,h,m);return jo(f,v,c),v})}function $c(t){if(t<Rc)throw new Error("sqrt is not defined for small field");Po(t,"tonelliShanks");let e=t-Z,r=0;for(;e%pt===de;)e/=pt,r++;let n=pt,o=sr(t);for(;Ic(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Nc;let s=o.pow(n,e),i=(e+Z)/pt;return function(c,f){let d=c;if(d.is0(f))return f;if(Ic(d,f)!==1)throw new Error("Cannot find square root");let h=r,l=d.mul(d.ONE,s),p=d.pow(f,e),y=d.pow(f,i);for(;!d.eql(p,d.ONE);){if(d.is0(p))throw new Error("Cannot find square root: probably non-prime P");let g=1,m=d.sqr(p);for(;!d.eql(m,d.ONE);)if(g++,m=d.sqr(m),g===h)throw new Error("Cannot find square root");let v=Z<<BigInt(h-g-1),T=d.pow(l,v);h=g,l=d.sqr(T),p=d.mul(p,l),y=d.mul(y,T)}return y}}function eu(t){return Po(t,"Fp.sqrt"),t%$o===Rc?Nc:t%Fc===Kc?J0:t%Cc===X0?Q0(t):$c(t)}function or(t){if(dt(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);rr(t.BYTES,"BYTES"),rr(t.BITS,"BITS");for(let e of tu)Rt(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=Z)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function zo(t,e,r=!1){or(t),Ur(e,"nums"),Be(r,"passZero");let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((a,c,f)=>n.is0(c)?a:(o[f]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return e.reduceRight((a,c,f)=>n.is0(c)?a:(o[f]=n.mul(a,o[f]),n.mul(a,c)),i),o}function Ic(t,e){or(t);let r=t;Po(r.ORDER,"FpLegendre");let n=(r.ORDER-Z)/pt,o=r.pow(e,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function ru(t,e){if(e!==void 0&&Ko(e),t<=de)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=nr(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}function sr(t,e={}){return Object.freeze(In.prototype),new In(t,e)}function jc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=Z)throw new Error("field order must be greater than 1");let e=nr(t-Z);return Math.ceil(e/8)}function Un(t){let e=jc(t);return e+Math.ceil(e/2)}function Rn(t,e,r=!1){le(t);let n=t.length,o=jc(e),s=Math.max(Un(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Co(t):Ne(t),a=we(i,e-Z)+Z;return r?Do(a,o):On(a,o)}var de,Z,pt,Rc,$o,Kc,V0,Fc,X0,Y0,Cc,Z0,tu,Uc,In,Kn=Ue(()=>{Kt();de=BigInt(0),Z=BigInt(1),pt=BigInt(2),Rc=BigInt(3),$o=BigInt(4),Kc=BigInt(5),V0=BigInt(7),Fc=BigInt(8),X0=BigInt(9),Y0=BigInt(15),Cc=BigInt(16),Z0=BigInt("0x10000000000000000");tu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];Uc=new WeakMap,In=class{constructor(e,r={}){u(this,"ORDER");u(this,"BITS");u(this,"BYTES");u(this,"isLE");u(this,"ZERO",de);u(this,"ONE",Z);u(this,"_lengths");u(this,"_mod");if(e<=Z)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:s}=ru(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return we(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return de<=e&&e<this.ORDER}is0(e){return e===de}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&Z)===Z}neg(e){return we(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return we(e*e,this.ORDER)}add(e,r){return we(e+r,this.ORDER)}sub(e,r){return we(e-r,this.ORDER)}mul(e,r){return we(e*r,this.ORDER)}pow(e,r){return Dc(e,r,this.ORDER)}div(e,r){return we(e*Oc(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 Oc(e,this.ORDER)}sqrt(e){let r=Uc.get(this);return r||Uc.set(this,r=eu(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Do(e,this.BYTES):On(e,this.BYTES)}fromBytes(e,r=!1){le(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let f=new Uint8Array(o);f.set(e,s?0:f.length-e.length),e=f}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=s?Co(e):Ne(e);if(a&&(c=we(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return zo(this,e,!0)}cmov(e,r,n){return Be(n,"condition"),n?r:e}}});function Cr(t,e="n"){if(typeof t!="number")throw new TypeError(`wrong u32 integer "${e}": expected number, got type=${typeof t}`);if(!Number.isSafeInteger(t)||t<0||t>4294967295)throw new RangeError(`wrong u32 integer "${e}": expected 0..4294967295, got ${t}`);return t}function Jc(t){return Cr(t,"x"),(t&t-1)===0&&t!==0}function Xo(t,e){if(Cr(t),typeof e!="number")throw new TypeError('"bits" expected number, got type='+typeof e);if(!Number.isSafeInteger(e)||e<0||e>32)throw new Error(`expected integer 0 <= bits <= 32, got ${e}`);let r=0;for(let n=0;n<e;n++,t>>>=1)r=r<<1|t&1;return r>>>0}function Qc(t){return Cr(t),31-Math.clz32(t)}function Zc(t){if(!t||typeof t!="object"||typeof t.length!="number")throw new TypeError('"values" expected array-like, got type='+typeof t);let e=t.length;if(!Jc(e))throw new Error("expected positive power-of-two length, got "+e);let r=Qc(e);for(let n=0;n<e;n++){let o=Xo(n,r);if(n<o){let s=t[n];t[n]=t[o],t[o]=s}}return t}var Yo,ea=Ue(()=>{Kt();Yo=(t,e)=>{$e(e,{N:"number",roots:"object",dit:"boolean"},{invertButterflies:"boolean",skipStages:"number",brp:"boolean"},"coreOpts");let{N:r,roots:n,dit:o,invertButterflies:s=!1,skipStages:i=0,brp:a=!0}=e;Cr(r,"coreOpts.N");let c=Qc(r);if(!Jc(r))throw new Error("FFT: Polynomial size should be power of two");Cr(i,"coreOpts.skipStages");let f=c===0?0:c-1;if(i>f)throw new Error(`FFT: wrong skipStages: expected 0 <= skipStages <= ${f}`);if(n.length!==r)throw new Error(`FFT: wrong roots length: expected ${r}, got ${n.length}`);let d=o!==s;return h=>{if(h.length!==r)throw new Error("FFT: wrong Polynomial length");o&&a&&Zc(h);for(let l=0,p=1;l<c-i;l++){let y=o?l+1+i:c-l,g=1<<y,m=g>>1,v=r>>y;for(let T=0;T<r;T+=g)for(let E=0,x=p++;E<m;E++){let O=s?o?r-x:x:E*v,F=T+E,G=T+E+m,W=n[O],j=h[G],I=h[F];if(d){let V=t.mul(j,W);h[F]=t.add(I,V),h[G]=t.sub(I,V)}else s?(h[F]=t.add(j,I),h[G]=t.mul(t.sub(j,I),W)):(h[F]=t.add(I,j),h[G]=t.mul(t.sub(I,j),W))}}return!o&&a&&Zc(h),h}}});function ul(t,e=!1){return e?{h:Number(t&Xn),l:Number(t>>pf&Xn)}:{h:Number(t>>pf&Xn)|0,l:Number(t&Xn)|0}}function yf(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=ul(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var Xn,pf,xf=Ue(()=>{Xn=BigInt(4294967295),pf=BigInt(32)});function Yn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function ye(t,e=""){if(typeof t!="number")throw new TypeError(Zn(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Zn(e)+"expected integer >= 0, got "+t);return t}function bf(t,e=""){if(typeof t!="boolean")throw new TypeError(Zn(e)+"expected boolean, got type="+typeof t);return t}function ue(t,e,r=""){if(Yn(t)&&(e===void 0||t.length===e))return t;e!==void 0&&ye(e,"length");let n=Yn(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=Zn(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function mf(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(ye(t.outputLen),ye(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}function Ds(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function wf(t,e){ue(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Ms(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Ns(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function ll(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function dl(t){for(let e=0;e<t.length;e++)t[e]=ll(t[e]);return t}function js(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];ue(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function Ps(t,e,r="opts"){return gf(t,"defaults"),e!==void 0&&gf(e,r),Object.assign(t,e)}function Af(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=Ps({},e,"info");let r=(o,s)=>t(s).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 Sf(t=32){ye(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 Zn,gf,Ef,$s,zs,qs=Ue(()=>{Zn=t=>t?`"${t}" `:"";gf=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)};Ef=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;$s=Ef?t=>t:dl;zs=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])})});function vl(t,e=24){if(!(t instanceof Uint32Array))throw new TypeError('"s" expected Uint32Array(50), got type='+typeof t);if(t.length!==50)throw new RangeError('"s" expected Uint32Array(50), got length='+t.length);if(ye(e,"rounds"),e<1||e>24)throw new Error('"rounds" expected integer 1..24');for(let r=24-e;r<24;r++){for(let s=0;s<10;s++)hr[s]=t[s]^t[s+10]^t[s+20]^t[s+30]^t[s+40];for(let s=0;s<10;s+=2){let i=(s+8)%10,a=(s+2)%10,c=hr[a],f=hr[a+1],d=vf(c,f,1)^hr[i],h=Bf(c,f,1)^hr[i+1];for(let l=0;l<50;l+=10)t[s+l]^=d,t[s+l+1]^=h}let n=t[2],o=t[3];for(let s=0;s<24;s++){let i=Tf[s],a=vf(n,o,i),c=Bf(n,o,i),f=kf[s];n=t[f],o=t[f+1],t[f]=a,t[f+1]=c}for(let s=0;s<50;s+=10){let i=t[s],a=t[s+1],c=t[s+2],f=t[s+3];t[s]^=~t[s+2]&t[s+4],t[s+1]^=~t[s+3]&t[s+5],t[s+2]^=~t[s+4]&t[s+6],t[s+3]^=~t[s+5]&t[s+7],t[s+4]^=~t[s+6]&t[s+8],t[s+5]^=~t[s+7]&t[s+9],t[s+6]^=~t[s+8]&i,t[s+7]^=~t[s+9]&a,t[s+8]^=~i&c,t[s+9]^=~a&f}t[0]^=bl[r],t[1]^=ml[r]}Ns(hr)}var hl,Vr,pl,yl,xl,gl,kf,Tf,Lf,Hf,bl,ml,wl,El,Al,Sl,vf,Bf,hr,Gs,_f,Of,xe,Ws=Ue(()=>{xf();qs();hl=BigInt(0),Vr=BigInt(1),pl=BigInt(2),yl=BigInt(7),xl=BigInt(256),gl=BigInt(113),kf=[],Tf=[],Lf=[];for(let t=0,e=Vr,r=1,n=0;t<24;t++){[r,n]=[n,(2*r+3*n)%5],kf.push(2*(5*n+r)),Tf.push((t+1)*(t+2)/2%64);let o=hl;for(let s=0;s<7;s++)e=(e<<Vr^(e>>yl)*gl)%xl,e&pl&&(o^=Vr<<(Vr<<BigInt(s))-Vr);Lf.push(o)}Hf=yf(Lf,!0),bl=Hf[0],ml=Hf[1],wl=(t,e,r)=>t<<r|e>>>32-r,El=(t,e,r)=>e<<r|t>>>32-r,Al=(t,e,r)=>e<<r-32|t>>>64-r,Sl=(t,e,r)=>t<<r-32|e>>>64-r,vf=(t,e,r)=>r>32?Al(t,e,r):wl(t,e,r),Bf=(t,e,r)=>r>32?Sl(t,e,r):El(t,e,r),hr=new Uint32Array(10);Gs=class t{constructor(e,r,n,o=!1,s=24){u(this,"state");u(this,"pos",0);u(this,"posOut",0);u(this,"finished",!1);u(this,"state32");u(this,"destroyed",!1);u(this,"blockLen");u(this,"suffix");u(this,"outputLen");u(this,"canXOF");u(this,"enableXOF",!1);u(this,"rounds");if(ye(e,"blockLen"),ye(r,"suffix"),ye(s,"rounds"),bf(o,"enableXOF"),this.blockLen=e,this.suffix=r,this.outputLen=n,this.enableXOF=o,this.canXOF=o,this.rounds=s,ye(n,"outputLen"),!(0<e&&e<200))throw new Error('"blockLen" must be 1..199');this.state=new Uint8Array(200),this.state32=Ms(this.state)}clone(){return this._cloneInto()}keccak(){$s(this.state32),vl(this.state32,this.rounds),$s(this.state32),this.posOut=0,this.pos=0}update(e){Ds(this),ue(e);let{blockLen:r,state:n,state32:o}=this,s=e.length,i=r%4===0&&e.byteOffset%4===0,a=r/4,c=i&&s>=r?Ms(e):void 0;for(let f=0;f<s;){if(c!==void 0&&this.pos===0&&f%4===0&&s-f>=r){for(let h=0,l=f/4;h<a;h++)o[h]^=c[l+h];f+=r,this.pos=r,this.keccak();continue}let d=Math.min(r-this.pos,s-f);for(let h=0;h<d;h++)n[this.pos++]^=e[f++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:r,pos:n,blockLen:o}=this;e[n]^=r,(r&128)!==0&&n===o-1&&this.keccak(),e[o-1]^=128,this.keccak()}writeInto(e){Ds(this,!1),ue(e),this.finish();let r=this.state,{blockLen:n}=this;for(let o=0,s=e.length;o<s;){this.posOut>=n&&this.keccak();let i=Math.min(n-this.posOut,s-o);e.set(r.subarray(this.posOut,this.posOut+i),o),this.posOut+=i,o+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not enabled");return this.writeInto(e)}xof(e){return ye(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(wf(e,this),this.finished)throw new Error("digest() was already called");this.writeInto(e.length===this.outputLen?e:e.subarray(0,this.outputLen)),this.destroy()}digest(){let e=new Uint8Array(this.outputLen);return this.digestInto(e),e}destroy(){this.destroyed=!0,Ns(this.state)}_cloneInto(e){let{blockLen:r,suffix:n,outputLen:o,rounds:s,enableXOF:i}=this;return e||(e=new t(r,n,o,i,s)),e.blockLen=r,e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=s,e.suffix=n,e.outputLen=o,e.enableXOF=i,e.canXOF=this.canXOF,e.destroyed=this.destroyed,e}},_f=(t,e,r,n={})=>Af((o={})=>(o=Ps({},o),new Gs(e,t,o.dkLen===void 0?r:o.dkLen,!0)),n),Of=_f(31,168,16,zs(11)),xe=_f(31,136,32,zs(12))});function Bl(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}function kl(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Xs(t,e){if(t=ue(t),e=ue(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 Ys(t){if(Yn(t))throw new TypeError('"opts" expected object, got Uint8Array');kl(t,"opts")}function Jn(t){Ys(t),t.context!==void 0&&ue(t.context,void 0,"opts.context")}function Qn(t){Jn(t),t.extraEntropy!==!1&&t.extraEntropy!==void 0&&ue(t.extraEntropy,void 0,"opts.extraEntropy")}function Xr(t,...e){let r=o=>typeof o=="number"?o:o.bytesLen,n=e.reduce((o,s)=>o+r(s),0);return{bytesLen:n,encode:o=>{let s=new Uint8Array(n);for(let i=0,a=0;i<e.length;i++){let c=e[i],f=r(c),d=typeof c=="number"?o[i]:c.encode(o[i]);ue(d,f,t),s.set(d,a),typeof c!="number"&&d.fill(0),a+=f}return s},decode:o=>{ue(o,n,t);let s=[];for(let i of e){let a=r(i),c=o.subarray(0,a);s.push(typeof i=="number"?c:i.decode(c)),o=o.subarray(a)}return s}}}function jt(t,e){let r=t,n=e*r.bytesLen;return{bytesLen:n,encode:o=>{let s=Bl(o,"u");if(s.length!==e)throw new RangeError(`vecCoder.encode: wrong length=${s.length}. Expected: ${e}`);let i=new Uint8Array(n);for(let a=0,c=0;a<s.length;a++){let f=r.encode(s[a]);i.set(f,c),f.fill(0),c+=f.length}return i},decode:o=>{ue(o,n);let s=[];for(let i=0;i<o.length;i+=r.bytesLen)s.push(r.decode(o.subarray(i,i+r.bytesLen)));return s}}}function Se(...t){for(let e of t)if(Array.isArray(e))for(let r of e)r.fill(0);else e.fill(0)}function Zs(t){if(ye(t,"bits"),t>32)throw new RangeError('"bits" expected <= 32, got '+t);return t===32?4294967295:~(-1<<t)>>>0}function Js(t,e=If){if(ue(t,void 0,"msg"),ue(e,void 0,"ctx"),e.length>255)throw new RangeError("context should be 255 bytes or less");return js(new Uint8Array([0,e.length]),e,t)}function Qs(t,e=0){if(typeof t!="function"||typeof t.create!="function")throw new TypeError('"hash" expected hash function, got type='+typeof t);mf(t),ye(e,"requiredStrength");let r=t.oid;if(ue(r,void 0,"hash.oid"),!Xs(r.subarray(0,10),Tl))throw new Error('"hash.oid" is invalid: expected NIST hash');let n=t.outputLen*8/2;if(e>n)throw new Error("Pre-hash security strength too low: "+n+", required: "+e)}function ei(t,e,r=If){if(Qs(t),ue(e,void 0,"msg"),ue(r,void 0,"ctx"),r.length>255)throw new RangeError("context should be 255 bytes or less");let n=t(e);return js(new Uint8Array([1,r.length]),r,t.oid,n)}var St,Vs,If,Tl,ti=Ue(()=>{qs();St=ue,Vs=Sf;If=Uint8Array.of();Tl=Uint8Array.from([6,9,96,134,72,1,101,3,4,2])});var Uf,Rf,eo,to,Kf=Ue(()=>{ea();Ws();ti();Uf=t=>{let{newPoly:e,N:r,Q:n,F:o,ROOT_OF_UNITY:s,brvBits:i,isKyber:a}=t,c=(E,x=n)=>{let O=E%x|0;return(O>=0?O|0:x+O|0)|0},f=(E,x=n)=>{let O=c(E,x)|0;return(O>x>>1?O-x|0:O)|0};function d(){let E=e(r);for(let x=0;x<r;x++){let O=Xo(x,i),F=BigInt(s)**BigInt(O)%BigInt(n);E[x]=Number(F)|0}return E}let h=d(),l=E=>{throw new Error("not implemented")},p=a?{add:(E,x)=>{let O=E+x|0;return O>=n?O-n|0:O},sub:(E,x)=>{let O=E-x|0;return O<0?O+n|0:O},mul:(E,x)=>c((E|0)*(x|0))|0,inv:l}:{add:(E,x)=>c((E|0)+(x|0))|0,sub:(E,x)=>c((E|0)-(x|0))|0,mul:(E,x)=>c((E|0)*(x|0))|0,inv:l},y={N:r,roots:h,invertButterflies:!0,skipStages:a?1:0,brp:!1},g=Yo(p,{dit:!1,...y}),m=Yo(p,{dit:!0,...y}),v={encode:E=>g(E),decode:E=>{m(E);for(let x=0;x<E.length;x++)E[x]=c(o*E[x]);return E}};return{mod:c,smod:f,nttZetas:h,NTT:{encode:E=>v.encode(E),decode:E=>v.decode(E)},bitsCoder:(E,x)=>{for(let G=0,W=0;G<r;G++)W+=E,W>32&&Zs(W),W%=8;let O=Zs(E),F=E*(r/8);return{bytesLen:F,encode:G=>{let W=G,j=new Uint8Array(F);for(let I=0,V=0,X=0,re=0;I<W.length;I++)for(V|=(x.encode(W[I])&O)<<X,X+=E;X>=8;X-=8,V>>=8)j[re++]=V&255;return j},decode:G=>{let W=e(r);for(let j=0,I=0,V=0,X=0;j<G.length;j++)for(I|=G[j]<<V,V+=8;V>=E;V-=E,I>>=E)W[X++]=x.decode(I&O);return W}}}}},Rf=t=>(e,r)=>{r||(r=t.blockLen);let n=new Uint8Array(e.length+2);n.set(e);let o=e.length,s=new Uint8Array(r),i=t.create({}),a=0,c=0;return{stats:()=>({calls:a,xofs:c}),get:(f,d)=>(n[o+0]=f,n[o+1]=d,i.destroy(),i=t.create({}).update(n),a++,()=>(c++,i.xofInto(s))),clean:()=>{i.destroy(),Se(s,n)}}},eo=Rf(Of),to=Rf(xe)});var oo={};yi(oo,{PARAMS:()=>no,ml_dsa44:()=>Ol,ml_dsa65:()=>Il,ml_dsa87:()=>Ul});function Ff(t){Ys(t),t.externalMu!==void 0&&Be(t.externalMu,"opts.externalMu")}function ro(t){let e=t,r=ve(ie);for(let n=0;n<ie;){let o=e();if(o.length%3)throw new Error("RejNTTPoly: unaligned block");for(let s=0;n<ie&&s<=o.length-3;s+=3){let i=(o[s+0]|o[s+1]<<8|o[s+2]<<16)&8388607;i<kt&&(r[n++]=i)}}return r}function oi(t){let e=t,{K:r,L:n,GAMMA1:o,GAMMA2:s,TAU:i,ETA:a,OMEGA:c}=e,{CRH_BYTES:f,TR_BYTES:d,C_TILDE_BYTES:h,XOF128:l,XOF256:p,securityLevel:y}=e;if(![2,4].includes(a))throw new Error("Wrong ETA");if(![1<<17,1<<19].includes(o))throw new Error("Wrong GAMMA1");if(![ri,ni].includes(s))throw new Error("Wrong GAMMA2");let g=i*a,m=b=>{let A=Y.mod(b),S=Y.smod(A,2*s)|0;return A-S===kt-1?{r1:0,r0:S-1|0}:{r1:Math.floor((A-S)/(2*s))|0,r0:S}},v=b=>m(b).r1,T=b=>m(b).r0,E=(b,A)=>b<=s||b>kt-s||b===kt-s&&A===0?0:1,x=Math.floor((kt-1)/(2*s)),O=(b,A)=>{let{r1:S,r0:B}=m(A);return b===1?B>0?Y.mod(S+1,x)|0:Y.mod(S-1,x)|0:S|0},F=b=>{let A=Y.mod(b),S=Y.smod(A,2**Pt)|0;return{r1:Math.floor((A-S)/2**Pt)|0,r0:S}},G={bytesLen:c+r,encode:b=>{let A=b;if(A===!1)throw new Error("hint.encode: hint is false");let S=new Uint8Array(c+r);for(let B=0,R=0;B<r;B++){for(let _=0;_<ie;_++)A[B][_]!==0&&(S[R++]=_);S[c+B]=R}return S},decode:b=>{let A=[],S=0;for(let B=0;B<r;B++){let R=ve(ie);if(b[c+B]<S||b[c+B]>c)return!1;for(let _=S;_<b[c+B];_++){if(_>S&&b[_]<=b[_-1])return!1;R[b[_]]=1}S=b[c+B],A.push(R)}for(let B=S;B<c;B++)if(b[B]!==0)return!1;return A}},W=Yr(a===2?3:4,b=>a-b,b=>{if(!(-a<=b&&b<=a))throw new Error(`malformed key s1/s3 ${b} outside of ETA range [${-a}, ${a}]`);return b}),j=Yr(13,b=>(1<<Pt-1)-b),I=Yr(10),V=Yr(o===1<<17?18:20,b=>Y.smod(o-b)),X=Yr(s===ri?6:4),re=jt(X,r),ee=Xr("publicKey",32,jt(I,r)),q=Xr("secretKey",32,32,d,jt(W,n),jt(W,r),jt(j,r)),P=Xr("signature",h,jt(V,n),G),k=a===2?b=>b<15?2-b%5:!1:b=>b<9?4-b:!1;function U(b){let A=b,S=ve(ie);for(let B=0;B<ie;){let R=A();for(let _=0;B<ie&&_<R.length;_+=1){let $=k(R[_]&15),J=k(R[_]>>4&15);$!==!1&&(S[B++]=$),B<ie&&J!==!1&&(S[B++]=J)}}return S}let D=b=>{let A=ve(ie),S=xe.create({}).update(b),B=new Uint8Array(xe.blockLen);S.xofInto(B);let R=B.slice(0,8);for(let _=ie-i,$=8,J=0,ae=0;_<ie;_++){let ne=_+1;for(;ne>_;)ne=B[$++],!($<xe.blockLen)&&(S.xofInto(B),$=0);A[_]=A[ne],A[ne]=1-((R[J]>>ae++&1)<<1),ae>=8&&(J++,ae=0)}return A},H=b=>{let A=b,S=ve(ie),B=ve(ie);for(let R=0;R<A.length;R++){let{r0:_,r1:$}=F(A[R]);S[R]=_,B[R]=$}return{r0:S,r1:B}},w=(b,A)=>{let S=b,B=A;for(let R=0;R<ie;R++)S[R]=O(B[R],S[R]);return S},L=(b,A)=>{let S=b,B=A,R=ve(ie),_=0;for(let $=0;$<ie;$++){let J=E(S[$],B[$]);R[$]=J,_+=J}return{v:R,cnt:_}},C=32,M=Xr("seed",32,64,32),N=Object.freeze({info:Object.freeze({type:"internal-ml-dsa"}),lengths:Object.freeze({secretKey:q.bytesLen,publicKey:ee.bytesLen,seed:32,signature:P.bytesLen,signRand:C}),keygen:b=>{let A=new Uint8Array(34),S=b===void 0;S&&(b=Vs(32)),St(b,32,"seed"),A.set(b),S&&Se(b),A[32]=r,A[33]=n;let[B,R,_]=M.decode(xe(A,{dkLen:M.bytesLen})),$=p(R),J=[];for(let z=0;z<n;z++)J.push(U($.get(z&255,z>>8&255)));let ae=[];for(let z=n;z<n+r;z++)ae.push(U($.get(z&255,z>>8&255)));let ne=J.map(z=>Y.NTT.encode(z.slice())),Q=[],fe=[],ge=l(B),ce=ve(ie);for(let z=0;z<r;z++){Se(ce);for(let he=0;he<n;he++){let me=ro(ge.get(he,z));vt(ce,Bt(me,ne[he]))}Y.NTT.decode(ce);let{r0:Ht,r1:oe}=H(vt(ce,ae[z]));Q.push(Ht),fe.push(oe)}let be=ee.encode([B,fe]),Ie=xe(be,{dkLen:d}),Ge=q.encode([B,_,Ie,J,ae,Q]);return ge.clean(),$.clean(),Se(B,R,_,J,ae,ne,ce,Q,fe,Ie,A),{publicKey:be,secretKey:Ge}},getPublicKey:b=>{let[A,S,B,R,_,$]=q.decode(b),J=l(A),ae=R.map(fe=>Y.NTT.encode(fe.slice())),ne=[],Q=ve(ie);for(let fe=0;fe<r;fe++){Q.fill(0);for(let ce=0;ce<n;ce++){let be=ro(J.get(ce,fe));vt(Q,Bt(be,ae[ce]))}Y.NTT.decode(Q),vt(Q,_[fe]);let{r1:ge}=H(Q);ne.push(ge)}return J.clean(),Se(Q,ae,$,R,_),ee.encode([A,ne])},sign:(b,A,S={})=>{Qn(S),Ff(S);let{extraEntropy:B,externalMu:R=!1}=S;R&&St(b,f,"mu");let _=B===!1||B===void 0,$=B===!1?new Uint8Array(32):B===void 0?Vs(C):B;St($,32,"extraEntropy");let J=(()=>{try{return q.decode(A)}catch(oe){throw _&&Se($),oe}})(),[ae,ne,Q,fe,ge,ce]=J,be=[],Ie=l(ae);for(let oe=0;oe<r;oe++){let he=[];for(let me=0;me<n;me++)he.push(ro(Ie.get(me,oe)));be.push(he)}Ie.clean();for(let oe=0;oe<n;oe++)Y.NTT.encode(fe[oe]);for(let oe=0;oe<r;oe++)Y.NTT.encode(ge[oe]),Y.NTT.encode(ce[oe]);let Ge=R?b:xe.create({dkLen:f}).update(Q).update(b).digest(),z=xe.create({dkLen:f}).update(ne).update($).update(Ge).digest();_&&Se($),St(z,f);let Ht=p(z,V.bytesLen);e:for(let oe=0;;){let he=[];for(let se=0;se<n;se++,oe++)he.push(V.decode(Ht.get(oe&255,oe>>8)()));let me=he.map(se=>Y.NTT.encode(se.slice())),Wt=[];for(let se=0;se<r;se++){let br=ve(ie);for(let rt=0;rt<n;rt++)vt(br,Bt(be[se][rt],me[rt]));Y.NTT.decode(br),Wt.push(br)}let lo=Wt.map(se=>se.map(v)),ho=xe.create({dkLen:h}).update(Ge).update(re.encode(lo)).digest(),nn=Y.NTT.encode(D(ho)),on=fe.map(se=>Bt(se,nn));for(let se=0;se<n;se++)if(vt(Y.NTT.decode(on[se]),he[se]),Zr(on[se],o-g))continue e;let di=0,po=[];for(let se=0;se<r;se++){let br=Y.NTT.decode(Bt(ge[se],nn)),rt=Df(Wt[se],br).map(T);if(Zr(rt,s-g))continue e;let hi=Y.NTT.decode(Bt(ce[se],nn));if(Zr(hi,s))continue e;vt(rt,hi);let pi=L(rt,lo[se]);po.push(pi.v),di+=pi.cnt}if(di>c)continue;Ht.clean();let $f=P.encode([ho,on,po]);return Se(ho,on,po,nn,lo,Wt,me,he,z,fe,ge,ce,...be),R||Se(Ge),$f}throw new Error("Unreachable code path reached, report this error")},verify:(b,A,S,B={})=>{Ff(B);let{externalMu:R=!1}=B;R&&St(A,f,"mu");let[_,$]=ee.decode(S),J=xe(S,{dkLen:d});if(b.length!==P.bytesLen)return!1;let[ae,ne,Q]=P.decode(b);if(Q===!1)return!1;for(let z=0;z<n;z++)if(Zr(ne[z],o-g))return!1;let fe=R?A:xe.create({dkLen:f}).update(J).update(A).digest(),ge=Y.NTT.encode(D(ae)),ce=ne.map(z=>z.slice());for(let z=0;z<n;z++)Y.NTT.encode(ce[z]);let be=[],Ie=l(_);for(let z=0;z<r;z++){let Ht=Bt(Y.NTT.encode(_l($[z])),ge),oe=ve(ie);for(let me=0;me<n;me++){let Wt=ro(Ie.get(me,z));vt(oe,Bt(Wt,ce[me]))}let he=Y.NTT.decode(Df(oe,Ht));be.push(w(he,Q[z]))}Ie.clean();let Ge=xe.create({dkLen:h}).update(fe).update(re.encode(be)).digest();for(let z of Q)if(!(z.reduce((oe,he)=>oe+he,0)<=c))return!1;for(let z of ne)if(Zr(z,o-g))return!1;return Xs(ae,Ge)}});return Object.freeze({info:Object.freeze({type:"ml-dsa"}),internal:N,securityLevel:y,keygen:N.keygen,lengths:N.lengths,getPublicKey:N.getPublicKey,sign:(b,A,S={})=>{Qn(S);let B=Js(b,S.context),R=N.sign(B,A,S);return Se(B),R},verify:(b,A,S,B={})=>(Jn(B),St(b,void 0,"signature"),N.verify(b,Js(A,B.context),S)),prehash:b=>{Qs(b,y);let A=b;return Object.freeze({info:Object.freeze({type:"hashml-dsa"}),securityLevel:y,lengths:N.lengths,keygen:N.keygen,getPublicKey:N.getPublicKey,sign:(S,B,R={})=>{Qn(R);let _=ei(A,S,R.context),$=N.sign(_,B,R);return Se(_),$},verify:(S,B,R,_={})=>(Jn(_),St(S,void 0,"signature"),N.verify(S,ei(A,B,_.context),R))})}})}var ie,kt,Ll,Hl,Pt,ri,ni,no,ve,Y,Cf,Yr,vt,Df,_l,Zr,Bt,Ol,Il,Ul,so=Ue(()=>{Kt();Ws();Kf();ti();ie=256,kt=8380417,Ll=1753,Hl=8347681,Pt=13,ri=Math.floor((kt-1)/88)|0,ni=Math.floor((kt-1)/32)|0,no=Object.freeze({2:Object.freeze({K:4,L:4,D:Pt,GAMMA1:2**17,GAMMA2:ri,TAU:39,ETA:2,OMEGA:80}),3:Object.freeze({K:6,L:5,D:Pt,GAMMA1:2**19,GAMMA2:ni,TAU:49,ETA:4,OMEGA:55}),5:Object.freeze({K:8,L:7,D:Pt,GAMMA1:2**19,GAMMA2:ni,TAU:60,ETA:2,OMEGA:75})}),ve=t=>new Int32Array(t),Y=Uf({N:ie,Q:kt,F:Hl,ROOT_OF_UNITY:Ll,newPoly:ve,isKyber:!1,brvBits:8}),Cf=t=>t,Yr=(t,e=Cf,r=Cf)=>Y.bitsCoder(t,{encode:n=>e(r(n)),decode:n=>r(e(n))}),vt=(t,e)=>{let r=t,n=e;for(let o=0;o<r.length;o++)r[o]=Y.mod(r[o]+n[o]);return r},Df=(t,e)=>{let r=t,n=e;for(let o=0;o<r.length;o++)r[o]=Y.mod(r[o]-n[o]);return r},_l=t=>{let e=t;for(let r=0;r<ie;r++)e[r]<<=Pt;return e},Zr=(t,e)=>{let r=t;for(let n=0;n<ie;n++)if(Math.abs(Y.smod(r[n]))>=e)return!0;return!1},Bt=(t,e)=>{let r=t,n=e,o=ve(ie);for(let s=0;s<r.length;s++)o[s]=Y.mod(r[s]*n[s]);return o};Ol=oi({...no[2],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:32,XOF128:eo,XOF256:to,securityLevel:128}),Il=oi({...no[3],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:48,XOF128:eo,XOF256:to,securityLevel:192}),Ul=oi({...no[5],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:64,XOF128:eo,XOF256:to,securityLevel:256})});var Nl={};yi(Nl,{InMemoryKeyStorage:()=>Lt,KeyRegistry:()=>Gt,createKeySDK:()=>li,default:()=>Ml});var Si=Object.freeze({p:0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,n:0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,h:1n,a:0n,b:7n,Gx:0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,Gy:0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n}),{p:Ot,n:ot,Gx:Vf,Gy:Xf,b:vi}=Si,pe=32,mr=64,wr={publicKey:pe+1,publicKeyUncompressed:mr+1,signature:mr,seed:pe+pe/2},te=(t="",e=Error)=>{let r=new e(t),{captureStackTrace:n}=Error;throw typeof n=="function"&&n(r,te),r},Yf=t=>t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&t.BYTES_PER_ELEMENT===1,ke=(t,e,r="")=>{let n=Yf(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,a=s?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof t}`,f=i+"expected Uint8Array"+a+", got "+c;return n?te(f,RangeError):te(f,TypeError)}return t},st=t=>new Uint8Array(t),Bi=(t,e)=>t.toString(16).padStart(e,"0"),ki=t=>{let e="";for(let r of ke(t))e+=Bi(r,2);return e},We={_0:48,_9:57,A:65,F:70,a:97,f:102},xi=t=>t>=We._0&&t<=We._9?t-We._0:t>=We.A&&t<=We.F?t-(We.A-10):t>=We.a&&t<=We.f?t-(We.a-10):void 0,Ti=t=>{let e="hex invalid";if(typeof t!="string")return te(e);let r=t.length,n=r/2;if(r%2)return te(e);let o=st(n);for(let s=0,i=0;s<n;s++,i+=2){let a=xi(t.charCodeAt(i)),c=xi(t.charCodeAt(i+1));if(a===void 0||c===void 0)return te(e);o[s]=a*16+c}return o},gi=()=>globalThis?.crypto?.subtle??te("crypto.subtle must be defined, consider polyfill"),Vt=(...t)=>{let e=0;for(let o of t)e+=ke(o).length;let r=st(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r},Li=(t=pe)=>(globalThis?.crypto).getRandomValues(st(t)),an=BigInt,Sr=(t,e,r,n="bad number: out of range")=>typeof t!="bigint"?te(n,TypeError):e<=t&&t<r?t:te(n,RangeError),K=(t,e=Ot)=>{let r=t%e;return r>=0n?r:e+r},nt=t=>K(t,ot),bo=(t,e)=>{(t===0n||e<=0n)&&te("no inverse n="+t+" mod="+e);let r=K(t,e),n=e,o=0n,s=1n,i=1n,a=0n;for(;r!==0n;){let c=n/r,f=n%r,d=o-i*c,h=s-a*c;n=r,r=f,o=i,s=a,i=d,a=h}return n===1n?K(o,e):te("no inverse")},Hi=t=>{let e=hn[t];return typeof e!="function"&&te("hashes."+t+" not set"),e},_i=(t,e,r)=>ke(Hi(t)(e,r),pe,"digest"),Zf=(t,e,r)=>Promise.resolve(Hi(t)(e,r)).then(n=>ke(n,pe,"digest"));var yo=t=>t instanceof Ve?t:te("Point expected"),Oi=t=>K(K(t*t)*t+vi),bi=t=>Sr(t,0n,Ot),cn=t=>Sr(t,1n,Ot),xo=t=>Sr(t,1n,ot),Ii=t=>!(t&1n),vr=t=>Uint8Array.of(t),Jf=t=>vr(Ii(t)?2:3),Qf=t=>{let e=Oi(cn(t)),r=1n;for(let n=e,o=(Ot+1n)/4n;o>0n;o>>=1n)o&1n&&(r=r*n%Ot),n=n*n%Ot;return K(r*r)!==e&&te("sqrt invalid"),Ii(r)?r:K(-r)};var Re=class Re{constructor(e,r,n){u(this,"X");u(this,"Y");u(this,"Z");this.X=bi(e),this.Y=cn(r),this.Z=bi(n),Object.freeze(this)}static CURVE(){return Si}static fromAffine(e){let{x:r,y:n}=e;return r===0n&&n===0n?_t:new Re(r,n,1n)}static fromBytes(e){ke(e);let{publicKey:r,publicKeyUncompressed:n}=wr,o,s=e.length,i=e[0],a=e.subarray(1),c=fn(a,0,pe);if(s===r&&(i===2||i===3)){let f=Qf(c);i===3&&(f=K(-f)),o=new Re(c,f,1n)}return s===n&&i===4&&(o=new Re(c,fn(a,pe,mr),1n)),o?o.assertValidity():te("bad point: not on curve")}static fromHex(e){return Re.fromBytes(Ti(e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}equals(e){let{X:r,Y:n,Z:o}=this,{X:s,Y:i,Z:a}=yo(e),c=K(r*a),f=K(s*o),d=K(n*a),h=K(i*o);return c===f&&d===h}is0(){return this.equals(_t)}negate(){return new Re(this.X,K(-this.Y),this.Z)}double(){return this.add(this)}add(e){let{X:r,Y:n,Z:o}=this,{X:s,Y:i,Z:a}=yo(e),c=0n,f=vi,d=0n,h=0n,l=0n,p=K(f*3n),y=K(r*s),g=K(n*i),m=K(o*a),v=K(r+n),T=K(s+i);v=K(v*T),T=K(y+g),v=K(v-T),T=K(r+o);let E=K(s+a);return T=K(T*E),E=K(y+m),T=K(T-E),E=K(n+o),d=K(i+a),E=K(E*d),d=K(g+m),E=K(E-d),l=K(c*T),d=K(p*m),l=K(d+l),d=K(g-l),l=K(g+l),h=K(d*l),g=K(y+y),g=K(g+y),m=K(c*m),T=K(p*T),g=K(g+m),m=K(y-m),m=K(c*m),T=K(T+m),y=K(g*T),h=K(h+y),y=K(E*T),d=K(v*d),d=K(d-y),y=K(v*g),l=K(E*l),l=K(l+y),new Re(d,h,l)}subtract(e){return this.add(yo(e).negate())}multiply(e,r=!0){if(!r&&e===0n)return _t;if(xo(e),e===1n)return this;if(this.equals(it))return x0(e).p;let n=_t,o=it;for(let s=this;e>0n;s=s.double(),e>>=1n)e&1n?n=n.add(s):r&&(o=o.add(s));return n}multiplyUnsafe(e){return this.multiply(e,!1)}toAffine(){let{X:e,Y:r,Z:n}=this;if(this.equals(_t))return{x:0n,y:0n};if(n===1n)return{x:e,y:r};let o=bo(n,Ot);return K(n*o)!==1n&&te("inverse invalid"),{x:K(e*o),y:K(r*o)}}assertValidity(){let{x:e,y:r}=this.toAffine();return cn(e),cn(r),K(r*r)===Oi(e)?this:te("bad point: not on curve")}toBytes(e=!0){let{x:r,y:n}=this.assertValidity().toAffine(),o=Xt(r);return e?Vt(Jf(n),o):Vt(vr(4),o,Xt(n))}toHex(e){return ki(this.toBytes(e))}};u(Re,"BASE"),u(Re,"ZERO");var Ve=Re,it=new Ve(Vf,Xf,1n),_t=new Ve(0n,1n,0n);Ve.BASE=it;Ve.ZERO=_t;var e0=(t,e,r)=>it.multiply(e,!1).add(t.multiply(r,!1)).assertValidity(),dn=t=>an("0x"+(ki(t)||"0")),fn=(t,e,r)=>dn(t.subarray(e,r)),t0=2n**256n,Xt=t=>Ti(Bi(Sr(t,0n,t0),mr)),mo=t=>{let e=dn(ke(t,pe,"secret key"));return Sr(e,1n,ot,"invalid secret key: outside of range")},wo=t=>t>ot>>1n,Ui=(t,e=!0)=>it.multiply(mo(t)).toBytes(e),r0=t=>{try{return!!mo(t)}catch{return!1}},n0=(t,e)=>{let{publicKey:r,publicKeyUncompressed:n}=wr;try{let o=t.length;return e===!0&&o!==r||e===!1&&o!==n?!1:!!Ve.fromBytes(t)}catch{return!1}},mi=t=>[0,1,2,3].includes(t)?t:te("invalid recovery id"),Eo=t=>{t===o0&&te('Signature format "der" is not supported: switch to noble-curves'),t!=null&&t!==Ar&&t!==un&&te("Signature format must be one of: compact, recovered, der")},Ri=(t,e=Ar)=>{Eo(e);let r=wr.signature+ +(e===un);t.length!==r&&te(`Signature format "${e}" expects Uint8Array with length ${r}`)},Er=class t{constructor(e,r,n){u(this,"r");u(this,"s");u(this,"recovery");this.r=xo(e),this.s=xo(r),n!=null&&(this.recovery=mi(n)),Object.freeze(this)}static fromBytes(e,r=Ar){Ri(e,r);let n;r===un&&(n=e[0],e=e.subarray(1));let o=fn(e,0,pe),s=fn(e,pe,mr);return new t(o,s,n)}addRecoveryBit(e){return new t(this.r,this.s,e)}hasHighS(){return wo(this.s)}toBytes(e=Ar){Eo(e);let{r,s:n,recovery:o}=this,s=Vt(Xt(r),Xt(n));return e===un?Vt(vr(mi(o)),s):s}},Ki=t=>{t.length>8192&&te("input is too large");let e=t.length*8-256,r=dn(t);return e>0?r>>an(e):r},Fi=t=>nt(Ki(ke(t))),Ar="compact",un="recovered",o0="der",wi="SHA-256",hn={hmacSha256Async:async(t,e)=>{let r=gi(),n="HMAC",o=await r.importKey("raw",t,{name:n,hash:{name:wi}},!1,["sign"]);return st(await r.sign(n,o,e))},hmacSha256:void 0,sha256Async:async t=>st(await gi().digest(wi,t)),sha256:void 0},Ci=(t,e,r)=>{let n=ke(t,void 0,"message");return e.prehash?r?Zf("sha256Async",n):_i("sha256",n):n},s0=st(0),i0=vr(0),c0=vr(1),a0=1e3,f0="drbg: tried max amount of iterations",u0=(t,e)=>{let r=st(pe),n=st(pe),o=0,s=()=>{r.fill(1),n.fill(0)},i=(...d)=>_i("hmacSha256",n,Vt(r,...d)),a=(d=s0)=>{n=i(i0,d),r=i(),d.length!==0&&(n=i(c0,d),r=i())},c=()=>(o++>=a0&&te(f0),r=i(),r);s(),a(t);let f;for(;!(f=e(c()));)a();return s(),f};var l0=(t,e,r,n)=>{let{lowS:o,extraEntropy:s}=r,i=Xt,a=Fi(t),c=i(a),f=mo(e),d=[i(f),c];if(s!=null&&s!==!1){let y=s===!0?Li(pe):s;d.push(ke(y,void 0,"extraEntropy"))}let h=Vt(...d),l=a;return n(h,y=>{let g=Ki(y);if(!(1n<=g&&g<ot))return;let m=bo(g,ot),v=it.multiply(g).toAffine(),T=nt(v.x);if(T===0n)return;let E=nt(m*nt(l+T*f));if(E===0n)return;let x=(v.x===T?0:2)|Number(v.y&1n),O=E;return o&&wo(E)&&(O=nt(-E),x^=1),new Er(T,O,x).toBytes(r.format)})},d0=(t,e,r,n={})=>{let{lowS:o,format:s}=n;t instanceof Er&&te("Signature must be in Uint8Array, use .toBytes()"),Ri(t,s),ke(r,void 0,"publicKey");try{let{r:i,s:a}=Er.fromBytes(t,s),c=Fi(e),f=Ve.fromBytes(r);if(o&&wo(a))return!1;let d=bo(a,ot),h=nt(c*d),l=nt(i*d),p=e0(f,h,l).toAffine();return nt(p.x)===i}catch{return!1}},Di=t=>({lowS:t.lowS??!0,prehash:t.prehash??!0,format:t.format??Ar,extraEntropy:t.extraEntropy??!1}),Mi=(t,e,r={})=>{r=Di(r),Eo(r.format);let n=Ci(t,r,!1);return l0(n,e,r,u0)};var Ni=(t,e,r,n={})=>{n=Di(n);let o=Ci(e,n,!1);return d0(t,o,r,n)};var h0=t=>{if(t=t===void 0?Li(wr.seed):t,ke(t),t.length<wr.seed||t.length>1024)return te("expected 48-1024b",RangeError);let e=K(dn(t),ot-1n);return Xt(e+1n)};var pn=Object.freeze({isValidSecretKey:r0,isValidPublicKey:n0,randomSecretKey:h0});var ln=8,p0=256,$i=Math.ceil(p0/ln)+1,go=2**(ln-1),y0=()=>{let t=[],e=it,r=e;for(let n=0;n<$i;n++){r=e,t.push(r);for(let o=1;o<go;o++)r=r.add(e),t.push(r);e=r.double()}return t},Ei,Ai=(t,e)=>{let r=e.negate();return t?r:e},x0=t=>{let e=Ei||(Ei=y0()),r=_t,n=it,o=2**ln,s=o,i=an(o-1),a=an(ln);for(let c=0;c<$i;c++){let f=Number(t&i);t>>=a,f>go&&(f-=s,t+=1n);let d=c*go,h=d,l=d+Math.abs(f)-1,p=c%2!==0,y=f<0;f===0?n=n.add(Ai(p,e[h])):r=r.add(Ai(y,e[l]))}return t!==0n&&te("invalid wnaf"),{p:r,f:n}};function ji(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var yn=t=>t?`"${t}" `:"";function Ke(t,e=""){if(typeof t!="number")throw new TypeError(yn(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(yn(e)+"expected integer >= 0, got "+t);return t}function zi(t,e=""){if(typeof t!="boolean")throw new TypeError(yn(e)+"expected boolean, got type="+typeof t);return t}function ct(t,e,r=""){if(ji(t)&&(e===void 0||t.length===e))return t;e!==void 0&&Ke(e,"length");let n=ji(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=yn(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function qi(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Ke(t.outputLen),Ke(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Pi=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)};function Xe(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function Yt(t,e){ct(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Ao(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Fe(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function xn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Te(t,e){return t<<32-e|t>>>e}var b0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function m0(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function w0(t){for(let e=0;e<t.length;e++)t[e]=m0(t[e]);return t}var So=b0?t=>t:w0;function Gi(t,e,r="opts"){return Pi(t,"defaults"),e!==void 0&&Pi(e,r),Object.assign(t,e)}function Br(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=Gi({},e,"info");let r=(o,s)=>t(s).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)}var kr=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});var gn=class{constructor(e,r){u(this,"oHash");u(this,"iHash");u(this,"blockLen");u(this,"outputLen");u(this,"canXOF",!1);u(this,"finished",!1);u(this,"destroyed",!1);if(qi(e),ct(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Fe(o)}update(e){return Xe(this),this.iHash.update(e),this}digestInto(e){Xe(this),Yt(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||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a,canXOF:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Wi=(()=>{let t=((e,r,n)=>new gn(e,r).update(n).digest());return t.create=(e,r)=>new gn(e,r),t})();var bn=BigInt(4294967295),Vi=BigInt(32);function E0(t,e=!1){return e?{h:Number(t&bn),l:Number(t>>Vi&bn)}:{h:Number(t>>Vi&bn)|0,l:Number(t&bn)|0}}function mn(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=E0(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var A0=t=>t/2**32|0,S0=t=>t>>>0;function Xi(t,e,r,n){let o=A0(r),s=S0(r);t.setUint32(e,n?s:o,n),t.setUint32(e+4,n?o:s,n)}var vo=(t,e,r)=>t>>>r,Bo=(t,e,r)=>t<<32-r|e>>>r,It=(t,e,r)=>t>>>r|e<<32-r,Ut=(t,e,r)=>t<<32-r|e>>>r,Tr=(t,e,r)=>t<<64-r|e>>>r-32,Lr=(t,e,r)=>t>>>r-32|e<<64-r;function Ce(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Yi=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Zi=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Ji=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Qi=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,ec=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),tc=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;function rc(t,e,r){return t&e^~t&r}function nc(t,e,r){return t&e^t&r^e&r}var Hr=class{constructor(e,r,n,o){u(this,"blockLen");u(this,"outputLen");u(this,"canXOF",!1);u(this,"padOffset");u(this,"isLE");u(this,"buffer");u(this,"view");u(this,"finished",!1);u(this,"length",0);u(this,"pos",0);u(this,"destroyed",!1);this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=xn(this.buffer)}update(e){Xe(this),ct(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let f=xn(e);for(;o<=s-a;a+=o)this.process(f,a);i=!0;continue}n.set(a===0&&c===s?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){Xe(this),Yt(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>o-i&&(this.process(n,0),r.fill(0)),Xi(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=e===r?n:xn(e),c=this.outputLen,f=c/4,d=this.get();if(c%4||f>d.length)throw new Error("invalid outputLen");for(let h=0;h<f;h++)a.setUint32(4*h,d[h],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return e.destroyed=s,e.finished=o,e.length=n,e.pos=i,i&&e.buffer.set(r),e}clone(){return this._cloneInto()}},oc=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var sc=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var B0=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),at=new Uint32Array(64),ko=class extends Hr{constructor(r,n){super(64,r,8,!1);u(this,"A",0);u(this,"B",0);u(this,"C",0);u(this,"D",0);u(this,"E",0);u(this,"F",0);u(this,"G",0);u(this,"H",0);this.A=n[0]|0,this.B=n[1]|0,this.C=n[2]|0,this.D=n[3]|0,this.E=n[4]|0,this.F=n[5]|0,this.G=n[6]|0,this.H=n[7]|0}get(){let{A:r,B:n,C:o,D:s,E:i,F:a,G:c,H:f}=this;return[r,n,o,s,i,a,c,f]}set(r,n,o,s,i,a,c,f){this.A=r|0,this.B=n|0,this.C=o|0,this.D=s|0,this.E=i|0,this.F=a|0,this.G=c|0,this.H=f|0}_cloneInto(r){return(r||(r=new this.constructor)).set(...this.get()),this._cloneIntoMeta(r)}process(r,n){for(let l=0;l<16;l++,n+=4)at[l]=r.getUint32(n,!1);for(let l=16;l<64;l++){let p=at[l-15],y=at[l-2],g=Te(p,7)^Te(p,18)^p>>>3,m=Te(y,17)^Te(y,19)^y>>>10;at[l]=m+at[l-7]+g+at[l-16]|0}let{A:o,B:s,C:i,D:a,E:c,F:f,G:d,H:h}=this;for(let l=0;l<64;l++){let p=Te(c,6)^Te(c,11)^Te(c,25),y=h+p+rc(c,f,d)+B0[l]+at[l]|0,m=(Te(o,2)^Te(o,13)^Te(o,22))+nc(o,s,i)|0;h=d,d=f,f=c,c=a+y|0,a=i,i=s,s=o,o=y+m|0}o=o+this.A|0,s=s+this.B|0,i=i+this.C|0,a=a+this.D|0,c=c+this.E|0,f=f+this.F|0,d=d+this.G|0,h=h+this.H|0,this.set(o,s,i,a,c,f,d,h)}roundClean(){Fe(at)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Fe(this.buffer)}},To=class extends ko{constructor(){super(32,oc)}};var ic=mn(["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))),k0=ic[0],T0=ic[1],ft=new Uint32Array(80),ut=new Uint32Array(80),Lo=class extends Hr{constructor(r,n){super(128,r,16,!1);u(this,"Ah",0);u(this,"Al",0);u(this,"Bh",0);u(this,"Bl",0);u(this,"Ch",0);u(this,"Cl",0);u(this,"Dh",0);u(this,"Dl",0);u(this,"Eh",0);u(this,"El",0);u(this,"Fh",0);u(this,"Fl",0);u(this,"Gh",0);u(this,"Gl",0);u(this,"Hh",0);u(this,"Hl",0);this.Ah=n[0]|0,this.Al=n[1]|0,this.Bh=n[2]|0,this.Bl=n[3]|0,this.Ch=n[4]|0,this.Cl=n[5]|0,this.Dh=n[6]|0,this.Dl=n[7]|0,this.Eh=n[8]|0,this.El=n[9]|0,this.Fh=n[10]|0,this.Fl=n[11]|0,this.Gh=n[12]|0,this.Gl=n[13]|0,this.Hh=n[14]|0,this.Hl=n[15]|0}get(){let{Ah:r,Al:n,Bh:o,Bl:s,Ch:i,Cl:a,Dh:c,Dl:f,Eh:d,El:h,Fh:l,Fl:p,Gh:y,Gl:g,Hh:m,Hl:v}=this;return[r,n,o,s,i,a,c,f,d,h,l,p,y,g,m,v]}set(r,n,o,s,i,a,c,f,d,h,l,p,y,g,m,v){this.Ah=r|0,this.Al=n|0,this.Bh=o|0,this.Bl=s|0,this.Ch=i|0,this.Cl=a|0,this.Dh=c|0,this.Dl=f|0,this.Eh=d|0,this.El=h|0,this.Fh=l|0,this.Fl=p|0,this.Gh=y|0,this.Gl=g|0,this.Hh=m|0,this.Hl=v|0}_cloneInto(r){return(r||(r=new this.constructor)).set(...this.get()),this._cloneIntoMeta(r)}process(r,n){for(let x=0;x<16;x++,n+=4)ft[x]=r.getUint32(n),ut[x]=r.getUint32(n+=4);for(let x=16;x<80;x++){let O=ft[x-15]|0,F=ut[x-15]|0,G=It(O,F,1)^It(O,F,8)^vo(O,F,7),W=Ut(O,F,1)^Ut(O,F,8)^Bo(O,F,7),j=ft[x-2]|0,I=ut[x-2]|0,V=It(j,I,19)^Tr(j,I,61)^vo(j,I,6),X=Ut(j,I,19)^Lr(j,I,61)^Bo(j,I,6),re=Ji(W,X,ut[x-7],ut[x-16]),ee=Qi(re,G,V,ft[x-7],ft[x-16]);ft[x]=ee|0,ut[x]=re|0}let{Ah:o,Al:s,Bh:i,Bl:a,Ch:c,Cl:f,Dh:d,Dl:h,Eh:l,El:p,Fh:y,Fl:g,Gh:m,Gl:v,Hh:T,Hl:E}=this;for(let x=0;x<80;x++){let O=It(l,p,14)^It(l,p,18)^Tr(l,p,41),F=Ut(l,p,14)^Ut(l,p,18)^Lr(l,p,41),G=l&y^~l&m,W=p&g^~p&v,j=ec(E,F,W,T0[x],ut[x]),I=tc(j,T,O,G,k0[x],ft[x]),V=j|0,X=It(o,s,28)^Tr(o,s,34)^Tr(o,s,39),re=Ut(o,s,28)^Lr(o,s,34)^Lr(o,s,39),ee=o&i^o&c^i&c,q=s&a^s&f^a&f;T=m|0,E=v|0,m=y|0,v=g|0,y=l|0,g=p|0,{h:l,l:p}=Ce(d|0,h|0,I|0,V|0),d=c|0,h=f|0,c=i|0,f=a|0,i=o|0,a=s|0;let P=Yi(V,re,q);o=Zi(P,I,X,ee),s=P|0}({h:o,l:s}=Ce(this.Ah|0,this.Al|0,o|0,s|0)),{h:i,l:a}=Ce(this.Bh|0,this.Bl|0,i|0,a|0),{h:c,l:f}=Ce(this.Ch|0,this.Cl|0,c|0,f|0),{h:d,l:h}=Ce(this.Dh|0,this.Dl|0,d|0,h|0),{h:l,l:p}=Ce(this.Eh|0,this.El|0,l|0,p|0),{h:y,l:g}=Ce(this.Fh|0,this.Fl|0,y|0,g|0),{h:m,l:v}=Ce(this.Gh|0,this.Gl|0,m|0,v|0),{h:T,l:E}=Ce(this.Hh|0,this.Hl|0,T|0,E|0),this.set(o,s,i,a,c,f,d,h,l,p,y,g,m,v,T,E)}roundClean(){Fe(ft,ut)}destroy(){this.destroyed=!0,Fe(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Ho=class extends Lo{constructor(){super(64,sc)}};var De=Br(()=>new To,kr(1));var cc=Br(()=>new Ho,kr(3));var L0=BigInt(0),_r=BigInt(1),H0=BigInt(2),_0=BigInt(7),O0=BigInt(256),I0=BigInt(113),uc=[],lc=[],dc=[];for(let t=0,e=_r,r=1,n=0;t<24;t++){[r,n]=[n,(2*r+3*n)%5],uc.push(2*(5*n+r)),lc.push((t+1)*(t+2)/2%64);let o=L0;for(let s=0;s<7;s++)e=(e<<_r^(e>>_0)*I0)%O0,e&H0&&(o^=_r<<(_r<<BigInt(s))-_r);dc.push(o)}var hc=mn(dc,!0),U0=hc[0],R0=hc[1],K0=(t,e,r)=>t<<r|e>>>32-r,F0=(t,e,r)=>e<<r|t>>>32-r,C0=(t,e,r)=>e<<r-32|t>>>64-r,D0=(t,e,r)=>t<<r-32|e>>>64-r,ac=(t,e,r)=>r>32?C0(t,e,r):K0(t,e,r),fc=(t,e,r)=>r>32?D0(t,e,r):F0(t,e,r),Zt=new Uint32Array(10);function M0(t,e=24){if(!(t instanceof Uint32Array))throw new TypeError('"s" expected Uint32Array(50), got type='+typeof t);if(t.length!==50)throw new RangeError('"s" expected Uint32Array(50), got length='+t.length);if(Ke(e,"rounds"),e<1||e>24)throw new Error('"rounds" expected integer 1..24');for(let r=24-e;r<24;r++){for(let s=0;s<10;s++)Zt[s]=t[s]^t[s+10]^t[s+20]^t[s+30]^t[s+40];for(let s=0;s<10;s+=2){let i=(s+8)%10,a=(s+2)%10,c=Zt[a],f=Zt[a+1],d=ac(c,f,1)^Zt[i],h=fc(c,f,1)^Zt[i+1];for(let l=0;l<50;l+=10)t[s+l]^=d,t[s+l+1]^=h}let n=t[2],o=t[3];for(let s=0;s<24;s++){let i=lc[s],a=ac(n,o,i),c=fc(n,o,i),f=uc[s];n=t[f],o=t[f+1],t[f]=a,t[f+1]=c}for(let s=0;s<50;s+=10){let i=t[s],a=t[s+1],c=t[s+2],f=t[s+3];t[s]^=~t[s+2]&t[s+4],t[s+1]^=~t[s+3]&t[s+5],t[s+2]^=~t[s+4]&t[s+6],t[s+3]^=~t[s+5]&t[s+7],t[s+4]^=~t[s+6]&t[s+8],t[s+5]^=~t[s+7]&t[s+9],t[s+6]^=~t[s+8]&i,t[s+7]^=~t[s+9]&a,t[s+8]^=~i&c,t[s+9]^=~a&f}t[0]^=U0[r],t[1]^=R0[r]}Fe(Zt)}var _o=class t{constructor(e,r,n,o=!1,s=24){u(this,"state");u(this,"pos",0);u(this,"posOut",0);u(this,"finished",!1);u(this,"state32");u(this,"destroyed",!1);u(this,"blockLen");u(this,"suffix");u(this,"outputLen");u(this,"canXOF");u(this,"enableXOF",!1);u(this,"rounds");if(Ke(e,"blockLen"),Ke(r,"suffix"),Ke(s,"rounds"),zi(o,"enableXOF"),this.blockLen=e,this.suffix=r,this.outputLen=n,this.enableXOF=o,this.canXOF=o,this.rounds=s,Ke(n,"outputLen"),!(0<e&&e<200))throw new Error('"blockLen" must be 1..199');this.state=new Uint8Array(200),this.state32=Ao(this.state)}clone(){return this._cloneInto()}keccak(){So(this.state32),M0(this.state32,this.rounds),So(this.state32),this.posOut=0,this.pos=0}update(e){Xe(this),ct(e);let{blockLen:r,state:n,state32:o}=this,s=e.length,i=r%4===0&&e.byteOffset%4===0,a=r/4,c=i&&s>=r?Ao(e):void 0;for(let f=0;f<s;){if(c!==void 0&&this.pos===0&&f%4===0&&s-f>=r){for(let h=0,l=f/4;h<a;h++)o[h]^=c[l+h];f+=r,this.pos=r,this.keccak();continue}let d=Math.min(r-this.pos,s-f);for(let h=0;h<d;h++)n[this.pos++]^=e[f++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:r,pos:n,blockLen:o}=this;e[n]^=r,(r&128)!==0&&n===o-1&&this.keccak(),e[o-1]^=128,this.keccak()}writeInto(e){Xe(this,!1),ct(e),this.finish();let r=this.state,{blockLen:n}=this;for(let o=0,s=e.length;o<s;){this.posOut>=n&&this.keccak();let i=Math.min(n-this.posOut,s-o);e.set(r.subarray(this.posOut,this.posOut+i),o),this.posOut+=i,o+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not enabled");return this.writeInto(e)}xof(e){return Ke(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Yt(e,this),this.finished)throw new Error("digest() was already called");this.writeInto(e.length===this.outputLen?e:e.subarray(0,this.outputLen)),this.destroy()}digest(){let e=new Uint8Array(this.outputLen);return this.digestInto(e),e}destroy(){this.destroyed=!0,Fe(this.state)}_cloneInto(e){let{blockLen:r,suffix:n,outputLen:o,rounds:s,enableXOF:i}=this;return e||(e=new t(r,n,o,i,s)),e.blockLen=r,e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=s,e.suffix=n,e.outputLen=o,e.enableXOF=i,e.canXOF=this.canXOF,e.destroyed=this.destroyed,e}},N0=(t,e,r,n={})=>Br(()=>new _o(e,t,r),n);var pc=N0(6,136,32,kr(8));function Or(t){return Array.from(t).map(e=>e.toString(16).padStart(2,"0")).join("")}function Jt(t){if(typeof t!="string")throw new Error("Hex input must be a string");if(t.length%2!==0)throw new Error("Hex string must have even length");if(!/^[0-9a-fA-F]*$/.test(t))throw new Error("Hex string contains a non-hex character");let e=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)e[r/2]=parseInt(t.slice(r,r+2),16);return e}async function wn(t,e){if(e==="sha256")return De(t);if(e==="sha512")return cc(t);if(e==="sha3-256")return pc(t);throw new Error(`Unsupported hash algorithm: ${e}`)}var $0=t=>t/2**32|0,j0=t=>t>>>0;function yc(t,e,r,n){let o=$0(r),s=j0(r);t.setUint32(e,n?s:o,n),t.setUint32(e+4,n?o:s,n)}er();function Sc(t,e,r){return t&e^~t&r}function vc(t,e,r){return t&e^t&r^e&r}var kn=class{constructor(e,r,n,o){u(this,"blockLen");u(this,"outputLen");u(this,"canXOF",!1);u(this,"padOffset");u(this,"isLE");u(this,"buffer");u(this,"view");u(this,"finished",!1);u(this,"length",0);u(this,"pos",0);u(this,"destroyed",!1);this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=vn(this.buffer)}update(e){Qt(this),Me(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let f=vn(e);for(;o<=s-a;a+=o)this.process(f,a);i=!0;continue}n.set(a===0&&c===s?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){Qt(this),Sn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>o-i&&(this.process(n,0),r.fill(0)),yc(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=e===r?n:vn(e),c=this.outputLen,f=c/4,d=this.get();if(c%4||f>d.length)throw new Error("invalid outputLen");for(let h=0;h<f;h++)a.setUint32(4*h,d[h],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return e.destroyed=s,e.finished=o,e.length=n,e.pos=i,i&&e.buffer.set(r),e}clone(){return this._cloneInto()}},Bc=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);er();var q0=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]),lt=new Uint32Array(64),Uo=class extends kn{constructor(r,n){super(64,r,8,!1);u(this,"A",0);u(this,"B",0);u(this,"C",0);u(this,"D",0);u(this,"E",0);u(this,"F",0);u(this,"G",0);u(this,"H",0);this.A=n[0]|0,this.B=n[1]|0,this.C=n[2]|0,this.D=n[3]|0,this.E=n[4]|0,this.F=n[5]|0,this.G=n[6]|0,this.H=n[7]|0}get(){let{A:r,B:n,C:o,D:s,E:i,F:a,G:c,H:f}=this;return[r,n,o,s,i,a,c,f]}set(r,n,o,s,i,a,c,f){this.A=r|0,this.B=n|0,this.C=o|0,this.D=s|0,this.E=i|0,this.F=a|0,this.G=c|0,this.H=f|0}_cloneInto(r){return(r||(r=new this.constructor)).set(...this.get()),this._cloneIntoMeta(r)}process(r,n){for(let l=0;l<16;l++,n+=4)lt[l]=r.getUint32(n,!1);for(let l=16;l<64;l++){let p=lt[l-15],y=lt[l-2],g=Le(p,7)^Le(p,18)^p>>>3,m=Le(y,17)^Le(y,19)^y>>>10;lt[l]=m+lt[l-7]+g+lt[l-16]|0}let{A:o,B:s,C:i,D:a,E:c,F:f,G:d,H:h}=this;for(let l=0;l<64;l++){let p=Le(c,6)^Le(c,11)^Le(c,25),y=h+p+Sc(c,f,d)+q0[l]+lt[l]|0,m=(Le(o,2)^Le(o,13)^Le(o,22))+vc(o,s,i)|0;h=d,d=f,f=c,c=a+y|0,a=i,i=s,s=o,o=y+m|0}o=o+this.A|0,s=s+this.B|0,i=i+this.C|0,a=a+this.D|0,c=c+this.E|0,f=f+this.F|0,d=d+this.G|0,h=h+this.H|0,this.set(o,s,i,a,c,f,d,h)}roundClean(){Ir(lt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ir(this.buffer)}},Ro=class extends Uo{constructor(){super(32,Bc)}};var kc=wc(()=>new Ro,Ac(1));Kt();Kn();var Wo=BigInt(0),Fr=BigInt(1),nu=BigInt(4),qo=16,Pc=128,ou=5,zc=2**31;function ir(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Rt(e.fromAffine,"Point.fromAffine"),Rt(e.fromBytes,"Point.fromBytes"),Rt(e.fromHex,"Point.fromHex"),dt(e.BASE,"Point.BASE"),dt(e.ZERO,"Point.ZERO"),or(e.Fp),or(e.Fn)}function Gc(t,e){ir(t),Wc(e,t);let r=zo(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function su(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function iu(t,e){let r=t*(4*e+128);if(r>zc)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+zc/2**20+" MiB")}function Vo(t,e){if(t!==void 0){Rt(t,"randomBytes");try{let r=t(e);if(!tr(r)||r.length!==e)return}catch{return}return t}}function Wc(t,e){Ur(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function cu(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,o)=>{if(!(r===void 0?e.isValid(n):ht(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var Vc=new WeakMap;function Go(t){return Vc.get(t)||1}function au(t,e){let r=t.double(),n=[t];for(let o=1;o<e;o++)n.push(n[o-1].add(r));return n}function fu(t,e){let r=2**e,n=r/2,o=BigInt(r-1),s=[];for(;t>Wo;){let i=0;t&Fr&&(i=Number(t&o),i>=n&&(i-=r),t-=BigInt(i)),s.push(i),t>>=Fr}return s}function uu(t,e,r){let n=2**e,o=n/2,s=BigInt(n-1),i=BigInt(e),a=[];for(let c=0;c<r;c++){let f=Number(t&s);t>>=i,f>o&&(f-=n,t+=Fr),a.push(f)}if(t!==Wo)throw new Error("invalid wnaf");return a}function lu(t,e,r){let n=0;for(let s of r)n=Math.max(n,s.length);let o=t;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<r.length;i++){let a=r[i][s];if(a){let c=e[i][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var Fn=class{constructor(e,r){u(this,"Point");u(this,"BASE");u(this,"ZERO");u(this,"randomBytes");u(this,"wnafPrecomputes",new WeakMap);u(this,"baseCanBeBlinded");u(this,"bits");ir(e),this.randomBytes=Vo(r,qo),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let o=Math.ceil(n/r)+1,s=2**(r-1),i=[],a=e;for(let c=0;c<o;c++){let f=a;for(let d=0;d<s;d++)i.push(f),f=f.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:o,comp:i}}wnafCachedCT(e,r){let{W:n,windows:o,comp:s}=e,i=2**(n-1),a=uu(r,n,o),c=this.ZERO,f=this.BASE;for(let d=0;d<o;d++){let h=a[d],l=d*i,p=Math.abs(h)-1,y=s[l];for(let m=1;m<i;m++)y=m===p?s[l+m]:y;let g=y.negate();h===0?f=f.add(s[l]):c=c.add(h<0?g:y)}return{p:c,f}}getWnafPrecomputes(e,r,n,o){let s=this.wnafPrecomputes.get(r),i=s?.find(a=>a.W===e&&a.bits===n);return i||(i=this.buildWnafTable(r,e,n),typeof o=="function"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(r,s)),s.push(i)),i}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!Mo(r,Fr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,o){let s=Go(e);return s===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(s,e,n,o),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+Pc,s=this.randomBytes(qo);if(!tr(s)||s.length!==qo)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+Ne(s)*this.Point.Fn.ORDER;return this.runCT(e,i,o,n)}fixedWindowCT(e,r,n){let o=ou,s=1<<o,i=Kr(o),a=new Array(s);a[0]=this.ZERO;for(let d=1;d<s;d++)a[d]=a[d-1].add(e);let c=Math.ceil(n/o),f=this.ZERO;for(let d=c-1;d>=0;d--){if(d!==c-1)for(let p=0;p<o;p++)f=f.double();let h=Number(r>>BigInt(d*o)&i),l=a[0];for(let p=1;p<s;p++)l=p===h?a[p]:l;f=f.add(l)}return{p:f,f}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===Fr?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,o){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,o):this.mulCT(e,r,o)}mulUnsafe(e,r,n){if(this.assertPoint(e),!ht(r))throw new Error("invalid scalar");let o=Go(e);if(o===1||r>=this.Point.Fn.ORDER)return Cn(this.Point,[e],[r],!0);let s=this.getWnafPrecomputes(o,e,this.bits,n);return this.wnafCachedCT(s,r).p}setWindowSize(e,r){this.assertPoint(e),su(r,this.bits);let n=Math.ceil((this.bits+Pc)/r)+1;iu(n*2**(r-1),this.Point.Fp.BYTES),Vc.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Go(e)!==1}};function Cn(t,e,r,n=!1){if(ir(t),Wc(e,t),Be(n,"allowOversized"),cu(r,t.Fn,n?t.Fn.ORDER**nu:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(i=>au(i,4)),s=r.map(i=>fu(i,4));return lu(t.ZERO,o,s)}function qc(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return or(e),e}else return sr(t,{isLE:r})}function Xc(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);$e(r);for(let c of["p","n","h"]){let f=e[c];if(!(ht(f)&&f!==Wo))throw new Error(`CURVE.${c} must be positive bigint`)}let o=qc(e.p,r.Fp,n),s=qc(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:s}}function Yc(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}Kn();er();var Dn=class{constructor(e,r){u(this,"oHash");u(this,"iHash");u(this,"blockLen");u(this,"outputLen");u(this,"canXOF",!1);u(this,"finished",!1);u(this,"destroyed",!1);if(An(e),Me(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Ir(o)}update(e){return Qt(this),this.iHash.update(e),this}digestInto(e){Qt(this),Sn(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||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a,canXOF:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ta=(()=>{let t=((e,r,n)=>new Dn(e,r).update(n).digest());return t.create=(e,r)=>new Dn(e,r),t})();er();Kt();Kt();var du=BigInt(0),Zo=class extends Error{constructor(e=""){super(e)}},Je={Err:Zo,_tlv:{encode:(t,e)=>{let{Err:r}=Je;if(rr(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(Lc(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=Rr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Rr(o.length/2|128):"";return Rr(t)+s+o+e},decode(t,e){let{Err:r}=Je;e=le(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let d of f)i=i<<8|d;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=Je;if(_n(t),t<du)throw new e("integer: negative integers are not allowed");let r=Rr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=Je;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Ne(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=Je,o=le(t,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l:d}=n.decode(2,c);if(d.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(t){let{_tlv:e,_int:r}=Je;$e(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}},Jo=(Object.freeze(Je._tlv),Object.freeze(Je._int),Object.freeze(Je));Kn();var ra=(t,e)=>(t+(t>=0?e:-e)/na)/e;function hu(t,e,r){No("scalar",t,Qe,r);let[[n,o],[s,i]]=e,a=ra(i*t,r),c=ra(-o*t,r),f=t-a*n-c*s,d=-a*o-c*i,h=f<Qe,l=d<Qe;h&&(f=-f),l&&(d=-d);let p=Kr(Math.ceil(nr(r)/2))+Ft;if(f<Qe||f>=p||d<Qe||d>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:h,k1:f,k2neg:l,k2:d}}function ts(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Qo(t,e){$e(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Be(r.lowS,"lowS"),Be(r.prehash,"prehash"),r.format!==void 0&&ts(r.format),r}var Qe=BigInt(0),Ft=BigInt(1),na=BigInt(2),es=BigInt(3),pu=BigInt(4);function oa(t,e={}){let r=Xc("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;$e(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:f}=e,d=e.randomBytes===void 0?Hn:e.randomBytes;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let h=ia(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function p(P,k,U){if(f&&k.is0())return Uint8Array.of(0);let{x:D,y:H}=k.toAffine(),w=n.toBytes(D);if(Be(U,"isCompressed"),U){l();let L=!n.isOdd(H);return Ze(sa(L),w)}else return Ze(Uint8Array.of(4),w,n.toBytes(H))}function y(P){le(P,void 0,"Point");let{publicKey:k,publicKeyUncompressed:U}=h,D=P.length,H=P[0],w=P.subarray(1);if(f&&D===1&&H===0)return{x:n.ZERO,y:n.ZERO};if(D===k&&(H===2||H===3)){let L=n.fromBytes(w);if(!n.isValid(L))throw new Error("bad point: is not on curve, wrong x");let C=E(L),M;try{M=n.sqrt(C)}catch(A){let S=A instanceof Error?": "+A.message:"";throw new Error("bad point: is not on curve, sqrt error"+S)}l();let N=n.isOdd(M);return(H&1)===1!==N&&(M=n.neg(M)),{x:L,y:M}}else if(D===U&&H===4){let L=n.BYTES,C=n.fromBytes(w.subarray(0,L)),M=n.fromBytes(w.subarray(L,L*2));if(!x(C,M))throw new Error("bad point: is not on curve");return{x:C,y:M}}else throw new Error(`bad point: got length ${D}, expected compressed=${k} or uncompressed=${U}`)}let g=e.toBytes===void 0?p:e.toBytes,m=e.fromBytes===void 0?y:e.fromBytes,v=n.mul(s.b,es),T=n.is0(s.a)?P=>n.ZERO:P=>n.mul(s.a,P);function E(P){let k=n.sqr(P),U=n.mul(k,P);return n.add(n.add(U,n.mul(P,s.a)),s.b)}function x(P,k){let U=n.sqr(k),D=E(P);return n.eql(U,D)}if(!x(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let O=n.mul(n.pow(s.a,es),pu),F=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(O,F)))throw new Error("bad curve params: a or b");function G(P,k,U=!1){if(!n.isValid(k)||U&&n.is0(k))throw new Error(`bad point coordinate ${P}`);return k}function W(P){if(!(P instanceof X))throw new Error("Weierstrass Point expected")}function j(P){if(!c||!c.basises)throw new Error("no endo");return hu(P,c.basises,o.ORDER)}function I(P,k,U,D){if(!o.isValid(D))throw new RangeError("invalid scalar: out of range");if(c){let{k1neg:H,k1:w,k2neg:L,k2:C}=j(D),M=new X(n.mul(U.X,c.beta),U.Y,U.Z);P.push(H?U.negate():U,L?M.negate():M),k.push(w,C)}else P.push(U),k.push(D)}let V=new WeakSet,q=class q{constructor(k,U,D){u(this,"X");u(this,"Y");u(this,"Z");this.X=G("x",k),this.Y=G("y",U,!0),this.Z=G("z",D),Object.freeze(this)}static CURVE(){return s}static fromAffine(k){let{x:U,y:D}=k||{};if(!k||!n.isValid(U)||!n.isValid(D))throw new Error("invalid affine point");if(k instanceof q)throw new Error("projective point not allowed");return n.is0(U)&&n.is0(D)?q.ZERO:new q(U,D,n.ONE)}static fromBytes(k){let U=q.fromAffine(m(le(k,void 0,"point")));return U.assertValidity(),U}static fromHex(k){return q.fromBytes(Ln(k))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(k=6,U=!0){return ee.setWindowSize(this,k),U||this.multiply(es),this}assertValidity(){let k=this;if(k.is0()){if(e.allowInfinityPoint&&n.is0(k.X)&&n.eql(k.Y,n.ONE)&&n.is0(k.Z))return;throw new Error("bad point: ZERO")}if(V.has(k))return;let{x:U,y:D}=k.toAffine();if(!n.isValid(U)||!n.isValid(D))throw new Error("bad point: x or y not field elements");if(!x(U,D))throw new Error("bad point: equation left != right");if(!k.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");V.add(k)}hasEvenY(){let{y:k}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(k)}equals(k){W(k);let{X:U,Y:D,Z:H}=this,{X:w,Y:L,Z:C}=k,M=n.eql(n.mul(U,C),n.mul(w,H)),N=n.eql(n.mul(D,C),n.mul(L,H));return M&&N}negate(){return new q(this.X,n.neg(this.Y),this.Z)}double(){let{X:k,Y:U,Z:D}=this,H=n.ZERO,w=n.ZERO,L=n.ZERO,C=n.mul(k,k),M=n.mul(U,U),N=n.mul(D,D),b=n.mul(k,U);return b=n.add(b,b),L=n.mul(k,D),L=n.add(L,L),H=T(L),w=n.mul(v,N),w=n.add(H,w),H=n.sub(M,w),w=n.add(M,w),w=n.mul(H,w),H=n.mul(b,H),L=n.mul(v,L),N=T(N),b=n.sub(C,N),b=T(b),b=n.add(b,L),L=n.add(C,C),C=n.add(L,C),C=n.add(C,N),C=n.mul(C,b),w=n.add(w,C),N=n.mul(U,D),N=n.add(N,N),C=n.mul(N,b),H=n.sub(H,C),L=n.mul(N,M),L=n.add(L,L),L=n.add(L,L),new q(H,w,L)}add(k){W(k);let{X:U,Y:D,Z:H}=this,{X:w,Y:L,Z:C}=k,M=n.ZERO,N=n.ZERO,b=n.ZERO,A=n.mul(U,w),S=n.mul(D,L),B=n.mul(H,C),R=n.add(U,D),_=n.add(w,L);R=n.mul(R,_),_=n.add(A,S),R=n.sub(R,_),_=n.add(U,H);let $=n.add(w,C);return _=n.mul(_,$),$=n.add(A,B),_=n.sub(_,$),$=n.add(D,H),M=n.add(L,C),$=n.mul($,M),M=n.add(S,B),$=n.sub($,M),b=T(_),M=n.mul(v,B),b=n.add(M,b),M=n.sub(S,b),b=n.add(S,b),N=n.mul(M,b),S=n.add(A,A),S=n.add(S,A),B=T(B),_=n.mul(v,_),S=n.add(S,B),B=n.sub(A,B),B=T(B),_=n.add(_,B),A=n.mul(S,_),N=n.add(N,A),A=n.mul($,_),M=n.mul(R,M),M=n.sub(M,A),A=n.mul(R,S),b=n.mul($,b),b=n.add(b,A),new q(M,N,b)}subtract(k){return W(k),this.add(k.negate())}is0(){return this.equals(q.ZERO)}multiply(k){if(!o.isValidNot0(k))throw new RangeError("invalid scalar: out of range");let{p:U,f:D}=ee.mulSecret(this,k,i,re);return re([U,D])[0]}multiplyUnsafe(k){let U=this,D=k;if(!o.isValid(D))throw new RangeError("invalid scalar: out of range");if(D===Qe||U.is0())return q.ZERO;if(D===Ft)return U;if(ee.hasWindowSize(this))return ee.mulUnsafe(U,D,re);let H=[],w=[];return I(H,w,U,D),Cn(q,H,w)}mulAddUnsafe(k,U,D){W(U);let H=[],w=[];return I(H,w,this,k),I(H,w,U,D),Cn(q,H,w)}toAffine(k){let U=this,D=k;if(D!=null&&!n.isValid(D))throw new RangeError('"invertedZ" expected valid field element');let{X:H,Y:w,Z:L}=U;if(n.eql(L,n.ONE))return{x:H,y:w};let C=U.is0();D==null&&(D=C?n.ONE:n.inv(L));let M=n.mul(H,D),N=n.mul(w,D),b=n.mul(L,D);if(C)return{x:n.ZERO,y:n.ZERO};if(!n.eql(b,n.ONE))throw new Error("invZ was invalid");return{x:M,y:N}}isTorsionFree(){let{isTorsionFree:k}=e;return i===Ft?!0:k?k(q,this):ee.mulUnsafe(this,a).is0()}clearCofactor(){let{clearCofactor:k}=e;return i===Ft?this:k?k(q,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Ft?this.is0():this.clearCofactor().is0()}toBytes(k=!0){return Be(k,"isCompressed"),this.assertValidity(),g(q,this,k)}toHex(k=!0){return Fo(this.toBytes(k))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}};u(q,"BASE",new q(s.Gx,s.Gy,n.ONE)),u(q,"ZERO",new q(n.ZERO,n.ONE,n.ZERO)),u(q,"Fp",n),u(q,"Fn",o);let X=q,re=P=>Gc(X,P),ee=new Fn(X,d);return ee.bits>=6&&X.BASE.precompute(6),Object.freeze(X.prototype),Object.freeze(X),X}function sa(t){return Uint8Array.of(t?2:3)}function ia(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function yu(t,e={}){ir(t);let{Fn:r}=t,n=e.randomBytes===void 0?Hn:e.randomBytes,o=Object.assign(ia(t.Fp,r),{seed:Math.max(Un(r.ORDER),16)});function s(p){try{let y=r.fromBytes(p);return r.isValidNot0(y)}catch{return!1}}function i(p,y){let{publicKey:g,publicKeyUncompressed:m}=o;try{let v=p.length;return y===!0&&v!==g||y===!1&&v!==m?!1:!!t.fromBytes(p)}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,Rn(le(p,o.seed,"seed"),r.ORDER)}function c(p,y=!0){return t.BASE.multiply(r.fromBytes(p)).toBytes(y)}function f(p){let{secretKey:y,publicKey:g,publicKeyUncompressed:m}=o,v=r._lengths;if(!tr(p))return;let T=le(p,void 0,"key").length,E=T===g||T===m,x=T===y||!!v?.includes(T);if(!(E&&x))return E}function d(p,y,g=!0){if(f(p)===!0)throw new Error("first arg must be private key");if(f(y)===!1)throw new Error("second arg must be public key");let m=r.fromBytes(p);return t.fromBytes(y).multiply(m).toBytes(g)}let h={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},l=Yc(a,c);return Object.freeze(h),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:d,keygen:l,Point:t,utils:h,lengths:o})}function ca(t,e,r={}){ir(t);let n=e;An(n),$e(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?Hn:o.randomBytes,i=o.hmac===void 0?(H,w)=>ta(n,H,w):o.hmac,{Fp:a,Fn:c}=t,{ORDER:f,BITS:d}=c,h=Un(f),l=Vo(s,h),{keygen:p,getPublicKey:y,getSharedSecret:g,utils:m,lengths:v}=yu(t,o),T={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},E=f*na+Ft<a.ORDER;function x(H){let w=f>>Ft;return H>w}function O(H,w){if(!c.isValidNot0(w))throw new Error(`invalid signature ${H}: out of range 1..Point.Fn.ORDER`);return w}function F(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function G(H,w,L){return F(),(H===L?0:2)|Number(a.isOdd(w))}function W(){if(E)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function j(H,w){ts(w);let L=v.signature,C=w==="compact"?L:w==="recovered"?L+1:void 0;return le(H,C)}class I{constructor(w,L,C){u(this,"r");u(this,"s");u(this,"recovery");if(this.r=O("r",w),this.s=O("s",L),C!=null){if(W(),![0,1,2,3].includes(C))throw new Error("invalid recovery id");this.recovery=C}Object.freeze(this)}static fromBytes(w,L=T.format){j(w,L);let C;if(L==="der"){let{r:A,s:S}=Jo.toSig(le(w));return new I(A,S)}L==="recovered"&&(C=w[0],L="compact",w=w.subarray(1));let M=v.signature/2,N=w.subarray(0,M),b=w.subarray(M,M*2);return new I(c.fromBytes(N),c.fromBytes(b),C)}static fromHex(w,L){return this.fromBytes(Ln(w),L)}assertRecovery(){let{recovery:w}=this;if(w==null)throw new Error("invalid recovery id: must be present");return w}addRecoveryBit(w){return new I(this.r,this.s,w)}recoverPublicKey(w){let{r:L,s:C}=this,M=this.assertRecovery(),N=M===2||M===3?L+f:L;if(!a.isValid(N))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let b=a.toBytes(N),A=t.fromBytes(Ze(sa((M&1)===0),b)),S=c.inv(N),B=X(le(w,void 0,"msgHash")),R=c.create(-B*S),_=c.create(C*S),$=t.BASE.mulAddUnsafe(R,A,_);if($.is0())throw new Error("invalid recovery: point at infinify");return $.assertValidity(),$}hasHighS(){return x(this.s)}toBytes(w=T.format){if(ts(w),w==="der")return Ln(Jo.hexFromSig(this));let{r:L,s:C}=this,M=c.toBytes(L),N=c.toBytes(C);return w==="recovered"?(W(),Ze(Uint8Array.of(this.assertRecovery()),M,N)):Ze(M,N)}toHex(w){return Fo(this.toBytes(w))}}Object.freeze(I.prototype),Object.freeze(I);let V=o.bits2int===void 0?function(w){if(w.length>8192)throw new Error("input is too large");let L=Ne(w),C=w.length*8-d;return C>0?L>>BigInt(C):L}:o.bits2int,X=o.bits2int_modN===void 0?function(w){return c.create(V(w))}:o.bits2int_modN,re=Kr(d);function ee(H){return No("num < 2^"+d,H,Qe,re),c.toBytes(H)}function q(H,w){return le(H,void 0,"message"),w?le(n(H),void 0,"prehashed message"):H}function P(H,w,L){let{lowS:C,prehash:M,extraEntropy:N}=Qo(L,T);H=q(H,M);let b=X(H),A=c.fromBytes(w);if(!c.isValidNot0(A))throw new Error("invalid private key");let S=[ee(A),ee(b)];if(N!=null&&N!==!1){let $=N===!0?s(v.secretKey):N;S.push(le($,void 0,"extraEntropy"))}let B=Ze(...S),R=b;function _($){let J=V($);if(!c.isValidNot0(J))return;let ae=t.BASE.multiply(J).toAffine(),ne=c.create(ae.x);if(ne===Qe)return;let Q;if(l!==void 0){let ce=Ne(Rn(l(h),f)),be=c.inv(c.mul(ce,J)),Ie=c.mul(ce,R),Ge=c.mul(ce,A);Q=c.create(be*c.create(Ie+Ge*ne))}else{let ce=Mc(J,f);Q=c.create(ce*c.create(R+ne*A))}if(Q===Qe)return;let fe=G(ae.x,ae.y,ne),ge=Q;return C&&x(Q)&&(ge=c.neg(Q),fe^=1),new I(ne,ge,E?void 0:fe)}return{seed:B,k2sig:_}}function k(H,w,L={}){let{seed:C,k2sig:M}=P(H,w,L);return _c(n.outputLen,c.BYTES,i)(C,M).toBytes(L.format)}function U(H,w,L,C={}){let{lowS:M,prehash:N,format:b}=Qo(C,T);if(L=le(L,void 0,"publicKey"),w=q(w,N),!tr(H)){let A=H instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+A)}j(H,b);try{let A=I.fromBytes(H,b),S=t.fromBytes(L);if(M&&A.hasHighS())return!1;let{r:B,s:R}=A,_=X(w),$=c.inv(R),J=c.create(_*$),ae=c.create(B*$),ne=t.BASE.mulAddUnsafe(J,S,ae);if(ne.is0())return!1;let Q=ne.toAffine();return!(c.create(Q.x)!==B||b==="recovered"&&A.recovery!==G(Q.x,Q.y,B))}catch{return!1}}function D(H,w,L={}){let{prehash:C}=Qo(L,T);return w=q(w,C),I.fromBytes(H,"recovered").recoverPublicKey(w).toBytes()}return Object.freeze({keygen:p,getPublicKey:y,getSharedSecret:g,utils:m,lengths:v,Point:t,sign:k,verify:U,recoverPublicKey:D,Signature:I,hash:n})}var ns={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},xu={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var aa=BigInt(2);function gu(t){let e=ns.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=t*t*t%e,d=f*f*t%e,h=Ee(d,r,e)*d%e,l=Ee(h,r,e)*d%e,p=Ee(l,aa,e)*f%e,y=Ee(p,o,e)*p%e,g=Ee(y,s,e)*y%e,m=Ee(g,a,e)*g%e,v=Ee(m,c,e)*m%e,T=Ee(v,a,e)*g%e,E=Ee(T,r,e)*d%e,x=Ee(E,i,e)*y%e,O=Ee(x,n,e)*f%e,F=Ee(O,aa,e);if(!rs.eql(rs.sqr(F),t))throw new Error("Cannot find square root");return F}var rs=sr(ns.p,{sqrt:gu}),bu=oa(ns,{Fp:rs,endo:xu}),cr=ca(bu,kc);function fa(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var os=t=>t?`"${t}" `:"";function ss(t,e=""){if(typeof t!="number")throw new TypeError(os(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(os(e)+"expected integer >= 0, got "+t);return t}function Ae(t,e,r=""){if(fa(t)&&(e===void 0||t.length===e))return t;e!==void 0&&ss(e,"length");let n=fa(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=os(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function la(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(ss(t.outputLen),ss(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var ua=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)};function ar(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function Mn(t,e){Ae(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function je(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function yt(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function He(t,e){return t<<32-e|t>>>e}function Dr(t,e){return t<<e|t>>>32-e>>>0}function Mr(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Ae(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function mu(t,e,r="opts"){return ua(t,"defaults"),e!==void 0&&ua(e,r),Object.assign(t,e)}function Nr(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=mu({},e,"info");let r=(o,s)=>t(s).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)}var is=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});var Nn=class{constructor(e,r){u(this,"oHash");u(this,"iHash");u(this,"blockLen");u(this,"outputLen");u(this,"canXOF",!1);u(this,"finished",!1);u(this,"destroyed",!1);if(la(e),Ae(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),je(o)}update(e){return ar(this),this.iHash.update(e),this}digestInto(e){ar(this),Mn(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||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a,canXOF:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},cs=(()=>{let t=((e,r,n)=>new Nn(e,r).update(n).digest());return t.create=(e,r)=>new Nn(e,r),t})();var $n=BigInt(4294967295),da=BigInt(32);function wu(t,e=!1){return e?{h:Number(t&$n),l:Number(t>>da&$n)}:{h:Number(t>>da&$n)|0,l:Number(t&$n)|0}}function ha(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=wu(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var Eu=t=>t/2**32|0,Au=t=>t>>>0;function pa(t,e,r,n){let o=Eu(r),s=Au(r);t.setUint32(e,n?s:o,n),t.setUint32(e+4,n?o:s,n)}var as=(t,e,r)=>t>>>r,fs=(t,e,r)=>t<<32-r|e>>>r,Ct=(t,e,r)=>t>>>r|e<<32-r,Dt=(t,e,r)=>t<<32-r|e>>>r,$r=(t,e,r)=>t<<64-r|e>>>r-32,jr=(t,e,r)=>t>>>r-32|e<<64-r;function Pe(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var ya=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),xa=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,ga=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),ba=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,ma=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),wa=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;function us(t,e,r){return t&e^~t&r}function ls(t,e,r){return t&e^t&r^e&r}var Mt=class{constructor(e,r,n,o){u(this,"blockLen");u(this,"outputLen");u(this,"canXOF",!1);u(this,"padOffset");u(this,"isLE");u(this,"buffer");u(this,"view");u(this,"finished",!1);u(this,"length",0);u(this,"pos",0);u(this,"destroyed",!1);this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=yt(this.buffer)}update(e){ar(this),Ae(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let f=yt(e);for(;o<=s-a;a+=o)this.process(f,a);i=!0;continue}n.set(a===0&&c===s?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){ar(this),Mn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>o-i&&(this.process(n,0),r.fill(0)),pa(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=e===r?n:yt(e),c=this.outputLen,f=c/4,d=this.get();if(c%4||f>d.length)throw new Error("invalid outputLen");for(let h=0;h<f;h++)a.setUint32(4*h,d[h],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return e.destroyed=s,e.finished=o,e.length=n,e.pos=i,i&&e.buffer.set(r),e}clone(){return this._cloneInto()}},Ea=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Aa=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var vu=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),va=Uint8Array.from(new Array(16).fill(0).map((t,e)=>e)),Bu=va.map(t=>(9*t+5)%16),Ba=(()=>{let r=[[va],[Bu]];for(let n=0;n<4;n++)for(let o of r)o.push(o[n].map(s=>vu[s]));return r})(),ka=Ba[0],Ta=Ba[1],La=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(t=>Uint8Array.from(t)),ku=ka.map((t,e)=>t.map(r=>La[e][r])),Tu=Ta.map((t,e)=>t.map(r=>La[e][r])),Lu=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),Hu=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Sa(t,e,r,n){return t===0?e^r^n:t===1?e&r|~e&n:t===2?(e|~r)^n:t===3?e&n|r&~n:e^(r|~n)}var jn=new Uint32Array(16),ds=class extends Mt{constructor(){super(64,20,8,!0);u(this,"h0",1732584193);u(this,"h1",-271733879);u(this,"h2",-1732584194);u(this,"h3",271733878);u(this,"h4",-1009589776)}get(){let{h0:r,h1:n,h2:o,h3:s,h4:i}=this;return[r,n,o,s,i]}set(r,n,o,s,i){this.h0=r|0,this.h1=n|0,this.h2=o|0,this.h3=s|0,this.h4=i|0}_cloneInto(r){return(r||(r=new this.constructor)).set(...this.get()),this._cloneIntoMeta(r)}process(r,n){for(let y=0;y<16;y++,n+=4)jn[y]=r.getUint32(n,!0);let o=this.h0|0,s=o,i=this.h1|0,a=i,c=this.h2|0,f=c,d=this.h3|0,h=d,l=this.h4|0,p=l;for(let y=0;y<5;y++){let g=4-y,m=Lu[y],v=Hu[y],T=ka[y],E=Ta[y],x=ku[y],O=Tu[y];for(let F=0;F<16;F++){let G=Dr(o+Sa(y,i,c,d)+jn[T[F]]+m,x[F])+l|0;o=l,l=d,d=Dr(c,10)|0,c=i,i=G}for(let F=0;F<16;F++){let G=Dr(s+Sa(g,a,f,h)+jn[E[F]]+v,O[F])+p|0;s=p,p=h,h=Dr(f,10)|0,f=a,a=G}}this.set(this.h1+c+h|0,this.h2+d+p|0,this.h3+l+s|0,this.h4+o+a|0,this.h0+i+f|0)}roundClean(){je(jn)}destroy(){this.destroyed=!0,je(this.buffer),this.set(0,0,0,0,0)}},Ha=Nr(()=>new ds);var _u=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),hs=class extends Mt{constructor(r,n){super(64,r,8,!1);u(this,"A",0);u(this,"B",0);u(this,"C",0);u(this,"D",0);u(this,"E",0);u(this,"F",0);u(this,"G",0);u(this,"H",0);this.A=n[0]|0,this.B=n[1]|0,this.C=n[2]|0,this.D=n[3]|0,this.E=n[4]|0,this.F=n[5]|0,this.G=n[6]|0,this.H=n[7]|0}get(){let{A:r,B:n,C:o,D:s,E:i,F:a,G:c,H:f}=this;return[r,n,o,s,i,a,c,f]}set(r,n,o,s,i,a,c,f){this.A=r|0,this.B=n|0,this.C=o|0,this.D=s|0,this.E=i|0,this.F=a|0,this.G=c|0,this.H=f|0}_cloneInto(r){return(r||(r=new this.constructor)).set(...this.get()),this._cloneIntoMeta(r)}process(r,n){for(let l=0;l<16;l++,n+=4)xt[l]=r.getUint32(n,!1);for(let l=16;l<64;l++){let p=xt[l-15],y=xt[l-2],g=He(p,7)^He(p,18)^p>>>3,m=He(y,17)^He(y,19)^y>>>10;xt[l]=m+xt[l-7]+g+xt[l-16]|0}let{A:o,B:s,C:i,D:a,E:c,F:f,G:d,H:h}=this;for(let l=0;l<64;l++){let p=He(c,6)^He(c,11)^He(c,25),y=h+p+us(c,f,d)+_u[l]+xt[l]|0,m=(He(o,2)^He(o,13)^He(o,22))+ls(o,s,i)|0;h=d,d=f,f=c,c=a+y|0,a=i,i=s,s=o,o=y+m|0}o=o+this.A|0,s=s+this.B|0,i=i+this.C|0,a=a+this.D|0,c=c+this.E|0,f=f+this.F|0,d=d+this.G|0,h=h+this.H|0,this.set(o,s,i,a,c,f,d,h)}roundClean(){je(xt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),je(this.buffer)}},ps=class extends hs{constructor(){super(32,Ea)}};var _a=ha(["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))),Ou=_a[0],Iu=_a[1],gt=new Uint32Array(80),bt=new Uint32Array(80),ys=class extends Mt{constructor(r,n){super(128,r,16,!1);u(this,"Ah",0);u(this,"Al",0);u(this,"Bh",0);u(this,"Bl",0);u(this,"Ch",0);u(this,"Cl",0);u(this,"Dh",0);u(this,"Dl",0);u(this,"Eh",0);u(this,"El",0);u(this,"Fh",0);u(this,"Fl",0);u(this,"Gh",0);u(this,"Gl",0);u(this,"Hh",0);u(this,"Hl",0);this.Ah=n[0]|0,this.Al=n[1]|0,this.Bh=n[2]|0,this.Bl=n[3]|0,this.Ch=n[4]|0,this.Cl=n[5]|0,this.Dh=n[6]|0,this.Dl=n[7]|0,this.Eh=n[8]|0,this.El=n[9]|0,this.Fh=n[10]|0,this.Fl=n[11]|0,this.Gh=n[12]|0,this.Gl=n[13]|0,this.Hh=n[14]|0,this.Hl=n[15]|0}get(){let{Ah:r,Al:n,Bh:o,Bl:s,Ch:i,Cl:a,Dh:c,Dl:f,Eh:d,El:h,Fh:l,Fl:p,Gh:y,Gl:g,Hh:m,Hl:v}=this;return[r,n,o,s,i,a,c,f,d,h,l,p,y,g,m,v]}set(r,n,o,s,i,a,c,f,d,h,l,p,y,g,m,v){this.Ah=r|0,this.Al=n|0,this.Bh=o|0,this.Bl=s|0,this.Ch=i|0,this.Cl=a|0,this.Dh=c|0,this.Dl=f|0,this.Eh=d|0,this.El=h|0,this.Fh=l|0,this.Fl=p|0,this.Gh=y|0,this.Gl=g|0,this.Hh=m|0,this.Hl=v|0}_cloneInto(r){return(r||(r=new this.constructor)).set(...this.get()),this._cloneIntoMeta(r)}process(r,n){for(let x=0;x<16;x++,n+=4)gt[x]=r.getUint32(n),bt[x]=r.getUint32(n+=4);for(let x=16;x<80;x++){let O=gt[x-15]|0,F=bt[x-15]|0,G=Ct(O,F,1)^Ct(O,F,8)^as(O,F,7),W=Dt(O,F,1)^Dt(O,F,8)^fs(O,F,7),j=gt[x-2]|0,I=bt[x-2]|0,V=Ct(j,I,19)^$r(j,I,61)^as(j,I,6),X=Dt(j,I,19)^jr(j,I,61)^fs(j,I,6),re=ga(W,X,bt[x-7],bt[x-16]),ee=ba(re,G,V,gt[x-7],gt[x-16]);gt[x]=ee|0,bt[x]=re|0}let{Ah:o,Al:s,Bh:i,Bl:a,Ch:c,Cl:f,Dh:d,Dl:h,Eh:l,El:p,Fh:y,Fl:g,Gh:m,Gl:v,Hh:T,Hl:E}=this;for(let x=0;x<80;x++){let O=Ct(l,p,14)^Ct(l,p,18)^$r(l,p,41),F=Dt(l,p,14)^Dt(l,p,18)^jr(l,p,41),G=l&y^~l&m,W=p&g^~p&v,j=ma(E,F,W,Iu[x],bt[x]),I=wa(j,T,O,G,Ou[x],gt[x]),V=j|0,X=Ct(o,s,28)^$r(o,s,34)^$r(o,s,39),re=Dt(o,s,28)^jr(o,s,34)^jr(o,s,39),ee=o&i^o&c^i&c,q=s&a^s&f^a&f;T=m|0,E=v|0,m=y|0,v=g|0,y=l|0,g=p|0,{h:l,l:p}=Pe(d|0,h|0,I|0,V|0),d=c|0,h=f|0,c=i|0,f=a|0,i=o|0,a=s|0;let P=ya(V,re,q);o=xa(P,I,X,ee),s=P|0}({h:o,l:s}=Pe(this.Ah|0,this.Al|0,o|0,s|0)),{h:i,l:a}=Pe(this.Bh|0,this.Bl|0,i|0,a|0),{h:c,l:f}=Pe(this.Ch|0,this.Cl|0,c|0,f|0),{h:d,l:h}=Pe(this.Dh|0,this.Dl|0,d|0,h|0),{h:l,l:p}=Pe(this.Eh|0,this.El|0,l|0,p|0),{h:y,l:g}=Pe(this.Fh|0,this.Fl|0,y|0,g|0),{h:m,l:v}=Pe(this.Gh|0,this.Gl|0,m|0,v|0),{h:T,l:E}=Pe(this.Hh|0,this.Hl|0,T|0,E|0),this.set(o,s,i,a,c,f,d,h,l,p,y,g,m,v,T,E)}roundClean(){je(gt,bt)}destroy(){this.destroyed=!0,je(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},xs=class extends ys{constructor(){super(64,Aa)}};var gs=Nr(()=>new ps,is(1));var bs=Nr(()=>new xs,is(3));var Uu=t=>Object.freeze(t());function Ru(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function Pn(t){if(!Ru(t))throw new TypeError("Uint8Array expected")}function Ua(t){if(typeof t!="function")throw new TypeError("function expected");return!0}function Ku(t,e){if(typeof e!="string")throw new TypeError(`${t}: string expected`);return!0}function Fu(t,e="number"){if(typeof t!="number")throw new TypeError(`${e}: expected number, got ${typeof t}`);if(!Number.isSafeInteger(t))throw new RangeError(`${e}: expected safe integer, got ${t}`)}function Ra(...t){let e=s=>s,r=(s,i)=>a=>s(i(a)),n=t.map(s=>s.encode).reduceRight(r,e),o=t.map(s=>s.decode).reduce(r,e);return{encode:n,decode:o}}var Oa=(()=>{try{let t=new TextDecoder;return t.decode(Uint8Array.of(65,48,43,127))==="A0+\x7F"?t:void 0}catch{return}})(),ms=8192;function Cu(t){let e=t.length;if(Oa!==void 0&&e>=12)return Oa.decode(t);if(e<=ms)return String.fromCharCode.apply(null,t);let r="";for(let n=0;n<e;n+=ms)r+=String.fromCharCode.apply(null,t.subarray(n,n+ms));return r}function Du(t,e){let r=t.length;if(r>128)throw new Error("alphabet: max 128 letters");let n=new Uint8Array(r),o=new Int8Array(128).fill(-1);for(let s=0;s<r;s++){let i=t.charCodeAt(s);if(t.codePointAt(s)!==i||i>127)throw new Error("alphabet: single-char ASCII letters only");n[s]=i,o[i]=s}if(e!==void 0)for(let s of Object.keys(e)){let i=s.charCodeAt(0),a=o[e[s].charCodeAt(0)];if(s.length!==1||i>127||a===void 0||a===-1)throw new Error(`alphabet: invalid alias ${s}`);o[i]=a}return{encode:s=>{let i=new Uint8Array(s.length);for(let a=0;a<s.length;a++){let c=s[a],f=n[c];if(f===void 0)throw new Error(`alphabet.encode: invalid digit ${c}`);i[a]=f}return Cu(i)},decode:s=>{Ku("decode",s);let i=s.length,a=new Uint8Array(i);for(let c=0;c<i;c++){let f=s.charCodeAt(c),d=f<128?o[f]:-1;if(d===-1)throw new Error(`Unknown letter "${s[c]}". Allowed: ${t}`);a[c]=d}return a}}}function Mu(t,e){if(Fu(t),t<=0)throw new RangeError(`checksum length must be positive: ${t}`);Ua(e);let r=e;return{encode(n){Pn(n);let o=r(n).slice(0,t),s=new Uint8Array(n.length+t);return s.set(n),s.set(o,n.length),s},decode(n){Pn(n);let o=n.slice(0,-t),s=n.slice(-t),i=r(o).slice(0,t);for(let a=0;a<t;a++)if(i[a]!==s[a])throw new Error("Invalid checksum");return o}}}var Ia=656356768,Nu={encode:t=>{Pn(t);let e=t.length;if(e===0)return new Uint8Array(0);let r=0;for(;r<e-1&&t[r]===0;)r++;let n=Math.ceil(e/2),o=new Uint16Array(n),s=e&1;s&&(o[0]=t[0]);for(let l=s,p=s;l<e;l+=2,p++)o[p]=t[l]<<8|t[l+1];let i=[],a=0;for(;a<n;){let l=0;for(let p=a;p<n;p++){let y=l*65536+o[p],g=Math.floor(y/Ia);l=y-g*Ia,o[p]=g,g===0&&p===a&&a++}i.push(l)}let c=i.length-1,f=c*5;for(let l=i[c];f++,!(l<58);l=Math.floor(l/58));let d=new Uint8Array(r+f),h=d.length-1;for(let l=0;l<c;l++){let p=i[l];for(let y=0;y<5;y++)d[h--]=p%58,p=Math.floor(p/58)}for(let l=i[c];h>=r;l=Math.floor(l/58))d[h--]=l%58;return d},decode:t=>{Pn(t);let e=t.length;if(e===0)return new Uint8Array(0);if(e>=65536)throw new Error("invalid length");let r=0;for(;r<e-1&&t[r]===0;)r++;let n=new Uint16Array(Math.ceil(e*6/16)+1),o=0,s=0,i=e%5||5;for(;s<e;){let d=0,h=1;for(let p=s+i;s<p;s++){let y=t[s];if(y>=58)throw new Error(`invalid integer: ${y}`);d=d*58+y,h*=58}i=5;let l=d;for(let p=0;p<o;p++){let y=n[p]*h+l;l=Math.floor(y/65536),n[p]=y-l*65536}for(;l>0;l=Math.floor(l/65536))n[o++]=l%65536}let a=o===0?1:o*2-(n[o-1]<256?1:0),c=new Uint8Array(r+a),f=c.length-1;for(let d=0;d<o;d++){let h=n[d];c[f--]=h&255,f>=r&&(c[f--]=h>>8)}return c}},$u=t=>Ra(Nu,Du(t)),ju=Uu(()=>$u("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"));var Ka=t=>{Ua(t);let e=t;return Ra(Mu(4,r=>e(e(r))),ju)};var zr=cr.Point,Pr=zr.Fn,ws=Ka(gs),Pu=Uint8Array.from("Bitcoin seed".split(""),t=>t.charCodeAt(0)),Es={private:76066276,public:76067358},As=2147483648,zu=t=>Ha(gs(t)),qu=t=>yt(t).getUint32(0,!1),fr=(t,e="number")=>{if(typeof t!="number")throw new TypeError(`"${e}" expected number, got type=${typeof t}`);if(!Number.isSafeInteger(t)||t<0||t>2**32-1)throw new RangeError(`"${e}" expected integer in range 0..2**32-1, got ${t}`);let r=new Uint8Array(4);return yt(r).setUint32(0,t,!1),r},Ss=(t,e="versions")=>{if(!(typeof t=="object"&&t!==null))throw new Error("versions must be an object");return fr(t.private,`${e}.private`),fr(t.public,`${e}.public`),t},zn=class t{constructor(e){u(this,"versions");u(this,"depth",0);u(this,"index",0);u(this,"chainCode",null);u(this,"parentFingerprint",0);u(this,"_privateKey");u(this,"_publicKey");u(this,"pubHash");if(!e||typeof e!="object")throw new Error("HDKey.constructor must not be called directly");if(this.versions=e.versions?Ss(e.versions):Es,this.depth=e.depth||0,this.chainCode=e.chainCode?Uint8Array.from(e.chainCode):null,this.index=e.index||0,this.parentFingerprint=e.parentFingerprint||0,!this.depth&&(this.parentFingerprint||this.index))throw new Error("HDKey: zero depth with non-zero index/parent fingerprint");if(this.depth>255)throw new Error("HDKey: depth exceeds the serializable value 255");if(e.publicKey&&e.privateKey)throw new Error("HDKey: publicKey and privateKey at same time.");if(e.privateKey){if(!cr.utils.isValidSecretKey(e.privateKey))throw new Error("Invalid private key");this._privateKey=Uint8Array.from(e.privateKey),this._publicKey=cr.getPublicKey(this._privateKey,!0)}else if(e.publicKey)this._publicKey=zr.fromBytes(e.publicKey).toBytes(!0);else throw new Error("HDKey: no public or private key provided");this.pubHash=zu(this._publicKey)}get fingerprint(){if(!this.pubHash)throw new Error("No publicKey set!");return qu(this.pubHash)}get identifier(){return this.pubHash}get pubKeyHash(){return this.pubHash}get privateKey(){return this._privateKey||null}get publicKey(){return this._publicKey||null}get privateExtendedKey(){let e=this._privateKey;if(!e)throw new Error("No private key");return ws.encode(this.serialize(this.versions.private,Mr(Uint8Array.of(0),e)))}get publicExtendedKey(){if(!this._publicKey)throw new Error("No public key");return ws.encode(this.serialize(this.versions.public,this._publicKey))}static fromMasterSeed(e,r=Es){if(Ae(e),r=Ss(r),8*e.length<128||8*e.length>512)throw new RangeError("HDKey: seed length must be between 128 and 512 bits; 256 bits is advised, got "+e.length);let n=cs(bs,Pu,e),o=n.slice(0,32),s=n.slice(32);return new t({versions:r,chainCode:s,privateKey:o})}static fromExtendedKey(e,r=Es){r=Ss(r);let n=ws.decode(e),o=yt(n),s=o.getUint32(0,!1),i={versions:r,depth:n[4],parentFingerprint:o.getUint32(5,!1),index:o.getUint32(9,!1),chainCode:n.slice(13,45)},a=n.slice(45),c=a[0]===0;if(s!==r[c?"private":"public"])throw new Error("Version mismatch");return c?new t({...i,privateKey:a.slice(1)}):new t({...i,publicKey:a})}static fromJSON(e){return t.fromExtendedKey(e.xpriv)}derive(e){if(!/^[mM]'?/.test(e))throw new Error('Path must start with "m" or "M"');if(/^[mM]'?$/.test(e))return this;let r=e.replace(/^[mM]'?\//,"").split("/"),n=this;for(let o of r){let s=/^(\d+)('?)$/.exec(o),i=s&&s[1];if(!s||s.length!==3||typeof i!="string")throw new Error("invalid child index: "+o);let a=+i;if(!Number.isSafeInteger(a)||a>=As)throw new Error("Invalid index");s[2]==="'"&&(a+=As),n=n.deriveChild(a)}return n}deriveChild(e,r){if(!this._publicKey||!this.chainCode)throw new Error("No publicKey or chainCode set");let n=fr(e,"index");if(e>=As){let c=this._privateKey;if(!c)throw new Error("Could not derive hardened child key");n=Mr(Uint8Array.of(0),c,n)}else n=Mr(this._publicKey,n);let o=r||cs(bs,this.chainCode,n);Ae(o,64);let s=o.slice(0,32),i=o.slice(32),a={versions:this.versions,chainCode:i,depth:this.depth+1,parentFingerprint:this.fingerprint,index:e};if(a.depth>255)throw new Error("HDKey: depth exceeds the serializable value 255");try{let c=Pr.fromBytes(s);if(this._privateKey){let f=Pr.create(Pr.fromBytes(this._privateKey)+c);if(!Pr.isValidNot0(f))throw new Error("The tweak was out of range or the resulted private key is invalid");a.privateKey=Pr.toBytes(f)}else{let f=zr.fromBytes(this._publicKey),d=c===0n?f:f.add(zr.BASE.multiply(c));if(d.equals(zr.ZERO))throw new Error("The tweak was equal to negative P, which made the result key invalid");a.publicKey=d.toBytes(!0)}return new t(a)}catch{return this.deriveChild(e+1)}}sign(e){if(!this._privateKey)throw new Error("No privateKey set!");return Ae(e,32),cr.sign(e,this._privateKey,{prehash:!1})}verify(e,r){if(Ae(e,32),Ae(r,64),!this._publicKey)throw new Error("No publicKey set!");return cr.verify(r,e,this._publicKey,{prehash:!1})}wipePrivateData(){return this._privateKey&&(this._privateKey.fill(0),this._privateKey=void 0),this}toJSON(){return{xpriv:this.privateExtendedKey,xpub:this.publicExtendedKey}}serialize(e,r){if(!this.chainCode)throw new Error("No chainCode set");return Ae(r,33),Mr(fr(e,"version"),new Uint8Array([this.depth]),fr(this.parentFingerprint,"parentFingerprint"),fr(this.index,"index"),this.chainCode,r)}};function Fa(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var vs=t=>t?`"${t}" `:"";function ze(t,e=""){if(typeof t!="number")throw new TypeError(vs(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(vs(e)+"expected integer >= 0, got "+t);return t}function mt(t,e,r=""){if(Fa(t)&&(e===void 0||t.length===e))return t;e!==void 0&&ze(e,"length");let n=Fa(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=vs(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function qn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(ze(t.outputLen),ze(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Ca=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)};function ur(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function Gn(t,e){mt(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function et(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function lr(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function _e(t,e){return t<<32-e|t>>>e}function Gu(t){if(typeof t!="string")throw new TypeError("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Bs(t,e=""){return typeof t=="string"?Gu(t):mt(t,void 0,e)}function ks(t,e,r="opts"){return Ca(t,"defaults"),e!==void 0&&Ca(e,r),Object.assign(t,e)}function Ts(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=ks({},e,"info");let r=(o,s)=>t(s).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 Da(t=32){ze(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 Ls=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});var Wn=class{constructor(e,r){u(this,"oHash");u(this,"iHash");u(this,"blockLen");u(this,"outputLen");u(this,"canXOF",!1);u(this,"finished",!1);u(this,"destroyed",!1);if(qn(e),mt(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),et(o)}update(e){return ur(this),this.iHash.update(e),this}digestInto(e){ur(this),Gn(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||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a,canXOF:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ma=(()=>{let t=((e,r,n)=>new Wn(e,r).update(n).digest());return t.create=(e,r)=>new Wn(e,r),t})();function Wu(t,e,r,n){qn(t);let o=ks({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:a}=o;if(ze(s,"c"),ze(i,"dkLen"),ze(a,"asyncTick"),s<1)throw new Error('"c" (iterations) must be >= 1');if(i<1)throw new Error('"dkLen" must be >= 1');if(i>(2**32-1)*t.outputLen)throw new Error("derived key too long");let c=Bs(e,"password"),f=Bs(r,"salt"),d=new Uint8Array(i),{iHash:h,oHash:l,outputLen:p}=Ma.create(t,c),y=new Uint8Array(p),g=Vu(h,l,f,y);return{c:s,dkLen:i,asyncTick:a,DK:d,outputLen:p,eng:g}}function Vu(t,e,r,n){let o=new Uint8Array(4),s=lr(o),i=t._cloneInto().update(r),a=e._cloneInto(),c=t._cloneInto,f=e._cloneInto;return{u1:(d,h)=>{s.setInt32(0,d,!1),i._cloneInto(a).update(o).digestInto(n),e._cloneInto(a).update(n).digestInto(n),h.set(n.subarray(0,h.length))},rounds:(d,h)=>{for(let l=1;l<d;l++){c.call(t,a).update(n).digestInto(n),f.call(e,a).update(n).digestInto(n);for(let p=0;p<h.length;p++)h[p]^=n[p]}},output:d=>(t.destroy(),e.destroy(),i.destroy(),a.destroy(),et(n),d)}}function Na(t,e,r,n){let{c:o,dkLen:s,DK:i,outputLen:a,eng:c}=Wu(t,e,r,n);for(let f=1,d=0;d<s;f++,d+=a){let h=i.subarray(d,d+a);c.u1(f,h),c.rounds(o,h)}return c.output(i)}var Vn=BigInt(4294967295),$a=BigInt(32);function Xu(t,e=!1){return e?{h:Number(t&Vn),l:Number(t>>$a&Vn)}:{h:Number(t>>$a&Vn)|0,l:Number(t&Vn)|0}}function ja(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=Xu(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var Yu=t=>t/2**32|0,Zu=t=>t>>>0;function Pa(t,e,r,n){let o=Yu(r),s=Zu(r);t.setUint32(e,n?s:o,n),t.setUint32(e+4,n?o:s,n)}var Hs=(t,e,r)=>t>>>r,_s=(t,e,r)=>t<<32-r|e>>>r,Nt=(t,e,r)=>t>>>r|e<<32-r,$t=(t,e,r)=>t<<32-r|e>>>r,qr=(t,e,r)=>t<<64-r|e>>>r-32,Gr=(t,e,r)=>t>>>r-32|e<<64-r;function qe(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var za=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),qa=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Ga=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Wa=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Va=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Xa=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;function Ya(t,e,r){return t&e^~t&r}function Za(t,e,r){return t&e^t&r^e&r}var Wr=class{constructor(e,r,n,o){u(this,"blockLen");u(this,"outputLen");u(this,"canXOF",!1);u(this,"padOffset");u(this,"isLE");u(this,"buffer");u(this,"view");u(this,"finished",!1);u(this,"length",0);u(this,"pos",0);u(this,"destroyed",!1);this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=lr(this.buffer)}update(e){ur(this),mt(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let f=lr(e);for(;o<=s-a;a+=o)this.process(f,a);i=!0;continue}n.set(a===0&&c===s?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){ur(this),Gn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>o-i&&(this.process(n,0),r.fill(0)),Pa(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=e===r?n:lr(e),c=this.outputLen,f=c/4,d=this.get();if(c%4||f>d.length)throw new Error("invalid outputLen");for(let h=0;h<f;h++)a.setUint32(4*h,d[h],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return e.destroyed=s,e.finished=o,e.length=n,e.pos=i,i&&e.buffer.set(r),e}clone(){return this._cloneInto()}},Ja=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Qa=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Qu=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]),wt=new Uint32Array(64),Os=class extends Wr{constructor(r,n){super(64,r,8,!1);u(this,"A",0);u(this,"B",0);u(this,"C",0);u(this,"D",0);u(this,"E",0);u(this,"F",0);u(this,"G",0);u(this,"H",0);this.A=n[0]|0,this.B=n[1]|0,this.C=n[2]|0,this.D=n[3]|0,this.E=n[4]|0,this.F=n[5]|0,this.G=n[6]|0,this.H=n[7]|0}get(){let{A:r,B:n,C:o,D:s,E:i,F:a,G:c,H:f}=this;return[r,n,o,s,i,a,c,f]}set(r,n,o,s,i,a,c,f){this.A=r|0,this.B=n|0,this.C=o|0,this.D=s|0,this.E=i|0,this.F=a|0,this.G=c|0,this.H=f|0}_cloneInto(r){return(r||(r=new this.constructor)).set(...this.get()),this._cloneIntoMeta(r)}process(r,n){for(let l=0;l<16;l++,n+=4)wt[l]=r.getUint32(n,!1);for(let l=16;l<64;l++){let p=wt[l-15],y=wt[l-2],g=_e(p,7)^_e(p,18)^p>>>3,m=_e(y,17)^_e(y,19)^y>>>10;wt[l]=m+wt[l-7]+g+wt[l-16]|0}let{A:o,B:s,C:i,D:a,E:c,F:f,G:d,H:h}=this;for(let l=0;l<64;l++){let p=_e(c,6)^_e(c,11)^_e(c,25),y=h+p+Ya(c,f,d)+Qu[l]+wt[l]|0,m=(_e(o,2)^_e(o,13)^_e(o,22))+Za(o,s,i)|0;h=d,d=f,f=c,c=a+y|0,a=i,i=s,s=o,o=y+m|0}o=o+this.A|0,s=s+this.B|0,i=i+this.C|0,a=a+this.D|0,c=c+this.E|0,f=f+this.F|0,d=d+this.G|0,h=h+this.H|0,this.set(o,s,i,a,c,f,d,h)}roundClean(){et(wt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),et(this.buffer)}},Is=class extends Os{constructor(){super(32,Ja)}};var ef=ja(["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))),el=ef[0],tl=ef[1],Et=new Uint32Array(80),At=new Uint32Array(80),Us=class extends Wr{constructor(r,n){super(128,r,16,!1);u(this,"Ah",0);u(this,"Al",0);u(this,"Bh",0);u(this,"Bl",0);u(this,"Ch",0);u(this,"Cl",0);u(this,"Dh",0);u(this,"Dl",0);u(this,"Eh",0);u(this,"El",0);u(this,"Fh",0);u(this,"Fl",0);u(this,"Gh",0);u(this,"Gl",0);u(this,"Hh",0);u(this,"Hl",0);this.Ah=n[0]|0,this.Al=n[1]|0,this.Bh=n[2]|0,this.Bl=n[3]|0,this.Ch=n[4]|0,this.Cl=n[5]|0,this.Dh=n[6]|0,this.Dl=n[7]|0,this.Eh=n[8]|0,this.El=n[9]|0,this.Fh=n[10]|0,this.Fl=n[11]|0,this.Gh=n[12]|0,this.Gl=n[13]|0,this.Hh=n[14]|0,this.Hl=n[15]|0}get(){let{Ah:r,Al:n,Bh:o,Bl:s,Ch:i,Cl:a,Dh:c,Dl:f,Eh:d,El:h,Fh:l,Fl:p,Gh:y,Gl:g,Hh:m,Hl:v}=this;return[r,n,o,s,i,a,c,f,d,h,l,p,y,g,m,v]}set(r,n,o,s,i,a,c,f,d,h,l,p,y,g,m,v){this.Ah=r|0,this.Al=n|0,this.Bh=o|0,this.Bl=s|0,this.Ch=i|0,this.Cl=a|0,this.Dh=c|0,this.Dl=f|0,this.Eh=d|0,this.El=h|0,this.Fh=l|0,this.Fl=p|0,this.Gh=y|0,this.Gl=g|0,this.Hh=m|0,this.Hl=v|0}_cloneInto(r){return(r||(r=new this.constructor)).set(...this.get()),this._cloneIntoMeta(r)}process(r,n){for(let x=0;x<16;x++,n+=4)Et[x]=r.getUint32(n),At[x]=r.getUint32(n+=4);for(let x=16;x<80;x++){let O=Et[x-15]|0,F=At[x-15]|0,G=Nt(O,F,1)^Nt(O,F,8)^Hs(O,F,7),W=$t(O,F,1)^$t(O,F,8)^_s(O,F,7),j=Et[x-2]|0,I=At[x-2]|0,V=Nt(j,I,19)^qr(j,I,61)^Hs(j,I,6),X=$t(j,I,19)^Gr(j,I,61)^_s(j,I,6),re=Ga(W,X,At[x-7],At[x-16]),ee=Wa(re,G,V,Et[x-7],Et[x-16]);Et[x]=ee|0,At[x]=re|0}let{Ah:o,Al:s,Bh:i,Bl:a,Ch:c,Cl:f,Dh:d,Dl:h,Eh:l,El:p,Fh:y,Fl:g,Gh:m,Gl:v,Hh:T,Hl:E}=this;for(let x=0;x<80;x++){let O=Nt(l,p,14)^Nt(l,p,18)^qr(l,p,41),F=$t(l,p,14)^$t(l,p,18)^Gr(l,p,41),G=l&y^~l&m,W=p&g^~p&v,j=Va(E,F,W,tl[x],At[x]),I=Xa(j,T,O,G,el[x],Et[x]),V=j|0,X=Nt(o,s,28)^qr(o,s,34)^qr(o,s,39),re=$t(o,s,28)^Gr(o,s,34)^Gr(o,s,39),ee=o&i^o&c^i&c,q=s&a^s&f^a&f;T=m|0,E=v|0,m=y|0,v=g|0,y=l|0,g=p|0,{h:l,l:p}=qe(d|0,h|0,I|0,V|0),d=c|0,h=f|0,c=i|0,f=a|0,i=o|0,a=s|0;let P=za(V,re,q);o=qa(P,I,X,ee),s=P|0}({h:o,l:s}=qe(this.Ah|0,this.Al|0,o|0,s|0)),{h:i,l:a}=qe(this.Bh|0,this.Bl|0,i|0,a|0),{h:c,l:f}=qe(this.Ch|0,this.Cl|0,c|0,f|0),{h:d,l:h}=qe(this.Dh|0,this.Dl|0,d|0,h|0),{h:l,l:p}=qe(this.Eh|0,this.El|0,l|0,p|0),{h:y,l:g}=qe(this.Fh|0,this.Fl|0,y|0,g|0),{h:m,l:v}=qe(this.Gh|0,this.Gl|0,m|0,v|0),{h:T,l:E}=qe(this.Hh|0,this.Hl|0,T|0,E|0),this.set(o,s,i,a,c,f,d,h,l,p,y,g,m,v,T,E)}roundClean(){et(Et,At)}destroy(){this.destroyed=!0,et(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Rs=class extends Us{constructor(){super(64,Qa)}};var tf=Ts(()=>new Is,Ls(1));var rf=Ts(()=>new Rs,Ls(3));var rl=t=>t[0]==="\u3042\u3044\u3053\u304F\u3057\u3093";function nf(t){if(typeof t!="string")throw new TypeError("invalid mnemonic type: "+typeof t);return t.normalize("NFKD")}function of(t){let e=nf(t),r=e.split(" ");if(![12,15,18,21,24].includes(r.length))throw new Error("Invalid mnemonic");return{nfkd:e,words:r}}function sf(t){if(mt(t),![16,20,24,28,32].includes(t.length))throw new RangeError("invalid entropy length")}function cf(t,e=128){if(ze(e),e%32!==0||e>256)throw new RangeError("Invalid entropy");return il(Da(e/8),t)}var af=t=>{let e=8-t.length/4;return tf(t)[0]>>e<<e};function ff(t){if(!Array.isArray(t)||t.length!==2048||typeof t[0]!="string")throw new TypeError("Wordlist: expected array of 2048 strings");t.forEach(e=>{if(typeof e!="string")throw new TypeError("wordlist: non-string element: "+e)})}function nl(t,e){ff(e);let r=new Uint8Array(t.length+1);r.set(t),r[t.length]=af(t);let n=[],o=0,s=0;for(let i of r)o=o<<8|i,s+=8,s>=11&&(s-=11,n.push(e[o>>>s&2047]),o&=(1<<s)-1);return n}function ol(t,e){ff(e);let r=t.length/3*4,n=new Uint8Array(r+1),o=0,s=0,i=0;for(let c of t){let f=e.indexOf(c);if(f===-1)throw new Error("Unknown word: "+c);for(o=o<<11|f,s+=11;s>=8;)s-=8,n[i++]=o>>>s&255;o&=(1<<s)-1}s>0&&(n[i]=o<<8-s);let a=n.subarray(0,r);if(n[r]!==af(a))throw new Error("Invalid checksum");return Uint8Array.from(a)}function sl(t,e){let{words:r}=of(t),n=ol(r,e);return sf(n),n}function il(t,e){return sf(t),nl(t,e).join(rl(e)?"\u3000":" ")}function uf(t,e){try{sl(t,e)}catch{return!1}return!0}var cl=t=>{if(typeof t!="string")throw new TypeError("invalid passphrase type: "+typeof t);return nf("mnemonic"+t)};function lf(t,e=""){return Na(rf,of(t).nfkd,cl(e),{c:2048,dkLen:64})}var Ks=Object.freeze(`abandon
1
+ "use strict";var LumenKeys=(()=>{var Br=Object.defineProperty;var Ji=Object.getOwnPropertyDescriptor;var Qi=Object.getOwnPropertyNames;var ec=Object.prototype.hasOwnProperty;var tc=(t,e,r)=>e in t?Br(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var Ne=(t,e)=>()=>(t&&(e=t(t=0)),e);var Do=(t,e)=>{for(var r in e)Br(t,r,{get:e[r],enumerable:!0})},rc=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Qi(e))!ec.call(t,o)&&o!==r&&Br(t,o,{get:()=>e[o],enumerable:!(n=Ji(e,o))||n.enumerable});return t};var nc=t=>rc(Br({},"__esModule",{value:!0}),t);var h=(t,e,r)=>tc(t,typeof e!="symbol"?e+"":e,r);function _t(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function se(t,e=""){if(typeof t!="number")throw new TypeError(Lr(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Lr(e)+"expected integer >= 0, got "+t);return t}function ys(t,e=""){if(typeof t!="boolean")throw new TypeError(Lr(e)+"expected boolean, got type="+typeof t);return t}function j(t,e,r=""){if(_t(t)&&(e===void 0||t.length===e))return t;e!==void 0&&se(e,"length");let n=_t(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=Lr(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function Qe(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(se(t.outputLen),se(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}function He(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function Ut(t,e){j(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Kn(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function ge(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Ue(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Ie(t,e){return t<<32-e|t>>>e}function nr(t,e){return t<<e|t>>>32-e>>>0}function Kc(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function Ic(t){for(let e=0;e<t.length;e++)t[e]=Kc(t[e]);return t}function Fr(t){if(j(t),ms)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Rc[t[r]];return e}function ps(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function Rn(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(ms)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,s=0;o<r;o++,s+=2){let i=ps(t.charCodeAt(s)),a=ps(t.charCodeAt(s+1));if(i===void 0||a===void 0){let c=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Oc(t){if(typeof t!="string")throw new TypeError("string expected");return new Uint8Array(new TextEncoder().encode(t))}function On(t,e=""){return typeof t=="string"?Oc(t):j(t,void 0,e)}function Ce(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];j(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function or(t,e,r="opts"){return hs(t,"defaults"),e!==void 0&&hs(e,r),Object.assign(t,e)}function et(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=or({},e,"info");let r=(o,s)=>t(s).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 Ct(t=32){se(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 Lr,hs,gs,In,ms,Rc,gt,Be=Ne(()=>{Lr=t=>t?`"${t}" `:"";hs=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)};gs=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;In=gs?t=>t:Ic,ms=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Rc=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));gt=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])})});function _c(t,e=!1){return e?{h:Number(t&Pr),l:Number(t>>bs&Pr)}:{h:Number(t>>bs&Pr)|0,l:Number(t&Pr)|0}}function Nr(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=_c(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}function ws(t,e,r,n){let o=Uc(r),s=Cc(r);t.setUint32(e,n?s:o,n),t.setUint32(e+4,n?o:s,n)}function Le(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Pr,bs,Uc,Cc,_n,Un,mt,bt,sr,ir,xs,Es,vs,Ss,ks,As,Dr=Ne(()=>{Pr=BigInt(4294967295),bs=BigInt(32);Uc=t=>t/2**32|0,Cc=t=>t>>>0;_n=(t,e,r)=>t>>>r,Un=(t,e,r)=>t<<32-r|e>>>r,mt=(t,e,r)=>t>>>r|e<<32-r,bt=(t,e,r)=>t<<32-r|e>>>r,sr=(t,e,r)=>t<<64-r|e>>>r-32,ir=(t,e,r)=>t>>>r-32|e<<64-r;xs=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Es=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,vs=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Ss=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,ks=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),As=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0});function Gc(t,e=24){if(!(t instanceof Uint32Array))throw new TypeError('"s" expected Uint32Array(50), got type='+typeof t);if(t.length!==50)throw new RangeError('"s" expected Uint32Array(50), got length='+t.length);if(se(e,"rounds"),e<1||e>24)throw new Error('"rounds" expected integer 1..24');for(let r=24-e;r<24;r++){for(let s=0;s<10;s++)Lt[s]=t[s]^t[s+10]^t[s+20]^t[s+30]^t[s+40];for(let s=0;s<10;s+=2){let i=(s+8)%10,a=(s+2)%10,c=Lt[a],f=Lt[a+1],u=Is(c,f,1)^Lt[i],d=Rs(c,f,1)^Lt[i+1];for(let l=0;l<50;l+=10)t[s+l]^=u,t[s+l+1]^=d}let n=t[2],o=t[3];for(let s=0;s<24;s++){let i=_s[s],a=Is(n,o,i),c=Rs(n,o,i),f=Os[s];n=t[f],o=t[f+1],t[f]=a,t[f+1]=c}for(let s=0;s<50;s+=10){let i=t[s],a=t[s+1],c=t[s+2],f=t[s+3];t[s]^=~t[s+2]&t[s+4],t[s+1]^=~t[s+3]&t[s+5],t[s+2]^=~t[s+4]&t[s+6],t[s+3]^=~t[s+5]&t[s+7],t[s+4]^=~t[s+6]&t[s+8],t[s+5]^=~t[s+7]&t[s+9],t[s+6]^=~t[s+8]&i,t[s+7]^=~t[s+9]&a,t[s+8]^=~i&c,t[s+9]^=~a&f}t[0]^=zc[r],t[1]^=qc[r]}ge(Lt)}var Nc,cr,Dc,$c,Hc,jc,Os,_s,Us,Cs,zc,qc,Vc,Wc,Zc,Yc,Is,Rs,Lt,$r,Xc,Ls,Fs,Ms,be,Hr=Ne(()=>{Dr();Be();Nc=BigInt(0),cr=BigInt(1),Dc=BigInt(2),$c=BigInt(7),Hc=BigInt(256),jc=BigInt(113),Os=[],_s=[],Us=[];for(let t=0,e=cr,r=1,n=0;t<24;t++){[r,n]=[n,(2*r+3*n)%5],Os.push(2*(5*n+r)),_s.push((t+1)*(t+2)/2%64);let o=Nc;for(let s=0;s<7;s++)e=(e<<cr^(e>>$c)*jc)%Hc,e&Dc&&(o^=cr<<(cr<<BigInt(s))-cr);Us.push(o)}Cs=Nr(Us,!0),zc=Cs[0],qc=Cs[1],Vc=(t,e,r)=>t<<r|e>>>32-r,Wc=(t,e,r)=>e<<r|t>>>32-r,Zc=(t,e,r)=>e<<r-32|t>>>64-r,Yc=(t,e,r)=>t<<r-32|e>>>64-r,Is=(t,e,r)=>r>32?Zc(t,e,r):Vc(t,e,r),Rs=(t,e,r)=>r>32?Yc(t,e,r):Wc(t,e,r),Lt=new Uint32Array(10);$r=class t{constructor(e,r,n,o=!1,s=24){h(this,"state");h(this,"pos",0);h(this,"posOut",0);h(this,"finished",!1);h(this,"state32");h(this,"destroyed",!1);h(this,"blockLen");h(this,"suffix");h(this,"outputLen");h(this,"canXOF");h(this,"enableXOF",!1);h(this,"rounds");if(se(e,"blockLen"),se(r,"suffix"),se(s,"rounds"),ys(o,"enableXOF"),this.blockLen=e,this.suffix=r,this.outputLen=n,this.enableXOF=o,this.canXOF=o,this.rounds=s,se(n,"outputLen"),!(0<e&&e<200))throw new Error('"blockLen" must be 1..199');this.state=new Uint8Array(200),this.state32=Kn(this.state)}clone(){return this._cloneInto()}keccak(){In(this.state32),Gc(this.state32,this.rounds),In(this.state32),this.posOut=0,this.pos=0}update(e){He(this),j(e);let{blockLen:r,state:n,state32:o}=this,s=e.length,i=r%4===0&&e.byteOffset%4===0,a=r/4,c=i&&s>=r?Kn(e):void 0;for(let f=0;f<s;){if(c!==void 0&&this.pos===0&&f%4===0&&s-f>=r){for(let d=0,l=f/4;d<a;d++)o[d]^=c[l+d];f+=r,this.pos=r,this.keccak();continue}let u=Math.min(r-this.pos,s-f);for(let d=0;d<u;d++)n[this.pos++]^=e[f++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:r,pos:n,blockLen:o}=this;e[n]^=r,(r&128)!==0&&n===o-1&&this.keccak(),e[o-1]^=128,this.keccak()}writeInto(e){He(this,!1),j(e),this.finish();let r=this.state,{blockLen:n}=this;for(let o=0,s=e.length;o<s;){this.posOut>=n&&this.keccak();let i=Math.min(n-this.posOut,s-o);e.set(r.subarray(this.posOut,this.posOut+i),o),this.posOut+=i,o+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not enabled");return this.writeInto(e)}xof(e){return se(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Ut(e,this),this.finished)throw new Error("digest() was already called");this.writeInto(e.length===this.outputLen?e:e.subarray(0,this.outputLen)),this.destroy()}digest(){let e=new Uint8Array(this.outputLen);return this.digestInto(e),e}destroy(){this.destroyed=!0,ge(this.state)}_cloneInto(e){let{blockLen:r,suffix:n,outputLen:o,rounds:s,enableXOF:i}=this;return e||(e=new t(r,n,o,i,s)),e.blockLen=r,e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=s,e.suffix=n,e.outputLen=o,e.enableXOF=i,e.canXOF=this.canXOF,e.destroyed=this.destroyed,e}},Xc=(t,e,r,n={})=>et(()=>new $r(e,t,r),n),Ls=Xc(6,136,32,gt(8)),Fs=(t,e,r,n={})=>et((o={})=>(o=or({},o),new $r(e,t,o.dkLen===void 0?r:o.dkLen,!0)),n),Ms=Fs(31,168,16,gt(11)),be=Fs(31,136,32,gt(12))});function fr(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}function Ns(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function ot(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Et(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}function Te(t,e=""){if(typeof t!="boolean")throw new TypeError(Jc(e)+"expected boolean, got type="+typeof t);return t}function Wr(t){if(typeof t=="bigint"){if(!st(t))throw new RangeError("positive bigint expected, got "+t)}else Dn(t);return t}function Pt(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 ur(t){let e=Wr(t).toString(16);return e.length&1?"0"+e:e}function Ds(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?zr:BigInt("0x"+t)}function Fe(t){return Ds(Fr(t))}function Hn(t){return Ds(Fr(Qc(j(t)).reverse()))}function Zr(t,e){if(se(e),e===0)throw new Error("zero output length is invalid");t=Wr(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return Rn(n.padStart(r,"0"))}function jn(t,e){return Zr(t,e).reverse()}function Qc(t){return Uint8Array.from(ue(t))}function st(t){return typeof t=="bigint"&&zr<=t}function zn(t,e,r){return st(t)&&st(e)&&st(r)&&e<=t&&t<r}function qn(t,e,r,n){if(!zn(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Nt(t){if(t<zr)throw new Error("expected non-negative bigint, got "+t);return t===zr?0:t.toString(2).length}function $s(t,e,r){if(se(t,"hashLen"),se(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=A=>new Uint8Array(A),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),f=n(t),u=0,d=()=>{c.fill(1),f.fill(0),u=0},l=(...A)=>r(f,ze(c,...A)),p=(A=o)=>{f=l(s,A),c=l(),A.length!==0&&(f=l(i,A),c=l())},y=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let A=0,_=[];for(;A<e;){c=l();let I=c.slice();_.push(I),A+=c.length}return ze(..._)};return(A,_)=>{d(),p(A);let I;for(;(I=_(y()))===void 0;)p();return d(),I}}function Me(t,e={},r={},n="object"){ot(t,n),ot(e,"fields"),ot(r,"optFields");function o(i,a,c){let f=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,u=t[i];if(!Object.hasOwn(t,i)&&(c?u!==void 0:a!=="function"))throw new TypeError(`${f} is invalid: expected own property`);if(c&&u===void 0)return;let d=typeof u;if(d!==a||u===null)throw new TypeError(`${f} is invalid: expected ${a}, got ${d}`)}let s=(i,a)=>Object.entries(i).forEach(([c,f])=>o(c,f,a));s(e,!1),s(r,!0)}var ue,Dn,$n,ze,qr,Mt,Vr,zr,Ps,Jc,lr,vt=Ne(()=>{Be();ue=(t,e,r)=>j(t,e,r),Dn=se;$n=Fr,ze=(...t)=>Ce(...t),qr=t=>Rn(t),Mt=_t,Vr=t=>Ct(t),zr=BigInt(0),Ps=BigInt(1),Jc=t=>t?`"${t}" `:"";lr=t=>(Pt(t,"n"),(Ps<<BigInt(t))-Ps)});function ve(t,e){if(e<=le)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=le?r:e+r}function Ys(t,e,r){if(r<=G)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<le)throw new Error("invalid exponent, negatives unsupported");if(e===le)return G;if(e===G)return t;let n=t%r;if(n<le&&(n+=r),e<na){let a=G;for(;e>le;)e&G&&(a=a*n%r),n=n*n%r,e>>=G;return a}let o=[];for(;e>le;)o.push(Number(e&ra)),e>>=Vn;let s=new Array(16);s[0]=G,s[1]=n;for(let a=2;a<16;a++)s[a]=s[a-1]*n%r;let i=s[o[o.length-1]];for(let a=o.length-2;a>=0;a--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let c=o[a];c!==0&&(i=i*s[c]%r)}return i}function Se(t,e,r){if(r<=G)throw new Error("pow2: expected modulus > 1, got "+r);if(e<le)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >le;)n*=n,n%=r;return n}function Hs(t,e){if(t===le)throw new Error("invert: expected non-zero number");if(e<=G)throw new Error("invert: expected modulus > 1, got "+e);let r=ve(t,e),n=e,o=le,s=G;for(;r!==le;){let a=n/r,c=n-r*a,f=o-s*a;n=r,r=c,o=s,s=f}if(n!==G)throw new Error("invert: does not exist");return ve(o,e)}function Gs(t,e){if(e<=G)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=ve(t,e);if(r===le)throw new Error("invertCt: expected non-zero number");let n=Ys(r,e-it,e);if(ve(r*n,e)!==G)throw new Error("invertCt: does not exist");return n}function Wn(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Zn(t,e){if((t&G)===le)throw new Error(e+": expected odd modulus, got "+t)}function Xs(t,e){let r=t,n=(r.ORDER+G)/Vn,o=r.pow(e,n);return Wn(r,o,e),o}function oa(t,e){let r=t,n=(r.ORDER-Vs)/Ws,o=r.mul(e,it),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,it),s),c=r.mul(i,r.sub(a,r.ONE));return Wn(r,c,e),c}function sa(t){let e=$t(t),r=Js(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+ea)/Zs;return((a,c)=>{let f=a,u=f.pow(c,i),d=f.mul(u,n),l=f.mul(u,o),p=f.mul(u,s),y=f.eql(f.sqr(d),c),b=f.eql(f.sqr(l),c);u=f.cmov(u,d,y),d=f.cmov(p,l,b);let A=f.eql(f.sqr(d),c),_=f.cmov(u,d,A);return Wn(f,_,c),_})}function Js(t){if(t<qs)throw new Error("sqrt is not defined for small field");Zn(t,"tonelliShanks");let e=t-G,r=0;for(;e%it===le;)e/=it,r++;let n=it,o=$t(t);for(;js(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Xs;let s=o.pow(n,e),i=(e+G)/it;return function(c,f){let u=c;if(u.is0(f))return f;if(js(u,f)!==1)throw new Error("Cannot find square root");let d=r,l=u.mul(u.ONE,s),p=u.pow(f,e),y=u.pow(f,i);for(;!u.eql(p,u.ONE);){if(u.is0(p))throw new Error("Cannot find square root: probably non-prime P");let b=1,A=u.sqr(p);for(;!u.eql(A,u.ONE);)if(b++,A=u.sqr(A),b===d)throw new Error("Cannot find square root");let _=G<<BigInt(d-b-1),I=u.pow(l,_);d=b,l=u.sqr(I),p=u.mul(p,l),y=u.mul(y,I)}return y}}function ia(t){return Zn(t,"Fp.sqrt"),t%Vn===qs?Xs:t%Ws===Vs?oa:t%Zs===ta?sa(t):Js(t)}function Dt(t){if(ot(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);Pt(t.BYTES,"BYTES"),Pt(t.BITS,"BITS");for(let e of ca)Et(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=G)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Yn(t,e,r=!1){Dt(t),fr(e,"nums"),Te(r,"passZero");let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((a,c,f)=>n.is0(c)?a:(o[f]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return e.reduceRight((a,c,f)=>n.is0(c)?a:(o[f]=n.mul(a,o[f]),n.mul(a,c)),i),o}function js(t,e){Dt(t);let r=t;Zn(r.ORDER,"FpLegendre");let n=(r.ORDER-G)/it,o=r.pow(e,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function aa(t,e){if(e!==void 0&&Dn(e),t<=le)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Nt(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}function $t(t,e={}){return Object.freeze(Yr.prototype),new Yr(t,e)}function Qs(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=G)throw new Error("field order must be greater than 1");let e=Nt(t-G);return Math.ceil(e/8)}function Gr(t){let e=Qs(t);return e+Math.ceil(e/2)}function Xr(t,e,r=!1){ue(t);let n=t.length,o=Qs(e),s=Math.max(Gr(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Hn(t):Fe(t),a=ve(i,e-G)+G;return r?jn(a,o):Zr(a,o)}var le,G,it,qs,Vn,Vs,ea,Ws,ta,ra,Zs,na,ca,zs,Yr,Jr=Ne(()=>{vt();le=BigInt(0),G=BigInt(1),it=BigInt(2),qs=BigInt(3),Vn=BigInt(4),Vs=BigInt(5),ea=BigInt(7),Ws=BigInt(8),ta=BigInt(9),ra=BigInt(15),Zs=BigInt(16),na=BigInt("0x10000000000000000");ca=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];zs=new WeakMap,Yr=class{constructor(e,r={}){h(this,"ORDER");h(this,"BITS");h(this,"BYTES");h(this,"isLE");h(this,"ZERO",le);h(this,"ONE",G);h(this,"_lengths");h(this,"_mod");if(e<=G)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:s}=aa(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return ve(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return le<=e&&e<this.ORDER}is0(e){return e===le}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&G)===G}neg(e){return ve(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ve(e*e,this.ORDER)}add(e,r){return ve(e+r,this.ORDER)}sub(e,r){return ve(e-r,this.ORDER)}mul(e,r){return ve(e*r,this.ORDER)}pow(e,r){return Ys(e,r,this.ORDER)}div(e,r){return ve(e*Hs(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 Hs(e,this.ORDER)}sqrt(e){let r=zs.get(this);return r||zs.set(this,r=ia(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?jn(e,this.BYTES):Zr(e,this.BYTES)}fromBytes(e,r=!1){ue(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let f=new Uint8Array(o);f.set(e,s?0:f.length-e.length),e=f}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=s?Hn(e):Fe(e);if(a&&(c=ve(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Yn(this,e,!0)}cmov(e,r,n){return Te(n,"condition"),n?r:e}}});function hr(t,e="n"){if(typeof t!="number")throw new TypeError(`wrong u32 integer "${e}": expected number, got type=${typeof t}`);if(!Number.isSafeInteger(t)||t<0||t>4294967295)throw new RangeError(`wrong u32 integer "${e}": expected 0..4294967295, got ${t}`);return t}function fi(t){return hr(t,"x"),(t&t-1)===0&&t!==0}function eo(t,e){if(hr(t),typeof e!="number")throw new TypeError('"bits" expected number, got type='+typeof e);if(!Number.isSafeInteger(e)||e<0||e>32)throw new Error(`expected integer 0 <= bits <= 32, got ${e}`);let r=0;for(let n=0;n<e;n++,t>>>=1)r=r<<1|t&1;return r>>>0}function ui(t){return hr(t),31-Math.clz32(t)}function ai(t){if(!t||typeof t!="object"||typeof t.length!="number")throw new TypeError('"values" expected array-like, got type='+typeof t);let e=t.length;if(!fi(e))throw new Error("expected positive power-of-two length, got "+e);let r=ui(e);for(let n=0;n<e;n++){let o=eo(n,r);if(n<o){let s=t[n];t[n]=t[o],t[o]=s}}return t}var to,li=Ne(()=>{vt();to=(t,e)=>{Me(e,{N:"number",roots:"object",dit:"boolean"},{invertButterflies:"boolean",skipStages:"number",brp:"boolean"},"coreOpts");let{N:r,roots:n,dit:o,invertButterflies:s=!1,skipStages:i=0,brp:a=!0}=e;hr(r,"coreOpts.N");let c=ui(r);if(!fi(r))throw new Error("FFT: Polynomial size should be power of two");hr(i,"coreOpts.skipStages");let f=c===0?0:c-1;if(i>f)throw new Error(`FFT: wrong skipStages: expected 0 <= skipStages <= ${f}`);if(n.length!==r)throw new Error(`FFT: wrong roots length: expected ${r}, got ${n.length}`);let u=o!==s;return d=>{if(d.length!==r)throw new Error("FFT: wrong Polynomial length");o&&a&&ai(d);for(let l=0,p=1;l<c-i;l++){let y=o?l+1+i:c-l,b=1<<y,A=b>>1,_=r>>y;for(let I=0;I<r;I+=b)for(let E=0,S=p++;E<A;E++){let N=s?o?r-S:S:E*_,H=I+E,V=I+E+A,W=n[N],Z=d[V],D=d[H];if(u){let ee=t.mul(Z,W);d[H]=t.add(D,ee),d[V]=t.sub(D,ee)}else s?(d[H]=t.add(Z,D),d[V]=t.mul(t.sub(Z,D),W)):(d[H]=t.add(D,Z),d[V]=t.mul(t.sub(D,Z),W))}}return!o&&a&&ai(d),d}}});function ef(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}function tf(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function xo(t,e){if(t=j(t),e=j(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 Eo(t){if(_t(t))throw new TypeError('"opts" expected object, got Uint8Array');tf(t,"opts")}function on(t){Eo(t),t.context!==void 0&&j(t.context,void 0,"opts.context")}function sn(t){on(t),t.extraEntropy!==!1&&t.extraEntropy!==void 0&&j(t.extraEntropy,void 0,"opts.extraEntropy")}function gr(t,...e){let r=o=>typeof o=="number"?o:o.bytesLen,n=e.reduce((o,s)=>o+r(s),0);return{bytesLen:n,encode:o=>{let s=new Uint8Array(n);for(let i=0,a=0;i<e.length;i++){let c=e[i],f=r(c),u=typeof c=="number"?o[i]:c.encode(o[i]);j(u,f,t),s.set(u,a),typeof c!="number"&&u.fill(0),a+=f}return s},decode:o=>{j(o,n,t);let s=[];for(let i of e){let a=r(i),c=o.subarray(0,a);s.push(typeof i=="number"?c:i.decode(c)),o=o.subarray(a)}return s}}}function kt(t,e){let r=t,n=e*r.bytesLen;return{bytesLen:n,encode:o=>{let s=ef(o,"u");if(s.length!==e)throw new RangeError(`vecCoder.encode: wrong length=${s.length}. Expected: ${e}`);let i=new Uint8Array(n);for(let a=0,c=0;a<s.length;a++){let f=r.encode(s[a]);i.set(f,c),f.fill(0),c+=f.length}return i},decode:o=>{j(o,n);let s=[];for(let i=0;i<o.length;i+=r.bytesLen)s.push(r.decode(o.subarray(i,i+r.bytesLen)));return s}}}function ke(...t){for(let e of t)if(Array.isArray(e))for(let r of e)r.fill(0);else e.fill(0)}function vo(t){if(se(t,"bits"),t>32)throw new RangeError('"bits" expected <= 32, got '+t);return t===32?4294967295:~(-1<<t)>>>0}function So(t,e=Hi){if(j(t,void 0,"msg"),j(e,void 0,"ctx"),e.length>255)throw new RangeError("context should be 255 bytes or less");return Ce(new Uint8Array([0,e.length]),e,t)}function ko(t,e=0){if(typeof t!="function"||typeof t.create!="function")throw new TypeError('"hash" expected hash function, got type='+typeof t);Qe(t),se(e,"requiredStrength");let r=t.oid;if(j(r,void 0,"hash.oid"),!xo(r.subarray(0,10),rf))throw new Error('"hash.oid" is invalid: expected NIST hash');let n=t.outputLen*8/2;if(e>n)throw new Error("Pre-hash security strength too low: "+n+", required: "+e)}function Ao(t,e,r=Hi){if(ko(t),j(e,void 0,"msg"),j(r,void 0,"ctx"),r.length>255)throw new RangeError("context should be 255 bytes or less");let n=t(e);return Ce(new Uint8Array([1,r.length]),r,t.oid,n)}var ct,wo,Hi,rf,Bo=Ne(()=>{Be();ct=j,wo=Ct;Hi=Uint8Array.of();rf=Uint8Array.from([6,9,96,134,72,1,101,3,4,2])});var ji,zi,cn,an,qi=Ne(()=>{li();Hr();Bo();ji=t=>{let{newPoly:e,N:r,Q:n,F:o,ROOT_OF_UNITY:s,brvBits:i,isKyber:a}=t,c=(E,S=n)=>{let N=E%S|0;return(N>=0?N|0:S+N|0)|0},f=(E,S=n)=>{let N=c(E,S)|0;return(N>S>>1?N-S|0:N)|0};function u(){let E=e(r);for(let S=0;S<r;S++){let N=eo(S,i),H=BigInt(s)**BigInt(N)%BigInt(n);E[S]=Number(H)|0}return E}let d=u(),l=E=>{throw new Error("not implemented")},p=a?{add:(E,S)=>{let N=E+S|0;return N>=n?N-n|0:N},sub:(E,S)=>{let N=E-S|0;return N<0?N+n|0:N},mul:(E,S)=>c((E|0)*(S|0))|0,inv:l}:{add:(E,S)=>c((E|0)+(S|0))|0,sub:(E,S)=>c((E|0)-(S|0))|0,mul:(E,S)=>c((E|0)*(S|0))|0,inv:l},y={N:r,roots:d,invertButterflies:!0,skipStages:a?1:0,brp:!1},b=to(p,{dit:!1,...y}),A=to(p,{dit:!0,...y}),_={encode:E=>b(E),decode:E=>{A(E);for(let S=0;S<E.length;S++)E[S]=c(o*E[S]);return E}};return{mod:c,smod:f,nttZetas:d,NTT:{encode:E=>_.encode(E),decode:E=>_.decode(E)},bitsCoder:(E,S)=>{for(let V=0,W=0;V<r;V++)W+=E,W>32&&vo(W),W%=8;let N=vo(E),H=E*(r/8);return{bytesLen:H,encode:V=>{let W=V,Z=new Uint8Array(H);for(let D=0,ee=0,X=0,ye=0;D<W.length;D++)for(ee|=(S.encode(W[D])&N)<<X,X+=E;X>=8;X-=8,ee>>=8)Z[ye++]=ee&255;return Z},decode:V=>{let W=e(r);for(let Z=0,D=0,ee=0,X=0;Z<V.length;Z++)for(D|=V[Z]<<ee,ee+=8;ee>=E;ee-=E,D>>=E)W[X++]=S.decode(D&N);return W}}}}},zi=t=>(e,r)=>{r||(r=t.blockLen);let n=new Uint8Array(e.length+2);n.set(e);let o=e.length,s=new Uint8Array(r),i=t.create({}),a=0,c=0;return{stats:()=>({calls:a,xofs:c}),get:(f,u)=>(n[o+0]=f,n[o+1]=u,i.destroy(),i=t.create({}).update(n),a++,()=>(c++,i.xofInto(s))),clean:()=>{i.destroy(),ke(s,n)}}},cn=zi(Ms),an=zi(be)});var ln={};Do(ln,{PARAMS:()=>un,ml_dsa44:()=>cf,ml_dsa65:()=>af,ml_dsa87:()=>ff});function Vi(t){Eo(t),t.externalMu!==void 0&&Te(t.externalMu,"opts.externalMu")}function fn(t){let e=t,r=Ae(ie);for(let n=0;n<ie;){let o=e();if(o.length%3)throw new Error("RejNTTPoly: unaligned block");for(let s=0;n<ie&&s<=o.length-3;s+=3){let i=(o[s+0]|o[s+1]<<8|o[s+2]<<16)&8388607;i<ut&&(r[n++]=i)}}return r}function Io(t){let e=t,{K:r,L:n,GAMMA1:o,GAMMA2:s,TAU:i,ETA:a,OMEGA:c}=e,{CRH_BYTES:f,TR_BYTES:u,C_TILDE_BYTES:d,XOF128:l,XOF256:p,securityLevel:y}=e;if(![2,4].includes(a))throw new Error("Wrong ETA");if(![1<<17,1<<19].includes(o))throw new Error("Wrong GAMMA1");if(![To,Ko].includes(s))throw new Error("Wrong GAMMA2");let b=i*a,A=g=>{let w=Y.mod(g),x=Y.smod(w,2*s)|0;return w-x===ut-1?{r1:0,r0:x-1|0}:{r1:Math.floor((w-x)/(2*s))|0,r0:x}},_=g=>A(g).r1,I=g=>A(g).r0,E=(g,w)=>g<=s||g>ut-s||g===ut-s&&w===0?0:1,S=Math.floor((ut-1)/(2*s)),N=(g,w)=>{let{r1:x,r0:v}=A(w);return g===1?v>0?Y.mod(x+1,S)|0:Y.mod(x-1,S)|0:x|0},H=g=>{let w=Y.mod(g),x=Y.smod(w,2**At)|0;return{r1:Math.floor((w-x)/2**At)|0,r0:x}},V={bytesLen:c+r,encode:g=>{let w=g;if(w===!1)throw new Error("hint.encode: hint is false");let x=new Uint8Array(c+r);for(let v=0,O=0;v<r;v++){for(let K=0;K<ie;K++)w[v][K]!==0&&(x[O++]=K);x[c+v]=O}return x},decode:g=>{let w=[],x=0;for(let v=0;v<r;v++){let O=Ae(ie);if(g[c+v]<x||g[c+v]>c)return!1;for(let K=x;K<g[c+v];K++){if(K>x&&g[K]<=g[K-1])return!1;O[g[K]]=1}x=g[c+v],w.push(O)}for(let v=x;v<c;v++)if(g[v]!==0)return!1;return w}},W=mr(a===2?3:4,g=>a-g,g=>{if(!(-a<=g&&g<=a))throw new Error(`malformed key s1/s3 ${g} outside of ETA range [${-a}, ${a}]`);return g}),Z=mr(13,g=>(1<<At-1)-g),D=mr(10),ee=mr(o===1<<17?18:20,g=>Y.smod(o-g)),X=mr(s===To?6:4),ye=kt(X,r),de=gr("publicKey",32,kt(D,r)),q=gr("secretKey",32,32,u,kt(W,n),kt(W,r),kt(Z,r)),z=gr("signature",d,kt(ee,n),V),k=a===2?g=>g<15?2-g%5:!1:g=>g<9?4-g:!1;function R(g){let w=g,x=Ae(ie);for(let v=0;v<ie;){let O=w();for(let K=0;v<ie&&K<O.length;K+=1){let P=k(O[K]&15),J=k(O[K]>>4&15);P!==!1&&(x[v++]=P),v<ie&&J!==!1&&(x[v++]=J)}}return x}let L=g=>{let w=Ae(ie),x=be.create({}).update(g),v=new Uint8Array(be.blockLen);x.xofInto(v);let O=v.slice(0,8);for(let K=ie-i,P=8,J=0,ae=0;K<ie;K++){let re=K+1;for(;re>K;)re=v[P++],!(P<be.blockLen)&&(x.xofInto(v),P=0);w[K]=w[re],w[re]=1-((O[J]>>ae++&1)<<1),ae>=8&&(J++,ae=0)}return w},T=g=>{let w=g,x=Ae(ie),v=Ae(ie);for(let O=0;O<w.length;O++){let{r0:K,r1:P}=H(w[O]);x[O]=K,v[O]=P}return{r0:x,r1:v}},m=(g,w)=>{let x=g,v=w;for(let O=0;O<ie;O++)x[O]=N(v[O],x[O]);return x},B=(g,w)=>{let x=g,v=w,O=Ae(ie),K=0;for(let P=0;P<ie;P++){let J=E(x[P],v[P]);O[P]=J,K+=J}return{v:O,cnt:K}},C=32,F=gr("seed",32,64,32),M=Object.freeze({info:Object.freeze({type:"internal-ml-dsa"}),lengths:Object.freeze({secretKey:q.bytesLen,publicKey:de.bytesLen,seed:32,signature:z.bytesLen,signRand:C}),keygen:g=>{let w=new Uint8Array(34),x=g===void 0;x&&(g=wo(32)),ct(g,32,"seed"),w.set(g),x&&ke(g),w[32]=r,w[33]=n;let[v,O,K]=F.decode(be(w,{dkLen:F.bytesLen})),P=p(O),J=[];for(let $=0;$<n;$++)J.push(R(P.get($&255,$>>8&255)));let ae=[];for(let $=n;$<n+r;$++)ae.push(R(P.get($&255,$>>8&255)));let re=J.map($=>Y.NTT.encode($.slice())),Q=[],fe=[],we=l(v),ce=Ae(ie);for(let $=0;$<r;$++){ke(ce);for(let pe=0;pe<n;pe++){let Ee=fn(we.get(pe,$));at(ce,ft(Ee,re[pe]))}Y.NTT.decode(ce);let{r0:ht,r1:ne}=T(at(ce,ae[$]));Q.push(ht),fe.push(ne)}let xe=de.encode([v,fe]),Oe=be(xe,{dkLen:u}),Pe=q.encode([v,K,Oe,J,ae,Q]);return we.clean(),P.clean(),ke(v,O,K,J,ae,re,ce,Q,fe,Oe,w),{publicKey:xe,secretKey:Pe}},getPublicKey:g=>{let[w,x,v,O,K,P]=q.decode(g),J=l(w),ae=O.map(fe=>Y.NTT.encode(fe.slice())),re=[],Q=Ae(ie);for(let fe=0;fe<r;fe++){Q.fill(0);for(let ce=0;ce<n;ce++){let xe=fn(J.get(ce,fe));at(Q,ft(xe,ae[ce]))}Y.NTT.decode(Q),at(Q,K[fe]);let{r1:we}=T(Q);re.push(we)}return J.clean(),ke(Q,ae,P,O,K),de.encode([w,re])},sign:(g,w,x={})=>{sn(x),Vi(x);let{extraEntropy:v,externalMu:O=!1}=x;O&&ct(g,f,"mu");let K=v===!1||v===void 0,P=v===!1?new Uint8Array(32):v===void 0?wo(C):v;ct(P,32,"extraEntropy");let J=(()=>{try{return q.decode(w)}catch(ne){throw K&&ke(P),ne}})(),[ae,re,Q,fe,we,ce]=J,xe=[],Oe=l(ae);for(let ne=0;ne<r;ne++){let pe=[];for(let Ee=0;Ee<n;Ee++)pe.push(fn(Oe.get(Ee,ne)));xe.push(pe)}Oe.clean();for(let ne=0;ne<n;ne++)Y.NTT.encode(fe[ne]);for(let ne=0;ne<r;ne++)Y.NTT.encode(we[ne]),Y.NTT.encode(ce[ne]);let Pe=O?g:be.create({dkLen:f}).update(Q).update(g).digest(),$=be.create({dkLen:f}).update(re).update(P).update(Pe).digest();K&&ke(P),ct($,f);let ht=p($,ee.bytesLen);e:for(let ne=0;;){let pe=[];for(let oe=0;oe<n;oe++,ne++)pe.push(ee.decode(ht.get(ne&255,ne>>8)()));let Ee=pe.map(oe=>Y.NTT.encode(oe.slice())),It=[];for(let oe=0;oe<r;oe++){let Gt=Ae(ie);for(let Ze=0;Ze<n;Ze++)at(Gt,ft(xe[oe][Ze],Ee[Ze]));Y.NTT.decode(Gt),It.push(Gt)}let bn=It.map(oe=>oe.map(_)),wn=be.create({dkLen:d}).update(Pe).update(ye.encode(bn)).digest(),kr=Y.NTT.encode(L(wn)),Ar=fe.map(oe=>ft(oe,kr));for(let oe=0;oe<n;oe++)if(at(Y.NTT.decode(Ar[oe]),pe[oe]),br(Ar[oe],o-b))continue e;let Mo=0,xn=[];for(let oe=0;oe<r;oe++){let Gt=Y.NTT.decode(ft(we[oe],kr)),Ze=Zi(It[oe],Gt).map(I);if(br(Ze,s-b))continue e;let Po=Y.NTT.decode(ft(ce[oe],kr));if(br(Po,s))continue e;at(Ze,Po);let No=B(Ze,bn[oe]);xn.push(No.v),Mo+=No.cnt}if(Mo>c)continue;ht.clean();let Xi=z.encode([wn,Ar,xn]);return ke(wn,Ar,xn,kr,bn,It,Ee,pe,$,fe,we,ce,...xe),O||ke(Pe),Xi}throw new Error("Unreachable code path reached, report this error")},verify:(g,w,x,v={})=>{Vi(v);let{externalMu:O=!1}=v;O&&ct(w,f,"mu");let[K,P]=de.decode(x),J=be(x,{dkLen:u});if(g.length!==z.bytesLen)return!1;let[ae,re,Q]=z.decode(g);if(Q===!1)return!1;for(let $=0;$<n;$++)if(br(re[$],o-b))return!1;let fe=O?w:be.create({dkLen:f}).update(J).update(w).digest(),we=Y.NTT.encode(L(ae)),ce=re.map($=>$.slice());for(let $=0;$<n;$++)Y.NTT.encode(ce[$]);let xe=[],Oe=l(K);for(let $=0;$<r;$++){let ht=ft(Y.NTT.encode(sf(P[$])),we),ne=Ae(ie);for(let Ee=0;Ee<n;Ee++){let It=fn(Oe.get(Ee,$));at(ne,ft(It,ce[Ee]))}let pe=Y.NTT.decode(Zi(ne,ht));xe.push(m(pe,Q[$]))}Oe.clean();let Pe=be.create({dkLen:d}).update(fe).update(ye.encode(xe)).digest();for(let $ of Q)if(!($.reduce((ne,pe)=>ne+pe,0)<=c))return!1;for(let $ of re)if(br($,o-b))return!1;return xo(ae,Pe)}});return Object.freeze({info:Object.freeze({type:"ml-dsa"}),internal:M,securityLevel:y,keygen:M.keygen,lengths:M.lengths,getPublicKey:M.getPublicKey,sign:(g,w,x={})=>{sn(x);let v=So(g,x.context),O=M.sign(v,w,x);return ke(v),O},verify:(g,w,x,v={})=>(on(v),ct(g,void 0,"signature"),M.verify(g,So(w,v.context),x)),prehash:g=>{ko(g,y);let w=g;return Object.freeze({info:Object.freeze({type:"hashml-dsa"}),securityLevel:y,lengths:M.lengths,keygen:M.keygen,getPublicKey:M.getPublicKey,sign:(x,v,O={})=>{sn(O);let K=Ao(w,x,O.context),P=M.sign(K,v,O);return ke(K),P},verify:(x,v,O,K={})=>(on(K),ct(x,void 0,"signature"),M.verify(x,Ao(w,v,K.context),O))})}})}var ie,ut,nf,of,At,To,Ko,un,Ae,Y,Wi,mr,at,Zi,sf,br,ft,cf,af,ff,dn=Ne(()=>{vt();Hr();qi();Bo();ie=256,ut=8380417,nf=1753,of=8347681,At=13,To=Math.floor((ut-1)/88)|0,Ko=Math.floor((ut-1)/32)|0,un=Object.freeze({2:Object.freeze({K:4,L:4,D:At,GAMMA1:2**17,GAMMA2:To,TAU:39,ETA:2,OMEGA:80}),3:Object.freeze({K:6,L:5,D:At,GAMMA1:2**19,GAMMA2:Ko,TAU:49,ETA:4,OMEGA:55}),5:Object.freeze({K:8,L:7,D:At,GAMMA1:2**19,GAMMA2:Ko,TAU:60,ETA:2,OMEGA:75})}),Ae=t=>new Int32Array(t),Y=ji({N:ie,Q:ut,F:of,ROOT_OF_UNITY:nf,newPoly:Ae,isKyber:!1,brvBits:8}),Wi=t=>t,mr=(t,e=Wi,r=Wi)=>Y.bitsCoder(t,{encode:n=>e(r(n)),decode:n=>r(e(n))}),at=(t,e)=>{let r=t,n=e;for(let o=0;o<r.length;o++)r[o]=Y.mod(r[o]+n[o]);return r},Zi=(t,e)=>{let r=t,n=e;for(let o=0;o<r.length;o++)r[o]=Y.mod(r[o]-n[o]);return r},sf=t=>{let e=t;for(let r=0;r<ie;r++)e[r]<<=At;return e},br=(t,e)=>{let r=t;for(let n=0;n<ie;n++)if(Math.abs(Y.smod(r[n]))>=e)return!0;return!1},ft=(t,e)=>{let r=t,n=e,o=Ae(ie);for(let s=0;s<r.length;s++)o[s]=Y.mod(r[s]*n[s]);return o};cf=Io({...un[2],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:32,XOF128:cn,XOF256:an,securityLevel:128}),af=Io({...un[3],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:48,XOF128:cn,XOF256:an,securityLevel:192}),ff=Io({...un[5],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:64,XOF128:cn,XOF256:an,securityLevel:256})});var gf={};Do(gf,{InMemoryKeyStorage:()=>dt,KeyRegistry:()=>Kt,createKeySDK:()=>Fo,default:()=>yf});var Zo=Object.freeze({p:0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,n:0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,h:1n,a:0n,b:7n,Gx:0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,Gy:0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n}),{p:yt,n:Ge,Gx:oc,Gy:sc,b:Yo}=Zo,me=32,Xt=64,Jt={publicKey:me+1,publicKeyUncompressed:Xt+1,signature:Xt,seed:me+me/2},te=(t="",e=Error)=>{let r=new e(t),{captureStackTrace:n}=Error;throw typeof n=="function"&&n(r,te),r},ic=t=>t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&t.BYTES_PER_ELEMENT===1,Ke=(t,e,r="")=>{let n=ic(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,a=s?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof t}`,f=i+"expected Uint8Array"+a+", got "+c;return n?te(f,RangeError):te(f,TypeError)}return t},Xe=t=>new Uint8Array(t),Go=(t,e)=>t.toString(16).padStart(e,"0"),Xo=t=>{let e="";for(let r of Ke(t))e+=Go(r,2);return e},De={_0:48,_9:57,A:65,F:70,a:97,f:102},$o=t=>t>=De._0&&t<=De._9?t-De._0:t>=De.A&&t<=De.F?t-(De.A-10):t>=De.a&&t<=De.f?t-(De.a-10):void 0,Jo=t=>{let e="hex invalid";if(typeof t!="string")return te(e);let r=t.length,n=r/2;if(r%2)return te(e);let o=Xe(n);for(let s=0,i=0;s<n;s++,i+=2){let a=$o(t.charCodeAt(i)),c=$o(t.charCodeAt(i+1));if(a===void 0||c===void 0)return te(e);o[s]=a*16+c}return o},Ho=()=>globalThis?.crypto?.subtle??te("crypto.subtle must be defined, consider polyfill"),Rt=(...t)=>{let e=0;for(let o of t)e+=Ke(o).length;let r=Xe(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r},Qo=(t=me)=>(globalThis?.crypto).getRandomValues(Xe(t)),Kr=BigInt,tr=(t,e,r,n="bad number: out of range")=>typeof t!="bigint"?te(n,TypeError):e<=t&&t<r?t:te(n,RangeError),U=(t,e=yt)=>{let r=t%e;return r>=0n?r:e+r},Ye=t=>U(t,Ge),kn=(t,e)=>{(t===0n||e<=0n)&&te("no inverse n="+t+" mod="+e);let r=U(t,e),n=e,o=0n,s=1n,i=1n,a=0n;for(;r!==0n;){let c=n/r,f=n%r,u=o-i*c,d=s-a*c;n=r,r=f,o=i,s=a,i=u,a=d}return n===1n?U(o,e):te("no inverse")},es=t=>{let e=Ur[t];return typeof e!="function"&&te("hashes."+t+" not set"),e},ts=(t,e,r)=>Ke(es(t)(e,r),me,"digest"),cc=(t,e,r)=>Promise.resolve(es(t)(e,r)).then(n=>Ke(n,me,"digest"));var En=t=>t instanceof $e?t:te("Point expected"),rs=t=>U(U(t*t)*t+Yo),jo=t=>tr(t,0n,yt),Tr=t=>tr(t,1n,yt),vn=t=>tr(t,1n,Ge),ns=t=>!(t&1n),rr=t=>Uint8Array.of(t),ac=t=>rr(ns(t)?2:3),fc=t=>{let e=rs(Tr(t)),r=1n;for(let n=e,o=(yt+1n)/4n;o>0n;o>>=1n)o&1n&&(r=r*n%yt),n=n*n%yt;return U(r*r)!==e&&te("sqrt invalid"),ns(r)?r:U(-r)};var _e=class _e{constructor(e,r,n){h(this,"X");h(this,"Y");h(this,"Z");this.X=jo(e),this.Y=Tr(r),this.Z=jo(n),Object.freeze(this)}static CURVE(){return Zo}static fromAffine(e){let{x:r,y:n}=e;return r===0n&&n===0n?pt:new _e(r,n,1n)}static fromBytes(e){Ke(e);let{publicKey:r,publicKeyUncompressed:n}=Jt,o,s=e.length,i=e[0],a=e.subarray(1),c=Ir(a,0,me);if(s===r&&(i===2||i===3)){let f=fc(c);i===3&&(f=U(-f)),o=new _e(c,f,1n)}return s===n&&i===4&&(o=new _e(c,Ir(a,me,Xt),1n)),o?o.assertValidity():te("bad point: not on curve")}static fromHex(e){return _e.fromBytes(Jo(e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}equals(e){let{X:r,Y:n,Z:o}=this,{X:s,Y:i,Z:a}=En(e),c=U(r*a),f=U(s*o),u=U(n*a),d=U(i*o);return c===f&&u===d}is0(){return this.equals(pt)}negate(){return new _e(this.X,U(-this.Y),this.Z)}double(){return this.add(this)}add(e){let{X:r,Y:n,Z:o}=this,{X:s,Y:i,Z:a}=En(e),c=0n,f=Yo,u=0n,d=0n,l=0n,p=U(f*3n),y=U(r*s),b=U(n*i),A=U(o*a),_=U(r+n),I=U(s+i);_=U(_*I),I=U(y+b),_=U(_-I),I=U(r+o);let E=U(s+a);return I=U(I*E),E=U(y+A),I=U(I-E),E=U(n+o),u=U(i+a),E=U(E*u),u=U(b+A),E=U(E-u),l=U(c*I),u=U(p*A),l=U(u+l),u=U(b-l),l=U(b+l),d=U(u*l),b=U(y+y),b=U(b+y),A=U(c*A),I=U(p*I),b=U(b+A),A=U(y-A),A=U(c*A),I=U(I+A),y=U(b*I),d=U(d+y),y=U(E*I),u=U(_*u),u=U(u-y),y=U(_*b),l=U(E*l),l=U(l+y),new _e(u,d,l)}subtract(e){return this.add(En(e).negate())}multiply(e,r=!0){if(!r&&e===0n)return pt;if(vn(e),e===1n)return this;if(this.equals(Je))return Bc(e).p;let n=pt,o=Je;for(let s=this;e>0n;s=s.double(),e>>=1n)e&1n?n=n.add(s):r&&(o=o.add(s));return n}multiplyUnsafe(e){return this.multiply(e,!1)}toAffine(){let{X:e,Y:r,Z:n}=this;if(this.equals(pt))return{x:0n,y:0n};if(n===1n)return{x:e,y:r};let o=kn(n,yt);return U(n*o)!==1n&&te("inverse invalid"),{x:U(e*o),y:U(r*o)}}assertValidity(){let{x:e,y:r}=this.toAffine();return Tr(e),Tr(r),U(r*r)===rs(e)?this:te("bad point: not on curve")}toBytes(e=!0){let{x:r,y:n}=this.assertValidity().toAffine(),o=Ot(r);return e?Rt(ac(n),o):Rt(rr(4),o,Ot(n))}toHex(e){return Xo(this.toBytes(e))}};h(_e,"BASE"),h(_e,"ZERO");var $e=_e,Je=new $e(oc,sc,1n),pt=new $e(0n,1n,0n);$e.BASE=Je;$e.ZERO=pt;var uc=(t,e,r)=>Je.multiply(e,!1).add(t.multiply(r,!1)).assertValidity(),_r=t=>Kr("0x"+(Xo(t)||"0")),Ir=(t,e,r)=>_r(t.subarray(e,r)),lc=2n**256n,Ot=t=>Jo(Go(tr(t,0n,lc),Xt)),An=t=>{let e=_r(Ke(t,me,"secret key"));return tr(e,1n,Ge,"invalid secret key: outside of range")},Bn=t=>t>Ge>>1n,os=(t,e=!0)=>Je.multiply(An(t)).toBytes(e),dc=t=>{try{return!!An(t)}catch{return!1}},hc=(t,e)=>{let{publicKey:r,publicKeyUncompressed:n}=Jt;try{let o=t.length;return e===!0&&o!==r||e===!1&&o!==n?!1:!!$e.fromBytes(t)}catch{return!1}},zo=t=>[0,1,2,3].includes(t)?t:te("invalid recovery id"),Tn=t=>{t===pc&&te('Signature format "der" is not supported: switch to noble-curves'),t!=null&&t!==er&&t!==Rr&&te("Signature format must be one of: compact, recovered, der")},ss=(t,e=er)=>{Tn(e);let r=Jt.signature+ +(e===Rr);t.length!==r&&te(`Signature format "${e}" expects Uint8Array with length ${r}`)},Qt=class t{constructor(e,r,n){h(this,"r");h(this,"s");h(this,"recovery");this.r=vn(e),this.s=vn(r),n!=null&&(this.recovery=zo(n)),Object.freeze(this)}static fromBytes(e,r=er){ss(e,r);let n;r===Rr&&(n=e[0],e=e.subarray(1));let o=Ir(e,0,me),s=Ir(e,me,Xt);return new t(o,s,n)}addRecoveryBit(e){return new t(this.r,this.s,e)}hasHighS(){return Bn(this.s)}toBytes(e=er){Tn(e);let{r,s:n,recovery:o}=this,s=Rt(Ot(r),Ot(n));return e===Rr?Rt(rr(zo(o)),s):s}},is=t=>{t.length>8192&&te("input is too large");let e=t.length*8-256,r=_r(t);return e>0?r>>Kr(e):r},cs=t=>Ye(is(Ke(t))),er="compact",Rr="recovered",pc="der",qo="SHA-256",Ur={hmacSha256Async:async(t,e)=>{let r=Ho(),n="HMAC",o=await r.importKey("raw",t,{name:n,hash:{name:qo}},!1,["sign"]);return Xe(await r.sign(n,o,e))},hmacSha256:void 0,sha256Async:async t=>Xe(await Ho().digest(qo,t)),sha256:void 0},as=(t,e,r)=>{let n=Ke(t,void 0,"message");return e.prehash?r?cc("sha256Async",n):ts("sha256",n):n},yc=Xe(0),gc=rr(0),mc=rr(1),bc=1e3,wc="drbg: tried max amount of iterations",xc=(t,e)=>{let r=Xe(me),n=Xe(me),o=0,s=()=>{r.fill(1),n.fill(0)},i=(...u)=>ts("hmacSha256",n,Rt(r,...u)),a=(u=yc)=>{n=i(gc,u),r=i(),u.length!==0&&(n=i(mc,u),r=i())},c=()=>(o++>=bc&&te(wc),r=i(),r);s(),a(t);let f;for(;!(f=e(c()));)a();return s(),f};var Ec=(t,e,r,n)=>{let{lowS:o,extraEntropy:s}=r,i=Ot,a=cs(t),c=i(a),f=An(e),u=[i(f),c];if(s!=null&&s!==!1){let y=s===!0?Qo(me):s;u.push(Ke(y,void 0,"extraEntropy"))}let d=Rt(...u),l=a;return n(d,y=>{let b=is(y);if(!(1n<=b&&b<Ge))return;let A=kn(b,Ge),_=Je.multiply(b).toAffine(),I=Ye(_.x);if(I===0n)return;let E=Ye(A*Ye(l+I*f));if(E===0n)return;let S=(_.x===I?0:2)|Number(_.y&1n),N=E;return o&&Bn(E)&&(N=Ye(-E),S^=1),new Qt(I,N,S).toBytes(r.format)})},vc=(t,e,r,n={})=>{let{lowS:o,format:s}=n;t instanceof Qt&&te("Signature must be in Uint8Array, use .toBytes()"),ss(t,s),Ke(r,void 0,"publicKey");try{let{r:i,s:a}=Qt.fromBytes(t,s),c=cs(e),f=$e.fromBytes(r);if(o&&Bn(a))return!1;let u=kn(a,Ge),d=Ye(c*u),l=Ye(i*u),p=uc(f,d,l).toAffine();return Ye(p.x)===i}catch{return!1}},fs=t=>({lowS:t.lowS??!0,prehash:t.prehash??!0,format:t.format??er,extraEntropy:t.extraEntropy??!1}),us=(t,e,r={})=>{r=fs(r),Tn(r.format);let n=as(t,r,!1);return Ec(n,e,r,xc)};var ls=(t,e,r,n={})=>{n=fs(n);let o=as(e,n,!1);return vc(t,o,r,n)};var Sc=t=>{if(t=t===void 0?Qo(Jt.seed):t,Ke(t),t.length<Jt.seed||t.length>1024)return te("expected 48-1024b",RangeError);let e=U(_r(t),Ge-1n);return Ot(e+1n)};var Cr=Object.freeze({isValidSecretKey:dc,isValidPublicKey:hc,randomSecretKey:Sc});var Or=8,kc=256,ds=Math.ceil(kc/Or)+1,Sn=2**(Or-1),Ac=()=>{let t=[],e=Je,r=e;for(let n=0;n<ds;n++){r=e,t.push(r);for(let o=1;o<Sn;o++)r=r.add(e),t.push(r);e=r.double()}return t},Vo,Wo=(t,e)=>{let r=e.negate();return t?r:e},Bc=t=>{let e=Vo||(Vo=Ac()),r=pt,n=Je,o=2**Or,s=o,i=Kr(o-1),a=Kr(Or);for(let c=0;c<ds;c++){let f=Number(t&i);t>>=a,f>Sn&&(f-=s,t+=1n);let u=c*Sn,d=u,l=u+Math.abs(f)-1,p=c%2!==0,y=f<0;f===0?n=n.add(Wo(p,e[d])):r=r.add(Wo(y,e[l]))}return t!==0n&&te("invalid wnaf"),{p:r,f:n}};Be();var Mr=class{constructor(e,r){h(this,"oHash");h(this,"iHash");h(this,"blockLen");h(this,"outputLen");h(this,"canXOF",!1);h(this,"finished",!1);h(this,"destroyed",!1);if(Qe(e),j(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),ge(o)}update(e){return He(this),this.iHash.update(e),this}digestInto(e){He(this),Ut(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||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a,canXOF:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},je=(()=>{let t=((e,r,n)=>new Mr(e,r).update(n).digest());return t.create=(e,r)=>new Mr(e,r),t})();Dr();Be();function Cn(t,e,r){return t&e^~t&r}function Ln(t,e,r){return t&e^t&r^e&r}var wt=class{constructor(e,r,n,o){h(this,"blockLen");h(this,"outputLen");h(this,"canXOF",!1);h(this,"padOffset");h(this,"isLE");h(this,"buffer");h(this,"view");h(this,"finished",!1);h(this,"length",0);h(this,"pos",0);h(this,"destroyed",!1);this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Ue(this.buffer)}update(e){He(this),j(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let f=Ue(e);for(;o<=s-a;a+=o)this.process(f,a);i=!0;continue}n.set(a===0&&c===s?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){He(this),Ut(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>o-i&&(this.process(n,0),r.fill(0)),ws(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=e===r?n:Ue(e),c=this.outputLen,f=c/4,u=this.get();if(c%4||f>u.length)throw new Error("invalid outputLen");for(let d=0;d<f;d++)a.setUint32(4*d,u[d],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return e.destroyed=s,e.finished=o,e.length=n,e.pos=i,i&&e.buffer.set(r),e}clone(){return this._cloneInto()}},Bs=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Ts=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);Dr();Be();var Fc=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),tt=new Uint32Array(64),Fn=class extends wt{constructor(r,n){super(64,r,8,!1);h(this,"A",0);h(this,"B",0);h(this,"C",0);h(this,"D",0);h(this,"E",0);h(this,"F",0);h(this,"G",0);h(this,"H",0);this.A=n[0]|0,this.B=n[1]|0,this.C=n[2]|0,this.D=n[3]|0,this.E=n[4]|0,this.F=n[5]|0,this.G=n[6]|0,this.H=n[7]|0}get(){let{A:r,B:n,C:o,D:s,E:i,F:a,G:c,H:f}=this;return[r,n,o,s,i,a,c,f]}set(r,n,o,s,i,a,c,f){this.A=r|0,this.B=n|0,this.C=o|0,this.D=s|0,this.E=i|0,this.F=a|0,this.G=c|0,this.H=f|0}_cloneInto(r){return(r||(r=new this.constructor)).set(...this.get()),this._cloneIntoMeta(r)}process(r,n){for(let l=0;l<16;l++,n+=4)tt[l]=r.getUint32(n,!1);for(let l=16;l<64;l++){let p=tt[l-15],y=tt[l-2],b=Ie(p,7)^Ie(p,18)^p>>>3,A=Ie(y,17)^Ie(y,19)^y>>>10;tt[l]=A+tt[l-7]+b+tt[l-16]|0}let{A:o,B:s,C:i,D:a,E:c,F:f,G:u,H:d}=this;for(let l=0;l<64;l++){let p=Ie(c,6)^Ie(c,11)^Ie(c,25),y=d+p+Cn(c,f,u)+Fc[l]+tt[l]|0,A=(Ie(o,2)^Ie(o,13)^Ie(o,22))+Ln(o,s,i)|0;d=u,u=f,f=c,c=a+y|0,a=i,i=s,s=o,o=y+A|0}o=o+this.A|0,s=s+this.B|0,i=i+this.C|0,a=a+this.D|0,c=c+this.E|0,f=f+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(o,s,i,a,c,f,u,d)}roundClean(){ge(tt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),ge(this.buffer)}},Mn=class extends Fn{constructor(){super(32,Bs)}};var Ks=Nr(["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))),Mc=Ks[0],Pc=Ks[1],rt=new Uint32Array(80),nt=new Uint32Array(80),Pn=class extends wt{constructor(r,n){super(128,r,16,!1);h(this,"Ah",0);h(this,"Al",0);h(this,"Bh",0);h(this,"Bl",0);h(this,"Ch",0);h(this,"Cl",0);h(this,"Dh",0);h(this,"Dl",0);h(this,"Eh",0);h(this,"El",0);h(this,"Fh",0);h(this,"Fl",0);h(this,"Gh",0);h(this,"Gl",0);h(this,"Hh",0);h(this,"Hl",0);this.Ah=n[0]|0,this.Al=n[1]|0,this.Bh=n[2]|0,this.Bl=n[3]|0,this.Ch=n[4]|0,this.Cl=n[5]|0,this.Dh=n[6]|0,this.Dl=n[7]|0,this.Eh=n[8]|0,this.El=n[9]|0,this.Fh=n[10]|0,this.Fl=n[11]|0,this.Gh=n[12]|0,this.Gl=n[13]|0,this.Hh=n[14]|0,this.Hl=n[15]|0}get(){let{Ah:r,Al:n,Bh:o,Bl:s,Ch:i,Cl:a,Dh:c,Dl:f,Eh:u,El:d,Fh:l,Fl:p,Gh:y,Gl:b,Hh:A,Hl:_}=this;return[r,n,o,s,i,a,c,f,u,d,l,p,y,b,A,_]}set(r,n,o,s,i,a,c,f,u,d,l,p,y,b,A,_){this.Ah=r|0,this.Al=n|0,this.Bh=o|0,this.Bl=s|0,this.Ch=i|0,this.Cl=a|0,this.Dh=c|0,this.Dl=f|0,this.Eh=u|0,this.El=d|0,this.Fh=l|0,this.Fl=p|0,this.Gh=y|0,this.Gl=b|0,this.Hh=A|0,this.Hl=_|0}_cloneInto(r){return(r||(r=new this.constructor)).set(...this.get()),this._cloneIntoMeta(r)}process(r,n){for(let S=0;S<16;S++,n+=4)rt[S]=r.getUint32(n),nt[S]=r.getUint32(n+=4);for(let S=16;S<80;S++){let N=rt[S-15]|0,H=nt[S-15]|0,V=mt(N,H,1)^mt(N,H,8)^_n(N,H,7),W=bt(N,H,1)^bt(N,H,8)^Un(N,H,7),Z=rt[S-2]|0,D=nt[S-2]|0,ee=mt(Z,D,19)^sr(Z,D,61)^_n(Z,D,6),X=bt(Z,D,19)^ir(Z,D,61)^Un(Z,D,6),ye=vs(W,X,nt[S-7],nt[S-16]),de=Ss(ye,V,ee,rt[S-7],rt[S-16]);rt[S]=de|0,nt[S]=ye|0}let{Ah:o,Al:s,Bh:i,Bl:a,Ch:c,Cl:f,Dh:u,Dl:d,Eh:l,El:p,Fh:y,Fl:b,Gh:A,Gl:_,Hh:I,Hl:E}=this;for(let S=0;S<80;S++){let N=mt(l,p,14)^mt(l,p,18)^sr(l,p,41),H=bt(l,p,14)^bt(l,p,18)^ir(l,p,41),V=l&y^~l&A,W=p&b^~p&_,Z=ks(E,H,W,Pc[S],nt[S]),D=As(Z,I,N,V,Mc[S],rt[S]),ee=Z|0,X=mt(o,s,28)^sr(o,s,34)^sr(o,s,39),ye=bt(o,s,28)^ir(o,s,34)^ir(o,s,39),de=o&i^o&c^i&c,q=s&a^s&f^a&f;I=A|0,E=_|0,A=y|0,_=b|0,y=l|0,b=p|0,{h:l,l:p}=Le(u|0,d|0,D|0,ee|0),u=c|0,d=f|0,c=i|0,f=a|0,i=o|0,a=s|0;let z=xs(ee,ye,q);o=Es(z,D,X,de),s=z|0}({h:o,l:s}=Le(this.Ah|0,this.Al|0,o|0,s|0)),{h:i,l:a}=Le(this.Bh|0,this.Bl|0,i|0,a|0),{h:c,l:f}=Le(this.Ch|0,this.Cl|0,c|0,f|0),{h:u,l:d}=Le(this.Dh|0,this.Dl|0,u|0,d|0),{h:l,l:p}=Le(this.Eh|0,this.El|0,l|0,p|0),{h:y,l:b}=Le(this.Fh|0,this.Fl|0,y|0,b|0),{h:A,l:_}=Le(this.Gh|0,this.Gl|0,A|0,_|0),{h:I,l:E}=Le(this.Hh|0,this.Hl|0,I|0,E|0),this.set(o,s,i,a,c,f,u,d,l,p,y,b,A,_,I,E)}roundClean(){ge(rt,nt)}destroy(){this.destroyed=!0,ge(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Nn=class extends Pn{constructor(){super(64,Ts)}};var he=et(()=>new Mn,gt(1));var xt=et(()=>new Nn,gt(3));Hr();function ar(t){return Array.from(t).map(e=>e.toString(16).padStart(2,"0")).join("")}function Ft(t){if(typeof t!="string")throw new Error("Hex input must be a string");if(t.length%2!==0)throw new Error("Hex string must have even length");if(!/^[0-9a-fA-F]*$/.test(t))throw new Error("Hex string contains a non-hex character");let e=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)e[r/2]=parseInt(t.slice(r,r+2),16);return e}async function jr(t,e){if(e==="sha256")return he(t);if(e==="sha512")return xt(t);if(e==="sha3-256")return Ls(t);throw new Error(`Unsupported hash algorithm: ${e}`)}vt();Jr();var Jn=BigInt(0),dr=BigInt(1),fa=BigInt(4),Gn=16,ei=128,ua=5,ti=2**31;function Ht(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Et(e.fromAffine,"Point.fromAffine"),Et(e.fromBytes,"Point.fromBytes"),Et(e.fromHex,"Point.fromHex"),ot(e.BASE,"Point.BASE"),ot(e.ZERO,"Point.ZERO"),Dt(e.Fp),Dt(e.Fn)}function ni(t,e){Ht(t),oi(e,t);let r=Yn(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function la(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function da(t,e){let r=t*(4*e+128);if(r>ti)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+ti/2**20+" MiB")}function Qn(t,e){if(t!==void 0){Et(t,"randomBytes");try{let r=t(e);if(!Mt(r)||r.length!==e)return}catch{return}return t}}function oi(t,e){fr(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function ha(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,o)=>{if(!(r===void 0?e.isValid(n):st(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var si=new WeakMap;function Xn(t){return si.get(t)||1}function pa(t,e){let r=t.double(),n=[t];for(let o=1;o<e;o++)n.push(n[o-1].add(r));return n}function ya(t,e){let r=2**e,n=r/2,o=BigInt(r-1),s=[];for(;t>Jn;){let i=0;t&dr&&(i=Number(t&o),i>=n&&(i-=r),t-=BigInt(i)),s.push(i),t>>=dr}return s}function ga(t,e,r){let n=2**e,o=n/2,s=BigInt(n-1),i=BigInt(e),a=[];for(let c=0;c<r;c++){let f=Number(t&s);t>>=i,f>o&&(f-=n,t+=dr),a.push(f)}if(t!==Jn)throw new Error("invalid wnaf");return a}function ma(t,e,r){let n=0;for(let s of r)n=Math.max(n,s.length);let o=t;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<r.length;i++){let a=r[i][s];if(a){let c=e[i][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var Qr=class{constructor(e,r){h(this,"Point");h(this,"BASE");h(this,"ZERO");h(this,"randomBytes");h(this,"wnafPrecomputes",new WeakMap);h(this,"baseCanBeBlinded");h(this,"bits");Ht(e),this.randomBytes=Qn(r,Gn),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let o=Math.ceil(n/r)+1,s=2**(r-1),i=[],a=e;for(let c=0;c<o;c++){let f=a;for(let u=0;u<s;u++)i.push(f),f=f.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:o,comp:i}}wnafCachedCT(e,r){let{W:n,windows:o,comp:s}=e,i=2**(n-1),a=ga(r,n,o),c=this.ZERO,f=this.BASE;for(let u=0;u<o;u++){let d=a[u],l=u*i,p=Math.abs(d)-1,y=s[l];for(let A=1;A<i;A++)y=A===p?s[l+A]:y;let b=y.negate();d===0?f=f.add(s[l]):c=c.add(d<0?b:y)}return{p:c,f}}getWnafPrecomputes(e,r,n,o){let s=this.wnafPrecomputes.get(r),i=s?.find(a=>a.W===e&&a.bits===n);return i||(i=this.buildWnafTable(r,e,n),typeof o=="function"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(r,s)),s.push(i)),i}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!zn(r,dr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,o){let s=Xn(e);return s===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(s,e,n,o),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+ei,s=this.randomBytes(Gn);if(!Mt(s)||s.length!==Gn)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+Fe(s)*this.Point.Fn.ORDER;return this.runCT(e,i,o,n)}fixedWindowCT(e,r,n){let o=ua,s=1<<o,i=lr(o),a=new Array(s);a[0]=this.ZERO;for(let u=1;u<s;u++)a[u]=a[u-1].add(e);let c=Math.ceil(n/o),f=this.ZERO;for(let u=c-1;u>=0;u--){if(u!==c-1)for(let p=0;p<o;p++)f=f.double();let d=Number(r>>BigInt(u*o)&i),l=a[0];for(let p=1;p<s;p++)l=p===d?a[p]:l;f=f.add(l)}return{p:f,f}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===dr?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,o){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,o):this.mulCT(e,r,o)}mulUnsafe(e,r,n){if(this.assertPoint(e),!st(r))throw new Error("invalid scalar");let o=Xn(e);if(o===1||r>=this.Point.Fn.ORDER)return en(this.Point,[e],[r],!0);let s=this.getWnafPrecomputes(o,e,this.bits,n);return this.wnafCachedCT(s,r).p}setWindowSize(e,r){this.assertPoint(e),la(r,this.bits);let n=Math.ceil((this.bits+ei)/r)+1;da(n*2**(r-1),this.Point.Fp.BYTES),si.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Xn(e)!==1}};function en(t,e,r,n=!1){if(Ht(t),oi(e,t),Te(n,"allowOversized"),ha(r,t.Fn,n?t.Fn.ORDER**fa:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(i=>pa(i,4)),s=r.map(i=>ya(i,4));return ma(t.ZERO,o,s)}function ri(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Dt(e),e}else return $t(t,{isLE:r})}function ii(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);Me(r);for(let c of["p","n","h"]){let f=e[c];if(!(st(f)&&f!==Jn))throw new Error(`CURVE.${c} must be positive bigint`)}let o=ri(e.p,r.Fp,n),s=ri(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:s}}function ci(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}Jr();Be();vt();vt();var ba=BigInt(0),ro=class extends Error{constructor(e=""){super(e)}},qe={Err:ro,_tlv:{encode:(t,e)=>{let{Err:r}=qe;if(Pt(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(Ns(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=ur(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?ur(o.length/2|128):"";return ur(t)+s+o+e},decode(t,e){let{Err:r}=qe;e=ue(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=qe;if(Wr(t),t<ba)throw new e("integer: negative integers are not allowed");let r=ur(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 Fe(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=qe,o=ue(t,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l:u}=n.decode(2,c);if(u.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(t){let{_tlv:e,_int:r}=qe;Me(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}},no=(Object.freeze(qe._tlv),Object.freeze(qe._int),Object.freeze(qe));Jr();var di=(t,e)=>(t+(t>=0?e:-e)/hi)/e;function wa(t,e,r){qn("scalar",t,Ve,r);let[[n,o],[s,i]]=e,a=di(i*t,r),c=di(-o*t,r),f=t-a*n-c*s,u=-a*o-c*i,d=f<Ve,l=u<Ve;d&&(f=-f),l&&(u=-u);let p=lr(Math.ceil(Nt(r)/2))+St;if(f<Ve||f>=p||u<Ve||u>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:d,k1:f,k2neg:l,k2:u}}function io(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function oo(t,e){Me(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Te(r.lowS,"lowS"),Te(r.prehash,"prehash"),r.format!==void 0&&io(r.format),r}var Ve=BigInt(0),St=BigInt(1),hi=BigInt(2),so=BigInt(3),xa=BigInt(4);function pi(t,e={}){let r=ii("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Me(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:f}=e,u=e.randomBytes===void 0?Vr:e.randomBytes;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let d=gi(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function p(z,k,R){if(f&&k.is0())return Uint8Array.of(0);let{x:L,y:T}=k.toAffine(),m=n.toBytes(L);if(Te(R,"isCompressed"),R){l();let B=!n.isOdd(T);return ze(yi(B),m)}else return ze(Uint8Array.of(4),m,n.toBytes(T))}function y(z){ue(z,void 0,"Point");let{publicKey:k,publicKeyUncompressed:R}=d,L=z.length,T=z[0],m=z.subarray(1);if(f&&L===1&&T===0)return{x:n.ZERO,y:n.ZERO};if(L===k&&(T===2||T===3)){let B=n.fromBytes(m);if(!n.isValid(B))throw new Error("bad point: is not on curve, wrong x");let C=E(B),F;try{F=n.sqrt(C)}catch(w){let x=w instanceof Error?": "+w.message:"";throw new Error("bad point: is not on curve, sqrt error"+x)}l();let M=n.isOdd(F);return(T&1)===1!==M&&(F=n.neg(F)),{x:B,y:F}}else if(L===R&&T===4){let B=n.BYTES,C=n.fromBytes(m.subarray(0,B)),F=n.fromBytes(m.subarray(B,B*2));if(!S(C,F))throw new Error("bad point: is not on curve");return{x:C,y:F}}else throw new Error(`bad point: got length ${L}, expected compressed=${k} or uncompressed=${R}`)}let b=e.toBytes===void 0?p:e.toBytes,A=e.fromBytes===void 0?y:e.fromBytes,_=n.mul(s.b,so),I=n.is0(s.a)?z=>n.ZERO:z=>n.mul(s.a,z);function E(z){let k=n.sqr(z),R=n.mul(k,z);return n.add(n.add(R,n.mul(z,s.a)),s.b)}function S(z,k){let R=n.sqr(k),L=E(z);return n.eql(R,L)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let N=n.mul(n.pow(s.a,so),xa),H=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(N,H)))throw new Error("bad curve params: a or b");function V(z,k,R=!1){if(!n.isValid(k)||R&&n.is0(k))throw new Error(`bad point coordinate ${z}`);return k}function W(z){if(!(z instanceof X))throw new Error("Weierstrass Point expected")}function Z(z){if(!c||!c.basises)throw new Error("no endo");return wa(z,c.basises,o.ORDER)}function D(z,k,R,L){if(!o.isValid(L))throw new RangeError("invalid scalar: out of range");if(c){let{k1neg:T,k1:m,k2neg:B,k2:C}=Z(L),F=new X(n.mul(R.X,c.beta),R.Y,R.Z);z.push(T?R.negate():R,B?F.negate():F),k.push(m,C)}else z.push(R),k.push(L)}let ee=new WeakSet,q=class q{constructor(k,R,L){h(this,"X");h(this,"Y");h(this,"Z");this.X=V("x",k),this.Y=V("y",R,!0),this.Z=V("z",L),Object.freeze(this)}static CURVE(){return s}static fromAffine(k){let{x:R,y:L}=k||{};if(!k||!n.isValid(R)||!n.isValid(L))throw new Error("invalid affine point");if(k instanceof q)throw new Error("projective point not allowed");return n.is0(R)&&n.is0(L)?q.ZERO:new q(R,L,n.ONE)}static fromBytes(k){let R=q.fromAffine(A(ue(k,void 0,"point")));return R.assertValidity(),R}static fromHex(k){return q.fromBytes(qr(k))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(k=6,R=!0){return de.setWindowSize(this,k),R||this.multiply(so),this}assertValidity(){let k=this;if(k.is0()){if(e.allowInfinityPoint&&n.is0(k.X)&&n.eql(k.Y,n.ONE)&&n.is0(k.Z))return;throw new Error("bad point: ZERO")}if(ee.has(k))return;let{x:R,y:L}=k.toAffine();if(!n.isValid(R)||!n.isValid(L))throw new Error("bad point: x or y not field elements");if(!S(R,L))throw new Error("bad point: equation left != right");if(!k.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");ee.add(k)}hasEvenY(){let{y:k}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(k)}equals(k){W(k);let{X:R,Y:L,Z:T}=this,{X:m,Y:B,Z:C}=k,F=n.eql(n.mul(R,C),n.mul(m,T)),M=n.eql(n.mul(L,C),n.mul(B,T));return F&&M}negate(){return new q(this.X,n.neg(this.Y),this.Z)}double(){let{X:k,Y:R,Z:L}=this,T=n.ZERO,m=n.ZERO,B=n.ZERO,C=n.mul(k,k),F=n.mul(R,R),M=n.mul(L,L),g=n.mul(k,R);return g=n.add(g,g),B=n.mul(k,L),B=n.add(B,B),T=I(B),m=n.mul(_,M),m=n.add(T,m),T=n.sub(F,m),m=n.add(F,m),m=n.mul(T,m),T=n.mul(g,T),B=n.mul(_,B),M=I(M),g=n.sub(C,M),g=I(g),g=n.add(g,B),B=n.add(C,C),C=n.add(B,C),C=n.add(C,M),C=n.mul(C,g),m=n.add(m,C),M=n.mul(R,L),M=n.add(M,M),C=n.mul(M,g),T=n.sub(T,C),B=n.mul(M,F),B=n.add(B,B),B=n.add(B,B),new q(T,m,B)}add(k){W(k);let{X:R,Y:L,Z:T}=this,{X:m,Y:B,Z:C}=k,F=n.ZERO,M=n.ZERO,g=n.ZERO,w=n.mul(R,m),x=n.mul(L,B),v=n.mul(T,C),O=n.add(R,L),K=n.add(m,B);O=n.mul(O,K),K=n.add(w,x),O=n.sub(O,K),K=n.add(R,T);let P=n.add(m,C);return K=n.mul(K,P),P=n.add(w,v),K=n.sub(K,P),P=n.add(L,T),F=n.add(B,C),P=n.mul(P,F),F=n.add(x,v),P=n.sub(P,F),g=I(K),F=n.mul(_,v),g=n.add(F,g),F=n.sub(x,g),g=n.add(x,g),M=n.mul(F,g),x=n.add(w,w),x=n.add(x,w),v=I(v),K=n.mul(_,K),x=n.add(x,v),v=n.sub(w,v),v=I(v),K=n.add(K,v),w=n.mul(x,K),M=n.add(M,w),w=n.mul(P,K),F=n.mul(O,F),F=n.sub(F,w),w=n.mul(O,x),g=n.mul(P,g),g=n.add(g,w),new q(F,M,g)}subtract(k){return W(k),this.add(k.negate())}is0(){return this.equals(q.ZERO)}multiply(k){if(!o.isValidNot0(k))throw new RangeError("invalid scalar: out of range");let{p:R,f:L}=de.mulSecret(this,k,i,ye);return ye([R,L])[0]}multiplyUnsafe(k){let R=this,L=k;if(!o.isValid(L))throw new RangeError("invalid scalar: out of range");if(L===Ve||R.is0())return q.ZERO;if(L===St)return R;if(de.hasWindowSize(this))return de.mulUnsafe(R,L,ye);let T=[],m=[];return D(T,m,R,L),en(q,T,m)}mulAddUnsafe(k,R,L){W(R);let T=[],m=[];return D(T,m,this,k),D(T,m,R,L),en(q,T,m)}toAffine(k){let R=this,L=k;if(L!=null&&!n.isValid(L))throw new RangeError('"invertedZ" expected valid field element');let{X:T,Y:m,Z:B}=R;if(n.eql(B,n.ONE))return{x:T,y:m};let C=R.is0();L==null&&(L=C?n.ONE:n.inv(B));let F=n.mul(T,L),M=n.mul(m,L),g=n.mul(B,L);if(C)return{x:n.ZERO,y:n.ZERO};if(!n.eql(g,n.ONE))throw new Error("invZ was invalid");return{x:F,y:M}}isTorsionFree(){let{isTorsionFree:k}=e;return i===St?!0:k?k(q,this):de.mulUnsafe(this,a).is0()}clearCofactor(){let{clearCofactor:k}=e;return i===St?this:k?k(q,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===St?this.is0():this.clearCofactor().is0()}toBytes(k=!0){return Te(k,"isCompressed"),this.assertValidity(),b(q,this,k)}toHex(k=!0){return $n(this.toBytes(k))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}};h(q,"BASE",new q(s.Gx,s.Gy,n.ONE)),h(q,"ZERO",new q(n.ZERO,n.ONE,n.ZERO)),h(q,"Fp",n),h(q,"Fn",o);let X=q,ye=z=>ni(X,z),de=new Qr(X,u);return de.bits>=6&&X.BASE.precompute(6),Object.freeze(X.prototype),Object.freeze(X),X}function yi(t){return Uint8Array.of(t?2:3)}function gi(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Ea(t,e={}){Ht(t);let{Fn:r}=t,n=e.randomBytes===void 0?Vr:e.randomBytes,o=Object.assign(gi(t.Fp,r),{seed:Math.max(Gr(r.ORDER),16)});function s(p){try{let y=r.fromBytes(p);return r.isValidNot0(y)}catch{return!1}}function i(p,y){let{publicKey:b,publicKeyUncompressed:A}=o;try{let _=p.length;return y===!0&&_!==b||y===!1&&_!==A?!1:!!t.fromBytes(p)}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,Xr(ue(p,o.seed,"seed"),r.ORDER)}function c(p,y=!0){return t.BASE.multiply(r.fromBytes(p)).toBytes(y)}function f(p){let{secretKey:y,publicKey:b,publicKeyUncompressed:A}=o,_=r._lengths;if(!Mt(p))return;let I=ue(p,void 0,"key").length,E=I===b||I===A,S=I===y||!!_?.includes(I);if(!(E&&S))return E}function u(p,y,b=!0){if(f(p)===!0)throw new Error("first arg must be private key");if(f(y)===!1)throw new Error("second arg must be public key");let A=r.fromBytes(p);return t.fromBytes(y).multiply(A).toBytes(b)}let d={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},l=ci(a,c);return Object.freeze(d),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:l,Point:t,utils:d,lengths:o})}function mi(t,e,r={}){Ht(t);let n=e;Qe(n),Me(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?Vr:o.randomBytes,i=o.hmac===void 0?(T,m)=>je(n,T,m):o.hmac,{Fp:a,Fn:c}=t,{ORDER:f,BITS:u}=c,d=Gr(f),l=Qn(s,d),{keygen:p,getPublicKey:y,getSharedSecret:b,utils:A,lengths:_}=Ea(t,o),I={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},E=f*hi+St<a.ORDER;function S(T){let m=f>>St;return T>m}function N(T,m){if(!c.isValidNot0(m))throw new Error(`invalid signature ${T}: out of range 1..Point.Fn.ORDER`);return m}function H(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function V(T,m,B){return H(),(T===B?0:2)|Number(a.isOdd(m))}function W(){if(E)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function Z(T,m){io(m);let B=_.signature,C=m==="compact"?B:m==="recovered"?B+1:void 0;return ue(T,C)}class D{constructor(m,B,C){h(this,"r");h(this,"s");h(this,"recovery");if(this.r=N("r",m),this.s=N("s",B),C!=null){if(W(),![0,1,2,3].includes(C))throw new Error("invalid recovery id");this.recovery=C}Object.freeze(this)}static fromBytes(m,B=I.format){Z(m,B);let C;if(B==="der"){let{r:w,s:x}=no.toSig(ue(m));return new D(w,x)}B==="recovered"&&(C=m[0],B="compact",m=m.subarray(1));let F=_.signature/2,M=m.subarray(0,F),g=m.subarray(F,F*2);return new D(c.fromBytes(M),c.fromBytes(g),C)}static fromHex(m,B){return this.fromBytes(qr(m),B)}assertRecovery(){let{recovery:m}=this;if(m==null)throw new Error("invalid recovery id: must be present");return m}addRecoveryBit(m){return new D(this.r,this.s,m)}recoverPublicKey(m){let{r:B,s:C}=this,F=this.assertRecovery(),M=F===2||F===3?B+f:B;if(!a.isValid(M))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let g=a.toBytes(M),w=t.fromBytes(ze(yi((F&1)===0),g)),x=c.inv(M),v=X(ue(m,void 0,"msgHash")),O=c.create(-v*x),K=c.create(C*x),P=t.BASE.mulAddUnsafe(O,w,K);if(P.is0())throw new Error("invalid recovery: point at infinify");return P.assertValidity(),P}hasHighS(){return S(this.s)}toBytes(m=I.format){if(io(m),m==="der")return qr(no.hexFromSig(this));let{r:B,s:C}=this,F=c.toBytes(B),M=c.toBytes(C);return m==="recovered"?(W(),ze(Uint8Array.of(this.assertRecovery()),F,M)):ze(F,M)}toHex(m){return $n(this.toBytes(m))}}Object.freeze(D.prototype),Object.freeze(D);let ee=o.bits2int===void 0?function(m){if(m.length>8192)throw new Error("input is too large");let B=Fe(m),C=m.length*8-u;return C>0?B>>BigInt(C):B}:o.bits2int,X=o.bits2int_modN===void 0?function(m){return c.create(ee(m))}:o.bits2int_modN,ye=lr(u);function de(T){return qn("num < 2^"+u,T,Ve,ye),c.toBytes(T)}function q(T,m){return ue(T,void 0,"message"),m?ue(n(T),void 0,"prehashed message"):T}function z(T,m,B){let{lowS:C,prehash:F,extraEntropy:M}=oo(B,I);T=q(T,F);let g=X(T),w=c.fromBytes(m);if(!c.isValidNot0(w))throw new Error("invalid private key");let x=[de(w),de(g)];if(M!=null&&M!==!1){let P=M===!0?s(_.secretKey):M;x.push(ue(P,void 0,"extraEntropy"))}let v=ze(...x),O=g;function K(P){let J=ee(P);if(!c.isValidNot0(J))return;let ae=t.BASE.multiply(J).toAffine(),re=c.create(ae.x);if(re===Ve)return;let Q;if(l!==void 0){let ce=Fe(Xr(l(d),f)),xe=c.inv(c.mul(ce,J)),Oe=c.mul(ce,O),Pe=c.mul(ce,w);Q=c.create(xe*c.create(Oe+Pe*re))}else{let ce=Gs(J,f);Q=c.create(ce*c.create(O+re*w))}if(Q===Ve)return;let fe=V(ae.x,ae.y,re),we=Q;return C&&S(Q)&&(we=c.neg(Q),fe^=1),new D(re,we,E?void 0:fe)}return{seed:v,k2sig:K}}function k(T,m,B={}){let{seed:C,k2sig:F}=z(T,m,B);return $s(n.outputLen,c.BYTES,i)(C,F).toBytes(B.format)}function R(T,m,B,C={}){let{lowS:F,prehash:M,format:g}=oo(C,I);if(B=ue(B,void 0,"publicKey"),m=q(m,M),!Mt(T)){let w=T instanceof D?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+w)}Z(T,g);try{let w=D.fromBytes(T,g),x=t.fromBytes(B);if(F&&w.hasHighS())return!1;let{r:v,s:O}=w,K=X(m),P=c.inv(O),J=c.create(K*P),ae=c.create(v*P),re=t.BASE.mulAddUnsafe(J,x,ae);if(re.is0())return!1;let Q=re.toAffine();return!(c.create(Q.x)!==v||g==="recovered"&&w.recovery!==V(Q.x,Q.y,v))}catch{return!1}}function L(T,m,B={}){let{prehash:C}=oo(B,I);return m=q(m,C),D.fromBytes(T,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:p,getPublicKey:y,getSharedSecret:b,utils:A,lengths:_,Point:t,sign:k,verify:R,recoverPublicKey:L,Signature:D,hash:n})}var ao={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},va={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var bi=BigInt(2);function Sa(t){let e=ao.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=t*t*t%e,u=f*f*t%e,d=Se(u,r,e)*u%e,l=Se(d,r,e)*u%e,p=Se(l,bi,e)*f%e,y=Se(p,o,e)*p%e,b=Se(y,s,e)*y%e,A=Se(b,a,e)*b%e,_=Se(A,c,e)*A%e,I=Se(_,a,e)*b%e,E=Se(I,r,e)*u%e,S=Se(E,i,e)*y%e,N=Se(S,n,e)*f%e,H=Se(N,bi,e);if(!co.eql(co.sqr(H),t))throw new Error("Cannot find square root");return H}var co=$t(ao.p,{sqrt:Sa}),ka=pi(ao,{Fp:co,endo:va}),jt=mi(ka,he);Be();var Aa=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),xi=Uint8Array.from(new Array(16).fill(0).map((t,e)=>e)),Ba=xi.map(t=>(9*t+5)%16),Ei=(()=>{let r=[[xi],[Ba]];for(let n=0;n<4;n++)for(let o of r)o.push(o[n].map(s=>Aa[s]));return r})(),vi=Ei[0],Si=Ei[1],ki=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(t=>Uint8Array.from(t)),Ta=vi.map((t,e)=>t.map(r=>ki[e][r])),Ka=Si.map((t,e)=>t.map(r=>ki[e][r])),Ia=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),Ra=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function wi(t,e,r,n){return t===0?e^r^n:t===1?e&r|~e&n:t===2?(e|~r)^n:t===3?e&n|r&~n:e^(r|~n)}var tn=new Uint32Array(16),fo=class extends wt{constructor(){super(64,20,8,!0);h(this,"h0",1732584193);h(this,"h1",-271733879);h(this,"h2",-1732584194);h(this,"h3",271733878);h(this,"h4",-1009589776)}get(){let{h0:r,h1:n,h2:o,h3:s,h4:i}=this;return[r,n,o,s,i]}set(r,n,o,s,i){this.h0=r|0,this.h1=n|0,this.h2=o|0,this.h3=s|0,this.h4=i|0}_cloneInto(r){return(r||(r=new this.constructor)).set(...this.get()),this._cloneIntoMeta(r)}process(r,n){for(let y=0;y<16;y++,n+=4)tn[y]=r.getUint32(n,!0);let o=this.h0|0,s=o,i=this.h1|0,a=i,c=this.h2|0,f=c,u=this.h3|0,d=u,l=this.h4|0,p=l;for(let y=0;y<5;y++){let b=4-y,A=Ia[y],_=Ra[y],I=vi[y],E=Si[y],S=Ta[y],N=Ka[y];for(let H=0;H<16;H++){let V=nr(o+wi(y,i,c,u)+tn[I[H]]+A,S[H])+l|0;o=l,l=u,u=nr(c,10)|0,c=i,i=V}for(let H=0;H<16;H++){let V=nr(s+wi(b,a,f,d)+tn[E[H]]+_,N[H])+p|0;s=p,p=d,d=nr(f,10)|0,f=a,a=V}}this.set(this.h1+c+d|0,this.h2+u+p|0,this.h3+l+s|0,this.h4+o+a|0,this.h0+i+f|0)}roundClean(){ge(tn)}destroy(){this.destroyed=!0,ge(this.buffer),this.set(0,0,0,0,0)}},Ai=et(()=>new fo);Be();var Oa=t=>Object.freeze(t());function _a(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function rn(t){if(!_a(t))throw new TypeError("Uint8Array expected")}function Ki(t){if(typeof t!="function")throw new TypeError("function expected");return!0}function Ua(t,e){if(typeof e!="string")throw new TypeError(`${t}: string expected`);return!0}function Ca(t,e="number"){if(typeof t!="number")throw new TypeError(`${e}: expected number, got ${typeof t}`);if(!Number.isSafeInteger(t))throw new RangeError(`${e}: expected safe integer, got ${t}`)}function Ii(...t){let e=s=>s,r=(s,i)=>a=>s(i(a)),n=t.map(s=>s.encode).reduceRight(r,e),o=t.map(s=>s.decode).reduce(r,e);return{encode:n,decode:o}}var Bi=(()=>{try{let t=new TextDecoder;return t.decode(Uint8Array.of(65,48,43,127))==="A0+\x7F"?t:void 0}catch{return}})(),uo=8192;function La(t){let e=t.length;if(Bi!==void 0&&e>=12)return Bi.decode(t);if(e<=uo)return String.fromCharCode.apply(null,t);let r="";for(let n=0;n<e;n+=uo)r+=String.fromCharCode.apply(null,t.subarray(n,n+uo));return r}function Fa(t,e){let r=t.length;if(r>128)throw new Error("alphabet: max 128 letters");let n=new Uint8Array(r),o=new Int8Array(128).fill(-1);for(let s=0;s<r;s++){let i=t.charCodeAt(s);if(t.codePointAt(s)!==i||i>127)throw new Error("alphabet: single-char ASCII letters only");n[s]=i,o[i]=s}if(e!==void 0)for(let s of Object.keys(e)){let i=s.charCodeAt(0),a=o[e[s].charCodeAt(0)];if(s.length!==1||i>127||a===void 0||a===-1)throw new Error(`alphabet: invalid alias ${s}`);o[i]=a}return{encode:s=>{let i=new Uint8Array(s.length);for(let a=0;a<s.length;a++){let c=s[a],f=n[c];if(f===void 0)throw new Error(`alphabet.encode: invalid digit ${c}`);i[a]=f}return La(i)},decode:s=>{Ua("decode",s);let i=s.length,a=new Uint8Array(i);for(let c=0;c<i;c++){let f=s.charCodeAt(c),u=f<128?o[f]:-1;if(u===-1)throw new Error(`Unknown letter "${s[c]}". Allowed: ${t}`);a[c]=u}return a}}}function Ma(t,e){if(Ca(t),t<=0)throw new RangeError(`checksum length must be positive: ${t}`);Ki(e);let r=e;return{encode(n){rn(n);let o=r(n).slice(0,t),s=new Uint8Array(n.length+t);return s.set(n),s.set(o,n.length),s},decode(n){rn(n);let o=n.slice(0,-t),s=n.slice(-t),i=r(o).slice(0,t);for(let a=0;a<t;a++)if(i[a]!==s[a])throw new Error("Invalid checksum");return o}}}var Ti=656356768,Pa={encode:t=>{rn(t);let e=t.length;if(e===0)return new Uint8Array(0);let r=0;for(;r<e-1&&t[r]===0;)r++;let n=Math.ceil(e/2),o=new Uint16Array(n),s=e&1;s&&(o[0]=t[0]);for(let l=s,p=s;l<e;l+=2,p++)o[p]=t[l]<<8|t[l+1];let i=[],a=0;for(;a<n;){let l=0;for(let p=a;p<n;p++){let y=l*65536+o[p],b=Math.floor(y/Ti);l=y-b*Ti,o[p]=b,b===0&&p===a&&a++}i.push(l)}let c=i.length-1,f=c*5;for(let l=i[c];f++,!(l<58);l=Math.floor(l/58));let u=new Uint8Array(r+f),d=u.length-1;for(let l=0;l<c;l++){let p=i[l];for(let y=0;y<5;y++)u[d--]=p%58,p=Math.floor(p/58)}for(let l=i[c];d>=r;l=Math.floor(l/58))u[d--]=l%58;return u},decode:t=>{rn(t);let e=t.length;if(e===0)return new Uint8Array(0);if(e>=65536)throw new Error("invalid length");let r=0;for(;r<e-1&&t[r]===0;)r++;let n=new Uint16Array(Math.ceil(e*6/16)+1),o=0,s=0,i=e%5||5;for(;s<e;){let u=0,d=1;for(let p=s+i;s<p;s++){let y=t[s];if(y>=58)throw new Error(`invalid integer: ${y}`);u=u*58+y,d*=58}i=5;let l=u;for(let p=0;p<o;p++){let y=n[p]*d+l;l=Math.floor(y/65536),n[p]=y-l*65536}for(;l>0;l=Math.floor(l/65536))n[o++]=l%65536}let a=o===0?1:o*2-(n[o-1]<256?1:0),c=new Uint8Array(r+a),f=c.length-1;for(let u=0;u<o;u++){let d=n[u];c[f--]=d&255,f>=r&&(c[f--]=d>>8)}return c}},Na=t=>Ii(Pa,Fa(t)),Da=Oa(()=>Na("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"));var Ri=t=>{Ki(t);let e=t;return Ii(Ma(4,r=>e(e(r))),Da)};var yr=jt.Point,pr=yr.Fn,lo=Ri(he),$a=Uint8Array.from("Bitcoin seed".split(""),t=>t.charCodeAt(0)),ho={private:76066276,public:76067358},po=2147483648,Ha=t=>Ai(he(t)),ja=t=>Ue(t).getUint32(0,!1),zt=(t,e="number")=>{if(typeof t!="number")throw new TypeError(`"${e}" expected number, got type=${typeof t}`);if(!Number.isSafeInteger(t)||t<0||t>2**32-1)throw new RangeError(`"${e}" expected integer in range 0..2**32-1, got ${t}`);let r=new Uint8Array(4);return Ue(r).setUint32(0,t,!1),r},yo=(t,e="versions")=>{if(!(typeof t=="object"&&t!==null))throw new Error("versions must be an object");return zt(t.private,`${e}.private`),zt(t.public,`${e}.public`),t},nn=class t{constructor(e){h(this,"versions");h(this,"depth",0);h(this,"index",0);h(this,"chainCode",null);h(this,"parentFingerprint",0);h(this,"_privateKey");h(this,"_publicKey");h(this,"pubHash");if(!e||typeof e!="object")throw new Error("HDKey.constructor must not be called directly");if(this.versions=e.versions?yo(e.versions):ho,this.depth=e.depth||0,this.chainCode=e.chainCode?Uint8Array.from(e.chainCode):null,this.index=e.index||0,this.parentFingerprint=e.parentFingerprint||0,!this.depth&&(this.parentFingerprint||this.index))throw new Error("HDKey: zero depth with non-zero index/parent fingerprint");if(this.depth>255)throw new Error("HDKey: depth exceeds the serializable value 255");if(e.publicKey&&e.privateKey)throw new Error("HDKey: publicKey and privateKey at same time.");if(e.privateKey){if(!jt.utils.isValidSecretKey(e.privateKey))throw new Error("Invalid private key");this._privateKey=Uint8Array.from(e.privateKey),this._publicKey=jt.getPublicKey(this._privateKey,!0)}else if(e.publicKey)this._publicKey=yr.fromBytes(e.publicKey).toBytes(!0);else throw new Error("HDKey: no public or private key provided");this.pubHash=Ha(this._publicKey)}get fingerprint(){if(!this.pubHash)throw new Error("No publicKey set!");return ja(this.pubHash)}get identifier(){return this.pubHash}get pubKeyHash(){return this.pubHash}get privateKey(){return this._privateKey||null}get publicKey(){return this._publicKey||null}get privateExtendedKey(){let e=this._privateKey;if(!e)throw new Error("No private key");return lo.encode(this.serialize(this.versions.private,Ce(Uint8Array.of(0),e)))}get publicExtendedKey(){if(!this._publicKey)throw new Error("No public key");return lo.encode(this.serialize(this.versions.public,this._publicKey))}static fromMasterSeed(e,r=ho){if(j(e),r=yo(r),8*e.length<128||8*e.length>512)throw new RangeError("HDKey: seed length must be between 128 and 512 bits; 256 bits is advised, got "+e.length);let n=je(xt,$a,e),o=n.slice(0,32),s=n.slice(32);return new t({versions:r,chainCode:s,privateKey:o})}static fromExtendedKey(e,r=ho){r=yo(r);let n=lo.decode(e),o=Ue(n),s=o.getUint32(0,!1),i={versions:r,depth:n[4],parentFingerprint:o.getUint32(5,!1),index:o.getUint32(9,!1),chainCode:n.slice(13,45)},a=n.slice(45),c=a[0]===0;if(s!==r[c?"private":"public"])throw new Error("Version mismatch");return c?new t({...i,privateKey:a.slice(1)}):new t({...i,publicKey:a})}static fromJSON(e){return t.fromExtendedKey(e.xpriv)}derive(e){if(!/^[mM]'?/.test(e))throw new Error('Path must start with "m" or "M"');if(/^[mM]'?$/.test(e))return this;let r=e.replace(/^[mM]'?\//,"").split("/"),n=this;for(let o of r){let s=/^(\d+)('?)$/.exec(o),i=s&&s[1];if(!s||s.length!==3||typeof i!="string")throw new Error("invalid child index: "+o);let a=+i;if(!Number.isSafeInteger(a)||a>=po)throw new Error("Invalid index");s[2]==="'"&&(a+=po),n=n.deriveChild(a)}return n}deriveChild(e,r){if(!this._publicKey||!this.chainCode)throw new Error("No publicKey or chainCode set");let n=zt(e,"index");if(e>=po){let c=this._privateKey;if(!c)throw new Error("Could not derive hardened child key");n=Ce(Uint8Array.of(0),c,n)}else n=Ce(this._publicKey,n);let o=r||je(xt,this.chainCode,n);j(o,64);let s=o.slice(0,32),i=o.slice(32),a={versions:this.versions,chainCode:i,depth:this.depth+1,parentFingerprint:this.fingerprint,index:e};if(a.depth>255)throw new Error("HDKey: depth exceeds the serializable value 255");try{let c=pr.fromBytes(s);if(this._privateKey){let f=pr.create(pr.fromBytes(this._privateKey)+c);if(!pr.isValidNot0(f))throw new Error("The tweak was out of range or the resulted private key is invalid");a.privateKey=pr.toBytes(f)}else{let f=yr.fromBytes(this._publicKey),u=c===0n?f:f.add(yr.BASE.multiply(c));if(u.equals(yr.ZERO))throw new Error("The tweak was equal to negative P, which made the result key invalid");a.publicKey=u.toBytes(!0)}return new t(a)}catch{return this.deriveChild(e+1)}}sign(e){if(!this._privateKey)throw new Error("No privateKey set!");return j(e,32),jt.sign(e,this._privateKey,{prehash:!1})}verify(e,r){if(j(e,32),j(r,64),!this._publicKey)throw new Error("No publicKey set!");return jt.verify(r,e,this._publicKey,{prehash:!1})}wipePrivateData(){return this._privateKey&&(this._privateKey.fill(0),this._privateKey=void 0),this}toJSON(){return{xpriv:this.privateExtendedKey,xpub:this.publicExtendedKey}}serialize(e,r){if(!this.chainCode)throw new Error("No chainCode set");return j(r,33),Ce(zt(e,"version"),new Uint8Array([this.depth]),zt(this.parentFingerprint,"parentFingerprint"),zt(this.index,"index"),this.chainCode,r)}};Be();function za(t,e,r,n){Qe(t);let o=or({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:a}=o;if(se(s,"c"),se(i,"dkLen"),se(a,"asyncTick"),s<1)throw new Error('"c" (iterations) must be >= 1');if(i<1)throw new Error('"dkLen" must be >= 1');if(i>(2**32-1)*t.outputLen)throw new Error("derived key too long");let c=On(e,"password"),f=On(r,"salt"),u=new Uint8Array(i),{iHash:d,oHash:l,outputLen:p}=je.create(t,c),y=new Uint8Array(p),b=qa(d,l,f,y);return{c:s,dkLen:i,asyncTick:a,DK:u,outputLen:p,eng:b}}function qa(t,e,r,n){let o=new Uint8Array(4),s=Ue(o),i=t._cloneInto().update(r),a=e._cloneInto(),c=t._cloneInto,f=e._cloneInto;return{u1:(u,d)=>{s.setInt32(0,u,!1),i._cloneInto(a).update(o).digestInto(n),e._cloneInto(a).update(n).digestInto(n),d.set(n.subarray(0,d.length))},rounds:(u,d)=>{for(let l=1;l<u;l++){c.call(t,a).update(n).digestInto(n),f.call(e,a).update(n).digestInto(n);for(let p=0;p<d.length;p++)d[p]^=n[p]}},output:u=>(t.destroy(),e.destroy(),i.destroy(),a.destroy(),ge(n),u)}}function Oi(t,e,r,n){let{c:o,dkLen:s,DK:i,outputLen:a,eng:c}=za(t,e,r,n);for(let f=1,u=0;u<s;f++,u+=a){let d=i.subarray(u,u+a);c.u1(f,d),c.rounds(o,d)}return c.output(i)}Be();var Va=t=>t[0]==="\u3042\u3044\u3053\u304F\u3057\u3093";function _i(t){if(typeof t!="string")throw new TypeError("invalid mnemonic type: "+typeof t);return t.normalize("NFKD")}function Ui(t){let e=_i(t),r=e.split(" ");if(![12,15,18,21,24].includes(r.length))throw new Error("Invalid mnemonic");return{nfkd:e,words:r}}function Ci(t){if(j(t),![16,20,24,28,32].includes(t.length))throw new RangeError("invalid entropy length")}function Li(t,e=128){if(se(e),e%32!==0||e>256)throw new RangeError("Invalid entropy");return Ga(Ct(e/8),t)}var Fi=t=>{let e=8-t.length/4;return he(t)[0]>>e<<e};function Mi(t){if(!Array.isArray(t)||t.length!==2048||typeof t[0]!="string")throw new TypeError("Wordlist: expected array of 2048 strings");t.forEach(e=>{if(typeof e!="string")throw new TypeError("wordlist: non-string element: "+e)})}function Wa(t,e){Mi(e);let r=new Uint8Array(t.length+1);r.set(t),r[t.length]=Fi(t);let n=[],o=0,s=0;for(let i of r)o=o<<8|i,s+=8,s>=11&&(s-=11,n.push(e[o>>>s&2047]),o&=(1<<s)-1);return n}function Za(t,e){Mi(e);let r=t.length/3*4,n=new Uint8Array(r+1),o=0,s=0,i=0;for(let c of t){let f=e.indexOf(c);if(f===-1)throw new Error("Unknown word: "+c);for(o=o<<11|f,s+=11;s>=8;)s-=8,n[i++]=o>>>s&255;o&=(1<<s)-1}s>0&&(n[i]=o<<8-s);let a=n.subarray(0,r);if(n[r]!==Fi(a))throw new Error("Invalid checksum");return Uint8Array.from(a)}function Ya(t,e){let{words:r}=Ui(t),n=Za(r,e);return Ci(n),n}function Ga(t,e){return Ci(t),Wa(t,e).join(Va(e)?"\u3000":" ")}function Pi(t,e){try{Ya(t,e)}catch{return!1}return!0}var Xa=t=>{if(typeof t!="string")throw new TypeError("invalid passphrase type: "+typeof t);return _i("mnemonic"+t)};function Ni(t,e=""){return Oi(xt,Ui(t).nfkd,Xa(e),{c:2048,dkLen:64})}var go=Object.freeze(`abandon
2
2
  ability
3
3
  able
4
4
  about
@@ -2046,9 +2046,9 @@ zebra
2046
2046
  zero
2047
2047
  zone
2048
2048
  zoo`.split(`
2049
- `));var Oe=class{async deriveKeypair(e){if(!e.seed)throw new Error("BIP32 derivation requires a seed");if(!e.path)throw new Error(`BIP32 derivation requires a path (e.g., "m/44'/0'/0'/0/0")`);try{let n=zn.fromMasterSeed(e.seed).derive(e.path);if(!n.privateKey)throw new Error(`Failed to derive private key at path ${e.path}`);if(!n.publicKey)throw new Error(`Failed to derive public key at path ${e.path}`);return{privateKey:n.privateKey,publicKey:n.publicKey}}catch(r){throw new Error(`BIP32 derivation failed at path ${e.path}: ${r instanceof Error?r.message:String(r)}`)}}mnemonicToSeed(e,r){if(typeof e!="string"||!uf(e,Ks))throw new Error("Invalid BIP39 mnemonic: unknown word, wrong word count, or checksum mismatch");return lf(e,r)}generateMnemonic(e=256){return cf(Ks,e)}static bitcoinPath(e=0,r=0,n=0){return`m/44'/0'/${e}'/${r}/${n}`}static bip44Path(e,r=0,n=0,o=0){for(let[s,i]of Object.entries({coinType:e,account:r,change:n,index:o}))if(!Number.isInteger(i)||i<0||i>2147483647)throw new Error(`BIP44 ${s} must be an integer in [0, 2^31 - 1], got ${String(i)}`);if(n!==0&&n!==1)throw new Error(`BIP44 change must be 0 (external) or 1 (internal), got ${n}`);return`m/44'/${e}'/${r}'/${n}/${o}`}static bitcoinSegWitPath(e=0,r=0,n=0){return`m/84'/0'/${e}'/${r}/${n}`}};var df="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";function al(t){let e=0n;for(let n of t)e=e*256n+BigInt(n);let r="";for(;e>0n;){let n=Number(e%58n);r=df[n]+r,e=e/58n}for(let n of t){if(n!==0)break;r="1"+r}return r}function fl(t){let e=0n;for(let n of t){let o=df.indexOf(n);if(o===-1)throw new Error(`Invalid Base58 character: ${n}`);e=e*58n+BigInt(o)}let r=[];for(;e>0n;)r.unshift(Number(e%256n)),e=e/256n;for(let n of t){if(n!=="1")break;r.unshift(0)}return new Uint8Array(r)}function Fs(t,e=!0,r="mainnet"){if(t.length!==32)throw new Error("Private key must be 32 bytes");let n=r==="mainnet"?128:239,o=new Uint8Array(e?34:33);o[0]=n,o.set(t,1),e&&(o[33]=1);let s=De(o),a=De(s).slice(0,4),c=new Uint8Array(o.length+4);return c.set(o),c.set(a,o.length),al(c)}function Cs(t){let e=fl(t);if(e.length!==37&&e.length!==38)throw new Error("Invalid WIF length");let r=e.slice(0,-4),n=e.slice(-4),o=De(r),i=De(o).slice(0,4);if(!n.every((h,l)=>h===i[l]))throw new Error("Invalid WIF checksum");let a=r[0],c=a===128?"mainnet":a===239?"testnet":null;if(!c)throw new Error(`Invalid WIF version byte: 0x${a.toString(16)}`);let f=r.length===34&&r[33]===1;return{privateKey:r.slice(1,33),compressed:f,network:c}}hn.sha256=t=>De(t);hn.hmacSha256=(t,e)=>Wi(De,t,e);function hf(t){if(!pn.isValidSecretKey(t))throw new Error("Private key is not a valid secp256k1 scalar")}var dr=class{constructor(){u(this,"suiteId","bsv-ecdsa-secp256k1");u(this,"version","1.0.0");u(this,"capabilities",{derivation:new Oe})}async generateKeypair(){let e=pn.randomSecretKey(),r=Ui(e,!0);return{privateKey:e,publicKey:r}}async sign(e,r){try{return Mi(r,e,{prehash:!1})}catch(n){throw new Error(`BsvEcdsaSuite signing failed: ${n instanceof Error?n.message:String(n)}`)}}async verify(e,r,n){try{return Ni(n,r,e,{prehash:!1})===!0}catch{return!1}}exportPublicKey(e){return Or(e)}importPublicKey(e){let r=Jt(e);if(!pn.isValidPublicKey(r))throw new Error("Invalid secp256k1 public key");return r}exportPrivateKey(e){return Fs(e,!0,"mainnet")}importPrivateKey(e){if(e.length===64){let r=Jt(e);if(r.length!==32)throw new Error("Private key must be 32 bytes");return hf(r),r}else try{let{privateKey:r}=Cs(e);return hf(r),r}catch(r){throw new Error(`Invalid private key format: ${r instanceof Error?r.message:String(r)}`)}}};var si=null,ii=null,ci=null;async function Rl(){return si||(si=(await Promise.resolve().then(()=>(so(),oo))).ml_dsa44),si}async function Kl(){return ii||(ii=(await Promise.resolve().then(()=>(so(),oo))).ml_dsa65),ii}async function Fl(){return ci||(ci=(await Promise.resolve().then(()=>(so(),oo))).ml_dsa87),ci}var ai={"ml-dsa-44":{publicKey:1312,privateKey:2560,signature:2420},"ml-dsa-65":{publicKey:1952,privateKey:4032,signature:3309},"ml-dsa-87":{publicKey:2592,privateKey:4896,signature:4627}},Jr=class{constructor(){u(this,"version","2.0.0");u(this,"capabilities",{})}async generateKeypair(){try{let r=(await this.getLib()).keygen();return{publicKey:r.publicKey,privateKey:r.secretKey}}catch(e){throw new Error(`${this.suiteId} key generation failed: ${e instanceof Error?e.message:String(e)}`)}}async sign(e,r){try{return(await this.getLib()).sign(r,e)}catch(n){throw new Error(`${this.suiteId} signing failed: ${n instanceof Error?n.message:String(n)}`)}}async verify(e,r,n){try{let o=await this.getLib();return e.length!==this.sizes.publicKey||n.length!==this.sizes.signature?!1:o.verify(n,r,e)===!0}catch{return!1}}exportPublicKey(e){return Or(e)}importPublicKey(e){let r=Jt(e);if(r.length!==this.sizes.publicKey)throw new Error(`${this.suiteId} public key must be ${this.sizes.publicKey} bytes, got ${r.length}`);return r}exportPrivateKey(e){return Or(e)}importPrivateKey(e){let r=Jt(e);if(r.length!==this.sizes.privateKey)throw new Error(`${this.suiteId} private key must be ${this.sizes.privateKey} bytes, got ${r.length}`);return r}},pr=class extends Jr{constructor(){super(...arguments);u(this,"suiteId","ml-dsa-44")}get sizes(){return ai["ml-dsa-44"]}async getLib(){return Rl()}},yr=class extends Jr{constructor(){super(...arguments);u(this,"suiteId","ml-dsa-65")}get sizes(){return ai["ml-dsa-65"]}async getLib(){return Kl()}},xr=class extends Jr{constructor(){super(...arguments);u(this,"suiteId","ml-dsa-87")}get sizes(){return ai["ml-dsa-87"]}async getLib(){return Fl()}};var io=class{constructor(){u(this,"suites",new Map)}register(e){if(this.suites.has(e.suiteId))throw new Error(`Signature suite already registered: ${e.suiteId}`);this.suites.set(e.suiteId,e)}getSuite(e){let r=this.suites.get(e);if(!r)throw new Error(`Unknown signature suite: ${e}. Available: ${this.listSuites().join(", ")}`);return r}hasSuite(e){return this.suites.has(e)}listSuites(){return[...this.suites.keys()]}getAllSuites(){return[...this.suites.values()]}unregister(e){return this.suites.delete(e)}clear(){this.suites.clear()}},Tt=new io;Tt.register(new dr);Tt.register(new pr);Tt.register(new yr);Tt.register(new xr);var zt=class extends Error{constructor(r,n){super(r);u(this,"code");this.code=n,this.name=this.constructor.name,Error.captureStackTrace(this,this.constructor)}},co=class extends zt{constructor(r){super(`Key not found: ${r}`,"KEY_NOT_FOUND");u(this,"keyId");this.keyId=r}},qt=class extends zt{constructor(r){super(`Key already exists: ${r}`,"KEY_ALREADY_EXISTS");u(this,"keyId");this.keyId=r}},ao=class extends zt{constructor(r,n){super(`Key expired: ${r} (expired at ${n})`,"KEY_EXPIRED");u(this,"keyId");u(this,"expiresAt");this.keyId=r,this.expiresAt=n}},Qr=class extends zt{constructor(r,n,o){super(`Key in invalid state: ${r} (current: ${n}, required: ${o})`,"KEY_INVALID_STATE");u(this,"keyId");u(this,"currentState");u(this,"requiredState");this.keyId=r,this.currentState=n,this.requiredState=o}};var gr=class extends zt{constructor(e){super(`Invalid key parameters: ${e}`,"INVALID_KEY_PARAMETERS")}};function tn(t){if(typeof t!="string")return null;let e=t.lastIndexOf(":");return e<=0||e===t.length-1?null:t.slice(0,e)}function tt(t){return{...t,usage:[...t.usage],...t.derivation?{derivation:{...t.derivation}}:{}}}function fi(t){return{publicKey:Uint8Array.from(t.publicKey),privateKey:Uint8Array.from(t.privateKey)}}function en(t,e=new Date){if(t.status&&t.status!=="active")return!1;if(t.expiresAt!==void 0){let r=new Date(t.expiresAt).getTime();if(Number.isNaN(r)||r<=e.getTime())return!1}return!0}function ui(t,e=new Date){if(t.status&&t.status!=="active")throw new Qr(t.keyId,t.status,"active");if(!en(t,e))throw new ao(t.keyId,String(t.expiresAt))}function Cl(t){if(t!==void 0&&(typeof t!="string"||Number.isNaN(new Date(t).getTime())))throw new gr(`expiresAt must be an ISO 8601 date, got ${JSON.stringify(t)}`)}var Lt=class{constructor(){u(this,"keys",new Map)}async store(e,r,n){this.keys.set(e,{keypair:fi(r),meta:tt(n)})}async storeIfAbsent(e,r,n){return this.keys.has(e)?!1:(this.keys.set(e,{keypair:fi(r),meta:tt(n)}),!0)}async load(e){let r=this.keys.get(e);return r?{keypair:fi(r.keypair),meta:tt(r.meta)}:null}async list(e){let r=Array.from(this.keys.values()).map(n=>tt(n.meta));return e?r.filter(n=>Object.entries(e).every(([o,s])=>o==="usage"&&Array.isArray(s)?s.some(i=>n.usage.includes(i)):n[o]===s)):r}async delete(e){let r=this.keys.get(e);r&&r.keypair.privateKey.fill(0),this.keys.delete(e)}async updateMeta(e,r){let n=this.keys.get(e);if(!n)throw new co(e);this.keys.set(e,{keypair:n.keypair,meta:tt({...n.meta,...r})})}clear(){for(let{keypair:e}of this.keys.values())e.privateKey.fill(0);this.keys.clear()}},Gt=class{constructor(e=new Lt){u(this,"storage");this.storage=e}async registerKey(e,r,n,o={}){if(typeof e!="string"||e.length===0)throw new gr("keyId must be a non-empty string");Cl(o.expiresAt);let s={keyId:e,suiteId:n,createdAt:new Date().toISOString(),expiresAt:o.expiresAt,usage:o.usage?[...o.usage]:["signing"],cryptoProfileVersion:o.cryptoProfileVersion||"1.0.0",status:o.status||"active",...o.rotatedFrom!==void 0?{rotatedFrom:o.rotatedFrom}:{},...o.derivation?{derivation:{...o.derivation}}:{}};if(this.storage.storeIfAbsent){if(!await this.storage.storeIfAbsent(e,r,s))throw new qt(e)}else{if(await this.storage.load(e))throw new qt(e);await this.storage.store(e,r,s)}return tt(s)}async getKey(e){return await this.storage.load(e)}async getPublicKey(e){let r=await this.storage.load(e);return r?{publicKey:Uint8Array.from(r.keypair.publicKey),meta:tt(r.meta)}:null}async listKeys(e){return await this.storage.list(e)}async listActiveKeys(e){let r=await this.storage.list(e),n=new Date;return r.filter(o=>en(o,n))}async rotateKey(e,r,n,o={}){let s=await this.storage.load(e);if(!s)throw new Error(`Cannot rotate: key not found: ${e}`);if(s.meta.status==="revoked"||s.meta.status==="rotated")throw new Qr(e,s.meta.status,"active or expired");let i;if(o.expiresAt===null)i=void 0;else if(o.expiresAt!==void 0)i=o.expiresAt;else if(s.meta.expiresAt!==void 0){let c=new Date(s.meta.expiresAt).getTime()-new Date(s.meta.createdAt).getTime();if(Number.isFinite(c)&&c>0)i=new Date(Date.now()+c).toISOString();else throw new gr(`cannot infer a lifetime for the replacement of ${e} (createdAt ${s.meta.createdAt}, expiresAt ${s.meta.expiresAt}); pass options.expiresAt`)}let a=await this.registerKey(r,n,s.meta.suiteId,{usage:s.meta.usage,cryptoProfileVersion:s.meta.cryptoProfileVersion,expiresAt:i,status:"active",rotatedFrom:e,derivation:o.derivation});try{await this.storage.updateMeta(e,{status:"rotated"})}catch(c){throw await this.storage.delete(r).catch(()=>{}),c}return a}async revokeKey(e,r){await this.storage.updateMeta(e,{status:"revoked",revokedAt:new Date().toISOString()})}async deleteKey(e){await this.storage.delete(e)}async markExpiredKeys(){let e=await this.storage.list(),r=new Date,n=0;for(let o of e)o.status==="active"&&!en(o,r)&&(await this.storage.updateMeta(o.keyId,{status:"expired"}),n++);return n}async pruneOldKeys(e=90){let r=await this.storage.list(),n=new Date;n.setDate(n.getDate()-e);let o=0;for(let s of r)(s.status==="revoked"&&s.revokedAt&&new Date(s.revokedAt)<n||s.status==="expired"&&s.expiresAt&&new Date(s.expiresAt)<n)&&(await this.storage.delete(s.keyId),o++);return o}};var Dl=/^pk-[^:-]+-(\d+)$/,Mf=8;function fo(t){if(typeof t!="string"||t.length===0)throw new Error("agentId must be a non-empty string")}function rn(t,e){return{meta:tt(t),publicKey:Uint8Array.from(e)}}function Nf(t,e){return e==="any"?!0:e==="not-revoked"?t.status!=="revoked":en(t)}var uo=class{constructor(e){this.keyCounter=new Map;this.counterInitialized=new Set;this.counterInitPromises=new Map;this.getOrCreateInFlight=new Map;this.keyRegistry=e.keyRegistry,this.suiteRegistry=e.suiteRegistry}async createKey(e,r,n={}){fo(e);let o=this.suiteRegistry.getSuite(r.primarySignatureSuite),s;if(n.derivationContext){if(!o.capabilities?.derivation){let a=this.getSuitesWithCapability("derivation");throw new Error(`Suite '${o.suiteId}' does not support key derivation.
2049
+ `));var Re=class{async deriveKeypair(e){if(!e.seed)throw new Error("BIP32 derivation requires a seed");if(!e.path)throw new Error(`BIP32 derivation requires a path (e.g., "m/44'/0'/0'/0/0")`);try{let n=nn.fromMasterSeed(e.seed).derive(e.path);if(!n.privateKey)throw new Error(`Failed to derive private key at path ${e.path}`);if(!n.publicKey)throw new Error(`Failed to derive public key at path ${e.path}`);return{privateKey:n.privateKey,publicKey:n.publicKey}}catch(r){throw new Error(`BIP32 derivation failed at path ${e.path}: ${r instanceof Error?r.message:String(r)}`)}}mnemonicToSeed(e,r){if(typeof e!="string"||!Pi(e,go))throw new Error("Invalid BIP39 mnemonic: unknown word, wrong word count, or checksum mismatch");return Ni(e,r)}generateMnemonic(e=256){return Li(go,e)}static bitcoinPath(e=0,r=0,n=0){return`m/44'/0'/${e}'/${r}/${n}`}static bip44Path(e,r=0,n=0,o=0){for(let[s,i]of Object.entries({coinType:e,account:r,change:n,index:o}))if(!Number.isInteger(i)||i<0||i>2147483647)throw new Error(`BIP44 ${s} must be an integer in [0, 2^31 - 1], got ${String(i)}`);if(n!==0&&n!==1)throw new Error(`BIP44 change must be 0 (external) or 1 (internal), got ${n}`);return`m/44'/${e}'/${r}'/${n}/${o}`}static bitcoinSegWitPath(e=0,r=0,n=0){return`m/84'/0'/${e}'/${r}/${n}`}};var Di="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";function Ja(t){let e=0n;for(let n of t)e=e*256n+BigInt(n);let r="";for(;e>0n;){let n=Number(e%58n);r=Di[n]+r,e=e/58n}for(let n of t){if(n!==0)break;r="1"+r}return r}function Qa(t){let e=0n;for(let n of t){let o=Di.indexOf(n);if(o===-1)throw new Error(`Invalid Base58 character: ${n}`);e=e*58n+BigInt(o)}let r=[];for(;e>0n;)r.unshift(Number(e%256n)),e=e/256n;for(let n of t){if(n!=="1")break;r.unshift(0)}return new Uint8Array(r)}function mo(t,e=!0,r="mainnet"){if(t.length!==32)throw new Error("Private key must be 32 bytes");let n=r==="mainnet"?128:239,o=new Uint8Array(e?34:33);o[0]=n,o.set(t,1),e&&(o[33]=1);let s=he(o),a=he(s).slice(0,4),c=new Uint8Array(o.length+4);return c.set(o),c.set(a,o.length),Ja(c)}function bo(t){let e=Qa(t);if(e.length!==37&&e.length!==38)throw new Error("Invalid WIF length");let r=e.slice(0,-4),n=e.slice(-4),o=he(r),i=he(o).slice(0,4);if(!n.every((d,l)=>d===i[l]))throw new Error("Invalid WIF checksum");let a=r[0],c=a===128?"mainnet":a===239?"testnet":null;if(!c)throw new Error(`Invalid WIF version byte: 0x${a.toString(16)}`);let f=r.length===34&&r[33]===1;return{privateKey:r.slice(1,33),compressed:f,network:c}}Ur.sha256=t=>he(t);Ur.hmacSha256=(t,e)=>je(he,t,e);function $i(t){if(!Cr.isValidSecretKey(t))throw new Error("Private key is not a valid secp256k1 scalar")}var qt=class{constructor(){h(this,"suiteId","bsv-ecdsa-secp256k1");h(this,"version","1.0.0");h(this,"capabilities",{derivation:new Re})}async generateKeypair(){let e=Cr.randomSecretKey(),r=os(e,!0);return{privateKey:e,publicKey:r}}async sign(e,r){try{return us(r,e,{prehash:!1})}catch(n){throw new Error(`BsvEcdsaSuite signing failed: ${n instanceof Error?n.message:String(n)}`)}}async verify(e,r,n){try{return ls(n,r,e,{prehash:!1})===!0}catch{return!1}}exportPublicKey(e){return ar(e)}importPublicKey(e){let r=Ft(e);if(!Cr.isValidPublicKey(r))throw new Error("Invalid secp256k1 public key");return r}exportPrivateKey(e){return mo(e,!0,"mainnet")}importPrivateKey(e){if(e.length===64){let r=Ft(e);if(r.length!==32)throw new Error("Private key must be 32 bytes");return $i(r),r}else try{let{privateKey:r}=bo(e);return $i(r),r}catch(r){throw new Error(`Invalid private key format: ${r instanceof Error?r.message:String(r)}`)}}};var Ro=null,Oo=null,_o=null;async function uf(){return Ro||(Ro=(await Promise.resolve().then(()=>(dn(),ln))).ml_dsa44),Ro}async function lf(){return Oo||(Oo=(await Promise.resolve().then(()=>(dn(),ln))).ml_dsa65),Oo}async function df(){return _o||(_o=(await Promise.resolve().then(()=>(dn(),ln))).ml_dsa87),_o}var Uo={"ml-dsa-44":{publicKey:1312,privateKey:2560,signature:2420},"ml-dsa-65":{publicKey:1952,privateKey:4032,signature:3309},"ml-dsa-87":{publicKey:2592,privateKey:4896,signature:4627}},wr=class{constructor(){h(this,"version","2.0.0");h(this,"capabilities",{})}async generateKeypair(){try{let r=(await this.getLib()).keygen();return{publicKey:r.publicKey,privateKey:r.secretKey}}catch(e){throw new Error(`${this.suiteId} key generation failed: ${e instanceof Error?e.message:String(e)}`)}}async sign(e,r){try{return(await this.getLib()).sign(r,e)}catch(n){throw new Error(`${this.suiteId} signing failed: ${n instanceof Error?n.message:String(n)}`)}}async verify(e,r,n){try{let o=await this.getLib();return e.length!==this.sizes.publicKey||n.length!==this.sizes.signature?!1:o.verify(n,r,e)===!0}catch{return!1}}exportPublicKey(e){return ar(e)}importPublicKey(e){let r=Ft(e);if(r.length!==this.sizes.publicKey)throw new Error(`${this.suiteId} public key must be ${this.sizes.publicKey} bytes, got ${r.length}`);return r}exportPrivateKey(e){return ar(e)}importPrivateKey(e){let r=Ft(e);if(r.length!==this.sizes.privateKey)throw new Error(`${this.suiteId} private key must be ${this.sizes.privateKey} bytes, got ${r.length}`);return r}},Vt=class extends wr{constructor(){super(...arguments);h(this,"suiteId","ml-dsa-44")}get sizes(){return Uo["ml-dsa-44"]}async getLib(){return uf()}},Wt=class extends wr{constructor(){super(...arguments);h(this,"suiteId","ml-dsa-65")}get sizes(){return Uo["ml-dsa-65"]}async getLib(){return lf()}},Zt=class extends wr{constructor(){super(...arguments);h(this,"suiteId","ml-dsa-87")}get sizes(){return Uo["ml-dsa-87"]}async getLib(){return df()}};var hn=class{constructor(){h(this,"suites",new Map)}register(e){if(this.suites.has(e.suiteId))throw new Error(`Signature suite already registered: ${e.suiteId}`);this.suites.set(e.suiteId,e)}getSuite(e){let r=this.suites.get(e);if(!r)throw new Error(`Unknown signature suite: ${e}. Available: ${this.listSuites().join(", ")}`);return r}hasSuite(e){return this.suites.has(e)}listSuites(){return[...this.suites.keys()]}getAllSuites(){return[...this.suites.values()]}unregister(e){return this.suites.delete(e)}clear(){this.suites.clear()}},lt=new hn;lt.register(new qt);lt.register(new Vt);lt.register(new Wt);lt.register(new Zt);var Bt=class extends Error{constructor(r,n){super(r);h(this,"code");this.code=n,this.name=this.constructor.name,Error.captureStackTrace(this,this.constructor)}},pn=class extends Bt{constructor(r){super(`Key not found: ${r}`,"KEY_NOT_FOUND");h(this,"keyId");this.keyId=r}},Tt=class extends Bt{constructor(r){super(`Key already exists: ${r}`,"KEY_ALREADY_EXISTS");h(this,"keyId");this.keyId=r}},yn=class extends Bt{constructor(r,n){super(`Key expired: ${r} (expired at ${n})`,"KEY_EXPIRED");h(this,"keyId");h(this,"expiresAt");this.keyId=r,this.expiresAt=n}},xr=class extends Bt{constructor(r,n,o){super(`Key in invalid state: ${r} (current: ${n}, required: ${o})`,"KEY_INVALID_STATE");h(this,"keyId");h(this,"currentState");h(this,"requiredState");this.keyId=r,this.currentState=n,this.requiredState=o}};var Yt=class extends Bt{constructor(e){super(`Invalid key parameters: ${e}`,"INVALID_KEY_PARAMETERS")}};function vr(t){if(typeof t!="string")return null;let e=t.lastIndexOf(":");return e<=0||e===t.length-1?null:t.slice(0,e)}function We(t){return{...t,usage:[...t.usage],...t.derivation?{derivation:{...t.derivation}}:{}}}function Co(t){return{publicKey:Uint8Array.from(t.publicKey),privateKey:Uint8Array.from(t.privateKey)}}function Er(t,e=new Date){if(t.status&&t.status!=="active")return!1;if(t.expiresAt!==void 0){let r=new Date(t.expiresAt).getTime();if(Number.isNaN(r)||r<=e.getTime())return!1}return!0}function Lo(t,e=new Date){if(t.status&&t.status!=="active")throw new xr(t.keyId,t.status,"active");if(!Er(t,e))throw new yn(t.keyId,String(t.expiresAt))}function hf(t){if(t!==void 0&&(typeof t!="string"||Number.isNaN(new Date(t).getTime())))throw new Yt(`expiresAt must be an ISO 8601 date, got ${JSON.stringify(t)}`)}var dt=class{constructor(){h(this,"keys",new Map)}async store(e,r,n){this.keys.set(e,{keypair:Co(r),meta:We(n)})}async storeIfAbsent(e,r,n){return this.keys.has(e)?!1:(this.keys.set(e,{keypair:Co(r),meta:We(n)}),!0)}async load(e){let r=this.keys.get(e);return r?{keypair:Co(r.keypair),meta:We(r.meta)}:null}async list(e){let r=Array.from(this.keys.values()).map(n=>We(n.meta));return e?r.filter(n=>Object.entries(e).every(([o,s])=>o==="usage"&&Array.isArray(s)?s.some(i=>n.usage.includes(i)):n[o]===s)):r}async delete(e){let r=this.keys.get(e);r&&r.keypair.privateKey.fill(0),this.keys.delete(e)}async updateMeta(e,r){let n=this.keys.get(e);if(!n)throw new pn(e);this.keys.set(e,{keypair:n.keypair,meta:We({...n.meta,...r})})}clear(){for(let{keypair:e}of this.keys.values())e.privateKey.fill(0);this.keys.clear()}},Kt=class{constructor(e=new dt){h(this,"storage");this.storage=e}async registerKey(e,r,n,o={}){if(typeof e!="string"||e.length===0)throw new Yt("keyId must be a non-empty string");hf(o.expiresAt);let s={keyId:e,suiteId:n,createdAt:new Date().toISOString(),expiresAt:o.expiresAt,usage:o.usage?[...o.usage]:["signing"],cryptoProfileVersion:o.cryptoProfileVersion||"1.0.0",status:o.status||"active",...o.rotatedFrom!==void 0?{rotatedFrom:o.rotatedFrom}:{},...o.derivation?{derivation:{...o.derivation}}:{}};if(this.storage.storeIfAbsent){if(!await this.storage.storeIfAbsent(e,r,s))throw new Tt(e)}else{if(await this.storage.load(e))throw new Tt(e);await this.storage.store(e,r,s)}return We(s)}async getKey(e){return await this.storage.load(e)}async getPublicKey(e){let r=await this.storage.load(e);return r?{publicKey:Uint8Array.from(r.keypair.publicKey),meta:We(r.meta)}:null}async listKeys(e){return await this.storage.list(e)}async listActiveKeys(e){let r=await this.storage.list(e),n=new Date;return r.filter(o=>Er(o,n))}async rotateKey(e,r,n,o={}){let s=await this.storage.load(e);if(!s)throw new Error(`Cannot rotate: key not found: ${e}`);if(s.meta.status==="revoked"||s.meta.status==="rotated")throw new xr(e,s.meta.status,"active or expired");let i;if(o.expiresAt===null)i=void 0;else if(o.expiresAt!==void 0)i=o.expiresAt;else if(s.meta.expiresAt!==void 0){let c=new Date(s.meta.expiresAt).getTime()-new Date(s.meta.createdAt).getTime();if(Number.isFinite(c)&&c>0)i=new Date(Date.now()+c).toISOString();else throw new Yt(`cannot infer a lifetime for the replacement of ${e} (createdAt ${s.meta.createdAt}, expiresAt ${s.meta.expiresAt}); pass options.expiresAt`)}let a=await this.registerKey(r,n,s.meta.suiteId,{usage:s.meta.usage,cryptoProfileVersion:s.meta.cryptoProfileVersion,expiresAt:i,status:"active",rotatedFrom:e,derivation:o.derivation});try{await this.storage.updateMeta(e,{status:"rotated"})}catch(c){throw await this.storage.delete(r).catch(()=>{}),c}return a}async revokeKey(e,r){await this.storage.updateMeta(e,{status:"revoked",revokedAt:new Date().toISOString()})}async deleteKey(e){await this.storage.delete(e)}async markExpiredKeys(){let e=await this.storage.list(),r=new Date,n=0;for(let o of e)o.status==="active"&&!Er(o,r)&&(await this.storage.updateMeta(o.keyId,{status:"expired"}),n++);return n}async pruneOldKeys(e=90){let r=await this.storage.list(),n=new Date;n.setDate(n.getDate()-e);let o=0;for(let s of r)(s.status==="revoked"&&s.revokedAt&&new Date(s.revokedAt)<n||s.status==="expired"&&s.expiresAt&&new Date(s.expiresAt)<n)&&(await this.storage.delete(s.keyId),o++);return o}};var pf=/^pk-[^:-]+-(\d+)$/,Yi=8;function gn(t){if(typeof t!="string"||t.length===0)throw new Error("agentId must be a non-empty string")}function Sr(t,e){return{meta:We(t),publicKey:Uint8Array.from(e)}}function Gi(t,e){return e==="any"?!0:e==="not-revoked"?t.status!=="revoked":Er(t)}var mn=class{constructor(e){this.keyCounter=new Map;this.counterInitialized=new Set;this.counterInitPromises=new Map;this.getOrCreateInFlight=new Map;this.keyRegistry=e.keyRegistry,this.suiteRegistry=e.suiteRegistry}async createKey(e,r,n={}){gn(e);let o=this.suiteRegistry.getSuite(r.primarySignatureSuite),s;if(n.derivationContext){if(!o.capabilities?.derivation){let a=this.getSuitesWithCapability("derivation");throw new Error(`Suite '${o.suiteId}' does not support key derivation.
2050
2050
  `+(a.length>0?`Suites with derivation capability: ${a.join(", ")}
2051
- Consider using one of these suites or remove the derivationContext option.`:"No suites currently support derivation. Remove the derivationContext option."))}s=await o.capabilities.derivation.deriveKeypair(n.derivationContext)}else s=await o.generateKeypair();let i=await this.registerUnderFreshId(e,r.primarySignatureSuite,a=>this.keyRegistry.registerKey(a,s,r.primarySignatureSuite,{expiresAt:n.expiresAt,usage:n.usage||["signing"],cryptoProfileVersion:n.cryptoProfileVersion||"1.0.0",derivation:n.derivationContext?{path:n.derivationContext.path??""}:void 0}));return rn(i,s.publicKey)}async getKey(e){let r=await this.keyRegistry.getPublicKey(e);return r?rn(r.meta,r.publicKey):null}async signWithKey(e,r){let n=await this.keyRegistry.getKey(e);if(!n)throw new Error(`Key not found: ${e}`);if(n.meta.status&&n.meta.status!=="active")throw new Error(`Key is not active: ${e} (status: ${n.meta.status})`);if(ui(n.meta),!n.meta.usage.some(a=>a==="signing"||a==="both"))throw new Error(`Key is not registered for signing: ${e} (usage: ${n.meta.usage.join(", ")})`);let o=this.suiteRegistry.getSuite(n.meta.suiteId),s=this.getHashAlgorithm(n.meta.suiteId),i=await wn(r,s);return await o.sign(n.keypair.privateKey,i)}async verifySignature(e,r,n,o={}){let s=await this.keyRegistry.getPublicKey(e);return!s||!Nf(s.meta,o.keyStatus??"any")?!1:this.verifyAgainst(s.meta,s.publicKey,r,n)}async verifyAgainst(e,r,n,o){try{let s=this.suiteRegistry.getSuite(e.suiteId),i=this.getHashAlgorithm(e.suiteId),a=await wn(n,i);return await s.verify(r,a,o)===!0}catch{return!1}}async listKeysForAgent(e,r=!0){fo(e);let o=(r?await this.keyRegistry.listActiveKeys():await this.keyRegistry.listKeys()).filter(i=>tn(i.keyId)===e),s=[];for(let i of o){let a=await this.keyRegistry.getPublicKey(i.keyId);a&&s.push(rn(a.meta,a.publicKey))}return s}async getActiveCryptoProfile(e){let r=await this.listKeysForAgent(e,!0);if(r.length===0)return null;let n=this.sortKeysByCreatedAt(r),o=new Set(n.map(i=>i.meta.suiteId)),s=Array.from(o);return{primarySignatureSuite:s[0],secondarySignatureSuite:s[1]}}async rotateAgentKeys(e,r={}){let n=r.derivedKeys??"error",o=await this.listKeysForAgent(e,!0),s=[];for(let c of o){if(this.suiteRegistry.getSuite(c.meta.suiteId),c.meta.derivation){if(n==="error")throw new Error(`Key ${c.meta.keyId} was derived from a seed (path ${c.meta.derivation.path||"unknown"}). Rotating it here would replace it with a random key that the mnemonic cannot recover. Derive the successor yourself with createKeyFromMnemonic at a new path, or pass { derivedKeys: 'skip' } or { derivedKeys: 'randomize' }. No keys were rotated.`);if(n==="skip")continue}s.push(c)}let i=[];for(let c of s){let f=this.suiteRegistry.getSuite(c.meta.suiteId);i.push(await f.generateKeypair())}let a=[];for(let[c,f]of s.entries()){let d=i[c],h=await this.registerUnderFreshId(e,f.meta.suiteId,l=>this.keyRegistry.rotateKey(f.meta.keyId,l,d,{expiresAt:r.expiresAt}));a.push(rn(h,d.publicKey))}return a}async getOrCreateKey(e,r,n={}){fo(e);let o=JSON.stringify([e,r.primarySignatureSuite]),s=this.getOrCreateInFlight.get(o);if(s){let a=await s;return rn(a.meta,a.publicKey)}let i=(async()=>{let c=(await this.listKeysForAgent(e,!0)).find(f=>f.meta.suiteId===r.primarySignatureSuite);return c||await this.createKey(e,r,n)})();this.getOrCreateInFlight.set(o,i);try{return await i}finally{this.getOrCreateInFlight.delete(o)}}async createDualSignatureKeys(e,r,n={}){if(!r.secondarySignatureSuite)throw new Error("secondarySignatureSuite is required to create dual signature keys");this.assertDualProfile(r);let o=await this.createKey(e,{primarySignatureSuite:r.primarySignatureSuite},n),s=await this.createKey(e,{primarySignatureSuite:r.secondarySignatureSuite},n);return{primaryKey:o,secondaryKey:s}}async getOrCreateDualSignatureKeys(e,r,n={}){if(!r.secondarySignatureSuite)throw new Error("secondarySignatureSuite is required to create dual signature keys");this.assertDualProfile(r);let o=await this.getOrCreateKey(e,{primarySignatureSuite:r.primarySignatureSuite},n),s=await this.getOrCreateKey(e,{primarySignatureSuite:r.secondarySignatureSuite},n);return{primaryKey:o,secondaryKey:s}}assertDualProfile(e){if(this.suiteRegistry.getSuite(e.primarySignatureSuite),this.suiteRegistry.getSuite(e.secondarySignatureSuite),e.primarySignatureSuite===e.secondarySignatureSuite)throw new Error(`Dual signature keys need two different suites; both are ${e.primarySignatureSuite}`)}async signWithSuites(e,r,n){let o=this.sortKeysByCreatedAt(await this.listKeysForAgent(e,!0));if(o.length===0)throw new Error(`No active keys found for agent: ${e}`);let s=Array.from(new Set(n?.length?n:o.map(a=>a.meta.suiteId))),i=[];for(let a of s){let c=o.find(d=>d.meta.suiteId===a);if(!c)throw new Error(`No active key for suite '${a}' and agent '${e}'`);let f=await this.signWithKey(c.meta.keyId,r);i.push({suiteId:a,keyId:c.meta.keyId,signature:f})}return{signatures:i}}async verifyWithSuites(e,r,n,o={}){fo(e);let s=o.keyStatus??"not-revoked",i=Array.from(new Set(o.requiredSuites??(await this.listKeysForAgent(e,!0)).map(h=>h.meta.suiteId))),a=(h,l=[])=>({results:l,allValid:!1,requiredSuites:i,missingSuites:i.filter(p=>!l.some(y=>y.valid&&y.suiteId===p)),error:h});if(!Array.isArray(n))return a("signatures must be an array");let c=[];for(let h of n){let l=String(h?.suiteId),p=String(h?.keyId),y=g=>c.push({suiteId:l,keyId:p,valid:!1,error:g});try{if(tn(p)!==e){y(`Key does not belong to agent '${e}'`);continue}let g=await this.keyRegistry.getPublicKey(p);if(!g){y("Key not found");continue}if(g.meta.suiteId!==l){y(`Suite mismatch: key is ${g.meta.suiteId}, signature claims ${l}`);continue}if(!Nf(g.meta,s)){y(`Key status not accepted (status: ${g.meta.status??"active"}, policy: ${s})`);continue}if(!(h.signature instanceof Uint8Array)){y("Signature must be a Uint8Array");continue}await this.verifyAgainst(g.meta,g.publicKey,r,h.signature)?c.push({suiteId:l,keyId:p,valid:!0}):y("Signature verification failed")}catch(g){y(g instanceof Error?g.message:String(g))}}if(i.length===0)return a(`No required suites: agent '${e}' has no usable keys and options.requiredSuites was not given`,c);if(c.length===0)return a("No signatures supplied",c);let f=i.filter(h=>!c.some(l=>l.valid&&l.suiteId===h)),d=c.every(h=>h.valid===!0);return{results:c,allValid:d&&f.length===0,requiredSuites:i,missingSuites:f,...f.length>0?{error:`No valid signature for required suite(s): ${f.join(", ")}`}:{}}}generateMnemonic(e=256){return new Oe().generateMnemonic(e)}async createKeyFromMnemonic(e,r,n,o=Oe.bitcoinPath(0,0,0),s,i={}){let c=new Oe().mnemonicToSeed(n,s);try{return await this.createKey(e,r,{...i,derivationContext:{seed:c,path:o}})}finally{c.fill(0)}}getCapabilities(e){let r=this.suiteRegistry.getSuite(e),n=[];return r.capabilities?.derivation&&n.push("derivation"),r.capabilities?.encryption&&n.push("encryption"),r.capabilities?.threshold&&n.push("threshold"),n}getSuitesWithCapability(e){return this.suiteRegistry.getAllSuites().filter(n=>!!n.capabilities?.[e]).map(n=>n.suiteId)}async createWalletKey(e,r,n,o={}){if(!n||typeof n.coinType!="number")throw new Error("createWalletKey requires path.coinType (SLIP-44: Bitcoin is 0, Bitcoin SV is 236)");let s=Oe.bip44Path(n.coinType,n.account??0,n.change?1:0,n.index??0);return this.createKeyFromMnemonic(e,{primarySignatureSuite:"bsv-ecdsa-secp256k1"},r,s,n.passphrase,o)}async createBitcoinWalletKey(e,r,n=0,o=0,s=!1,i={}){let a=Oe.bitcoinPath(n,s?1:0,o);return this.createKeyFromMnemonic(e,{primarySignatureSuite:"bsv-ecdsa-secp256k1"},r,a,void 0,i)}getHashAlgorithm(e){return e.startsWith("ml-dsa")?"sha3-256":"sha256"}async registerUnderFreshId(e,r,n){let o=r.split("-")[0].replace(/[^A-Za-z0-9]/g,"")||"key";for(let s=0;s<Mf;s++){let i=await this.getNextCounter(e),a=`${e}:pk-${o}-${i}`;try{return await n(a)}catch(c){if(!(c instanceof qt))throw c;this.counterInitialized.delete(e),this.keyCounter.delete(e)}}throw new Error(`Could not allocate a key ID for agent '${e}' after ${Mf} attempts`)}async getNextCounter(e){if(!this.counterInitialized.has(e)){if(!this.counterInitPromises.has(e)){let s=(async()=>{try{let a=(await this.keyRegistry.listKeys()).reduce((c,f)=>{if(tn(f.keyId)!==e)return c;let d=f.keyId.slice(e.length+1),h=Dl.exec(d);if(!h)return c;let l=parseInt(h[1],10);return Number.isSafeInteger(l)?Math.max(c,l):c},0);this.keyCounter.set(e,Math.max(a,this.keyCounter.get(e)||0)),this.counterInitialized.add(e)}finally{this.counterInitPromises.delete(e)}})();this.counterInitPromises.set(e,s)}let o=this.counterInitPromises.get(e);o&&await o}let n=(this.keyCounter.get(e)||0)+1;return this.keyCounter.set(e,n),n}sortKeysByCreatedAt(e){return[...e].sort((r,n)=>{let o=new Date(r.meta.createdAt).getTime(),s=new Date(n.meta.createdAt).getTime();if(o!==s)return o-s;let i=this.getSuitePriority(r.meta.suiteId)-this.getSuitePriority(n.meta.suiteId);return i!==0?i:r.meta.keyId.localeCompare(n.meta.keyId)})}getSuitePriority(e){return e.startsWith("ml-dsa")?0:e.includes("ecdsa")?1:2}};async function li(t){let e=t?.keyRegistry??new Gt(new Lt);return new uo({keyRegistry:e,suiteRegistry:Tt})}var Ml={createKeySDK:li};typeof window<"u"&&(window.LumenKeys={createKeySDK:li});return Wf(Nl);})();
2051
+ Consider using one of these suites or remove the derivationContext option.`:"No suites currently support derivation. Remove the derivationContext option."))}s=await o.capabilities.derivation.deriveKeypair(n.derivationContext)}else s=await o.generateKeypair();let i=await this.registerUnderFreshId(e,r.primarySignatureSuite,a=>this.keyRegistry.registerKey(a,s,r.primarySignatureSuite,{expiresAt:n.expiresAt,usage:n.usage||["signing"],cryptoProfileVersion:n.cryptoProfileVersion||"1.0.0",derivation:n.derivationContext?{path:n.derivationContext.path??""}:void 0}));return Sr(i,s.publicKey)}async getKey(e){let r=await this.keyRegistry.getPublicKey(e);return r?Sr(r.meta,r.publicKey):null}async signWithKey(e,r){let n=await this.keyRegistry.getKey(e);if(!n)throw new Error(`Key not found: ${e}`);if(n.meta.status&&n.meta.status!=="active")throw new Error(`Key is not active: ${e} (status: ${n.meta.status})`);if(Lo(n.meta),!n.meta.usage.some(a=>a==="signing"||a==="both"))throw new Error(`Key is not registered for signing: ${e} (usage: ${n.meta.usage.join(", ")})`);let o=this.suiteRegistry.getSuite(n.meta.suiteId),s=this.getHashAlgorithm(n.meta.suiteId),i=await jr(r,s);return await o.sign(n.keypair.privateKey,i)}async verifySignature(e,r,n,o={}){let s=await this.keyRegistry.getPublicKey(e);return!s||!Gi(s.meta,o.keyStatus??"any")?!1:this.verifyAgainst(s.meta,s.publicKey,r,n)}async verifyAgainst(e,r,n,o){try{let s=this.suiteRegistry.getSuite(e.suiteId),i=this.getHashAlgorithm(e.suiteId),a=await jr(n,i);return await s.verify(r,a,o)===!0}catch{return!1}}async listKeysForAgent(e,r=!0){gn(e);let o=(r?await this.keyRegistry.listActiveKeys():await this.keyRegistry.listKeys()).filter(i=>vr(i.keyId)===e),s=[];for(let i of o){let a=await this.keyRegistry.getPublicKey(i.keyId);a&&s.push(Sr(a.meta,a.publicKey))}return s}async getActiveCryptoProfile(e){let r=await this.listKeysForAgent(e,!0);if(r.length===0)return null;let n=this.sortKeysByCreatedAt(r),o=new Set(n.map(i=>i.meta.suiteId)),s=Array.from(o);return{primarySignatureSuite:s[0],secondarySignatureSuite:s[1]}}async rotateAgentKeys(e,r={}){let n=r.derivedKeys??"error",o=await this.listKeysForAgent(e,!0),s=[];for(let c of o){if(this.suiteRegistry.getSuite(c.meta.suiteId),c.meta.derivation){if(n==="error")throw new Error(`Key ${c.meta.keyId} was derived from a seed (path ${c.meta.derivation.path||"unknown"}). Rotating it here would replace it with a random key that the mnemonic cannot recover. Derive the successor yourself with createKeyFromMnemonic at a new path, or pass { derivedKeys: 'skip' } or { derivedKeys: 'randomize' }. No keys were rotated.`);if(n==="skip")continue}s.push(c)}let i=[];for(let c of s){let f=this.suiteRegistry.getSuite(c.meta.suiteId);i.push(await f.generateKeypair())}let a=[];for(let[c,f]of s.entries()){let u=i[c],d=await this.registerUnderFreshId(e,f.meta.suiteId,l=>this.keyRegistry.rotateKey(f.meta.keyId,l,u,{expiresAt:r.expiresAt}));a.push(Sr(d,u.publicKey))}return a}async getOrCreateKey(e,r,n={}){gn(e);let o=JSON.stringify([e,r.primarySignatureSuite]),s=this.getOrCreateInFlight.get(o);if(s){let a=await s;return Sr(a.meta,a.publicKey)}let i=(async()=>{let c=(await this.listKeysForAgent(e,!0)).find(f=>f.meta.suiteId===r.primarySignatureSuite);return c||await this.createKey(e,r,n)})();this.getOrCreateInFlight.set(o,i);try{return await i}finally{this.getOrCreateInFlight.delete(o)}}async createDualSignatureKeys(e,r,n={}){if(!r.secondarySignatureSuite)throw new Error("secondarySignatureSuite is required to create dual signature keys");this.assertDualProfile(r);let o=await this.createKey(e,{primarySignatureSuite:r.primarySignatureSuite},n),s=await this.createKey(e,{primarySignatureSuite:r.secondarySignatureSuite},n);return{primaryKey:o,secondaryKey:s}}async getOrCreateDualSignatureKeys(e,r,n={}){if(!r.secondarySignatureSuite)throw new Error("secondarySignatureSuite is required to create dual signature keys");this.assertDualProfile(r);let o=await this.getOrCreateKey(e,{primarySignatureSuite:r.primarySignatureSuite},n),s=await this.getOrCreateKey(e,{primarySignatureSuite:r.secondarySignatureSuite},n);return{primaryKey:o,secondaryKey:s}}assertDualProfile(e){if(this.suiteRegistry.getSuite(e.primarySignatureSuite),this.suiteRegistry.getSuite(e.secondarySignatureSuite),e.primarySignatureSuite===e.secondarySignatureSuite)throw new Error(`Dual signature keys need two different suites; both are ${e.primarySignatureSuite}`)}async signWithSuites(e,r,n){let o=this.sortKeysByCreatedAt(await this.listKeysForAgent(e,!0));if(o.length===0)throw new Error(`No active keys found for agent: ${e}`);let s=Array.from(new Set(n?.length?n:o.map(a=>a.meta.suiteId))),i=[];for(let a of s){let c=o.find(u=>u.meta.suiteId===a);if(!c)throw new Error(`No active key for suite '${a}' and agent '${e}'`);let f=await this.signWithKey(c.meta.keyId,r);i.push({suiteId:a,keyId:c.meta.keyId,signature:f})}return{signatures:i}}async verifyWithSuites(e,r,n,o={}){gn(e);let s=o.keyStatus??"not-revoked",i=Array.from(new Set(o.requiredSuites??(await this.listKeysForAgent(e,!0)).map(d=>d.meta.suiteId))),a=(d,l=[])=>({results:l,allValid:!1,requiredSuites:i,missingSuites:i.filter(p=>!l.some(y=>y.valid&&y.suiteId===p)),error:d});if(!Array.isArray(n))return a("signatures must be an array");let c=[];for(let d of n){let l=String(d?.suiteId),p=String(d?.keyId),y=b=>c.push({suiteId:l,keyId:p,valid:!1,error:b});try{if(vr(p)!==e){y(`Key does not belong to agent '${e}'`);continue}let b=await this.keyRegistry.getPublicKey(p);if(!b){y("Key not found");continue}if(b.meta.suiteId!==l){y(`Suite mismatch: key is ${b.meta.suiteId}, signature claims ${l}`);continue}if(!Gi(b.meta,s)){y(`Key status not accepted (status: ${b.meta.status??"active"}, policy: ${s})`);continue}if(!(d.signature instanceof Uint8Array)){y("Signature must be a Uint8Array");continue}await this.verifyAgainst(b.meta,b.publicKey,r,d.signature)?c.push({suiteId:l,keyId:p,valid:!0}):y("Signature verification failed")}catch(b){y(b instanceof Error?b.message:String(b))}}if(i.length===0)return a(`No required suites: agent '${e}' has no usable keys and options.requiredSuites was not given`,c);if(c.length===0)return a("No signatures supplied",c);let f=i.filter(d=>!c.some(l=>l.valid&&l.suiteId===d)),u=c.every(d=>d.valid===!0);return{results:c,allValid:u&&f.length===0,requiredSuites:i,missingSuites:f,...f.length>0?{error:`No valid signature for required suite(s): ${f.join(", ")}`}:{}}}generateMnemonic(e=256){return new Re().generateMnemonic(e)}async createKeyFromMnemonic(e,r,n,o=Re.bitcoinPath(0,0,0),s,i={}){let c=new Re().mnemonicToSeed(n,s);try{return await this.createKey(e,r,{...i,derivationContext:{seed:c,path:o}})}finally{c.fill(0)}}getCapabilities(e){let r=this.suiteRegistry.getSuite(e),n=[];return r.capabilities?.derivation&&n.push("derivation"),r.capabilities?.encryption&&n.push("encryption"),r.capabilities?.threshold&&n.push("threshold"),n}getSuitesWithCapability(e){return this.suiteRegistry.getAllSuites().filter(n=>!!n.capabilities?.[e]).map(n=>n.suiteId)}async createWalletKey(e,r,n,o={}){if(!n||typeof n.coinType!="number")throw new Error("createWalletKey requires path.coinType (SLIP-44: Bitcoin is 0, Bitcoin SV is 236)");let s=Re.bip44Path(n.coinType,n.account??0,n.change?1:0,n.index??0);return this.createKeyFromMnemonic(e,{primarySignatureSuite:"bsv-ecdsa-secp256k1"},r,s,n.passphrase,o)}async createBitcoinWalletKey(e,r,n=0,o=0,s=!1,i={}){let a=Re.bitcoinPath(n,s?1:0,o);return this.createKeyFromMnemonic(e,{primarySignatureSuite:"bsv-ecdsa-secp256k1"},r,a,void 0,i)}getHashAlgorithm(e){return e.startsWith("ml-dsa")?"sha3-256":"sha256"}async registerUnderFreshId(e,r,n){let o=r.split("-")[0].replace(/[^A-Za-z0-9]/g,"")||"key";for(let s=0;s<Yi;s++){let i=await this.getNextCounter(e),a=`${e}:pk-${o}-${i}`;try{return await n(a)}catch(c){if(!(c instanceof Tt))throw c;this.counterInitialized.delete(e),this.keyCounter.delete(e)}}throw new Error(`Could not allocate a key ID for agent '${e}' after ${Yi} attempts`)}async getNextCounter(e){if(!this.counterInitialized.has(e)){if(!this.counterInitPromises.has(e)){let s=(async()=>{try{let a=(await this.keyRegistry.listKeys()).reduce((c,f)=>{if(vr(f.keyId)!==e)return c;let u=f.keyId.slice(e.length+1),d=pf.exec(u);if(!d)return c;let l=parseInt(d[1],10);return Number.isSafeInteger(l)?Math.max(c,l):c},0);this.keyCounter.set(e,Math.max(a,this.keyCounter.get(e)||0)),this.counterInitialized.add(e)}finally{this.counterInitPromises.delete(e)}})();this.counterInitPromises.set(e,s)}let o=this.counterInitPromises.get(e);o&&await o}let n=(this.keyCounter.get(e)||0)+1;return this.keyCounter.set(e,n),n}sortKeysByCreatedAt(e){return[...e].sort((r,n)=>{let o=new Date(r.meta.createdAt).getTime(),s=new Date(n.meta.createdAt).getTime();if(o!==s)return o-s;let i=this.getSuitePriority(r.meta.suiteId)-this.getSuitePriority(n.meta.suiteId);return i!==0?i:r.meta.keyId.localeCompare(n.meta.keyId)})}getSuitePriority(e){return e.startsWith("ml-dsa")?0:e.includes("ecdsa")?1:2}};async function Fo(t){let e=t?.keyRegistry??new Kt(new dt);return new mn({keyRegistry:e,suiteRegistry:lt})}var yf={createKeySDK:Fo};typeof window<"u"&&(window.LumenKeys={createKeySDK:Fo});return nc(gf);})();
2052
2052
  /*! Bundled license information:
2053
2053
 
2054
2054
  @noble/curves/utils.js: