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

feat: Added tool to recover public keys from secret keys #224

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
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());
}
}
Loading