Skip to content

Commit

Permalink
Merge pull request #519 from chainbound/jonas/feat/cli-bls-gen
Browse files Browse the repository at this point in the history
feat(cli): add generate bls keypair command
  • Loading branch information
merklefruit authored Dec 5, 2024
2 parents 015ca28 + 460d19b commit a33d65d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bolt-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ pub enum Cmd {

/// Handle operators in the bolt network.
Operators(OperatorsCommand),

/// Useful data generation commands.
Generate(GenerateCommand),
}

impl Cmd {
Expand All @@ -45,6 +48,7 @@ impl Cmd {
Self::Send(cmd) => cmd.run().await,
Self::Validators(cmd) => cmd.run().await,
Self::Operators(cmd) => cmd.run().await,
Self::Generate(cmd) => cmd.run(),
}
}
}
Expand Down Expand Up @@ -299,6 +303,18 @@ pub enum SymbioticSubcommand {
},
}

#[derive(Debug, Clone, Parser)]
pub struct GenerateCommand {
#[clap(subcommand)]
pub generate: GenerateSubcommand,
}

#[derive(Debug, Clone, Subcommand)]
pub enum GenerateSubcommand {
/// Generate a BLS keypair.
Bls,
}

/// The action to perform.
#[derive(Debug, Clone, Copy, ValueEnum)]
#[clap(rename_all = "kebab_case")]
Expand Down
21 changes: 21 additions & 0 deletions bolt-cli/src/commands/generate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use ethereum_consensus::crypto::SecretKey;

use crate::cli::{GenerateCommand, GenerateSubcommand};

impl GenerateCommand {
pub fn run(&self) -> eyre::Result<()> {
match self.generate {
GenerateSubcommand::Bls => {
let mut rng = rand::thread_rng();
let sk = SecretKey::random(&mut rng)?;

let pubkey = sk.public_key();

println!("BLS secret key: 0x{}", hex::encode(sk.to_bytes()));
println!("BLS public key: {pubkey:?}");
}
}

Ok(())
}
}
3 changes: 3 additions & 0 deletions bolt-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ pub mod validators;

/// Module for the operators-related commands to interact with the bolt network.
pub mod operators;

/// Module for generating various types of data like BLS keys.
pub mod generate;

0 comments on commit a33d65d

Please sign in to comment.