mirror of
https://github.com/perfect-panel/ppanel-web.git
synced 2026-02-10 02:11:19 -05:00
17 lines
568 B
TypeScript
17 lines
568 B
TypeScript
import mlkem from 'mlkem-wasm';
|
|
import { toB64Url } from './util';
|
|
|
|
export async function generateMLKEM768KeyPair() {
|
|
const mlkemKeyPair = await mlkem.generateKey({ name: 'ML-KEM-768' }, true, [
|
|
'encapsulateBits',
|
|
'decapsulateBits',
|
|
]);
|
|
const mlkemPublicKeyRaw = await mlkem.exportKey('raw-public', mlkemKeyPair.publicKey);
|
|
const mlkemPrivateKeyRaw = await mlkem.exportKey('raw-seed', mlkemKeyPair.privateKey);
|
|
|
|
return {
|
|
publicKey: toB64Url(new Uint8Array(mlkemPublicKeyRaw)),
|
|
privateKey: toB64Url(new Uint8Array(mlkemPrivateKeyRaw)),
|
|
};
|
|
}
|