import { dilithiumGenKeyPair, dilithiumSign, dilithiumVerifySig } from './api.js'; import { randomBytes, createHash } from 'crypto'; async function testDilithium() { try { // Generate the first key pair const { publicKey: publicKey1, secretKey: secretKey1 } = await dilithiumGenKeyPair({ randomBytes }); console.log("First Key Pair Generated."); console.log("Secret Key 1:", secretKey1.toString('hex')); console.log("Public Key 1:", publicKey1.toString('hex')); // Generate the second key pair const { publicKey: publicKey2 } = await dilithiumGenKeyPair({ randomBytes }); console.log("Second Key Pair Generated."); console.log("Public Key 2:", publicKey2.toString('hex')); // Hash the second public key using SHA-256 const hash = createHash('sha256'); hash.update(publicKey2); const hashedPublicKey2 = hash.digest(); console.log("Hashed Public Key 2:", hashedPublicKey2.toString('hex')); // Sign the hash with the first secret key const signature = await dilithiumSign({ secretKey: secretKey1, challenge: hashedPublicKey2 }); console.log("Signature:", signature.toString('hex')); // Verify the signature with the first public key const isValid = await dilithiumVerifySig({ publicKey: publicKey1, challenge: hashedPublicKey2, signature }); console.log("Signature Validity:", isValid); } catch (error) { console.error("Error in testDilithium:", error); } } testDilithium();