LarpixClient/webroot/crypto-pq.js
olcxja a660ba32bd
All checks were successful
Android Build / publish (push) Successful in 28s
Linux Build / publish (push) Successful in 52s
Switch to X25519 + ML-KEM-768 encryption
2026-05-27 20:40:24 +02:00

14 lines
55 KiB
JavaScript

(()=>{var qn=Object.create;var dr=Object.defineProperty;var Zn=Object.getOwnPropertyDescriptor;var Gn=Object.getOwnPropertyNames;var Xn=Object.getPrototypeOf,Yn=Object.prototype.hasOwnProperty;var $n=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var S=(e,t)=>()=>(e&&(t=e(e=0)),t);var Wn=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Qn=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Gn(t))!Yn.call(e,n)&&n!==r&&dr(e,n,{get:()=>t[n],enumerable:!(o=Zn(t,n))||o.enumerable});return e};var Jn=(e,t,r)=>(r=e!=null?qn(Xn(e)):{},Qn(t||!e||!e.__esModule?dr(r,"default",{value:e,enumerable:!0}):r,e));function we(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function qt(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(`${r}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new RangeError(`${r}expected integer >= 0, got ${e}`)}}function J(e,t,r=""){let o=we(e),n=e?.length,i=t!==void 0;if(!o||i&&n!==t){let s=r&&`"${r}" `,c=i?` of length ${t}`:"",f=o?`length=${n}`:`type=${typeof e}`,a=s+"expected Uint8Array"+c+", got "+f;throw o?new RangeError(a):new TypeError(a)}return e}function _e(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function br(e,t){J(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function Ft(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Zt(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Gt(e){if(J(e),xr)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=to[e[r]];return t}function pr(e){if(e>=st._0&&e<=st._9)return e-st._0;if(e>=st.A&&e<=st.F)return e-(st.A-10);if(e>=st.a&&e<=st.f)return e-(st.a-10)}function Rt(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(xr)try{return Uint8Array.fromHex(e)}catch(n){throw n instanceof SyntaxError?new RangeError(n.message):n}let t=e.length,r=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let o=new Uint8Array(r);for(let n=0,i=0;n<r;n++,i+=2){let s=pr(e.charCodeAt(i)),c=pr(e.charCodeAt(i+1));if(s===void 0||c===void 0){let f=e[i]+e[i+1];throw new RangeError('hex string expected, got non-hex character "'+f+'" at index '+i)}o[n]=s*16+c}return o}function ge(...e){let t=0;for(let o=0;o<e.length;o++){let n=e[o];J(n),t+=n.length}let r=new Uint8Array(t);for(let o=0,n=0;o<e.length;o++){let i=e[o];r.set(i,n),n+=i.length}return r}function yr(e,t={}){let r=(n,i)=>e(i).update(n).digest(),o=e(void 0);return r.outputLen=o.outputLen,r.blockLen=o.blockLen,r.canXOF=o.canXOF,r.create=n=>e(n),Object.assign(r,t),Object.freeze(r)}function mr(e=32){qt(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var xr,to,st,wr,Ut=S(()=>{xr=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",to=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));st={_0:48,_9:57,A:65,F:70,a:97,f:102};wr=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])})});var Xt,C,_r=S(()=>{Ut();Xt=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,o,n){this.blockLen=t,this.outputLen=r,this.padOffset=o,this.isLE=n,this.buffer=new Uint8Array(t),this.view=Zt(this.buffer)}update(t){_e(this),J(t);let{view:r,buffer:o,blockLen:n}=this,i=t.length;for(let s=0;s<i;){let c=Math.min(n-this.pos,i-s);if(c===n){let f=Zt(t);for(;n<=i-s;s+=n)this.process(f,s);continue}o.set(t.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===n&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){_e(this),br(t,this),this.finished=!0;let{buffer:r,view:o,blockLen:n,isLE:i}=this,{pos:s}=this;r[s++]=128,Ft(this.buffer.subarray(s)),this.padOffset>n-s&&(this.process(o,0),s=0);for(let h=s;h<n;h++)r[h]=0;o.setBigUint64(n-8,BigInt(this.length*8),i),this.process(o,0);let c=Zt(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let a=f/4,u=this.get();if(a>u.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<a;h++)c.setUint32(4*h,u[h],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let o=t.slice(0,r);return this.destroy(),o}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:o,length:n,finished:i,destroyed:s,pos:c}=this;return t.destroyed=s,t.finished=i,t.length=n,t.pos=c,n%r&&t.buffer.set(o),t}clone(){return this._cloneInto()}},C=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209])});function eo(e,t=!1){return t?{h:Number(e&Yt),l:Number(e>>gr&Yt)}:{h:Number(e>>gr&Yt)|0,l:Number(e&Yt)|0}}function Er(e,t=!1){let r=e.length,o=new Uint32Array(r),n=new Uint32Array(r);for(let i=0;i<r;i++){let{h:s,l:c}=eo(e[i],t);[o[i],n[i]]=[s,c]}return[o,n]}function et(e,t,r,o){let n=(t>>>0)+(o>>>0);return{h:e+r+(n/2**32|0)|0,l:n|0}}var Yt,gr,Ee,ve,gt,Et,Pt,Ht,vr,Sr,Br,Ar,Or,Tr,kr=S(()=>{Yt=BigInt(4294967295),gr=BigInt(32);Ee=(e,t,r)=>e>>>r,ve=(e,t,r)=>e<<32-r|t>>>r,gt=(e,t,r)=>e>>>r|t<<32-r,Et=(e,t,r)=>e<<32-r|t>>>r,Pt=(e,t,r)=>e<<64-r|t>>>r-32,Ht=(e,t,r)=>e>>>r-32|t<<64-r;vr=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Sr=(e,t,r,o)=>t+r+o+(e/2**32|0)|0,Br=(e,t,r,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(o>>>0),Ar=(e,t,r,o,n)=>t+r+o+n+(e/2**32|0)|0,Or=(e,t,r,o,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(o>>>0)+(n>>>0),Tr=(e,t,r,o,n,i)=>t+r+o+n+i+(e/2**32|0)|0});var Ir,no,oo,ut,lt,Se,Be,Ae,Lr=S(()=>{_r();kr();Ut();Ir=Er(["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(e=>BigInt(e))),no=Ir[0],oo=Ir[1],ut=new Uint32Array(80),lt=new Uint32Array(80),Se=class extends Xt{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:o,Bl:n,Ch:i,Cl:s,Dh:c,Dl:f,Eh:a,El:u,Fh:h,Fl:x,Gh:d,Gl:p,Hh:w,Hl:l}=this;return[t,r,o,n,i,s,c,f,a,u,h,x,d,p,w,l]}set(t,r,o,n,i,s,c,f,a,u,h,x,d,p,w,l){this.Ah=t|0,this.Al=r|0,this.Bh=o|0,this.Bl=n|0,this.Ch=i|0,this.Cl=s|0,this.Dh=c|0,this.Dl=f|0,this.Eh=a|0,this.El=u|0,this.Fh=h|0,this.Fl=x|0,this.Gh=d|0,this.Gl=p|0,this.Hh=w|0,this.Hl=l|0}process(t,r){for(let y=0;y<16;y++,r+=4)ut[y]=t.getUint32(r),lt[y]=t.getUint32(r+=4);for(let y=16;y<80;y++){let B=ut[y-15]|0,E=lt[y-15]|0,L=gt(B,E,1)^gt(B,E,8)^Ee(B,E,7),T=Et(B,E,1)^Et(B,E,8)^ve(B,E,7),A=ut[y-2]|0,v=lt[y-2]|0,U=gt(A,v,19)^Pt(A,v,61)^Ee(A,v,6),H=Et(A,v,19)^Ht(A,v,61)^ve(A,v,6),j=Br(T,H,lt[y-7],lt[y-16]),R=Ar(j,L,U,ut[y-7],ut[y-16]);ut[y]=R|0,lt[y]=j|0}let{Ah:o,Al:n,Bh:i,Bl:s,Ch:c,Cl:f,Dh:a,Dl:u,Eh:h,El:x,Fh:d,Fl:p,Gh:w,Gl:l,Hh:b,Hl:m}=this;for(let y=0;y<80;y++){let B=gt(h,x,14)^gt(h,x,18)^Pt(h,x,41),E=Et(h,x,14)^Et(h,x,18)^Ht(h,x,41),L=h&d^~h&w,T=x&p^~x&l,A=Or(m,E,T,oo[y],lt[y]),v=Tr(A,b,B,L,no[y],ut[y]),U=A|0,H=gt(o,n,28)^Pt(o,n,34)^Pt(o,n,39),j=Et(o,n,28)^Ht(o,n,34)^Ht(o,n,39),R=o&i^o&c^i&c,_=n&s^n&f^s&f;b=w|0,m=l|0,w=d|0,l=p|0,d=h|0,p=x|0,{h,l:x}=et(a|0,u|0,v|0,U|0),a=c|0,u=f|0,c=i|0,f=s|0,i=o|0,s=n|0;let O=vr(U,j,_);o=Sr(O,v,H,R),n=O|0}({h:o,l:n}=et(this.Ah|0,this.Al|0,o|0,n|0)),{h:i,l:s}=et(this.Bh|0,this.Bl|0,i|0,s|0),{h:c,l:f}=et(this.Ch|0,this.Cl|0,c|0,f|0),{h:a,l:u}=et(this.Dh|0,this.Dl|0,a|0,u|0),{h,l:x}=et(this.Eh|0,this.El|0,h|0,x|0),{h:d,l:p}=et(this.Fh|0,this.Fl|0,d|0,p|0),{h:w,l}=et(this.Gh|0,this.Gl|0,w|0,l|0),{h:b,l:m}=et(this.Hh|0,this.Hl|0,b|0,m|0),this.set(o,n,i,s,c,f,a,u,h,x,d,p,w,l,b,m)}roundClean(){Ft(ut,lt)}destroy(){this.destroyed=!0,Ft(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Be=class extends Se{Ah=C[0]|0;Al=C[1]|0;Bh=C[2]|0;Bl=C[3]|0;Ch=C[4]|0;Cl=C[5]|0;Dh=C[6]|0;Dl=C[7]|0;Eh=C[8]|0;El=C[9]|0;Fh=C[10]|0;Fl=C[11]|0;Gh=C[12]|0;Gl=C[13]|0;Hh=C[14]|0;Hl=C[15]|0;constructor(){super(64)}},Ae=yr(()=>new Be,wr(3))});function Qt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new TypeError(r+"expected boolean, got type="+typeof e)}return e}function io(e){if(typeof e=="bigint"){if(!$t(e))throw new RangeError("positive bigint expected, got "+e)}else Te(e);return e}function dt(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function Rr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?Wt:BigInt("0x"+e)}function Fe(e){return Rr(Gt(e))}function rt(e){return Rr(Gt(pt(J(e)).reverse()))}function Re(e,t){if(qt(t),t===0)throw new RangeError("zero length");e=io(e);let r=e.toString(16);if(r.length>t*2)throw new RangeError("number too large");return Rt(r.padStart(t*2,"0"))}function Jt(e,t){return Re(e,t).reverse()}function Ur(e,t){if(e=V(e),t=V(t),e.length!==t.length)return!1;let r=0;for(let o=0;o<e.length;o++)r|=e[o]^t[o];return r===0}function pt(e){return Uint8Array.from(V(e))}function te(e){if(typeof e!="string")throw new TypeError("ascii string expected, got "+typeof e);return Uint8Array.from(e,(t,r)=>{let o=t.charCodeAt(0);if(t.length!==1||o>127)throw new RangeError(`string contains non-ASCII character "${e[r]}" with code ${o} at position ${r}`);return o})}function so(e,t,r){return $t(e)&&$t(t)&&$t(r)&&t<=e&&e<r}function kt(e,t,r,o){if(!so(t,r,o))throw new RangeError("expected valid "+e+": "+r+" <= n < "+o+", got "+t)}function Ue(e){if(e<Wt)throw new Error("expected non-negative bigint, got "+e);let t;for(t=0;e>Wt;e>>=Oe,t+=1);return t}function bt(e,t={},r={}){if(Object.prototype.toString.call(e)!=="[object Object]")throw new TypeError("expected valid options object");function o(i,s,c){if(!c&&s!=="function"&&!Object.hasOwn(e,i))throw new TypeError(`param "${i}" is invalid: expected own property`);let f=e[i];if(c&&f===void 0)return;let a=typeof f;if(a!==s||f===null)throw new TypeError(`param "${i}" is invalid: expected ${s}, got ${a}`)}let n=(i,s)=>Object.entries(i).forEach(([c,f])=>o(c,f,s));n(t,!1),n(r,!0)}var V,Te,ke,ht,Fr,Ie,Le,Wt,Oe,$t,Pr,Pe,vt=S(()=>{Ut();V=(e,t,r)=>J(e,t,r),Te=qt,ke=Gt,ht=(...e)=>ge(...e),Fr=e=>Rt(e),Ie=we,Le=e=>mr(e),Wt=BigInt(0),Oe=BigInt(1);$t=e=>typeof e=="bigint"&&Wt<=e;Pr=e=>(Oe<<BigInt(e))-Oe;Pe=()=>{throw new Error("not implemented")}});function I(e,t){if(t<=z)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=z?r:t+r}function X(e,t,r){if(t<z)throw new Error("pow2: expected non-negative exponent, got "+t);let o=e;for(;t-- >z;)o*=o,o%=r;return o}function Hr(e,t){if(e===z)throw new Error("invert: expected non-zero number");if(t<=z)throw new Error("invert: expected positive modulus, got "+t);let r=I(e,t),o=t,n=z,i=P,s=P,c=z;for(;r!==z;){let a=o/r,u=o-r*a,h=n-s*a,x=i-c*a;o=r,r=u,n=s,i=c,s=h,c=x}if(o!==P)throw new Error("invert: does not exist");return I(n,t)}function He(e,t,r){let o=e;if(!o.eql(o.sqr(t),r))throw new Error("Cannot find square root")}function Vr(e,t){let r=e,o=(r.ORDER+P)/Nr,n=r.pow(t,o);return He(r,n,t),n}function ao(e,t){let r=e,o=(r.ORDER-Dr)/Kr,n=r.mul(t,St),i=r.pow(n,o),s=r.mul(t,i),c=r.mul(r.mul(s,St),i),f=r.mul(s,r.sub(c,r.ONE));return He(r,f,t),f}function uo(e){let t=ne(e),r=qr(e),o=r(t,t.neg(t.ONE)),n=r(t,o),i=r(t,t.neg(o)),s=(e+co)/Mr;return((c,f)=>{let a=c,u=a.pow(f,s),h=a.mul(u,o),x=a.mul(u,n),d=a.mul(u,i),p=a.eql(a.sqr(h),f),w=a.eql(a.sqr(x),f);u=a.cmov(u,h,p),h=a.cmov(d,x,w);let l=a.eql(a.sqr(h),f),b=a.cmov(u,h,l);return He(a,b,f),b})}function qr(e){if(e<zr)throw new Error("sqrt is not defined for small field");let t=e-P,r=0;for(;t%St===z;)t/=St,r++;let o=St,n=ne(e);for(;jr(n,o)===1;)if(o++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Vr;let i=n.pow(o,t),s=(t+P)/St;return function(f,a){let u=f;if(u.is0(a))return a;if(jr(u,a)!==1)throw new Error("Cannot find square root");let h=r,x=u.mul(u.ONE,i),d=u.pow(a,t),p=u.pow(a,s);for(;!u.eql(d,u.ONE);){if(u.is0(d))return u.ZERO;let w=1,l=u.sqr(d);for(;!u.eql(l,u.ONE);)if(w++,l=u.sqr(l),w===h)throw new Error("Cannot find square root");let b=P<<BigInt(h-w-1),m=u.pow(x,b);h=w,x=u.sqr(m),d=u.mul(d,x),p=u.mul(p,m)}return p}}function lo(e){return e%Nr===zr?Vr:e%Kr===Dr?ao:e%Mr===fo?uo(e):qr(e)}function Zr(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=ho.reduce((o,n)=>(o[n]="function",o),t);if(bt(e,r),dt(e.BYTES,"BYTES"),dt(e.BITS,"BITS"),e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=P)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function po(e,t,r){let o=e;if(r<z)throw new Error("invalid exponent, negatives unsupported");if(r===z)return o.ONE;if(r===P)return t;let n=o.ONE,i=t;for(;r>z;)r&P&&(n=o.mul(n,i)),i=o.sqr(i),r>>=P;return n}function re(e,t,r=!1){let o=e,n=new Array(t.length).fill(r?o.ZERO:void 0),i=t.reduce((c,f,a)=>o.is0(f)?c:(n[a]=c,o.mul(c,f)),o.ONE),s=o.inv(i);return t.reduceRight((c,f,a)=>o.is0(f)?c:(n[a]=o.mul(c,n[a]),o.mul(c,f)),s),n}function jr(e,t){let r=e,o=(r.ORDER-P)/St,n=r.pow(t,o),i=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),c=r.eql(n,r.neg(r.ONE));if(!i&&!s&&!c)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function bo(e,t){if(t!==void 0&&Te(t),e<=z)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=Ue(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${t})`);let o=t!==void 0?t:r,n=Math.ceil(o/8);return{nBitLength:o,nByteLength:n}}function ne(e,t={}){return new ee(e,t)}var z,P,St,zr,Nr,Dr,co,Kr,fo,Mr,ct,ho,Cr,ee,oe=S(()=>{vt();z=BigInt(0),P=BigInt(1),St=BigInt(2),zr=BigInt(3),Nr=BigInt(4),Dr=BigInt(5),co=BigInt(7),Kr=BigInt(8),fo=BigInt(9),Mr=BigInt(16);ct=(e,t)=>(I(e,t)&P)===P,ho=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];Cr=new WeakMap,ee=class{ORDER;BITS;BYTES;isLE;ZERO=z;ONE=P;_lengths;_mod;constructor(t,r={}){if(t<=P)throw new Error("invalid field: expected ORDER > 1, got "+t);let o;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(o=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:n,nByteLength:i}=bo(t,o);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=n,this.BYTES=i,Object.freeze(this)}create(t){return I(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return z<=t&&t<this.ORDER}is0(t){return t===z}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&P)===P}neg(t){return I(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return I(t*t,this.ORDER)}add(t,r){return I(t+r,this.ORDER)}sub(t,r){return I(t-r,this.ORDER)}mul(t,r){return I(t*r,this.ORDER)}pow(t,r){return po(this,t,r)}div(t,r){return I(t*Hr(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return Hr(t,this.ORDER)}sqrt(t){let r=Cr.get(this);return r||Cr.set(this,r=lo(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?Jt(t,this.BYTES):Re(t,this.BYTES)}fromBytes(t,r=!1){V(t);let{_lengths:o,BYTES:n,isLE:i,ORDER:s,_mod:c}=this;if(o){if(t.length<1||!o.includes(t.length)||t.length>n)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let a=new Uint8Array(n);a.set(t,i?0:a.length-t.length),t=a}if(t.length!==n)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=i?rt(t):Fe(t);if(c&&(f=I(f,s)),!r&&!this.isValid(f))throw new Error("invalid field element: outside of range 0..ORDER");return f}invertBatch(t){return re(this,t)}cmov(t,r,o){return Qt(o,"condition"),o?r:t}};Object.freeze(ee.prototype)});function Gr(e,t){let r=t.negate();return e?r:t}function ce(e,t){let r=re(e.Fp,t.map(o=>o.Z));return t.map((o,n)=>e.fromAffine(o.toAffine(r[n])))}function Wr(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function je(e,t){Wr(e,t);let r=Math.ceil(t/e)+1,o=2**(e-1),n=2**e,i=Pr(e),s=BigInt(e);return{windows:r,windowSize:o,mask:i,maxNumber:n,shiftBy:s}}function Xr(e,t,r){let{windowSize:o,mask:n,maxNumber:i,shiftBy:s}=r,c=Number(e&n),f=e>>s;c>o&&(c-=i,f+=Ne);let a=t*o,u=a+Math.abs(c)-1,h=c===0,x=c<0,d=t%2!==0;return{nextN:f,offset:u,isZero:h,isNeg:x,isNegF:d,offsetF:a}}function ze(e){return Qr.get(e)||1}function Yr(e){if(e!==ie)throw new Error("invalid wNAF")}function $r(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Zr(t),t}else return ne(e,{isLE:r})}function Jr(e,t,r={},o){if(o===void 0&&(o=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let f of["p","n","h"]){let a=t[f];if(!(typeof a=="bigint"&&a>ie))throw new Error(`CURVE.${f} must be positive bigint`)}let n=$r(t.p,r.Fp,o),i=$r(t.n,r.Fn,o),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let f of c)if(!n.isValid(t[f]))throw new Error(`CURVE.${f} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:n,Fn:i}}function De(e,t){return function(o){let n=e(o);return{secretKey:n,publicKey:t(n)}}}var ie,Ne,Ce,Qr,se,Ke=S(()=>{vt();oe();ie=BigInt(0),Ne=BigInt(1);Ce=new WeakMap,Qr=new WeakMap;se=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,o=this.ZERO){let n=t;for(;r>ie;)r&Ne&&(o=o.add(n)),n=n.double(),r>>=Ne;return o}precomputeWindow(t,r){let{windows:o,windowSize:n}=je(r,this.bits),i=[],s=t,c=s;for(let f=0;f<o;f++){c=s,i.push(c);for(let a=1;a<n;a++)c=c.add(s),i.push(c);s=c.double()}return i}wNAF(t,r,o){if(!this.Fn.isValid(o))throw new Error("invalid scalar");let n=this.ZERO,i=this.BASE,s=je(t,this.bits);for(let c=0;c<s.windows;c++){let{nextN:f,offset:a,isZero:u,isNeg:h,isNegF:x,offsetF:d}=Xr(o,c,s);o=f,u?i=i.add(Gr(x,r[d])):n=n.add(Gr(h,r[a]))}return Yr(o),{p:n,f:i}}wNAFUnsafe(t,r,o,n=this.ZERO){let i=je(t,this.bits);for(let s=0;s<i.windows&&o!==ie;s++){let{nextN:c,offset:f,isZero:a,isNeg:u}=Xr(o,s,i);if(o=c,!a){let h=r[f];n=n.add(u?h.negate():h)}}return Yr(o),n}getPrecomputes(t,r,o){let n=Ce.get(r);return n||(n=this.precomputeWindow(r,t),t!==1&&(typeof o=="function"&&(n=o(n)),Ce.set(r,n))),n}cached(t,r,o){let n=ze(t);return this.wNAF(n,this.getPrecomputes(n,t,o),r)}unsafe(t,r,o,n){let i=ze(t);return i===1?this._unsafeLadder(t,r,n):this.wNAFUnsafe(i,this.getPrecomputes(i,t,o),r,n)}createCache(t,r){Wr(r,this.bits),Qr.set(t,r),Ce.delete(t)}hasCache(t){return ze(t)!==1}}});function yo(e,t,r,o){let n=e.sqr(r),i=e.sqr(o),s=e.add(e.mul(t.a,n),i),c=e.add(e.ONE,e.mul(t.d,e.mul(n,i)));return e.eql(s,c)}function tn(e,t={}){let r=t,o=Jr("edwards",e,r,r.FpFnLE),{Fp:n,Fn:i}=o,s=o.CURVE,{h:c}=s;bt(r,{},{uvRatio:"function"});let f=Me<<BigInt(i.BYTES*8)-M,a=w=>n.create(w),u=r.uvRatio===void 0?(w,l)=>{try{return{isValid:!0,value:n.sqrt(n.div(w,l))}}catch{return{isValid:!1,value:xt}}}:r.uvRatio;if(!yo(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function h(w,l,b=!1){let m=b?M:xt;return kt("coordinate "+w,l,m,f),l}function x(w){if(!(w instanceof d))throw new Error("EdwardsPoint expected")}class d{static BASE=new d(s.Gx,s.Gy,M,a(s.Gx*s.Gy));static ZERO=new d(xt,M,M,xt);static Fp=n;static Fn=i;X;Y;Z;T;constructor(l,b,m,y){this.X=h("x",l),this.Y=h("y",b),this.Z=h("z",m,!0),this.T=h("t",y),Object.freeze(this)}static CURVE(){return s}static fromAffine(l){if(l instanceof d)throw new Error("extended point not allowed");let{x:b,y:m}=l||{};return h("x",b),h("y",m),new d(b,m,M,a(b*m))}static fromBytes(l,b=!1){let m=n.BYTES,{a:y,d:B}=s;l=pt(V(l,m,"point")),Qt(b,"zip215");let E=pt(l),L=l[m-1];E[m-1]=L&-129;let T=rt(E),A=b?f:n.ORDER;kt("point.y",T,xt,A);let v=a(T*T),U=a(v-M),H=a(B*v-y),{isValid:j,value:R}=u(U,H);if(!j)throw new Error("bad point: invalid y coordinate");let _=(R&M)===M,O=(L&128)!==0;if(!b&&R===xt&&O)throw new Error("bad point: x=0 and x_0=1");return O!==_&&(R=a(-R)),d.fromAffine({x:R,y:T})}static fromHex(l,b=!1){return d.fromBytes(Fr(l),b)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(l=8,b=!0){return p.createCache(this,l),b||this.multiply(Me),this}assertValidity(){let l=this,{a:b,d:m}=s;if(l.is0())throw new Error("bad point: ZERO");let{X:y,Y:B,Z:E,T:L}=l,T=a(y*y),A=a(B*B),v=a(E*E),U=a(v*v),H=a(T*b),j=a(v*a(H+A)),R=a(U+a(m*a(T*A)));if(j!==R)throw new Error("bad point: equation left != right (1)");let _=a(y*B),O=a(E*L);if(_!==O)throw new Error("bad point: equation left != right (2)")}equals(l){x(l);let{X:b,Y:m,Z:y}=this,{X:B,Y:E,Z:L}=l,T=a(b*L),A=a(B*y),v=a(m*L),U=a(E*y);return T===A&&v===U}is0(){return this.equals(d.ZERO)}negate(){return new d(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:l}=s,{X:b,Y:m,Z:y}=this,B=a(b*b),E=a(m*m),L=a(Me*a(y*y)),T=a(l*B),A=b+m,v=a(a(A*A)-B-E),U=T+E,H=U-L,j=T-E,R=a(v*H),_=a(U*j),O=a(v*j),K=a(H*U);return new d(R,_,K,O)}add(l){x(l);let{a:b,d:m}=s,{X:y,Y:B,Z:E,T:L}=this,{X:T,Y:A,Z:v,T:U}=l,H=a(y*T),j=a(B*A),R=a(L*m*U),_=a(E*v),O=a((y+B)*(T+A)-H-j),K=_-R,_t=_+R,Q=a(j-b*H),tt=a(O*K),ot=a(_t*Q),it=a(O*Q),at=a(K*_t);return new d(tt,ot,at,it)}subtract(l){return x(l),this.add(l.negate())}multiply(l){if(!i.isValidNot0(l))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:b,f:m}=p.cached(this,l,y=>ce(d,y));return ce(d,[b,m])[0]}multiplyUnsafe(l){if(!i.isValid(l))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return l===xt?d.ZERO:this.is0()||l===M?this:p.unsafe(this,l,b=>ce(d,b))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return p.unsafe(this,s.n).is0()}toAffine(l){let b=this,m=l,{X:y,Y:B,Z:E}=b,L=b.is0();m==null&&(m=L?xo:n.inv(E));let T=a(y*m),A=a(B*m),v=n.mul(E,m);if(L)return{x:xt,y:M};if(v!==M)throw new Error("invZ was invalid");return{x:T,y:A}}clearCofactor(){return c===M?this:this.multiplyUnsafe(c)}toBytes(){let{x:l,y:b}=this.toAffine(),m=n.toBytes(b);return m[m.length-1]|=l&M?128:0,m}toHex(){return ke(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let p=new se(d,i.BITS);return i.BITS>=8&&d.BASE.precompute(8),Object.freeze(d.prototype),Object.freeze(d),d}var xt,M,Me,xo,fe,en=S(()=>{vt();Ke();xt=BigInt(0),M=BigInt(1),Me=BigInt(2),xo=BigInt(8);fe=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){Pe()}static fromHex(t){Pe()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return ke(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.ep.precompute(t,r),this}}});function jt(e,t){if(dt(e),dt(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(e<0||e>2**(8*t)-1)throw new Error("invalid I2OSP input: "+e);let r=Array.from({length:t}).fill(0);for(let o=t-1;o>=0;o--)r[o]=e&255,e>>>=8;return new Uint8Array(r)}function mo(e,t){let r=new Uint8Array(e.length);for(let o=0;o<e.length;o++)r[o]=e[o]^t[o];return r}function wo(e){if(!Ie(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof e=="string"?te(e):e;if(t.length===0)throw new Error("DST must be non-empty");return t}function Ve(e,t,r,o){V(e),dt(r),t=wo(t),t.length>255&&(t=o(ht(te("H2C-OVERSIZE-DST-"),t)));let{outputLen:n,blockLen:i}=o,s=Math.ceil(r/n);if(r>65535||s>255)throw new Error("expand_message_xmd: invalid lenInBytes");let c=ht(t,jt(t.length,1)),f=new Uint8Array(i),a=jt(r,2),u=new Array(s),h=o(ht(f,e,a,jt(0,1),c));u[0]=o(ht(h,jt(1,1),c));for(let d=1;d<s;d++){let p=[mo(h,u[d-1]),jt(d+1,1),c];u[d]=o(ht(...p))}return ht(...u).slice(0,r)}var rn,nn=S(()=>{vt();rn="HashToScalar-"});function _o(e){return bt(e,{P:"bigint",type:"string",adjustScalarBytes:"function",powPminus2:"function"},{randomBytes:"function"}),Object.freeze({...e})}function on(e){let t=_o(e),{P:r,type:o,adjustScalarBytes:n,powPminus2:i,randomBytes:s}=t,c=o==="x25519";if(!c&&o!=="x448")throw new Error("invalid type");let f=s===void 0?Le:s,a=c?255:448,u=c?32:56,h=BigInt(c?9:5),x=BigInt(c?121665:39081),d=c?ae**BigInt(254):ae**BigInt(447),p=c?BigInt(8)*ae**BigInt(251)-It:BigInt(4)*ae**BigInt(445)-It,w=d+p+It,l=_=>I(_,r),b=m(h);function m(_){return Jt(l(_),u)}function y(_){let O=pt(V(_,u,"uCoordinate"));return c&&(O[31]&=127),l(rt(O))}function B(_){return rt(n(pt(V(_,u,"scalar"))))}function E(_,O){let K=U(y(O),B(_));if(K===Ct)throw new Error("invalid private or public key received");return m(K)}function L(_){return E(_,b)}let T=L,A=E;function v(_,O,K){let _t=l(_*(O-K));return O=l(O-_t),K=l(K+_t),{x_2:O,x_3:K}}function U(_,O){kt("u",_,Ct,r),kt("scalar",O,d,w);let K=O,_t=_,Q=It,tt=Ct,ot=_,it=It,at=Ct;for(let be=BigInt(a-1);be>=Ct;be--){let sr=K>>be&It;at^=sr,{x_2:Q,x_3:ot}=v(at,Q,ot),{x_2:tt,x_3:it}=v(at,tt,it),at=sr;let xe=Q+tt,ye=l(xe*xe),me=Q-tt,cr=l(me*me),fr=ye-cr,Mn=ot+it,Vn=ot-it,ar=l(Vn*xe),ur=l(Mn*me),lr=ar+ur,hr=ar-ur;ot=l(lr*lr),it=l(_t*l(hr*hr)),Q=l(ye*cr),tt=l(fr*(ye+l(x*fr)))}({x_2:Q,x_3:ot}=v(at,Q,ot)),{x_2:tt,x_3:it}=v(at,tt,it);let Kn=i(tt);return l(Q*Kn)}let H={secretKey:u,publicKey:u,seed:u},j=_=>(_=_===void 0?f(u):_,V(_,H.seed,"seed"),_),R={randomSecretKey:j};return Object.freeze(H),Object.freeze(R),Object.freeze({keygen:De(j,T),getSharedSecret:A,getPublicKey:T,scalarMult:E,scalarMultBase:L,utils:R,GuBytes:b.slice(),lengths:H})}var Ct,It,ae,sn=S(()=>{vt();Ke();oe();Ct=BigInt(0),It=BigInt(1),ae=BigInt(2)});function un(e){let t=BigInt(10),r=BigInt(20),o=BigInt(40),n=BigInt(80),i=At,c=e*e%i*e%i,f=X(c,cn,i)*c%i,a=X(f,ft,i)*e%i,u=X(a,vo,i)*a%i,h=X(u,t,i)*u%i,x=X(h,r,i)*h%i,d=X(x,o,i)*x%i,p=X(d,n,i)*d%i,w=X(p,n,i)*d%i,l=X(w,t,i)*u%i;return{pow_p_5_8:X(l,cn,i)*e%i,b2:c}}function Bo(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}function Ye(e,t){let r=At,o=I(t*t*t,r),n=I(o*o*t,r),i=un(e*n).pow_p_5_8,s=I(e*o*i,r),c=I(t*s*s,r),f=s,a=I(s*qe,r),u=c===e,h=c===I(-e,r),x=c===I(-e*qe,r);return u&&(s=f),(h||x)&&(s=a),ct(s,r)&&(s=I(-s,r)),{isValid:u||h,value:s}}function an(e){let{d:t}=Xe,r=At,o=b=>yt.create(b),n=o(Ze*e*e),i=o((n+ft)*To),s=BigInt(-1),c=o((s-t*n)*o(n+t)),{isValid:f,value:a}=Ye(i,c),u=o(a*e);ct(u,r)||(u=o(-u)),f||(a=u),f||(s=n);let h=o(s*(n-ft)*ko-c),x=a*a,d=o((a+a)*c),p=o(h*Ao),w=o(ft-x),l=o(ft+x);return new Bt(o(d*l),o(w*p),o(p*l),o(d*w))}var go,ft,cn,Eo,vo,So,At,Xe,qe,Bt,yt,ln,hn,Ze,Ao,Oo,To,ko,fn,Io,Ge,mt,Lo,dn=S(()=>{Lr();Ut();en();nn();oe();sn();vt();go=BigInt(0),ft=BigInt(1),cn=BigInt(2),Eo=BigInt(3),vo=BigInt(5),So=BigInt(8),At=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Xe={p:At,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:So,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};qe=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");Bt=tn(Xe,{uvRatio:Ye}),yt=Bt.Fp,ln=Bt.Fn,hn=(()=>{let e=At;return on({P:e,type:"x25519",powPminus2:t=>{let{pow_p_5_8:r,b2:o}=un(t);return I(X(r,Eo,e)*o,e)},adjustScalarBytes:Bo})})(),Ze=qe,Ao=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Oo=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),To=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),ko=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),fn=e=>Ye(ft,e),Io=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Ge=e=>yt.create(rt(e)&Io);mt=class e extends fe{static BASE=new e(Bt.BASE);static ZERO=new e(Bt.ZERO);static Fp=yt;static Fn=ln;constructor(t){super(t)}static fromAffine(t){return new e(Bt.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static fromBytes(t){J(t,32);let{a:r,d:o}=Xe,n=At,i=B=>yt.create(B),s=Ge(t);if(!Ur(yt.toBytes(s),t)||ct(s,n))throw new Error("invalid ristretto255 encoding 1");let c=i(s*s),f=i(ft+r*c),a=i(ft-r*c),u=i(f*f),h=i(a*a),x=i(r*o*u-h),{isValid:d,value:p}=fn(i(x*h)),w=i(p*a),l=i(p*w*x),b=i((s+s)*w);ct(b,n)&&(b=i(-b));let m=i(f*l),y=i(b*m);if(!d||ct(y,n)||m===go)throw new Error("invalid ristretto255 encoding 2");return new e(new Bt(b,m,ft,y))}static fromHex(t){return e.fromBytes(Rt(t))}toBytes(){let{X:t,Y:r,Z:o,T:n}=this.ep,i=At,s=l=>yt.create(l),c=s(s(o+r)*s(o-r)),f=s(t*r),a=s(f*f),{value:u}=fn(s(c*a)),h=s(u*c),x=s(u*f),d=s(h*x*n),p;if(ct(n*d,i)){let l=s(r*Ze),b=s(t*Ze);t=l,r=b,p=s(h*Oo)}else p=x;ct(t*d,i)&&(r=s(-r));let w=s((o-r)*p);return ct(w,i)&&(w=s(-w)),yt.toBytes(w)}equals(t){this.assertSame(t);let{X:r,Y:o}=this.ep,{X:n,Y:i}=t.ep,s=a=>yt.create(a),c=s(r*i)===s(o*n),f=s(o*i)===s(r*n);return c||f}is0(){return this.equals(e.ZERO)}};Object.freeze(mt.BASE);Object.freeze(mt.ZERO);Object.freeze(mt.prototype);Object.freeze(mt);Lo=Object.freeze({Point:mt,hashToCurve(e,t){let r=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,o=Ve(e,r,64,Ae);return Lo.deriveToCurve(o)},hashToScalar(e,t={DST:rn}){let r=Ve(e,t.DST,64,Ae);return ln.create(rt(r))},deriveToCurve(e){J(e,64);let t=Ge(e.subarray(0,32)),r=an(t),o=Ge(e.subarray(32,64)),n=an(o);return new mt(r.add(n))}})});var q,wt=S(()=>{q=class extends Error{constructor(t){let r;t instanceof Error?r=t.message:typeof t=="string"?r=t:r="",super(r),this.name=this.constructor.name}}});var $e,We,Lt=S(()=>{$e=[2285,2571,2970,1812,1493,1422,287,202,3158,622,1577,182,962,2127,1855,1468,573,2004,264,383,2500,1458,1727,3199,2648,1017,732,608,1787,411,3124,1758,1223,652,2777,1015,2036,1491,3047,1785,516,3321,3009,2663,1711,2167,126,1469,2476,3239,3058,830,107,1908,3082,2378,2931,961,1821,2604,448,2264,677,2054,2226,430,555,843,2078,871,1550,105,422,587,177,3094,3038,2869,1574,1653,3083,778,1159,3182,2552,1483,2727,1119,1739,644,2457,349,418,329,3173,3254,817,1097,603,610,1322,2044,1864,384,2114,3193,1218,1994,2455,220,2142,1670,2144,1799,2051,794,1819,2475,2459,478,3221,3021,996,991,958,1869,1522,1628],We=[1701,1807,1460,2371,2338,2333,308,108,2851,870,854,1510,2535,1278,1530,1185,1659,1187,3109,874,1335,2111,136,1215,2945,1465,1285,2007,2719,2726,2232,2512,75,156,3e3,2911,2980,872,2685,1590,2210,602,1846,777,147,2170,2551,246,1676,1755,460,291,235,3152,2742,2907,3224,1779,2458,1251,2486,2774,2899,1103,1275,2652,1065,2881,725,1508,2368,398,951,247,1421,3222,2499,271,90,853,1860,3203,1162,1618,666,320,8,2813,1544,282,1838,1293,2314,552,2677,2106,1571,205,2918,1542,2721,2597,2312,681,130,1602,1871,829,2946,3065,1325,2756,1861,1474,1202,2367,3147,1752,2707,171,3127,3042,1907,1836,1517,359,758,1441]});function Fo(e,t=!1){return t?{h:Number(e&ue),l:Number(e>>pn&ue)}:{h:Number(e>>pn&ue)|0,l:Number(e&ue)|0}}function bn(e,t=!1){let r=e.length,o=new Uint32Array(r),n=new Uint32Array(r);for(let i=0;i<r;i++){let{h:s,l:c}=Fo(e[i],t);[o[i],n[i]]=[s,c]}return[o,n]}var ue,pn,N,D,Y,$,xn=S(()=>{ue=0xffffffffn,pn=32n;N=(e,t,r)=>e<<r|t>>>32-r,D=(e,t,r)=>t<<r|e>>>32-r,Y=(e,t,r)=>t<<r-32|e>>>64-r,$=(e,t,r)=>e<<r-32|t>>>64-r});function Ro(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Qe(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >0, got ${e}`)}}function le(e,t,r=""){let o=Ro(e),n=e?.length,i=t!==void 0;if(!o||i&&n!==t){let s=r&&`"${r}" `,c=i?` of length ${t}`:"",f=o?`length=${n}`:`type=${typeof e}`;throw new Error(s+"expected Uint8Array"+c+", got "+f)}return e}function Je(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function yn(e,t){le(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function mn(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function wn(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Po(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function Ho(e){for(let t=0;t<e.length;t++)e[t]=Po(e[t]);return e}var Uo,tr,_n=S(()=>{Uo=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;tr=Uo?e=>e:Ho});function Zo(e,t=24,r){r||(r=new Uint32Array(10));for(let o=24-t;o<24;o++){for(let f=0;f<10;f++)r[f]=e[f]^e[f+10]^e[f+20]^e[f+30]^e[f+40];{let f=Nt(r[2],r[3],1)^r[8],a=Dt(r[2],r[3],1)^r[9];e[0]^=f,e[1]^=a,e[10]^=f,e[11]^=a,e[20]^=f,e[21]^=a,e[30]^=f,e[31]^=a,e[40]^=f,e[41]^=a}{let f=Nt(r[4],r[5],1)^r[0],a=Dt(r[4],r[5],1)^r[1];e[2]^=f,e[3]^=a,e[12]^=f,e[13]^=a,e[22]^=f,e[23]^=a,e[32]^=f,e[33]^=a,e[42]^=f,e[43]^=a}{let f=Nt(r[6],r[7],1)^r[2],a=Dt(r[6],r[7],1)^r[3];e[4]^=f,e[5]^=a,e[14]^=f,e[15]^=a,e[24]^=f,e[25]^=a,e[34]^=f,e[35]^=a,e[44]^=f,e[45]^=a}{let f=Nt(r[8],r[9],1)^r[4],a=Dt(r[8],r[9],1)^r[5];e[6]^=f,e[7]^=a,e[16]^=f,e[17]^=a,e[26]^=f,e[27]^=a,e[36]^=f,e[37]^=a,e[46]^=f,e[47]^=a}{let f=Nt(r[0],r[1],1)^r[6],a=Dt(r[0],r[1],1)^r[7];e[8]^=f,e[9]^=a,e[18]^=f,e[19]^=a,e[28]^=f,e[29]^=a,e[38]^=f,e[39]^=a,e[48]^=f,e[49]^=a}let n=e[2],i=e[3],s,c;s=N(n,i,1),c=D(n,i,1),n=e[20],i=e[21],e[20]=s,e[21]=c,s=N(n,i,3),c=D(n,i,3),n=e[14],i=e[15],e[14]=s,e[15]=c,s=N(n,i,6),c=D(n,i,6),n=e[22],i=e[23],e[22]=s,e[23]=c,s=N(n,i,10),c=D(n,i,10),n=e[34],i=e[35],e[34]=s,e[35]=c,s=N(n,i,15),c=D(n,i,15),n=e[36],i=e[37],e[36]=s,e[37]=c,s=N(n,i,21),c=D(n,i,21),n=e[6],i=e[7],e[6]=s,e[7]=c,s=N(n,i,28),c=D(n,i,28),n=e[10],i=e[11],e[10]=s,e[11]=c,s=Y(n,i,36),c=$(n,i,36),n=e[32],i=e[33],e[32]=s,e[33]=c,s=Y(n,i,45),c=$(n,i,45),n=e[16],i=e[17],e[16]=s,e[17]=c,s=Y(n,i,55),c=$(n,i,55),n=e[42],i=e[43],e[42]=s,e[43]=c,s=N(n,i,2),c=D(n,i,2),n=e[48],i=e[49],e[48]=s,e[49]=c,s=N(n,i,14),c=D(n,i,14),n=e[8],i=e[9],e[8]=s,e[9]=c,s=N(n,i,27),c=D(n,i,27),n=e[30],i=e[31],e[30]=s,e[31]=c,s=Y(n,i,41),c=$(n,i,41),n=e[46],i=e[47],e[46]=s,e[47]=c,s=Y(n,i,56),c=$(n,i,56),n=e[38],i=e[39],e[38]=s,e[39]=c,s=N(n,i,8),c=D(n,i,8),n=e[26],i=e[27],e[26]=s,e[27]=c,s=N(n,i,25),c=D(n,i,25),n=e[24],i=e[25],e[24]=s,e[25]=c,s=Y(n,i,43),c=$(n,i,43),n=e[4],i=e[5],e[4]=s,e[5]=c,s=Y(n,i,62),c=$(n,i,62),n=e[40],i=e[41],e[40]=s,e[41]=c,s=N(n,i,18),c=D(n,i,18),n=e[28],i=e[29],e[28]=s,e[29]=c,s=Y(n,i,39),c=$(n,i,39),n=e[44],i=e[45],e[44]=s,e[45]=c,s=Y(n,i,61),c=$(n,i,61),n=e[18],i=e[19],e[18]=s,e[19]=c,s=N(n,i,20),c=D(n,i,20),n=e[12],i=e[13],e[12]=s,e[13]=c,s=Y(n,i,44),c=$(n,i,44),e[2]=s,e[3]=c;for(let f=0;f<50;f+=10)r[0]=e[f],r[1]=e[f+1],r[2]=e[f+2],r[3]=e[f+3],r[4]=e[f+4],r[5]=e[f+5],r[6]=e[f+6],r[7]=e[f+7],r[8]=e[f+8],r[9]=e[f+9],e[f+0]^=~r[2]&r[4],e[f+1]^=~r[3]&r[5],e[f+2]^=~r[4]&r[6],e[f+3]^=~r[5]&r[7],e[f+4]^=~r[6]&r[8],e[f+5]^=~r[7]&r[9],e[f+6]^=~r[8]&r[0],e[f+7]^=~r[9]&r[1],e[f+8]^=~r[0]&r[2],e[f+9]^=~r[1]&r[3];e[0]^=Vo[o],e[1]^=qo[o]}}var jo,zt,Co,zo,No,Do,Ko,Mo,gn,En,Vo,qo,Nt,Dt,nt,er=S(()=>{xn();_n();jo=0n,zt=1n,Co=2n,zo=7n,No=256n,Do=0x71n,Ko=[],Mo=[],gn=[];for(let e=0,t=zt,r=1,o=0;e<24;e++){[r,o]=[o,(2*r+3*o)%5],Ko.push(2*(5*o+r)),Mo.push((e+1)*(e+2)/2%64);let n=jo;for(let i=0;i<7;i++)t=(t<<zt^(t>>zo)*Do)%No,t&Co&&(n^=zt<<(zt<<BigInt(i))-zt);gn.push(n)}En=bn(gn,!0),Vo=En[0],qo=En[1],Nt=(e,t,r)=>r>32?Y(e,t,r):N(e,t,r),Dt=(e,t,r)=>r>32?$(e,t,r):D(e,t,r);nt=class e{constructor(t,r,o,n=!1,i=24){if(Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pos",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"posOut",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"finished",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"state32",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_B",{enumerable:!0,configurable:!0,writable:!0,value:new Uint32Array(10)}),Object.defineProperty(this,"blockLen",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"suffix",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"outputLen",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"enableXOF",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"rounds",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.blockLen=t,this.suffix=r,this.outputLen=o,this.enableXOF=n,this.rounds=i,Qe(o,"outputLen"),!(0<t&&t<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=mn(this.state)}clone(){return this._cloneInto()}reset(){this.state.fill(0),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1}keccak(){tr(this.state32),Zo(this.state32,this.rounds,this._B),tr(this.state32),this.posOut=0,this.pos=0}update(t){return Je(this),le(t),this.updateUnsafe(t)}updateUnsafe(t){let{blockLen:r,state:o}=this,n=t.length;for(let i=0;i<n;){let s=Math.min(r-this.pos,n-i);for(let c=0;c<s;c++)o[this.pos++]^=t[i++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:t,suffix:r,pos:o,blockLen:n}=this;t[o]^=r,(r&128)!==0&&o===n-1&&this.keccak(),t[n-1]^=128,this.keccak()}writeInto(t){return Je(this,!1),le(t),this.writeIntoUnsafe(t)}writeIntoUnsafe(t){this.finish();let r=this.state,{blockLen:o}=this;for(let n=0,i=t.length;n<i;){this.posOut>=o&&this.keccak();let s=Math.min(o-this.posOut,i-n);t.set(r.subarray(this.posOut,this.posOut+s),n),this.posOut+=s,n+=s}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return Qe(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(yn(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,wn(this.state)}_cloneInto(t){let{blockLen:r,suffix:o,outputLen:n,rounds:i,enableXOF:s}=this;return t||=new e(r,o,n,s,i),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=i,t.suffix=o,t.outputLen=n,t.enableXOF=s,t.destroyed=this.destroyed,t}}});var rr=S(()=>{er()});function Wo(e,t){return new Proxy(e,{get(r,o,n){return o in t?t[o]:e[o]},set(r,o,n){return o in t&&delete t[o],e[o]=n,!0},deleteProperty(r,o){let n=!1;return o in t&&(delete t[o],n=!0),o in e&&(delete e[o],n=!0),n},ownKeys(r){let o=Reflect.ownKeys(e),n=Reflect.ownKeys(t),i=new Set(n);return[...o.filter(s=>!i.has(s)),...n]},defineProperty(r,o,n){return o in t&&delete t[o],Reflect.defineProperty(e,o,n),!0},getOwnPropertyDescriptor(r,o){return o in t?Reflect.getOwnPropertyDescriptor(t,o):Reflect.getOwnPropertyDescriptor(e,o)},has(r,o){return o in t||o in e}})}var $o,Sn,Bn=S(()=>{$o={},Sn=Wo(globalThis,$o)});function Z(e){return e&255}function W(e){return e<<16>>16}function F(e){return e&65535}function An(e,t){if(e.length!=t.length)return 0;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];let o=~r&255;return o&=o>>4,o&=o>>2,o&=o>>1,o&1}function On(e,t){if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}async function Tn(){if(typeof Sn<"u"&&globalThis.crypto!==void 0)return globalThis.crypto;try{let{webcrypto:e}=await import("crypto");return e}catch{throw new Error("failed to load Crypto")}}function kn(e,t=0){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}var he=S(()=>{Bn();rr()});function Jo(e){let t=new Uint8Array(32),r,o;for(let n=0;n<256/8;n++)for(let i=0;i<8;i++)o=e[8*n+i]-3329,o+=o>>31&3329,r=((F(o)<<1)+F(3329/2))/F(3329)&1,t[n]|=Z(r<<i);return t}function ti(e){let t=new Int16Array(256),r;for(let o=0;o<256/8;o++)for(let n=0;n<8;n++)r=-1*W(e[o]>>n&1),t[8*o+n]=r&W(3330/2);return t}function In(e,t,r,o,n){let i=0,s,c;for(let f=0;i<n&&f+3<=o;)s=(F(r[f]>>0)|F(r[f+1])<<8)&4095,c=(F(r[f+1]>>4)|F(r[f+2])<<4)&4095,f=f+3,s<3329&&(e[t+i]=s,i=i+1),i<n&&c<3329&&(e[t+i]=c,i=i+1);return i}function Ln(e,t,r){let o,n,i,s;for(let c=0;c<256/8;c++){o=kn(t,4*c),n=o&1431655765,n=n+(o>>1&1431655765);for(let f=0;f<8;f++)i=W(n>>4*f+0&3),s=W(n>>4*f+r&3),e[8*c+f]=i-s}}function de(e){for(let t=0,r=1,o=128;o>=2;o>>=1)for(let n=0;n<256;n=t+o){let i=$e[r];for(r=r+1,t=n;t<n+o;t++){let s=G(i,e[t+o]);e[t+o]=e[t]-s,e[t]=e[t]+s}}return e}function G(e,t){let r=e*t,o=Math.imul(r,62209)<<16>>16;return r-o*3329>>16}function Ot(e){for(let t=0;t<256;t++)e[t]=Un(e[t]);return e}function Un(e){let t=ei*e>>24;return t=t*3329,e-t}function ri(e){for(let r=0;r<256;r++){let o=e[r]*1353,n=Math.imul(o,62209)<<16>>16;e[r]=o-n*3329>>16}return e}function pe(e,t){let r=Fn(e[0],t[0]),o;for(let n=1;n<e.length;n++)o=Fn(e[n],t[n]),r=Kt(r,o);return Ot(r)}function Fn(e,t){for(let r=0;r<256/4;r++){let o=4*r,n=e[o],i=e[o+1],s=e[o+2],c=e[o+3],f=t[o],a=t[o+1],u=t[o+2],h=t[o+3],x=$e[64+r];e[o]=G(G(i,a),x)+G(n,f),e[o+1]=G(n,a)+G(i,f),e[o+2]=G(G(c,h),-x)+G(s,u),e[o+3]=G(s,h)+G(c,u)}return e}function Kt(e,t){for(let r=0;r<256;r++)e[r]+=t[r];return e}function ni(e,t){for(let r=0;r<256;r++)e[r]-=t[r];return e}function nr(e){let t=0;for(let r=0,o=2;o<=128;o<<=1)for(let n=0;n<256;n=t+o){let i=We[r];for(r=r+1,t=n;t<n+o;t++){let s=e[t];e[t]=Un(s+e[t+o]),e[t+o]=s-e[t+o],e[t+o]=G(i,e[t+o])}}for(t=0;t<256;t++)e[t]=G(e[t],We[127]);return e}var Tt,ei,Mt=S(()=>{rr();Lt();he();Tt=class{constructor(){Object.defineProperty(this,"_api",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_k",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_du",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_dv",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_eta1",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_eta2",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_skSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_pkSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_compressedUSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_compressedVSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_poolG",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_poolH",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_poolKdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_poolXof",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_poolPrf1",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_poolPrf2",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_bufG",{enumerable:!0,configurable:!0,writable:!0,value:new Uint8Array(64)}),Object.defineProperty(this,"_bufH",{enumerable:!0,configurable:!0,writable:!0,value:new Uint8Array(32)}),Object.defineProperty(this,"_bufKdf",{enumerable:!0,configurable:!0,writable:!0,value:new Uint8Array(32)}),Object.defineProperty(this,"_bufXof",{enumerable:!0,configurable:!0,writable:!0,value:new Uint8Array(672)}),Object.defineProperty(this,"_bufPrf1",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_bufPrf2",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nonceBuf",{enumerable:!0,configurable:!0,writable:!0,value:new Uint8Array(1)}),Object.defineProperty(this,"_xofSeed",{enumerable:!0,configurable:!0,writable:!0,value:new Uint8Array(34)}),Object.defineProperty(this,"_kBuf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_matrixA",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_noiseVecs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_polyVec",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_bufPkCheck",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_bufCt",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}_initPool(){this._poolG=new nt(72,6,64),this._poolH=new nt(136,6,32),this._poolKdf=new nt(136,31,32,!0),this._poolXof=new nt(168,31,672,!0);let t=this._eta1*256/4;this._poolPrf1=new nt(136,31,t,!0),this._bufPrf1=new Uint8Array(t);let r=this._eta2*256/4;this._poolPrf2=new nt(136,31,r,!0),this._bufPrf2=new Uint8Array(r),this._kBuf=new Uint8Array([this._k]),this._matrixA=new Array(this._k);for(let n=0;n<this._k;n++){this._matrixA[n]=new Array(this._k);for(let i=0;i<this._k;i++)this._matrixA[n][i]=new Int16Array(256)}let o=2*this._k+1;this._noiseVecs=new Array(o);for(let n=0;n<o;n++)this._noiseVecs[n]=new Int16Array(256);this._polyVec=new Array(this._k);for(let n=0;n<this._k;n++)this._polyVec[n]=new Int16Array(256);this._bufPkCheck=new Uint8Array(384*this._k),this._bufCt=new Uint8Array(this._compressedUSize+this._compressedVSize)}_zeroPool(){this._bufG.fill(0),this._bufH.fill(0),this._bufKdf.fill(0),this._bufXof.fill(0),this._bufPrf1.fill(0),this._bufPrf2.fill(0),this._nonceBuf[0]=0,this._xofSeed.fill(0);for(let t=0;t<this._k;t++)for(let r=0;r<this._k;r++)this._matrixA[t][r].fill(0);for(let t=0;t<this._noiseVecs.length;t++)this._noiseVecs[t].fill(0);for(let t=0;t<this._k;t++)this._polyVec[t].fill(0);this._bufPkCheck.fill(0),this._bufCt.fill(0),this._poolG.reset(),this._poolH.reset(),this._poolKdf.reset(),this._poolXof.reset(),this._poolPrf1.reset(),this._poolPrf2.reset()}_polyToBytes(t,r,o){let n,i;for(let s=0;s<256/2;s++)n=o[2*s]-3329,n+=n>>31&3329,i=o[2*s+1]-3329,i+=i>>31&3329,t[r+3*s+0]=Z(n),t[r+3*s+1]=Z(n>>8)|Z(i<<4),t[r+3*s+2]=Z(i>>4)}_polyFromBytes(t,r,o){for(let n=0;n<256/2;n++)t[2*n]=W((F(r[o+3*n+0])>>0|F(r[o+3*n+1])<<8)&4095),t[2*n+1]=W((F(r[o+3*n+1])>>4|F(r[o+3*n+2])<<4)&4095)}_g(t,r){return this._poolG.reset(),this._poolG.updateUnsafe(t),r!==void 0&&this._poolG.updateUnsafe(r),this._poolG.writeIntoUnsafe(this._bufG),[this._bufG.subarray(0,32),this._bufG.subarray(32,64)]}_h(t){return this._poolH.reset(),this._poolH.updateUnsafe(t).writeIntoUnsafe(this._bufH),this._bufH}_kdf(t,r){return this._poolKdf.reset(),this._poolKdf.updateUnsafe(t),r!==void 0&&this._poolKdf.updateUnsafe(r),this._poolKdf.writeIntoUnsafe(this._bufKdf),this._bufKdf}_xof(t){return this._poolXof.reset(),this._poolXof.updateUnsafe(t).writeIntoUnsafe(this._bufXof),this._bufXof}_prf1(t,r){return this._nonceBuf[0]=r,this._poolPrf1.reset(),this._poolPrf1.updateUnsafe(t).updateUnsafe(this._nonceBuf).writeIntoUnsafe(this._bufPrf1),this._bufPrf1}_prf2(t,r){return this._nonceBuf[0]=r,this._poolPrf2.reset(),this._poolPrf2.updateUnsafe(t).updateUnsafe(this._nonceBuf).writeIntoUnsafe(this._bufPrf2),this._bufPrf2}_generateKeyPairCore(){try{let t=new Uint8Array(64);return this._api.getRandomValues(t),this._deriveKeyPair(t)}finally{this._zeroPool()}}_deriveKeyPairCore(t){try{if(t.byteLength!==64)throw new Error("seed must be 64 bytes in length");return this._deriveKeyPair(t)}finally{this._zeroPool()}}_encapCore(t,r){try{if(t.length!==384*this._k+32)throw new Error("invalid encapsulation key");let o=this._getSeed(r),[n,i]=this._g(o,this._h(t));return this._encap(t,o,i),[this._bufCt.slice(),n.slice()]}finally{this._zeroPool()}}_decapCore(t,r){try{if(t.byteLength!==this._compressedUSize+this._compressedVSize)throw new Error("Invalid ct size");if(r.length!==768*this._k+96)throw new Error("Invalid decapsulation key");let o=r.subarray(0,this._skSize),n=r.subarray(this._skSize,this._skSize+this._pkSize),i=r.subarray(this._skSize+this._pkSize,this._skSize+this._pkSize+32),s=r.subarray(this._skSize+this._pkSize+32,this._skSize+this._pkSize+64),c=this._decap(t,o),[f,a]=this._g(c,i),u=this._kdf(s,t);return this._encap(n,c,a),An(t,this._bufCt)===1?f.slice():u.slice()}finally{this._zeroPool()}}async _setup(){this._api===void 0&&(this._api=await Tn())}_getSeed(t){if(t==null){let r=new Uint8Array(32);return this._api.getRandomValues(r),r}if(t.byteLength!==32)throw new Error("seed must be 32 bytes in length");return t}_deriveKeyPair(t){let r=t.subarray(0,32),o=t.subarray(32,64),[n,i]=this._deriveCpaKeyPair(r),s=this._h(n),c=new Uint8Array(this._skSize+this._pkSize+64);return c.set(i,0),c.set(n,this._skSize),c.set(s,this._skSize+this._pkSize),c.set(o,this._skSize+this._pkSize+32),[n,c]}_deriveCpaKeyPair(t){let[r,o]=this._g(t,this._kBuf),n=this._sampleMatrix(r,!1),i=this._sampleNoise1(o,0,this._k),s=this._sampleNoise1(o,this._k,this._k);for(let u=0;u<this._k;u++)i[u]=de(i[u]),i[u]=Ot(i[u]),s[u]=de(s[u]);let c=new Array(this._k);for(let u=0;u<this._k;u++)c[u]=ri(pe(n[u],i)),c[u]=Kt(c[u],s[u]),c[u]=Ot(c[u]);let f=new Uint8Array(this._pkSize);for(let u=0;u<this._k;u++)this._polyToBytes(f,u*384,c[u]);f.set(r,this._skSize);let a=new Uint8Array(this._skSize);for(let u=0;u<this._k;u++)this._polyToBytes(a,u*384,i[u]);return[f,a]}_encap(t,r,o){let n=this._polyVec,i=this._bufPkCheck;for(let p=0;p<this._k;p++)this._polyFromBytes(n[p],t,p*384),this._polyToBytes(i,p*384,n[p]);if(!On(t.subarray(0,i.length),i))throw new Error("invalid encapsulation key");let s=t.subarray(this._skSize),c=this._sampleMatrix(s,!0),f=this._sampleNoise1(o,0,this._k),a=this._sampleNoise2(o,this._k,this._k),u=this._sampleNoise2(o,this._k*2,1)[0];for(let p=0;p<this._k;p++)f[p]=de(f[p]),f[p]=Ot(f[p]);let h=new Array(this._k);for(let p=0;p<this._k;p++)h[p]=pe(c[p],f),h[p]=nr(h[p]),h[p]=Kt(h[p],a[p]),h[p]=Ot(h[p]);let x=ti(r),d=pe(n,f);return d=nr(d),d=Kt(d,u),d=Kt(d,x),d=Ot(d),this._compressU(this._bufCt.subarray(0,this._compressedUSize),h),this._compressV(this._bufCt.subarray(this._compressedUSize),d),this._bufCt}_decap(t,r){let o=this._decompressU(t.subarray(0,this._compressedUSize)),n=this._decompressV(t.subarray(this._compressedUSize)),i=this._polyvecFromBytes(r);for(let c=0;c<this._k;c++)o[c]=de(o[c]);let s=pe(i,o);return s=nr(s),s=ni(n,s),s=Ot(s),Jo(s)}_sampleMatrix(t,r){let o=this._matrixA;this._xofSeed.set(t);for(let n=0,i=0;i<this._k;i++)for(let s=0;s<this._k;s++){r?(this._xofSeed[t.length]=i,this._xofSeed[t.length+1]=s):(this._xofSeed[t.length]=s,this._xofSeed[t.length+1]=i);let c=this._xof(this._xofSeed);for(n=In(o[i][s],0,c.subarray(0,504),504,256);n<256;){let f=c.subarray(504,672);n+=In(o[i][s],n,f,168,256-n)}}return o}_sampleNoise1(t,r,o){let n=new Array(o);for(let i=0;i<o;i++)n[i]=this._noiseVecs[r+i],Ln(n[i],this._prf1(t,r+i),this._eta1);return n}_sampleNoise2(t,r,o){let n=new Array(o);for(let i=0;i<o;i++)n[i]=this._noiseVecs[r+i],Ln(n[i],this._prf2(t,r+i),this._eta2);return n}_polyvecFromBytes(t){let r=this._polyVec;for(let o=0;o<this._k;o++)this._polyFromBytes(r[o],t,o*384);return r}_compressU(t,r){let o=new Array(4);for(let n=0,i=0;i<this._k;i++)for(let s=0;s<256/4;s++){for(let c=0;c<4;c++)o[c]=((r[i][4*s+c]<<10)+3329/2)/3329&1023;t[n++]=Z(o[0]>>0),t[n++]=Z(o[0]>>8|o[1]<<2),t[n++]=Z(o[1]>>6|o[2]<<4),t[n++]=Z(o[2]>>4|o[3]<<6),t[n++]=Z(o[3]>>2)}return t}_compressV(t,r){let o=new Uint8Array(8);for(let n=0,i=0;i<256/8;i++){for(let s=0;s<8;s++)o[s]=Z(((r[8*i+s]<<4)+3329/2)/3329)&15;t[n++]=o[0]|o[1]<<4,t[n++]=o[2]|o[3]<<4,t[n++]=o[4]|o[5]<<4,t[n++]=o[6]|o[7]<<4}return t}_decompressU(t){let r=new Array(this._k);for(let n=0;n<this._k;n++)r[n]=new Int16Array(256);let o=new Array(4);for(let n=0,i=0;i<this._k;i++)for(let s=0;s<256/4;s++){o[0]=F(t[n+0])>>0|F(t[n+1])<<8,o[1]=F(t[n+1])>>2|F(t[n+2])<<6,o[2]=F(t[n+2])>>4|F(t[n+3])<<4,o[3]=F(t[n+3])>>6|F(t[n+4])<<2,n=n+5;for(let c=0;c<4;c++)r[i][4*s+c]=W((o[c]&1023)*3329+512>>10)}return r}_decompressV(t){let r=new Int16Array(256);for(let o=0,n=0;n<256/2;n++,o++)r[2*n+0]=W((t[o]&15)*3329+8>>4),r[2*n+1]=W((t[o]>>4)*3329+8>>4);return r}};ei=((1<<24)+3329/2)/3329});var or=S(()=>{Lt();Mt();he()});var Pn=S(()=>{wt();or()});var Hn=S(()=>{wt();or()});var Vt,jn=S(()=>{Lt();wt();Mt();Vt=class extends Tt{constructor(){super(),Object.defineProperty(this,"_k",{enumerable:!0,configurable:!0,writable:!0,value:3}),Object.defineProperty(this,"_du",{enumerable:!0,configurable:!0,writable:!0,value:10}),Object.defineProperty(this,"_dv",{enumerable:!0,configurable:!0,writable:!0,value:4}),Object.defineProperty(this,"_eta1",{enumerable:!0,configurable:!0,writable:!0,value:2}),Object.defineProperty(this,"_eta2",{enumerable:!0,configurable:!0,writable:!0,value:2}),this._skSize=12*this._k*256/8,this._pkSize=this._skSize+32,this._compressedUSize=this._k*this._du*256/8,this._compressedVSize=this._dv*256/8,this._initPool()}async generateKeyPair(){await this._setup();try{return this._generateKeyPairCore()}catch(t){throw new q(t)}}async deriveKeyPair(t){await this._setup();try{return this._deriveKeyPairCore(t)}catch(r){throw new q(r)}}async encap(t,r){await this._setup();try{return this._encapCore(t,r)}catch(o){throw new q(o)}}async decap(t,r){await this._setup();try{return this._decapCore(t,r)}catch(o){throw new q(o)}}}});var Cn=S(()=>{Lt();wt();Mt()});var ir=S(()=>{Lt();Mt();he()});var zn=S(()=>{wt();ir()});var Nn=S(()=>{wt();ir()});var Dn=S(()=>{wt();Pn();Hn();jn();Cn();zn();Nn();er()});var si=Wn(()=>{dn();Dn();window.x25519=hn;window.MlKem768=Vt});si();})();
/*! Bundled license information:
@noble/curves/utils.js:
@noble/curves/abstract/modular.js:
@noble/curves/abstract/curve.js:
@noble/curves/abstract/edwards.js:
@noble/curves/abstract/montgomery.js:
@noble/curves/ed25519.js:
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
mlkem/esm/src/sha3/utils.js:
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
*/