255 lines
7.1 KiB
Rust
255 lines
7.1 KiB
Rust
pub mod commands;
|
|
pub mod config;
|
|
pub mod error;
|
|
pub mod shell;
|
|
|
|
use clap::{Parser, Subcommand};
|
|
|
|
#[derive(Parser)]
|
|
#[command(name = "crypto-cli")]
|
|
#[command(about = "Cryptographic operations CLI with Rhai scripting support", long_about = None)]
|
|
pub struct Cli {
|
|
#[command(subcommand)]
|
|
pub command: Commands,
|
|
|
|
#[arg(short, long, help = "Enable verbose output")]
|
|
pub verbose: bool,
|
|
|
|
#[arg(short, long, help = "Config file path")]
|
|
pub config: Option<String>,
|
|
}
|
|
|
|
#[derive(Subcommand)]
|
|
pub enum Commands {
|
|
/// Key management commands
|
|
Key {
|
|
#[command(subcommand)]
|
|
command: KeyCommands,
|
|
},
|
|
|
|
/// Encryption/decryption commands
|
|
Crypto {
|
|
#[command(subcommand)]
|
|
command: CryptoCommands,
|
|
},
|
|
|
|
/// Ethereum wallet commands
|
|
Ethereum {
|
|
#[command(subcommand)]
|
|
command: EthereumCommands,
|
|
},
|
|
|
|
/// Execute Rhai script
|
|
Script {
|
|
#[arg(help = "Path to Rhai script file")]
|
|
path: Option<String>,
|
|
|
|
#[arg(short, long, help = "Execute script from string")]
|
|
inline: Option<String>,
|
|
},
|
|
|
|
/// Interactive shell
|
|
Shell,
|
|
}
|
|
|
|
// Define subcommands for each category
|
|
#[derive(Subcommand)]
|
|
pub enum KeyCommands {
|
|
/// Create a new key space
|
|
CreateSpace {
|
|
/// Name of the key space
|
|
name: String,
|
|
#[arg(long)]
|
|
/// Password to encrypt the key space (required)
|
|
password: String
|
|
},
|
|
/// List available key spaces
|
|
ListSpaces,
|
|
/// Load a key space
|
|
Load {
|
|
/// Name of the key space to load
|
|
name: String,
|
|
#[arg(long)]
|
|
/// Password to decrypt the key space
|
|
password: Option<String>
|
|
},
|
|
/// Create a new keypair in the current key space
|
|
CreateKeypair {
|
|
/// Name of the keypair
|
|
name: String,
|
|
#[arg(long)]
|
|
space: Option<String>,
|
|
#[arg(long)]
|
|
password: Option<String>
|
|
},
|
|
/// List keypairs in the current key space
|
|
ListKeypairs {
|
|
#[arg(long)]
|
|
/// Key space to list keypairs from
|
|
space: Option<String>,
|
|
#[arg(long)]
|
|
/// Password to decrypt the key space
|
|
password: Option<String>
|
|
},
|
|
/// Export a keypair
|
|
Export {
|
|
/// Name of the keypair to export
|
|
name: String,
|
|
/// Output file path (prints to stdout if not specified)
|
|
output: Option<String>,
|
|
#[arg(long)]
|
|
/// Key space containing the keypair
|
|
space: Option<String>,
|
|
#[arg(long)]
|
|
/// Password to decrypt the key space
|
|
password: Option<String>
|
|
},
|
|
/// Import a keypair
|
|
Import {
|
|
/// Name to give the imported keypair
|
|
name: String,
|
|
/// Input file path (reads from stdin if not specified)
|
|
input: Option<String>,
|
|
#[arg(long)]
|
|
/// Key space to import the keypair into
|
|
space: Option<String>,
|
|
#[arg(long)]
|
|
/// Password to decrypt the key space
|
|
password: Option<String>
|
|
},
|
|
}
|
|
|
|
#[derive(Subcommand)]
|
|
pub enum CryptoCommands {
|
|
/// Sign a message with a keypair
|
|
Sign {
|
|
#[arg(long)]
|
|
/// Message to sign (as a string)
|
|
message: Option<String>,
|
|
#[arg(long)]
|
|
/// Input file containing the message to sign
|
|
input: Option<String>,
|
|
#[arg(long)]
|
|
/// Name of the keypair to use for signing
|
|
keypair: String,
|
|
#[arg(long)]
|
|
/// Output file for the signature (prints to stdout if not specified)
|
|
output: Option<String>,
|
|
#[arg(long)]
|
|
/// Key space containing the keypair
|
|
space: Option<String>,
|
|
#[arg(long)]
|
|
/// Password to decrypt the key space
|
|
password: Option<String>
|
|
},
|
|
/// Verify a signature
|
|
Verify {
|
|
#[arg(long)]
|
|
/// Message to verify (as a string)
|
|
message: Option<String>,
|
|
#[arg(long)]
|
|
/// Input file containing the message to verify
|
|
input: Option<String>,
|
|
#[arg(long)]
|
|
/// Signature to verify (base64 encoded)
|
|
signature: String,
|
|
#[arg(long)]
|
|
/// Name of the keypair to use for verification
|
|
keypair: Option<String>,
|
|
#[arg(long)]
|
|
/// Public key to use for verification (base64 encoded)
|
|
pubkey: Option<String>,
|
|
#[arg(long)]
|
|
/// Key space containing the keypair
|
|
space: Option<String>,
|
|
#[arg(long)]
|
|
/// Password to decrypt the key space
|
|
password: Option<String>
|
|
},
|
|
/// Encrypt data for a recipient
|
|
Encrypt {
|
|
#[arg(long)]
|
|
/// Data to encrypt (as a string)
|
|
data: Option<String>,
|
|
#[arg(long)]
|
|
/// Input file containing the data to encrypt
|
|
input: Option<String>,
|
|
#[arg(long)]
|
|
/// Name of the recipient keypair
|
|
recipient: String,
|
|
#[arg(long)]
|
|
/// Output file for the encrypted data (prints to stdout if not specified)
|
|
output: Option<String>,
|
|
#[arg(long)]
|
|
/// Key space containing the keypair
|
|
space: Option<String>,
|
|
#[arg(long)]
|
|
/// Password to decrypt the key space
|
|
password: Option<String>
|
|
},
|
|
/// Decrypt data with a keypair
|
|
Decrypt {
|
|
#[arg(long)]
|
|
/// Data to decrypt (as a string, base64 encoded)
|
|
data: Option<String>,
|
|
#[arg(long)]
|
|
/// Input file containing the data to decrypt
|
|
input: Option<String>,
|
|
#[arg(long)]
|
|
/// Name of the keypair to use for decryption
|
|
keypair: String,
|
|
#[arg(long)]
|
|
/// Output file for the decrypted data (prints to stdout if not specified)
|
|
output: Option<String>,
|
|
#[arg(long)]
|
|
/// Key space containing the keypair
|
|
space: Option<String>,
|
|
#[arg(long)]
|
|
/// Password to decrypt the key space
|
|
password: Option<String>
|
|
},
|
|
}
|
|
|
|
#[derive(Subcommand)]
|
|
pub enum EthereumCommands {
|
|
/// Create an Ethereum wallet from a keypair
|
|
Create {
|
|
#[arg(long)]
|
|
/// Name of the keypair to use
|
|
keypair: String,
|
|
#[arg(long)]
|
|
/// Key space containing the keypair
|
|
space: Option<String>,
|
|
#[arg(long)]
|
|
/// Password to decrypt the key space
|
|
password: Option<String>
|
|
},
|
|
/// Get the Ethereum address for a keypair
|
|
Address {
|
|
#[arg(long)]
|
|
/// Name of the keypair
|
|
keypair: String,
|
|
#[arg(long)]
|
|
/// Key space containing the keypair
|
|
space: Option<String>,
|
|
#[arg(long)]
|
|
/// Password to decrypt the key space
|
|
password: Option<String>
|
|
},
|
|
/// Get the balance of an Ethereum address
|
|
Balance {
|
|
#[arg(long)]
|
|
/// Ethereum address (uses the current wallet if not specified)
|
|
address: Option<String>,
|
|
#[arg(long)]
|
|
/// Network to use (e.g., "gnosis")
|
|
network: String,
|
|
#[arg(long)]
|
|
/// Key space containing the keypair
|
|
space: Option<String>,
|
|
#[arg(long)]
|
|
/// Password to decrypt the key space
|
|
password: Option<String>
|
|
},
|
|
}
|