import {Command} from 'commander' import {createAccount} from './account' import {createWalletKey} from './create' import {addKey, createKey, listKeys} from './keys' import {transactTransaction} from './transact' /** * Create the wallet command with subcommands */ export function createWalletCommand(): Command { const walletCommand = new Command('wallet') walletCommand.description('Manage local wallet and sign transactions') // wallet create - Create a new wallet key walletCommand .command('create') .description('Create a new wallet key') .option('-n, --name ', 'Name for the key (default: auto-generated)') .option('-p, --password', 'Prompt for a password to encrypt the key') .action(async (options) => { await createWalletKey(options) }) // wallet keys - Manage keys const keysCommand = new Command('keys') keysCommand.description('Manage wallet keys') // wallet keys (no subcommand) - List all keys keysCommand.action(() => { listKeys() }) // wallet keys create - Create a new key keysCommand .command('create') .description('Create a new key in the wallet') .option('-n, --name ', 'Name for the key (default: auto-generated)') .option('-p, --password', 'Prompt for a password to encrypt the key') .action(async (options) => { await createKey(options) }) // wallet keys add - Add an existing private key keysCommand .command('add') .description('Add an existing private key to the wallet') .argument('', 'Private key to import (e.g., PVT_K1_...)') .option('-n, --name ', 'Name for the key (default: auto-generated)') .option('-p, --password', 'Prompt for a password to encrypt the key') .action(async (privateKey, options) => { await addKey(options, privateKey) }) walletCommand.addCommand(keysCommand) // wallet account - Manage accounts const accountCommand = new Command('account') accountCommand.description('Manage blockchain accounts') // wallet account create - Create a new account accountCommand .command('create') .description('Create a new account on the blockchain') .option( '-n, --name ', 'Account name (default: auto-generated, must end with .gm for remote chains)' ) .option('-k, --key ', 'Public key to use (default: auto-generated)') .option( '-c, --chain ', 'Chain to create account on (Jungle4 or KylinTestnet, default: Jungle4)' ) .option( '-u, --url ', 'Blockchain API URL (for local chains, e.g., http://127.0.0.1:8888)' ) .action(async (options) => { await createAccount(options) }) walletCommand.addCommand(accountCommand) // wallet transact - Sign a transaction walletCommand .command('transact') .description( 'Transact (sign and optionally broadcast) a transaction with a key from the wallet' ) .argument('', 'Transaction JSON string or path to JSON file') .option('-k, --key ', 'Name or public key of the key to use for signing') .option('-p, --password', 'Prompt for password if key is encrypted with custom password') .option('-o, --output ', 'Output file path for signed transaction (default: stdout)') .option('-b, --broadcast', 'Broadcast the signed transaction to the network') .option('-u, --url ', 'API endpoint for broadcasting (default: http://127.0.0.1:8888)') .action(async (transaction, options) => { await transactTransaction(transaction, options) }) return walletCommand }