@smartledger/keys 3.0.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +168 -515
- package/dist/cjs/browser.d.ts +16 -6
- package/dist/cjs/browser.d.ts.map +1 -1
- package/dist/cjs/browser.js +15 -10
- package/dist/cjs/browser.js.map +1 -1
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +19 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/sdk.d.ts +83 -9
- package/dist/cjs/sdk.d.ts.map +1 -1
- package/dist/cjs/sdk.js +322 -87
- package/dist/cjs/sdk.js.map +1 -1
- package/dist/cjs/types.d.ts +78 -3
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/browser.d.ts +16 -6
- package/dist/esm/browser.d.ts.map +1 -1
- package/dist/esm/browser.js +14 -10
- package/dist/esm/browser.js.map +1 -1
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/sdk.d.ts +83 -9
- package/dist/esm/sdk.d.ts.map +1 -1
- package/dist/esm/sdk.js +322 -87
- package/dist/esm/sdk.js.map +1 -1
- package/dist/esm/types.d.ts +78 -3
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/lumen-keys.js +2010 -4326
- package/dist/lumen-keys.min.js +4 -7
- package/dist/lumen-keys.min.js.map +4 -4
- package/package.json +11 -12
- package/dist/lumen-keys.js.map +0 -7
- package/dist/tsconfig.esm.tsbuildinfo +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/lumen-keys.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var LumenKeys=(()=>{var sn=Object.defineProperty;var Y0=Object.getOwnPropertyDescriptor;var X0=Object.getOwnPropertyNames;var Z0=Object.prototype.hasOwnProperty;var J0=(t,e,r)=>e in t?sn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var ye=(t,e)=>()=>(t&&(e=t(t=0)),e);var yo=(t,e)=>{for(var r in e)sn(t,r,{get:e[r],enumerable:!0})},Q0=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of X0(e))!Z0.call(t,o)&&o!==r&&sn(t,o,{get:()=>e[o],enumerable:!(n=Y0(e,o))||n.enumerable});return t};var ef=t=>Q0(sn({},"__esModule",{value:!0}),t);var u=(t,e,r)=>J0(t,typeof e!="symbol"?e+"":e,r);var y=ye(()=>{"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 _f(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Lo(t,e=""){if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new Error(`${r}expected integer >= 0, got ${t}`)}}function Zt(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 Jt(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 gn(t,e){Zt(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 rc(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Me(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function mn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Oe(t,e){return t<<32-e|t>>>e}function Uf(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function Of(t){for(let e=0;e<t.length;e++)t[e]=Uf(t[e]);return t}function vr(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 If,To,kr,wn=ye(()=>{y();If=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;To=If?t=>t:Of;kr=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])})});function nc(t,e,r){return t&e^~t&r}function oc(t,e,r){return t&e^t&r^e&r}var Hr,Je,be,sc=ye(()=>{y();wn();Hr=class{constructor(e,r,n,o){u(this,"blockLen");u(this,"outputLen");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=mn(this.buffer)}update(e){Jt(this),Zt(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=mn(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){Jt(this),gn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Me(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let h=i;h<o;h++)r[h]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let c=mn(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=a/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)c.setUint32(4*h,l[h],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()}},Je=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),be=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209])});function Rf(t,e=!1){return e?{h:Number(t&En),l:Number(t>>ic&En)}:{h:Number(t>>ic&En)|0,l:Number(t&En)|0}}function An(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]}function Ne(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var En,ic,_o,Io,Rt,Kt,Lr,Tr,cc,ac,fc,uc,lc,dc,hc,pc,xc,yc,Uo=ye(()=>{y();En=BigInt(4294967295),ic=BigInt(32);_o=(t,e,r)=>t>>>r,Io=(t,e,r)=>t<<32-r|e>>>r,Rt=(t,e,r)=>t>>>r|e<<32-r,Kt=(t,e,r)=>t<<32-r|e>>>r,Lr=(t,e,r)=>t<<64-r|e>>>r-32,Tr=(t,e,r)=>t>>>r-32|e<<64-r,cc=(t,e,r)=>t<<r|e>>>32-r,ac=(t,e,r)=>e<<r|t>>>32-r,fc=(t,e,r)=>e<<r-32|t>>>64-r,uc=(t,e,r)=>t<<r-32|e>>>64-r;lc=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),dc=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,hc=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),pc=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,xc=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),yc=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0});var Cf,lt,Oo,Ro,bc,Ff,Df,dt,ht,Ko,Co,gc,mc,wc=ye(()=>{y();sc();Uo();wn();Cf=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),Oo=class extends Hr{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 h=0;h<16;h++,r+=4)lt[h]=e.getUint32(r,!1);for(let h=16;h<64;h++){let d=lt[h-15],p=lt[h-2],x=Oe(d,7)^Oe(d,18)^d>>>3,E=Oe(p,17)^Oe(p,19)^p>>>10;lt[h]=E+lt[h-7]+x+lt[h-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:f,H:l}=this;for(let h=0;h<64;h++){let d=Oe(c,6)^Oe(c,11)^Oe(c,25),p=l+d+nc(c,a,f)+Cf[h]+lt[h]|0,E=(Oe(n,2)^Oe(n,13)^Oe(n,22))+oc(n,o,s)|0;l=f,f=a,a=c,c=i+p|0,i=s,s=o,o=n,n=p+E|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,f=f+this.G|0,l=l+this.H|0,this.set(n,o,s,i,c,a,f,l)}roundClean(){Me(lt)}destroy(){this.set(0,0,0,0,0,0,0,0),Me(this.buffer)}},Ro=class extends Oo{constructor(){super(32);u(this,"A",Je[0]|0);u(this,"B",Je[1]|0);u(this,"C",Je[2]|0);u(this,"D",Je[3]|0);u(this,"E",Je[4]|0);u(this,"F",Je[5]|0);u(this,"G",Je[6]|0);u(this,"H",Je[7]|0)}},bc=An(["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))),Ff=bc[0],Df=bc[1],dt=new Uint32Array(80),ht=new Uint32Array(80),Ko=class extends Hr{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:f,El:l,Fh:h,Fl:d,Gh:p,Gl:x,Hh:E,Hl:w}=this;return[e,r,n,o,s,i,c,a,f,l,h,d,p,x,E,w]}set(e,r,n,o,s,i,c,a,f,l,h,d,p,x,E,w){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=f|0,this.El=l|0,this.Fh=h|0,this.Fl=d|0,this.Gh=p|0,this.Gl=x|0,this.Hh=E|0,this.Hl=w|0}process(e,r){for(let g=0;g<16;g++,r+=4)dt[g]=e.getUint32(r),ht[g]=e.getUint32(r+=4);for(let g=16;g<80;g++){let m=dt[g-15]|0,U=ht[g-15]|0,P=Rt(m,U,1)^Rt(m,U,8)^_o(m,U,7),X=Kt(m,U,1)^Kt(m,U,8)^Io(m,U,7),q=dt[g-2]|0,z=ht[g-2]|0,D=Rt(q,z,19)^Lr(q,z,61)^_o(q,z,6),J=Kt(q,z,19)^Tr(q,z,61)^Io(q,z,6),Z=hc(X,J,ht[g-7],ht[g-16]),ae=pc(Z,P,D,dt[g-7],dt[g-16]);dt[g]=ae|0,ht[g]=Z|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:f,Dl:l,Eh:h,El:d,Fh:p,Fl:x,Gh:E,Gl:w,Hh:H,Hl:L}=this;for(let g=0;g<80;g++){let m=Rt(h,d,14)^Rt(h,d,18)^Lr(h,d,41),U=Kt(h,d,14)^Kt(h,d,18)^Tr(h,d,41),P=h&p^~h&E,X=d&x^~d&w,q=xc(L,U,X,Df[g],ht[g]),z=yc(q,H,m,P,Ff[g],dt[g]),D=q|0,J=Rt(n,o,28)^Lr(n,o,34)^Lr(n,o,39),Z=Kt(n,o,28)^Tr(n,o,34)^Tr(n,o,39),ae=n&s^n&c^s&c,fe=o&i^o&a^i&a;H=E|0,L=w|0,E=p|0,w=x|0,p=h|0,x=d|0,{h,l:d}=Ne(f|0,l|0,z|0,D|0),f=c|0,l=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let V=lc(D,Z,fe);n=dc(V,z,J,ae),o=V|0}({h:n,l:o}=Ne(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ne(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Ne(this.Ch|0,this.Cl|0,c|0,a|0),{h:f,l}=Ne(this.Dh|0,this.Dl|0,f|0,l|0),{h,l:d}=Ne(this.Eh|0,this.El|0,h|0,d|0),{h:p,l:x}=Ne(this.Fh|0,this.Fl|0,p|0,x|0),{h:E,l:w}=Ne(this.Gh|0,this.Gl|0,E|0,w|0),{h:H,l:L}=Ne(this.Hh|0,this.Hl|0,H|0,L|0),this.set(n,o,s,i,c,a,f,l,h,d,p,x,E,w,H,L)}roundClean(){Me(dt,ht)}destroy(){Me(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Co=class extends Ko{constructor(){super(64);u(this,"Ah",be[0]|0);u(this,"Al",be[1]|0);u(this,"Bh",be[2]|0);u(this,"Bl",be[3]|0);u(this,"Ch",be[4]|0);u(this,"Cl",be[5]|0);u(this,"Dh",be[6]|0);u(this,"Dl",be[7]|0);u(this,"Eh",be[8]|0);u(this,"El",be[9]|0);u(this,"Fh",be[10]|0);u(this,"Fl",be[11]|0);u(this,"Gh",be[12]|0);u(this,"Gl",be[13]|0);u(this,"Hh",be[14]|0);u(this,"Hl",be[15]|0)}},gc=vr(()=>new Ro,kr(1)),mc=vr(()=>new Co,kr(3))});function qf(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,f=r[a],l=r[a+1],h=Ec(f,l,1)^r[c],d=Ac(f,l,1)^r[c+1];for(let p=0;p<50;p+=10)t[i+p]^=h,t[i+p+1]^=d}let o=t[2],s=t[3];for(let i=0;i<24;i++){let c=Sc[i],a=Ec(o,s,c),f=Ac(o,s,c),l=Bc[i];o=t[l],s=t[l+1],t[l]=a,t[l+1]=f}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]^=Gf[n],t[1]^=zf[n]}Me(r)}var Mf,_r,Nf,jf,Pf,$f,Bc,Sc,vc,kc,Gf,zf,Ec,Ac,Fo,Wf,Hc,Lc=ye(()=>{y();Uo();wn();Mf=BigInt(0),_r=BigInt(1),Nf=BigInt(2),jf=BigInt(7),Pf=BigInt(256),$f=BigInt(113),Bc=[],Sc=[],vc=[];for(let t=0,e=_r,r=1,n=0;t<24;t++){[r,n]=[n,(2*r+3*n)%5],Bc.push(2*(5*n+r)),Sc.push((t+1)*(t+2)/2%64);let o=Mf;for(let s=0;s<7;s++)e=(e<<_r^(e>>jf)*$f)%Pf,e&Nf&&(o^=_r<<(_r<<BigInt(s))-_r);vc.push(o)}kc=An(vc,!0),Gf=kc[0],zf=kc[1],Ec=(t,e,r)=>r>32?fc(t,e,r):cc(t,e,r),Ac=(t,e,r)=>r>32?uc(t,e,r):ac(t,e,r);Fo=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,"enableXOF",!1);u(this,"rounds");if(this.blockLen=e,this.suffix=r,this.outputLen=n,this.enableXOF=o,this.rounds=s,Lo(n,"outputLen"),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=rc(this.state)}clone(){return this._cloneInto()}keccak(){To(this.state32),qf(this.state32,this.rounds),To(this.state32),this.posOut=0,this.pos=0}update(e){Jt(this),Zt(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)!==0&&n===o-1&&this.keccak(),e[o-1]^=128,this.keccak()}writeInto(e){Jt(this,!1),Zt(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 Lo(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(gn(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,Me(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}},Wf=(t,e,r,n={})=>vr(()=>new Fo(e,t,r),n),Hc=Wf(6,136,32,kr(8))});var Bn={};yo(Bn,{createHash:()=>Tc,default:()=>Vf});function Tc(t){let e=new Uint8Array(0),r;switch(t.toLowerCase()){case"sha256":case"sha-256":r=gc;break;case"sha512":case"sha-512":r=mc;break;case"sha3-256":r=Hc;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 Vf,Sn=ye(()=>{"use strict";y();wc();Lc();Vf={createHash:Tc}});function kn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function Qe(t,e=""){if(typeof t!="number")throw new TypeError(Do(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Do(e)+"expected integer >= 0, got "+t);return t}function je(t,e,r=""){if(kn(t)&&(e===void 0||t.length===e))return t;e!==void 0&&Qe(e,"length");let n=kn(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=Do(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function Hn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Qe(t.outputLen),Qe(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}function er(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function Ln(t,e){je(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Ur(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Tn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Re(t,e){return t<<32-e|t>>>e}function _n(t){if(je(t),Oc)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Zf[t[r]];return e}function Uc(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function Mo(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Oc)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=Uc(t.charCodeAt(s)),c=Uc(t.charCodeAt(s+1));if(i===void 0||c===void 0){let a=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function Rc(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];je(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 Jf(t,e,r="opts"){return Ic(t,"defaults"),e!==void 0&&Ic(e,r),Object.assign(t,e)}function Kc(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=Jf({},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 Cc(t=32){Qe(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 Do,Ic,Oc,Zf,Fc,tr=ye(()=>{y();Do=t=>t?`"${t}" `:"";Ic=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)};Oc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Zf=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));Fc=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])})});function Or(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 $c(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function xt(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 Ct(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}function _e(t,e=""){if(typeof t!="boolean")throw new TypeError(eu(e)+"expected boolean, got type="+typeof t);return t}function Kn(t){if(typeof t=="bigint"){if(!yt(t))throw new RangeError("positive bigint expected, got "+t)}else Po(t);return t}function nr(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=Kn(t).toString(16);return e.length&1?"0"+e:e}function Gc(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Un:BigInt("0x"+t)}function Pe(t){return Gc(_n(t))}function Go(t){return Gc(_n(tu(je(t)).reverse()))}function Cn(t,e){if(Qe(e),e===0)throw new Error("zero output length is invalid");t=Kn(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return Mo(n.padStart(r,"0"))}function zo(t,e){return Cn(t,e).reverse()}function tu(t){return Uint8Array.from(pe(t))}function yt(t){return typeof t=="bigint"&&Un<=t}function qo(t,e,r){return yt(t)&&yt(e)&&yt(r)&&e<=t&&t<r}function Wo(t,e,r,n){if(!qo(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function or(t){if(t<Un)throw new Error("expected non-negative bigint, got "+t);return t===Un?0:t.toString(2).length}function zc(t,e,r){if(Qe(t,"hashLen"),Qe(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=w=>new Uint8Array(w),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),c=1e3,a=n(t),f=n(t),l=0,h=()=>{a.fill(1),f.fill(0),l=0},d=(...w)=>r(f,et(a,...w)),p=(w=o)=>{f=d(s,w),a=d(),w.length!==0&&(f=d(i,w),a=d())},x=()=>{if(l++>=c)throw new Error("drbg: tried max amount of iterations");let w=0,H=[];for(;w<e;){a=d();let L=a.slice();H.push(L),w+=a.length}return et(...H)};return(w,H)=>{h(),p(w);let L;for(;(L=H(x()))===void 0;)p();return h(),L}}function $e(t,e={},r={},n="object"){xt(t,n),xt(e,"fields"),xt(r,"optFields");function o(i,c,a){let f=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,l=t[i];if(!Object.hasOwn(t,i)&&(a?l!==void 0:c!=="function"))throw new TypeError(`${f} is invalid: expected own property`);if(a&&l===void 0)return;let h=typeof l;if(h!==c||l===null)throw new TypeError(`${f} is invalid: expected ${c}, got ${h}`)}let s=(i,c)=>Object.entries(i).forEach(([a,f])=>o(a,f,c));s(e,!1),s(r,!0)}var pe,Po,$o,et,On,rr,Rn,Un,Pc,eu,Kr,Ft=ye(()=>{y();tr();pe=(t,e,r)=>je(t,e,r),Po=Qe;$o=_n,et=(...t)=>Rc(...t),On=t=>Mo(t),rr=kn,Rn=t=>Cc(t),Un=BigInt(0),Pc=BigInt(1),eu=t=>t?`"${t}" `:"";Kr=t=>(nr(t,"n"),(Pc<<BigInt(t))-Pc)});function ve(t,e){if(e<=xe)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=xe?r:e+r}function Qc(t,e,r){if(r<=ee)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<xe)throw new Error("invalid exponent, negatives unsupported");if(e===xe)return ee;if(e===ee)return t;let n=t%r;if(n<xe&&(n+=r),e<su){let c=ee;for(;e>xe;)e&ee&&(c=c*n%r),n=n*n%r,e>>=ee;return c}let o=[];for(;e>xe;)o.push(Number(e&ou)),e>>=Vo;let s=new Array(16);s[0]=ee,s[1]=n;for(let c=2;c<16;c++)s[c]=s[c-1]*n%r;let i=s[o[o.length-1]];for(let c=o.length-2;c>=0;c--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let a=o[c];a!==0&&(i=i*s[a]%r)}return i}function ke(t,e,r){if(r<=ee)throw new Error("pow2: expected modulus > 1, got "+r);if(e<xe)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >xe;)n*=n,n%=r;return n}function qc(t,e){if(t===xe)throw new Error("invert: expected non-zero number");if(e<=ee)throw new Error("invert: expected modulus > 1, got "+e);let r=ve(t,e),n=e,o=xe,s=ee;for(;r!==xe;){let c=n/r,a=n-r*c,f=o-s*c;n=r,r=a,o=s,s=f}if(n!==ee)throw new Error("invert: does not exist");return ve(o,e)}function ea(t,e){if(e<=ee)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=ve(t,e);if(r===xe)throw new Error("invertCt: expected non-zero number");let n=Qc(r,e-bt,e);if(ve(r*n,e)!==ee)throw new Error("invertCt: does not exist");return n}function Yo(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Xo(t,e){if((t&ee)===xe)throw new Error(e+": expected odd modulus, got "+t)}function ta(t,e){let r=t,n=(r.ORDER+ee)/Vo,o=r.pow(e,n);return Yo(r,o,e),o}function iu(t,e){let r=t,n=(r.ORDER-Xc)/Zc,o=r.mul(e,bt),s=r.pow(o,n),i=r.mul(e,s),c=r.mul(r.mul(i,bt),s),a=r.mul(i,r.sub(c,r.ONE));return Yo(r,a,e),a}function cu(t){let e=ir(t),r=ra(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+ru)/Jc;return((c,a)=>{let f=c,l=f.pow(a,i),h=f.mul(l,n),d=f.mul(l,o),p=f.mul(l,s),x=f.eql(f.sqr(h),a),E=f.eql(f.sqr(d),a);l=f.cmov(l,h,x),h=f.cmov(p,d,E);let w=f.eql(f.sqr(h),a),H=f.cmov(l,h,w);return Yo(f,H,a),H})}function ra(t){if(t<Yc)throw new Error("sqrt is not defined for small field");Xo(t,"tonelliShanks");let e=t-ee,r=0;for(;e%bt===xe;)e/=bt,r++;let n=bt,o=ir(t);for(;Wc(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ta;let s=o.pow(n,e),i=(e+ee)/bt;return function(a,f){let l=a;if(l.is0(f))return f;if(Wc(l,f)!==1)throw new Error("Cannot find square root");let h=r,d=l.mul(l.ONE,s),p=l.pow(f,e),x=l.pow(f,i);for(;!l.eql(p,l.ONE);){if(l.is0(p))throw new Error("Cannot find square root: probably non-prime P");let E=1,w=l.sqr(p);for(;!l.eql(w,l.ONE);)if(E++,w=l.sqr(w),E===h)throw new Error("Cannot find square root");let H=ee<<BigInt(h-E-1),L=l.pow(d,H);h=E,d=l.sqr(L),p=l.mul(p,d),x=l.mul(x,L)}return x}}function au(t){return Xo(t,"Fp.sqrt"),t%Vo===Yc?ta:t%Zc===Xc?iu:t%Jc===nu?cu(t):ra(t)}function sr(t){if(xt(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);nr(t.BYTES,"BYTES"),nr(t.BITS,"BITS");for(let e of fu)Ct(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=ee)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Zo(t,e,r=!1){sr(t),Or(e,"nums"),_e(r,"passZero");let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((c,a,f)=>n.is0(a)?c:(o[f]=c,n.mul(c,a)),n.ONE),i=n.inv(s);return e.reduceRight((c,a,f)=>n.is0(a)?c:(o[f]=n.mul(c,o[f]),n.mul(c,a)),i),o}function Wc(t,e){sr(t);let r=t;Xo(r.ORDER,"FpLegendre");let n=(r.ORDER-ee)/bt,o=r.pow(e,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),c=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!c)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function uu(t,e){if(e!==void 0&&Po(e),t<=xe)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=or(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 ir(t,e={}){return Object.freeze(Fn.prototype),new Fn(t,e)}function na(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=ee)throw new Error("field order must be greater than 1");let e=or(t-ee);return Math.ceil(e/8)}function Dn(t){let e=na(t);return e+Math.ceil(e/2)}function Mn(t,e,r=!1){pe(t);let n=t.length,o=na(e),s=Math.max(Dn(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Go(t):Pe(t),c=ve(i,e-ee)+ee;return r?zo(c,o):Cn(c,o)}var xe,ee,bt,Yc,Vo,Xc,ru,Zc,nu,ou,Jc,su,fu,Vc,Fn,Nn=ye(()=>{y();Ft();xe=BigInt(0),ee=BigInt(1),bt=BigInt(2),Yc=BigInt(3),Vo=BigInt(4),Xc=BigInt(5),ru=BigInt(7),Zc=BigInt(8),nu=BigInt(9),ou=BigInt(15),Jc=BigInt(16),su=BigInt("0x10000000000000000");fu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];Vc=new WeakMap,Fn=class{constructor(e,r={}){u(this,"ORDER");u(this,"BITS");u(this,"BYTES");u(this,"isLE");u(this,"ZERO",xe);u(this,"ONE",ee);u(this,"_lengths");u(this,"_mod");if(e<=ee)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=uu(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return ve(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return xe<=e&&e<this.ORDER}is0(e){return e===xe}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&ee)===ee}neg(e){return ve(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ve(e*e,this.ORDER)}add(e,r){return ve(e+r,this.ORDER)}sub(e,r){return ve(e-r,this.ORDER)}mul(e,r){return ve(e*r,this.ORDER)}pow(e,r){return Qc(e,r,this.ORDER)}div(e,r){return ve(e*qc(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 qc(e,this.ORDER)}sqrt(e){let r=Vc.get(this);return r||Vc.set(this,r=au(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?zo(e,this.BYTES):Cn(e,this.BYTES)}fromBytes(e,r=!1){pe(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:c}=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 a=s?Go(e):Pe(e);if(c&&(a=ve(a,i)),!r&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(e){return Zo(this,e,!0)}cmov(e,r,n){return _e(n,"condition"),n?r:e}}});function Fr(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 ha(t){return Fr(t,"x"),(t&t-1)===0&&t!==0}function rs(t,e){if(Fr(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 pa(t){return Fr(t),31-Math.clz32(t)}function da(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(!ha(e))throw new Error("expected positive power-of-two length, got "+e);let r=pa(e);for(let n=0;n<e;n++){let o=rs(n,r);if(n<o){let s=t[n];t[n]=t[o],t[o]=s}}return t}var ns,xa=ye(()=>{y();Ft();ns=(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:c=!0}=e;Fr(r,"coreOpts.N");let a=pa(r);if(!ha(r))throw new Error("FFT: Polynomial size should be power of two");Fr(i,"coreOpts.skipStages");let f=a===0?0:a-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 l=o!==s;return h=>{if(h.length!==r)throw new Error("FFT: wrong Polynomial length");o&&c&&da(h);for(let d=0,p=1;d<a-i;d++){let x=o?d+1+i:a-d,E=1<<x,w=E>>1,H=r>>x;for(let L=0;L<r;L+=E)for(let g=0,m=p++;g<w;g++){let U=s?o?r-m:m:g*H,P=L+g,X=L+g+w,q=n[U],z=h[X],D=h[P];if(l){let J=t.mul(z,q);h[P]=t.add(D,J),h[X]=t.sub(D,J)}else s?(h[P]=t.add(z,D),h[X]=t.mul(t.sub(z,D),q)):(h[P]=t.add(D,z),h[X]=t.mul(t.sub(D,z),q))}}return!o&&c&&da(h),h}}});function wl(t,e=!1){return e?{h:Number(t&eo),l:Number(t>>B0&eo)}:{h:Number(t>>B0&eo)|0,l:Number(t&eo)|0}}function S0(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}=wl(t[s],e);[n[s],o[s]]=[i,c]}return[n,o]}var eo,B0,v0=ye(()=>{y();eo=BigInt(4294967295),B0=BigInt(32)});function to(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function we(t,e=""){if(typeof t!="number")throw new TypeError(ro(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(ro(e)+"expected integer >= 0, got "+t);return t}function H0(t,e=""){if(typeof t!="boolean")throw new TypeError(ro(e)+"expected boolean, got type="+typeof t);return t}function he(t,e,r=""){if(to(t)&&(e===void 0||t.length===e))return t;e!==void 0&&we(e,"length");let n=to(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=ro(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function L0(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(we(t.outputLen),we(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}function Gs(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function T0(t,e){he(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function zs(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function qs(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function El(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function Al(t){for(let e=0;e<t.length;e++)t[e]=El(t[e]);return t}function Vs(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];he(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 Ys(t,e,r="opts"){return k0(t,"defaults"),e!==void 0&&k0(e,r),Object.assign(t,e)}function I0(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=Ys({},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 U0(t=32){we(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 ro,k0,_0,Ws,Xs,Zs=ye(()=>{y();ro=t=>t?`"${t}" `:"";k0=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)};_0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;Ws=_0?t=>t:Al;Xs=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])})});function Rl(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(we(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++)pr[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,c=(s+2)%10,a=pr[c],f=pr[c+1],l=O0(a,f,1)^pr[i],h=R0(a,f,1)^pr[i+1];for(let d=0;d<50;d+=10)t[s+d]^=l,t[s+d+1]^=h}let n=t[2],o=t[3];for(let s=0;s<24;s++){let i=C0[s],c=O0(n,o,i),a=R0(n,o,i),f=K0[s];n=t[f],o=t[f+1],t[f]=c,t[f+1]=a}for(let s=0;s<50;s+=10){let i=t[s],c=t[s+1],a=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]&c,t[s+8]^=~i&a,t[s+9]^=~c&f}t[0]^=Ll[r],t[1]^=Tl[r]}qs(pr)}var Bl,Vr,Sl,vl,kl,Hl,K0,C0,F0,D0,Ll,Tl,_l,Il,Ul,Ol,O0,R0,pr,Js,M0,N0,Ee,Qs=ye(()=>{y();v0();Zs();Bl=BigInt(0),Vr=BigInt(1),Sl=BigInt(2),vl=BigInt(7),kl=BigInt(256),Hl=BigInt(113),K0=[],C0=[],F0=[];for(let t=0,e=Vr,r=1,n=0;t<24;t++){[r,n]=[n,(2*r+3*n)%5],K0.push(2*(5*n+r)),C0.push((t+1)*(t+2)/2%64);let o=Bl;for(let s=0;s<7;s++)e=(e<<Vr^(e>>vl)*Hl)%kl,e&Sl&&(o^=Vr<<(Vr<<BigInt(s))-Vr);F0.push(o)}D0=S0(F0,!0),Ll=D0[0],Tl=D0[1],_l=(t,e,r)=>t<<r|e>>>32-r,Il=(t,e,r)=>e<<r|t>>>32-r,Ul=(t,e,r)=>e<<r-32|t>>>64-r,Ol=(t,e,r)=>t<<r-32|e>>>64-r,O0=(t,e,r)=>r>32?Ul(t,e,r):_l(t,e,r),R0=(t,e,r)=>r>32?Ol(t,e,r):Il(t,e,r),pr=new Uint32Array(10);Js=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(we(e,"blockLen"),we(r,"suffix"),we(s,"rounds"),H0(o,"enableXOF"),this.blockLen=e,this.suffix=r,this.outputLen=n,this.enableXOF=o,this.canXOF=o,this.rounds=s,we(n,"outputLen"),!(0<e&&e<200))throw new Error('"blockLen" must be 1..199');this.state=new Uint8Array(200),this.state32=zs(this.state)}clone(){return this._cloneInto()}keccak(){Ws(this.state32),Rl(this.state32,this.rounds),Ws(this.state32),this.posOut=0,this.pos=0}update(e){Gs(this),he(e);let{blockLen:r,state:n,state32:o}=this,s=e.length,i=r%4===0&&e.byteOffset%4===0,c=r/4,a=i&&s>=r?zs(e):void 0;for(let f=0;f<s;){if(a!==void 0&&this.pos===0&&f%4===0&&s-f>=r){for(let h=0,d=f/4;h<c;h++)o[h]^=a[d+h];f+=r,this.pos=r,this.keccak();continue}let l=Math.min(r-this.pos,s-f);for(let h=0;h<l;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){Gs(this,!1),he(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 we(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(T0(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,qs(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}},M0=(t,e,r,n={})=>I0((o={})=>(o=Ys({},o),new Js(e,t,o.dkLen===void 0?r:o.dkLen,!0)),n),N0=M0(31,168,16,Xs(11)),Ee=M0(31,136,32,Xs(12))});function Kl(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 Cl(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 ti(t,e){if(t=he(t),e=he(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 ri(t){if(to(t))throw new TypeError('"opts" expected object, got Uint8Array');Cl(t,"opts")}function no(t){ri(t),t.context!==void 0&&he(t.context,void 0,"opts.context")}function oo(t){no(t),t.extraEntropy!==!1&&t.extraEntropy!==void 0&&he(t.extraEntropy,void 0,"opts.extraEntropy")}function Yr(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],f=r(a),l=typeof a=="number"?o[i]:a.encode(o[i]);he(l,f,t),s.set(l,c),typeof a!="number"&&l.fill(0),c+=f}return s},decode:o=>{he(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 Gt(t,e){let r=t,n=e*r.bytesLen;return{bytesLen:n,encode:o=>{let s=Kl(o,"u");if(s.length!==e)throw new RangeError(`vecCoder.encode: wrong length=${s.length}. Expected: ${e}`);let i=new Uint8Array(n);for(let c=0,a=0;c<s.length;c++){let f=r.encode(s[c]);i.set(f,a),f.fill(0),a+=f.length}return i},decode:o=>{he(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 Le(...t){for(let e of t)if(Array.isArray(e))for(let r of e)r.fill(0);else e.fill(0)}function ni(t){if(we(t,"bits"),t>32)throw new RangeError('"bits" expected <= 32, got '+t);return t===32?4294967295:~(-1<<t)>>>0}function oi(t,e=j0){if(he(t,void 0,"msg"),he(e,void 0,"ctx"),e.length>255)throw new RangeError("context should be 255 bytes or less");return Vs(new Uint8Array([0,e.length]),e,t)}function si(t,e=0){if(typeof t!="function"||typeof t.create!="function")throw new TypeError('"hash" expected hash function, got type='+typeof t);L0(t),we(e,"requiredStrength");let r=t.oid;if(he(r,void 0,"hash.oid"),!ti(r.subarray(0,10),Fl))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 ii(t,e,r=j0){if(si(t),he(e,void 0,"msg"),he(r,void 0,"ctx"),r.length>255)throw new RangeError("context should be 255 bytes or less");let n=t(e);return Vs(new Uint8Array([1,r.length]),r,t.oid,n)}var kt,ei,j0,Fl,ci=ye(()=>{y();Zs();kt=he,ei=U0;j0=Uint8Array.of();Fl=Uint8Array.from([6,9,96,134,72,1,101,3,4,2])});var P0,$0,so,io,G0=ye(()=>{y();xa();Qs();ci();P0=t=>{let{newPoly:e,N:r,Q:n,F:o,ROOT_OF_UNITY:s,brvBits:i,isKyber:c}=t,a=(g,m=n)=>{let U=g%m|0;return(U>=0?U|0:m+U|0)|0},f=(g,m=n)=>{let U=a(g,m)|0;return(U>m>>1?U-m|0:U)|0};function l(){let g=e(r);for(let m=0;m<r;m++){let U=rs(m,i),P=BigInt(s)**BigInt(U)%BigInt(n);g[m]=Number(P)|0}return g}let h=l(),d=g=>{throw new Error("not implemented")},p=c?{add:(g,m)=>{let U=g+m|0;return U>=n?U-n|0:U},sub:(g,m)=>{let U=g-m|0;return U<0?U+n|0:U},mul:(g,m)=>a((g|0)*(m|0))|0,inv:d}:{add:(g,m)=>a((g|0)+(m|0))|0,sub:(g,m)=>a((g|0)-(m|0))|0,mul:(g,m)=>a((g|0)*(m|0))|0,inv:d},x={N:r,roots:h,invertButterflies:!0,skipStages:c?1:0,brp:!1},E=ns(p,{dit:!1,...x}),w=ns(p,{dit:!0,...x}),H={encode:g=>E(g),decode:g=>{w(g);for(let m=0;m<g.length;m++)g[m]=a(o*g[m]);return g}};return{mod:a,smod:f,nttZetas:h,NTT:{encode:g=>H.encode(g),decode:g=>H.decode(g)},bitsCoder:(g,m)=>{for(let X=0,q=0;X<r;X++)q+=g,q>32&&ni(q),q%=8;let U=ni(g),P=g*(r/8);return{bytesLen:P,encode:X=>{let q=X,z=new Uint8Array(P);for(let D=0,J=0,Z=0,ae=0;D<q.length;D++)for(J|=(m.encode(q[D])&U)<<Z,Z+=g;Z>=8;Z-=8,J>>=8)z[ae++]=J&255;return z},decode:X=>{let q=e(r);for(let z=0,D=0,J=0,Z=0;z<X.length;z++)for(D|=X[z]<<J,J+=8;J>=g;J-=g,D>>=g)q[Z++]=m.decode(D&U);return q}}}}},$0=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:(f,l)=>(n[o+0]=f,n[o+1]=l,i.destroy(),i=t.create({}).update(n),c++,()=>(a++,i.xofInto(s))),clean:()=>{i.destroy(),Le(s,n)}}},so=$0(N0),io=$0(Ee)});var fo={};yo(fo,{PARAMS:()=>ao,ml_dsa44:()=>jl,ml_dsa65:()=>Pl,ml_dsa87:()=>$l});function z0(t){ri(t),t.externalMu!==void 0&&_e(t.externalMu,"opts.externalMu")}function co(t){let e=t,r=Te(ce);for(let n=0;n<ce;){let o=e();if(o.length%3)throw new Error("RejNTTPoly: unaligned block");for(let s=0;n<ce&&s<=o.length-3;s+=3){let i=(o[s+0]|o[s+1]<<8|o[s+2]<<16)&8388607;i<Tt&&(r[n++]=i)}}return r}function ui(t){let e=t,{K:r,L:n,GAMMA1:o,GAMMA2:s,TAU:i,ETA:c,OMEGA:a}=e,{CRH_BYTES:f,TR_BYTES:l,C_TILDE_BYTES:h,XOF128:d,XOF256:p,securityLevel:x}=e;if(![2,4].includes(c))throw new Error("Wrong ETA");if(![1<<17,1<<19].includes(o))throw new Error("Wrong GAMMA1");if(![ai,fi].includes(s))throw new Error("Wrong GAMMA2");let E=i*c,w=b=>{let B=Q.mod(b),S=Q.smod(B,2*s)|0;return B-S===Tt-1?{r1:0,r0:S-1|0}:{r1:Math.floor((B-S)/(2*s))|0,r0:S}},H=b=>w(b).r1,L=b=>w(b).r0,g=(b,B)=>b<=s||b>Tt-s||b===Tt-s&&B===0?0:1,m=Math.floor((Tt-1)/(2*s)),U=(b,B)=>{let{r1:S,r0:v}=w(B);return b===1?v>0?Q.mod(S+1,m)|0:Q.mod(S-1,m)|0:S|0},P=b=>{let B=Q.mod(b),S=Q.smod(B,2**zt)|0;return{r1:Math.floor((B-S)/2**zt)|0,r0:S}},X={bytesLen:a+r,encode:b=>{let B=b;if(B===!1)throw new Error("hint.encode: hint is false");let S=new Uint8Array(a+r);for(let v=0,R=0;v<r;v++){for(let I=0;I<ce;I++)B[v][I]!==0&&(S[R++]=I);S[a+v]=R}return S},decode:b=>{let B=[],S=0;for(let v=0;v<r;v++){let R=Te(ce);if(b[a+v]<S||b[a+v]>a)return!1;for(let I=S;I<b[a+v];I++){if(I>S&&b[I]<=b[I-1])return!1;R[b[I]]=1}S=b[a+v],B.push(R)}for(let v=S;v<a;v++)if(b[v]!==0)return!1;return B}},q=Xr(c===2?3:4,b=>c-b,b=>{if(!(-c<=b&&b<=c))throw new Error(`malformed key s1/s3 ${b} outside of ETA range [${-c}, ${c}]`);return b}),z=Xr(13,b=>(1<<zt-1)-b),D=Xr(10),J=Xr(o===1<<17?18:20,b=>Q.smod(o-b)),Z=Xr(s===ai?6:4),ae=Gt(Z,r),fe=Yr("publicKey",32,Gt(D,r)),V=Yr("secretKey",32,32,l,Gt(q,n),Gt(q,r),Gt(z,r)),Y=Yr("signature",h,Gt(J,n),X),k=c===2?b=>b<15?2-b%5:!1:b=>b<9?4-b:!1;function O(b){let B=b,S=Te(ce);for(let v=0;v<ce;){let R=B();for(let I=0;v<ce&&I<R.length;I+=1){let G=k(R[I]&15),te=k(R[I]>>4&15);G!==!1&&(S[v++]=G),v<ce&&te!==!1&&(S[v++]=te)}}return S}let N=b=>{let B=Te(ce),S=Ee.create({}).update(b),v=new Uint8Array(Ee.blockLen);S.xofInto(v);let R=v.slice(0,8);for(let I=ce-i,G=8,te=0,le=0;I<ce;I++){let oe=I+1;for(;oe>I;)oe=v[G++],!(G<Ee.blockLen)&&(S.xofInto(v),G=0);B[I]=B[oe],B[oe]=1-((R[te]>>le++&1)<<1),le>=8&&(te++,le=0)}return B},_=b=>{let B=b,S=Te(ce),v=Te(ce);for(let R=0;R<B.length;R++){let{r0:I,r1:G}=P(B[R]);S[R]=I,v[R]=G}return{r0:S,r1:v}},A=(b,B)=>{let S=b,v=B;for(let R=0;R<ce;R++)S[R]=U(v[R],S[R]);return S},T=(b,B)=>{let S=b,v=B,R=Te(ce),I=0;for(let G=0;G<ce;G++){let te=g(S[G],v[G]);R[G]=te,I+=te}return{v:R,cnt:I}},M=32,j=Yr("seed",32,64,32),$=Object.freeze({info:Object.freeze({type:"internal-ml-dsa"}),lengths:Object.freeze({secretKey:V.bytesLen,publicKey:fe.bytesLen,seed:32,signature:Y.bytesLen,signRand:M}),keygen:b=>{let B=new Uint8Array(34),S=b===void 0;S&&(b=ei(32)),kt(b,32,"seed"),B.set(b),S&&Le(b),B[32]=r,B[33]=n;let[v,R,I]=j.decode(Ee(B,{dkLen:j.bytesLen})),G=p(R),te=[];for(let W=0;W<n;W++)te.push(O(G.get(W&255,W>>8&255)));let le=[];for(let W=n;W<n+r;W++)le.push(O(G.get(W&255,W>>8&255)));let oe=te.map(W=>Q.NTT.encode(W.slice())),re=[],de=[],Ae=d(v),ue=Te(ce);for(let W=0;W<r;W++){Le(ue);for(let ge=0;ge<n;ge++){let Se=co(Ae.get(ge,W));Ht(ue,Lt(Se,oe[ge]))}Q.NTT.decode(ue);let{r0:It,r1:se}=_(Ht(ue,le[W]));re.push(It),de.push(se)}let Be=fe.encode([v,de]),Fe=Ee(Be,{dkLen:l}),Ye=V.encode([v,I,Fe,te,le,re]);return Ae.clean(),G.clean(),Le(v,R,I,te,le,oe,ue,re,de,Fe,B),{publicKey:Be,secretKey:Ye}},getPublicKey:b=>{let[B,S,v,R,I,G]=V.decode(b),te=d(B),le=R.map(de=>Q.NTT.encode(de.slice())),oe=[],re=Te(ce);for(let de=0;de<r;de++){re.fill(0);for(let ue=0;ue<n;ue++){let Be=co(te.get(ue,de));Ht(re,Lt(Be,le[ue]))}Q.NTT.decode(re),Ht(re,I[de]);let{r1:Ae}=_(re);oe.push(Ae)}return te.clean(),Le(re,le,G,R,I),fe.encode([B,oe])},sign:(b,B,S={})=>{oo(S),z0(S);let{extraEntropy:v,externalMu:R=!1}=S;R&&kt(b,f,"mu");let I=v===!1||v===void 0,G=v===!1?new Uint8Array(32):v===void 0?ei(M):v;kt(G,32,"extraEntropy");let te=(()=>{try{return V.decode(B)}catch(se){throw I&&Le(G),se}})(),[le,oe,re,de,Ae,ue]=te,Be=[],Fe=d(le);for(let se=0;se<r;se++){let ge=[];for(let Se=0;Se<n;Se++)ge.push(co(Fe.get(Se,se)));Be.push(ge)}Fe.clean();for(let se=0;se<n;se++)Q.NTT.encode(de[se]);for(let se=0;se<r;se++)Q.NTT.encode(Ae[se]),Q.NTT.encode(ue[se]);let Ye=R?b:Ee.create({dkLen:f}).update(re).update(b).digest(),W=Ee.create({dkLen:f}).update(oe).update(G).update(Ye).digest();I&&Le(G),kt(W,f);let It=p(W,J.bytesLen);e:for(let se=0;;){let ge=[];for(let ie=0;ie<n;ie++,se++)ge.push(J.decode(It.get(se&255,se>>8)()));let Se=ge.map(ie=>Q.NTT.encode(ie.slice())),Wt=[];for(let ie=0;ie<r;ie++){let yr=Te(ce);for(let ot=0;ot<n;ot++)Ht(yr,Lt(Be[ie][ot],Se[ot]));Q.NTT.decode(yr),Wt.push(yr)}let ho=Wt.map(ie=>ie.map(H)),po=Ee.create({dkLen:h}).update(Ye).update(ae.encode(ho)).digest(),nn=Q.NTT.encode(N(po)),on=de.map(ie=>Lt(ie,nn));for(let ie=0;ie<n;ie++)if(Ht(Q.NTT.decode(on[ie]),ge[ie]),Zr(on[ie],o-E))continue e;let yi=0,xo=[];for(let ie=0;ie<r;ie++){let yr=Q.NTT.decode(Lt(Ae[ie],nn)),ot=W0(Wt[ie],yr).map(L);if(Zr(ot,s-E))continue e;let bi=Q.NTT.decode(Lt(ue[ie],nn));if(Zr(bi,s))continue e;Ht(ot,bi);let gi=T(ot,ho[ie]);xo.push(gi.v),yi+=gi.cnt}if(yi>a)continue;It.clean();let V0=Y.encode([po,on,xo]);return Le(po,on,xo,nn,ho,Wt,Se,ge,W,de,Ae,ue,...Be),R||Le(Ye),V0}throw new Error("Unreachable code path reached, report this error")},verify:(b,B,S,v={})=>{z0(v);let{externalMu:R=!1}=v;R&&kt(B,f,"mu");let[I,G]=fe.decode(S),te=Ee(S,{dkLen:l});if(b.length!==Y.bytesLen)return!1;let[le,oe,re]=Y.decode(b);if(re===!1)return!1;for(let W=0;W<n;W++)if(Zr(oe[W],o-E))return!1;let de=R?B:Ee.create({dkLen:f}).update(te).update(B).digest(),Ae=Q.NTT.encode(N(le)),ue=oe.map(W=>W.slice());for(let W=0;W<n;W++)Q.NTT.encode(ue[W]);let Be=[],Fe=d(I);for(let W=0;W<r;W++){let It=Lt(Q.NTT.encode(Nl(G[W])),Ae),se=Te(ce);for(let Se=0;Se<n;Se++){let Wt=co(Fe.get(Se,W));Ht(se,Lt(Wt,ue[Se]))}let ge=Q.NTT.decode(W0(se,It));Be.push(A(ge,re[W]))}Fe.clean();let Ye=Ee.create({dkLen:h}).update(de).update(ae.encode(Be)).digest();for(let W of re)if(!(W.reduce((se,ge)=>se+ge,0)<=a))return!1;for(let W of oe)if(Zr(W,o-E))return!1;return ti(le,Ye)}});return Object.freeze({info:Object.freeze({type:"ml-dsa"}),internal:$,securityLevel:x,keygen:$.keygen,lengths:$.lengths,getPublicKey:$.getPublicKey,sign:(b,B,S={})=>{oo(S);let v=oi(b,S.context),R=$.sign(v,B,S);return Le(v),R},verify:(b,B,S,v={})=>(no(v),kt(b,void 0,"signature"),$.verify(b,oi(B,v.context),S)),prehash:b=>{si(b,x);let B=b;return Object.freeze({info:Object.freeze({type:"hashml-dsa"}),securityLevel:x,lengths:$.lengths,keygen:$.keygen,getPublicKey:$.getPublicKey,sign:(S,v,R={})=>{oo(R);let I=ii(B,S,R.context),G=$.sign(I,v,R);return Le(I),G},verify:(S,v,R,I={})=>(no(I),kt(S,void 0,"signature"),$.verify(S,ii(B,v,I.context),R))})}})}var ce,Tt,Dl,Ml,zt,ai,fi,ao,Te,Q,q0,Xr,Ht,W0,Nl,Zr,Lt,jl,Pl,$l,uo=ye(()=>{y();Ft();Qs();G0();ci();ce=256,Tt=8380417,Dl=1753,Ml=8347681,zt=13,ai=Math.floor((Tt-1)/88)|0,fi=Math.floor((Tt-1)/32)|0,ao=Object.freeze({2:Object.freeze({K:4,L:4,D:zt,GAMMA1:2**17,GAMMA2:ai,TAU:39,ETA:2,OMEGA:80}),3:Object.freeze({K:6,L:5,D:zt,GAMMA1:2**19,GAMMA2:fi,TAU:49,ETA:4,OMEGA:55}),5:Object.freeze({K:8,L:7,D:zt,GAMMA1:2**19,GAMMA2:fi,TAU:60,ETA:2,OMEGA:75})}),Te=t=>new Int32Array(t),Q=P0({N:ce,Q:Tt,F:Ml,ROOT_OF_UNITY:Dl,newPoly:Te,isKyber:!1,brvBits:8}),q0=t=>t,Xr=(t,e=q0,r=q0)=>Q.bitsCoder(t,{encode:n=>e(r(n)),decode:n=>r(e(n))}),Ht=(t,e)=>{let r=t,n=e;for(let o=0;o<r.length;o++)r[o]=Q.mod(r[o]+n[o]);return r},W0=(t,e)=>{let r=t,n=e;for(let o=0;o<r.length;o++)r[o]=Q.mod(r[o]-n[o]);return r},Nl=t=>{let e=t;for(let r=0;r<ce;r++)e[r]<<=zt;return e},Zr=(t,e)=>{let r=t;for(let n=0;n<ce;n++)if(Math.abs(Q.smod(r[n]))>=e)return!0;return!1},Lt=(t,e)=>{let r=t,n=e,o=Te(ce);for(let s=0;s<r.length;s++)o[s]=Q.mod(r[s]*n[s]);return o};jl=ui({...ao[2],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:32,XOF128:so,XOF256:io,securityLevel:128}),Pl=ui({...ao[3],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:48,XOF128:so,XOF256:io,securityLevel:192}),$l=ui({...ao[5],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:64,XOF128:so,XOF256:io,securityLevel:256})});var Vl={};yo(Vl,{InMemoryKeyStorage:()=>_t,createKeySDK:()=>xi,default:()=>Wl});y();y();y();y();y();y();y();var ki=Object.freeze({p:0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,n:0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,h:1n,a:0n,b:7n,Gx:0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,Gy:0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n}),{p:Ot,n:it,Gx:tf,Gy:rf,b:Hi}=ki,me=32,br=64,gr={publicKey:me+1,publicKeyUncompressed:br+1,signature:br,seed:me+me/2},ne=(t="",e=Error)=>{let r=new e(t),{captureStackTrace:n}=Error;throw typeof n=="function"&&n(r,ne),r},nf=t=>t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&t.BYTES_PER_ELEMENT===1,Ie=(t,e,r="")=>{let n=nf(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}`,f=i+"expected Uint8Array"+c+", got "+a;return n?ne(f,RangeError):ne(f,TypeError)}return t},ct=t=>new Uint8Array(t),Li=(t,e)=>t.toString(16).padStart(e,"0"),Ti=t=>{let e="";for(let r of Ie(t))e+=Li(r,2);return e},Xe={_0:48,_9:57,A:65,F:70,a:97,f:102},mi=t=>t>=Xe._0&&t<=Xe._9?t-Xe._0:t>=Xe.A&&t<=Xe.F?t-(Xe.A-10):t>=Xe.a&&t<=Xe.f?t-(Xe.a-10):void 0,_i=t=>{let e="hex invalid";if(typeof t!="string")return ne(e);let r=t.length,n=r/2;if(r%2)return ne(e);let o=ct(n);for(let s=0,i=0;s<n;s++,i+=2){let c=mi(t.charCodeAt(i)),a=mi(t.charCodeAt(i+1));if(c===void 0||a===void 0)return ne(e);o[s]=c*16+a}return o},wi=()=>globalThis?.crypto?.subtle??ne("crypto.subtle must be defined, consider polyfill"),Vt=(...t)=>{let e=0;for(let o of t)e+=Ie(o).length;let r=ct(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r},Ii=(t=me)=>(globalThis?.crypto).getRandomValues(ct(t)),an=BigInt,Er=(t,e,r,n="bad number: out of range")=>typeof t!="bigint"?ne(n,TypeError):e<=t&&t<r?t:ne(n,RangeError),F=(t,e=Ot)=>{let r=t%e;return r>=0n?r:e+r},st=t=>F(t,it),wo=(t,e)=>{(t===0n||e<=0n)&&ne("no inverse n="+t+" mod="+e);let r=F(t,e),n=e,o=0n,s=1n,i=1n,c=0n;for(;r!==0n;){let a=n/r,f=n%r,l=o-i*a,h=s-c*a;n=r,r=f,o=i,s=c,i=l,c=h}return n===1n?F(o,e):ne("no inverse")},Ui=t=>{let e=hn[t];return typeof e!="function"&&ne("hashes."+t+" not set"),e},Oi=(t,e,r)=>Ie(Ui(t)(e,r),me,"digest"),of=(t,e,r)=>Promise.resolve(Ui(t)(e,r)).then(n=>Ie(n,me,"digest"));var bo=t=>t instanceof Ze?t:ne("Point expected"),Ri=t=>F(F(t*t)*t+Hi),Ei=t=>Er(t,0n,Ot),cn=t=>Er(t,1n,Ot),go=t=>Er(t,1n,it),Ki=t=>!(t&1n),Ar=t=>Uint8Array.of(t),sf=t=>Ar(Ki(t)?2:3),cf=t=>{let e=Ri(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 F(r*r)!==e&&ne("sqrt invalid"),Ki(r)?r:F(-r)};var De=class De{constructor(e,r,n){u(this,"X");u(this,"Y");u(this,"Z");this.X=Ei(e),this.Y=cn(r),this.Z=Ei(n),Object.freeze(this)}static CURVE(){return ki}static fromAffine(e){let{x:r,y:n}=e;return r===0n&&n===0n?Ut:new De(r,n,1n)}static fromBytes(e){Ie(e);let{publicKey:r,publicKeyUncompressed:n}=gr,o,s=e.length,i=e[0],c=e.subarray(1),a=fn(c,0,me);if(s===r&&(i===2||i===3)){let f=cf(a);i===3&&(f=F(-f)),o=new De(a,f,1n)}return s===n&&i===4&&(o=new De(a,fn(c,me,br),1n)),o?o.assertValidity():ne("bad point: not on curve")}static fromHex(e){return De.fromBytes(_i(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:c}=bo(e),a=F(r*c),f=F(s*o),l=F(n*c),h=F(i*o);return a===f&&l===h}is0(){return this.equals(Ut)}negate(){return new De(this.X,F(-this.Y),this.Z)}double(){return this.add(this)}add(e){let{X:r,Y:n,Z:o}=this,{X:s,Y:i,Z:c}=bo(e),a=0n,f=Hi,l=0n,h=0n,d=0n,p=F(f*3n),x=F(r*s),E=F(n*i),w=F(o*c),H=F(r+n),L=F(s+i);H=F(H*L),L=F(x+E),H=F(H-L),L=F(r+o);let g=F(s+c);return L=F(L*g),g=F(x+w),L=F(L-g),g=F(n+o),l=F(i+c),g=F(g*l),l=F(E+w),g=F(g-l),d=F(a*L),l=F(p*w),d=F(l+d),l=F(E-d),d=F(E+d),h=F(l*d),E=F(x+x),E=F(E+x),w=F(a*w),L=F(p*L),E=F(E+w),w=F(x-w),w=F(a*w),L=F(L+w),x=F(E*L),h=F(h+x),x=F(g*L),l=F(H*l),l=F(l-x),x=F(H*E),d=F(g*d),d=F(d+x),new De(l,h,d)}subtract(e){return this.add(bo(e).negate())}multiply(e,r=!0){if(!r&&e===0n)return Ut;if(go(e),e===1n)return this;if(this.equals(at))return Sf(e).p;let n=Ut,o=at;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(Ut))return{x:0n,y:0n};if(n===1n)return{x:e,y:r};let o=wo(n,Ot);return F(n*o)!==1n&&ne("inverse invalid"),{x:F(e*o),y:F(r*o)}}assertValidity(){let{x:e,y:r}=this.toAffine();return cn(e),cn(r),F(r*r)===Ri(e)?this:ne("bad point: not on curve")}toBytes(e=!0){let{x:r,y:n}=this.assertValidity().toAffine(),o=Yt(r);return e?Vt(sf(n),o):Vt(Ar(4),o,Yt(n))}toHex(e){return Ti(this.toBytes(e))}};u(De,"BASE"),u(De,"ZERO");var Ze=De,at=new Ze(tf,rf,1n),Ut=new Ze(0n,1n,0n);Ze.BASE=at;Ze.ZERO=Ut;var af=(t,e,r)=>at.multiply(e,!1).add(t.multiply(r,!1)).assertValidity(),dn=t=>an("0x"+(Ti(t)||"0")),fn=(t,e,r)=>dn(t.subarray(e,r)),ff=2n**256n,Yt=t=>_i(Li(Er(t,0n,ff),br)),Eo=t=>{let e=dn(Ie(t,me,"secret key"));return Er(e,1n,it,"invalid secret key: outside of range")},Ao=t=>t>it>>1n,Ci=(t,e=!0)=>at.multiply(Eo(t)).toBytes(e),uf=t=>{try{return!!Eo(t)}catch{return!1}},lf=(t,e)=>{let{publicKey:r,publicKeyUncompressed:n}=gr;try{let o=t.length;return e===!0&&o!==r||e===!1&&o!==n?!1:!!Ze.fromBytes(t)}catch{return!1}},Ai=t=>[0,1,2,3].includes(t)?t:ne("invalid recovery id"),Bo=t=>{t===df&&ne('Signature format "der" is not supported: switch to noble-curves'),t!=null&&t!==wr&&t!==un&&ne("Signature format must be one of: compact, recovered, der")},Fi=(t,e=wr)=>{Bo(e);let r=gr.signature+ +(e===un);t.length!==r&&ne(`Signature format "${e}" expects Uint8Array with length ${r}`)},mr=class t{constructor(e,r,n){u(this,"r");u(this,"s");u(this,"recovery");this.r=go(e),this.s=go(r),n!=null&&(this.recovery=Ai(n)),Object.freeze(this)}static fromBytes(e,r=wr){Fi(e,r);let n;r===un&&(n=e[0],e=e.subarray(1));let o=fn(e,0,me),s=fn(e,me,br);return new t(o,s,n)}addRecoveryBit(e){return new t(this.r,this.s,e)}hasHighS(){return Ao(this.s)}toBytes(e=wr){Bo(e);let{r,s:n,recovery:o}=this,s=Vt(Yt(r),Yt(n));return e===un?Vt(Ar(Ai(o)),s):s}},Di=t=>{t.length>8192&&ne("input is too large");let e=t.length*8-256,r=dn(t);return e>0?r>>an(e):r},Mi=t=>st(Di(Ie(t))),wr="compact",un="recovered",df="der",Bi="SHA-256",hn={hmacSha256Async:async(t,e)=>{let r=wi(),n="HMAC",o=await r.importKey("raw",t,{name:n,hash:{name:Bi}},!1,["sign"]);return ct(await r.sign(n,o,e))},hmacSha256:void 0,sha256Async:async t=>ct(await wi().digest(Bi,t)),sha256:void 0},Ni=(t,e,r)=>{let n=Ie(t,void 0,"message");return e.prehash?r?of("sha256Async",n):Oi("sha256",n):n},hf=ct(0),pf=Ar(0),xf=Ar(1),yf=1e3,bf="drbg: tried max amount of iterations",gf=(t,e)=>{let r=ct(me),n=ct(me),o=0,s=()=>{r.fill(1),n.fill(0)},i=(...l)=>Oi("hmacSha256",n,Vt(r,...l)),c=(l=hf)=>{n=i(pf,l),r=i(),l.length!==0&&(n=i(xf,l),r=i())},a=()=>(o++>=yf&&ne(bf),r=i(),r);s(),c(t);let f;for(;!(f=e(a()));)c();return s(),f};var mf=(t,e,r,n)=>{let{lowS:o,extraEntropy:s}=r,i=Yt,c=Mi(t),a=i(c),f=Eo(e),l=[i(f),a];if(s!=null&&s!==!1){let x=s===!0?Ii(me):s;l.push(Ie(x,void 0,"extraEntropy"))}let h=Vt(...l),d=c;return n(h,x=>{let E=Di(x);if(!(1n<=E&&E<it))return;let w=wo(E,it),H=at.multiply(E).toAffine(),L=st(H.x);if(L===0n)return;let g=st(w*st(d+L*f));if(g===0n)return;let m=(H.x===L?0:2)|Number(H.y&1n),U=g;return o&&Ao(g)&&(U=st(-g),m^=1),new mr(L,U,m).toBytes(r.format)})},wf=(t,e,r,n={})=>{let{lowS:o,format:s}=n;t instanceof mr&&ne("Signature must be in Uint8Array, use .toBytes()"),Fi(t,s),Ie(r,void 0,"publicKey");try{let{r:i,s:c}=mr.fromBytes(t,s),a=Mi(e),f=Ze.fromBytes(r);if(o&&Ao(c))return!1;let l=wo(c,it),h=st(a*l),d=st(i*l),p=af(f,h,d).toAffine();return st(p.x)===i}catch{return!1}},ji=t=>({lowS:t.lowS??!0,prehash:t.prehash??!0,format:t.format??wr,extraEntropy:t.extraEntropy??!1}),Pi=(t,e,r={})=>{r=ji(r),Bo(r.format);let n=Ni(t,r,!1);return mf(n,e,r,gf)};var $i=(t,e,r,n={})=>{n=ji(n);let o=Ni(e,n,!1);return wf(t,o,r,n)};var Ef=t=>{if(t=t===void 0?Ii(gr.seed):t,Ie(t),t.length<gr.seed||t.length>1024)return ne("expected 48-1024b",RangeError);let e=F(dn(t),it-1n);return Yt(e+1n)};var Gi=Object.freeze({isValidSecretKey:uf,isValidPublicKey:lf,randomSecretKey:Ef});var ln=8,Af=256,zi=Math.ceil(Af/ln)+1,mo=2**(ln-1),Bf=()=>{let t=[],e=at,r=e;for(let n=0;n<zi;n++){r=e,t.push(r);for(let o=1;o<mo;o++)r=r.add(e),t.push(r);e=r.double()}return t},Si,vi=(t,e)=>{let r=e.negate();return t?r:e},Sf=t=>{let e=Si||(Si=Bf()),r=Ut,n=at,o=2**ln,s=o,i=an(o-1),c=an(ln);for(let a=0;a<zi;a++){let f=Number(t&i);t>>=c,f>mo&&(f-=s,t+=1n);let l=a*mo,h=l,d=l+Math.abs(f)-1,p=a%2!==0,x=f<0;f===0?n=n.add(vi(p,e[h])):r=r.add(vi(x,e[d]))}return t!==0n&&ne("invalid wnaf"),{p:r,f:n}};y();y();function qi(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var So=t=>t?`"${t}" `:"";function vo(t,e=""){if(typeof t!="number")throw new TypeError(So(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(So(e)+"expected integer >= 0, got "+t);return t}function Br(t,e,r=""){if(qi(t)&&(e===void 0||t.length===e))return t;e!==void 0&&vo(e,"length");let n=qi(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=So(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function Vi(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(vo(t.outputLen),vo(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Wi=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)};function Xt(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function pn(t,e){Br(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Sr(...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 Ue(t,e){return t<<32-e|t>>>e}function kf(t,e,r="opts"){return Wi(t,"defaults"),e!==void 0&&Wi(e,r),Object.assign(t,e)}function Yi(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=kf({},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 Xi=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});var yn=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(Vi(e),Br(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),Sr(o)}update(e){return Xt(this),this.iHash.update(e),this}digestInto(e){Xt(this),pn(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c,canXOF:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=c,e.canXOF=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Zi=(()=>{let t=((e,r,n)=>new yn(e,r).update(n).digest());return t.create=(e,r)=>new yn(e,r),t})();y();y();y();var Hf=t=>t/2**32|0,Lf=t=>t>>>0;function Ji(t,e,r,n){let o=Hf(r),s=Lf(r);t.setUint32(e,n?s:o,n),t.setUint32(e+4,n?o:s,n)}function Qi(t,e,r){return t&e^~t&r}function ec(t,e,r){return t&e^t&r^e&r}var bn=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){Xt(this),Br(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length,i=!1;for(let c=0;c<s;){let a=Math.min(o-this.pos,s-c);if(a===o){let f=xn(e);for(;o<=s-c;c+=o)this.process(f,c);i=!0;continue}n.set(c===0&&a===s?e:e.subarray(c,c+a),this.pos),this.pos+=a,c+=a,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){Xt(this),pn(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)),Ji(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let c=e===r?n:xn(e),a=this.outputLen,f=a/4,l=this.get();if(a%4||f>l.length)throw new Error("invalid outputLen");for(let h=0;h<f;h++)c.setUint32(4*h,l[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()}},tc=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Tf=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),ko=class extends bn{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:c,G:a,H:f}=this;return[r,n,o,s,i,c,a,f]}set(r,n,o,s,i,c,a,f){this.A=r|0,this.B=n|0,this.C=o|0,this.D=s|0,this.E=i|0,this.F=c|0,this.G=a|0,this.H=f|0}_cloneInto(r){return(r||(r=new this.constructor)).set(...this.get()),this._cloneIntoMeta(r)}process(r,n){for(let d=0;d<16;d++,n+=4)ft[d]=r.getUint32(n,!1);for(let d=16;d<64;d++){let p=ft[d-15],x=ft[d-2],E=Ue(p,7)^Ue(p,18)^p>>>3,w=Ue(x,17)^Ue(x,19)^x>>>10;ft[d]=w+ft[d-7]+E+ft[d-16]|0}let{A:o,B:s,C:i,D:c,E:a,F:f,G:l,H:h}=this;for(let d=0;d<64;d++){let p=Ue(a,6)^Ue(a,11)^Ue(a,25),x=h+p+Qi(a,f,l)+Tf[d]+ft[d]|0,w=(Ue(o,2)^Ue(o,13)^Ue(o,22))+ec(o,s,i)|0;h=l,l=f,f=a,a=c+x|0,c=i,i=s,s=o,o=x+w|0}o=o+this.A|0,s=s+this.B|0,i=i+this.C|0,c=c+this.D|0,a=a+this.E|0,f=f+this.F|0,l=l+this.G|0,h=h+this.H|0,this.set(o,s,i,c,a,f,l,h)}roundClean(){Sr(ft)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Sr(this.buffer)}},Ho=class extends ko{constructor(){super(32,tc)}};var ut=Yi(()=>new Ho,Xi(1));y();function Ir(t){return Array.from(t).map(e=>e.toString(16).padStart(2,"0")).join("")}function Qt(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 vn(t,e){if(e==="sha256"){let r=await Promise.resolve().then(()=>(Sn(),Bn));return new Uint8Array(r.createHash("sha256").update(t).digest())}else if(e==="sha512"){let r=await Promise.resolve().then(()=>(Sn(),Bn));return new Uint8Array(r.createHash("sha512").update(t).digest())}else if(e==="sha3-256"){let r=await Promise.resolve().then(()=>(Sn(),Bn));return new Uint8Array(r.createHash("sha3-256").update(t).digest())}throw new Error(`Unsupported hash algorithm: ${e}`)}y();y();y();y();y();y();var Yf=t=>t/2**32|0,Xf=t=>t>>>0;function _c(t,e,r,n){let o=Yf(r),s=Xf(r);t.setUint32(e,n?s:o,n),t.setUint32(e+4,n?o:s,n)}tr();function Dc(t,e,r){return t&e^~t&r}function Mc(t,e,r){return t&e^t&r^e&r}var In=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=Tn(this.buffer)}update(e){er(this),je(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length,i=!1;for(let c=0;c<s;){let a=Math.min(o-this.pos,s-c);if(a===o){let f=Tn(e);for(;o<=s-c;c+=o)this.process(f,c);i=!0;continue}n.set(c===0&&a===s?e:e.subarray(c,c+a),this.pos),this.pos+=a,c+=a,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){er(this),Ln(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)),_c(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let c=e===r?n:Tn(e),a=this.outputLen,f=a/4,l=this.get();if(a%4||f>l.length)throw new Error("invalid outputLen");for(let h=0;h<f;h++)c.setUint32(4*h,l[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()}},Nc=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);tr();var Qf=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]),pt=new Uint32Array(64),No=class extends In{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:c,G:a,H:f}=this;return[r,n,o,s,i,c,a,f]}set(r,n,o,s,i,c,a,f){this.A=r|0,this.B=n|0,this.C=o|0,this.D=s|0,this.E=i|0,this.F=c|0,this.G=a|0,this.H=f|0}_cloneInto(r){return(r||(r=new this.constructor)).set(...this.get()),this._cloneIntoMeta(r)}process(r,n){for(let d=0;d<16;d++,n+=4)pt[d]=r.getUint32(n,!1);for(let d=16;d<64;d++){let p=pt[d-15],x=pt[d-2],E=Re(p,7)^Re(p,18)^p>>>3,w=Re(x,17)^Re(x,19)^x>>>10;pt[d]=w+pt[d-7]+E+pt[d-16]|0}let{A:o,B:s,C:i,D:c,E:a,F:f,G:l,H:h}=this;for(let d=0;d<64;d++){let p=Re(a,6)^Re(a,11)^Re(a,25),x=h+p+Dc(a,f,l)+Qf[d]+pt[d]|0,w=(Re(o,2)^Re(o,13)^Re(o,22))+Mc(o,s,i)|0;h=l,l=f,f=a,a=c+x|0,c=i,i=s,s=o,o=x+w|0}o=o+this.A|0,s=s+this.B|0,i=i+this.C|0,c=c+this.D|0,a=a+this.E|0,f=f+this.F|0,l=l+this.G|0,h=h+this.H|0,this.set(o,s,i,c,a,f,l,h)}roundClean(){Ur(pt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ur(this.buffer)}},jo=class extends No{constructor(){super(32,Nc)}};var jc=Kc(()=>new jo,Fc(1));y();Ft();Nn();var es=BigInt(0),Cr=BigInt(1),lu=BigInt(4),Jo=16,oa=128,du=5,sa=2**31;function cr(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Ct(e.fromAffine,"Point.fromAffine"),Ct(e.fromBytes,"Point.fromBytes"),Ct(e.fromHex,"Point.fromHex"),xt(e.BASE,"Point.BASE"),xt(e.ZERO,"Point.ZERO"),sr(e.Fp),sr(e.Fn)}function ca(t,e){cr(t),aa(e,t);let r=Zo(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function hu(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 pu(t,e){let r=t*(4*e+128);if(r>sa)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+sa/2**20+" MiB")}function ts(t,e){if(t!==void 0){Ct(t,"randomBytes");try{let r=t(e);if(!rr(r)||r.length!==e)return}catch{return}return t}}function aa(t,e){Or(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function xu(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):yt(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var fa=new WeakMap;function Qo(t){return fa.get(t)||1}function yu(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 bu(t,e){let r=2**e,n=r/2,o=BigInt(r-1),s=[];for(;t>es;){let i=0;t&Cr&&(i=Number(t&o),i>=n&&(i-=r),t-=BigInt(i)),s.push(i),t>>=Cr}return s}function gu(t,e,r){let n=2**e,o=n/2,s=BigInt(n-1),i=BigInt(e),c=[];for(let a=0;a<r;a++){let f=Number(t&s);t>>=i,f>o&&(f-=n,t+=Cr),c.push(f)}if(t!==es)throw new Error("invalid wnaf");return c}function mu(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 c=r[i][s];if(c){let a=e[i][Math.abs(c)-1>>1];o=o.add(c<0?a.negate():a)}}}return o}var jn=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");cr(e),this.randomBytes=ts(r,Jo),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=[],c=e;for(let a=0;a<o;a++){let f=c;for(let l=0;l<s;l++)i.push(f),f=f.add(c);c=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),c=gu(r,n,o),a=this.ZERO,f=this.BASE;for(let l=0;l<o;l++){let h=c[l],d=l*i,p=Math.abs(h)-1,x=s[d];for(let w=1;w<i;w++)x=w===p?s[d+w]:x;let E=x.negate();h===0?f=f.add(s[d]):a=a.add(h<0?E:x)}return{p:a,f}}getWnafPrecomputes(e,r,n,o){let s=this.wnafPrecomputes.get(r),i=s?.find(c=>c.W===e&&c.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),!qo(r,Cr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,o){let s=Qo(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+oa,s=this.randomBytes(Jo);if(!rr(s)||s.length!==Jo)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+Pe(s)*this.Point.Fn.ORDER;return this.runCT(e,i,o,n)}fixedWindowCT(e,r,n){let o=du,s=1<<o,i=Kr(o),c=new Array(s);c[0]=this.ZERO;for(let l=1;l<s;l++)c[l]=c[l-1].add(e);let a=Math.ceil(n/o),f=this.ZERO;for(let l=a-1;l>=0;l--){if(l!==a-1)for(let p=0;p<o;p++)f=f.double();let h=Number(r>>BigInt(l*o)&i),d=c[0];for(let p=1;p<s;p++)d=p===h?c[p]:d;f=f.add(d)}return{p:f,f}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===Cr?!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),!yt(r))throw new Error("invalid scalar");let o=Qo(e);if(o===1||r>=this.Point.Fn.ORDER)return Pn(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),hu(r,this.bits);let n=Math.ceil((this.bits+oa)/r)+1;pu(n*2**(r-1),this.Point.Fp.BYTES),fa.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Qo(e)!==1}};function Pn(t,e,r,n=!1){if(cr(t),aa(e,t),_e(n,"allowOversized"),xu(r,t.Fn,n?t.Fn.ORDER**lu:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(i=>yu(i,4)),s=r.map(i=>bu(i,4));return mu(t.ZERO,o,s)}function ia(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return sr(e),e}else return ir(t,{isLE:r})}function ua(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 a of["p","n","h"]){let f=e[a];if(!(yt(f)&&f!==es))throw new Error(`CURVE.${a} must be positive bigint`)}let o=ia(e.p,r.Fp,n),s=ia(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 la(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}Nn();y();y();tr();var $n=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(Hn(e),je(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),Ur(o)}update(e){return er(this),this.iHash.update(e),this}digestInto(e){er(this),Ln(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:c,canXOF:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=c,e.canXOF=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ya=(()=>{let t=((e,r,n)=>new $n(e,r).update(n).digest());return t.create=(e,r)=>new $n(e,r),t})();tr();Ft();y();Ft();var wu=BigInt(0),os=class extends Error{constructor(e=""){super(e)}},tt={Err:os,_tlv:{encode:(t,e)=>{let{Err:r}=tt;if(nr(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if($c(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}=tt;e=pe(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 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 f=e.subarray(n,n+a);if(f.length!==a)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let l of f)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}=tt;if(Kn(t),t<wu)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}=tt;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 Pe(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=tt,o=pe(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:f,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(f)}},hexFromSig(t){let{_tlv:e,_int:r}=tt;$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)}},ss=(Object.freeze(tt._tlv),Object.freeze(tt._int),Object.freeze(tt));Nn();var ba=(t,e)=>(t+(t>=0?e:-e)/ga)/e;function Eu(t,e,r){Wo("scalar",t,rt,r);let[[n,o],[s,i]]=e,c=ba(i*t,r),a=ba(-o*t,r),f=t-c*n-a*s,l=-c*o-a*i,h=f<rt,d=l<rt;h&&(f=-f),d&&(l=-l);let p=Kr(Math.ceil(or(r)/2))+Dt;if(f<rt||f>=p||l<rt||l>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:h,k1:f,k2neg:d,k2:l}}function as(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function is(t,e){$e(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return _e(r.lowS,"lowS"),_e(r.prehash,"prehash"),r.format!==void 0&&as(r.format),r}var rt=BigInt(0),Dt=BigInt(1),ga=BigInt(2),cs=BigInt(3),Au=BigInt(4);function ma(t,e={}){let r=ua("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:c}=s;$e(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:a,allowInfinityPoint:f}=e,l=e.randomBytes===void 0?Rn:e.randomBytes;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 h=Ea(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function p(Y,k,O){if(f&&k.is0())return Uint8Array.of(0);let{x:N,y:_}=k.toAffine(),A=n.toBytes(N);if(_e(O,"isCompressed"),O){d();let T=!n.isOdd(_);return et(wa(T),A)}else return et(Uint8Array.of(4),A,n.toBytes(_))}function x(Y){pe(Y,void 0,"Point");let{publicKey:k,publicKeyUncompressed:O}=h,N=Y.length,_=Y[0],A=Y.subarray(1);if(f&&N===1&&_===0)return{x:n.ZERO,y:n.ZERO};if(N===k&&(_===2||_===3)){let T=n.fromBytes(A);if(!n.isValid(T))throw new Error("bad point: is not on curve, wrong x");let M=g(T),j;try{j=n.sqrt(M)}catch(B){let S=B instanceof Error?": "+B.message:"";throw new Error("bad point: is not on curve, sqrt error"+S)}d();let $=n.isOdd(j);return(_&1)===1!==$&&(j=n.neg(j)),{x:T,y:j}}else if(N===O&&_===4){let T=n.BYTES,M=n.fromBytes(A.subarray(0,T)),j=n.fromBytes(A.subarray(T,T*2));if(!m(M,j))throw new Error("bad point: is not on curve");return{x:M,y:j}}else throw new Error(`bad point: got length ${N}, expected compressed=${k} or uncompressed=${O}`)}let E=e.toBytes===void 0?p:e.toBytes,w=e.fromBytes===void 0?x:e.fromBytes,H=n.mul(s.b,cs),L=n.is0(s.a)?Y=>n.ZERO:Y=>n.mul(s.a,Y);function g(Y){let k=n.sqr(Y),O=n.mul(k,Y);return n.add(n.add(O,n.mul(Y,s.a)),s.b)}function m(Y,k){let O=n.sqr(k),N=g(Y);return n.eql(O,N)}if(!m(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let U=n.mul(n.pow(s.a,cs),Au),P=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(U,P)))throw new Error("bad curve params: a or b");function X(Y,k,O=!1){if(!n.isValid(k)||O&&n.is0(k))throw new Error(`bad point coordinate ${Y}`);return k}function q(Y){if(!(Y instanceof Z))throw new Error("Weierstrass Point expected")}function z(Y){if(!a||!a.basises)throw new Error("no endo");return Eu(Y,a.basises,o.ORDER)}function D(Y,k,O,N){if(!o.isValid(N))throw new RangeError("invalid scalar: out of range");if(a){let{k1neg:_,k1:A,k2neg:T,k2:M}=z(N),j=new Z(n.mul(O.X,a.beta),O.Y,O.Z);Y.push(_?O.negate():O,T?j.negate():j),k.push(A,M)}else Y.push(O),k.push(N)}let J=new WeakSet,V=class V{constructor(k,O,N){u(this,"X");u(this,"Y");u(this,"Z");this.X=X("x",k),this.Y=X("y",O,!0),this.Z=X("z",N),Object.freeze(this)}static CURVE(){return s}static fromAffine(k){let{x:O,y:N}=k||{};if(!k||!n.isValid(O)||!n.isValid(N))throw new Error("invalid affine point");if(k instanceof V)throw new Error("projective point not allowed");return n.is0(O)&&n.is0(N)?V.ZERO:new V(O,N,n.ONE)}static fromBytes(k){let O=V.fromAffine(w(pe(k,void 0,"point")));return O.assertValidity(),O}static fromHex(k){return V.fromBytes(On(k))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(k=6,O=!0){return fe.setWindowSize(this,k),O||this.multiply(cs),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(J.has(k))return;let{x:O,y:N}=k.toAffine();if(!n.isValid(O)||!n.isValid(N))throw new Error("bad point: x or y not field elements");if(!m(O,N))throw new Error("bad point: equation left != right");if(!k.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");J.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){q(k);let{X:O,Y:N,Z:_}=this,{X:A,Y:T,Z:M}=k,j=n.eql(n.mul(O,M),n.mul(A,_)),$=n.eql(n.mul(N,M),n.mul(T,_));return j&&$}negate(){return new V(this.X,n.neg(this.Y),this.Z)}double(){let{X:k,Y:O,Z:N}=this,_=n.ZERO,A=n.ZERO,T=n.ZERO,M=n.mul(k,k),j=n.mul(O,O),$=n.mul(N,N),b=n.mul(k,O);return b=n.add(b,b),T=n.mul(k,N),T=n.add(T,T),_=L(T),A=n.mul(H,$),A=n.add(_,A),_=n.sub(j,A),A=n.add(j,A),A=n.mul(_,A),_=n.mul(b,_),T=n.mul(H,T),$=L($),b=n.sub(M,$),b=L(b),b=n.add(b,T),T=n.add(M,M),M=n.add(T,M),M=n.add(M,$),M=n.mul(M,b),A=n.add(A,M),$=n.mul(O,N),$=n.add($,$),M=n.mul($,b),_=n.sub(_,M),T=n.mul($,j),T=n.add(T,T),T=n.add(T,T),new V(_,A,T)}add(k){q(k);let{X:O,Y:N,Z:_}=this,{X:A,Y:T,Z:M}=k,j=n.ZERO,$=n.ZERO,b=n.ZERO,B=n.mul(O,A),S=n.mul(N,T),v=n.mul(_,M),R=n.add(O,N),I=n.add(A,T);R=n.mul(R,I),I=n.add(B,S),R=n.sub(R,I),I=n.add(O,_);let G=n.add(A,M);return I=n.mul(I,G),G=n.add(B,v),I=n.sub(I,G),G=n.add(N,_),j=n.add(T,M),G=n.mul(G,j),j=n.add(S,v),G=n.sub(G,j),b=L(I),j=n.mul(H,v),b=n.add(j,b),j=n.sub(S,b),b=n.add(S,b),$=n.mul(j,b),S=n.add(B,B),S=n.add(S,B),v=L(v),I=n.mul(H,I),S=n.add(S,v),v=n.sub(B,v),v=L(v),I=n.add(I,v),B=n.mul(S,I),$=n.add($,B),B=n.mul(G,I),j=n.mul(R,j),j=n.sub(j,B),B=n.mul(R,S),b=n.mul(G,b),b=n.add(b,B),new V(j,$,b)}subtract(k){return q(k),this.add(k.negate())}is0(){return this.equals(V.ZERO)}multiply(k){if(!o.isValidNot0(k))throw new RangeError("invalid scalar: out of range");let{p:O,f:N}=fe.mulSecret(this,k,i,ae);return ae([O,N])[0]}multiplyUnsafe(k){let O=this,N=k;if(!o.isValid(N))throw new RangeError("invalid scalar: out of range");if(N===rt||O.is0())return V.ZERO;if(N===Dt)return O;if(fe.hasWindowSize(this))return fe.mulUnsafe(O,N,ae);let _=[],A=[];return D(_,A,O,N),Pn(V,_,A)}mulAddUnsafe(k,O,N){q(O);let _=[],A=[];return D(_,A,this,k),D(_,A,O,N),Pn(V,_,A)}toAffine(k){let O=this,N=k;if(N!=null&&!n.isValid(N))throw new RangeError('"invertedZ" expected valid field element');let{X:_,Y:A,Z:T}=O;if(n.eql(T,n.ONE))return{x:_,y:A};let M=O.is0();N==null&&(N=M?n.ONE:n.inv(T));let j=n.mul(_,N),$=n.mul(A,N),b=n.mul(T,N);if(M)return{x:n.ZERO,y:n.ZERO};if(!n.eql(b,n.ONE))throw new Error("invZ was invalid");return{x:j,y:$}}isTorsionFree(){let{isTorsionFree:k}=e;return i===Dt?!0:k?k(V,this):fe.mulUnsafe(this,c).is0()}clearCofactor(){let{clearCofactor:k}=e;return i===Dt?this:k?k(V,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Dt?this.is0():this.clearCofactor().is0()}toBytes(k=!0){return _e(k,"isCompressed"),this.assertValidity(),E(V,this,k)}toHex(k=!0){return $o(this.toBytes(k))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}};u(V,"BASE",new V(s.Gx,s.Gy,n.ONE)),u(V,"ZERO",new V(n.ZERO,n.ONE,n.ZERO)),u(V,"Fp",n),u(V,"Fn",o);let Z=V,ae=Y=>ca(Z,Y),fe=new jn(Z,l);return fe.bits>=6&&Z.BASE.precompute(6),Object.freeze(Z.prototype),Object.freeze(Z),Z}function wa(t){return Uint8Array.of(t?2:3)}function Ea(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Bu(t,e={}){cr(t);let{Fn:r}=t,n=e.randomBytes===void 0?Rn:e.randomBytes,o=Object.assign(Ea(t.Fp,r),{seed:Math.max(Dn(r.ORDER),16)});function s(p){try{let x=r.fromBytes(p);return r.isValidNot0(x)}catch{return!1}}function i(p,x){let{publicKey:E,publicKeyUncompressed:w}=o;try{let H=p.length;return x===!0&&H!==E||x===!1&&H!==w?!1:!!t.fromBytes(p)}catch{return!1}}function c(p){return p=p===void 0?n(o.seed):p,Mn(pe(p,o.seed,"seed"),r.ORDER)}function a(p,x=!0){return t.BASE.multiply(r.fromBytes(p)).toBytes(x)}function f(p){let{secretKey:x,publicKey:E,publicKeyUncompressed:w}=o,H=r._lengths;if(!rr(p))return;let L=pe(p,void 0,"key").length,g=L===E||L===w,m=L===x||!!H?.includes(L);if(!(g&&m))return g}function l(p,x,E=!0){if(f(p)===!0)throw new Error("first arg must be private key");if(f(x)===!1)throw new Error("second arg must be public key");let w=r.fromBytes(p);return t.fromBytes(x).multiply(w).toBytes(E)}let h={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c},d=la(c,a);return Object.freeze(h),Object.freeze(o),Object.freeze({getPublicKey:a,getSharedSecret:l,keygen:d,Point:t,utils:h,lengths:o})}function Aa(t,e,r={}){cr(t);let n=e;Hn(n),$e(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?Rn:o.randomBytes,i=o.hmac===void 0?(_,A)=>ya(n,_,A):o.hmac,{Fp:c,Fn:a}=t,{ORDER:f,BITS:l}=a,h=Dn(f),d=ts(s,h),{keygen:p,getPublicKey:x,getSharedSecret:E,utils:w,lengths:H}=Bu(t,o),L={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},g=f*ga+Dt<c.ORDER;function m(_){let A=f>>Dt;return _>A}function U(_,A){if(!a.isValidNot0(A))throw new Error(`invalid signature ${_}: out of range 1..Point.Fn.ORDER`);return A}function P(){if(!c.isOdd)throw new Error("Field doesn't support isOdd")}function X(_,A,T){return P(),(_===T?0:2)|Number(c.isOdd(A))}function q(){if(g)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function z(_,A){as(A);let T=H.signature,M=A==="compact"?T:A==="recovered"?T+1:void 0;return pe(_,M)}class D{constructor(A,T,M){u(this,"r");u(this,"s");u(this,"recovery");if(this.r=U("r",A),this.s=U("s",T),M!=null){if(q(),![0,1,2,3].includes(M))throw new Error("invalid recovery id");this.recovery=M}Object.freeze(this)}static fromBytes(A,T=L.format){z(A,T);let M;if(T==="der"){let{r:B,s:S}=ss.toSig(pe(A));return new D(B,S)}T==="recovered"&&(M=A[0],T="compact",A=A.subarray(1));let j=H.signature/2,$=A.subarray(0,j),b=A.subarray(j,j*2);return new D(a.fromBytes($),a.fromBytes(b),M)}static fromHex(A,T){return this.fromBytes(On(A),T)}assertRecovery(){let{recovery:A}=this;if(A==null)throw new Error("invalid recovery id: must be present");return A}addRecoveryBit(A){return new D(this.r,this.s,A)}recoverPublicKey(A){let{r:T,s:M}=this,j=this.assertRecovery(),$=j===2||j===3?T+f:T;if(!c.isValid($))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let b=c.toBytes($),B=t.fromBytes(et(wa((j&1)===0),b)),S=a.inv($),v=Z(pe(A,void 0,"msgHash")),R=a.create(-v*S),I=a.create(M*S),G=t.BASE.mulAddUnsafe(R,B,I);if(G.is0())throw new Error("invalid recovery: point at infinify");return G.assertValidity(),G}hasHighS(){return m(this.s)}toBytes(A=L.format){if(as(A),A==="der")return On(ss.hexFromSig(this));let{r:T,s:M}=this,j=a.toBytes(T),$=a.toBytes(M);return A==="recovered"?(q(),et(Uint8Array.of(this.assertRecovery()),j,$)):et(j,$)}toHex(A){return $o(this.toBytes(A))}}Object.freeze(D.prototype),Object.freeze(D);let J=o.bits2int===void 0?function(A){if(A.length>8192)throw new Error("input is too large");let T=Pe(A),M=A.length*8-l;return M>0?T>>BigInt(M):T}:o.bits2int,Z=o.bits2int_modN===void 0?function(A){return a.create(J(A))}:o.bits2int_modN,ae=Kr(l);function fe(_){return Wo("num < 2^"+l,_,rt,ae),a.toBytes(_)}function V(_,A){return pe(_,void 0,"message"),A?pe(n(_),void 0,"prehashed message"):_}function Y(_,A,T){let{lowS:M,prehash:j,extraEntropy:$}=is(T,L);_=V(_,j);let b=Z(_),B=a.fromBytes(A);if(!a.isValidNot0(B))throw new Error("invalid private key");let S=[fe(B),fe(b)];if($!=null&&$!==!1){let G=$===!0?s(H.secretKey):$;S.push(pe(G,void 0,"extraEntropy"))}let v=et(...S),R=b;function I(G){let te=J(G);if(!a.isValidNot0(te))return;let le=t.BASE.multiply(te).toAffine(),oe=a.create(le.x);if(oe===rt)return;let re;if(d!==void 0){let ue=Pe(Mn(d(h),f)),Be=a.inv(a.mul(ue,te)),Fe=a.mul(ue,R),Ye=a.mul(ue,B);re=a.create(Be*a.create(Fe+Ye*oe))}else{let ue=ea(te,f);re=a.create(ue*a.create(R+oe*B))}if(re===rt)return;let de=X(le.x,le.y,oe),Ae=re;return M&&m(re)&&(Ae=a.neg(re),de^=1),new D(oe,Ae,g?void 0:de)}return{seed:v,k2sig:I}}function k(_,A,T={}){let{seed:M,k2sig:j}=Y(_,A,T);return zc(n.outputLen,a.BYTES,i)(M,j).toBytes(T.format)}function O(_,A,T,M={}){let{lowS:j,prehash:$,format:b}=is(M,L);if(T=pe(T,void 0,"publicKey"),A=V(A,$),!rr(_)){let B=_ instanceof D?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+B)}z(_,b);try{let B=D.fromBytes(_,b),S=t.fromBytes(T);if(j&&B.hasHighS())return!1;let{r:v,s:R}=B,I=Z(A),G=a.inv(R),te=a.create(I*G),le=a.create(v*G),oe=t.BASE.mulAddUnsafe(te,S,le);if(oe.is0())return!1;let re=oe.toAffine();return!(a.create(re.x)!==v||b==="recovered"&&B.recovery!==X(re.x,re.y,v))}catch{return!1}}function N(_,A,T={}){let{prehash:M}=is(T,L);return A=V(A,M),D.fromBytes(_,"recovered").recoverPublicKey(A).toBytes()}return Object.freeze({keygen:p,getPublicKey:x,getSharedSecret:E,utils:w,lengths:H,Point:t,sign:k,verify:O,recoverPublicKey:N,Signature:D,hash:n})}var us={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Su={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ba=BigInt(2);function vu(t){let e=us.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),f=t*t*t%e,l=f*f*t%e,h=ke(l,r,e)*l%e,d=ke(h,r,e)*l%e,p=ke(d,Ba,e)*f%e,x=ke(p,o,e)*p%e,E=ke(x,s,e)*x%e,w=ke(E,c,e)*E%e,H=ke(w,a,e)*w%e,L=ke(H,c,e)*E%e,g=ke(L,r,e)*l%e,m=ke(g,i,e)*x%e,U=ke(m,n,e)*f%e,P=ke(U,Ba,e);if(!fs.eql(fs.sqr(P),t))throw new Error("Cannot find square root");return P}var fs=ir(us.p,{sqrt:vu}),ku=ma(us,{Fp:fs,endo:Su}),ar=Aa(ku,jc);y();y();function Sa(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var ls=t=>t?`"${t}" `:"";function ds(t,e=""){if(typeof t!="number")throw new TypeError(ls(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(ls(e)+"expected integer >= 0, got "+t);return t}function He(t,e,r=""){if(Sa(t)&&(e===void 0||t.length===e))return t;e!==void 0&&ds(e,"length");let n=Sa(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=ls(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function ka(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(ds(t.outputLen),ds(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var va=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)};function fr(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){He(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Ge(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function gt(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];He(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 Hu(t,e,r="opts"){return va(t,"defaults"),e!==void 0&&va(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=Hu({},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 hs=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});var zn=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(ka(e),He(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Ge(o)}update(e){return fr(this),this.iHash.update(e),this}digestInto(e){fr(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:c,canXOF:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=c,e.canXOF=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ps=(()=>{let t=((e,r,n)=>new zn(e,r).update(n).digest());return t.create=(e,r)=>new zn(e,r),t})();y();y();y();var qn=BigInt(4294967295),Ha=BigInt(32);function Lu(t,e=!1){return e?{h:Number(t&qn),l:Number(t>>Ha&qn)}:{h:Number(t>>Ha&qn)|0,l:Number(t&qn)|0}}function La(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}=Lu(t[s],e);[n[s],o[s]]=[i,c]}return[n,o]}var Tu=t=>t/2**32|0,_u=t=>t>>>0;function Ta(t,e,r,n){let o=Tu(r),s=_u(r);t.setUint32(e,n?s:o,n),t.setUint32(e+4,n?o:s,n)}var xs=(t,e,r)=>t>>>r,ys=(t,e,r)=>t<<32-r|e>>>r,Mt=(t,e,r)=>t>>>r|e<<32-r,Nt=(t,e,r)=>t<<32-r|e>>>r,jr=(t,e,r)=>t<<64-r|e>>>r-32,Pr=(t,e,r)=>t>>>r-32|e<<64-r;function ze(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var _a=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Ia=(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),Oa=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Ra=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Ka=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;function bs(t,e,r){return t&e^~t&r}function gs(t,e,r){return t&e^t&r^e&r}var jt=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=gt(this.buffer)}update(e){fr(this),He(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length,i=!1;for(let c=0;c<s;){let a=Math.min(o-this.pos,s-c);if(a===o){let f=gt(e);for(;o<=s-c;c+=o)this.process(f,c);i=!0;continue}n.set(c===0&&a===s?e:e.subarray(c,c+a),this.pos),this.pos+=a,c+=a,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){fr(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)),Ta(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let c=e===r?n:gt(e),a=this.outputLen,f=a/4,l=this.get();if(a%4||f>l.length)throw new Error("invalid outputLen");for(let h=0;h<f;h++)c.setUint32(4*h,l[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()}},Ca=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Fa=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Uu=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Ma=Uint8Array.from(new Array(16).fill(0).map((t,e)=>e)),Ou=Ma.map(t=>(9*t+5)%16),Na=(()=>{let r=[[Ma],[Ou]];for(let n=0;n<4;n++)for(let o of r)o.push(o[n].map(s=>Uu[s]));return r})(),ja=Na[0],Pa=Na[1],$a=[[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)),Ru=ja.map((t,e)=>t.map(r=>$a[e][r])),Ku=Pa.map((t,e)=>t.map(r=>$a[e][r])),Cu=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),Fu=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Da(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 Wn=new Uint32Array(16),ms=class extends jt{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 x=0;x<16;x++,n+=4)Wn[x]=r.getUint32(n,!0);let o=this.h0|0,s=o,i=this.h1|0,c=i,a=this.h2|0,f=a,l=this.h3|0,h=l,d=this.h4|0,p=d;for(let x=0;x<5;x++){let E=4-x,w=Cu[x],H=Fu[x],L=ja[x],g=Pa[x],m=Ru[x],U=Ku[x];for(let P=0;P<16;P++){let X=Dr(o+Da(x,i,a,l)+Wn[L[P]]+w,m[P])+d|0;o=d,d=l,l=Dr(a,10)|0,a=i,i=X}for(let P=0;P<16;P++){let X=Dr(s+Da(E,c,f,h)+Wn[g[P]]+H,U[P])+p|0;s=p,p=h,h=Dr(f,10)|0,f=c,c=X}}this.set(this.h1+a+h|0,this.h2+l+p|0,this.h3+d+s|0,this.h4+o+c|0,this.h0+i+f|0)}roundClean(){Ge(Wn)}destroy(){this.destroyed=!0,Ge(this.buffer),this.set(0,0,0,0,0)}},Ga=Nr(()=>new ms);y();var Du=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),ws=class extends jt{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:c,G:a,H:f}=this;return[r,n,o,s,i,c,a,f]}set(r,n,o,s,i,c,a,f){this.A=r|0,this.B=n|0,this.C=o|0,this.D=s|0,this.E=i|0,this.F=c|0,this.G=a|0,this.H=f|0}_cloneInto(r){return(r||(r=new this.constructor)).set(...this.get()),this._cloneIntoMeta(r)}process(r,n){for(let d=0;d<16;d++,n+=4)mt[d]=r.getUint32(n,!1);for(let d=16;d<64;d++){let p=mt[d-15],x=mt[d-2],E=Ke(p,7)^Ke(p,18)^p>>>3,w=Ke(x,17)^Ke(x,19)^x>>>10;mt[d]=w+mt[d-7]+E+mt[d-16]|0}let{A:o,B:s,C:i,D:c,E:a,F:f,G:l,H:h}=this;for(let d=0;d<64;d++){let p=Ke(a,6)^Ke(a,11)^Ke(a,25),x=h+p+bs(a,f,l)+Du[d]+mt[d]|0,w=(Ke(o,2)^Ke(o,13)^Ke(o,22))+gs(o,s,i)|0;h=l,l=f,f=a,a=c+x|0,c=i,i=s,s=o,o=x+w|0}o=o+this.A|0,s=s+this.B|0,i=i+this.C|0,c=c+this.D|0,a=a+this.E|0,f=f+this.F|0,l=l+this.G|0,h=h+this.H|0,this.set(o,s,i,c,a,f,l,h)}roundClean(){Ge(mt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ge(this.buffer)}},Es=class extends ws{constructor(){super(32,Ca)}};var za=La(["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))),Mu=za[0],Nu=za[1],wt=new Uint32Array(80),Et=new Uint32Array(80),As=class extends jt{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:c,Dh:a,Dl:f,Eh:l,El:h,Fh:d,Fl:p,Gh:x,Gl:E,Hh:w,Hl:H}=this;return[r,n,o,s,i,c,a,f,l,h,d,p,x,E,w,H]}set(r,n,o,s,i,c,a,f,l,h,d,p,x,E,w,H){this.Ah=r|0,this.Al=n|0,this.Bh=o|0,this.Bl=s|0,this.Ch=i|0,this.Cl=c|0,this.Dh=a|0,this.Dl=f|0,this.Eh=l|0,this.El=h|0,this.Fh=d|0,this.Fl=p|0,this.Gh=x|0,this.Gl=E|0,this.Hh=w|0,this.Hl=H|0}_cloneInto(r){return(r||(r=new this.constructor)).set(...this.get()),this._cloneIntoMeta(r)}process(r,n){for(let m=0;m<16;m++,n+=4)wt[m]=r.getUint32(n),Et[m]=r.getUint32(n+=4);for(let m=16;m<80;m++){let U=wt[m-15]|0,P=Et[m-15]|0,X=Mt(U,P,1)^Mt(U,P,8)^xs(U,P,7),q=Nt(U,P,1)^Nt(U,P,8)^ys(U,P,7),z=wt[m-2]|0,D=Et[m-2]|0,J=Mt(z,D,19)^jr(z,D,61)^xs(z,D,6),Z=Nt(z,D,19)^Pr(z,D,61)^ys(z,D,6),ae=Ua(q,Z,Et[m-7],Et[m-16]),fe=Oa(ae,X,J,wt[m-7],wt[m-16]);wt[m]=fe|0,Et[m]=ae|0}let{Ah:o,Al:s,Bh:i,Bl:c,Ch:a,Cl:f,Dh:l,Dl:h,Eh:d,El:p,Fh:x,Fl:E,Gh:w,Gl:H,Hh:L,Hl:g}=this;for(let m=0;m<80;m++){let U=Mt(d,p,14)^Mt(d,p,18)^jr(d,p,41),P=Nt(d,p,14)^Nt(d,p,18)^Pr(d,p,41),X=d&x^~d&w,q=p&E^~p&H,z=Ra(g,P,q,Nu[m],Et[m]),D=Ka(z,L,U,X,Mu[m],wt[m]),J=z|0,Z=Mt(o,s,28)^jr(o,s,34)^jr(o,s,39),ae=Nt(o,s,28)^Pr(o,s,34)^Pr(o,s,39),fe=o&i^o&a^i&a,V=s&c^s&f^c&f;L=w|0,g=H|0,w=x|0,H=E|0,x=d|0,E=p|0,{h:d,l:p}=ze(l|0,h|0,D|0,J|0),l=a|0,h=f|0,a=i|0,f=c|0,i=o|0,c=s|0;let Y=_a(J,ae,V);o=Ia(Y,D,Z,fe),s=Y|0}({h:o,l:s}=ze(this.Ah|0,this.Al|0,o|0,s|0)),{h:i,l:c}=ze(this.Bh|0,this.Bl|0,i|0,c|0),{h:a,l:f}=ze(this.Ch|0,this.Cl|0,a|0,f|0),{h:l,l:h}=ze(this.Dh|0,this.Dl|0,l|0,h|0),{h:d,l:p}=ze(this.Eh|0,this.El|0,d|0,p|0),{h:x,l:E}=ze(this.Fh|0,this.Fl|0,x|0,E|0),{h:w,l:H}=ze(this.Gh|0,this.Gl|0,w|0,H|0),{h:L,l:g}=ze(this.Hh|0,this.Hl|0,L|0,g|0),this.set(o,s,i,c,a,f,l,h,d,p,x,E,w,H,L,g)}roundClean(){Ge(wt,Et)}destroy(){this.destroyed=!0,Ge(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Bs=class extends As{constructor(){super(64,Fa)}};var Ss=Nr(()=>new Es,hs(1));var vs=Nr(()=>new Bs,hs(3));y();var ju=t=>Object.freeze(t());function Pu(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function Vn(t){if(!Pu(t))throw new TypeError("Uint8Array expected")}function Va(t){if(typeof t!="function")throw new TypeError("function expected");return!0}function $u(t,e){if(typeof e!="string")throw new TypeError(`${t}: string expected`);return!0}function Gu(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 Ya(...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}}var qa=(()=>{try{let t=new TextDecoder;return t.decode(Uint8Array.of(65,48,43,127))==="A0+\x7F"?t:void 0}catch{return}})(),ks=8192;function zu(t){let e=t.length;if(qa!==void 0&&e>=12)return qa.decode(t);if(e<=ks)return String.fromCharCode.apply(null,t);let r="";for(let n=0;n<e;n+=ks)r+=String.fromCharCode.apply(null,t.subarray(n,n+ks));return r}function qu(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),c=o[e[s].charCodeAt(0)];if(s.length!==1||i>127||c===void 0||c===-1)throw new Error(`alphabet: invalid alias ${s}`);o[i]=c}return{encode:s=>{let i=new Uint8Array(s.length);for(let c=0;c<s.length;c++){let a=s[c],f=n[a];if(f===void 0)throw new Error(`alphabet.encode: invalid digit ${a}`);i[c]=f}return zu(i)},decode:s=>{$u("decode",s);let i=s.length,c=new Uint8Array(i);for(let a=0;a<i;a++){let f=s.charCodeAt(a),l=f<128?o[f]:-1;if(l===-1)throw new Error(`Unknown letter "${s[a]}". Allowed: ${t}`);c[a]=l}return c}}}function Wu(t,e){if(Gu(t),t<=0)throw new RangeError(`checksum length must be positive: ${t}`);Va(e);let r=e;return{encode(n){Vn(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){Vn(n);let o=n.slice(0,-t),s=n.slice(-t),i=r(o).slice(0,t);for(let c=0;c<t;c++)if(i[c]!==s[c])throw new Error("Invalid checksum");return o}}}var Wa=656356768,Vu={encode:t=>{Vn(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 d=s,p=s;d<e;d+=2,p++)o[p]=t[d]<<8|t[d+1];let i=[],c=0;for(;c<n;){let d=0;for(let p=c;p<n;p++){let x=d*65536+o[p],E=Math.floor(x/Wa);d=x-E*Wa,o[p]=E,E===0&&p===c&&c++}i.push(d)}let a=i.length-1,f=a*5;for(let d=i[a];f++,!(d<58);d=Math.floor(d/58));let l=new Uint8Array(r+f),h=l.length-1;for(let d=0;d<a;d++){let p=i[d];for(let x=0;x<5;x++)l[h--]=p%58,p=Math.floor(p/58)}for(let d=i[a];h>=r;d=Math.floor(d/58))l[h--]=d%58;return l},decode:t=>{Vn(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 l=0,h=1;for(let p=s+i;s<p;s++){let x=t[s];if(x>=58)throw new Error(`invalid integer: ${x}`);l=l*58+x,h*=58}i=5;let d=l;for(let p=0;p<o;p++){let x=n[p]*h+d;d=Math.floor(x/65536),n[p]=x-d*65536}for(;d>0;d=Math.floor(d/65536))n[o++]=d%65536}let c=o===0?1:o*2-(n[o-1]<256?1:0),a=new Uint8Array(r+c),f=a.length-1;for(let l=0;l<o;l++){let h=n[l];a[f--]=h&255,f>=r&&(a[f--]=h>>8)}return a}},Yu=t=>Ya(Vu,qu(t)),Xu=ju(()=>Yu("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"));var Xa=t=>{Va(t);let e=t;return Ya(Wu(4,r=>e(e(r))),Xu)};var Gr=ar.Point,$r=Gr.Fn,Hs=Xa(Ss),Zu=Uint8Array.from("Bitcoin seed".split(""),t=>t.charCodeAt(0)),Ls={private:76066276,public:76067358},Ts=2147483648,Ju=t=>Ga(Ss(t)),Qu=t=>gt(t).getUint32(0,!1),ur=(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 gt(r).setUint32(0,t,!1),r},_s=(t,e="versions")=>{if(!(typeof t=="object"&&t!==null))throw new Error("versions must be an object");return ur(t.private,`${e}.private`),ur(t.public,`${e}.public`),t},Yn=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?_s(e.versions):Ls,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(!ar.utils.isValidSecretKey(e.privateKey))throw new Error("Invalid private key");this._privateKey=Uint8Array.from(e.privateKey),this._publicKey=ar.getPublicKey(this._privateKey,!0)}else if(e.publicKey)this._publicKey=Gr.fromBytes(e.publicKey).toBytes(!0);else throw new Error("HDKey: no public or private key provided");this.pubHash=Ju(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 Hs.encode(this.serialize(this.versions.private,Mr(Uint8Array.of(0),e)))}get publicExtendedKey(){if(!this._publicKey)throw new Error("No public key");return Hs.encode(this.serialize(this.versions.public,this._publicKey))}static fromMasterSeed(e,r=Ls){if(He(e),r=_s(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=ps(vs,Zu,e),o=n.slice(0,32),s=n.slice(32);return new t({versions:r,chainCode:s,privateKey:o})}static fromExtendedKey(e,r=Ls){r=_s(r);let n=Hs.decode(e),o=gt(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>=Ts)throw new Error("Invalid index");s[2]==="'"&&(c+=Ts),n=n.deriveChild(c)}return n}deriveChild(e,r){if(!this._publicKey||!this.chainCode)throw new Error("No publicKey or chainCode set");let n=ur(e,"index");if(e>=Ts){let a=this._privateKey;if(!a)throw new Error("Could not derive hardened child key");n=Mr(Uint8Array.of(0),a,n)}else n=Mr(this._publicKey,n);let o=r||ps(vs,this.chainCode,n);He(o,64);let s=o.slice(0,32),i=o.slice(32),c={versions:this.versions,chainCode:i,depth:this.depth+1,parentFingerprint:this.fingerprint,index:e};if(c.depth>255)throw new Error("HDKey: depth exceeds the serializable value 255");try{let a=$r.fromBytes(s);if(this._privateKey){let f=$r.create($r.fromBytes(this._privateKey)+a);if(!$r.isValidNot0(f))throw new Error("The tweak was out of range or the resulted private key is invalid");c.privateKey=$r.toBytes(f)}else{let f=Gr.fromBytes(this._publicKey),l=a===0n?f:f.add(Gr.BASE.multiply(a));if(l.equals(Gr.ZERO))throw new Error("The tweak was equal to negative P, which made the result key invalid");c.publicKey=l.toBytes(!0)}return new t(c)}catch{return this.deriveChild(e+1)}}sign(e){if(!this._privateKey)throw new Error("No privateKey set!");return He(e,32),ar.sign(e,this._privateKey,{prehash:!1})}verify(e,r){if(He(e,32),He(r,64),!this._publicKey)throw new Error("No publicKey set!");return ar.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 He(r,33),Mr(ur(e,"version"),new Uint8Array([this.depth]),ur(this.parentFingerprint,"parentFingerprint"),ur(this.index,"index"),this.chainCode,r)}};y();y();y();y();function Za(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var Is=t=>t?`"${t}" `:"";function qe(t,e=""){if(typeof t!="number")throw new TypeError(Is(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Is(e)+"expected integer >= 0, got "+t);return t}function At(t,e,r=""){if(Za(t)&&(e===void 0||t.length===e))return t;e!==void 0&&qe(e,"length");let n=Za(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=Is(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function Xn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(qe(t.outputLen),qe(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Ja=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)};function lr(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function Zn(t,e){At(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function nt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function dr(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Ce(t,e){return t<<32-e|t>>>e}function el(t){if(typeof t!="string")throw new TypeError("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Us(t,e=""){return typeof t=="string"?el(t):At(t,void 0,e)}function Os(t,e,r="opts"){return Ja(t,"defaults"),e!==void 0&&Ja(e,r),Object.assign(t,e)}function Rs(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=Os({},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 Qa(t=32){qe(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 Ks=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});var Jn=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(Xn(e),At(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),nt(o)}update(e){return lr(this),this.iHash.update(e),this}digestInto(e){lr(this),Zn(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:c,canXOF:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=c,e.canXOF=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},e0=(()=>{let t=((e,r,n)=>new Jn(e,r).update(n).digest());return t.create=(e,r)=>new Jn(e,r),t})();function tl(t,e,r,n){Xn(t);let o=Os({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:c}=o;if(qe(s,"c"),qe(i,"dkLen"),qe(c,"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 a=Us(e,"password"),f=Us(r,"salt"),l=new Uint8Array(i),{iHash:h,oHash:d,outputLen:p}=e0.create(t,a),x=new Uint8Array(p),E=rl(h,d,f,x);return{c:s,dkLen:i,asyncTick:c,DK:l,outputLen:p,eng:E}}function rl(t,e,r,n){let o=new Uint8Array(4),s=dr(o),i=t._cloneInto().update(r),c=e._cloneInto(),a=t._cloneInto,f=e._cloneInto;return{u1:(l,h)=>{s.setInt32(0,l,!1),i._cloneInto(c).update(o).digestInto(n),e._cloneInto(c).update(n).digestInto(n),h.set(n.subarray(0,h.length))},rounds:(l,h)=>{for(let d=1;d<l;d++){a.call(t,c).update(n).digestInto(n),f.call(e,c).update(n).digestInto(n);for(let p=0;p<h.length;p++)h[p]^=n[p]}},output:l=>(t.destroy(),e.destroy(),i.destroy(),c.destroy(),nt(n),l)}}function t0(t,e,r,n){let{c:o,dkLen:s,DK:i,outputLen:c,eng:a}=tl(t,e,r,n);for(let f=1,l=0;l<s;f++,l+=c){let h=i.subarray(l,l+c);a.u1(f,h),a.rounds(o,h)}return a.output(i)}y();y();y();var Qn=BigInt(4294967295),r0=BigInt(32);function nl(t,e=!1){return e?{h:Number(t&Qn),l:Number(t>>r0&Qn)}:{h:Number(t>>r0&Qn)|0,l:Number(t&Qn)|0}}function n0(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}=nl(t[s],e);[n[s],o[s]]=[i,c]}return[n,o]}var ol=t=>t/2**32|0,sl=t=>t>>>0;function o0(t,e,r,n){let o=ol(r),s=sl(r);t.setUint32(e,n?s:o,n),t.setUint32(e+4,n?o:s,n)}var Cs=(t,e,r)=>t>>>r,Fs=(t,e,r)=>t<<32-r|e>>>r,Pt=(t,e,r)=>t>>>r|e<<32-r,$t=(t,e,r)=>t<<32-r|e>>>r,zr=(t,e,r)=>t<<64-r|e>>>r-32,qr=(t,e,r)=>t>>>r-32|e<<64-r;function We(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var s0=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),i0=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,c0=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),a0=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,f0=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),u0=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;function l0(t,e,r){return t&e^~t&r}function d0(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=dr(this.buffer)}update(e){lr(this),At(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length,i=!1;for(let c=0;c<s;){let a=Math.min(o-this.pos,s-c);if(a===o){let f=dr(e);for(;o<=s-c;c+=o)this.process(f,c);i=!0;continue}n.set(c===0&&a===s?e:e.subarray(c,c+a),this.pos),this.pos+=a,c+=a,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){lr(this),Zn(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)),o0(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let c=e===r?n:dr(e),a=this.outputLen,f=a/4,l=this.get();if(a%4||f>l.length)throw new Error("invalid outputLen");for(let h=0;h<f;h++)c.setUint32(4*h,l[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()}},h0=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var p0=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var cl=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Bt=new Uint32Array(64),Ds=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:c,G:a,H:f}=this;return[r,n,o,s,i,c,a,f]}set(r,n,o,s,i,c,a,f){this.A=r|0,this.B=n|0,this.C=o|0,this.D=s|0,this.E=i|0,this.F=c|0,this.G=a|0,this.H=f|0}_cloneInto(r){return(r||(r=new this.constructor)).set(...this.get()),this._cloneIntoMeta(r)}process(r,n){for(let d=0;d<16;d++,n+=4)Bt[d]=r.getUint32(n,!1);for(let d=16;d<64;d++){let p=Bt[d-15],x=Bt[d-2],E=Ce(p,7)^Ce(p,18)^p>>>3,w=Ce(x,17)^Ce(x,19)^x>>>10;Bt[d]=w+Bt[d-7]+E+Bt[d-16]|0}let{A:o,B:s,C:i,D:c,E:a,F:f,G:l,H:h}=this;for(let d=0;d<64;d++){let p=Ce(a,6)^Ce(a,11)^Ce(a,25),x=h+p+l0(a,f,l)+cl[d]+Bt[d]|0,w=(Ce(o,2)^Ce(o,13)^Ce(o,22))+d0(o,s,i)|0;h=l,l=f,f=a,a=c+x|0,c=i,i=s,s=o,o=x+w|0}o=o+this.A|0,s=s+this.B|0,i=i+this.C|0,c=c+this.D|0,a=a+this.E|0,f=f+this.F|0,l=l+this.G|0,h=h+this.H|0,this.set(o,s,i,c,a,f,l,h)}roundClean(){nt(Bt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),nt(this.buffer)}},Ms=class extends Ds{constructor(){super(32,h0)}};var x0=n0(["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))),al=x0[0],fl=x0[1],St=new Uint32Array(80),vt=new Uint32Array(80),Ns=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:c,Dh:a,Dl:f,Eh:l,El:h,Fh:d,Fl:p,Gh:x,Gl:E,Hh:w,Hl:H}=this;return[r,n,o,s,i,c,a,f,l,h,d,p,x,E,w,H]}set(r,n,o,s,i,c,a,f,l,h,d,p,x,E,w,H){this.Ah=r|0,this.Al=n|0,this.Bh=o|0,this.Bl=s|0,this.Ch=i|0,this.Cl=c|0,this.Dh=a|0,this.Dl=f|0,this.Eh=l|0,this.El=h|0,this.Fh=d|0,this.Fl=p|0,this.Gh=x|0,this.Gl=E|0,this.Hh=w|0,this.Hl=H|0}_cloneInto(r){return(r||(r=new this.constructor)).set(...this.get()),this._cloneIntoMeta(r)}process(r,n){for(let m=0;m<16;m++,n+=4)St[m]=r.getUint32(n),vt[m]=r.getUint32(n+=4);for(let m=16;m<80;m++){let U=St[m-15]|0,P=vt[m-15]|0,X=Pt(U,P,1)^Pt(U,P,8)^Cs(U,P,7),q=$t(U,P,1)^$t(U,P,8)^Fs(U,P,7),z=St[m-2]|0,D=vt[m-2]|0,J=Pt(z,D,19)^zr(z,D,61)^Cs(z,D,6),Z=$t(z,D,19)^qr(z,D,61)^Fs(z,D,6),ae=c0(q,Z,vt[m-7],vt[m-16]),fe=a0(ae,X,J,St[m-7],St[m-16]);St[m]=fe|0,vt[m]=ae|0}let{Ah:o,Al:s,Bh:i,Bl:c,Ch:a,Cl:f,Dh:l,Dl:h,Eh:d,El:p,Fh:x,Fl:E,Gh:w,Gl:H,Hh:L,Hl:g}=this;for(let m=0;m<80;m++){let U=Pt(d,p,14)^Pt(d,p,18)^zr(d,p,41),P=$t(d,p,14)^$t(d,p,18)^qr(d,p,41),X=d&x^~d&w,q=p&E^~p&H,z=f0(g,P,q,fl[m],vt[m]),D=u0(z,L,U,X,al[m],St[m]),J=z|0,Z=Pt(o,s,28)^zr(o,s,34)^zr(o,s,39),ae=$t(o,s,28)^qr(o,s,34)^qr(o,s,39),fe=o&i^o&a^i&a,V=s&c^s&f^c&f;L=w|0,g=H|0,w=x|0,H=E|0,x=d|0,E=p|0,{h:d,l:p}=We(l|0,h|0,D|0,J|0),l=a|0,h=f|0,a=i|0,f=c|0,i=o|0,c=s|0;let Y=s0(J,ae,V);o=i0(Y,D,Z,fe),s=Y|0}({h:o,l:s}=We(this.Ah|0,this.Al|0,o|0,s|0)),{h:i,l:c}=We(this.Bh|0,this.Bl|0,i|0,c|0),{h:a,l:f}=We(this.Ch|0,this.Cl|0,a|0,f|0),{h:l,l:h}=We(this.Dh|0,this.Dl|0,l|0,h|0),{h:d,l:p}=We(this.Eh|0,this.El|0,d|0,p|0),{h:x,l:E}=We(this.Fh|0,this.Fl|0,x|0,E|0),{h:w,l:H}=We(this.Gh|0,this.Gl|0,w|0,H|0),{h:L,l:g}=We(this.Hh|0,this.Hl|0,L|0,g|0),this.set(o,s,i,c,a,f,l,h,d,p,x,E,w,H,L,g)}roundClean(){nt(St,vt)}destroy(){this.destroyed=!0,nt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},js=class extends Ns{constructor(){super(64,p0)}};var y0=Rs(()=>new Ms,Ks(1));var b0=Rs(()=>new js,Ks(3));var ul=t=>t[0]==="\u3042\u3044\u3053\u304F\u3057\u3093";function g0(t){if(typeof t!="string")throw new TypeError("invalid mnemonic type: "+typeof t);return t.normalize("NFKD")}function ll(t){let e=g0(t),r=e.split(" ");if(![12,15,18,21,24].includes(r.length))throw new Error("Invalid mnemonic");return{nfkd:e,words:r}}function dl(t){if(At(t),![16,20,24,28,32].includes(t.length))throw new RangeError("invalid entropy length")}function m0(t,e=128){if(qe(e),e%32!==0||e>256)throw new RangeError("Invalid entropy");return yl(Qa(e/8),t)}var hl=t=>{let e=8-t.length/4;return y0(t)[0]>>e<<e};function pl(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 xl(t,e){pl(e);let r=new Uint8Array(t.length+1);r.set(t),r[t.length]=hl(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 yl(t,e){return dl(t),xl(t,e).join(ul(e)?"\u3000":" ")}var bl=t=>{if(typeof t!="string")throw new TypeError("invalid passphrase type: "+typeof t);return g0("mnemonic"+t)};function w0(t,e=""){return t0(b0,ll(t).nfkd,bl(e),{c:2048,dkLen:64})}y();var E0=Object.freeze(`abandon
|
|
1
|
+
"use strict";var LumenKeys=(()=>{var Br=Object.defineProperty;var Ji=Object.getOwnPropertyDescriptor;var Qi=Object.getOwnPropertyNames;var ec=Object.prototype.hasOwnProperty;var tc=(t,e,r)=>e in t?Br(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var Ne=(t,e)=>()=>(t&&(e=t(t=0)),e);var Do=(t,e)=>{for(var r in e)Br(t,r,{get:e[r],enumerable:!0})},rc=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Qi(e))!ec.call(t,o)&&o!==r&&Br(t,o,{get:()=>e[o],enumerable:!(n=Ji(e,o))||n.enumerable});return t};var nc=t=>rc(Br({},"__esModule",{value:!0}),t);var h=(t,e,r)=>tc(t,typeof e!="symbol"?e+"":e,r);function _t(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function se(t,e=""){if(typeof t!="number")throw new TypeError(Lr(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Lr(e)+"expected integer >= 0, got "+t);return t}function ys(t,e=""){if(typeof t!="boolean")throw new TypeError(Lr(e)+"expected boolean, got type="+typeof t);return t}function j(t,e,r=""){if(_t(t)&&(e===void 0||t.length===e))return t;e!==void 0&&se(e,"length");let n=_t(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=Lr(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function Qe(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(se(t.outputLen),se(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}function He(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function Ut(t,e){j(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Kn(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function ge(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Ue(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Ie(t,e){return t<<32-e|t>>>e}function nr(t,e){return t<<e|t>>>32-e>>>0}function Kc(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function Ic(t){for(let e=0;e<t.length;e++)t[e]=Kc(t[e]);return t}function Fr(t){if(j(t),ms)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Rc[t[r]];return e}function ps(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function Rn(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(ms)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=ps(t.charCodeAt(s)),a=ps(t.charCodeAt(s+1));if(i===void 0||a===void 0){let c=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Oc(t){if(typeof t!="string")throw new TypeError("string expected");return new Uint8Array(new TextEncoder().encode(t))}function On(t,e=""){return typeof t=="string"?Oc(t):j(t,void 0,e)}function Ce(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];j(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function or(t,e,r="opts"){return hs(t,"defaults"),e!==void 0&&hs(e,r),Object.assign(t,e)}function et(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=or({},e,"info");let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function Ct(t=32){se(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var Lr,hs,gs,In,ms,Rc,gt,Be=Ne(()=>{Lr=t=>t?`"${t}" `:"";hs=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)};gs=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;In=gs?t=>t:Ic,ms=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Rc=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));gt=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])})});function _c(t,e=!1){return e?{h:Number(t&Pr),l:Number(t>>bs&Pr)}:{h:Number(t>>bs&Pr)|0,l:Number(t&Pr)|0}}function Nr(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=_c(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}function ws(t,e,r,n){let o=Uc(r),s=Cc(r);t.setUint32(e,n?s:o,n),t.setUint32(e+4,n?o:s,n)}function Le(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Pr,bs,Uc,Cc,_n,Un,mt,bt,sr,ir,xs,Es,vs,Ss,ks,As,Dr=Ne(()=>{Pr=BigInt(4294967295),bs=BigInt(32);Uc=t=>t/2**32|0,Cc=t=>t>>>0;_n=(t,e,r)=>t>>>r,Un=(t,e,r)=>t<<32-r|e>>>r,mt=(t,e,r)=>t>>>r|e<<32-r,bt=(t,e,r)=>t<<32-r|e>>>r,sr=(t,e,r)=>t<<64-r|e>>>r-32,ir=(t,e,r)=>t>>>r-32|e<<64-r;xs=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Es=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,vs=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Ss=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,ks=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),As=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0});function Gc(t,e=24){if(!(t instanceof Uint32Array))throw new TypeError('"s" expected Uint32Array(50), got type='+typeof t);if(t.length!==50)throw new RangeError('"s" expected Uint32Array(50), got length='+t.length);if(se(e,"rounds"),e<1||e>24)throw new Error('"rounds" expected integer 1..24');for(let r=24-e;r<24;r++){for(let s=0;s<10;s++)Lt[s]=t[s]^t[s+10]^t[s+20]^t[s+30]^t[s+40];for(let s=0;s<10;s+=2){let i=(s+8)%10,a=(s+2)%10,c=Lt[a],f=Lt[a+1],u=Is(c,f,1)^Lt[i],d=Rs(c,f,1)^Lt[i+1];for(let l=0;l<50;l+=10)t[s+l]^=u,t[s+l+1]^=d}let n=t[2],o=t[3];for(let s=0;s<24;s++){let i=_s[s],a=Is(n,o,i),c=Rs(n,o,i),f=Os[s];n=t[f],o=t[f+1],t[f]=a,t[f+1]=c}for(let s=0;s<50;s+=10){let i=t[s],a=t[s+1],c=t[s+2],f=t[s+3];t[s]^=~t[s+2]&t[s+4],t[s+1]^=~t[s+3]&t[s+5],t[s+2]^=~t[s+4]&t[s+6],t[s+3]^=~t[s+5]&t[s+7],t[s+4]^=~t[s+6]&t[s+8],t[s+5]^=~t[s+7]&t[s+9],t[s+6]^=~t[s+8]&i,t[s+7]^=~t[s+9]&a,t[s+8]^=~i&c,t[s+9]^=~a&f}t[0]^=zc[r],t[1]^=qc[r]}ge(Lt)}var Nc,cr,Dc,$c,Hc,jc,Os,_s,Us,Cs,zc,qc,Vc,Wc,Zc,Yc,Is,Rs,Lt,$r,Xc,Ls,Fs,Ms,be,Hr=Ne(()=>{Dr();Be();Nc=BigInt(0),cr=BigInt(1),Dc=BigInt(2),$c=BigInt(7),Hc=BigInt(256),jc=BigInt(113),Os=[],_s=[],Us=[];for(let t=0,e=cr,r=1,n=0;t<24;t++){[r,n]=[n,(2*r+3*n)%5],Os.push(2*(5*n+r)),_s.push((t+1)*(t+2)/2%64);let o=Nc;for(let s=0;s<7;s++)e=(e<<cr^(e>>$c)*jc)%Hc,e&Dc&&(o^=cr<<(cr<<BigInt(s))-cr);Us.push(o)}Cs=Nr(Us,!0),zc=Cs[0],qc=Cs[1],Vc=(t,e,r)=>t<<r|e>>>32-r,Wc=(t,e,r)=>e<<r|t>>>32-r,Zc=(t,e,r)=>e<<r-32|t>>>64-r,Yc=(t,e,r)=>t<<r-32|e>>>64-r,Is=(t,e,r)=>r>32?Zc(t,e,r):Vc(t,e,r),Rs=(t,e,r)=>r>32?Yc(t,e,r):Wc(t,e,r),Lt=new Uint32Array(10);$r=class t{constructor(e,r,n,o=!1,s=24){h(this,"state");h(this,"pos",0);h(this,"posOut",0);h(this,"finished",!1);h(this,"state32");h(this,"destroyed",!1);h(this,"blockLen");h(this,"suffix");h(this,"outputLen");h(this,"canXOF");h(this,"enableXOF",!1);h(this,"rounds");if(se(e,"blockLen"),se(r,"suffix"),se(s,"rounds"),ys(o,"enableXOF"),this.blockLen=e,this.suffix=r,this.outputLen=n,this.enableXOF=o,this.canXOF=o,this.rounds=s,se(n,"outputLen"),!(0<e&&e<200))throw new Error('"blockLen" must be 1..199');this.state=new Uint8Array(200),this.state32=Kn(this.state)}clone(){return this._cloneInto()}keccak(){In(this.state32),Gc(this.state32,this.rounds),In(this.state32),this.posOut=0,this.pos=0}update(e){He(this),j(e);let{blockLen:r,state:n,state32:o}=this,s=e.length,i=r%4===0&&e.byteOffset%4===0,a=r/4,c=i&&s>=r?Kn(e):void 0;for(let f=0;f<s;){if(c!==void 0&&this.pos===0&&f%4===0&&s-f>=r){for(let d=0,l=f/4;d<a;d++)o[d]^=c[l+d];f+=r,this.pos=r,this.keccak();continue}let u=Math.min(r-this.pos,s-f);for(let d=0;d<u;d++)n[this.pos++]^=e[f++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:r,pos:n,blockLen:o}=this;e[n]^=r,(r&128)!==0&&n===o-1&&this.keccak(),e[o-1]^=128,this.keccak()}writeInto(e){He(this,!1),j(e),this.finish();let r=this.state,{blockLen:n}=this;for(let o=0,s=e.length;o<s;){this.posOut>=n&&this.keccak();let i=Math.min(n-this.posOut,s-o);e.set(r.subarray(this.posOut,this.posOut+i),o),this.posOut+=i,o+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not enabled");return this.writeInto(e)}xof(e){return se(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Ut(e,this),this.finished)throw new Error("digest() was already called");this.writeInto(e.length===this.outputLen?e:e.subarray(0,this.outputLen)),this.destroy()}digest(){let e=new Uint8Array(this.outputLen);return this.digestInto(e),e}destroy(){this.destroyed=!0,ge(this.state)}_cloneInto(e){let{blockLen:r,suffix:n,outputLen:o,rounds:s,enableXOF:i}=this;return e||(e=new t(r,n,o,i,s)),e.blockLen=r,e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=s,e.suffix=n,e.outputLen=o,e.enableXOF=i,e.canXOF=this.canXOF,e.destroyed=this.destroyed,e}},Xc=(t,e,r,n={})=>et(()=>new $r(e,t,r),n),Ls=Xc(6,136,32,gt(8)),Fs=(t,e,r,n={})=>et((o={})=>(o=or({},o),new $r(e,t,o.dkLen===void 0?r:o.dkLen,!0)),n),Ms=Fs(31,168,16,gt(11)),be=Fs(31,136,32,gt(12))});function fr(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}function Ns(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function ot(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Et(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}function Te(t,e=""){if(typeof t!="boolean")throw new TypeError(Jc(e)+"expected boolean, got type="+typeof t);return t}function Wr(t){if(typeof t=="bigint"){if(!st(t))throw new RangeError("positive bigint expected, got "+t)}else Dn(t);return t}function Pt(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function ur(t){let e=Wr(t).toString(16);return e.length&1?"0"+e:e}function Ds(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?zr:BigInt("0x"+t)}function Fe(t){return Ds(Fr(t))}function Hn(t){return Ds(Fr(Qc(j(t)).reverse()))}function Zr(t,e){if(se(e),e===0)throw new Error("zero output length is invalid");t=Wr(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return Rn(n.padStart(r,"0"))}function jn(t,e){return Zr(t,e).reverse()}function Qc(t){return Uint8Array.from(ue(t))}function st(t){return typeof t=="bigint"&&zr<=t}function zn(t,e,r){return st(t)&&st(e)&&st(r)&&e<=t&&t<r}function qn(t,e,r,n){if(!zn(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Nt(t){if(t<zr)throw new Error("expected non-negative bigint, got "+t);return t===zr?0:t.toString(2).length}function $s(t,e,r){if(se(t,"hashLen"),se(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=A=>new Uint8Array(A),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),f=n(t),u=0,d=()=>{c.fill(1),f.fill(0),u=0},l=(...A)=>r(f,ze(c,...A)),p=(A=o)=>{f=l(s,A),c=l(),A.length!==0&&(f=l(i,A),c=l())},y=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let A=0,_=[];for(;A<e;){c=l();let I=c.slice();_.push(I),A+=c.length}return ze(..._)};return(A,_)=>{d(),p(A);let I;for(;(I=_(y()))===void 0;)p();return d(),I}}function Me(t,e={},r={},n="object"){ot(t,n),ot(e,"fields"),ot(r,"optFields");function o(i,a,c){let f=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,u=t[i];if(!Object.hasOwn(t,i)&&(c?u!==void 0:a!=="function"))throw new TypeError(`${f} is invalid: expected own property`);if(c&&u===void 0)return;let d=typeof u;if(d!==a||u===null)throw new TypeError(`${f} is invalid: expected ${a}, got ${d}`)}let s=(i,a)=>Object.entries(i).forEach(([c,f])=>o(c,f,a));s(e,!1),s(r,!0)}var ue,Dn,$n,ze,qr,Mt,Vr,zr,Ps,Jc,lr,vt=Ne(()=>{Be();ue=(t,e,r)=>j(t,e,r),Dn=se;$n=Fr,ze=(...t)=>Ce(...t),qr=t=>Rn(t),Mt=_t,Vr=t=>Ct(t),zr=BigInt(0),Ps=BigInt(1),Jc=t=>t?`"${t}" `:"";lr=t=>(Pt(t,"n"),(Ps<<BigInt(t))-Ps)});function ve(t,e){if(e<=le)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=le?r:e+r}function Ys(t,e,r){if(r<=G)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<le)throw new Error("invalid exponent, negatives unsupported");if(e===le)return G;if(e===G)return t;let n=t%r;if(n<le&&(n+=r),e<na){let a=G;for(;e>le;)e&G&&(a=a*n%r),n=n*n%r,e>>=G;return a}let o=[];for(;e>le;)o.push(Number(e&ra)),e>>=Vn;let s=new Array(16);s[0]=G,s[1]=n;for(let a=2;a<16;a++)s[a]=s[a-1]*n%r;let i=s[o[o.length-1]];for(let a=o.length-2;a>=0;a--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let c=o[a];c!==0&&(i=i*s[c]%r)}return i}function Se(t,e,r){if(r<=G)throw new Error("pow2: expected modulus > 1, got "+r);if(e<le)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >le;)n*=n,n%=r;return n}function Hs(t,e){if(t===le)throw new Error("invert: expected non-zero number");if(e<=G)throw new Error("invert: expected modulus > 1, got "+e);let r=ve(t,e),n=e,o=le,s=G;for(;r!==le;){let a=n/r,c=n-r*a,f=o-s*a;n=r,r=c,o=s,s=f}if(n!==G)throw new Error("invert: does not exist");return ve(o,e)}function Gs(t,e){if(e<=G)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=ve(t,e);if(r===le)throw new Error("invertCt: expected non-zero number");let n=Ys(r,e-it,e);if(ve(r*n,e)!==G)throw new Error("invertCt: does not exist");return n}function Wn(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Zn(t,e){if((t&G)===le)throw new Error(e+": expected odd modulus, got "+t)}function Xs(t,e){let r=t,n=(r.ORDER+G)/Vn,o=r.pow(e,n);return Wn(r,o,e),o}function oa(t,e){let r=t,n=(r.ORDER-Vs)/Ws,o=r.mul(e,it),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,it),s),c=r.mul(i,r.sub(a,r.ONE));return Wn(r,c,e),c}function sa(t){let e=$t(t),r=Js(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+ea)/Zs;return((a,c)=>{let f=a,u=f.pow(c,i),d=f.mul(u,n),l=f.mul(u,o),p=f.mul(u,s),y=f.eql(f.sqr(d),c),b=f.eql(f.sqr(l),c);u=f.cmov(u,d,y),d=f.cmov(p,l,b);let A=f.eql(f.sqr(d),c),_=f.cmov(u,d,A);return Wn(f,_,c),_})}function Js(t){if(t<qs)throw new Error("sqrt is not defined for small field");Zn(t,"tonelliShanks");let e=t-G,r=0;for(;e%it===le;)e/=it,r++;let n=it,o=$t(t);for(;js(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Xs;let s=o.pow(n,e),i=(e+G)/it;return function(c,f){let u=c;if(u.is0(f))return f;if(js(u,f)!==1)throw new Error("Cannot find square root");let d=r,l=u.mul(u.ONE,s),p=u.pow(f,e),y=u.pow(f,i);for(;!u.eql(p,u.ONE);){if(u.is0(p))throw new Error("Cannot find square root: probably non-prime P");let b=1,A=u.sqr(p);for(;!u.eql(A,u.ONE);)if(b++,A=u.sqr(A),b===d)throw new Error("Cannot find square root");let _=G<<BigInt(d-b-1),I=u.pow(l,_);d=b,l=u.sqr(I),p=u.mul(p,l),y=u.mul(y,I)}return y}}function ia(t){return Zn(t,"Fp.sqrt"),t%Vn===qs?Xs:t%Ws===Vs?oa:t%Zs===ta?sa(t):Js(t)}function Dt(t){if(ot(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);Pt(t.BYTES,"BYTES"),Pt(t.BITS,"BITS");for(let e of ca)Et(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=G)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Yn(t,e,r=!1){Dt(t),fr(e,"nums"),Te(r,"passZero");let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((a,c,f)=>n.is0(c)?a:(o[f]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return e.reduceRight((a,c,f)=>n.is0(c)?a:(o[f]=n.mul(a,o[f]),n.mul(a,c)),i),o}function js(t,e){Dt(t);let r=t;Zn(r.ORDER,"FpLegendre");let n=(r.ORDER-G)/it,o=r.pow(e,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function aa(t,e){if(e!==void 0&&Dn(e),t<=le)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Nt(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}function $t(t,e={}){return Object.freeze(Yr.prototype),new Yr(t,e)}function Qs(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=G)throw new Error("field order must be greater than 1");let e=Nt(t-G);return Math.ceil(e/8)}function Gr(t){let e=Qs(t);return e+Math.ceil(e/2)}function Xr(t,e,r=!1){ue(t);let n=t.length,o=Qs(e),s=Math.max(Gr(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Hn(t):Fe(t),a=ve(i,e-G)+G;return r?jn(a,o):Zr(a,o)}var le,G,it,qs,Vn,Vs,ea,Ws,ta,ra,Zs,na,ca,zs,Yr,Jr=Ne(()=>{vt();le=BigInt(0),G=BigInt(1),it=BigInt(2),qs=BigInt(3),Vn=BigInt(4),Vs=BigInt(5),ea=BigInt(7),Ws=BigInt(8),ta=BigInt(9),ra=BigInt(15),Zs=BigInt(16),na=BigInt("0x10000000000000000");ca=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];zs=new WeakMap,Yr=class{constructor(e,r={}){h(this,"ORDER");h(this,"BITS");h(this,"BYTES");h(this,"isLE");h(this,"ZERO",le);h(this,"ONE",G);h(this,"_lengths");h(this,"_mod");if(e<=G)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=aa(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return ve(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return le<=e&&e<this.ORDER}is0(e){return e===le}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&G)===G}neg(e){return ve(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ve(e*e,this.ORDER)}add(e,r){return ve(e+r,this.ORDER)}sub(e,r){return ve(e-r,this.ORDER)}mul(e,r){return ve(e*r,this.ORDER)}pow(e,r){return Ys(e,r,this.ORDER)}div(e,r){return ve(e*Hs(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return Hs(e,this.ORDER)}sqrt(e){let r=zs.get(this);return r||zs.set(this,r=ia(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?jn(e,this.BYTES):Zr(e,this.BYTES)}fromBytes(e,r=!1){ue(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let f=new Uint8Array(o);f.set(e,s?0:f.length-e.length),e=f}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=s?Hn(e):Fe(e);if(a&&(c=ve(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Yn(this,e,!0)}cmov(e,r,n){return Te(n,"condition"),n?r:e}}});function hr(t,e="n"){if(typeof t!="number")throw new TypeError(`wrong u32 integer "${e}": expected number, got type=${typeof t}`);if(!Number.isSafeInteger(t)||t<0||t>4294967295)throw new RangeError(`wrong u32 integer "${e}": expected 0..4294967295, got ${t}`);return t}function fi(t){return hr(t,"x"),(t&t-1)===0&&t!==0}function eo(t,e){if(hr(t),typeof e!="number")throw new TypeError('"bits" expected number, got type='+typeof e);if(!Number.isSafeInteger(e)||e<0||e>32)throw new Error(`expected integer 0 <= bits <= 32, got ${e}`);let r=0;for(let n=0;n<e;n++,t>>>=1)r=r<<1|t&1;return r>>>0}function ui(t){return hr(t),31-Math.clz32(t)}function ai(t){if(!t||typeof t!="object"||typeof t.length!="number")throw new TypeError('"values" expected array-like, got type='+typeof t);let e=t.length;if(!fi(e))throw new Error("expected positive power-of-two length, got "+e);let r=ui(e);for(let n=0;n<e;n++){let o=eo(n,r);if(n<o){let s=t[n];t[n]=t[o],t[o]=s}}return t}var to,li=Ne(()=>{vt();to=(t,e)=>{Me(e,{N:"number",roots:"object",dit:"boolean"},{invertButterflies:"boolean",skipStages:"number",brp:"boolean"},"coreOpts");let{N:r,roots:n,dit:o,invertButterflies:s=!1,skipStages:i=0,brp:a=!0}=e;hr(r,"coreOpts.N");let c=ui(r);if(!fi(r))throw new Error("FFT: Polynomial size should be power of two");hr(i,"coreOpts.skipStages");let f=c===0?0:c-1;if(i>f)throw new Error(`FFT: wrong skipStages: expected 0 <= skipStages <= ${f}`);if(n.length!==r)throw new Error(`FFT: wrong roots length: expected ${r}, got ${n.length}`);let u=o!==s;return d=>{if(d.length!==r)throw new Error("FFT: wrong Polynomial length");o&&a&&ai(d);for(let l=0,p=1;l<c-i;l++){let y=o?l+1+i:c-l,b=1<<y,A=b>>1,_=r>>y;for(let I=0;I<r;I+=b)for(let E=0,S=p++;E<A;E++){let N=s?o?r-S:S:E*_,H=I+E,V=I+E+A,W=n[N],Z=d[V],D=d[H];if(u){let ee=t.mul(Z,W);d[H]=t.add(D,ee),d[V]=t.sub(D,ee)}else s?(d[H]=t.add(Z,D),d[V]=t.mul(t.sub(Z,D),W)):(d[H]=t.add(D,Z),d[V]=t.mul(t.sub(D,Z),W))}}return!o&&a&&ai(d),d}}});function ef(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}function tf(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function xo(t,e){if(t=j(t),e=j(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function Eo(t){if(_t(t))throw new TypeError('"opts" expected object, got Uint8Array');tf(t,"opts")}function on(t){Eo(t),t.context!==void 0&&j(t.context,void 0,"opts.context")}function sn(t){on(t),t.extraEntropy!==!1&&t.extraEntropy!==void 0&&j(t.extraEntropy,void 0,"opts.extraEntropy")}function gr(t,...e){let r=o=>typeof o=="number"?o:o.bytesLen,n=e.reduce((o,s)=>o+r(s),0);return{bytesLen:n,encode:o=>{let s=new Uint8Array(n);for(let i=0,a=0;i<e.length;i++){let c=e[i],f=r(c),u=typeof c=="number"?o[i]:c.encode(o[i]);j(u,f,t),s.set(u,a),typeof c!="number"&&u.fill(0),a+=f}return s},decode:o=>{j(o,n,t);let s=[];for(let i of e){let a=r(i),c=o.subarray(0,a);s.push(typeof i=="number"?c:i.decode(c)),o=o.subarray(a)}return s}}}function kt(t,e){let r=t,n=e*r.bytesLen;return{bytesLen:n,encode:o=>{let s=ef(o,"u");if(s.length!==e)throw new RangeError(`vecCoder.encode: wrong length=${s.length}. Expected: ${e}`);let i=new Uint8Array(n);for(let a=0,c=0;a<s.length;a++){let f=r.encode(s[a]);i.set(f,c),f.fill(0),c+=f.length}return i},decode:o=>{j(o,n);let s=[];for(let i=0;i<o.length;i+=r.bytesLen)s.push(r.decode(o.subarray(i,i+r.bytesLen)));return s}}}function ke(...t){for(let e of t)if(Array.isArray(e))for(let r of e)r.fill(0);else e.fill(0)}function vo(t){if(se(t,"bits"),t>32)throw new RangeError('"bits" expected <= 32, got '+t);return t===32?4294967295:~(-1<<t)>>>0}function So(t,e=Hi){if(j(t,void 0,"msg"),j(e,void 0,"ctx"),e.length>255)throw new RangeError("context should be 255 bytes or less");return Ce(new Uint8Array([0,e.length]),e,t)}function ko(t,e=0){if(typeof t!="function"||typeof t.create!="function")throw new TypeError('"hash" expected hash function, got type='+typeof t);Qe(t),se(e,"requiredStrength");let r=t.oid;if(j(r,void 0,"hash.oid"),!xo(r.subarray(0,10),rf))throw new Error('"hash.oid" is invalid: expected NIST hash');let n=t.outputLen*8/2;if(e>n)throw new Error("Pre-hash security strength too low: "+n+", required: "+e)}function Ao(t,e,r=Hi){if(ko(t),j(e,void 0,"msg"),j(r,void 0,"ctx"),r.length>255)throw new RangeError("context should be 255 bytes or less");let n=t(e);return Ce(new Uint8Array([1,r.length]),r,t.oid,n)}var ct,wo,Hi,rf,Bo=Ne(()=>{Be();ct=j,wo=Ct;Hi=Uint8Array.of();rf=Uint8Array.from([6,9,96,134,72,1,101,3,4,2])});var ji,zi,cn,an,qi=Ne(()=>{li();Hr();Bo();ji=t=>{let{newPoly:e,N:r,Q:n,F:o,ROOT_OF_UNITY:s,brvBits:i,isKyber:a}=t,c=(E,S=n)=>{let N=E%S|0;return(N>=0?N|0:S+N|0)|0},f=(E,S=n)=>{let N=c(E,S)|0;return(N>S>>1?N-S|0:N)|0};function u(){let E=e(r);for(let S=0;S<r;S++){let N=eo(S,i),H=BigInt(s)**BigInt(N)%BigInt(n);E[S]=Number(H)|0}return E}let d=u(),l=E=>{throw new Error("not implemented")},p=a?{add:(E,S)=>{let N=E+S|0;return N>=n?N-n|0:N},sub:(E,S)=>{let N=E-S|0;return N<0?N+n|0:N},mul:(E,S)=>c((E|0)*(S|0))|0,inv:l}:{add:(E,S)=>c((E|0)+(S|0))|0,sub:(E,S)=>c((E|0)-(S|0))|0,mul:(E,S)=>c((E|0)*(S|0))|0,inv:l},y={N:r,roots:d,invertButterflies:!0,skipStages:a?1:0,brp:!1},b=to(p,{dit:!1,...y}),A=to(p,{dit:!0,...y}),_={encode:E=>b(E),decode:E=>{A(E);for(let S=0;S<E.length;S++)E[S]=c(o*E[S]);return E}};return{mod:c,smod:f,nttZetas:d,NTT:{encode:E=>_.encode(E),decode:E=>_.decode(E)},bitsCoder:(E,S)=>{for(let V=0,W=0;V<r;V++)W+=E,W>32&&vo(W),W%=8;let N=vo(E),H=E*(r/8);return{bytesLen:H,encode:V=>{let W=V,Z=new Uint8Array(H);for(let D=0,ee=0,X=0,ye=0;D<W.length;D++)for(ee|=(S.encode(W[D])&N)<<X,X+=E;X>=8;X-=8,ee>>=8)Z[ye++]=ee&255;return Z},decode:V=>{let W=e(r);for(let Z=0,D=0,ee=0,X=0;Z<V.length;Z++)for(D|=V[Z]<<ee,ee+=8;ee>=E;ee-=E,D>>=E)W[X++]=S.decode(D&N);return W}}}}},zi=t=>(e,r)=>{r||(r=t.blockLen);let n=new Uint8Array(e.length+2);n.set(e);let o=e.length,s=new Uint8Array(r),i=t.create({}),a=0,c=0;return{stats:()=>({calls:a,xofs:c}),get:(f,u)=>(n[o+0]=f,n[o+1]=u,i.destroy(),i=t.create({}).update(n),a++,()=>(c++,i.xofInto(s))),clean:()=>{i.destroy(),ke(s,n)}}},cn=zi(Ms),an=zi(be)});var ln={};Do(ln,{PARAMS:()=>un,ml_dsa44:()=>cf,ml_dsa65:()=>af,ml_dsa87:()=>ff});function Vi(t){Eo(t),t.externalMu!==void 0&&Te(t.externalMu,"opts.externalMu")}function fn(t){let e=t,r=Ae(ie);for(let n=0;n<ie;){let o=e();if(o.length%3)throw new Error("RejNTTPoly: unaligned block");for(let s=0;n<ie&&s<=o.length-3;s+=3){let i=(o[s+0]|o[s+1]<<8|o[s+2]<<16)&8388607;i<ut&&(r[n++]=i)}}return r}function Io(t){let e=t,{K:r,L:n,GAMMA1:o,GAMMA2:s,TAU:i,ETA:a,OMEGA:c}=e,{CRH_BYTES:f,TR_BYTES:u,C_TILDE_BYTES:d,XOF128:l,XOF256:p,securityLevel:y}=e;if(![2,4].includes(a))throw new Error("Wrong ETA");if(![1<<17,1<<19].includes(o))throw new Error("Wrong GAMMA1");if(![To,Ko].includes(s))throw new Error("Wrong GAMMA2");let b=i*a,A=g=>{let w=Y.mod(g),x=Y.smod(w,2*s)|0;return w-x===ut-1?{r1:0,r0:x-1|0}:{r1:Math.floor((w-x)/(2*s))|0,r0:x}},_=g=>A(g).r1,I=g=>A(g).r0,E=(g,w)=>g<=s||g>ut-s||g===ut-s&&w===0?0:1,S=Math.floor((ut-1)/(2*s)),N=(g,w)=>{let{r1:x,r0:v}=A(w);return g===1?v>0?Y.mod(x+1,S)|0:Y.mod(x-1,S)|0:x|0},H=g=>{let w=Y.mod(g),x=Y.smod(w,2**At)|0;return{r1:Math.floor((w-x)/2**At)|0,r0:x}},V={bytesLen:c+r,encode:g=>{let w=g;if(w===!1)throw new Error("hint.encode: hint is false");let x=new Uint8Array(c+r);for(let v=0,O=0;v<r;v++){for(let K=0;K<ie;K++)w[v][K]!==0&&(x[O++]=K);x[c+v]=O}return x},decode:g=>{let w=[],x=0;for(let v=0;v<r;v++){let O=Ae(ie);if(g[c+v]<x||g[c+v]>c)return!1;for(let K=x;K<g[c+v];K++){if(K>x&&g[K]<=g[K-1])return!1;O[g[K]]=1}x=g[c+v],w.push(O)}for(let v=x;v<c;v++)if(g[v]!==0)return!1;return w}},W=mr(a===2?3:4,g=>a-g,g=>{if(!(-a<=g&&g<=a))throw new Error(`malformed key s1/s3 ${g} outside of ETA range [${-a}, ${a}]`);return g}),Z=mr(13,g=>(1<<At-1)-g),D=mr(10),ee=mr(o===1<<17?18:20,g=>Y.smod(o-g)),X=mr(s===To?6:4),ye=kt(X,r),de=gr("publicKey",32,kt(D,r)),q=gr("secretKey",32,32,u,kt(W,n),kt(W,r),kt(Z,r)),z=gr("signature",d,kt(ee,n),V),k=a===2?g=>g<15?2-g%5:!1:g=>g<9?4-g:!1;function R(g){let w=g,x=Ae(ie);for(let v=0;v<ie;){let O=w();for(let K=0;v<ie&&K<O.length;K+=1){let P=k(O[K]&15),J=k(O[K]>>4&15);P!==!1&&(x[v++]=P),v<ie&&J!==!1&&(x[v++]=J)}}return x}let L=g=>{let w=Ae(ie),x=be.create({}).update(g),v=new Uint8Array(be.blockLen);x.xofInto(v);let O=v.slice(0,8);for(let K=ie-i,P=8,J=0,ae=0;K<ie;K++){let re=K+1;for(;re>K;)re=v[P++],!(P<be.blockLen)&&(x.xofInto(v),P=0);w[K]=w[re],w[re]=1-((O[J]>>ae++&1)<<1),ae>=8&&(J++,ae=0)}return w},T=g=>{let w=g,x=Ae(ie),v=Ae(ie);for(let O=0;O<w.length;O++){let{r0:K,r1:P}=H(w[O]);x[O]=K,v[O]=P}return{r0:x,r1:v}},m=(g,w)=>{let x=g,v=w;for(let O=0;O<ie;O++)x[O]=N(v[O],x[O]);return x},B=(g,w)=>{let x=g,v=w,O=Ae(ie),K=0;for(let P=0;P<ie;P++){let J=E(x[P],v[P]);O[P]=J,K+=J}return{v:O,cnt:K}},C=32,F=gr("seed",32,64,32),M=Object.freeze({info:Object.freeze({type:"internal-ml-dsa"}),lengths:Object.freeze({secretKey:q.bytesLen,publicKey:de.bytesLen,seed:32,signature:z.bytesLen,signRand:C}),keygen:g=>{let w=new Uint8Array(34),x=g===void 0;x&&(g=wo(32)),ct(g,32,"seed"),w.set(g),x&&ke(g),w[32]=r,w[33]=n;let[v,O,K]=F.decode(be(w,{dkLen:F.bytesLen})),P=p(O),J=[];for(let $=0;$<n;$++)J.push(R(P.get($&255,$>>8&255)));let ae=[];for(let $=n;$<n+r;$++)ae.push(R(P.get($&255,$>>8&255)));let re=J.map($=>Y.NTT.encode($.slice())),Q=[],fe=[],we=l(v),ce=Ae(ie);for(let $=0;$<r;$++){ke(ce);for(let pe=0;pe<n;pe++){let Ee=fn(we.get(pe,$));at(ce,ft(Ee,re[pe]))}Y.NTT.decode(ce);let{r0:ht,r1:ne}=T(at(ce,ae[$]));Q.push(ht),fe.push(ne)}let xe=de.encode([v,fe]),Oe=be(xe,{dkLen:u}),Pe=q.encode([v,K,Oe,J,ae,Q]);return we.clean(),P.clean(),ke(v,O,K,J,ae,re,ce,Q,fe,Oe,w),{publicKey:xe,secretKey:Pe}},getPublicKey:g=>{let[w,x,v,O,K,P]=q.decode(g),J=l(w),ae=O.map(fe=>Y.NTT.encode(fe.slice())),re=[],Q=Ae(ie);for(let fe=0;fe<r;fe++){Q.fill(0);for(let ce=0;ce<n;ce++){let xe=fn(J.get(ce,fe));at(Q,ft(xe,ae[ce]))}Y.NTT.decode(Q),at(Q,K[fe]);let{r1:we}=T(Q);re.push(we)}return J.clean(),ke(Q,ae,P,O,K),de.encode([w,re])},sign:(g,w,x={})=>{sn(x),Vi(x);let{extraEntropy:v,externalMu:O=!1}=x;O&&ct(g,f,"mu");let K=v===!1||v===void 0,P=v===!1?new Uint8Array(32):v===void 0?wo(C):v;ct(P,32,"extraEntropy");let J=(()=>{try{return q.decode(w)}catch(ne){throw K&&ke(P),ne}})(),[ae,re,Q,fe,we,ce]=J,xe=[],Oe=l(ae);for(let ne=0;ne<r;ne++){let pe=[];for(let Ee=0;Ee<n;Ee++)pe.push(fn(Oe.get(Ee,ne)));xe.push(pe)}Oe.clean();for(let ne=0;ne<n;ne++)Y.NTT.encode(fe[ne]);for(let ne=0;ne<r;ne++)Y.NTT.encode(we[ne]),Y.NTT.encode(ce[ne]);let Pe=O?g:be.create({dkLen:f}).update(Q).update(g).digest(),$=be.create({dkLen:f}).update(re).update(P).update(Pe).digest();K&&ke(P),ct($,f);let ht=p($,ee.bytesLen);e:for(let ne=0;;){let pe=[];for(let oe=0;oe<n;oe++,ne++)pe.push(ee.decode(ht.get(ne&255,ne>>8)()));let Ee=pe.map(oe=>Y.NTT.encode(oe.slice())),It=[];for(let oe=0;oe<r;oe++){let Gt=Ae(ie);for(let Ze=0;Ze<n;Ze++)at(Gt,ft(xe[oe][Ze],Ee[Ze]));Y.NTT.decode(Gt),It.push(Gt)}let bn=It.map(oe=>oe.map(_)),wn=be.create({dkLen:d}).update(Pe).update(ye.encode(bn)).digest(),kr=Y.NTT.encode(L(wn)),Ar=fe.map(oe=>ft(oe,kr));for(let oe=0;oe<n;oe++)if(at(Y.NTT.decode(Ar[oe]),pe[oe]),br(Ar[oe],o-b))continue e;let Mo=0,xn=[];for(let oe=0;oe<r;oe++){let Gt=Y.NTT.decode(ft(we[oe],kr)),Ze=Zi(It[oe],Gt).map(I);if(br(Ze,s-b))continue e;let Po=Y.NTT.decode(ft(ce[oe],kr));if(br(Po,s))continue e;at(Ze,Po);let No=B(Ze,bn[oe]);xn.push(No.v),Mo+=No.cnt}if(Mo>c)continue;ht.clean();let Xi=z.encode([wn,Ar,xn]);return ke(wn,Ar,xn,kr,bn,It,Ee,pe,$,fe,we,ce,...xe),O||ke(Pe),Xi}throw new Error("Unreachable code path reached, report this error")},verify:(g,w,x,v={})=>{Vi(v);let{externalMu:O=!1}=v;O&&ct(w,f,"mu");let[K,P]=de.decode(x),J=be(x,{dkLen:u});if(g.length!==z.bytesLen)return!1;let[ae,re,Q]=z.decode(g);if(Q===!1)return!1;for(let $=0;$<n;$++)if(br(re[$],o-b))return!1;let fe=O?w:be.create({dkLen:f}).update(J).update(w).digest(),we=Y.NTT.encode(L(ae)),ce=re.map($=>$.slice());for(let $=0;$<n;$++)Y.NTT.encode(ce[$]);let xe=[],Oe=l(K);for(let $=0;$<r;$++){let ht=ft(Y.NTT.encode(sf(P[$])),we),ne=Ae(ie);for(let Ee=0;Ee<n;Ee++){let It=fn(Oe.get(Ee,$));at(ne,ft(It,ce[Ee]))}let pe=Y.NTT.decode(Zi(ne,ht));xe.push(m(pe,Q[$]))}Oe.clean();let Pe=be.create({dkLen:d}).update(fe).update(ye.encode(xe)).digest();for(let $ of Q)if(!($.reduce((ne,pe)=>ne+pe,0)<=c))return!1;for(let $ of re)if(br($,o-b))return!1;return xo(ae,Pe)}});return Object.freeze({info:Object.freeze({type:"ml-dsa"}),internal:M,securityLevel:y,keygen:M.keygen,lengths:M.lengths,getPublicKey:M.getPublicKey,sign:(g,w,x={})=>{sn(x);let v=So(g,x.context),O=M.sign(v,w,x);return ke(v),O},verify:(g,w,x,v={})=>(on(v),ct(g,void 0,"signature"),M.verify(g,So(w,v.context),x)),prehash:g=>{ko(g,y);let w=g;return Object.freeze({info:Object.freeze({type:"hashml-dsa"}),securityLevel:y,lengths:M.lengths,keygen:M.keygen,getPublicKey:M.getPublicKey,sign:(x,v,O={})=>{sn(O);let K=Ao(w,x,O.context),P=M.sign(K,v,O);return ke(K),P},verify:(x,v,O,K={})=>(on(K),ct(x,void 0,"signature"),M.verify(x,Ao(w,v,K.context),O))})}})}var ie,ut,nf,of,At,To,Ko,un,Ae,Y,Wi,mr,at,Zi,sf,br,ft,cf,af,ff,dn=Ne(()=>{vt();Hr();qi();Bo();ie=256,ut=8380417,nf=1753,of=8347681,At=13,To=Math.floor((ut-1)/88)|0,Ko=Math.floor((ut-1)/32)|0,un=Object.freeze({2:Object.freeze({K:4,L:4,D:At,GAMMA1:2**17,GAMMA2:To,TAU:39,ETA:2,OMEGA:80}),3:Object.freeze({K:6,L:5,D:At,GAMMA1:2**19,GAMMA2:Ko,TAU:49,ETA:4,OMEGA:55}),5:Object.freeze({K:8,L:7,D:At,GAMMA1:2**19,GAMMA2:Ko,TAU:60,ETA:2,OMEGA:75})}),Ae=t=>new Int32Array(t),Y=ji({N:ie,Q:ut,F:of,ROOT_OF_UNITY:nf,newPoly:Ae,isKyber:!1,brvBits:8}),Wi=t=>t,mr=(t,e=Wi,r=Wi)=>Y.bitsCoder(t,{encode:n=>e(r(n)),decode:n=>r(e(n))}),at=(t,e)=>{let r=t,n=e;for(let o=0;o<r.length;o++)r[o]=Y.mod(r[o]+n[o]);return r},Zi=(t,e)=>{let r=t,n=e;for(let o=0;o<r.length;o++)r[o]=Y.mod(r[o]-n[o]);return r},sf=t=>{let e=t;for(let r=0;r<ie;r++)e[r]<<=At;return e},br=(t,e)=>{let r=t;for(let n=0;n<ie;n++)if(Math.abs(Y.smod(r[n]))>=e)return!0;return!1},ft=(t,e)=>{let r=t,n=e,o=Ae(ie);for(let s=0;s<r.length;s++)o[s]=Y.mod(r[s]*n[s]);return o};cf=Io({...un[2],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:32,XOF128:cn,XOF256:an,securityLevel:128}),af=Io({...un[3],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:48,XOF128:cn,XOF256:an,securityLevel:192}),ff=Io({...un[5],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:64,XOF128:cn,XOF256:an,securityLevel:256})});var gf={};Do(gf,{InMemoryKeyStorage:()=>dt,KeyRegistry:()=>Kt,createKeySDK:()=>Fo,default:()=>yf});var Zo=Object.freeze({p:0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,n:0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,h:1n,a:0n,b:7n,Gx:0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,Gy:0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n}),{p:yt,n:Ge,Gx:oc,Gy:sc,b:Yo}=Zo,me=32,Xt=64,Jt={publicKey:me+1,publicKeyUncompressed:Xt+1,signature:Xt,seed:me+me/2},te=(t="",e=Error)=>{let r=new e(t),{captureStackTrace:n}=Error;throw typeof n=="function"&&n(r,te),r},ic=t=>t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&t.BYTES_PER_ELEMENT===1,Ke=(t,e,r="")=>{let n=ic(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,a=s?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof t}`,f=i+"expected Uint8Array"+a+", got "+c;return n?te(f,RangeError):te(f,TypeError)}return t},Xe=t=>new Uint8Array(t),Go=(t,e)=>t.toString(16).padStart(e,"0"),Xo=t=>{let e="";for(let r of Ke(t))e+=Go(r,2);return e},De={_0:48,_9:57,A:65,F:70,a:97,f:102},$o=t=>t>=De._0&&t<=De._9?t-De._0:t>=De.A&&t<=De.F?t-(De.A-10):t>=De.a&&t<=De.f?t-(De.a-10):void 0,Jo=t=>{let e="hex invalid";if(typeof t!="string")return te(e);let r=t.length,n=r/2;if(r%2)return te(e);let o=Xe(n);for(let s=0,i=0;s<n;s++,i+=2){let a=$o(t.charCodeAt(i)),c=$o(t.charCodeAt(i+1));if(a===void 0||c===void 0)return te(e);o[s]=a*16+c}return o},Ho=()=>globalThis?.crypto?.subtle??te("crypto.subtle must be defined, consider polyfill"),Rt=(...t)=>{let e=0;for(let o of t)e+=Ke(o).length;let r=Xe(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r},Qo=(t=me)=>(globalThis?.crypto).getRandomValues(Xe(t)),Kr=BigInt,tr=(t,e,r,n="bad number: out of range")=>typeof t!="bigint"?te(n,TypeError):e<=t&&t<r?t:te(n,RangeError),U=(t,e=yt)=>{let r=t%e;return r>=0n?r:e+r},Ye=t=>U(t,Ge),kn=(t,e)=>{(t===0n||e<=0n)&&te("no inverse n="+t+" mod="+e);let r=U(t,e),n=e,o=0n,s=1n,i=1n,a=0n;for(;r!==0n;){let c=n/r,f=n%r,u=o-i*c,d=s-a*c;n=r,r=f,o=i,s=a,i=u,a=d}return n===1n?U(o,e):te("no inverse")},es=t=>{let e=Ur[t];return typeof e!="function"&&te("hashes."+t+" not set"),e},ts=(t,e,r)=>Ke(es(t)(e,r),me,"digest"),cc=(t,e,r)=>Promise.resolve(es(t)(e,r)).then(n=>Ke(n,me,"digest"));var En=t=>t instanceof $e?t:te("Point expected"),rs=t=>U(U(t*t)*t+Yo),jo=t=>tr(t,0n,yt),Tr=t=>tr(t,1n,yt),vn=t=>tr(t,1n,Ge),ns=t=>!(t&1n),rr=t=>Uint8Array.of(t),ac=t=>rr(ns(t)?2:3),fc=t=>{let e=rs(Tr(t)),r=1n;for(let n=e,o=(yt+1n)/4n;o>0n;o>>=1n)o&1n&&(r=r*n%yt),n=n*n%yt;return U(r*r)!==e&&te("sqrt invalid"),ns(r)?r:U(-r)};var _e=class _e{constructor(e,r,n){h(this,"X");h(this,"Y");h(this,"Z");this.X=jo(e),this.Y=Tr(r),this.Z=jo(n),Object.freeze(this)}static CURVE(){return Zo}static fromAffine(e){let{x:r,y:n}=e;return r===0n&&n===0n?pt:new _e(r,n,1n)}static fromBytes(e){Ke(e);let{publicKey:r,publicKeyUncompressed:n}=Jt,o,s=e.length,i=e[0],a=e.subarray(1),c=Ir(a,0,me);if(s===r&&(i===2||i===3)){let f=fc(c);i===3&&(f=U(-f)),o=new _e(c,f,1n)}return s===n&&i===4&&(o=new _e(c,Ir(a,me,Xt),1n)),o?o.assertValidity():te("bad point: not on curve")}static fromHex(e){return _e.fromBytes(Jo(e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}equals(e){let{X:r,Y:n,Z:o}=this,{X:s,Y:i,Z:a}=En(e),c=U(r*a),f=U(s*o),u=U(n*a),d=U(i*o);return c===f&&u===d}is0(){return this.equals(pt)}negate(){return new _e(this.X,U(-this.Y),this.Z)}double(){return this.add(this)}add(e){let{X:r,Y:n,Z:o}=this,{X:s,Y:i,Z:a}=En(e),c=0n,f=Yo,u=0n,d=0n,l=0n,p=U(f*3n),y=U(r*s),b=U(n*i),A=U(o*a),_=U(r+n),I=U(s+i);_=U(_*I),I=U(y+b),_=U(_-I),I=U(r+o);let E=U(s+a);return I=U(I*E),E=U(y+A),I=U(I-E),E=U(n+o),u=U(i+a),E=U(E*u),u=U(b+A),E=U(E-u),l=U(c*I),u=U(p*A),l=U(u+l),u=U(b-l),l=U(b+l),d=U(u*l),b=U(y+y),b=U(b+y),A=U(c*A),I=U(p*I),b=U(b+A),A=U(y-A),A=U(c*A),I=U(I+A),y=U(b*I),d=U(d+y),y=U(E*I),u=U(_*u),u=U(u-y),y=U(_*b),l=U(E*l),l=U(l+y),new _e(u,d,l)}subtract(e){return this.add(En(e).negate())}multiply(e,r=!0){if(!r&&e===0n)return pt;if(vn(e),e===1n)return this;if(this.equals(Je))return Bc(e).p;let n=pt,o=Je;for(let s=this;e>0n;s=s.double(),e>>=1n)e&1n?n=n.add(s):r&&(o=o.add(s));return n}multiplyUnsafe(e){return this.multiply(e,!1)}toAffine(){let{X:e,Y:r,Z:n}=this;if(this.equals(pt))return{x:0n,y:0n};if(n===1n)return{x:e,y:r};let o=kn(n,yt);return U(n*o)!==1n&&te("inverse invalid"),{x:U(e*o),y:U(r*o)}}assertValidity(){let{x:e,y:r}=this.toAffine();return Tr(e),Tr(r),U(r*r)===rs(e)?this:te("bad point: not on curve")}toBytes(e=!0){let{x:r,y:n}=this.assertValidity().toAffine(),o=Ot(r);return e?Rt(ac(n),o):Rt(rr(4),o,Ot(n))}toHex(e){return Xo(this.toBytes(e))}};h(_e,"BASE"),h(_e,"ZERO");var $e=_e,Je=new $e(oc,sc,1n),pt=new $e(0n,1n,0n);$e.BASE=Je;$e.ZERO=pt;var uc=(t,e,r)=>Je.multiply(e,!1).add(t.multiply(r,!1)).assertValidity(),_r=t=>Kr("0x"+(Xo(t)||"0")),Ir=(t,e,r)=>_r(t.subarray(e,r)),lc=2n**256n,Ot=t=>Jo(Go(tr(t,0n,lc),Xt)),An=t=>{let e=_r(Ke(t,me,"secret key"));return tr(e,1n,Ge,"invalid secret key: outside of range")},Bn=t=>t>Ge>>1n,os=(t,e=!0)=>Je.multiply(An(t)).toBytes(e),dc=t=>{try{return!!An(t)}catch{return!1}},hc=(t,e)=>{let{publicKey:r,publicKeyUncompressed:n}=Jt;try{let o=t.length;return e===!0&&o!==r||e===!1&&o!==n?!1:!!$e.fromBytes(t)}catch{return!1}},zo=t=>[0,1,2,3].includes(t)?t:te("invalid recovery id"),Tn=t=>{t===pc&&te('Signature format "der" is not supported: switch to noble-curves'),t!=null&&t!==er&&t!==Rr&&te("Signature format must be one of: compact, recovered, der")},ss=(t,e=er)=>{Tn(e);let r=Jt.signature+ +(e===Rr);t.length!==r&&te(`Signature format "${e}" expects Uint8Array with length ${r}`)},Qt=class t{constructor(e,r,n){h(this,"r");h(this,"s");h(this,"recovery");this.r=vn(e),this.s=vn(r),n!=null&&(this.recovery=zo(n)),Object.freeze(this)}static fromBytes(e,r=er){ss(e,r);let n;r===Rr&&(n=e[0],e=e.subarray(1));let o=Ir(e,0,me),s=Ir(e,me,Xt);return new t(o,s,n)}addRecoveryBit(e){return new t(this.r,this.s,e)}hasHighS(){return Bn(this.s)}toBytes(e=er){Tn(e);let{r,s:n,recovery:o}=this,s=Rt(Ot(r),Ot(n));return e===Rr?Rt(rr(zo(o)),s):s}},is=t=>{t.length>8192&&te("input is too large");let e=t.length*8-256,r=_r(t);return e>0?r>>Kr(e):r},cs=t=>Ye(is(Ke(t))),er="compact",Rr="recovered",pc="der",qo="SHA-256",Ur={hmacSha256Async:async(t,e)=>{let r=Ho(),n="HMAC",o=await r.importKey("raw",t,{name:n,hash:{name:qo}},!1,["sign"]);return Xe(await r.sign(n,o,e))},hmacSha256:void 0,sha256Async:async t=>Xe(await Ho().digest(qo,t)),sha256:void 0},as=(t,e,r)=>{let n=Ke(t,void 0,"message");return e.prehash?r?cc("sha256Async",n):ts("sha256",n):n},yc=Xe(0),gc=rr(0),mc=rr(1),bc=1e3,wc="drbg: tried max amount of iterations",xc=(t,e)=>{let r=Xe(me),n=Xe(me),o=0,s=()=>{r.fill(1),n.fill(0)},i=(...u)=>ts("hmacSha256",n,Rt(r,...u)),a=(u=yc)=>{n=i(gc,u),r=i(),u.length!==0&&(n=i(mc,u),r=i())},c=()=>(o++>=bc&&te(wc),r=i(),r);s(),a(t);let f;for(;!(f=e(c()));)a();return s(),f};var Ec=(t,e,r,n)=>{let{lowS:o,extraEntropy:s}=r,i=Ot,a=cs(t),c=i(a),f=An(e),u=[i(f),c];if(s!=null&&s!==!1){let y=s===!0?Qo(me):s;u.push(Ke(y,void 0,"extraEntropy"))}let d=Rt(...u),l=a;return n(d,y=>{let b=is(y);if(!(1n<=b&&b<Ge))return;let A=kn(b,Ge),_=Je.multiply(b).toAffine(),I=Ye(_.x);if(I===0n)return;let E=Ye(A*Ye(l+I*f));if(E===0n)return;let S=(_.x===I?0:2)|Number(_.y&1n),N=E;return o&&Bn(E)&&(N=Ye(-E),S^=1),new Qt(I,N,S).toBytes(r.format)})},vc=(t,e,r,n={})=>{let{lowS:o,format:s}=n;t instanceof Qt&&te("Signature must be in Uint8Array, use .toBytes()"),ss(t,s),Ke(r,void 0,"publicKey");try{let{r:i,s:a}=Qt.fromBytes(t,s),c=cs(e),f=$e.fromBytes(r);if(o&&Bn(a))return!1;let u=kn(a,Ge),d=Ye(c*u),l=Ye(i*u),p=uc(f,d,l).toAffine();return Ye(p.x)===i}catch{return!1}},fs=t=>({lowS:t.lowS??!0,prehash:t.prehash??!0,format:t.format??er,extraEntropy:t.extraEntropy??!1}),us=(t,e,r={})=>{r=fs(r),Tn(r.format);let n=as(t,r,!1);return Ec(n,e,r,xc)};var ls=(t,e,r,n={})=>{n=fs(n);let o=as(e,n,!1);return vc(t,o,r,n)};var Sc=t=>{if(t=t===void 0?Qo(Jt.seed):t,Ke(t),t.length<Jt.seed||t.length>1024)return te("expected 48-1024b",RangeError);let e=U(_r(t),Ge-1n);return Ot(e+1n)};var Cr=Object.freeze({isValidSecretKey:dc,isValidPublicKey:hc,randomSecretKey:Sc});var Or=8,kc=256,ds=Math.ceil(kc/Or)+1,Sn=2**(Or-1),Ac=()=>{let t=[],e=Je,r=e;for(let n=0;n<ds;n++){r=e,t.push(r);for(let o=1;o<Sn;o++)r=r.add(e),t.push(r);e=r.double()}return t},Vo,Wo=(t,e)=>{let r=e.negate();return t?r:e},Bc=t=>{let e=Vo||(Vo=Ac()),r=pt,n=Je,o=2**Or,s=o,i=Kr(o-1),a=Kr(Or);for(let c=0;c<ds;c++){let f=Number(t&i);t>>=a,f>Sn&&(f-=s,t+=1n);let u=c*Sn,d=u,l=u+Math.abs(f)-1,p=c%2!==0,y=f<0;f===0?n=n.add(Wo(p,e[d])):r=r.add(Wo(y,e[l]))}return t!==0n&&te("invalid wnaf"),{p:r,f:n}};Be();var Mr=class{constructor(e,r){h(this,"oHash");h(this,"iHash");h(this,"blockLen");h(this,"outputLen");h(this,"canXOF",!1);h(this,"finished",!1);h(this,"destroyed",!1);if(Qe(e),j(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),ge(o)}update(e){return He(this),this.iHash.update(e),this}digestInto(e){He(this),Ut(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a,canXOF:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},je=(()=>{let t=((e,r,n)=>new Mr(e,r).update(n).digest());return t.create=(e,r)=>new Mr(e,r),t})();Dr();Be();function Cn(t,e,r){return t&e^~t&r}function Ln(t,e,r){return t&e^t&r^e&r}var wt=class{constructor(e,r,n,o){h(this,"blockLen");h(this,"outputLen");h(this,"canXOF",!1);h(this,"padOffset");h(this,"isLE");h(this,"buffer");h(this,"view");h(this,"finished",!1);h(this,"length",0);h(this,"pos",0);h(this,"destroyed",!1);this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Ue(this.buffer)}update(e){He(this),j(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let f=Ue(e);for(;o<=s-a;a+=o)this.process(f,a);i=!0;continue}n.set(a===0&&c===s?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){He(this),Ut(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>o-i&&(this.process(n,0),r.fill(0)),ws(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=e===r?n:Ue(e),c=this.outputLen,f=c/4,u=this.get();if(c%4||f>u.length)throw new Error("invalid outputLen");for(let d=0;d<f;d++)a.setUint32(4*d,u[d],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return e.destroyed=s,e.finished=o,e.length=n,e.pos=i,i&&e.buffer.set(r),e}clone(){return this._cloneInto()}},Bs=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Ts=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);Dr();Be();var Fc=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),tt=new Uint32Array(64),Fn=class extends wt{constructor(r,n){super(64,r,8,!1);h(this,"A",0);h(this,"B",0);h(this,"C",0);h(this,"D",0);h(this,"E",0);h(this,"F",0);h(this,"G",0);h(this,"H",0);this.A=n[0]|0,this.B=n[1]|0,this.C=n[2]|0,this.D=n[3]|0,this.E=n[4]|0,this.F=n[5]|0,this.G=n[6]|0,this.H=n[7]|0}get(){let{A:r,B:n,C:o,D:s,E:i,F:a,G:c,H:f}=this;return[r,n,o,s,i,a,c,f]}set(r,n,o,s,i,a,c,f){this.A=r|0,this.B=n|0,this.C=o|0,this.D=s|0,this.E=i|0,this.F=a|0,this.G=c|0,this.H=f|0}_cloneInto(r){return(r||(r=new this.constructor)).set(...this.get()),this._cloneIntoMeta(r)}process(r,n){for(let l=0;l<16;l++,n+=4)tt[l]=r.getUint32(n,!1);for(let l=16;l<64;l++){let p=tt[l-15],y=tt[l-2],b=Ie(p,7)^Ie(p,18)^p>>>3,A=Ie(y,17)^Ie(y,19)^y>>>10;tt[l]=A+tt[l-7]+b+tt[l-16]|0}let{A:o,B:s,C:i,D:a,E:c,F:f,G:u,H:d}=this;for(let l=0;l<64;l++){let p=Ie(c,6)^Ie(c,11)^Ie(c,25),y=d+p+Cn(c,f,u)+Fc[l]+tt[l]|0,A=(Ie(o,2)^Ie(o,13)^Ie(o,22))+Ln(o,s,i)|0;d=u,u=f,f=c,c=a+y|0,a=i,i=s,s=o,o=y+A|0}o=o+this.A|0,s=s+this.B|0,i=i+this.C|0,a=a+this.D|0,c=c+this.E|0,f=f+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(o,s,i,a,c,f,u,d)}roundClean(){ge(tt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),ge(this.buffer)}},Mn=class extends Fn{constructor(){super(32,Bs)}};var Ks=Nr(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),Mc=Ks[0],Pc=Ks[1],rt=new Uint32Array(80),nt=new Uint32Array(80),Pn=class extends wt{constructor(r,n){super(128,r,16,!1);h(this,"Ah",0);h(this,"Al",0);h(this,"Bh",0);h(this,"Bl",0);h(this,"Ch",0);h(this,"Cl",0);h(this,"Dh",0);h(this,"Dl",0);h(this,"Eh",0);h(this,"El",0);h(this,"Fh",0);h(this,"Fl",0);h(this,"Gh",0);h(this,"Gl",0);h(this,"Hh",0);h(this,"Hl",0);this.Ah=n[0]|0,this.Al=n[1]|0,this.Bh=n[2]|0,this.Bl=n[3]|0,this.Ch=n[4]|0,this.Cl=n[5]|0,this.Dh=n[6]|0,this.Dl=n[7]|0,this.Eh=n[8]|0,this.El=n[9]|0,this.Fh=n[10]|0,this.Fl=n[11]|0,this.Gh=n[12]|0,this.Gl=n[13]|0,this.Hh=n[14]|0,this.Hl=n[15]|0}get(){let{Ah:r,Al:n,Bh:o,Bl:s,Ch:i,Cl:a,Dh:c,Dl:f,Eh:u,El:d,Fh:l,Fl:p,Gh:y,Gl:b,Hh:A,Hl:_}=this;return[r,n,o,s,i,a,c,f,u,d,l,p,y,b,A,_]}set(r,n,o,s,i,a,c,f,u,d,l,p,y,b,A,_){this.Ah=r|0,this.Al=n|0,this.Bh=o|0,this.Bl=s|0,this.Ch=i|0,this.Cl=a|0,this.Dh=c|0,this.Dl=f|0,this.Eh=u|0,this.El=d|0,this.Fh=l|0,this.Fl=p|0,this.Gh=y|0,this.Gl=b|0,this.Hh=A|0,this.Hl=_|0}_cloneInto(r){return(r||(r=new this.constructor)).set(...this.get()),this._cloneIntoMeta(r)}process(r,n){for(let S=0;S<16;S++,n+=4)rt[S]=r.getUint32(n),nt[S]=r.getUint32(n+=4);for(let S=16;S<80;S++){let N=rt[S-15]|0,H=nt[S-15]|0,V=mt(N,H,1)^mt(N,H,8)^_n(N,H,7),W=bt(N,H,1)^bt(N,H,8)^Un(N,H,7),Z=rt[S-2]|0,D=nt[S-2]|0,ee=mt(Z,D,19)^sr(Z,D,61)^_n(Z,D,6),X=bt(Z,D,19)^ir(Z,D,61)^Un(Z,D,6),ye=vs(W,X,nt[S-7],nt[S-16]),de=Ss(ye,V,ee,rt[S-7],rt[S-16]);rt[S]=de|0,nt[S]=ye|0}let{Ah:o,Al:s,Bh:i,Bl:a,Ch:c,Cl:f,Dh:u,Dl:d,Eh:l,El:p,Fh:y,Fl:b,Gh:A,Gl:_,Hh:I,Hl:E}=this;for(let S=0;S<80;S++){let N=mt(l,p,14)^mt(l,p,18)^sr(l,p,41),H=bt(l,p,14)^bt(l,p,18)^ir(l,p,41),V=l&y^~l&A,W=p&b^~p&_,Z=ks(E,H,W,Pc[S],nt[S]),D=As(Z,I,N,V,Mc[S],rt[S]),ee=Z|0,X=mt(o,s,28)^sr(o,s,34)^sr(o,s,39),ye=bt(o,s,28)^ir(o,s,34)^ir(o,s,39),de=o&i^o&c^i&c,q=s&a^s&f^a&f;I=A|0,E=_|0,A=y|0,_=b|0,y=l|0,b=p|0,{h:l,l:p}=Le(u|0,d|0,D|0,ee|0),u=c|0,d=f|0,c=i|0,f=a|0,i=o|0,a=s|0;let z=xs(ee,ye,q);o=Es(z,D,X,de),s=z|0}({h:o,l:s}=Le(this.Ah|0,this.Al|0,o|0,s|0)),{h:i,l:a}=Le(this.Bh|0,this.Bl|0,i|0,a|0),{h:c,l:f}=Le(this.Ch|0,this.Cl|0,c|0,f|0),{h:u,l:d}=Le(this.Dh|0,this.Dl|0,u|0,d|0),{h:l,l:p}=Le(this.Eh|0,this.El|0,l|0,p|0),{h:y,l:b}=Le(this.Fh|0,this.Fl|0,y|0,b|0),{h:A,l:_}=Le(this.Gh|0,this.Gl|0,A|0,_|0),{h:I,l:E}=Le(this.Hh|0,this.Hl|0,I|0,E|0),this.set(o,s,i,a,c,f,u,d,l,p,y,b,A,_,I,E)}roundClean(){ge(rt,nt)}destroy(){this.destroyed=!0,ge(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Nn=class extends Pn{constructor(){super(64,Ts)}};var he=et(()=>new Mn,gt(1));var xt=et(()=>new Nn,gt(3));Hr();function ar(t){return Array.from(t).map(e=>e.toString(16).padStart(2,"0")).join("")}function Ft(t){if(typeof t!="string")throw new Error("Hex input must be a string");if(t.length%2!==0)throw new Error("Hex string must have even length");if(!/^[0-9a-fA-F]*$/.test(t))throw new Error("Hex string contains a non-hex character");let e=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)e[r/2]=parseInt(t.slice(r,r+2),16);return e}async function jr(t,e){if(e==="sha256")return he(t);if(e==="sha512")return xt(t);if(e==="sha3-256")return Ls(t);throw new Error(`Unsupported hash algorithm: ${e}`)}vt();Jr();var Jn=BigInt(0),dr=BigInt(1),fa=BigInt(4),Gn=16,ei=128,ua=5,ti=2**31;function Ht(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Et(e.fromAffine,"Point.fromAffine"),Et(e.fromBytes,"Point.fromBytes"),Et(e.fromHex,"Point.fromHex"),ot(e.BASE,"Point.BASE"),ot(e.ZERO,"Point.ZERO"),Dt(e.Fp),Dt(e.Fn)}function ni(t,e){Ht(t),oi(e,t);let r=Yn(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function la(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function da(t,e){let r=t*(4*e+128);if(r>ti)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+ti/2**20+" MiB")}function Qn(t,e){if(t!==void 0){Et(t,"randomBytes");try{let r=t(e);if(!Mt(r)||r.length!==e)return}catch{return}return t}}function oi(t,e){fr(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function ha(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,o)=>{if(!(r===void 0?e.isValid(n):st(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var si=new WeakMap;function Xn(t){return si.get(t)||1}function pa(t,e){let r=t.double(),n=[t];for(let o=1;o<e;o++)n.push(n[o-1].add(r));return n}function ya(t,e){let r=2**e,n=r/2,o=BigInt(r-1),s=[];for(;t>Jn;){let i=0;t&dr&&(i=Number(t&o),i>=n&&(i-=r),t-=BigInt(i)),s.push(i),t>>=dr}return s}function ga(t,e,r){let n=2**e,o=n/2,s=BigInt(n-1),i=BigInt(e),a=[];for(let c=0;c<r;c++){let f=Number(t&s);t>>=i,f>o&&(f-=n,t+=dr),a.push(f)}if(t!==Jn)throw new Error("invalid wnaf");return a}function ma(t,e,r){let n=0;for(let s of r)n=Math.max(n,s.length);let o=t;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<r.length;i++){let a=r[i][s];if(a){let c=e[i][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var Qr=class{constructor(e,r){h(this,"Point");h(this,"BASE");h(this,"ZERO");h(this,"randomBytes");h(this,"wnafPrecomputes",new WeakMap);h(this,"baseCanBeBlinded");h(this,"bits");Ht(e),this.randomBytes=Qn(r,Gn),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let o=Math.ceil(n/r)+1,s=2**(r-1),i=[],a=e;for(let c=0;c<o;c++){let f=a;for(let u=0;u<s;u++)i.push(f),f=f.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:o,comp:i}}wnafCachedCT(e,r){let{W:n,windows:o,comp:s}=e,i=2**(n-1),a=ga(r,n,o),c=this.ZERO,f=this.BASE;for(let u=0;u<o;u++){let d=a[u],l=u*i,p=Math.abs(d)-1,y=s[l];for(let A=1;A<i;A++)y=A===p?s[l+A]:y;let b=y.negate();d===0?f=f.add(s[l]):c=c.add(d<0?b:y)}return{p:c,f}}getWnafPrecomputes(e,r,n,o){let s=this.wnafPrecomputes.get(r),i=s?.find(a=>a.W===e&&a.bits===n);return i||(i=this.buildWnafTable(r,e,n),typeof o=="function"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(r,s)),s.push(i)),i}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!zn(r,dr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,o){let s=Xn(e);return s===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(s,e,n,o),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+ei,s=this.randomBytes(Gn);if(!Mt(s)||s.length!==Gn)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+Fe(s)*this.Point.Fn.ORDER;return this.runCT(e,i,o,n)}fixedWindowCT(e,r,n){let o=ua,s=1<<o,i=lr(o),a=new Array(s);a[0]=this.ZERO;for(let u=1;u<s;u++)a[u]=a[u-1].add(e);let c=Math.ceil(n/o),f=this.ZERO;for(let u=c-1;u>=0;u--){if(u!==c-1)for(let p=0;p<o;p++)f=f.double();let d=Number(r>>BigInt(u*o)&i),l=a[0];for(let p=1;p<s;p++)l=p===d?a[p]:l;f=f.add(l)}return{p:f,f}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===dr?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,o){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,o):this.mulCT(e,r,o)}mulUnsafe(e,r,n){if(this.assertPoint(e),!st(r))throw new Error("invalid scalar");let o=Xn(e);if(o===1||r>=this.Point.Fn.ORDER)return en(this.Point,[e],[r],!0);let s=this.getWnafPrecomputes(o,e,this.bits,n);return this.wnafCachedCT(s,r).p}setWindowSize(e,r){this.assertPoint(e),la(r,this.bits);let n=Math.ceil((this.bits+ei)/r)+1;da(n*2**(r-1),this.Point.Fp.BYTES),si.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Xn(e)!==1}};function en(t,e,r,n=!1){if(Ht(t),oi(e,t),Te(n,"allowOversized"),ha(r,t.Fn,n?t.Fn.ORDER**fa:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(i=>pa(i,4)),s=r.map(i=>ya(i,4));return ma(t.ZERO,o,s)}function ri(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Dt(e),e}else return $t(t,{isLE:r})}function ii(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);Me(r);for(let c of["p","n","h"]){let f=e[c];if(!(st(f)&&f!==Jn))throw new Error(`CURVE.${c} must be positive bigint`)}let o=ri(e.p,r.Fp,n),s=ri(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function ci(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}Jr();Be();vt();vt();var ba=BigInt(0),ro=class extends Error{constructor(e=""){super(e)}},qe={Err:ro,_tlv:{encode:(t,e)=>{let{Err:r}=qe;if(Pt(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(Ns(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=ur(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?ur(o.length/2|128):"";return ur(t)+s+o+e},decode(t,e){let{Err:r}=qe;e=ue(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=qe;if(Wr(t),t<ba)throw new e("integer: negative integers are not allowed");let r=ur(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=qe;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Fe(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=qe,o=ue(t,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l:u}=n.decode(2,c);if(u.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(t){let{_tlv:e,_int:r}=qe;Me(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}},no=(Object.freeze(qe._tlv),Object.freeze(qe._int),Object.freeze(qe));Jr();var di=(t,e)=>(t+(t>=0?e:-e)/hi)/e;function wa(t,e,r){qn("scalar",t,Ve,r);let[[n,o],[s,i]]=e,a=di(i*t,r),c=di(-o*t,r),f=t-a*n-c*s,u=-a*o-c*i,d=f<Ve,l=u<Ve;d&&(f=-f),l&&(u=-u);let p=lr(Math.ceil(Nt(r)/2))+St;if(f<Ve||f>=p||u<Ve||u>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:d,k1:f,k2neg:l,k2:u}}function io(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function oo(t,e){Me(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Te(r.lowS,"lowS"),Te(r.prehash,"prehash"),r.format!==void 0&&io(r.format),r}var Ve=BigInt(0),St=BigInt(1),hi=BigInt(2),so=BigInt(3),xa=BigInt(4);function pi(t,e={}){let r=ii("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Me(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:f}=e,u=e.randomBytes===void 0?Vr:e.randomBytes;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let d=gi(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function p(z,k,R){if(f&&k.is0())return Uint8Array.of(0);let{x:L,y:T}=k.toAffine(),m=n.toBytes(L);if(Te(R,"isCompressed"),R){l();let B=!n.isOdd(T);return ze(yi(B),m)}else return ze(Uint8Array.of(4),m,n.toBytes(T))}function y(z){ue(z,void 0,"Point");let{publicKey:k,publicKeyUncompressed:R}=d,L=z.length,T=z[0],m=z.subarray(1);if(f&&L===1&&T===0)return{x:n.ZERO,y:n.ZERO};if(L===k&&(T===2||T===3)){let B=n.fromBytes(m);if(!n.isValid(B))throw new Error("bad point: is not on curve, wrong x");let C=E(B),F;try{F=n.sqrt(C)}catch(w){let x=w instanceof Error?": "+w.message:"";throw new Error("bad point: is not on curve, sqrt error"+x)}l();let M=n.isOdd(F);return(T&1)===1!==M&&(F=n.neg(F)),{x:B,y:F}}else if(L===R&&T===4){let B=n.BYTES,C=n.fromBytes(m.subarray(0,B)),F=n.fromBytes(m.subarray(B,B*2));if(!S(C,F))throw new Error("bad point: is not on curve");return{x:C,y:F}}else throw new Error(`bad point: got length ${L}, expected compressed=${k} or uncompressed=${R}`)}let b=e.toBytes===void 0?p:e.toBytes,A=e.fromBytes===void 0?y:e.fromBytes,_=n.mul(s.b,so),I=n.is0(s.a)?z=>n.ZERO:z=>n.mul(s.a,z);function E(z){let k=n.sqr(z),R=n.mul(k,z);return n.add(n.add(R,n.mul(z,s.a)),s.b)}function S(z,k){let R=n.sqr(k),L=E(z);return n.eql(R,L)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let N=n.mul(n.pow(s.a,so),xa),H=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(N,H)))throw new Error("bad curve params: a or b");function V(z,k,R=!1){if(!n.isValid(k)||R&&n.is0(k))throw new Error(`bad point coordinate ${z}`);return k}function W(z){if(!(z instanceof X))throw new Error("Weierstrass Point expected")}function Z(z){if(!c||!c.basises)throw new Error("no endo");return wa(z,c.basises,o.ORDER)}function D(z,k,R,L){if(!o.isValid(L))throw new RangeError("invalid scalar: out of range");if(c){let{k1neg:T,k1:m,k2neg:B,k2:C}=Z(L),F=new X(n.mul(R.X,c.beta),R.Y,R.Z);z.push(T?R.negate():R,B?F.negate():F),k.push(m,C)}else z.push(R),k.push(L)}let ee=new WeakSet,q=class q{constructor(k,R,L){h(this,"X");h(this,"Y");h(this,"Z");this.X=V("x",k),this.Y=V("y",R,!0),this.Z=V("z",L),Object.freeze(this)}static CURVE(){return s}static fromAffine(k){let{x:R,y:L}=k||{};if(!k||!n.isValid(R)||!n.isValid(L))throw new Error("invalid affine point");if(k instanceof q)throw new Error("projective point not allowed");return n.is0(R)&&n.is0(L)?q.ZERO:new q(R,L,n.ONE)}static fromBytes(k){let R=q.fromAffine(A(ue(k,void 0,"point")));return R.assertValidity(),R}static fromHex(k){return q.fromBytes(qr(k))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(k=6,R=!0){return de.setWindowSize(this,k),R||this.multiply(so),this}assertValidity(){let k=this;if(k.is0()){if(e.allowInfinityPoint&&n.is0(k.X)&&n.eql(k.Y,n.ONE)&&n.is0(k.Z))return;throw new Error("bad point: ZERO")}if(ee.has(k))return;let{x:R,y:L}=k.toAffine();if(!n.isValid(R)||!n.isValid(L))throw new Error("bad point: x or y not field elements");if(!S(R,L))throw new Error("bad point: equation left != right");if(!k.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");ee.add(k)}hasEvenY(){let{y:k}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(k)}equals(k){W(k);let{X:R,Y:L,Z:T}=this,{X:m,Y:B,Z:C}=k,F=n.eql(n.mul(R,C),n.mul(m,T)),M=n.eql(n.mul(L,C),n.mul(B,T));return F&&M}negate(){return new q(this.X,n.neg(this.Y),this.Z)}double(){let{X:k,Y:R,Z:L}=this,T=n.ZERO,m=n.ZERO,B=n.ZERO,C=n.mul(k,k),F=n.mul(R,R),M=n.mul(L,L),g=n.mul(k,R);return g=n.add(g,g),B=n.mul(k,L),B=n.add(B,B),T=I(B),m=n.mul(_,M),m=n.add(T,m),T=n.sub(F,m),m=n.add(F,m),m=n.mul(T,m),T=n.mul(g,T),B=n.mul(_,B),M=I(M),g=n.sub(C,M),g=I(g),g=n.add(g,B),B=n.add(C,C),C=n.add(B,C),C=n.add(C,M),C=n.mul(C,g),m=n.add(m,C),M=n.mul(R,L),M=n.add(M,M),C=n.mul(M,g),T=n.sub(T,C),B=n.mul(M,F),B=n.add(B,B),B=n.add(B,B),new q(T,m,B)}add(k){W(k);let{X:R,Y:L,Z:T}=this,{X:m,Y:B,Z:C}=k,F=n.ZERO,M=n.ZERO,g=n.ZERO,w=n.mul(R,m),x=n.mul(L,B),v=n.mul(T,C),O=n.add(R,L),K=n.add(m,B);O=n.mul(O,K),K=n.add(w,x),O=n.sub(O,K),K=n.add(R,T);let P=n.add(m,C);return K=n.mul(K,P),P=n.add(w,v),K=n.sub(K,P),P=n.add(L,T),F=n.add(B,C),P=n.mul(P,F),F=n.add(x,v),P=n.sub(P,F),g=I(K),F=n.mul(_,v),g=n.add(F,g),F=n.sub(x,g),g=n.add(x,g),M=n.mul(F,g),x=n.add(w,w),x=n.add(x,w),v=I(v),K=n.mul(_,K),x=n.add(x,v),v=n.sub(w,v),v=I(v),K=n.add(K,v),w=n.mul(x,K),M=n.add(M,w),w=n.mul(P,K),F=n.mul(O,F),F=n.sub(F,w),w=n.mul(O,x),g=n.mul(P,g),g=n.add(g,w),new q(F,M,g)}subtract(k){return W(k),this.add(k.negate())}is0(){return this.equals(q.ZERO)}multiply(k){if(!o.isValidNot0(k))throw new RangeError("invalid scalar: out of range");let{p:R,f:L}=de.mulSecret(this,k,i,ye);return ye([R,L])[0]}multiplyUnsafe(k){let R=this,L=k;if(!o.isValid(L))throw new RangeError("invalid scalar: out of range");if(L===Ve||R.is0())return q.ZERO;if(L===St)return R;if(de.hasWindowSize(this))return de.mulUnsafe(R,L,ye);let T=[],m=[];return D(T,m,R,L),en(q,T,m)}mulAddUnsafe(k,R,L){W(R);let T=[],m=[];return D(T,m,this,k),D(T,m,R,L),en(q,T,m)}toAffine(k){let R=this,L=k;if(L!=null&&!n.isValid(L))throw new RangeError('"invertedZ" expected valid field element');let{X:T,Y:m,Z:B}=R;if(n.eql(B,n.ONE))return{x:T,y:m};let C=R.is0();L==null&&(L=C?n.ONE:n.inv(B));let F=n.mul(T,L),M=n.mul(m,L),g=n.mul(B,L);if(C)return{x:n.ZERO,y:n.ZERO};if(!n.eql(g,n.ONE))throw new Error("invZ was invalid");return{x:F,y:M}}isTorsionFree(){let{isTorsionFree:k}=e;return i===St?!0:k?k(q,this):de.mulUnsafe(this,a).is0()}clearCofactor(){let{clearCofactor:k}=e;return i===St?this:k?k(q,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===St?this.is0():this.clearCofactor().is0()}toBytes(k=!0){return Te(k,"isCompressed"),this.assertValidity(),b(q,this,k)}toHex(k=!0){return $n(this.toBytes(k))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}};h(q,"BASE",new q(s.Gx,s.Gy,n.ONE)),h(q,"ZERO",new q(n.ZERO,n.ONE,n.ZERO)),h(q,"Fp",n),h(q,"Fn",o);let X=q,ye=z=>ni(X,z),de=new Qr(X,u);return de.bits>=6&&X.BASE.precompute(6),Object.freeze(X.prototype),Object.freeze(X),X}function yi(t){return Uint8Array.of(t?2:3)}function gi(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Ea(t,e={}){Ht(t);let{Fn:r}=t,n=e.randomBytes===void 0?Vr:e.randomBytes,o=Object.assign(gi(t.Fp,r),{seed:Math.max(Gr(r.ORDER),16)});function s(p){try{let y=r.fromBytes(p);return r.isValidNot0(y)}catch{return!1}}function i(p,y){let{publicKey:b,publicKeyUncompressed:A}=o;try{let _=p.length;return y===!0&&_!==b||y===!1&&_!==A?!1:!!t.fromBytes(p)}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,Xr(ue(p,o.seed,"seed"),r.ORDER)}function c(p,y=!0){return t.BASE.multiply(r.fromBytes(p)).toBytes(y)}function f(p){let{secretKey:y,publicKey:b,publicKeyUncompressed:A}=o,_=r._lengths;if(!Mt(p))return;let I=ue(p,void 0,"key").length,E=I===b||I===A,S=I===y||!!_?.includes(I);if(!(E&&S))return E}function u(p,y,b=!0){if(f(p)===!0)throw new Error("first arg must be private key");if(f(y)===!1)throw new Error("second arg must be public key");let A=r.fromBytes(p);return t.fromBytes(y).multiply(A).toBytes(b)}let d={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},l=ci(a,c);return Object.freeze(d),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:l,Point:t,utils:d,lengths:o})}function mi(t,e,r={}){Ht(t);let n=e;Qe(n),Me(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?Vr:o.randomBytes,i=o.hmac===void 0?(T,m)=>je(n,T,m):o.hmac,{Fp:a,Fn:c}=t,{ORDER:f,BITS:u}=c,d=Gr(f),l=Qn(s,d),{keygen:p,getPublicKey:y,getSharedSecret:b,utils:A,lengths:_}=Ea(t,o),I={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},E=f*hi+St<a.ORDER;function S(T){let m=f>>St;return T>m}function N(T,m){if(!c.isValidNot0(m))throw new Error(`invalid signature ${T}: out of range 1..Point.Fn.ORDER`);return m}function H(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function V(T,m,B){return H(),(T===B?0:2)|Number(a.isOdd(m))}function W(){if(E)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function Z(T,m){io(m);let B=_.signature,C=m==="compact"?B:m==="recovered"?B+1:void 0;return ue(T,C)}class D{constructor(m,B,C){h(this,"r");h(this,"s");h(this,"recovery");if(this.r=N("r",m),this.s=N("s",B),C!=null){if(W(),![0,1,2,3].includes(C))throw new Error("invalid recovery id");this.recovery=C}Object.freeze(this)}static fromBytes(m,B=I.format){Z(m,B);let C;if(B==="der"){let{r:w,s:x}=no.toSig(ue(m));return new D(w,x)}B==="recovered"&&(C=m[0],B="compact",m=m.subarray(1));let F=_.signature/2,M=m.subarray(0,F),g=m.subarray(F,F*2);return new D(c.fromBytes(M),c.fromBytes(g),C)}static fromHex(m,B){return this.fromBytes(qr(m),B)}assertRecovery(){let{recovery:m}=this;if(m==null)throw new Error("invalid recovery id: must be present");return m}addRecoveryBit(m){return new D(this.r,this.s,m)}recoverPublicKey(m){let{r:B,s:C}=this,F=this.assertRecovery(),M=F===2||F===3?B+f:B;if(!a.isValid(M))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let g=a.toBytes(M),w=t.fromBytes(ze(yi((F&1)===0),g)),x=c.inv(M),v=X(ue(m,void 0,"msgHash")),O=c.create(-v*x),K=c.create(C*x),P=t.BASE.mulAddUnsafe(O,w,K);if(P.is0())throw new Error("invalid recovery: point at infinify");return P.assertValidity(),P}hasHighS(){return S(this.s)}toBytes(m=I.format){if(io(m),m==="der")return qr(no.hexFromSig(this));let{r:B,s:C}=this,F=c.toBytes(B),M=c.toBytes(C);return m==="recovered"?(W(),ze(Uint8Array.of(this.assertRecovery()),F,M)):ze(F,M)}toHex(m){return $n(this.toBytes(m))}}Object.freeze(D.prototype),Object.freeze(D);let ee=o.bits2int===void 0?function(m){if(m.length>8192)throw new Error("input is too large");let B=Fe(m),C=m.length*8-u;return C>0?B>>BigInt(C):B}:o.bits2int,X=o.bits2int_modN===void 0?function(m){return c.create(ee(m))}:o.bits2int_modN,ye=lr(u);function de(T){return qn("num < 2^"+u,T,Ve,ye),c.toBytes(T)}function q(T,m){return ue(T,void 0,"message"),m?ue(n(T),void 0,"prehashed message"):T}function z(T,m,B){let{lowS:C,prehash:F,extraEntropy:M}=oo(B,I);T=q(T,F);let g=X(T),w=c.fromBytes(m);if(!c.isValidNot0(w))throw new Error("invalid private key");let x=[de(w),de(g)];if(M!=null&&M!==!1){let P=M===!0?s(_.secretKey):M;x.push(ue(P,void 0,"extraEntropy"))}let v=ze(...x),O=g;function K(P){let J=ee(P);if(!c.isValidNot0(J))return;let ae=t.BASE.multiply(J).toAffine(),re=c.create(ae.x);if(re===Ve)return;let Q;if(l!==void 0){let ce=Fe(Xr(l(d),f)),xe=c.inv(c.mul(ce,J)),Oe=c.mul(ce,O),Pe=c.mul(ce,w);Q=c.create(xe*c.create(Oe+Pe*re))}else{let ce=Gs(J,f);Q=c.create(ce*c.create(O+re*w))}if(Q===Ve)return;let fe=V(ae.x,ae.y,re),we=Q;return C&&S(Q)&&(we=c.neg(Q),fe^=1),new D(re,we,E?void 0:fe)}return{seed:v,k2sig:K}}function k(T,m,B={}){let{seed:C,k2sig:F}=z(T,m,B);return $s(n.outputLen,c.BYTES,i)(C,F).toBytes(B.format)}function R(T,m,B,C={}){let{lowS:F,prehash:M,format:g}=oo(C,I);if(B=ue(B,void 0,"publicKey"),m=q(m,M),!Mt(T)){let w=T instanceof D?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+w)}Z(T,g);try{let w=D.fromBytes(T,g),x=t.fromBytes(B);if(F&&w.hasHighS())return!1;let{r:v,s:O}=w,K=X(m),P=c.inv(O),J=c.create(K*P),ae=c.create(v*P),re=t.BASE.mulAddUnsafe(J,x,ae);if(re.is0())return!1;let Q=re.toAffine();return!(c.create(Q.x)!==v||g==="recovered"&&w.recovery!==V(Q.x,Q.y,v))}catch{return!1}}function L(T,m,B={}){let{prehash:C}=oo(B,I);return m=q(m,C),D.fromBytes(T,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:p,getPublicKey:y,getSharedSecret:b,utils:A,lengths:_,Point:t,sign:k,verify:R,recoverPublicKey:L,Signature:D,hash:n})}var ao={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},va={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var bi=BigInt(2);function Sa(t){let e=ao.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=t*t*t%e,u=f*f*t%e,d=Se(u,r,e)*u%e,l=Se(d,r,e)*u%e,p=Se(l,bi,e)*f%e,y=Se(p,o,e)*p%e,b=Se(y,s,e)*y%e,A=Se(b,a,e)*b%e,_=Se(A,c,e)*A%e,I=Se(_,a,e)*b%e,E=Se(I,r,e)*u%e,S=Se(E,i,e)*y%e,N=Se(S,n,e)*f%e,H=Se(N,bi,e);if(!co.eql(co.sqr(H),t))throw new Error("Cannot find square root");return H}var co=$t(ao.p,{sqrt:Sa}),ka=pi(ao,{Fp:co,endo:va}),jt=mi(ka,he);Be();var Aa=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),xi=Uint8Array.from(new Array(16).fill(0).map((t,e)=>e)),Ba=xi.map(t=>(9*t+5)%16),Ei=(()=>{let r=[[xi],[Ba]];for(let n=0;n<4;n++)for(let o of r)o.push(o[n].map(s=>Aa[s]));return r})(),vi=Ei[0],Si=Ei[1],ki=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(t=>Uint8Array.from(t)),Ta=vi.map((t,e)=>t.map(r=>ki[e][r])),Ka=Si.map((t,e)=>t.map(r=>ki[e][r])),Ia=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),Ra=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function wi(t,e,r,n){return t===0?e^r^n:t===1?e&r|~e&n:t===2?(e|~r)^n:t===3?e&n|r&~n:e^(r|~n)}var tn=new Uint32Array(16),fo=class extends wt{constructor(){super(64,20,8,!0);h(this,"h0",1732584193);h(this,"h1",-271733879);h(this,"h2",-1732584194);h(this,"h3",271733878);h(this,"h4",-1009589776)}get(){let{h0:r,h1:n,h2:o,h3:s,h4:i}=this;return[r,n,o,s,i]}set(r,n,o,s,i){this.h0=r|0,this.h1=n|0,this.h2=o|0,this.h3=s|0,this.h4=i|0}_cloneInto(r){return(r||(r=new this.constructor)).set(...this.get()),this._cloneIntoMeta(r)}process(r,n){for(let y=0;y<16;y++,n+=4)tn[y]=r.getUint32(n,!0);let o=this.h0|0,s=o,i=this.h1|0,a=i,c=this.h2|0,f=c,u=this.h3|0,d=u,l=this.h4|0,p=l;for(let y=0;y<5;y++){let b=4-y,A=Ia[y],_=Ra[y],I=vi[y],E=Si[y],S=Ta[y],N=Ka[y];for(let H=0;H<16;H++){let V=nr(o+wi(y,i,c,u)+tn[I[H]]+A,S[H])+l|0;o=l,l=u,u=nr(c,10)|0,c=i,i=V}for(let H=0;H<16;H++){let V=nr(s+wi(b,a,f,d)+tn[E[H]]+_,N[H])+p|0;s=p,p=d,d=nr(f,10)|0,f=a,a=V}}this.set(this.h1+c+d|0,this.h2+u+p|0,this.h3+l+s|0,this.h4+o+a|0,this.h0+i+f|0)}roundClean(){ge(tn)}destroy(){this.destroyed=!0,ge(this.buffer),this.set(0,0,0,0,0)}},Ai=et(()=>new fo);Be();var Oa=t=>Object.freeze(t());function _a(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function rn(t){if(!_a(t))throw new TypeError("Uint8Array expected")}function Ki(t){if(typeof t!="function")throw new TypeError("function expected");return!0}function Ua(t,e){if(typeof e!="string")throw new TypeError(`${t}: string expected`);return!0}function Ca(t,e="number"){if(typeof t!="number")throw new TypeError(`${e}: expected number, got ${typeof t}`);if(!Number.isSafeInteger(t))throw new RangeError(`${e}: expected safe integer, got ${t}`)}function Ii(...t){let e=s=>s,r=(s,i)=>a=>s(i(a)),n=t.map(s=>s.encode).reduceRight(r,e),o=t.map(s=>s.decode).reduce(r,e);return{encode:n,decode:o}}var Bi=(()=>{try{let t=new TextDecoder;return t.decode(Uint8Array.of(65,48,43,127))==="A0+\x7F"?t:void 0}catch{return}})(),uo=8192;function La(t){let e=t.length;if(Bi!==void 0&&e>=12)return Bi.decode(t);if(e<=uo)return String.fromCharCode.apply(null,t);let r="";for(let n=0;n<e;n+=uo)r+=String.fromCharCode.apply(null,t.subarray(n,n+uo));return r}function Fa(t,e){let r=t.length;if(r>128)throw new Error("alphabet: max 128 letters");let n=new Uint8Array(r),o=new Int8Array(128).fill(-1);for(let s=0;s<r;s++){let i=t.charCodeAt(s);if(t.codePointAt(s)!==i||i>127)throw new Error("alphabet: single-char ASCII letters only");n[s]=i,o[i]=s}if(e!==void 0)for(let s of Object.keys(e)){let i=s.charCodeAt(0),a=o[e[s].charCodeAt(0)];if(s.length!==1||i>127||a===void 0||a===-1)throw new Error(`alphabet: invalid alias ${s}`);o[i]=a}return{encode:s=>{let i=new Uint8Array(s.length);for(let a=0;a<s.length;a++){let c=s[a],f=n[c];if(f===void 0)throw new Error(`alphabet.encode: invalid digit ${c}`);i[a]=f}return La(i)},decode:s=>{Ua("decode",s);let i=s.length,a=new Uint8Array(i);for(let c=0;c<i;c++){let f=s.charCodeAt(c),u=f<128?o[f]:-1;if(u===-1)throw new Error(`Unknown letter "${s[c]}". Allowed: ${t}`);a[c]=u}return a}}}function Ma(t,e){if(Ca(t),t<=0)throw new RangeError(`checksum length must be positive: ${t}`);Ki(e);let r=e;return{encode(n){rn(n);let o=r(n).slice(0,t),s=new Uint8Array(n.length+t);return s.set(n),s.set(o,n.length),s},decode(n){rn(n);let o=n.slice(0,-t),s=n.slice(-t),i=r(o).slice(0,t);for(let a=0;a<t;a++)if(i[a]!==s[a])throw new Error("Invalid checksum");return o}}}var Ti=656356768,Pa={encode:t=>{rn(t);let e=t.length;if(e===0)return new Uint8Array(0);let r=0;for(;r<e-1&&t[r]===0;)r++;let n=Math.ceil(e/2),o=new Uint16Array(n),s=e&1;s&&(o[0]=t[0]);for(let l=s,p=s;l<e;l+=2,p++)o[p]=t[l]<<8|t[l+1];let i=[],a=0;for(;a<n;){let l=0;for(let p=a;p<n;p++){let y=l*65536+o[p],b=Math.floor(y/Ti);l=y-b*Ti,o[p]=b,b===0&&p===a&&a++}i.push(l)}let c=i.length-1,f=c*5;for(let l=i[c];f++,!(l<58);l=Math.floor(l/58));let u=new Uint8Array(r+f),d=u.length-1;for(let l=0;l<c;l++){let p=i[l];for(let y=0;y<5;y++)u[d--]=p%58,p=Math.floor(p/58)}for(let l=i[c];d>=r;l=Math.floor(l/58))u[d--]=l%58;return u},decode:t=>{rn(t);let e=t.length;if(e===0)return new Uint8Array(0);if(e>=65536)throw new Error("invalid length");let r=0;for(;r<e-1&&t[r]===0;)r++;let n=new Uint16Array(Math.ceil(e*6/16)+1),o=0,s=0,i=e%5||5;for(;s<e;){let u=0,d=1;for(let p=s+i;s<p;s++){let y=t[s];if(y>=58)throw new Error(`invalid integer: ${y}`);u=u*58+y,d*=58}i=5;let l=u;for(let p=0;p<o;p++){let y=n[p]*d+l;l=Math.floor(y/65536),n[p]=y-l*65536}for(;l>0;l=Math.floor(l/65536))n[o++]=l%65536}let a=o===0?1:o*2-(n[o-1]<256?1:0),c=new Uint8Array(r+a),f=c.length-1;for(let u=0;u<o;u++){let d=n[u];c[f--]=d&255,f>=r&&(c[f--]=d>>8)}return c}},Na=t=>Ii(Pa,Fa(t)),Da=Oa(()=>Na("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"));var Ri=t=>{Ki(t);let e=t;return Ii(Ma(4,r=>e(e(r))),Da)};var yr=jt.Point,pr=yr.Fn,lo=Ri(he),$a=Uint8Array.from("Bitcoin seed".split(""),t=>t.charCodeAt(0)),ho={private:76066276,public:76067358},po=2147483648,Ha=t=>Ai(he(t)),ja=t=>Ue(t).getUint32(0,!1),zt=(t,e="number")=>{if(typeof t!="number")throw new TypeError(`"${e}" expected number, got type=${typeof t}`);if(!Number.isSafeInteger(t)||t<0||t>2**32-1)throw new RangeError(`"${e}" expected integer in range 0..2**32-1, got ${t}`);let r=new Uint8Array(4);return Ue(r).setUint32(0,t,!1),r},yo=(t,e="versions")=>{if(!(typeof t=="object"&&t!==null))throw new Error("versions must be an object");return zt(t.private,`${e}.private`),zt(t.public,`${e}.public`),t},nn=class t{constructor(e){h(this,"versions");h(this,"depth",0);h(this,"index",0);h(this,"chainCode",null);h(this,"parentFingerprint",0);h(this,"_privateKey");h(this,"_publicKey");h(this,"pubHash");if(!e||typeof e!="object")throw new Error("HDKey.constructor must not be called directly");if(this.versions=e.versions?yo(e.versions):ho,this.depth=e.depth||0,this.chainCode=e.chainCode?Uint8Array.from(e.chainCode):null,this.index=e.index||0,this.parentFingerprint=e.parentFingerprint||0,!this.depth&&(this.parentFingerprint||this.index))throw new Error("HDKey: zero depth with non-zero index/parent fingerprint");if(this.depth>255)throw new Error("HDKey: depth exceeds the serializable value 255");if(e.publicKey&&e.privateKey)throw new Error("HDKey: publicKey and privateKey at same time.");if(e.privateKey){if(!jt.utils.isValidSecretKey(e.privateKey))throw new Error("Invalid private key");this._privateKey=Uint8Array.from(e.privateKey),this._publicKey=jt.getPublicKey(this._privateKey,!0)}else if(e.publicKey)this._publicKey=yr.fromBytes(e.publicKey).toBytes(!0);else throw new Error("HDKey: no public or private key provided");this.pubHash=Ha(this._publicKey)}get fingerprint(){if(!this.pubHash)throw new Error("No publicKey set!");return ja(this.pubHash)}get identifier(){return this.pubHash}get pubKeyHash(){return this.pubHash}get privateKey(){return this._privateKey||null}get publicKey(){return this._publicKey||null}get privateExtendedKey(){let e=this._privateKey;if(!e)throw new Error("No private key");return lo.encode(this.serialize(this.versions.private,Ce(Uint8Array.of(0),e)))}get publicExtendedKey(){if(!this._publicKey)throw new Error("No public key");return lo.encode(this.serialize(this.versions.public,this._publicKey))}static fromMasterSeed(e,r=ho){if(j(e),r=yo(r),8*e.length<128||8*e.length>512)throw new RangeError("HDKey: seed length must be between 128 and 512 bits; 256 bits is advised, got "+e.length);let n=je(xt,$a,e),o=n.slice(0,32),s=n.slice(32);return new t({versions:r,chainCode:s,privateKey:o})}static fromExtendedKey(e,r=ho){r=yo(r);let n=lo.decode(e),o=Ue(n),s=o.getUint32(0,!1),i={versions:r,depth:n[4],parentFingerprint:o.getUint32(5,!1),index:o.getUint32(9,!1),chainCode:n.slice(13,45)},a=n.slice(45),c=a[0]===0;if(s!==r[c?"private":"public"])throw new Error("Version mismatch");return c?new t({...i,privateKey:a.slice(1)}):new t({...i,publicKey:a})}static fromJSON(e){return t.fromExtendedKey(e.xpriv)}derive(e){if(!/^[mM]'?/.test(e))throw new Error('Path must start with "m" or "M"');if(/^[mM]'?$/.test(e))return this;let r=e.replace(/^[mM]'?\//,"").split("/"),n=this;for(let o of r){let s=/^(\d+)('?)$/.exec(o),i=s&&s[1];if(!s||s.length!==3||typeof i!="string")throw new Error("invalid child index: "+o);let a=+i;if(!Number.isSafeInteger(a)||a>=po)throw new Error("Invalid index");s[2]==="'"&&(a+=po),n=n.deriveChild(a)}return n}deriveChild(e,r){if(!this._publicKey||!this.chainCode)throw new Error("No publicKey or chainCode set");let n=zt(e,"index");if(e>=po){let c=this._privateKey;if(!c)throw new Error("Could not derive hardened child key");n=Ce(Uint8Array.of(0),c,n)}else n=Ce(this._publicKey,n);let o=r||je(xt,this.chainCode,n);j(o,64);let s=o.slice(0,32),i=o.slice(32),a={versions:this.versions,chainCode:i,depth:this.depth+1,parentFingerprint:this.fingerprint,index:e};if(a.depth>255)throw new Error("HDKey: depth exceeds the serializable value 255");try{let c=pr.fromBytes(s);if(this._privateKey){let f=pr.create(pr.fromBytes(this._privateKey)+c);if(!pr.isValidNot0(f))throw new Error("The tweak was out of range or the resulted private key is invalid");a.privateKey=pr.toBytes(f)}else{let f=yr.fromBytes(this._publicKey),u=c===0n?f:f.add(yr.BASE.multiply(c));if(u.equals(yr.ZERO))throw new Error("The tweak was equal to negative P, which made the result key invalid");a.publicKey=u.toBytes(!0)}return new t(a)}catch{return this.deriveChild(e+1)}}sign(e){if(!this._privateKey)throw new Error("No privateKey set!");return j(e,32),jt.sign(e,this._privateKey,{prehash:!1})}verify(e,r){if(j(e,32),j(r,64),!this._publicKey)throw new Error("No publicKey set!");return jt.verify(r,e,this._publicKey,{prehash:!1})}wipePrivateData(){return this._privateKey&&(this._privateKey.fill(0),this._privateKey=void 0),this}toJSON(){return{xpriv:this.privateExtendedKey,xpub:this.publicExtendedKey}}serialize(e,r){if(!this.chainCode)throw new Error("No chainCode set");return j(r,33),Ce(zt(e,"version"),new Uint8Array([this.depth]),zt(this.parentFingerprint,"parentFingerprint"),zt(this.index,"index"),this.chainCode,r)}};Be();function za(t,e,r,n){Qe(t);let o=or({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:a}=o;if(se(s,"c"),se(i,"dkLen"),se(a,"asyncTick"),s<1)throw new Error('"c" (iterations) must be >= 1');if(i<1)throw new Error('"dkLen" must be >= 1');if(i>(2**32-1)*t.outputLen)throw new Error("derived key too long");let c=On(e,"password"),f=On(r,"salt"),u=new Uint8Array(i),{iHash:d,oHash:l,outputLen:p}=je.create(t,c),y=new Uint8Array(p),b=qa(d,l,f,y);return{c:s,dkLen:i,asyncTick:a,DK:u,outputLen:p,eng:b}}function qa(t,e,r,n){let o=new Uint8Array(4),s=Ue(o),i=t._cloneInto().update(r),a=e._cloneInto(),c=t._cloneInto,f=e._cloneInto;return{u1:(u,d)=>{s.setInt32(0,u,!1),i._cloneInto(a).update(o).digestInto(n),e._cloneInto(a).update(n).digestInto(n),d.set(n.subarray(0,d.length))},rounds:(u,d)=>{for(let l=1;l<u;l++){c.call(t,a).update(n).digestInto(n),f.call(e,a).update(n).digestInto(n);for(let p=0;p<d.length;p++)d[p]^=n[p]}},output:u=>(t.destroy(),e.destroy(),i.destroy(),a.destroy(),ge(n),u)}}function Oi(t,e,r,n){let{c:o,dkLen:s,DK:i,outputLen:a,eng:c}=za(t,e,r,n);for(let f=1,u=0;u<s;f++,u+=a){let d=i.subarray(u,u+a);c.u1(f,d),c.rounds(o,d)}return c.output(i)}Be();var Va=t=>t[0]==="\u3042\u3044\u3053\u304F\u3057\u3093";function _i(t){if(typeof t!="string")throw new TypeError("invalid mnemonic type: "+typeof t);return t.normalize("NFKD")}function Ui(t){let e=_i(t),r=e.split(" ");if(![12,15,18,21,24].includes(r.length))throw new Error("Invalid mnemonic");return{nfkd:e,words:r}}function Ci(t){if(j(t),![16,20,24,28,32].includes(t.length))throw new RangeError("invalid entropy length")}function Li(t,e=128){if(se(e),e%32!==0||e>256)throw new RangeError("Invalid entropy");return Ga(Ct(e/8),t)}var Fi=t=>{let e=8-t.length/4;return he(t)[0]>>e<<e};function Mi(t){if(!Array.isArray(t)||t.length!==2048||typeof t[0]!="string")throw new TypeError("Wordlist: expected array of 2048 strings");t.forEach(e=>{if(typeof e!="string")throw new TypeError("wordlist: non-string element: "+e)})}function Wa(t,e){Mi(e);let r=new Uint8Array(t.length+1);r.set(t),r[t.length]=Fi(t);let n=[],o=0,s=0;for(let i of r)o=o<<8|i,s+=8,s>=11&&(s-=11,n.push(e[o>>>s&2047]),o&=(1<<s)-1);return n}function Za(t,e){Mi(e);let r=t.length/3*4,n=new Uint8Array(r+1),o=0,s=0,i=0;for(let c of t){let f=e.indexOf(c);if(f===-1)throw new Error("Unknown word: "+c);for(o=o<<11|f,s+=11;s>=8;)s-=8,n[i++]=o>>>s&255;o&=(1<<s)-1}s>0&&(n[i]=o<<8-s);let a=n.subarray(0,r);if(n[r]!==Fi(a))throw new Error("Invalid checksum");return Uint8Array.from(a)}function Ya(t,e){let{words:r}=Ui(t),n=Za(r,e);return Ci(n),n}function Ga(t,e){return Ci(t),Wa(t,e).join(Va(e)?"\u3000":" ")}function Pi(t,e){try{Ya(t,e)}catch{return!1}return!0}var Xa=t=>{if(typeof t!="string")throw new TypeError("invalid passphrase type: "+typeof t);return _i("mnemonic"+t)};function Ni(t,e=""){return Oi(xt,Ui(t).nfkd,Xa(e),{c:2048,dkLen:64})}var go=Object.freeze(`abandon
|
|
2
2
|
ability
|
|
3
3
|
able
|
|
4
4
|
about
|
|
@@ -2046,14 +2046,11 @@ zebra
|
|
|
2046
2046
|
zero
|
|
2047
2047
|
zone
|
|
2048
2048
|
zoo`.split(`
|
|
2049
|
-
`));var Ve=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=Yn.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 w0(e,r)}generateMnemonic(e=256){return m0(E0,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}`}};y();var A0="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";function gl(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=A0[n]+r,e=e/58n}for(let n of t){if(n!==0)break;r="1"+r}return r}function ml(t){let e=0n;for(let n of t){let o=A0.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 Ps(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=ut(o),c=ut(s).slice(0,4),a=new Uint8Array(o.length+4);return a.set(o),a.set(c,o.length),gl(a)}function $s(t){let e=ml(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=ut(r),i=ut(o).slice(0,4);if(!n.every((h,d)=>h===i[d]))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 f=r.length===34&&r[33]===1;return{privateKey:r.slice(1,33),compressed:f,network:a}}hn.sha256=t=>ut(t);hn.hmacSha256=(t,e)=>Zi(ut,t,e);var hr=class{constructor(){u(this,"suiteId","bsv-ecdsa-secp256k1");u(this,"version","1.0.0");u(this,"capabilities",{derivation:new Ve})}async generateKeypair(){let e=Gi.randomSecretKey(),r=Ci(e,!0);return{privateKey:e,publicKey:r}}async sign(e,r){try{return Pi(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 $i(n,r,e,{prehash:!1})}catch{return!1}}exportPublicKey(e){return Ir(e)}importPublicKey(e){return Qt(e)}exportPrivateKey(e){return Ps(e,!0,"mainnet")}importPrivateKey(e){if(e.length===64){let r=Qt(e);if(r.length!==32)throw new Error("Private key must be 32 bytes");return r}else try{let{privateKey:r}=$s(e);return r}catch(r){throw new Error(`Invalid private key format: ${r instanceof Error?r.message:String(r)}`)}}};y();var li=null,di=null,hi=null;async function Gl(){return li||(li=(await Promise.resolve().then(()=>(uo(),fo))).ml_dsa44),li}async function zl(){return di||(di=(await Promise.resolve().then(()=>(uo(),fo))).ml_dsa65),di}async function ql(){return hi||(hi=(await Promise.resolve().then(()=>(uo(),fo))).ml_dsa87),hi}var pi={"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{return(await this.getLib()).verify(n,r,e)}catch{return!1}}exportPublicKey(e){return Ir(e)}importPublicKey(e){let r=Qt(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 Ir(e)}importPrivateKey(e){let r=Qt(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);u(this,"suiteId","ml-dsa-44")}get sizes(){return pi["ml-dsa-44"]}async getLib(){return Gl()}},en=class extends Jr{constructor(){super(...arguments);u(this,"suiteId","ml-dsa-65")}get sizes(){return pi["ml-dsa-65"]}async getLib(){return zl()}},xr=class extends Jr{constructor(){super(...arguments);u(this,"suiteId","ml-dsa-87")}get sizes(){return pi["ml-dsa-87"]}async getLib(){return ql()}};var tn=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()}},qt=new tn;qt.register(new hr);qt.register(new Qr);qt.register(new en);qt.register(new xr);y();y();var _t=class{constructor(){u(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 _t){u(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}};y();y();var lo=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
|
-
`+(
|
|
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.
|
|
2049
|
+
`));var Re=class{async deriveKeypair(e){if(!e.seed)throw new Error("BIP32 derivation requires a seed");if(!e.path)throw new Error(`BIP32 derivation requires a path (e.g., "m/44'/0'/0'/0/0")`);try{let n=nn.fromMasterSeed(e.seed).derive(e.path);if(!n.privateKey)throw new Error(`Failed to derive private key at path ${e.path}`);if(!n.publicKey)throw new Error(`Failed to derive public key at path ${e.path}`);return{privateKey:n.privateKey,publicKey:n.publicKey}}catch(r){throw new Error(`BIP32 derivation failed at path ${e.path}: ${r instanceof Error?r.message:String(r)}`)}}mnemonicToSeed(e,r){if(typeof e!="string"||!Pi(e,go))throw new Error("Invalid BIP39 mnemonic: unknown word, wrong word count, or checksum mismatch");return Ni(e,r)}generateMnemonic(e=256){return Li(go,e)}static bitcoinPath(e=0,r=0,n=0){return`m/44'/0'/${e}'/${r}/${n}`}static bip44Path(e,r=0,n=0,o=0){for(let[s,i]of Object.entries({coinType:e,account:r,change:n,index:o}))if(!Number.isInteger(i)||i<0||i>2147483647)throw new Error(`BIP44 ${s} must be an integer in [0, 2^31 - 1], got ${String(i)}`);if(n!==0&&n!==1)throw new Error(`BIP44 change must be 0 (external) or 1 (internal), got ${n}`);return`m/44'/${e}'/${r}'/${n}/${o}`}static bitcoinSegWitPath(e=0,r=0,n=0){return`m/84'/0'/${e}'/${r}/${n}`}};var Di="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";function Ja(t){let e=0n;for(let n of t)e=e*256n+BigInt(n);let r="";for(;e>0n;){let n=Number(e%58n);r=Di[n]+r,e=e/58n}for(let n of t){if(n!==0)break;r="1"+r}return r}function Qa(t){let e=0n;for(let n of t){let o=Di.indexOf(n);if(o===-1)throw new Error(`Invalid Base58 character: ${n}`);e=e*58n+BigInt(o)}let r=[];for(;e>0n;)r.unshift(Number(e%256n)),e=e/256n;for(let n of t){if(n!=="1")break;r.unshift(0)}return new Uint8Array(r)}function mo(t,e=!0,r="mainnet"){if(t.length!==32)throw new Error("Private key must be 32 bytes");let n=r==="mainnet"?128:239,o=new Uint8Array(e?34:33);o[0]=n,o.set(t,1),e&&(o[33]=1);let s=he(o),a=he(s).slice(0,4),c=new Uint8Array(o.length+4);return c.set(o),c.set(a,o.length),Ja(c)}function bo(t){let e=Qa(t);if(e.length!==37&&e.length!==38)throw new Error("Invalid WIF length");let r=e.slice(0,-4),n=e.slice(-4),o=he(r),i=he(o).slice(0,4);if(!n.every((d,l)=>d===i[l]))throw new Error("Invalid WIF checksum");let a=r[0],c=a===128?"mainnet":a===239?"testnet":null;if(!c)throw new Error(`Invalid WIF version byte: 0x${a.toString(16)}`);let f=r.length===34&&r[33]===1;return{privateKey:r.slice(1,33),compressed:f,network:c}}Ur.sha256=t=>he(t);Ur.hmacSha256=(t,e)=>je(he,t,e);function $i(t){if(!Cr.isValidSecretKey(t))throw new Error("Private key is not a valid secp256k1 scalar")}var qt=class{constructor(){h(this,"suiteId","bsv-ecdsa-secp256k1");h(this,"version","1.0.0");h(this,"capabilities",{derivation:new Re})}async generateKeypair(){let e=Cr.randomSecretKey(),r=os(e,!0);return{privateKey:e,publicKey:r}}async sign(e,r){try{return us(r,e,{prehash:!1})}catch(n){throw new Error(`BsvEcdsaSuite signing failed: ${n instanceof Error?n.message:String(n)}`)}}async verify(e,r,n){try{return ls(n,r,e,{prehash:!1})===!0}catch{return!1}}exportPublicKey(e){return ar(e)}importPublicKey(e){let r=Ft(e);if(!Cr.isValidPublicKey(r))throw new Error("Invalid secp256k1 public key");return r}exportPrivateKey(e){return mo(e,!0,"mainnet")}importPrivateKey(e){if(e.length===64){let r=Ft(e);if(r.length!==32)throw new Error("Private key must be 32 bytes");return $i(r),r}else try{let{privateKey:r}=bo(e);return $i(r),r}catch(r){throw new Error(`Invalid private key format: ${r instanceof Error?r.message:String(r)}`)}}};var Ro=null,Oo=null,_o=null;async function uf(){return Ro||(Ro=(await Promise.resolve().then(()=>(dn(),ln))).ml_dsa44),Ro}async function lf(){return Oo||(Oo=(await Promise.resolve().then(()=>(dn(),ln))).ml_dsa65),Oo}async function df(){return _o||(_o=(await Promise.resolve().then(()=>(dn(),ln))).ml_dsa87),_o}var Uo={"ml-dsa-44":{publicKey:1312,privateKey:2560,signature:2420},"ml-dsa-65":{publicKey:1952,privateKey:4032,signature:3309},"ml-dsa-87":{publicKey:2592,privateKey:4896,signature:4627}},wr=class{constructor(){h(this,"version","2.0.0");h(this,"capabilities",{})}async generateKeypair(){try{let r=(await this.getLib()).keygen();return{publicKey:r.publicKey,privateKey:r.secretKey}}catch(e){throw new Error(`${this.suiteId} key generation failed: ${e instanceof Error?e.message:String(e)}`)}}async sign(e,r){try{return(await this.getLib()).sign(r,e)}catch(n){throw new Error(`${this.suiteId} signing failed: ${n instanceof Error?n.message:String(n)}`)}}async verify(e,r,n){try{let o=await this.getLib();return e.length!==this.sizes.publicKey||n.length!==this.sizes.signature?!1:o.verify(n,r,e)===!0}catch{return!1}}exportPublicKey(e){return ar(e)}importPublicKey(e){let r=Ft(e);if(r.length!==this.sizes.publicKey)throw new Error(`${this.suiteId} public key must be ${this.sizes.publicKey} bytes, got ${r.length}`);return r}exportPrivateKey(e){return ar(e)}importPrivateKey(e){let r=Ft(e);if(r.length!==this.sizes.privateKey)throw new Error(`${this.suiteId} private key must be ${this.sizes.privateKey} bytes, got ${r.length}`);return r}},Vt=class extends wr{constructor(){super(...arguments);h(this,"suiteId","ml-dsa-44")}get sizes(){return Uo["ml-dsa-44"]}async getLib(){return uf()}},Wt=class extends wr{constructor(){super(...arguments);h(this,"suiteId","ml-dsa-65")}get sizes(){return Uo["ml-dsa-65"]}async getLib(){return lf()}},Zt=class extends wr{constructor(){super(...arguments);h(this,"suiteId","ml-dsa-87")}get sizes(){return Uo["ml-dsa-87"]}async getLib(){return df()}};var hn=class{constructor(){h(this,"suites",new Map)}register(e){if(this.suites.has(e.suiteId))throw new Error(`Signature suite already registered: ${e.suiteId}`);this.suites.set(e.suiteId,e)}getSuite(e){let r=this.suites.get(e);if(!r)throw new Error(`Unknown signature suite: ${e}. Available: ${this.listSuites().join(", ")}`);return r}hasSuite(e){return this.suites.has(e)}listSuites(){return[...this.suites.keys()]}getAllSuites(){return[...this.suites.values()]}unregister(e){return this.suites.delete(e)}clear(){this.suites.clear()}},lt=new hn;lt.register(new qt);lt.register(new Vt);lt.register(new Wt);lt.register(new Zt);var Bt=class extends Error{constructor(r,n){super(r);h(this,"code");this.code=n,this.name=this.constructor.name,Error.captureStackTrace(this,this.constructor)}},pn=class extends Bt{constructor(r){super(`Key not found: ${r}`,"KEY_NOT_FOUND");h(this,"keyId");this.keyId=r}},Tt=class extends Bt{constructor(r){super(`Key already exists: ${r}`,"KEY_ALREADY_EXISTS");h(this,"keyId");this.keyId=r}},yn=class extends Bt{constructor(r,n){super(`Key expired: ${r} (expired at ${n})`,"KEY_EXPIRED");h(this,"keyId");h(this,"expiresAt");this.keyId=r,this.expiresAt=n}},xr=class extends Bt{constructor(r,n,o){super(`Key in invalid state: ${r} (current: ${n}, required: ${o})`,"KEY_INVALID_STATE");h(this,"keyId");h(this,"currentState");h(this,"requiredState");this.keyId=r,this.currentState=n,this.requiredState=o}};var Yt=class extends Bt{constructor(e){super(`Invalid key parameters: ${e}`,"INVALID_KEY_PARAMETERS")}};function vr(t){if(typeof t!="string")return null;let e=t.lastIndexOf(":");return e<=0||e===t.length-1?null:t.slice(0,e)}function We(t){return{...t,usage:[...t.usage],...t.derivation?{derivation:{...t.derivation}}:{}}}function Co(t){return{publicKey:Uint8Array.from(t.publicKey),privateKey:Uint8Array.from(t.privateKey)}}function Er(t,e=new Date){if(t.status&&t.status!=="active")return!1;if(t.expiresAt!==void 0){let r=new Date(t.expiresAt).getTime();if(Number.isNaN(r)||r<=e.getTime())return!1}return!0}function Lo(t,e=new Date){if(t.status&&t.status!=="active")throw new xr(t.keyId,t.status,"active");if(!Er(t,e))throw new yn(t.keyId,String(t.expiresAt))}function hf(t){if(t!==void 0&&(typeof t!="string"||Number.isNaN(new Date(t).getTime())))throw new Yt(`expiresAt must be an ISO 8601 date, got ${JSON.stringify(t)}`)}var dt=class{constructor(){h(this,"keys",new Map)}async store(e,r,n){this.keys.set(e,{keypair:Co(r),meta:We(n)})}async storeIfAbsent(e,r,n){return this.keys.has(e)?!1:(this.keys.set(e,{keypair:Co(r),meta:We(n)}),!0)}async load(e){let r=this.keys.get(e);return r?{keypair:Co(r.keypair),meta:We(r.meta)}:null}async list(e){let r=Array.from(this.keys.values()).map(n=>We(n.meta));return e?r.filter(n=>Object.entries(e).every(([o,s])=>o==="usage"&&Array.isArray(s)?s.some(i=>n.usage.includes(i)):n[o]===s)):r}async delete(e){let r=this.keys.get(e);r&&r.keypair.privateKey.fill(0),this.keys.delete(e)}async updateMeta(e,r){let n=this.keys.get(e);if(!n)throw new pn(e);this.keys.set(e,{keypair:n.keypair,meta:We({...n.meta,...r})})}clear(){for(let{keypair:e}of this.keys.values())e.privateKey.fill(0);this.keys.clear()}},Kt=class{constructor(e=new dt){h(this,"storage");this.storage=e}async registerKey(e,r,n,o={}){if(typeof e!="string"||e.length===0)throw new Yt("keyId must be a non-empty string");hf(o.expiresAt);let s={keyId:e,suiteId:n,createdAt:new Date().toISOString(),expiresAt:o.expiresAt,usage:o.usage?[...o.usage]:["signing"],cryptoProfileVersion:o.cryptoProfileVersion||"1.0.0",status:o.status||"active",...o.rotatedFrom!==void 0?{rotatedFrom:o.rotatedFrom}:{},...o.derivation?{derivation:{...o.derivation}}:{}};if(this.storage.storeIfAbsent){if(!await this.storage.storeIfAbsent(e,r,s))throw new Tt(e)}else{if(await this.storage.load(e))throw new Tt(e);await this.storage.store(e,r,s)}return We(s)}async getKey(e){return await this.storage.load(e)}async getPublicKey(e){let r=await this.storage.load(e);return r?{publicKey:Uint8Array.from(r.keypair.publicKey),meta:We(r.meta)}:null}async listKeys(e){return await this.storage.list(e)}async listActiveKeys(e){let r=await this.storage.list(e),n=new Date;return r.filter(o=>Er(o,n))}async rotateKey(e,r,n,o={}){let s=await this.storage.load(e);if(!s)throw new Error(`Cannot rotate: key not found: ${e}`);if(s.meta.status==="revoked"||s.meta.status==="rotated")throw new xr(e,s.meta.status,"active or expired");let i;if(o.expiresAt===null)i=void 0;else if(o.expiresAt!==void 0)i=o.expiresAt;else if(s.meta.expiresAt!==void 0){let c=new Date(s.meta.expiresAt).getTime()-new Date(s.meta.createdAt).getTime();if(Number.isFinite(c)&&c>0)i=new Date(Date.now()+c).toISOString();else throw new Yt(`cannot infer a lifetime for the replacement of ${e} (createdAt ${s.meta.createdAt}, expiresAt ${s.meta.expiresAt}); pass options.expiresAt`)}let a=await this.registerKey(r,n,s.meta.suiteId,{usage:s.meta.usage,cryptoProfileVersion:s.meta.cryptoProfileVersion,expiresAt:i,status:"active",rotatedFrom:e,derivation:o.derivation});try{await this.storage.updateMeta(e,{status:"rotated"})}catch(c){throw await this.storage.delete(r).catch(()=>{}),c}return a}async revokeKey(e,r){await this.storage.updateMeta(e,{status:"revoked",revokedAt:new Date().toISOString()})}async deleteKey(e){await this.storage.delete(e)}async markExpiredKeys(){let e=await this.storage.list(),r=new Date,n=0;for(let o of e)o.status==="active"&&!Er(o,r)&&(await this.storage.updateMeta(o.keyId,{status:"expired"}),n++);return n}async pruneOldKeys(e=90){let r=await this.storage.list(),n=new Date;n.setDate(n.getDate()-e);let o=0;for(let s of r)(s.status==="revoked"&&s.revokedAt&&new Date(s.revokedAt)<n||s.status==="expired"&&s.expiresAt&&new Date(s.expiresAt)<n)&&(await this.storage.delete(s.keyId),o++);return o}};var pf=/^pk-[^:-]+-(\d+)$/,Yi=8;function gn(t){if(typeof t!="string"||t.length===0)throw new Error("agentId must be a non-empty string")}function Sr(t,e){return{meta:We(t),publicKey:Uint8Array.from(e)}}function Gi(t,e){return e==="any"?!0:e==="not-revoked"?t.status!=="revoked":Er(t)}var mn=class{constructor(e){this.keyCounter=new Map;this.counterInitialized=new Set;this.counterInitPromises=new Map;this.getOrCreateInFlight=new Map;this.keyRegistry=e.keyRegistry,this.suiteRegistry=e.suiteRegistry}async createKey(e,r,n={}){gn(e);let o=this.suiteRegistry.getSuite(r.primarySignatureSuite),s;if(n.derivationContext){if(!o.capabilities?.derivation){let a=this.getSuitesWithCapability("derivation");throw new Error(`Suite '${o.suiteId}' does not support key derivation.
|
|
2050
|
+
`+(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 Sr(i,s.publicKey)}async getKey(e){let r=await this.keyRegistry.getPublicKey(e);return r?Sr(r.meta,r.publicKey):null}async signWithKey(e,r){let n=await this.keyRegistry.getKey(e);if(!n)throw new Error(`Key not found: ${e}`);if(n.meta.status&&n.meta.status!=="active")throw new Error(`Key is not active: ${e} (status: ${n.meta.status})`);if(Lo(n.meta),!n.meta.usage.some(a=>a==="signing"||a==="both"))throw new Error(`Key is not registered for signing: ${e} (usage: ${n.meta.usage.join(", ")})`);let o=this.suiteRegistry.getSuite(n.meta.suiteId),s=this.getHashAlgorithm(n.meta.suiteId),i=await jr(r,s);return await o.sign(n.keypair.privateKey,i)}async verifySignature(e,r,n,o={}){let s=await this.keyRegistry.getPublicKey(e);return!s||!Gi(s.meta,o.keyStatus??"any")?!1:this.verifyAgainst(s.meta,s.publicKey,r,n)}async verifyAgainst(e,r,n,o){try{let s=this.suiteRegistry.getSuite(e.suiteId),i=this.getHashAlgorithm(e.suiteId),a=await jr(n,i);return await s.verify(r,a,o)===!0}catch{return!1}}async listKeysForAgent(e,r=!0){gn(e);let o=(r?await this.keyRegistry.listActiveKeys():await this.keyRegistry.listKeys()).filter(i=>vr(i.keyId)===e),s=[];for(let i of o){let a=await this.keyRegistry.getPublicKey(i.keyId);a&&s.push(Sr(a.meta,a.publicKey))}return s}async getActiveCryptoProfile(e){let r=await this.listKeysForAgent(e,!0);if(r.length===0)return null;let n=this.sortKeysByCreatedAt(r),o=new Set(n.map(i=>i.meta.suiteId)),s=Array.from(o);return{primarySignatureSuite:s[0],secondarySignatureSuite:s[1]}}async rotateAgentKeys(e,r={}){let n=r.derivedKeys??"error",o=await this.listKeysForAgent(e,!0),s=[];for(let c of o){if(this.suiteRegistry.getSuite(c.meta.suiteId),c.meta.derivation){if(n==="error")throw new Error(`Key ${c.meta.keyId} was derived from a seed (path ${c.meta.derivation.path||"unknown"}). Rotating it here would replace it with a random key that the mnemonic cannot recover. Derive the successor yourself with createKeyFromMnemonic at a new path, or pass { derivedKeys: 'skip' } or { derivedKeys: 'randomize' }. No keys were rotated.`);if(n==="skip")continue}s.push(c)}let i=[];for(let c of s){let f=this.suiteRegistry.getSuite(c.meta.suiteId);i.push(await f.generateKeypair())}let a=[];for(let[c,f]of s.entries()){let u=i[c],d=await this.registerUnderFreshId(e,f.meta.suiteId,l=>this.keyRegistry.rotateKey(f.meta.keyId,l,u,{expiresAt:r.expiresAt}));a.push(Sr(d,u.publicKey))}return a}async getOrCreateKey(e,r,n={}){gn(e);let o=JSON.stringify([e,r.primarySignatureSuite]),s=this.getOrCreateInFlight.get(o);if(s){let a=await s;return Sr(a.meta,a.publicKey)}let i=(async()=>{let c=(await this.listKeysForAgent(e,!0)).find(f=>f.meta.suiteId===r.primarySignatureSuite);return c||await this.createKey(e,r,n)})();this.getOrCreateInFlight.set(o,i);try{return await i}finally{this.getOrCreateInFlight.delete(o)}}async createDualSignatureKeys(e,r,n={}){if(!r.secondarySignatureSuite)throw new Error("secondarySignatureSuite is required to create dual signature keys");this.assertDualProfile(r);let o=await this.createKey(e,{primarySignatureSuite:r.primarySignatureSuite},n),s=await this.createKey(e,{primarySignatureSuite:r.secondarySignatureSuite},n);return{primaryKey:o,secondaryKey:s}}async getOrCreateDualSignatureKeys(e,r,n={}){if(!r.secondarySignatureSuite)throw new Error("secondarySignatureSuite is required to create dual signature keys");this.assertDualProfile(r);let o=await this.getOrCreateKey(e,{primarySignatureSuite:r.primarySignatureSuite},n),s=await this.getOrCreateKey(e,{primarySignatureSuite:r.secondarySignatureSuite},n);return{primaryKey:o,secondaryKey:s}}assertDualProfile(e){if(this.suiteRegistry.getSuite(e.primarySignatureSuite),this.suiteRegistry.getSuite(e.secondarySignatureSuite),e.primarySignatureSuite===e.secondarySignatureSuite)throw new Error(`Dual signature keys need two different suites; both are ${e.primarySignatureSuite}`)}async signWithSuites(e,r,n){let o=this.sortKeysByCreatedAt(await this.listKeysForAgent(e,!0));if(o.length===0)throw new Error(`No active keys found for agent: ${e}`);let s=Array.from(new Set(n?.length?n:o.map(a=>a.meta.suiteId))),i=[];for(let a of s){let c=o.find(u=>u.meta.suiteId===a);if(!c)throw new Error(`No active key for suite '${a}' and agent '${e}'`);let f=await this.signWithKey(c.meta.keyId,r);i.push({suiteId:a,keyId:c.meta.keyId,signature:f})}return{signatures:i}}async verifyWithSuites(e,r,n,o={}){gn(e);let s=o.keyStatus??"not-revoked",i=Array.from(new Set(o.requiredSuites??(await this.listKeysForAgent(e,!0)).map(d=>d.meta.suiteId))),a=(d,l=[])=>({results:l,allValid:!1,requiredSuites:i,missingSuites:i.filter(p=>!l.some(y=>y.valid&&y.suiteId===p)),error:d});if(!Array.isArray(n))return a("signatures must be an array");let c=[];for(let d of n){let l=String(d?.suiteId),p=String(d?.keyId),y=b=>c.push({suiteId:l,keyId:p,valid:!1,error:b});try{if(vr(p)!==e){y(`Key does not belong to agent '${e}'`);continue}let b=await this.keyRegistry.getPublicKey(p);if(!b){y("Key not found");continue}if(b.meta.suiteId!==l){y(`Suite mismatch: key is ${b.meta.suiteId}, signature claims ${l}`);continue}if(!Gi(b.meta,s)){y(`Key status not accepted (status: ${b.meta.status??"active"}, policy: ${s})`);continue}if(!(d.signature instanceof Uint8Array)){y("Signature must be a Uint8Array");continue}await this.verifyAgainst(b.meta,b.publicKey,r,d.signature)?c.push({suiteId:l,keyId:p,valid:!0}):y("Signature verification failed")}catch(b){y(b instanceof Error?b.message:String(b))}}if(i.length===0)return a(`No required suites: agent '${e}' has no usable keys and options.requiredSuites was not given`,c);if(c.length===0)return a("No signatures supplied",c);let f=i.filter(d=>!c.some(l=>l.valid&&l.suiteId===d)),u=c.every(d=>d.valid===!0);return{results:c,allValid:u&&f.length===0,requiredSuites:i,missingSuites:f,...f.length>0?{error:`No valid signature for required suite(s): ${f.join(", ")}`}:{}}}generateMnemonic(e=256){return new Re().generateMnemonic(e)}async createKeyFromMnemonic(e,r,n,o=Re.bitcoinPath(0,0,0),s,i={}){let c=new Re().mnemonicToSeed(n,s);try{return await this.createKey(e,r,{...i,derivationContext:{seed:c,path:o}})}finally{c.fill(0)}}getCapabilities(e){let r=this.suiteRegistry.getSuite(e),n=[];return r.capabilities?.derivation&&n.push("derivation"),r.capabilities?.encryption&&n.push("encryption"),r.capabilities?.threshold&&n.push("threshold"),n}getSuitesWithCapability(e){return this.suiteRegistry.getAllSuites().filter(n=>!!n.capabilities?.[e]).map(n=>n.suiteId)}async createWalletKey(e,r,n,o={}){if(!n||typeof n.coinType!="number")throw new Error("createWalletKey requires path.coinType (SLIP-44: Bitcoin is 0, Bitcoin SV is 236)");let s=Re.bip44Path(n.coinType,n.account??0,n.change?1:0,n.index??0);return this.createKeyFromMnemonic(e,{primarySignatureSuite:"bsv-ecdsa-secp256k1"},r,s,n.passphrase,o)}async createBitcoinWalletKey(e,r,n=0,o=0,s=!1,i={}){let a=Re.bitcoinPath(n,s?1:0,o);return this.createKeyFromMnemonic(e,{primarySignatureSuite:"bsv-ecdsa-secp256k1"},r,a,void 0,i)}getHashAlgorithm(e){return e.startsWith("ml-dsa")?"sha3-256":"sha256"}async registerUnderFreshId(e,r,n){let o=r.split("-")[0].replace(/[^A-Za-z0-9]/g,"")||"key";for(let s=0;s<Yi;s++){let i=await this.getNextCounter(e),a=`${e}:pk-${o}-${i}`;try{return await n(a)}catch(c){if(!(c instanceof Tt))throw c;this.counterInitialized.delete(e),this.keyCounter.delete(e)}}throw new Error(`Could not allocate a key ID for agent '${e}' after ${Yi} attempts`)}async getNextCounter(e){if(!this.counterInitialized.has(e)){if(!this.counterInitPromises.has(e)){let s=(async()=>{try{let a=(await this.keyRegistry.listKeys()).reduce((c,f)=>{if(vr(f.keyId)!==e)return c;let u=f.keyId.slice(e.length+1),d=pf.exec(u);if(!d)return c;let l=parseInt(d[1],10);return Number.isSafeInteger(l)?Math.max(c,l):c},0);this.keyCounter.set(e,Math.max(a,this.keyCounter.get(e)||0)),this.counterInitialized.add(e)}finally{this.counterInitPromises.delete(e)}})();this.counterInitPromises.set(e,s)}let o=this.counterInitPromises.get(e);o&&await o}let n=(this.keyCounter.get(e)||0)+1;return this.keyCounter.set(e,n),n}sortKeysByCreatedAt(e){return[...e].sort((r,n)=>{let o=new Date(r.meta.createdAt).getTime(),s=new Date(n.meta.createdAt).getTime();if(o!==s)return o-s;let i=this.getSuitePriority(r.meta.suiteId)-this.getSuitePriority(n.meta.suiteId);return i!==0?i:r.meta.keyId.localeCompare(n.meta.keyId)})}getSuitePriority(e){return e.startsWith("ml-dsa")?0:e.includes("ecdsa")?1:2}};async function Fo(t){let e=t?.keyRegistry??new Kt(new dt);return new mn({keyRegistry:e,suiteRegistry:lt})}var yf={createKeySDK:Fo};typeof window<"u"&&(window.LumenKeys={createKeySDK:Fo});return nc(gf);})();
|
|
2052
2052
|
/*! Bundled license information:
|
|
2053
2053
|
|
|
2054
|
-
@noble/hashes/utils.js:
|
|
2055
|
-
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
2056
|
-
|
|
2057
2054
|
@noble/curves/utils.js:
|
|
2058
2055
|
@noble/curves/abstract/modular.js:
|
|
2059
2056
|
@noble/curves/abstract/curve.js:
|