@smartledger/keys 2.0.0 → 3.1.0

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 e0=Object.getOwnPropertyDescriptor;var t0=Object.getOwnPropertyNames;var r0=Object.prototype.hasOwnProperty;var n0=(t,e,r)=>e in t?sn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var pe=(t,e)=>()=>(t&&(e=t(t=0)),e);var oo=(t,e)=>{for(var r in e)sn(t,r,{get:e[r],enumerable:!0})},o0=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of t0(e))!r0.call(t,o)&&o!==r&&sn(t,o,{get:()=>e[o],enumerable:!(n=e0(e,o))||n.enumerable});return t};var s0=t=>o0(sn({},"__esModule",{value:!0}),t);var d=(t,e,r)=>n0(t,typeof e!="symbol"?e+"":e,r);var m=pe(()=>{"use strict";if(typeof Uint8Array.prototype.toString!="function"||!Uint8Array.prototype.toString.toString().includes("[native code]")){let t=Uint8Array.prototype.toString;Uint8Array.prototype.toString=function(e){if(e==="base64"){let r="",n=new Uint8Array(this);for(let o=0;o<n.byteLength;o++)r+=String.fromCharCode(n[o]);return btoa(r)}return t.call(this)}}typeof window>"u"&&(window.global=window)});function S0(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function vr(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Xe(t,...e){if(!S0(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function bi(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");vr(t.outputLen),vr(t.blockLen)}function Je(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function ln(t,e){Xe(t);let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function gi(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function ke(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function dn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Ie(t,e){return t<<32-e|t>>>e}function H0(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function I0(t){for(let e=0;e<t.length;e++)t[e]=H0(t[e]);return t}function L0(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Kt(t){return typeof t=="string"&&(t=L0(t)),Xe(t),t}function Br(t){let e=n=>t().update(Kt(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}var k0,lo,at,Sr=pe(()=>{m();k0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;lo=k0?t=>t:I0;at=class{}});function U0(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),a=n?4:0,u=n?0:4;t.setUint32(e+a,i,n),t.setUint32(e+u,c,n)}function mi(t,e,r){return t&e^~t&r}function wi(t,e,r){return t&e^t&r^e&r}var kr,Qe,fe,Ei=pe(()=>{m();Sr();kr=class extends at{constructor(e,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=dn(this.buffer)}update(e){Je(this),e=Kt(e),Xe(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=dn(e);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(e.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Je(this),ln(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,ke(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)r[f]=0;U0(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=dn(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)c.setUint32(4*f,l[f],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=c,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Qe=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),fe=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209])});function _0(t,e=!1){return e?{h:Number(t&pn),l:Number(t>>Ai&pn)}:{h:Number(t>>Ai&pn)|0,l:Number(t&pn)|0}}function xn(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:c}=_0(t[s],e);[n[s],o[s]]=[i,c]}return[n,o]}function Ve(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var pn,Ai,po,xo,Ct,Ot,Hr,Ir,vi,Bi,Si,ki,Hi,Ii,Li,Ui,_i,Ki,yo=pe(()=>{m();pn=BigInt(4294967295),Ai=BigInt(32);po=(t,e,r)=>t>>>r,xo=(t,e,r)=>t<<32-r|e>>>r,Ct=(t,e,r)=>t>>>r|e<<32-r,Ot=(t,e,r)=>t<<32-r|e>>>r,Hr=(t,e,r)=>t<<64-r|e>>>r-32,Ir=(t,e,r)=>t>>>r-32|e<<64-r,vi=(t,e,r)=>t<<r|e>>>32-r,Bi=(t,e,r)=>e<<r|t>>>32-r,Si=(t,e,r)=>e<<r-32|t>>>64-r,ki=(t,e,r)=>t<<r-32|e>>>64-r;Hi=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Ii=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Li=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Ui=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,_i=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Ki=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0});var C0,ft,yn,Ci,O0,R0,ut,lt,bo,bn,Oi,go=pe(()=>{m();Ei();yo();Sr();C0=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]),ft=new Uint32Array(64),yn=class extends kr{constructor(e=32){super(64,e,8,!1),this.A=Qe[0]|0,this.B=Qe[1]|0,this.C=Qe[2]|0,this.D=Qe[3]|0,this.E=Qe[4]|0,this.F=Qe[5]|0,this.G=Qe[6]|0,this.H=Qe[7]|0}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[e,r,n,o,s,i,c,a]}set(e,r,n,o,s,i,c,a){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(e,r){for(let f=0;f<16;f++,r+=4)ft[f]=e.getUint32(r,!1);for(let f=16;f<64;f++){let h=ft[f-15],p=ft[f-2],x=Ie(h,7)^Ie(h,18)^h>>>3,w=Ie(p,17)^Ie(p,19)^p>>>10;ft[f]=w+ft[f-7]+x+ft[f-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:l}=this;for(let f=0;f<64;f++){let h=Ie(c,6)^Ie(c,11)^Ie(c,25),p=l+h+mi(c,a,u)+C0[f]+ft[f]|0,w=(Ie(n,2)^Ie(n,13)^Ie(n,22))+wi(n,o,s)|0;l=u,u=a,a=c,c=i+p|0,i=s,s=o,o=n,n=p+w|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,c,a,u,l)}roundClean(){ke(ft)}destroy(){this.set(0,0,0,0,0,0,0,0),ke(this.buffer)}},Ci=xn(["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))),O0=Ci[0],R0=Ci[1],ut=new Uint32Array(80),lt=new Uint32Array(80),bo=class extends kr{constructor(e=64){super(128,e,16,!1),this.Ah=fe[0]|0,this.Al=fe[1]|0,this.Bh=fe[2]|0,this.Bl=fe[3]|0,this.Ch=fe[4]|0,this.Cl=fe[5]|0,this.Dh=fe[6]|0,this.Dl=fe[7]|0,this.Eh=fe[8]|0,this.El=fe[9]|0,this.Fh=fe[10]|0,this.Fl=fe[11]|0,this.Gh=fe[12]|0,this.Gl=fe[13]|0,this.Hh=fe[14]|0,this.Hl=fe[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:l,Fh:f,Fl:h,Gh:p,Gl:x,Hh:w,Hl:v}=this;return[e,r,n,o,s,i,c,a,u,l,f,h,p,x,w,v]}set(e,r,n,o,s,i,c,a,u,l,f,h,p,x,w,v){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=h|0,this.Gh=p|0,this.Gl=x|0,this.Hh=w|0,this.Hl=v|0}process(e,r){for(let y=0;y<16;y++,r+=4)ut[y]=e.getUint32(r),lt[y]=e.getUint32(r+=4);for(let y=16;y<80;y++){let L=ut[y-15]|0,P=lt[y-15]|0,F=Ct(L,P,1)^Ct(L,P,8)^po(L,P,7),X=Ot(L,P,1)^Ot(L,P,8)^xo(L,P,7),M=ut[y-2]|0,U=lt[y-2]|0,Y=Ct(M,U,19)^Hr(M,U,61)^po(M,U,6),ee=Ot(M,U,19)^Ir(M,U,61)^xo(M,U,6),$=Li(X,ee,lt[y-7],lt[y-16]),j=Ui($,F,Y,ut[y-7],ut[y-16]);ut[y]=j|0,lt[y]=$|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:l,Eh:f,El:h,Fh:p,Fl:x,Gh:w,Gl:v,Hh:I,Hl:B}=this;for(let y=0;y<80;y++){let L=Ct(f,h,14)^Ct(f,h,18)^Hr(f,h,41),P=Ot(f,h,14)^Ot(f,h,18)^Ir(f,h,41),F=f&p^~f&w,X=h&x^~h&v,M=_i(B,P,X,R0[y],lt[y]),U=Ki(M,I,L,F,O0[y],ut[y]),Y=M|0,ee=Ct(n,o,28)^Hr(n,o,34)^Hr(n,o,39),$=Ot(n,o,28)^Ir(n,o,34)^Ir(n,o,39),j=n&s^n&c^s&c,g=o&i^o&a^i&a;I=w|0,B=v|0,w=p|0,v=x|0,p=f|0,x=h|0,{h:f,l:h}=Ve(u|0,l|0,U|0,Y|0),u=c|0,l=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let b=Hi(Y,$,g);n=Ii(b,U,ee,j),o=b|0}({h:n,l:o}=Ve(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ve(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Ve(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l}=Ve(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:h}=Ve(this.Eh|0,this.El|0,f|0,h|0),{h:p,l:x}=Ve(this.Fh|0,this.Fl|0,p|0,x|0),{h:w,l:v}=Ve(this.Gh|0,this.Gl|0,w|0,v|0),{h:I,l:B}=Ve(this.Hh|0,this.Hl|0,I|0,B|0),this.set(n,o,s,i,c,a,u,l,f,h,p,x,w,v,I,B)}roundClean(){ke(ut,lt)}destroy(){ke(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},bn=Br(()=>new yn),Oi=Br(()=>new bo)});function j0(t,e=24){let r=new Uint32Array(10);for(let n=24-e;n<24;n++){for(let i=0;i<10;i++)r[i]=t[i]^t[i+10]^t[i+20]^t[i+30]^t[i+40];for(let i=0;i<10;i+=2){let c=(i+8)%10,a=(i+2)%10,u=r[a],l=r[a+1],f=Ri(u,l,1)^r[c],h=Ti(u,l,1)^r[c+1];for(let p=0;p<50;p+=10)t[i+p]^=f,t[i+p+1]^=h}let o=t[2],s=t[3];for(let i=0;i<24;i++){let c=Mi[i],a=Ri(o,s,c),u=Ti(o,s,c),l=Di[i];o=t[l],s=t[l+1],t[l]=a,t[l+1]=u}for(let i=0;i<50;i+=10){for(let c=0;c<10;c++)r[c]=t[i+c];for(let c=0;c<10;c++)t[i+c]^=~r[(c+2)%10]&r[(c+4)%10]}t[0]^=V0[n],t[1]^=$0[n]}ke(r)}var T0,Lr,D0,M0,N0,P0,Di,Mi,Ni,Pi,V0,$0,Ri,Ti,mo,q0,Vi,$i=pe(()=>{m();yo();Sr();T0=BigInt(0),Lr=BigInt(1),D0=BigInt(2),M0=BigInt(7),N0=BigInt(256),P0=BigInt(113),Di=[],Mi=[],Ni=[];for(let t=0,e=Lr,r=1,n=0;t<24;t++){[r,n]=[n,(2*r+3*n)%5],Di.push(2*(5*n+r)),Mi.push((t+1)*(t+2)/2%64);let o=T0;for(let s=0;s<7;s++)e=(e<<Lr^(e>>M0)*P0)%N0,e&D0&&(o^=Lr<<(Lr<<BigInt(s))-Lr);Ni.push(o)}Pi=xn(Ni,!0),V0=Pi[0],$0=Pi[1],Ri=(t,e,r)=>r>32?Si(t,e,r):vi(t,e,r),Ti=(t,e,r)=>r>32?ki(t,e,r):Bi(t,e,r);mo=class t extends at{constructor(e,r,n,o=!1,s=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=r,this.outputLen=n,this.enableXOF=o,this.rounds=s,vr(n),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=gi(this.state)}clone(){return this._cloneInto()}keccak(){lo(this.state32),j0(this.state32,this.rounds),lo(this.state32),this.posOut=0,this.pos=0}update(e){Je(this),e=Kt(e),Xe(e);let{blockLen:r,state:n}=this,o=e.length;for(let s=0;s<o;){let i=Math.min(r-this.pos,o-s);for(let c=0;c<i;c++)n[this.pos++]^=e[s++];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&&n===o-1&&this.keccak(),e[o-1]^=128,this.keccak()}writeInto(e){Je(this,!1),Xe(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 possible for this instance");return this.writeInto(e)}xof(e){return vr(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(ln(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,ke(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.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.destroyed=this.destroyed,e}},q0=(t,e,r)=>Br(()=>new mo(e,t,r)),Vi=q0(6,136,256/8)});var gn={};oo(gn,{createHash:()=>ji,default:()=>G0});function ji(t){let e=new Uint8Array(0),r;switch(t.toLowerCase()){case"sha256":case"sha-256":r=bn;break;case"sha512":case"sha-512":r=Oi;break;case"sha3-256":r=Vi;break;default:throw new Error(`Unsupported hash algorithm: ${t}`)}return{update(n){let o=n instanceof Uint8Array?n:new Uint8Array(n),s=new Uint8Array(e.length+o.length);return s.set(e),s.set(o,e.length),e=s,this},digest(){return r(e)}}}var G0,mn=pe(()=>{"use strict";m();go();$i();G0={createHash:ji}});function _r(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function $e(t,e=""){if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new Error(`${r}expected integer >= 0, got ${t}`)}}function Q(t,e,r=""){let n=_r(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,c=s?` of length ${e}`:"",a=n?`length=${o}`:`type=${typeof t}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return t}function En(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash must wrapped by utils.createHasher");$e(t.outputLen),$e(t.blockLen)}function nr(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Gi(t,e){Q(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function Tt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function An(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Le(t,e){return t<<32-e|t>>>e}function Dt(t){if(Q(t),Fi)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=F0[t[r]];return e}function qi(t){if(t>=et._0&&t<=et._9)return t-et._0;if(t>=et.A&&t<=et.F)return t-(et.A-10);if(t>=et.a&&t<=et.f)return t-(et.a-10)}function Mt(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(Fi)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("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=qi(t.charCodeAt(s)),c=qi(t.charCodeAt(s+1));if(i===void 0||c===void 0){let a=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function Ue(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Q(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 Wi(t,e={}){let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function vn(t=32){let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(t))}var Fi,F0,et,zi,Nt=pe(()=>{m();Fi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",F0=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));et={_0:48,_9:57,A:65,F:70,a:97,f:102};zi=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])})});function Pt(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new Error(r+"expected boolean, got type="+typeof t)}return t}function Ji(t){if(typeof t=="bigint"){if(!Sn(t))throw new Error("positive bigint expected, got "+t)}else $e(t);return t}function Kr(t){let e=Ji(t).toString(16);return e.length&1?"0"+e:e}function Qi(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?vo:BigInt("0x"+t)}function or(t){return Qi(Dt(t))}function Bo(t){return Qi(Dt(z0(Q(t)).reverse()))}function kn(t,e){$e(e),t=Ji(t);let r=Mt(t.toString(16).padStart(e*2,"0"));if(r.length!==e)throw new Error("number too large");return r}function So(t,e){return kn(t,e).reverse()}function z0(t){return Uint8Array.from(t)}function Z0(t,e,r){return Sn(t)&&Sn(e)&&Sn(r)&&e<=t&&t<r}function ec(t,e,r,n){if(!Z0(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function ko(t){let e;for(e=0;t>vo;t>>=Ao,e+=1);return e}function tc(t,e,r){if($e(t,"hashLen"),$e(e,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=v=>new Uint8Array(v),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),c=1e3,a=n(t),u=n(t),l=0,f=()=>{a.fill(1),u.fill(0),l=0},h=(...v)=>r(u,Ue(a,...v)),p=(v=o)=>{u=h(s,v),a=h(),v.length!==0&&(u=h(i,v),a=h())},x=()=>{if(l++>=c)throw new Error("drbg: tried max amount of iterations");let v=0,I=[];for(;v<e;){a=h();let B=a.slice();I.push(B),v+=a.length}return Ue(...I)};return(v,I)=>{f(),p(v);let B;for(;!(B=I(x()));)p();return f(),B}}function Or(t,e={},r={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function n(s,i,c){let a=t[s];if(c&&a===void 0)return;let u=typeof a;if(u!==i||a===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([c,a])=>n(c,a,i));o(e,!1),o(r,!0)}function Ho(t){let e=new WeakMap;return(r,...n)=>{let o=e.get(r);if(o!==void 0)return o;let s=t(r,...n);return e.set(r,s),s}}var vo,Ao,Sn,Cr,Rr=pe(()=>{m();Nt();Nt();vo=BigInt(0),Ao=BigInt(1);Sn=t=>typeof t=="bigint"&&vo<=t;Cr=t=>(Ao<<BigInt(t))-Ao});function Zf(t,e=!1){return e?{h:Number(t&Gn),l:Number(t>>Aa&Gn)}:{h:Number(t>>Aa&Gn)|0,l:Number(t&Gn)|0}}function va(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:c}=Zf(t[s],e);[n[s],o[s]]=[i,c]}return[n,o]}var Gn,Aa,Ba,Sa,ka,Ha,Ia=pe(()=>{m();Gn=BigInt(4294967295),Aa=BigInt(32);Ba=(t,e,r)=>t<<r|e>>>32-r,Sa=(t,e,r)=>e<<r|t>>>32-r,ka=(t,e,r)=>e<<r-32|t>>>64-r,Ha=(t,e,r)=>t<<r-32|e>>>64-r});function ws(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Es(t,e=""){if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new Error(`${r}expected integer >= 0, got ${t}`)}}function ie(t,e,r=""){let n=ws(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,c=s?` of length ${e}`:"",a=n?`length=${o}`:`type=${typeof t}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return t}function As(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function La(t,e){ie(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function Ua(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function vs(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Xf(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function Jf(t){for(let e=0;e<t.length;e++)t[e]=Xf(t[e]);return t}function Ss(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];ie(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 _a(t,e={}){let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function Ka(t=32){let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(t))}var Yf,Bs,ks,Fn=pe(()=>{m();Yf=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;Bs=Yf?t=>t:Jf;ks=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])})});function iu(t,e=24){let r=new Uint32Array(10);for(let n=24-e;n<24;n++){for(let i=0;i<10;i++)r[i]=t[i]^t[i+10]^t[i+20]^t[i+30]^t[i+40];for(let i=0;i<10;i+=2){let c=(i+8)%10,a=(i+2)%10,u=r[a],l=r[a+1],f=Ca(u,l,1)^r[c],h=Oa(u,l,1)^r[c+1];for(let p=0;p<50;p+=10)t[i+p]^=f,t[i+p+1]^=h}let o=t[2],s=t[3];for(let i=0;i<24;i++){let c=Ta[i],a=Ca(o,s,c),u=Oa(o,s,c),l=Ra[i];o=t[l],s=t[l+1],t[l]=a,t[l+1]=u}for(let i=0;i<50;i+=10){for(let c=0;c<10;c++)r[c]=t[i+c];for(let c=0;c<10;c++)t[i+c]^=~r[(c+2)%10]&r[(c+4)%10]}t[0]^=ou[n],t[1]^=su[n]}vs(r)}var Qf,zr,eu,tu,ru,nu,Ra,Ta,Da,Ma,ou,su,Ca,Oa,Hs,Na,Pa,be,Is=pe(()=>{m();Ia();Fn();Qf=BigInt(0),zr=BigInt(1),eu=BigInt(2),tu=BigInt(7),ru=BigInt(256),nu=BigInt(113),Ra=[],Ta=[],Da=[];for(let t=0,e=zr,r=1,n=0;t<24;t++){[r,n]=[n,(2*r+3*n)%5],Ra.push(2*(5*n+r)),Ta.push((t+1)*(t+2)/2%64);let o=Qf;for(let s=0;s<7;s++)e=(e<<zr^(e>>tu)*nu)%ru,e&eu&&(o^=zr<<(zr<<BigInt(s))-zr);Da.push(o)}Ma=va(Da,!0),ou=Ma[0],su=Ma[1],Ca=(t,e,r)=>r>32?ka(t,e,r):Ba(t,e,r),Oa=(t,e,r)=>r>32?Ha(t,e,r):Sa(t,e,r);Hs=class t{constructor(e,r,n,o=!1,s=24){d(this,"state");d(this,"pos",0);d(this,"posOut",0);d(this,"finished",!1);d(this,"state32");d(this,"destroyed",!1);d(this,"blockLen");d(this,"suffix");d(this,"outputLen");d(this,"enableXOF",!1);d(this,"rounds");if(this.blockLen=e,this.suffix=r,this.outputLen=n,this.enableXOF=o,this.rounds=s,Es(n,"outputLen"),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=Ua(this.state)}clone(){return this._cloneInto()}keccak(){Bs(this.state32),iu(this.state32,this.rounds),Bs(this.state32),this.posOut=0,this.pos=0}update(e){As(this),ie(e);let{blockLen:r,state:n}=this,o=e.length;for(let s=0;s<o;){let i=Math.min(r-this.pos,o-s);for(let c=0;c<i;c++)n[this.pos++]^=e[s++];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&&n===o-1&&this.keccak(),e[o-1]^=128,this.keccak()}writeInto(e){As(this,!1),ie(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 possible for this instance");return this.writeInto(e)}xof(e){return Es(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(La(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,vs(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.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.destroyed=this.destroyed,e}},Na=(t,e,r,n={})=>_a((o={})=>new Hs(e,t,o.dkLen===void 0?r:o.dkLen,!0),n),Pa=Na(31,168,16,ks(11)),be=Na(31,136,32,ks(12))});function Ls(t){if(!Number.isSafeInteger(t)||t<0||t>4294967295)throw new Error("wrong u32 integer:"+t);return t}function $a(t){return Ls(t),(t&t-1)===0&&t!==0}function Us(t,e){Ls(t);let r=0;for(let n=0;n<e;n++,t>>>=1)r=r<<1|t&1;return r}function ja(t){return Ls(t),31-Math.clz32(t)}function Va(t){let e=t.length;if(e<2||!$a(e))throw new Error("n must be a power of 2 and greater than 1. Got "+e);let r=ja(e);for(let n=0;n<e;n++){let o=Us(n,r);if(n<o){let s=t[n];t[n]=t[o],t[o]=s}}return t}var _s,qa=pe(()=>{m();_s=(t,e)=>{let{N:r,roots:n,dit:o,invertButterflies:s=!1,skipStages:i=0,brp:c=!0}=e,a=ja(r);if(!$a(r))throw new Error("FFT: Polynomial size should be power of two");let u=o!==s;return l=>{if(l.length!==r)throw new Error("FFT: wrong Polynomial length");o&&c&&Va(l);for(let f=0,h=1;f<a-i;f++){let p=o?f+1+i:a-f,x=1<<p,w=x>>1,v=r>>p;for(let I=0;I<r;I+=x)for(let B=0,y=h++;B<w;B++){let L=s?o?r-y:y:B*v,P=I+B,F=I+B+w,X=n[L],M=l[F],U=l[P];if(u){let Y=t.mul(M,X);l[P]=t.add(U,Y),l[F]=t.sub(U,Y)}else s?(l[P]=t.add(M,U),l[F]=t.mul(t.sub(M,U),X)):(l[P]=t.add(U,M),l[F]=t.mul(t.sub(U,M),X))}}return!o&&c&&Va(l),l}}});function Cs(t,e){if(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 Os(t){if(typeof t!="object"||t===null||ws(t))throw new Error("expected opts to be an object")}function Wn(t){Os(t),t.context!==void 0&&ie(t.context,void 0,"opts.context")}function zn(t){Wn(t),t.extraEntropy!==!1&&t.extraEntropy!==void 0&&ie(t.extraEntropy,void 0,"opts.extraEntropy")}function Zr(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,c=0;i<e.length;i++){let a=e[i],u=r(a),l=typeof a=="number"?o[i]:a.encode(o[i]);ie(l,u,t),s.set(l,c),typeof a!="number"&&l.fill(0),c+=u}return s},decode:o=>{ie(o,n,t);let s=[];for(let i of e){let c=r(i),a=o.subarray(0,c);s.push(typeof i=="number"?a:i.decode(a)),o=o.subarray(c)}return s}}}function Zt(t,e){let r=e*t.bytesLen;return{bytesLen:r,encode:n=>{if(n.length!==e)throw new Error(`vecCoder.encode: wrong length=${n.length}. Expected: ${e}`);let o=new Uint8Array(r);for(let s=0,i=0;s<n.length;s++){let c=t.encode(n[s]);o.set(c,i),c.fill(0),i+=c.length}return o},decode:n=>{ie(n,r);let o=[];for(let s=0;s<n.length;s+=t.bytesLen)o.push(t.decode(n.subarray(s,s+t.bytesLen)));return o}}}function Fe(...t){for(let e of t)if(Array.isArray(e))for(let r of e)r.fill(0);else e.fill(0)}function Rs(t){return(1<<t)-1}function Ts(t,e=Ga){if(ie(t),ie(e),e.length>255)throw new Error("context should be less than 255 bytes");return Ss(new Uint8Array([0,e.length]),e,t)}function Fa(t,e=0){if(!t.oid||!Cs(t.oid.subarray(0,10),cu))throw new Error("hash.oid is invalid: expected NIST hash");let r=t.outputLen*8/2;if(e>r)throw new Error("Pre-hash security strength too low: "+r+", required: "+e)}function Ds(t,e,r=Ga){if(ie(e),ie(r),r.length>255)throw new Error("context should be less than 255 bytes");let n=t(e);return Ss(new Uint8Array([1,r.length]),r,t.oid,n)}var Ks,Ga,cu,Ms=pe(()=>{m();Fn();Fn();Ks=Ka;Ga=Uint8Array.of();cu=Uint8Array.from([6,9,96,134,72,1,101,3,4,2])});var Wa,za,Zn,Yn,Za=pe(()=>{m();qa();Is();Ms();Wa=t=>{let{newPoly:e,N:r,Q:n,F:o,ROOT_OF_UNITY:s,brvBits:i,isKyber:c}=t,a=(B,y=n)=>{let L=B%y|0;return(L>=0?L|0:y+L|0)|0},u=(B,y=n)=>{let L=a(B,y)|0;return(L>y>>1?L-y|0:L)|0};function l(){let B=e(r);for(let y=0;y<r;y++){let L=Us(y,i),P=BigInt(s)**BigInt(L)%BigInt(n);B[y]=Number(P)|0}return B}let f=l(),h={add:(B,y)=>a((B|0)+(y|0))|0,sub:(B,y)=>a((B|0)-(y|0))|0,mul:(B,y)=>a((B|0)*(y|0))|0,inv:B=>{throw new Error("not implemented")}},p={N:r,roots:f,invertButterflies:!0,skipStages:c?1:0,brp:!1},x=_s(h,{dit:!1,...p}),w=_s(h,{dit:!0,...p});return{mod:a,smod:u,nttZetas:f,NTT:{encode:B=>x(B),decode:B=>{w(B);for(let y=0;y<B.length;y++)B[y]=a(o*B[y]);return B}},bitsCoder:(B,y)=>{let L=Rs(B),P=B*(r/8);return{bytesLen:P,encode:F=>{let X=new Uint8Array(P);for(let M=0,U=0,Y=0,ee=0;M<F.length;M++)for(U|=(y.encode(F[M])&L)<<Y,Y+=B;Y>=8;Y-=8,U>>=8)X[ee++]=U&Rs(Y);return X},decode:F=>{let X=e(r);for(let M=0,U=0,Y=0,ee=0;M<F.length;M++)for(U|=F[M]<<Y,Y+=8;Y>=B;Y-=B,U>>=B)X[ee++]=y.decode(U&L);return X}}}}},za=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({}),c=0,a=0;return{stats:()=>({calls:c,xofs:a}),get:(u,l)=>(n[o+0]=u,n[o+1]=l,i.destroy(),i=t.create({}).update(n),c++,()=>(a++,i.xofInto(s))),clean:()=>{i.destroy(),Fe(s,n)}}},Zn=za(Pa),Yn=za(be)});var eo={};oo(eo,{PARAMS:()=>Qn,ml_dsa44:()=>du,ml_dsa65:()=>hu,ml_dsa87:()=>pu});function Ya(t){Os(t),t.externalMu!==void 0&&Pt(t.externalMu,"opts.externalMu")}function Xn(t){let e=ve(re);for(let r=0;r<re;){let n=t();if(n.length%3)throw new Error("RejNTTPoly: unaligned block");for(let o=0;r<re&&o<=n.length-3;o+=3){let s=(n[o+0]|n[o+1]<<8|n[o+2]<<16)&8388607;s<Bt&&(e[r++]=s)}}return e}function Vs(t){let{K:e,L:r,GAMMA1:n,GAMMA2:o,TAU:s,ETA:i,OMEGA:c}=t,{CRH_BYTES:a,TR_BYTES:u,C_TILDE_BYTES:l,XOF128:f,XOF256:h,securityLevel:p}=t;if(![2,4].includes(i))throw new Error("Wrong ETA");if(![1<<17,1<<19].includes(n))throw new Error("Wrong GAMMA1");if(![Ns,Ps].includes(o))throw new Error("Wrong GAMMA2");let x=s*i,w=A=>{let S=Yt(A),E=Jn(S,2*o)|0;return S-E===Bt-1?{r1:0,r0:E-1|0}:{r1:Math.floor((S-E)/(2*o))|0,r0:E}},v=A=>w(A).r1,I=A=>w(A).r0,B=(A,S)=>A<=o||A>Bt-o||A===Bt-o&&S===0?0:1,y=(A,S)=>{let E=Math.floor((Bt-1)/(2*o)),{r1:k,r0:O}=w(S);return A===1?O>0?Yt(k+1,E)|0:Yt(k-1,E)|0:k|0},L=A=>{let S=Yt(A),E=Jn(S,2**Xt)|0;return{r1:Math.floor((S-E)/2**Xt)|0,r0:E}},P={bytesLen:c+e,encode:A=>{if(A===!1)throw new Error("hint.encode: hint is false");let S=new Uint8Array(c+e);for(let E=0,k=0;E<e;E++){for(let O=0;O<re;O++)A[E][O]!==0&&(S[k++]=O);S[c+E]=k}return S},decode:A=>{let S=[],E=0;for(let k=0;k<e;k++){let O=ve(re);if(A[c+k]<E||A[c+k]>c)return!1;for(let G=E;G<A[c+k];G++){if(G>E&&A[G]<=A[G-1])return!1;O[A[G]]=1}E=A[c+k],S.push(O)}for(let k=E;k<c;k++)if(A[k]!==0)return!1;return S}},F=Yr(i===2?3:4,A=>i-A,A=>{if(!(-i<=A&&A<=i))throw new Error(`malformed key s1/s3 ${A} outside of ETA range [${-i}, ${i}]`);return A}),X=Yr(13,A=>(1<<Xt-1)-A),M=Yr(10),U=Yr(n===1<<17?18:20,A=>Jn(n-A)),Y=Yr(o===Ns?6:4),ee=Zt(Y,e),$=Zr("publicKey",32,Zt(M,e)),j=Zr("secretKey",32,32,u,Zt(F,r),Zt(F,e),Zt(X,e)),g=Zr("signature",l,Zt(U,r),P),b=i===2?A=>A<15?2-A%5:!1:A=>A<9?4-A:!1;function H(A){let S=ve(re);for(let E=0;E<re;){let k=A();for(let O=0;E<re&&O<k.length;O+=1){let G=b(k[O]&15),Z=b(k[O]>>4&15);G!==!1&&(S[E++]=G),E<re&&Z!==!1&&(S[E++]=Z)}}return S}let C=A=>{let S=ve(re),E=be.create({}).update(A),k=new Uint8Array(be.blockLen);E.xofInto(k);let O=k.slice(0,8);for(let G=re-s,Z=8,J=0,oe=0;G<re;G++){let se=G+1;for(;se>G;)se=k[Z++],!(Z<be.blockLen)&&(E.xofInto(k),Z=0);S[G]=S[se],S[se]=1-((O[J]>>oe++&1)<<1),oe>=8&&(J++,oe=0)}return S},q=A=>{let S=ve(re),E=ve(re);for(let k=0;k<A.length;k++){let{r0:O,r1:G}=L(A[k]);S[k]=O,E[k]=G}return{r0:S,r1:E}},N=(A,S)=>{for(let E=0;E<re;E++)A[E]=y(S[E],A[E]);return A},W=(A,S)=>{let E=ve(re),k=0;for(let O=0;O<re;O++){let G=B(A[O],S[O]);E[O]=G,k+=G}return{v:E,cnt:k}},_=32,z=Zr("seed",32,64,32),V={info:{type:"internal-ml-dsa"},lengths:{secretKey:j.bytesLen,publicKey:$.bytesLen,seed:32,signature:g.bytesLen,signRand:_},keygen:A=>{let S=new Uint8Array(34),E=A===void 0;E&&(A=Ks(32)),ie(A,32,"seed"),S.set(A),E&&Fe(A),S[32]=e,S[33]=r;let[k,O,G]=z.decode(be(S,{dkLen:z.bytesLen})),Z=h(O),J=[];for(let D=0;D<r;D++)J.push(H(Z.get(D&255,D>>8&255)));let oe=[];for(let D=r;D<r+e;D++)oe.push(H(Z.get(D&255,D>>8&255)));let se=J.map(D=>de.encode(D.slice())),ce=[],he=[],We=f(k),ae=ve(re);for(let D=0;D<e;D++){Fe(ae);for(let me=0;me<r;me++){let Te=Xn(We.get(me,D));At(ae,vt(Te,se[me]))}de.decode(ae);let{r0:Be,r1:ge}=q(At(ae,oe[D]));ce.push(Be),he.push(ge)}let Re=$.encode([k,he]),ze=be(Re,{dkLen:u}),Qt=j.encode([k,G,ze,J,oe,ce]);return We.clean(),Z.clean(),Fe(k,O,G,J,oe,se,ae,ce,he,ze,S),{publicKey:Re,secretKey:Qt}},getPublicKey:A=>{let[S,E,k,O,G,Z]=j.decode(A),J=f(S),oe=O.map(he=>de.encode(he.slice())),se=[],ce=ve(re);for(let he=0;he<e;he++){ce.fill(0);for(let ae=0;ae<r;ae++){let Re=Xn(J.get(ae,he));At(ce,vt(Re,oe[ae]))}de.decode(ce),At(ce,G[he]);let{r1:We}=q(ce);se.push(We)}return J.clean(),Fe(ce,oe,Z,O,G),$.encode([S,se])},sign:(A,S,E={})=>{zn(E),Ya(E);let{extraEntropy:k,externalMu:O=!1}=E,[G,Z,J,oe,se,ce]=j.decode(S),he=[],We=f(G);for(let D=0;D<e;D++){let Be=[];for(let ge=0;ge<r;ge++)Be.push(Xn(We.get(ge,D)));he.push(Be)}We.clean();for(let D=0;D<r;D++)de.encode(oe[D]);for(let D=0;D<e;D++)de.encode(se[D]),de.encode(ce[D]);let ae=O?A:be.create({dkLen:a}).update(J).update(A).digest(),Re=k===!1?new Uint8Array(32):k===void 0?Ks(_):k;ie(Re,32,"extraEntropy");let ze=be.create({dkLen:a}).update(Z).update(Re).update(ae).digest();ie(ze,a);let Qt=h(ze,U.bytesLen);e:for(let D=0;;){let Be=[];for(let te=0;te<r;te++,D++)Be.push(U.decode(Qt.get(D&255,D>>8)()));let ge=Be.map(te=>de.encode(te.slice())),me=[];for(let te=0;te<e;te++){let xr=ve(re);for(let it=0;it<r;it++)At(xr,vt(he[te][it],ge[it]));de.decode(xr),me.push(xr)}let Te=me.map(te=>te.map(v)),pr=be.create({dkLen:l}).update(ae).update(ee.encode(Te)).digest(),nn=de.encode(C(pr)),on=oe.map(te=>vt(te,nn));for(let te=0;te<r;te++)if(At(de.decode(on[te]),Be[te]),Xr(on[te],n-x))continue e;let Ws=0,no=[];for(let te=0;te<e;te++){let xr=de.decode(vt(se[te],nn)),it=Ja(me[te],xr).map(I);if(Xr(it,o-x))continue e;let zs=de.decode(vt(ce[te],nn));if(Xr(zs,o))continue e;At(it,zs);let Zs=W(it,Te[te]);no.push(Zs.v),Ws+=Zs.cnt}if(Ws>c)continue;Qt.clean();let Qa=g.encode([pr,on,no]);return Fe(pr,on,no,nn,Te,me,ge,Be,ze,ae,oe,se,ce,...he),Qa}throw new Error("Unreachable code path reached, report this error")},verify:(A,S,E,k={})=>{Ya(k);let{externalMu:O=!1}=k,[G,Z]=$.decode(E),J=be(E,{dkLen:u});if(A.length!==g.bytesLen)return!1;let[oe,se,ce]=g.decode(A);if(ce===!1)return!1;for(let D=0;D<r;D++)if(Xr(se[D],n-x))return!1;let he=O?S:be.create({dkLen:a}).update(J).update(S).digest(),We=de.encode(C(oe)),ae=se.map(D=>D.slice());for(let D=0;D<r;D++)de.encode(ae[D]);let Re=[],ze=f(G);for(let D=0;D<e;D++){let Be=vt(de.encode(lu(Z[D])),We),ge=ve(re);for(let Te=0;Te<r;Te++){let pr=Xn(ze.get(Te,D));At(ge,vt(pr,ae[Te]))}let me=de.decode(Ja(ge,Be));Re.push(N(me,ce[D]))}ze.clean();let Qt=be.create({dkLen:l}).update(he).update(ee.encode(Re)).digest();for(let D of ce)if(!(D.reduce((ge,me)=>ge+me,0)<=c))return!1;for(let D of se)if(Xr(D,n-x))return!1;return Cs(oe,Qt)}};return{info:{type:"ml-dsa"},internal:V,securityLevel:p,keygen:V.keygen,lengths:V.lengths,getPublicKey:V.getPublicKey,sign:(A,S,E={})=>{zn(E);let k=Ts(A,E.context),O=V.sign(k,S,E);return Fe(k),O},verify:(A,S,E,k={})=>(Wn(k),V.verify(A,Ts(S,k.context),E)),prehash:A=>(Fa(A,p),{info:{type:"hashml-dsa"},securityLevel:p,lengths:V.lengths,keygen:V.keygen,getPublicKey:V.getPublicKey,sign:(S,E,k={})=>{zn(k);let O=Ds(A,S,k.context),G=V.sign(O,E,k);return Fe(O),G},verify:(S,E,k,O={})=>(Wn(O),V.verify(S,Ds(A,E,O.context),k))})}}var re,Bt,au,fu,Xt,Ns,Ps,Qn,ve,Yt,Jn,de,uu,Xa,Yr,At,Ja,lu,Xr,vt,du,hu,pu,to=pe(()=>{m();Rr();Is();Za();Ms();re=256,Bt=8380417,au=1753,fu=8347681,Xt=13,Ns=Math.floor((Bt-1)/88)|0,Ps=Math.floor((Bt-1)/32)|0,Qn={2:{K:4,L:4,D:Xt,GAMMA1:2**17,GAMMA2:Ns,TAU:39,ETA:2,OMEGA:80},3:{K:6,L:5,D:Xt,GAMMA1:2**19,GAMMA2:Ps,TAU:49,ETA:4,OMEGA:55},5:{K:8,L:7,D:Xt,GAMMA1:2**19,GAMMA2:Ps,TAU:60,ETA:2,OMEGA:75}},ve=t=>new Int32Array(t),{mod:Yt,smod:Jn,NTT:de,bitsCoder:uu}=Wa({N:re,Q:Bt,F:fu,ROOT_OF_UNITY:au,newPoly:ve,isKyber:!1,brvBits:8}),Xa=t=>t,Yr=(t,e=Xa,r=Xa)=>uu(t,{encode:n=>e(r(n)),decode:n=>r(e(n))}),At=(t,e)=>{for(let r=0;r<t.length;r++)t[r]=Yt(t[r]+e[r]);return t},Ja=(t,e)=>{for(let r=0;r<t.length;r++)t[r]=Yt(t[r]-e[r]);return t},lu=t=>{for(let e=0;e<re;e++)t[e]<<=Xt;return t},Xr=(t,e)=>{for(let r=0;r<re;r++)if(Math.abs(Jn(t[r]))>=e)return!0;return!1},vt=(t,e)=>{let r=ve(re);for(let n=0;n<t.length;n++)r[n]=Yt(t[n]*e[n]);return r};du=Vs({...Qn[2],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:32,XOF128:Zn,XOF256:Yn,securityLevel:128}),hu=Vs({...Qn[3],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:48,XOF128:Zn,XOF256:Yn,securityLevel:192}),pu=Vs({...Qn[5],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:64,XOF128:Zn,XOF256:Yn,securityLevel:256})});var mu={};oo(mu,{InMemoryKeyStorage:()=>St,createKeySDK:()=>Fs,default:()=>gu});m();m();m();m();m();m();m();var i0={p:0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,n:0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,h:1n,a:0n,b:7n,Gx:0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,Gy:0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n},{p:Ht,n:Pe,Gx:c0,Gy:a0,b:ti}=i0,we=32,It=64,ne=(t="")=>{throw new Error(t)},ri=t=>typeof t=="bigint",ni=t=>typeof t=="string",f0=t=>t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array",Ut=(t,e)=>!f0(t)||typeof e=="number"&&e>0&&t.length!==e?ne("Uint8Array expected"):t,Lt=t=>new Uint8Array(t),u0=t=>Uint8Array.from(t),oi=(t,e)=>t.toString(16).padStart(e,"0"),un=t=>Array.from(Ut(t)).map(e=>oi(e,2)).join(""),Ze={_0:48,_9:57,A:65,F:70,a:97,f:102},Ys=t=>{if(t>=Ze._0&&t<=Ze._9)return t-Ze._0;if(t>=Ze.A&&t<=Ze.F)return t-(Ze.A-10);if(t>=Ze.a&&t<=Ze.f)return t-(Ze.a-10)},ao=t=>{let e="hex invalid";if(!ni(t))return ne(e);let r=t.length,n=r/2;if(r%2)return ne(e);let o=Lt(n);for(let s=0,i=0;s<n;s++,i+=2){let c=Ys(t.charCodeAt(i)),a=Ys(t.charCodeAt(i+1));if(c===void 0||a===void 0)return ne(e);o[s]=c*16+a}return o},Me=(t,e)=>Ut(ni(t)?ao(t):u0(Ut(t)),e),si=()=>globalThis?.crypto,l0=()=>si()?.subtle??ne("crypto.subtle must be defined"),_t=(...t)=>{let e=Lt(t.reduce((n,o)=>n+Ut(o).length,0)),r=0;return t.forEach(n=>{e.set(n,r),r+=n.length}),e},fo=(t=we)=>si().getRandomValues(Lt(t)),tr=BigInt,mr=(t,e,r,n="bad number: out of range")=>ri(t)&&e<=t&&t<r?t:ne(n),K=(t,e=Ht)=>{let r=t%e;return r>=0n?r:e+r},Se=t=>K(t,Pe),wr=(t,e)=>{(t===0n||e<=0n)&&ne("no inverse n="+t+" mod="+e);let r=K(t,e),n=e,o=0n,s=1n,i=1n,c=0n;for(;r!==0n;){let a=n/r,u=n%r,l=o-i*a,f=s-c*a;n=r,r=u,o=i,s=c,i=l,c=f}return n===1n?K(o,e):ne("no inverse")},d0=t=>{let e=Ar[t];return typeof e!="function"&&ne("hashes."+t+" not set"),e},Xs=t=>t instanceof Ye?t:ne("Point expected"),ii=t=>K(K(t*t)*t+ti),Js=t=>mr(t,0n,Ht),yr=t=>mr(t,1n,Ht),so=t=>mr(t,1n,Pe),io=t=>(t&1n)===0n,er=t=>Uint8Array.of(t),ci=t=>er(io(t)?2:3),h0=t=>{let e=ii(yr(t)),r=1n;for(let n=e,o=(Ht+1n)/4n;o>0n;o>>=1n)o&1n&&(r=r*n%Ht),n=n*n%Ht;return K(r*r)===e?r:ne("sqrt invalid")},De=class De{constructor(e,r,n){d(this,"px");d(this,"py");d(this,"pz");this.px=Js(e),this.py=yr(r),this.pz=Js(n),Object.freeze(this)}static fromBytes(e){Ut(e);let r,n=e[0],o=e.subarray(1),s=cn(o,0,we),i=e.length;if(i===we+1&&[2,3].includes(n)){let c=h0(s),a=io(c);io(tr(n))!==a&&(c=K(-c)),r=new De(s,c,1n)}return i===It+1&&n===4&&(r=new De(s,cn(o,we,It),1n)),r?r.assertValidity():ne("bad point: not on curve")}equals(e){let{px:r,py:n,pz:o}=this,{px:s,py:i,pz:c}=Xs(e),a=K(r*c),u=K(s*o),l=K(n*c),f=K(i*o);return a===u&&l===f}is0(){return this.equals(kt)}negate(){return new De(this.px,K(-this.py),this.pz)}double(){return this.add(this)}add(e){let{px:r,py:n,pz:o}=this,{px:s,py:i,pz:c}=Xs(e),a=0n,u=ti,l=0n,f=0n,h=0n,p=K(u*3n),x=K(r*s),w=K(n*i),v=K(o*c),I=K(r+n),B=K(s+i);I=K(I*B),B=K(x+w),I=K(I-B),B=K(r+o);let y=K(s+c);return B=K(B*y),y=K(x+v),B=K(B-y),y=K(n+o),l=K(i+c),y=K(y*l),l=K(w+v),y=K(y-l),h=K(a*B),l=K(p*v),h=K(l+h),l=K(w-h),h=K(w+h),f=K(l*h),w=K(x+x),w=K(w+x),v=K(a*v),B=K(p*B),w=K(w+v),v=K(x-v),v=K(a*v),B=K(B+v),x=K(w*B),f=K(f+x),x=K(y*B),l=K(I*l),l=K(l-x),x=K(I*w),h=K(y*h),h=K(h+x),new De(l,f,h)}multiply(e,r=!0){if(!r&&e===0n)return kt;if(so(e),e===1n)return this;if(this.equals(Ne))return v0(e).p;let n=kt,o=Ne;for(let s=this;e>0n;s=s.double(),e>>=1n)e&1n?n=n.add(s):r&&(o=o.add(s));return n}toAffine(){let{px:e,py:r,pz:n}=this;if(this.equals(kt))return{x:0n,y:0n};if(n===1n)return{x:e,y:r};let o=wr(n,Ht);return K(n*o)!==1n&&ne("inverse invalid"),{x:K(e*o),y:K(r*o)}}assertValidity(){let{x:e,y:r}=this.toAffine();return yr(e),yr(r),K(r*r)===ii(e)?this:ne("bad point: not on curve")}toBytes(e=!0){let{x:r,y:n}=this.assertValidity().toAffine(),o=ct(r);return e?_t(ci(n),o):_t(er(4),o,ct(n))}static fromAffine(e){let{x:r,y:n}=e;return r===0n&&n===0n?kt:new De(r,n,1n)}toHex(e){return un(this.toBytes(e))}static fromPrivateKey(e){return Ne.multiply(br(e))}static fromHex(e){return De.fromBytes(Me(e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}toRawBytes(e){return this.toBytes(e)}};d(De,"BASE"),d(De,"ZERO");var Ye=De,Ne=new Ye(c0,a0,1n),kt=new Ye(0n,1n,0n);Ye.BASE=Ne;Ye.ZERO=kt;var ai=(t,e,r)=>Ne.multiply(e,!1).add(t.multiply(r,!1)).assertValidity(),Er=t=>tr("0x"+(un(t)||"0")),cn=(t,e,r)=>Er(t.subarray(e,r)),p0=2n**256n,ct=t=>ao(oi(mr(t,0n,p0),It)),br=t=>{let e=ri(t)?t:Er(Me(t,we));return mr(e,1n,Pe,"private key invalid 3")},an=t=>t>Pe>>1n,fi=(t,e=!0)=>Ne.multiply(br(t)).toBytes(e),gr=class t{constructor(e,r,n){d(this,"r");d(this,"s");d(this,"recovery");this.r=so(e),this.s=so(r),n!=null&&(this.recovery=n),Object.freeze(this)}static fromBytes(e){Ut(e,It);let r=cn(e,0,we),n=cn(e,we,It);return new t(r,n)}toBytes(){let{r:e,s:r}=this;return _t(ct(e),ct(r))}addRecoveryBit(e){return new t(this.r,this.s,e)}hasHighS(){return an(this.s)}toCompactRawBytes(){return this.toBytes()}toCompactHex(){return un(this.toBytes())}recoverPublicKey(e){return g0(this,e)}static fromCompact(e){return t.fromBytes(Me(e,It))}assertValidity(){return this}normalizeS(){let{r:e,s:r,recovery:n}=this;return an(r)?new t(e,Se(-r),n):this}},ui=t=>{let e=t.length*8-256;e>1024&&ne("msg invalid");let r=Er(t);return e>0?r>>tr(e):r},uo=t=>Se(ui(Ut(t))),li={lowS:!0},x0={lowS:!0},y0=(t,e,r=li)=>{["der","recovered","canonical"].some(h=>h in r)&&ne("option not supported");let{lowS:n,extraEntropy:o}=r;n==null&&(n=!0);let s=ct,i=uo(Me(t)),c=s(i),a=br(e),u=[s(a),c];o&&u.push(o===!0?fo(we):Me(o));let l=i,f=h=>{let p=ui(h);if(!(1n<=p&&p<Pe))return;let x=Ne.multiply(p).toAffine(),w=Se(x.x);if(w===0n)return;let v=wr(p,Pe),I=Se(v*Se(l+Se(a*w)));if(I===0n)return;let B=I,y=(x.x===w?0:2)|Number(x.y&1n);return n&&an(I)&&(B=Se(-I),y^=1),new gr(w,B,y)};return{seed:_t(...u),k2sig:f}},b0=t=>{let e=Lt(we),r=Lt(we),n=0,o=Lt(0),s=()=>{e.fill(1),r.fill(0),n=0},i=1e3,c="drbg: tried 1000 values";if(t){let a=(...f)=>Ar.hmacSha256Async(r,e,...f),u=async(f=o)=>{r=await a(er(0),f),e=await a(),f.length!==0&&(r=await a(er(1),f),e=await a())},l=async()=>(n++>=i&&ne(c),e=await a(),e);return async(f,h)=>{s(),await u(f);let p;for(;!(p=h(await l()));)await u();return s(),p}}else{let a=(...f)=>d0("hmacSha256Sync")(r,e,...f),u=(f=o)=>{r=a(er(0),f),e=a(),f.length!==0&&(r=a(er(1),f),e=a())},l=()=>(n++>=i&&ne(c),e=a(),e);return(f,h)=>{s(),u(f);let p;for(;!(p=h(l()));)u();return s(),p}}};var di=(t,e,r=li)=>{let{seed:n,k2sig:o}=y0(t,e,r);return b0(!1)(n,o)},hi=(t,e,r,n=x0)=>{let{lowS:o}=n;o==null&&(o=!0),"strict"in n&&ne("option not supported");let s,i=t&&typeof t=="object"&&"r"in t;!i&&Me(t).length!==It&&ne("signature must be 64 bytes");try{s=i?new gr(t.r,t.s):gr.fromCompact(t);let c=uo(Me(e)),a=Ye.fromBytes(Me(r)),{r:u,s:l}=s;if(o&&an(l))return!1;let f=wr(l,Pe),h=Se(c*f),p=Se(u*f),x=ai(a,h,p).toAffine();return Se(x.x)===u}catch{return!1}},g0=(t,e)=>{let{r,s:n,recovery:o}=t;[0,1,2,3].includes(o)||ne("recovery id invalid");let s=uo(Me(e,we)),i=o===2||o===3?r+Pe:r;yr(i);let c=ci(tr(o)),a=_t(c,ct(i)),u=Ye.fromBytes(a),l=wr(i,Pe),f=Se(-s*l),h=Se(n*l);return ai(u,f,h)};var pi=t=>{t=Me(t),(t.length<we+8||t.length>1024)&&ne("expected 40-1024b");let e=K(Er(t),Pe-1n);return ct(e+1n)},m0=()=>pi(fo(we+16)),w0="SHA-256",Ar={hexToBytes:ao,bytesToHex:un,concatBytes:_t,bytesToNumberBE:Er,numberToBytesBE:ct,mod:K,invert:wr,hmacSha256Async:async(t,...e)=>{let r=l0(),n="HMAC",o=await r.importKey("raw",t,{name:n,hash:{name:w0}},!1,["sign"]);return Lt(await r.sign(n,o,_t(...e)))},hmacSha256Sync:void 0,hashToPrivateKey:pi,randomBytes:fo},xi={normPrivateKeyToScalar:br,isValidPrivateKey:t=>{try{return!!br(t)}catch{return!1}},randomPrivateKey:m0,precompute:(t=8,e=Ne)=>(e.multiply(3n),e)},fn=8,E0=256,yi=Math.ceil(E0/fn)+1,co=2**(fn-1),A0=()=>{let t=[],e=Ne,r=e;for(let n=0;n<yi;n++){r=e,t.push(r);for(let o=1;o<co;o++)r=r.add(e),t.push(r);e=r.double()}return t},Qs,ei=(t,e)=>{let r=e.negate();return t?r:e},v0=t=>{let e=Qs||(Qs=A0()),r=kt,n=Ne,o=2**fn,s=o,i=tr(o-1),c=tr(fn);for(let a=0;a<yi;a++){let u=Number(t&i);t>>=c,u>co&&(u-=s,t+=1n);let l=a*co,f=l,h=l+Math.abs(u)-1,p=a%2!==0,x=u<0;u===0?n=n.add(ei(p,e[f])):r=r.add(ei(x,e[h]))}return{p:r,f:n}};m();Sr();var hn=class extends at{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,bi(e);let n=Kt(r);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?e.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=e.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),ke(s)}update(e){return Je(this),this.iHash.update(e),this}digestInto(e){Je(this),Xe(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),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:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=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()}},ho=(t,e,r)=>new hn(t,e).update(r).digest();ho.create=(t,e)=>new hn(t,e);m();go();var Rt=bn;m();function Ur(t){return Array.from(t).map(e=>e.toString(16).padStart(2,"0")).join("")}function rr(t){if(t.length%2!==0)throw new Error("Hex string must have even length");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"){let r=await Promise.resolve().then(()=>(mn(),gn));return new Uint8Array(r.createHash("sha256").update(t).digest())}else if(e==="sha512"){let r=await Promise.resolve().then(()=>(mn(),gn));return new Uint8Array(r.createHash("sha512").update(t).digest())}else if(e==="sha3-256"){let r=await Promise.resolve().then(()=>(mn(),gn));return new Uint8Array(r.createHash("sha3-256").update(t).digest())}throw new Error(`Unsupported hash algorithm: ${e}`)}m();m();m();m();m();Nt();function Zi(t,e,r){return t&e^~t&r}function Yi(t,e,r){return t&e^t&r^e&r}var Bn=class{constructor(e,r,n,o){d(this,"blockLen");d(this,"outputLen");d(this,"padOffset");d(this,"isLE");d(this,"buffer");d(this,"view");d(this,"finished",!1);d(this,"length",0);d(this,"pos",0);d(this,"destroyed",!1);this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=An(this.buffer)}update(e){nr(this),Q(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=An(e);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(e.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){nr(this),Gi(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Tt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)r[f]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let c=An(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=a/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)c.setUint32(4*f,l[f],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=c,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},tt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);Nt();var W0=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]),dt=new Uint32Array(64),wo=class extends Bn{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[e,r,n,o,s,i,c,a]}set(e,r,n,o,s,i,c,a){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(e,r){for(let f=0;f<16;f++,r+=4)dt[f]=e.getUint32(r,!1);for(let f=16;f<64;f++){let h=dt[f-15],p=dt[f-2],x=Le(h,7)^Le(h,18)^h>>>3,w=Le(p,17)^Le(p,19)^p>>>10;dt[f]=w+dt[f-7]+x+dt[f-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:l}=this;for(let f=0;f<64;f++){let h=Le(c,6)^Le(c,11)^Le(c,25),p=l+h+Zi(c,a,u)+W0[f]+dt[f]|0,w=(Le(n,2)^Le(n,13)^Le(n,22))+Yi(n,o,s)|0;l=u,u=a,a=c,c=i+p|0,i=s,s=o,o=n,n=p+w|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,c,a,u,l)}roundClean(){Tt(dt)}destroy(){this.set(0,0,0,0,0,0,0,0),Tt(this.buffer)}},Eo=class extends wo{constructor(){super(32);d(this,"A",tt[0]|0);d(this,"B",tt[1]|0);d(this,"C",tt[2]|0);d(this,"D",tt[3]|0);d(this,"E",tt[4]|0);d(this,"F",tt[5]|0);d(this,"G",tt[6]|0);d(this,"H",tt[7]|0)}};var Xi=Wi(()=>new Eo,zi(1));m();Rr();m();Rr();var ye=BigInt(0),xe=BigInt(1),Vt=BigInt(2),oc=BigInt(3),sc=BigInt(4),ic=BigInt(5),Y0=BigInt(7),cc=BigInt(8),X0=BigInt(9),ac=BigInt(16);function _e(t,e){let r=t%e;return r>=ye?r:e+r}function Ee(t,e,r){let n=t;for(;e-- >ye;)n*=n,n%=r;return n}function rc(t,e){if(t===ye)throw new Error("invert: expected non-zero number");if(e<=ye)throw new Error("invert: expected positive modulus, got "+e);let r=_e(t,e),n=e,o=ye,s=xe,i=xe,c=ye;for(;r!==ye;){let u=n/r,l=n%r,f=o-i*u,h=s-c*u;n=r,r=l,o=i,s=c,i=f,c=h}if(n!==xe)throw new Error("invert: does not exist");return _e(o,e)}function Lo(t,e,r){if(!t.eql(t.sqr(e),r))throw new Error("Cannot find square root")}function fc(t,e){let r=(t.ORDER+xe)/sc,n=t.pow(e,r);return Lo(t,n,e),n}function J0(t,e){let r=(t.ORDER-ic)/cc,n=t.mul(e,Vt),o=t.pow(n,r),s=t.mul(e,o),i=t.mul(t.mul(s,Vt),o),c=t.mul(s,t.sub(i,t.ONE));return Lo(t,c,e),c}function Q0(t){let e=sr(t),r=uc(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+Y0)/ac;return(c,a)=>{let u=c.pow(a,i),l=c.mul(u,n),f=c.mul(u,o),h=c.mul(u,s),p=c.eql(c.sqr(l),a),x=c.eql(c.sqr(f),a);u=c.cmov(u,l,p),l=c.cmov(h,f,x);let w=c.eql(c.sqr(l),a),v=c.cmov(u,l,w);return Lo(c,v,a),v}}function uc(t){if(t<oc)throw new Error("sqrt is not defined for small field");let e=t-xe,r=0;for(;e%Vt===ye;)e/=Vt,r++;let n=Vt,o=sr(t);for(;nc(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return fc;let s=o.pow(n,e),i=(e+xe)/Vt;return function(a,u){if(a.is0(u))return u;if(nc(a,u)!==1)throw new Error("Cannot find square root");let l=r,f=a.mul(a.ONE,s),h=a.pow(u,e),p=a.pow(u,i);for(;!a.eql(h,a.ONE);){if(a.is0(h))return a.ZERO;let x=1,w=a.sqr(h);for(;!a.eql(w,a.ONE);)if(x++,w=a.sqr(w),x===l)throw new Error("Cannot find square root");let v=xe<<BigInt(l-x-1),I=a.pow(f,v);l=x,f=a.sqr(I),h=a.mul(h,f),p=a.mul(p,I)}return p}}function ef(t){return t%sc===oc?fc:t%cc===ic?J0:t%ac===X0?Q0(t):uc(t)}var tf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Uo(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=tf.reduce((n,o)=>(n[o]="function",n),e);return Or(t,r),t}function rf(t,e,r){if(r<ye)throw new Error("invalid exponent, negatives unsupported");if(r===ye)return t.ONE;if(r===xe)return e;let n=t.ONE,o=e;for(;r>ye;)r&xe&&(n=t.mul(n,o)),o=t.sqr(o),r>>=xe;return n}function Hn(t,e,r=!1){let n=new Array(e.length).fill(r?t.ZERO:void 0),o=e.reduce((i,c,a)=>t.is0(c)?i:(n[a]=i,t.mul(i,c)),t.ONE),s=t.inv(o);return e.reduceRight((i,c,a)=>t.is0(c)?i:(n[a]=t.mul(i,n[a]),t.mul(i,c)),s),n}function nc(t,e){let r=(t.ORDER-xe)/Vt,n=t.pow(e,r),o=t.eql(n,t.ONE),s=t.eql(n,t.ZERO),i=t.eql(n,t.neg(t.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function nf(t,e){e!==void 0&&$e(e);let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var Io=class{constructor(e,r={}){d(this,"ORDER");d(this,"BITS");d(this,"BYTES");d(this,"isLE");d(this,"ZERO",ye);d(this,"ONE",xe);d(this,"_lengths");d(this,"_sqrt");d(this,"_mod");if(e<=ye)throw new Error("invalid field: expected ORDER > 0, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=nf(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return _e(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof e);return ye<=e&&e<this.ORDER}is0(e){return e===ye}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&xe)===xe}neg(e){return _e(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return _e(e*e,this.ORDER)}add(e,r){return _e(e+r,this.ORDER)}sub(e,r){return _e(e-r,this.ORDER)}mul(e,r){return _e(e*r,this.ORDER)}pow(e,r){return rf(this,e,r)}div(e,r){return _e(e*rc(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return rc(e,this.ORDER)}sqrt(e){return this._sqrt||(this._sqrt=ef(this.ORDER)),this._sqrt(this,e)}toBytes(e){return this.isLE?So(e,this.BYTES):kn(e,this.BYTES)}fromBytes(e,r=!1){Q(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:c}=this;if(n){if(!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,s?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let a=s?Bo(e):or(e);if(c&&(a=_e(a,i)),!r&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(e){return Hn(this,e)}cmov(e,r,n){return n?r:e}};function sr(t,e={}){return new Io(t,e)}function lc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function _o(t){let e=lc(t);return e+Math.ceil(e/2)}function Ko(t,e,r=!1){Q(t);let n=t.length,o=lc(e),s=_o(e);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Bo(t):or(t),c=_e(i,e-xe)+xe;return r?So(c,o):kn(c,o)}var ir=BigInt(0),$t=BigInt(1);function Tr(t,e){let r=e.negate();return t?r:e}function To(t,e){let r=Hn(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function xc(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Co(t,e){xc(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,s=Cr(t),i=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function dc(t,e,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(t&o),a=t>>i;c>n&&(c-=s,a+=$t);let u=e*n,l=u+Math.abs(c)-1,f=c===0,h=c<0,p=e%2!==0;return{nextN:a,offset:l,isZero:f,isNeg:h,isNegF:p,offsetF:u}}var Oo=new WeakMap,yc=new WeakMap;function Ro(t){return yc.get(t)||1}function hc(t){if(t!==ir)throw new Error("invalid wNAF")}var In=class{constructor(e,r){d(this,"BASE");d(this,"ZERO");d(this,"Fn");d(this,"bits");this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let o=e;for(;r>ir;)r&$t&&(n=n.add(o)),o=o.double(),r>>=$t;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=Co(r,this.bits),s=[],i=e,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let u=1;u<o;u++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Co(e,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:u,isZero:l,isNeg:f,isNegF:h,offsetF:p}=dc(n,c,i);n=a,l?s=s.add(Tr(h,r[p])):o=o.add(Tr(f,r[u]))}return hc(n),{p:o,f:s}}wNAFUnsafe(e,r,n,o=this.ZERO){let s=Co(e,this.bits);for(let i=0;i<s.windows&&n!==ir;i++){let{nextN:c,offset:a,isZero:u,isNeg:l}=dc(n,i,s);if(n=c,!u){let f=r[a];o=o.add(l?f.negate():f)}}return hc(n),o}getPrecomputes(e,r,n){let o=Oo.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),Oo.set(r,o))),o}cached(e,r,n){let o=Ro(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let s=Ro(e);return s===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,o)}createCache(e,r){xc(r,this.bits),yc.set(e,r),Oo.delete(e)}hasCache(e){return Ro(e)!==1}};function bc(t,e,r,n){let o=e,s=t.ZERO,i=t.ZERO;for(;r>ir||n>ir;)r&$t&&(s=s.add(o)),n&$t&&(i=i.add(o)),o=o.double(),r>>=$t,n>>=$t;return{p1:s,p2:i}}function pc(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Uo(e),e}else return sr(t,{isLE:r})}function gc(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let a of["p","n","h"]){let u=e[a];if(!(typeof u=="bigint"&&u>ir))throw new Error(`CURVE.${a} must be positive bigint`)}let o=pc(e.p,r.Fp,n),s=pc(e.n,r.Fn,n),c=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(e[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function mc(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}m();m();Nt();var Ln=class{constructor(e,r){d(this,"oHash");d(this,"iHash");d(this,"blockLen");d(this,"outputLen");d(this,"finished",!1);d(this,"destroyed",!1);if(En(e),Q(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let 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),Tt(o)}update(e){return nr(this),this.iHash.update(e),this}digestInto(e){nr(this),Q(e,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),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:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=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()}},Do=(t,e,r)=>new Ln(t,e).update(r).digest();Do.create=(t,e)=>new Ln(t,e);Nt();Rr();var wc=(t,e)=>(t+(t>=0?e:-e)/Ec)/e;function of(t,e,r){let[[n,o],[s,i]]=e,c=wc(i*t,r),a=wc(-o*t,r),u=t-c*n-a*s,l=-c*o-a*i,f=u<rt,h=l<rt;f&&(u=-u),h&&(l=-l);let p=Cr(Math.ceil(ko(r)/2))+cr;if(u<rt||u>=p||l<rt||l>=p)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:f,k1:u,k2neg:h,k2:l}}function No(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Mo(t,e){let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Pt(r.lowS,"lowS"),Pt(r.prehash,"prehash"),r.format!==void 0&&No(r.format),r}var Po=class extends Error{constructor(e=""){super(e)}},ht={Err:Po,_tlv:{encode:(t,e)=>{let{Err:r}=ht;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=Kr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Kr(o.length/2|128):"";return Kr(t)+s+o+e},decode(t,e){let{Err:r}=ht,n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=e.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=ht;if(t<rt)throw new e("integer: negative integers are not allowed");let r=Kr(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}=ht;if(t[0]&128)throw new e("invalid signature integer: negative");if(t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return or(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=ht,o=Q(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:c,l:a}=n.decode(2,s),{v:u,l}=n.decode(2,a);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=ht,n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}},rt=BigInt(0),cr=BigInt(1),Ec=BigInt(2),Un=BigInt(3),sf=BigInt(4);function Ac(t,e={}){let r=gc("weierstrass",t,e),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;Or(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:a}=e;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=Bc(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(j,g,b){let{x:H,y:C}=g.toAffine(),q=n.toBytes(H);if(Pt(b,"isCompressed"),b){l();let N=!n.isOdd(C);return Ue(vc(N),q)}else return Ue(Uint8Array.of(4),q,n.toBytes(C))}function h(j){Q(j,void 0,"Point");let{publicKey:g,publicKeyUncompressed:b}=u,H=j.length,C=j[0],q=j.subarray(1);if(H===g&&(C===2||C===3)){let N=n.fromBytes(q);if(!n.isValid(N))throw new Error("bad point: is not on curve, wrong x");let W=w(N),_;try{_=n.sqrt(W)}catch(A){let S=A instanceof Error?": "+A.message:"";throw new Error("bad point: is not on curve, sqrt error"+S)}l();let z=n.isOdd(_);return(C&1)===1!==z&&(_=n.neg(_)),{x:N,y:_}}else if(H===b&&C===4){let N=n.BYTES,W=n.fromBytes(q.subarray(0,N)),_=n.fromBytes(q.subarray(N,N*2));if(!v(W,_))throw new Error("bad point: is not on curve");return{x:W,y:_}}else throw new Error(`bad point: got length ${H}, expected compressed=${g} or uncompressed=${b}`)}let p=e.toBytes||f,x=e.fromBytes||h;function w(j){let g=n.sqr(j),b=n.mul(g,j);return n.add(n.add(b,n.mul(j,s.a)),s.b)}function v(j,g){let b=n.sqr(g),H=w(j);return n.eql(b,H)}if(!v(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let I=n.mul(n.pow(s.a,Un),sf),B=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(I,B)))throw new Error("bad curve params: a or b");function y(j,g,b=!1){if(!n.isValid(g)||b&&n.is0(g))throw new Error(`bad point coordinate ${j}`);return g}function L(j){if(!(j instanceof U))throw new Error("Weierstrass Point expected")}function P(j){if(!a||!a.basises)throw new Error("no endo");return of(j,a.basises,o.ORDER)}let F=Ho((j,g)=>{let{X:b,Y:H,Z:C}=j;if(n.eql(C,n.ONE))return{x:b,y:H};let q=j.is0();g==null&&(g=q?n.ONE:n.inv(C));let N=n.mul(b,g),W=n.mul(H,g),_=n.mul(C,g);if(q)return{x:n.ZERO,y:n.ZERO};if(!n.eql(_,n.ONE))throw new Error("invZ was invalid");return{x:N,y:W}}),X=Ho(j=>{if(j.is0()){if(e.allowInfinityPoint&&!n.is0(j.Y))return;throw new Error("bad point: ZERO")}let{x:g,y:b}=j.toAffine();if(!n.isValid(g)||!n.isValid(b))throw new Error("bad point: x or y not field elements");if(!v(g,b))throw new Error("bad point: equation left != right");if(!j.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function M(j,g,b,H,C){return b=new U(n.mul(b.X,j),b.Y,b.Z),g=Tr(H,g),b=Tr(C,b),g.add(b)}let $=class ${constructor(g,b,H){d(this,"X");d(this,"Y");d(this,"Z");this.X=y("x",g),this.Y=y("y",b,!0),this.Z=y("z",H),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){let{x:b,y:H}=g||{};if(!g||!n.isValid(b)||!n.isValid(H))throw new Error("invalid affine point");if(g instanceof $)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(H)?$.ZERO:new $(b,H,n.ONE)}static fromBytes(g){let b=$.fromAffine(x(Q(g,void 0,"point")));return b.assertValidity(),b}static fromHex(g){return $.fromBytes(Mt(g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,b=!0){return ee.createCache(this,g),b||this.multiply(Un),this}assertValidity(){X(this)}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){L(g);let{X:b,Y:H,Z:C}=this,{X:q,Y:N,Z:W}=g,_=n.eql(n.mul(b,W),n.mul(q,C)),z=n.eql(n.mul(H,W),n.mul(N,C));return _&&z}negate(){return new $(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b}=s,H=n.mul(b,Un),{X:C,Y:q,Z:N}=this,W=n.ZERO,_=n.ZERO,z=n.ZERO,V=n.mul(C,C),A=n.mul(q,q),S=n.mul(N,N),E=n.mul(C,q);return E=n.add(E,E),z=n.mul(C,N),z=n.add(z,z),W=n.mul(g,z),_=n.mul(H,S),_=n.add(W,_),W=n.sub(A,_),_=n.add(A,_),_=n.mul(W,_),W=n.mul(E,W),z=n.mul(H,z),S=n.mul(g,S),E=n.sub(V,S),E=n.mul(g,E),E=n.add(E,z),z=n.add(V,V),V=n.add(z,V),V=n.add(V,S),V=n.mul(V,E),_=n.add(_,V),S=n.mul(q,N),S=n.add(S,S),V=n.mul(S,E),W=n.sub(W,V),z=n.mul(S,A),z=n.add(z,z),z=n.add(z,z),new $(W,_,z)}add(g){L(g);let{X:b,Y:H,Z:C}=this,{X:q,Y:N,Z:W}=g,_=n.ZERO,z=n.ZERO,V=n.ZERO,A=s.a,S=n.mul(s.b,Un),E=n.mul(b,q),k=n.mul(H,N),O=n.mul(C,W),G=n.add(b,H),Z=n.add(q,N);G=n.mul(G,Z),Z=n.add(E,k),G=n.sub(G,Z),Z=n.add(b,C);let J=n.add(q,W);return Z=n.mul(Z,J),J=n.add(E,O),Z=n.sub(Z,J),J=n.add(H,C),_=n.add(N,W),J=n.mul(J,_),_=n.add(k,O),J=n.sub(J,_),V=n.mul(A,Z),_=n.mul(S,O),V=n.add(_,V),_=n.sub(k,V),V=n.add(k,V),z=n.mul(_,V),k=n.add(E,E),k=n.add(k,E),O=n.mul(A,O),Z=n.mul(S,Z),k=n.add(k,O),O=n.sub(E,O),O=n.mul(A,O),Z=n.add(Z,O),E=n.mul(k,Z),z=n.add(z,E),E=n.mul(J,Z),_=n.mul(G,_),_=n.sub(_,E),E=n.mul(G,k),V=n.mul(J,V),V=n.add(V,E),new $(_,z,V)}subtract(g){return this.add(g.negate())}is0(){return this.equals($.ZERO)}multiply(g){let{endo:b}=e;if(!o.isValidNot0(g))throw new Error("invalid scalar: out of range");let H,C,q=N=>ee.cached(this,N,W=>To($,W));if(b){let{k1neg:N,k1:W,k2neg:_,k2:z}=P(g),{p:V,f:A}=q(W),{p:S,f:E}=q(z);C=A.add(E),H=M(b.beta,V,S,N,_)}else{let{p:N,f:W}=q(g);H=N,C=W}return To($,[H,C])[0]}multiplyUnsafe(g){let{endo:b}=e,H=this;if(!o.isValid(g))throw new Error("invalid scalar: out of range");if(g===rt||H.is0())return $.ZERO;if(g===cr)return H;if(ee.hasCache(this))return this.multiply(g);if(b){let{k1neg:C,k1:q,k2neg:N,k2:W}=P(g),{p1:_,p2:z}=bc($,H,q,W);return M(b.beta,_,z,C,N)}else return ee.unsafe(H,g)}toAffine(g){return F(this,g)}isTorsionFree(){let{isTorsionFree:g}=e;return i===cr?!0:g?g($,this):ee.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:g}=e;return i===cr?this:g?g($,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(g=!0){return Pt(g,"isCompressed"),this.assertValidity(),p($,this,g)}toHex(g=!0){return Dt(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}};d($,"BASE",new $(s.Gx,s.Gy,n.ONE)),d($,"ZERO",new $(n.ZERO,n.ONE,n.ZERO)),d($,"Fp",n),d($,"Fn",o);let U=$,Y=o.BITS,ee=new In(U,e.endo?Math.ceil(Y/2):Y);return U.BASE.precompute(8),U}function vc(t){return Uint8Array.of(t?2:3)}function Bc(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function cf(t,e={}){let{Fn:r}=t,n=e.randomBytes||vn,o=Object.assign(Bc(t.Fp,r),{seed:_o(r.ORDER)});function s(p){try{let x=r.fromBytes(p);return r.isValidNot0(x)}catch{return!1}}function i(p,x){let{publicKey:w,publicKeyUncompressed:v}=o;try{let I=p.length;return x===!0&&I!==w||x===!1&&I!==v?!1:!!t.fromBytes(p)}catch{return!1}}function c(p=n(o.seed)){return Ko(Q(p,o.seed,"seed"),r.ORDER)}function a(p,x=!0){return t.BASE.multiply(r.fromBytes(p)).toBytes(x)}function u(p){let{secretKey:x,publicKey:w,publicKeyUncompressed:v}=o;if(!_r(p)||"_lengths"in r&&r._lengths||x===w)return;let I=Q(p,void 0,"key").length;return I===w||I===v}function l(p,x,w=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(x)===!1)throw new Error("second arg must be public key");let v=r.fromBytes(p);return t.fromBytes(x).multiply(v).toBytes(w)}let f={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c},h=mc(c,a);return Object.freeze({getPublicKey:a,getSharedSecret:l,keygen:h,Point:t,utils:f,lengths:o})}function Sc(t,e,r={}){En(e),Or(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||vn,o=r.hmac||((g,b)=>Do(e,g,b)),{Fp:s,Fn:i}=t,{ORDER:c,BITS:a}=i,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:h,lengths:p}=cf(t,r),x={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},w=c*Ec<s.ORDER;function v(g){let b=c>>cr;return g>b}function I(g,b){if(!i.isValidNot0(b))throw new Error(`invalid signature ${g}: out of range 1..Point.Fn.ORDER`);return b}function B(){if(w)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function y(g,b){No(b);let H=p.signature,C=b==="compact"?H:b==="recovered"?H+1:void 0;return Q(g,C)}class L{constructor(b,H,C){d(this,"r");d(this,"s");d(this,"recovery");if(this.r=I("r",b),this.s=I("s",H),C!=null){if(B(),![0,1,2,3].includes(C))throw new Error("invalid recovery id");this.recovery=C}Object.freeze(this)}static fromBytes(b,H=x.format){y(b,H);let C;if(H==="der"){let{r:_,s:z}=ht.toSig(Q(b));return new L(_,z)}H==="recovered"&&(C=b[0],H="compact",b=b.subarray(1));let q=p.signature/2,N=b.subarray(0,q),W=b.subarray(q,q*2);return new L(i.fromBytes(N),i.fromBytes(W),C)}static fromHex(b,H){return this.fromBytes(Mt(b),H)}assertRecovery(){let{recovery:b}=this;if(b==null)throw new Error("invalid recovery id: must be present");return b}addRecoveryBit(b){return new L(this.r,this.s,b)}recoverPublicKey(b){let{r:H,s:C}=this,q=this.assertRecovery(),N=q===2||q===3?H+c:H;if(!s.isValid(N))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let W=s.toBytes(N),_=t.fromBytes(Ue(vc((q&1)===0),W)),z=i.inv(N),V=F(Q(b,void 0,"msgHash")),A=i.create(-V*z),S=i.create(C*z),E=t.BASE.multiplyUnsafe(A).add(_.multiplyUnsafe(S));if(E.is0())throw new Error("invalid recovery: point at infinify");return E.assertValidity(),E}hasHighS(){return v(this.s)}toBytes(b=x.format){if(No(b),b==="der")return Mt(ht.hexFromSig(this));let{r:H,s:C}=this,q=i.toBytes(H),N=i.toBytes(C);return b==="recovered"?(B(),Ue(Uint8Array.of(this.assertRecovery()),q,N)):Ue(q,N)}toHex(b){return Dt(this.toBytes(b))}}let P=r.bits2int||function(b){if(b.length>8192)throw new Error("input is too large");let H=or(b),C=b.length*8-a;return C>0?H>>BigInt(C):H},F=r.bits2int_modN||function(b){return i.create(P(b))},X=Cr(a);function M(g){return ec("num < 2^"+a,g,rt,X),i.toBytes(g)}function U(g,b){return Q(g,void 0,"message"),b?Q(e(g),void 0,"prehashed message"):g}function Y(g,b,H){let{lowS:C,prehash:q,extraEntropy:N}=Mo(H,x);g=U(g,q);let W=F(g),_=i.fromBytes(b);if(!i.isValidNot0(_))throw new Error("invalid private key");let z=[M(_),M(W)];if(N!=null&&N!==!1){let E=N===!0?n(p.secretKey):N;z.push(Q(E,void 0,"extraEntropy"))}let V=Ue(...z),A=W;function S(E){let k=P(E);if(!i.isValidNot0(k))return;let O=i.inv(k),G=t.BASE.multiply(k).toAffine(),Z=i.create(G.x);if(Z===rt)return;let J=i.create(O*i.create(A+Z*_));if(J===rt)return;let oe=(G.x===Z?0:2)|Number(G.y&cr),se=J;return C&&v(J)&&(se=i.neg(J),oe^=1),new L(Z,se,w?void 0:oe)}return{seed:V,k2sig:S}}function ee(g,b,H={}){let{seed:C,k2sig:q}=Y(g,b,H);return tc(e.outputLen,i.BYTES,o)(C,q).toBytes(H.format)}function $(g,b,H,C={}){let{lowS:q,prehash:N,format:W}=Mo(C,x);if(H=Q(H,void 0,"publicKey"),b=U(b,N),!_r(g)){let _=g instanceof L?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+_)}y(g,W);try{let _=L.fromBytes(g,W),z=t.fromBytes(H);if(q&&_.hasHighS())return!1;let{r:V,s:A}=_,S=F(b),E=i.inv(A),k=i.create(S*E),O=i.create(V*E),G=t.BASE.multiplyUnsafe(k).add(z.multiplyUnsafe(O));return G.is0()?!1:i.create(G.x)===V}catch{return!1}}function j(g,b,H={}){let{prehash:C}=Mo(H,x);return b=U(b,C),L.fromBytes(g,"recovered").recoverPublicKey(b).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:h,lengths:p,Point:t,sign:ee,verify:$,recoverPublicKey:j,Signature:L,hash:e})}var $o={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},af={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var kc=BigInt(2);function ff(t){let e=$o.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=t*t*t%e,l=u*u*t%e,f=Ee(l,r,e)*l%e,h=Ee(f,r,e)*l%e,p=Ee(h,kc,e)*u%e,x=Ee(p,o,e)*p%e,w=Ee(x,s,e)*x%e,v=Ee(w,c,e)*w%e,I=Ee(v,a,e)*v%e,B=Ee(I,c,e)*w%e,y=Ee(B,r,e)*l%e,L=Ee(y,i,e)*x%e,P=Ee(L,n,e)*u%e,F=Ee(P,kc,e);if(!Vo.eql(Vo.sqr(F),t))throw new Error("Cannot find square root");return F}var Vo=sr($o.p,{sqrt:ff}),uf=Ac($o,{Fp:Vo,endo:af}),jt=Sc(uf,Xi);m();m();function lf(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Hc(t,e=""){if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new Error(`${r}expected integer >= 0, got ${t}`)}}function Ae(t,e,r=""){let n=lf(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,c=s?` of length ${e}`:"",a=n?`length=${o}`:`type=${typeof t}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return t}function Ic(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Hc(t.outputLen),Hc(t.blockLen)}function ar(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Lc(t,e){Ae(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function He(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function pt(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Ke(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 Nr(t,e={}){let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}var jo=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});var _n=class{constructor(e,r){d(this,"oHash");d(this,"iHash");d(this,"blockLen");d(this,"outputLen");d(this,"finished",!1);d(this,"destroyed",!1);if(Ic(e),Ae(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let 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),He(o)}update(e){return ar(this),this.iHash.update(e),this}digestInto(e){ar(this),Ae(e,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),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:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=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()}},Kn=(t,e,r)=>new _n(t,e).update(r).digest();Kn.create=(t,e)=>new _n(t,e);m();m();function qo(t,e,r){return t&e^~t&r}function Go(t,e,r){return t&e^t&r^e&r}var qt=class{constructor(e,r,n,o){d(this,"blockLen");d(this,"outputLen");d(this,"padOffset");d(this,"isLE");d(this,"buffer");d(this,"view");d(this,"finished",!1);d(this,"length",0);d(this,"pos",0);d(this,"destroyed",!1);this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=pt(this.buffer)}update(e){ar(this),Ae(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=pt(e);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(e.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ar(this),Lc(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,He(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)r[f]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let c=pt(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=a/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)c.setUint32(4*f,l[f],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=c,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},nt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ue=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var df=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),_c=Uint8Array.from(new Array(16).fill(0).map((t,e)=>e)),hf=_c.map(t=>(9*t+5)%16),Kc=(()=>{let r=[[_c],[hf]];for(let n=0;n<4;n++)for(let o of r)o.push(o[n].map(s=>df[s]));return r})(),Cc=Kc[0],Oc=Kc[1],Rc=[[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)),pf=Cc.map((t,e)=>t.map(r=>Rc[e][r])),xf=Oc.map((t,e)=>t.map(r=>Rc[e][r])),yf=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),bf=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Uc(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 Cn=new Uint32Array(16),Fo=class extends qt{constructor(){super(64,20,8,!0);d(this,"h0",1732584193);d(this,"h1",-271733879);d(this,"h2",-1732584194);d(this,"h3",271733878);d(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}process(r,n){for(let x=0;x<16;x++,n+=4)Cn[x]=r.getUint32(n,!0);let o=this.h0|0,s=o,i=this.h1|0,c=i,a=this.h2|0,u=a,l=this.h3|0,f=l,h=this.h4|0,p=h;for(let x=0;x<5;x++){let w=4-x,v=yf[x],I=bf[x],B=Cc[x],y=Oc[x],L=pf[x],P=xf[x];for(let F=0;F<16;F++){let X=Dr(o+Uc(x,i,a,l)+Cn[B[F]]+v,L[F])+h|0;o=h,h=l,l=Dr(a,10)|0,a=i,i=X}for(let F=0;F<16;F++){let X=Dr(s+Uc(w,c,u,f)+Cn[y[F]]+I,P[F])+p|0;s=p,p=f,f=Dr(u,10)|0,u=c,c=X}}this.set(this.h1+a+f|0,this.h2+l+p|0,this.h3+h+s|0,this.h4+o+c|0,this.h0+i+u|0)}roundClean(){He(Cn)}destroy(){this.destroyed=!0,He(this.buffer),this.set(0,0,0,0,0)}},Tc=Nr(()=>new Fo);m();m();var On=BigInt(4294967295),Dc=BigInt(32);function gf(t,e=!1){return e?{h:Number(t&On),l:Number(t>>Dc&On)}:{h:Number(t>>Dc&On)|0,l:Number(t&On)|0}}function Mc(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:c}=gf(t[s],e);[n[s],o[s]]=[i,c]}return[n,o]}var Wo=(t,e,r)=>t>>>r,zo=(t,e,r)=>t<<32-r|e>>>r,Gt=(t,e,r)=>t>>>r|e<<32-r,Ft=(t,e,r)=>t<<32-r|e>>>r,Pr=(t,e,r)=>t<<64-r|e>>>r-32,Vr=(t,e,r)=>t>>>r-32|e<<64-r;function je(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Nc=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Pc=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Vc=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),$c=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,jc=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),qc=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;var wf=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),Zo=class extends qt{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[e,r,n,o,s,i,c,a]}set(e,r,n,o,s,i,c,a){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(e,r){for(let f=0;f<16;f++,r+=4)xt[f]=e.getUint32(r,!1);for(let f=16;f<64;f++){let h=xt[f-15],p=xt[f-2],x=Ke(h,7)^Ke(h,18)^h>>>3,w=Ke(p,17)^Ke(p,19)^p>>>10;xt[f]=w+xt[f-7]+x+xt[f-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:l}=this;for(let f=0;f<64;f++){let h=Ke(c,6)^Ke(c,11)^Ke(c,25),p=l+h+qo(c,a,u)+wf[f]+xt[f]|0,w=(Ke(n,2)^Ke(n,13)^Ke(n,22))+Go(n,o,s)|0;l=u,u=a,a=c,c=i+p|0,i=s,s=o,o=n,n=p+w|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,c,a,u,l)}roundClean(){He(xt)}destroy(){this.set(0,0,0,0,0,0,0,0),He(this.buffer)}},Yo=class extends Zo{constructor(){super(32);d(this,"A",nt[0]|0);d(this,"B",nt[1]|0);d(this,"C",nt[2]|0);d(this,"D",nt[3]|0);d(this,"E",nt[4]|0);d(this,"F",nt[5]|0);d(this,"G",nt[6]|0);d(this,"H",nt[7]|0)}};var Gc=Mc(["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))),Ef=Gc[0],Af=Gc[1],yt=new Uint32Array(80),bt=new Uint32Array(80),Xo=class extends qt{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:l,Fh:f,Fl:h,Gh:p,Gl:x,Hh:w,Hl:v}=this;return[e,r,n,o,s,i,c,a,u,l,f,h,p,x,w,v]}set(e,r,n,o,s,i,c,a,u,l,f,h,p,x,w,v){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=h|0,this.Gh=p|0,this.Gl=x|0,this.Hh=w|0,this.Hl=v|0}process(e,r){for(let y=0;y<16;y++,r+=4)yt[y]=e.getUint32(r),bt[y]=e.getUint32(r+=4);for(let y=16;y<80;y++){let L=yt[y-15]|0,P=bt[y-15]|0,F=Gt(L,P,1)^Gt(L,P,8)^Wo(L,P,7),X=Ft(L,P,1)^Ft(L,P,8)^zo(L,P,7),M=yt[y-2]|0,U=bt[y-2]|0,Y=Gt(M,U,19)^Pr(M,U,61)^Wo(M,U,6),ee=Ft(M,U,19)^Vr(M,U,61)^zo(M,U,6),$=Vc(X,ee,bt[y-7],bt[y-16]),j=$c($,F,Y,yt[y-7],yt[y-16]);yt[y]=j|0,bt[y]=$|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:l,Eh:f,El:h,Fh:p,Fl:x,Gh:w,Gl:v,Hh:I,Hl:B}=this;for(let y=0;y<80;y++){let L=Gt(f,h,14)^Gt(f,h,18)^Pr(f,h,41),P=Ft(f,h,14)^Ft(f,h,18)^Vr(f,h,41),F=f&p^~f&w,X=h&x^~h&v,M=jc(B,P,X,Af[y],bt[y]),U=qc(M,I,L,F,Ef[y],yt[y]),Y=M|0,ee=Gt(n,o,28)^Pr(n,o,34)^Pr(n,o,39),$=Ft(n,o,28)^Vr(n,o,34)^Vr(n,o,39),j=n&s^n&c^s&c,g=o&i^o&a^i&a;I=w|0,B=v|0,w=p|0,v=x|0,p=f|0,x=h|0,{h:f,l:h}=je(u|0,l|0,U|0,Y|0),u=c|0,l=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let b=Nc(Y,$,g);n=Pc(b,U,ee,j),o=b|0}({h:n,l:o}=je(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=je(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=je(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l}=je(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:h}=je(this.Eh|0,this.El|0,f|0,h|0),{h:p,l:x}=je(this.Fh|0,this.Fl|0,p|0,x|0),{h:w,l:v}=je(this.Gh|0,this.Gl|0,w|0,v|0),{h:I,l:B}=je(this.Hh|0,this.Hl|0,I|0,B|0),this.set(n,o,s,i,c,a,u,l,f,h,p,x,w,v,I,B)}roundClean(){He(yt,bt)}destroy(){He(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Jo=class extends Xo{constructor(){super(64);d(this,"Ah",ue[0]|0);d(this,"Al",ue[1]|0);d(this,"Bh",ue[2]|0);d(this,"Bl",ue[3]|0);d(this,"Ch",ue[4]|0);d(this,"Cl",ue[5]|0);d(this,"Dh",ue[6]|0);d(this,"Dl",ue[7]|0);d(this,"Eh",ue[8]|0);d(this,"El",ue[9]|0);d(this,"Fh",ue[10]|0);d(this,"Fl",ue[11]|0);d(this,"Gh",ue[12]|0);d(this,"Gl",ue[13]|0);d(this,"Hh",ue[14]|0);d(this,"Hl",ue[15]|0)}};var Qo=Nr(()=>new Yo,jo(1));var es=Nr(()=>new Jo,jo(3));m();function Rn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Fc(t,e){return Array.isArray(e)?e.length===0?!0:t?e.every(r=>typeof r=="string"):e.every(r=>Number.isSafeInteger(r)):!1}function vf(t){if(typeof t!="function")throw new Error("function expected");return!0}function Tn(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function fr(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function Dn(t){if(!Array.isArray(t))throw new Error("array expected")}function Mn(t,e){if(!Fc(!0,e))throw new Error(`${t}: array of strings expected`)}function Wc(t,e){if(!Fc(!1,e))throw new Error(`${t}: array of numbers expected`)}function os(...t){let e=s=>s,r=(s,i)=>c=>s(i(c)),n=t.map(s=>s.encode).reduceRight(r,e),o=t.map(s=>s.decode).reduce(r,e);return{encode:n,decode:o}}function zc(t){let e=typeof t=="string"?t.split(""):t,r=e.length;Mn("alphabet",e);let n=new Map(e.map((o,s)=>[o,s]));return{encode:o=>(Dn(o),o.map(s=>{if(!Number.isSafeInteger(s)||s<0||s>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${s}". Allowed: ${t}`);return e[s]})),decode:o=>(Dn(o),o.map(s=>{Tn("alphabet.decode",s);let i=n.get(s);if(i===void 0)throw new Error(`Unknown letter: "${s}". Allowed: ${t}`);return i}))}}function Zc(t=""){return Tn("join",t),{encode:e=>(Mn("join.decode",e),e.join(t)),decode:e=>(Tn("join.decode",e),e.split(t))}}function Bf(t,e="="){return fr(t),Tn("padding",e),{encode(r){for(Mn("padding.encode",r);r.length*t%8;)r.push(e);return r},decode(r){Mn("padding.decode",r);let n=r.length;if(n*t%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;n>0&&r[n-1]===e;n--)if((n-1)*t%8===0)throw new Error("padding: invalid, string has too much padding");return r.slice(0,n)}}}function rs(t,e,r){if(e<2)throw new Error(`convertRadix: invalid from=${e}, base cannot be less than 2`);if(r<2)throw new Error(`convertRadix: invalid to=${r}, base cannot be less than 2`);if(Dn(t),!t.length)return[];let n=0,o=[],s=Array.from(t,c=>{if(fr(c),c<0||c>=e)throw new Error(`invalid integer: ${c}`);return c}),i=s.length;for(;;){let c=0,a=!0;for(let u=n;u<i;u++){let l=s[u],f=e*c,h=f+l;if(!Number.isSafeInteger(h)||f/e!==c||h-l!==f)throw new Error("convertRadix: carry overflow");let p=h/r;c=h%r;let x=Math.floor(p);if(s[u]=x,!Number.isSafeInteger(x)||x*r+c!==h)throw new Error("convertRadix: carry overflow");if(a)x?a=!1:n=u;else continue}if(o.push(c),a)break}for(let c=0;c<t.length-1&&t[c]===0;c++)o.push(0);return o.reverse()}var Yc=(t,e)=>e===0?t:Yc(e,t%e),Nn=(t,e)=>t+(e-Yc(t,e)),ts=(()=>{let t=[];for(let e=0;e<40;e++)t.push(2**e);return t})();function ns(t,e,r,n){if(Dn(t),e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(r<=0||r>32)throw new Error(`convertRadix2: wrong to=${r}`);if(Nn(e,r)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${r} carryBits=${Nn(e,r)}`);let o=0,s=0,i=ts[e],c=ts[r]-1,a=[];for(let u of t){if(fr(u),u>=i)throw new Error(`convertRadix2: invalid data word=${u} from=${e}`);if(o=o<<e|u,s+e>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${e}`);for(s+=e;s>=r;s-=r)a.push((o>>s-r&c)>>>0);let l=ts[s];if(l===void 0)throw new Error("invalid carry");o&=l-1}if(o=o<<r-s&c,!n&&s>=e)throw new Error("Excess padding");if(!n&&o>0)throw new Error(`Non-zero padding: ${o}`);return n&&s>0&&a.push(o>>>0),a}function Xc(t){fr(t);let e=2**8;return{encode:r=>{if(!Rn(r))throw new Error("radix.encode input should be Uint8Array");return rs(Array.from(r),e,t)},decode:r=>(Wc("radix.decode",r),Uint8Array.from(rs(r,t,e)))}}function Sf(t,e=!1){if(fr(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(Nn(8,t)>32||Nn(t,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!Rn(r))throw new Error("radix2.encode input should be Uint8Array");return ns(Array.from(r),8,t,!e)},decode:r=>(Wc("radix2.decode",r),Uint8Array.from(ns(r,t,8,e)))}}function Jc(t,e){return fr(t),vf(e),{encode(r){if(!Rn(r))throw new Error("checksum.encode: input should be Uint8Array");let n=e(r).slice(0,t),o=new Uint8Array(r.length+t);return o.set(r),o.set(n,r.length),o},decode(r){if(!Rn(r))throw new Error("checksum.decode: input should be Uint8Array");let n=r.slice(0,-t),o=r.slice(-t),s=e(n).slice(0,t);for(let i=0;i<t;i++)if(s[i]!==o[i])throw new Error("Invalid checksum");return n}}}var $r={alphabet:zc,chain:os,checksum:Jc,convertRadix:rs,convertRadix2:ns,radix:Xc,radix2:Sf,join:Zc,padding:Bf};var kf=t=>os(Xc(58),zc(t),Zc("")),Hf=kf("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var Qc=t=>os(Jc(4,e=>t(t(e))),Hf);var qr=jt.Point,{Fn:jr}=qr,ss=Qc(Qo),If=Uint8Array.from("Bitcoin seed".split(""),t=>t.charCodeAt(0)),is={private:76066276,public:76067358},cs=2147483648,Lf=t=>Tc(Qo(t)),Uf=t=>pt(t).getUint32(0,!1),Pn=t=>{if(!Number.isSafeInteger(t)||t<0||t>2**32-1)throw new Error("invalid number, should be from 0 to 2**32-1, got "+t);let e=new Uint8Array(4);return pt(e).setUint32(0,t,!1),e},Vn=class t{constructor(e){d(this,"versions");d(this,"depth",0);d(this,"index",0);d(this,"chainCode",null);d(this,"parentFingerprint",0);d(this,"_privateKey");d(this,"_publicKey");d(this,"pubHash");if(!e||typeof e!="object")throw new Error("HDKey.constructor must not be called directly");if(this.versions=e.versions||is,this.depth=e.depth||0,this.chainCode=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=e.privateKey,this._publicKey=jt.getPublicKey(e.privateKey,!0)}else if(e.publicKey)this._publicKey=qr.fromBytes(e.publicKey).toBytes(!0);else throw new Error("HDKey: no public or private key provided");this.pubHash=Lf(this._publicKey)}get fingerprint(){if(!this.pubHash)throw new Error("No publicKey set!");return Uf(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 ss.encode(this.serialize(this.versions.private,Mr(Uint8Array.of(0),e)))}get publicExtendedKey(){if(!this._publicKey)throw new Error("No public key");return ss.encode(this.serialize(this.versions.public,this._publicKey))}static fromMasterSeed(e,r=is){if(Ae(e),8*e.length<128||8*e.length>512)throw new Error("HDKey: seed length must be between 128 and 512 bits; 256 bits is advised, got "+e.length);let n=Kn(es,If,e),o=n.slice(0,32),s=n.slice(32);return new t({versions:r,chainCode:s,privateKey:o})}static fromExtendedKey(e,r=is){let n=ss.decode(e),o=pt(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)},c=n.slice(45),a=c[0]===0;if(s!==r[a?"private":"public"])throw new Error("Version mismatch");return a?new t({...i,privateKey:c.slice(1)}):new t({...i,publicKey:c})}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 c=+i;if(!Number.isSafeInteger(c)||c>=cs)throw new Error("Invalid index");s[2]==="'"&&(c+=cs),n=n.deriveChild(c)}return n}deriveChild(e){if(!this._publicKey||!this.chainCode)throw new Error("No publicKey or chainCode set");let r=Pn(e);if(e>=cs){let a=this._privateKey;if(!a)throw new Error("Could not derive hardened child key");r=Mr(Uint8Array.of(0),a,r)}else r=Mr(this._publicKey,r);let n=Kn(es,this.chainCode,r),o=n.slice(0,32),s=n.slice(32);if(!jt.utils.isValidSecretKey(o))throw new Error("Tweak bigger than curve order");let i={versions:this.versions,chainCode:s,depth:this.depth+1,parentFingerprint:this.fingerprint,index:e},c=jr.fromBytes(o);try{if(this._privateKey){let a=jr.create(jr.fromBytes(this._privateKey)+c);if(!jr.isValidNot0(a))throw new Error("The tweak was out of range or the resulted private key is invalid");i.privateKey=jr.toBytes(a)}else{let a=qr.fromBytes(this._publicKey).add(qr.BASE.multiply(c));if(a.equals(qr.ZERO))throw new Error("The tweak was equal to negative P, which made the result key invalid");i.publicKey=a.toBytes(!0)}return new t(i)}catch{return this.deriveChild(e+1)}}sign(e){if(!this._privateKey)throw new Error("No privateKey set!");return Ae(e,32),jt.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 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 Ae(r,33),Mr(Pn(e),new Uint8Array([this.depth]),Pn(this.parentFingerprint),Pn(this.index),this.chainCode,r)}};m();m();m();m();function _f(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function gt(t,e=""){if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new Error(`${r}expected integer >= 0, got ${t}`)}}function ot(t,e,r=""){let n=_f(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,c=s?` of length ${e}`:"",a=n?`length=${o}`:`type=${typeof t}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return t}function $n(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash must wrapped by utils.createHasher");gt(t.outputLen),gt(t.blockLen)}function ur(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function ea(t,e){ot(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function Ce(...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 Oe(t,e){return t<<32-e|t>>>e}function Kf(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function as(t,e=""){return typeof t=="string"?Kf(t):ot(t,void 0,e)}function ta(t,e){if(e!==void 0&&{}.toString.call(e)!=="[object Object]")throw new Error("options must be object or undefined");return Object.assign(t,e)}function fs(t,e={}){let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function ra(t=32){let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(t))}var us=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});var jn=class{constructor(e,r){d(this,"oHash");d(this,"iHash");d(this,"blockLen");d(this,"outputLen");d(this,"finished",!1);d(this,"destroyed",!1);if($n(e),ot(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let 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),Ce(o)}update(e){return ur(this),this.iHash.update(e),this}digestInto(e){ur(this),ot(e,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),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:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=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()}},ls=(t,e,r)=>new jn(t,e).update(r).digest();ls.create=(t,e)=>new jn(t,e);function Cf(t,e,r,n){$n(t);let o=ta({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:c}=o;if(gt(s,"c"),gt(i,"dkLen"),gt(c,"asyncTick"),s<1)throw new Error("iterations (c) must be >= 1");let a=as(e,"password"),u=as(r,"salt"),l=new Uint8Array(i),f=ls.create(t,a),h=f._cloneInto().update(u);return{c:s,dkLen:i,asyncTick:c,DK:l,PRF:f,PRFSalt:h}}function Of(t,e,r,n,o){return t.destroy(),e.destroy(),n&&n.destroy(),Ce(o),r}function na(t,e,r,n){let{c:o,dkLen:s,DK:i,PRF:c,PRFSalt:a}=Cf(t,e,r,n),u,l=new Uint8Array(4),f=lr(l),h=new Uint8Array(c.outputLen);for(let p=1,x=0;x<s;p++,x+=c.outputLen){let w=i.subarray(x,x+c.outputLen);f.setInt32(0,p,!1),(u=a._cloneInto(u)).update(l).digestInto(h),w.set(h.subarray(0,w.length));for(let v=1;v<o;v++){c._cloneInto(u).update(h).digestInto(h);for(let I=0;I<w.length;I++)w[I]^=h[I]}}return Of(c,a,i,u,h)}m();m();function oa(t,e,r){return t&e^~t&r}function sa(t,e,r){return t&e^t&r^e&r}var Gr=class{constructor(e,r,n,o){d(this,"blockLen");d(this,"outputLen");d(this,"padOffset");d(this,"isLE");d(this,"buffer");d(this,"view");d(this,"finished",!1);d(this,"length",0);d(this,"pos",0);d(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),ot(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=lr(e);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(e.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ur(this),ea(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Ce(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)r[f]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let c=lr(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=a/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)c.setUint32(4*f,l[f],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=c,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},st=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var le=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);m();var qn=BigInt(4294967295),ia=BigInt(32);function Rf(t,e=!1){return e?{h:Number(t&qn),l:Number(t>>ia&qn)}:{h:Number(t>>ia&qn)|0,l:Number(t&qn)|0}}function ca(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:c}=Rf(t[s],e);[n[s],o[s]]=[i,c]}return[n,o]}var ds=(t,e,r)=>t>>>r,hs=(t,e,r)=>t<<32-r|e>>>r,Wt=(t,e,r)=>t>>>r|e<<32-r,zt=(t,e,r)=>t<<32-r|e>>>r,Fr=(t,e,r)=>t<<64-r|e>>>r-32,Wr=(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 aa=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),fa=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,ua=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),la=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,da=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ha=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;var Df=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]),mt=new Uint32Array(64),ps=class extends Gr{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[e,r,n,o,s,i,c,a]}set(e,r,n,o,s,i,c,a){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(e,r){for(let f=0;f<16;f++,r+=4)mt[f]=e.getUint32(r,!1);for(let f=16;f<64;f++){let h=mt[f-15],p=mt[f-2],x=Oe(h,7)^Oe(h,18)^h>>>3,w=Oe(p,17)^Oe(p,19)^p>>>10;mt[f]=w+mt[f-7]+x+mt[f-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:l}=this;for(let f=0;f<64;f++){let h=Oe(c,6)^Oe(c,11)^Oe(c,25),p=l+h+oa(c,a,u)+Df[f]+mt[f]|0,w=(Oe(n,2)^Oe(n,13)^Oe(n,22))+sa(n,o,s)|0;l=u,u=a,a=c,c=i+p|0,i=s,s=o,o=n,n=p+w|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,c,a,u,l)}roundClean(){Ce(mt)}destroy(){this.set(0,0,0,0,0,0,0,0),Ce(this.buffer)}},xs=class extends ps{constructor(){super(32);d(this,"A",st[0]|0);d(this,"B",st[1]|0);d(this,"C",st[2]|0);d(this,"D",st[3]|0);d(this,"E",st[4]|0);d(this,"F",st[5]|0);d(this,"G",st[6]|0);d(this,"H",st[7]|0)}};var pa=ca(["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))),Mf=pa[0],Nf=pa[1],wt=new Uint32Array(80),Et=new Uint32Array(80),ys=class extends Gr{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:l,Fh:f,Fl:h,Gh:p,Gl:x,Hh:w,Hl:v}=this;return[e,r,n,o,s,i,c,a,u,l,f,h,p,x,w,v]}set(e,r,n,o,s,i,c,a,u,l,f,h,p,x,w,v){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=h|0,this.Gh=p|0,this.Gl=x|0,this.Hh=w|0,this.Hl=v|0}process(e,r){for(let y=0;y<16;y++,r+=4)wt[y]=e.getUint32(r),Et[y]=e.getUint32(r+=4);for(let y=16;y<80;y++){let L=wt[y-15]|0,P=Et[y-15]|0,F=Wt(L,P,1)^Wt(L,P,8)^ds(L,P,7),X=zt(L,P,1)^zt(L,P,8)^hs(L,P,7),M=wt[y-2]|0,U=Et[y-2]|0,Y=Wt(M,U,19)^Fr(M,U,61)^ds(M,U,6),ee=zt(M,U,19)^Wr(M,U,61)^hs(M,U,6),$=ua(X,ee,Et[y-7],Et[y-16]),j=la($,F,Y,wt[y-7],wt[y-16]);wt[y]=j|0,Et[y]=$|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:l,Eh:f,El:h,Fh:p,Fl:x,Gh:w,Gl:v,Hh:I,Hl:B}=this;for(let y=0;y<80;y++){let L=Wt(f,h,14)^Wt(f,h,18)^Fr(f,h,41),P=zt(f,h,14)^zt(f,h,18)^Wr(f,h,41),F=f&p^~f&w,X=h&x^~h&v,M=da(B,P,X,Nf[y],Et[y]),U=ha(M,I,L,F,Mf[y],wt[y]),Y=M|0,ee=Wt(n,o,28)^Fr(n,o,34)^Fr(n,o,39),$=zt(n,o,28)^Wr(n,o,34)^Wr(n,o,39),j=n&s^n&c^s&c,g=o&i^o&a^i&a;I=w|0,B=v|0,w=p|0,v=x|0,p=f|0,x=h|0,{h:f,l:h}=qe(u|0,l|0,U|0,Y|0),u=c|0,l=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let b=aa(Y,$,g);n=fa(b,U,ee,j),o=b|0}({h:n,l:o}=qe(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=qe(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=qe(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l}=qe(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:h}=qe(this.Eh|0,this.El|0,f|0,h|0),{h:p,l:x}=qe(this.Fh|0,this.Fl|0,p|0,x|0),{h:w,l:v}=qe(this.Gh|0,this.Gl|0,w|0,v|0),{h:I,l:B}=qe(this.Hh|0,this.Hl|0,I|0,B|0),this.set(n,o,s,i,c,a,u,l,f,h,p,x,w,v,I,B)}roundClean(){Ce(wt,Et)}destroy(){Ce(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},bs=class extends ys{constructor(){super(64);d(this,"Ah",le[0]|0);d(this,"Al",le[1]|0);d(this,"Bh",le[2]|0);d(this,"Bl",le[3]|0);d(this,"Ch",le[4]|0);d(this,"Cl",le[5]|0);d(this,"Dh",le[6]|0);d(this,"Dl",le[7]|0);d(this,"Eh",le[8]|0);d(this,"El",le[9]|0);d(this,"Fh",le[10]|0);d(this,"Fl",le[11]|0);d(this,"Gh",le[12]|0);d(this,"Gl",le[13]|0);d(this,"Hh",le[14]|0);d(this,"Hl",le[15]|0)}};var xa=fs(()=>new xs,us(1));var ya=fs(()=>new bs,us(3));var Pf=t=>t[0]==="\u3042\u3044\u3053\u304F\u3057\u3093";function ba(t){if(typeof t!="string")throw new TypeError("invalid mnemonic type: "+typeof t);return t.normalize("NFKD")}function Vf(t){let e=ba(t),r=e.split(" ");if(![12,15,18,21,24].includes(r.length))throw new Error("Invalid mnemonic");return{nfkd:e,words:r}}function $f(t){if(ot(t),![16,20,24,28,32].includes(t.length))throw new Error("invalid entropy length")}function ga(t,e=128){if(gt(e),e%32!==0||e>256)throw new TypeError("Invalid entropy");return Gf(ra(e/8),t)}var jf=t=>{let e=8-t.length/4;return new Uint8Array([xa(t)[0]>>e<<e])};function qf(t){if(!Array.isArray(t)||t.length!==2048||typeof t[0]!="string")throw new Error("Wordlist: expected array of 2048 strings");return t.forEach(e=>{if(typeof e!="string")throw new Error("wordlist: non-string element: "+e)}),$r.chain($r.checksum(1,jf),$r.radix2(11,!0),$r.alphabet(t))}function Gf(t,e){return $f(t),qf(e).encode(t).join(Pf(e)?"\u3000":" ")}var Ff=t=>ba("mnemonic"+t);function ma(t,e=""){return na(ya,Vf(t).nfkd,Ff(e),{c:2048,dkLen:64})}m();var wa=`abandon
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
2
2
  ability
3
3
  able
4
4
  about
@@ -2046,59 +2046,33 @@ zebra
2046
2046
  zero
2047
2047
  zone
2048
2048
  zoo`.split(`
2049
- `);var Ge=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=Vn.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){return ma(e,r)}generateMnemonic(e=256){return ga(wa,e)}static bitcoinPath(e=0,r=0,n=0){return`m/44'/0'/${e}'/${r}/${n}`}static bitcoinSegWitPath(e=0,r=0,n=0){return`m/84'/0'/${e}'/${r}/${n}`}};m();var Ea="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";function Wf(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=Ea[n]+r,e=e/58n}for(let n of t){if(n!==0)break;r="1"+r}return r}function zf(t){let e=0n;for(let n of t){let o=Ea.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 gs(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=Rt(o),c=Rt(s).slice(0,4),a=new Uint8Array(o.length+4);return a.set(o),a.set(c,o.length),Wf(a)}function ms(t){let e=zf(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=Rt(r),i=Rt(o).slice(0,4);if(!n.every((f,h)=>f===i[h]))throw new Error("Invalid WIF checksum");let c=r[0],a=c===128?"mainnet":c===239?"testnet":null;if(!a)throw new Error(`Invalid WIF version byte: 0x${c.toString(16)}`);let u=r.length===34&&r[33]===1;return{privateKey:r.slice(1,33),compressed:u,network:a}}Ar.hmacSha256Sync=(t,...e)=>ho(Rt,t,Ar.concatBytes(...e));var dr=class{constructor(){d(this,"suiteId","bsv-ecdsa-secp256k1");d(this,"version","1.0.0");d(this,"capabilities",{derivation:new Ge})}async generateKeypair(){let e=xi.randomPrivateKey(),r=fi(e,!0);return{privateKey:e,publicKey:r}}async sign(e,r){try{return(await di(r,e)).toCompactRawBytes()}catch(n){throw new Error(`BsvEcdsaSuite signing failed: ${n instanceof Error?n.message:String(n)}`)}}async verify(e,r,n){try{return hi(n,r,e)}catch{return!1}}exportPublicKey(e){return Ur(e)}importPublicKey(e){return rr(e)}exportPrivateKey(e){return gs(e,!0,"mainnet")}importPrivateKey(e){if(e.length===64){let r=rr(e);if(r.length!==32)throw new Error("Private key must be 32 bytes");return r}else try{let{privateKey:r}=ms(e);return r}catch(r){throw new Error(`Invalid private key format: ${r instanceof Error?r.message:String(r)}`)}}};m();var $s=null,js=null,qs=null;async function xu(){return $s||($s=(await Promise.resolve().then(()=>(to(),eo))).ml_dsa44),$s}async function yu(){return js||(js=(await Promise.resolve().then(()=>(to(),eo))).ml_dsa65),js}async function bu(){return qs||(qs=(await Promise.resolve().then(()=>(to(),eo))).ml_dsa87),qs}var Gs={"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(){d(this,"version","2.0.0");d(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{return(await this.getLib()).verify(n,r,e)}catch{return!1}}exportPublicKey(e){return Ur(e)}importPublicKey(e){let r=rr(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 Ur(e)}importPrivateKey(e){let r=rr(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}},Qr=class extends Jr{constructor(){super(...arguments);d(this,"suiteId","ml-dsa-44")}get sizes(){return Gs["ml-dsa-44"]}async getLib(){return xu()}},en=class extends Jr{constructor(){super(...arguments);d(this,"suiteId","ml-dsa-65")}get sizes(){return Gs["ml-dsa-65"]}async getLib(){return yu()}},hr=class extends Jr{constructor(){super(...arguments);d(this,"suiteId","ml-dsa-87")}get sizes(){return Gs["ml-dsa-87"]}async getLib(){return bu()}};var tn=class{constructor(){d(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()}},Jt=new tn;Jt.register(new dr);Jt.register(new Qr);Jt.register(new en);Jt.register(new hr);m();m();var St=class{constructor(){d(this,"keys",new Map)}async store(e,r,n){this.keys.set(e,{keypair:r,meta:n})}async load(e){return this.keys.get(e)||null}async list(e){let r=Array.from(this.keys.values()).map(n=>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){this.keys.delete(e)}async updateMeta(e,r){let n=this.keys.get(e);if(!n)throw new Error(`Key not found: ${e}`);this.keys.set(e,{keypair:n.keypair,meta:{...n.meta,...r}})}clear(){this.keys.clear()}},rn=class{constructor(e=new St){d(this,"storage");this.storage=e}async registerKey(e,r,n,o={}){let s={keyId:e,suiteId:n,createdAt:new Date().toISOString(),expiresAt:o.expiresAt,usage:o.usage||["signing"],cryptoProfileVersion:o.cryptoProfileVersion||"1.0.0",status:o.status||"active"};return await this.storage.store(e,r,s),s}async getKey(e){return await this.storage.load(e)}async getPublicKey(e){let r=await this.storage.load(e);return r?{publicKey:r.keypair.publicKey,meta: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=>!(o.status&&o.status!=="active"||o.expiresAt&&new Date(o.expiresAt)<n))}async rotateKey(e,r,n){let o=await this.storage.load(e);if(!o)throw new Error(`Cannot rotate: key not found: ${e}`);return await this.storage.updateMeta(e,{status:"rotated"}),await this.registerKey(r,n,o.meta.suiteId,{usage:o.meta.usage,cryptoProfileVersion:o.meta.cryptoProfileVersion,expiresAt:o.meta.expiresAt,status:"active"}),await this.storage.updateMeta(r,{rotatedFrom:e}),(await this.storage.load(r)).meta}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.expiresAt&&new Date(o.expiresAt)<r&&o.status==="active"&&(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}};m();m();var ro=class{constructor(e){this.keyCounter=new Map;this.counterInitialized=new Set;this.counterInitPromises=new Map;this.keyRegistry=e.keyRegistry,this.suiteRegistry=e.suiteRegistry}async createKey(e,r,n={}){let o=this.suiteRegistry.getSuite(r.primarySignatureSuite),s;if(n.derivationContext){if(!o.capabilities?.derivation){let l=this.getSuitesWithCapability("derivation");throw new Error(`Suite '${o.suiteId}' does not support key derivation.
2050
- `+(l.length>0?`Suites with derivation capability: ${l.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.getNextCounter(e),c=r.primarySignatureSuite.split("-")[0],a=`${e}:pk-${c}-${i}`;return{meta:await this.keyRegistry.registerKey(a,s,r.primarySignatureSuite,{expiresAt:n.expiresAt,usage:n.usage||["signing"],cryptoProfileVersion:n.cryptoProfileVersion||"1.0.0"}),publicKey:s.publicKey}}async getKey(e){let r=await this.keyRegistry.getPublicKey(e);return r?{meta:r.meta,publicKey: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!=="active")throw new Error(`Key is not active: ${e} (status: ${n.meta.status})`);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){let o=await this.keyRegistry.getPublicKey(e);if(!o)return!1;let s=this.suiteRegistry.getSuite(o.meta.suiteId),i=this.getHashAlgorithm(o.meta.suiteId),c=await wn(r,i);try{return await s.verify(o.publicKey,c,n)}catch{return!1}}async listKeysForAgent(e,r=!0){let o=(r?await this.keyRegistry.listActiveKeys():await this.keyRegistry.listKeys()).filter(i=>i.keyId.startsWith(`${e}:`)),s=[];for(let i of o){let c=await this.keyRegistry.getPublicKey(i.keyId);c&&s.push({meta:c.meta,publicKey:c.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){let r=await this.listKeysForAgent(e,!0),n=[];for(let o of r){let i=await this.suiteRegistry.getSuite(o.meta.suiteId).generateKeypair(),c=await this.getNextCounter(e),a=o.meta.suiteId.split("-")[0],u=`${e}:pk-${a}-${c}`,l=await this.keyRegistry.rotateKey(o.meta.keyId,u,i);n.push({meta:l,publicKey:i.publicKey})}return n}async getOrCreateKey(e,r,n={}){let s=(await this.listKeysForAgent(e,!0)).find(i=>i.meta.suiteId===r.primarySignatureSuite);return s||await this.createKey(e,r,n)}async createDualSignatureKeys(e,r,n={}){if(!r.secondarySignatureSuite)throw new Error("secondarySignatureSuite is required to create dual signature keys");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");let o=await this.getOrCreateKey(e,{primarySignatureSuite:r.primarySignatureSuite},n),s=await this.getOrCreateKey(e,{primarySignatureSuite:r.secondarySignatureSuite},n);return{primaryKey:o,secondaryKey:s}}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=n?.length?n:Array.from(new Set(o.map(c=>c.meta.suiteId))),i=[];for(let c of s){let a=o.find(l=>l.meta.suiteId===c);if(!a)throw new Error(`No active key for suite '${c}' and agent '${e}'`);let u=await this.signWithKey(a.meta.keyId,r);i.push({suiteId:c,keyId:a.meta.keyId,signature:u})}return{signatures:i}}async verifyWithSuites(e,r,n){let o=[];for(let s of n)try{let i=await this.verifySignature(s.keyId,r,s.signature);o.push({suiteId:s.suiteId,keyId:s.keyId,valid:i})}catch(i){o.push({suiteId:s.suiteId,keyId:s.keyId,valid:!1,error:i.message})}return{results:o,allValid:o.every(s=>s.valid)}}generateMnemonic(e=256){return new Ge().generateMnemonic(e)}async createKeyFromMnemonic(e,r,n,o=Ge.bitcoinPath(0,0,0),s,i={}){let a=new Ge().mnemonicToSeed(n,s);return await this.createKey(e,r,{...i,derivationContext:{seed:a,path:o}})}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 createBitcoinWalletKey(e,r,n=0,o=0,s=!1,i={}){let c=Ge.bitcoinPath(n,s?1:0,o);return this.createKeyFromMnemonic(e,{primarySignatureSuite:"bsv-ecdsa-secp256k1"},r,c,void 0,i)}getHashAlgorithm(e){return e.startsWith("ml-dsa")?"sha3-256":"sha256"}async getNextCounter(e){if(!this.counterInitialized.has(e)){if(!this.counterInitPromises.has(e)){let s=(async()=>{let c=(await this.keyRegistry.listKeys()).reduce((a,u)=>{if(!u.keyId.startsWith(`${e}:pk-`))return a;let l=u.keyId.match(/:pk-[^-]+-(\d+)$/);if(!l)return a;let f=parseInt(l[1],10);return Number.isFinite(f)?Math.max(a,f):a},0);this.keyCounter.set(e,c),this.counterInitialized.add(e),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}};m();async function Fs(){let t=new St,e=new rn(t);return new ro({keyRegistry:e,suiteRegistry:Jt})}var gu={createKeySDK:Fs};typeof window<"u"&&(window.LumenKeys={createKeySDK:Fs});return s0(mu);})();
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.
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);})();
2052
2052
  /*! Bundled license information:
2053
2053
 
2054
- @noble/hashes/esm/utils.js:
2055
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2056
-
2057
- @noble/hashes/utils.js:
2058
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2059
-
2060
2054
  @noble/curves/utils.js:
2055
+ @noble/curves/abstract/modular.js:
2056
+ @noble/curves/abstract/curve.js:
2057
+ @noble/curves/abstract/der.js:
2058
+ @noble/curves/abstract/weierstrass.js:
2059
+ @noble/curves/secp256k1.js:
2061
2060
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2062
2061
 
2063
- @noble/hashes/utils.js:
2064
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2065
-
2066
2062
  @noble/post-quantum/utils.js:
2067
- (*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) *)
2068
-
2069
2063
  @noble/post-quantum/_crystals.js:
2070
- (*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) *)
2071
-
2072
2064
  @noble/post-quantum/ml-dsa.js:
2073
2065
  (*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) *)
2074
2066
 
2075
2067
  @noble/secp256k1/index.js:
2076
2068
  (*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) *)
2077
2069
 
2078
- @noble/curves/abstract/modular.js:
2079
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2080
-
2081
- @noble/curves/abstract/curve.js:
2082
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2083
-
2084
- @noble/curves/abstract/weierstrass.js:
2085
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2086
-
2087
- @noble/curves/secp256k1.js:
2088
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2089
-
2090
- @noble/hashes/utils.js:
2091
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2092
-
2093
2070
  @scure/base/index.js:
2094
2071
  (*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2095
2072
 
2096
2073
  @scure/bip32/index.js:
2097
2074
  (*! scure-bip32 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
2098
2075
 
2099
- @noble/hashes/utils.js:
2100
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2101
-
2102
2076
  @scure/bip39/index.js:
2103
2077
  (*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
2104
2078
  */