Introduce repository pattern across multiple services, including `favorites`, `tags`, `sessions`, `reports`, `auth`, and more. Decouple crypto functionalities into modular services like `HashingService`, `JwtService`, and `EncryptionService`. Improve testability and maintainability by simplifying dependencies and consolidating utility logic.
21 lines
557 B
TypeScript
21 lines
557 B
TypeScript
import { Injectable } from "@nestjs/common";
|
|
import { ml_kem768 } from "@noble/post-quantum/ml-kem.js";
|
|
|
|
@Injectable()
|
|
export class PostQuantumService {
|
|
generatePostQuantumKeyPair() {
|
|
const seed = new Uint8Array(64);
|
|
crypto.getRandomValues(seed);
|
|
const { publicKey, secretKey } = ml_kem768.keygen(seed);
|
|
return { publicKey, secretKey };
|
|
}
|
|
|
|
encapsulate(publicKey: Uint8Array) {
|
|
return ml_kem768.encapsulate(publicKey);
|
|
}
|
|
|
|
decapsulate(cipherText: Uint8Array, secretKey: Uint8Array) {
|
|
return ml_kem768.decapsulate(cipherText, secretKey);
|
|
}
|
|
}
|