From f1522f8b23ef1a5450e626d187accac6bc637eb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Fran=C3=A7a?= Date: Fri, 13 Dec 2024 16:29:37 +0000 Subject: [PATCH] feat: Added tool to recover public keys from secret keys (#224) --- node/tools/src/bin/keys.rs | 4 +-- node/tools/src/bin/keys_recovery.rs | 43 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 node/tools/src/bin/keys_recovery.rs diff --git a/node/tools/src/bin/keys.rs b/node/tools/src/bin/keys.rs index d7b0e29f..8b751c45 100644 --- a/node/tools/src/bin/keys.rs +++ b/node/tools/src/bin/keys.rs @@ -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(); diff --git a/node/tools/src/bin/keys_recovery.rs b/node/tools/src/bin/keys_recovery.rs new file mode 100644 index 00000000..1bae3747 --- /dev/null +++ b/node/tools/src/bin/keys_recovery.rs @@ -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()); + } +}