diff --git a/bolt-delegations-cli/src/config.rs b/bolt-delegations-cli/src/config.rs index 4ad000b82..2f520db7e 100644 --- a/bolt-delegations-cli/src/config.rs +++ b/bolt-delegations-cli/src/config.rs @@ -13,11 +13,33 @@ pub struct Opts { #[derive(Subcommand, Debug, Clone)] pub enum Commands { /// Generate delegation messages. - Generate { - /// The source of the validator key (local or keystore). - #[clap(long, env = "SOURCE")] - source: SourceType, + GenerateLocal { + /// The private key in hex format (required if source is local). + /// Multiple secret keys must be seperated by commas. + #[clap( + long, + env = "SECRET_KEYS", + value_parser, + value_delimiter = ',', + hide_env_values = true, + conflicts_with("keystore_path") + )] + secret_key: Option>, + + /// The BLS public key to which the delegation message should be signed. + #[clap(long, env = "DELEGATEE_PUBKEY")] + delegatee_pubkey: String, + + /// The output file for the delegations. + #[clap(long, env = "OUTPUT_FILE_PATH", default_value = "delegations.json")] + out: String, + /// The chain for which the delegation message is intended. + #[clap(long, env = "CHAIN", default_value = "mainnet")] + chain: Chain, + }, + + GenerateKeystore { /// Path to the keystore file (required if source is keystore). #[clap(long, env = "KEY_PATH", conflicts_with("secret_key"))] keystore_path: Option, @@ -33,17 +55,6 @@ pub enum Commands { )] keystore_password: String, - /// The private key in hex format (required if source is local). - /// Multiple secret keys must be seperated by commas. - #[clap( - long, - env = "SECRET_KEYS", - value_parser, - value_delimiter = ',', - conflicts_with("keystore_path") - )] - secret_key: Option>, - /// The BLS public key to which the delegation message should be signed. #[clap(long, env = "DELEGATEE_PUBKEY")] delegatee_pubkey: String, @@ -58,12 +69,6 @@ pub enum Commands { }, } -#[derive(ValueEnum, Debug, Clone)] -pub enum SourceType { - Local, - Keystore, -} - /// Supported chains for the CLI #[derive(Debug, Clone, Copy, ValueEnum)] #[clap(rename_all = "kebab_case")] diff --git a/bolt-delegations-cli/src/main.rs b/bolt-delegations-cli/src/main.rs index 05b0fb466..830858cf1 100644 --- a/bolt-delegations-cli/src/main.rs +++ b/bolt-delegations-cli/src/main.rs @@ -6,7 +6,7 @@ use eyre::Result; use lighthouse_eth2_keystore::Keystore; pub mod config; -use config::{Chain, Commands, Opts, SourceType}; +use config::{Chain, Commands, Opts}; pub mod types; use types::{DelegationMessage, KeystoreError, SignedDelegation}; @@ -20,31 +20,28 @@ fn main() -> Result<()> { let cli = Opts::parse(); match &cli.command { - Commands::Generate { - source, + Commands::GenerateLocal { secret_key, delegatee_pubkey, out, chain } => { + let secret_keys = secret_key.as_ref().unwrap(); + let delegatee_pubkey = parse_public_key(delegatee_pubkey)?; + let signed_delegation = generate_from_local_key(secret_keys, delegatee_pubkey, chain)?; + + write_delegations_to_file(out, &signed_delegation)?; + println!("Signed delegation messages generated and saved to {}", out); + } + Commands::GenerateKeystore { keystore_path, - secret_key, keystore_password, delegatee_pubkey, out, chain, } => { let delegatee_pubkey = parse_public_key(delegatee_pubkey)?; - let signed_delegation = match source { - SourceType::Local => { - // Secret key is expected from CLI argument or env variable - generate_from_local_key(secret_key.as_ref().unwrap(), delegatee_pubkey, chain)? - } - SourceType::Keystore => { - // Keystore path and password is expected - generate_from_keystore( - keystore_path.as_deref(), - keystore_password.as_bytes(), - delegatee_pubkey, - chain, - )? - } - }; + let signed_delegation = generate_from_keystore( + keystore_path.as_deref(), + keystore_password.as_bytes(), + delegatee_pubkey, + chain, + )?; write_delegations_to_file(out, &signed_delegation)?; println!("Signed delegation messages generated and saved to {}", out);