Skip to content

Commit

Permalink
Merge pull request #272 from ralexstokes/lh-val-import
Browse files Browse the repository at this point in the history
produce output for `lighthouse validator-manager import`
  • Loading branch information
ralexstokes authored Sep 29, 2023
2 parents 1884b36 + 4932d94 commit 8c204e1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
13 changes: 13 additions & 0 deletions ethereum-consensus/src/bin/ec/validator/keystores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ where
s.collect_str(&"")
}

fn as_json_str<S, D: Serialize>(data: D, s: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let encoding = serde_json::to_string(&data).unwrap();
s.collect_str(&encoding)
}

pub type Passphrase = String;
const PASSPHRASE_LEN: usize = 32;

Expand Down Expand Up @@ -201,7 +209,12 @@ impl Keystore {

#[derive(Debug, Serialize, Deserialize)]
pub struct KeystoreWithPassphrase {
// NOTE: this JSON name is lighthouse specific
#[serde(rename = "voting_keystore")]
#[serde(serialize_with = "as_json_str")]
keystore: Keystore,
// NOTE: this JSON name is lighthouse specific
#[serde(rename = "voting_keystore_password")]
passphrase: Passphrase,
}

Expand Down
14 changes: 12 additions & 2 deletions ethereum-consensus/src/bin/ec/validator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ use clap::{Args, Subcommand};
#[derive(Debug, Subcommand)]
pub enum Commands {
Mnemonic,
GenerateKeystores { phrase: String, start: u32, end: u32 },
#[clap(
about = "Generates keystores (with passphrases) that target a format compatible with `lighthouse validator-manager` utility."
)]
GenerateLighthouseKeystores {
#[clap(help = "BIP-39 mnemonic to use following EIP-2334")]
phrase: String,
#[clap(help = "EIP-2334 index to start key generation (inclusive)")]
start: u32,
#[clap(help = "EIP-2334 index to stop key generation (exclusive)")]
end: u32,
},
}

#[derive(Debug, Args)]
Expand All @@ -25,7 +35,7 @@ impl Command {
println!("{}", mnemonic);
Ok(())
}
Commands::GenerateKeystores { phrase, start, end } => {
Commands::GenerateLighthouseKeystores { phrase, start, end } => {
let mnemonic = mnemonic::recover_from_phrase(&phrase)?;
let seed = mnemonic::to_seed(mnemonic, None);
let (signing_keys, _withdrawal_keys) = keys::generate(&seed, start, end);
Expand Down

0 comments on commit 8c204e1

Please sign in to comment.