UNPKG

crypto-keygen-suite

Version:

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

104 lines (93 loc) 3.74 kB
import yargs from 'yargs/yargs'; import { hideBin } from 'yargs/helpers'; import crypto from 'crypto'; // Secure MPC Node class MPCNode { constructor(secret) { this.secret = BigInt(secret); this.share = this.generateShare(); } generateShare() { return this.secret > 1 ? BigInt(crypto.randomInt(1, Number(this.secret))) : BigInt(1); } computePartialSum(otherShare) { return this.secret - this.share + BigInt(otherShare); } computePartialMultiplication(otherShare) { return (this.secret * BigInt(otherShare)); } computeVoteAgreement(otherShare) { return this.secret === BigInt(otherShare) ? "✅ Votes Match!" : "❌ Votes Do Not Match!"; } computeEncryptedAuction(otherShares) { const auctionPrice = otherShares.map(BigInt).reduce((acc, val) => acc + val, this.secret); return `🏆 Final Encrypted Auction Price: ${auctionPrice}`; } } // CLI Setup async function main() { const argv = yargs(hideBin(process.argv)) .option('mode', { alias: 'm', type: 'string', choices: ['generate', 'sum', 'multiply', 'vote', 'auction'], describe: 'Generate secret shares or perform MPC operations', }) .option('secret', { alias: 's', type: 'string', describe: 'Secret value for MPC computation', }) .option('share', { alias: 'sh', type: 'string', describe: 'Received share from another participant', }) .option('shares', { alias: 'shs', type: 'array', describe: 'List of shares for auction calculations', }) .help() .argv; if (argv.mode === 'generate') { if (!argv.secret) { console.error("❌ Generating shares requires a secret!"); return; } const node = new MPCNode(argv.secret); console.log(`🔑 Secret Share: ${node.share}`); } else if (argv.mode === 'sum') { if (!argv.secret || !argv.share) { console.error("❌ Sum computation requires your secret and a share from another participant!"); return; } const node = new MPCNode(argv.secret); console.log(`➕ Computed MPC Sum: ${node.computePartialSum(argv.share)}`); } else if (argv.mode === 'multiply') { if (!argv.secret || !argv.share) { console.error("❌ Multiplication computation requires your secret and another share!"); return; } const node = new MPCNode(argv.secret); console.log(`✖️ Computed MPC Multiplication: ${node.computePartialMultiplication(argv.share)}`); } else if (argv.mode === 'vote') { if (!argv.secret || !argv.share) { console.error("❌ Voting computation requires your vote and another participant's vote!"); return; } const node = new MPCNode(argv.secret); console.log(`🗳️ Voting Result: ${node.computeVoteAgreement(argv.share)}`); } else if (argv.mode === 'auction') { if (!argv.secret || !argv.shares || argv.shares.length === 0) { console.error("❌ Encrypted auction requires multiple shared bid values!"); return; } const node = new MPCNode(argv.secret); console.log(node.computeEncryptedAuction(argv.shares)); } else { console.error("❌ Invalid mode. Use --mode generate | sum | multiply | vote | auction"); } } console.log("🚀 Debug: Running main function..."); main();