Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cli): unify KeysSource and SecretsSource #556

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 1 addition & 40 deletions bolt-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub struct DelegateCommand {

/// The source of the private key.
#[clap(subcommand)]
pub source: SecretsSource,
pub source: KeysSource,
}

/// Command for outputting a list of pubkeys in JSON format.
Expand Down Expand Up @@ -327,45 +327,6 @@ pub enum Action {

#[derive(Debug, Clone, Parser)]
pub enum KeysSource {
/// Use directly local public keys as source.
PublicKeys {
/// The public keys in hex format. Multiple public keys must be seperated by commas.
#[clap(long, env = "PUBLIC_KEYS", value_delimiter = ',', hide_env_values = true)]
public_keys: Vec<String>,
},

/// Use local secret keys to generate the associated public keys.
SecretKeys {
/// The private key in hex format. Multiple secret keys must be seperated by commas.
#[clap(long, env = "SECRET_KEYS", value_delimiter = ',', hide_env_values = true)]
secret_keys: Vec<String>,
},

/// Use an EIP-2335 filesystem keystore directory as source for public keys.
LocalKeystore {
/// The path to the keystore file.
#[clap(long, env = "KEYSTORE_PATH")]
path: String,
},

/// Use a remote DIRK keystore as source for public keys.
Dirk {
/// The options for connecting to the DIRK keystore.
#[clap(flatten)]
opts: DirkOpts,
},

/// Use a remote web3signer keystore as source for the public keys.
#[clap(name = "web3signer")]
Web3Signer {
/// The options for connecting to the web3signer keystore.
#[clap(flatten)]
opts: Web3SignerOpts,
},
}

#[derive(Debug, Clone, Parser)]
pub enum SecretsSource {
/// Use local secret keys to generate the signed messages.
SecretKeys {
/// The private key in hex format.
Expand Down
10 changes: 5 additions & 5 deletions bolt-cli/src/commands/delegate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use eyre::Result;
use tracing::debug;

use crate::{
cli::{DelegateCommand, SecretsSource},
cli::{DelegateCommand, KeysSource},
common::{keystore::KeystoreSecret, parse_bls_public_key, write_to_file},
};

Expand All @@ -25,7 +25,7 @@ impl DelegateCommand {
/// Run the `delegate` command.
pub async fn run(self) -> Result<()> {
let signed_messages = match self.source {
SecretsSource::SecretKeys { secret_keys } => {
KeysSource::SecretKeys { secret_keys } => {
let delegatee_pubkey = parse_bls_public_key(&self.delegatee_pubkey)?;
local::generate_from_local_keys(
&secret_keys,
Expand All @@ -34,7 +34,7 @@ impl DelegateCommand {
self.action,
)?
}
SecretsSource::LocalKeystore { opts } => {
KeysSource::LocalKeystore { opts } => {
let keystore_secret = KeystoreSecret::from_keystore_options(&opts)?;
let delegatee_pubkey = parse_bls_public_key(&self.delegatee_pubkey)?;
keystore::generate_from_keystore(
Expand All @@ -45,11 +45,11 @@ impl DelegateCommand {
self.action,
)?
}
SecretsSource::Dirk { opts } => {
KeysSource::Dirk { opts } => {
let delegatee_pubkey = parse_bls_public_key(&self.delegatee_pubkey)?;
dirk::generate_from_dirk(opts, delegatee_pubkey, self.chain, self.action).await?
}
SecretsSource::Web3Signer { opts } => {
KeysSource::Web3Signer { opts } => {
let delegatee_pubkey = parse_bls_public_key(&self.delegatee_pubkey)?;
web3signer::generate_from_web3signer(opts, delegatee_pubkey, self.action).await?
}
Expand Down
8 changes: 2 additions & 6 deletions bolt-cli/src/commands/pubkeys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,14 @@ use crate::{
impl PubkeysCommand {
pub async fn run(self) -> Result<()> {
match self.source {
KeysSource::PublicKeys { public_keys } => {
write_to_file(&self.out, &public_keys)?;
println!("Pubkeys saved to {}", self.out);
}
KeysSource::SecretKeys { secret_keys } => {
let pubkeys = list_from_local_keys(&secret_keys)?;

write_to_file(&self.out, &pubkeys)?;
println!("Pubkeys generated and saved to {}", self.out);
}
KeysSource::LocalKeystore { path } => {
let pubkeys = list_from_keystore(&path)?;
KeysSource::LocalKeystore { opts } => {
let pubkeys = list_from_keystore(&opts.path)?;

write_to_file(&self.out, &pubkeys)?;
println!("Pubkeys generated from local keystore and saved to {}", self.out);
Expand Down
Loading