UNPKG

crypto-keygen-suite

Version:

Key generation utilities for cryptographic operations. YES I RENAMED IT. SIX STATE PROTOCOL!!! See its folder for all <3

95 lines (81 loc) 3.54 kB
import pkg from 'sphincs'; import yargs from 'yargs/yargs'; import { hideBin } from 'yargs/helpers'; import fs from 'fs'; const Sphincs = pkg.Sphincs || pkg.default?.Sphincs || pkg; // Ensure correct reference async function generateSphincsKeys(securityLevel, hash, format, secure) { try { if (!Sphincs || typeof Sphincs.keyPair !== 'function') { throw new Error("❌ Sphincs module does not expose `keyPair()`. Check the package structure."); } console.log("🚀 Debug: Sphincs module structure:"); console.log(Sphincs); // Call `keyPair()` directly instead of instantiating Sphincs const { publicKey, privateKey } = await Sphincs.keyPair(securityLevel, hash); console.log(`✅ SPHINCS+ Key Pair Generated (Security Level: ${securityLevel}, Hash: ${hash})`); // Convert keys based on chosen format let formattedPubKey, formattedPrivKey; switch (format) { case 'hex': formattedPubKey = Buffer.from(publicKey).toString('hex'); formattedPrivKey = Buffer.from(privateKey).toString('hex'); break; case 'base64': formattedPubKey = Buffer.from(publicKey).toString('base64'); formattedPrivKey = Buffer.from(privateKey).toString('base64'); break; case 'raw': default: formattedPubKey = publicKey; formattedPrivKey = privateKey; break; } console.log(`Public Key (${format.toUpperCase()}):`, formattedPubKey); console.log(`Private Key (${format.toUpperCase()}):`, formattedPrivKey); if (secure) { console.log("🔒 Secure Mode Enabled: Saving keys to files."); fs.writeFileSync(`sphincsplus_pubkey.${format}`, formattedPubKey); fs.writeFileSync(`sphincsplus_privkey.${format}`, formattedPrivKey); } return { publicKey: formattedPubKey, privateKey: formattedPrivKey }; } catch (error) { console.error(`❌ Key Generation Failed: ${error.message}`); } } async function main() { const argv = yargs(hideBin(process.argv)) .option('securityLevel', { alias: 's', type: 'string', default: 'fast', choices: ['fast', 'small', 'robust'], describe: 'Choose SPHINCS+ security mode (fast, small, or robust)' }) .option('hash', { alias: 'h', type: 'string', default: 'SHA256', choices: ['SHA256', 'SHAKE256'], describe: 'Hash function used in SPHINCS+' }) .option('format', { alias: 'f', type: 'string', default: 'raw', choices: ['raw', 'hex', 'base64'], describe: 'Choose output format (raw, hex, base64)' }) .option('secure', { alias: 'p', type: 'boolean', default: false, describe: 'Enable secure key storage' }) .argv; await generateSphincsKeys(argv.securityLevel, argv.hash, argv.format, argv.secure); } console.log("🚀 Debug: Package Structure:"); console.log(pkg); // Logs entire package content console.log("Available keys:", Object.keys(pkg)); // Logs all available exported functions console.log("🚀 Debug: Running main function..."); main();