Skip to content

Commit

Permalink
feat: Added tool to recover public keys from secret keys (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoffranca authored Dec 13, 2024
1 parent 8a49824 commit f1522f8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions node/tools/src/bin/keys.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! This tool generates a validator key pair and prints it to stdout.
//! This tool generates a validator/attester/node key pair and prints it to stdout.
#![allow(clippy::print_stdout)]

use crypto::TextFmt as _;
use zksync_consensus_crypto as crypto;
use zksync_consensus_roles::{attester, node, validator};

/// This tool generates a validator key pair and prints it to stdout.
/// This tool generates a validator/attester/node key pair and prints it to stdout.
fn main() {
let validator_key = validator::SecretKey::generate();
let attester_key = attester::SecretKey::generate();
Expand Down
43 changes: 43 additions & 0 deletions node/tools/src/bin/keys_recovery.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//! This tool calculates a node/validator public key from its corresponding secret key and prints it to stdout.
#![allow(clippy::print_stdout)]

use crypto::TextFmt as _;
use std::io;
use zksync_consensus_crypto as crypto;
use zksync_consensus_roles::{node, validator};

/// This tool calculates a node/validator public key from its corresponding secret key and prints it to stdout.
fn main() {
println!("Please enter the node secret key (don't trim the identifiers at the beginning) or leave empty to skip:");

let mut input = String::new();

io::stdin()
.read_line(&mut input)
.expect("Failed to read line");

let input = input.trim();

if !input.is_empty() {
let text = crypto::Text::new(input);
let secret_key = node::SecretKey::decode(text).expect("Failed to decode the secret key");
println!("{}", secret_key.public().encode());
}

println!("Please enter the validator secret key (don't trim the identifiers at the beginning) or leave empty to skip:");

let mut input = String::new();

io::stdin()
.read_line(&mut input)
.expect("Failed to read line");

let input = input.trim();

if !input.is_empty() {
let text = crypto::Text::new(input);
let secret_key =
validator::SecretKey::decode(text).expect("Failed to decode the secret key");
println!("{}", secret_key.public().encode());
}
}

0 comments on commit f1522f8

Please sign in to comment.