From 6cb32418ec0edce37bc96084a60d5f39c5c100bf Mon Sep 17 00:00:00 2001 From: Halimao <1065621723@qq.com> Date: Wed, 10 Jul 2024 12:26:25 +0800 Subject: [PATCH] refactor: output private key into file instead of console --- crates/astria-cli/src/commands/sequencer.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/astria-cli/src/commands/sequencer.rs b/crates/astria-cli/src/commands/sequencer.rs index 63311c7df5..7004ed50d0 100644 --- a/crates/astria-cli/src/commands/sequencer.rs +++ b/crates/astria-cli/src/commands/sequencer.rs @@ -1,3 +1,5 @@ +use std::fs; + use astria_core::{ crypto::SigningKey, primitive::v1::{ @@ -70,7 +72,8 @@ fn get_address_pretty(signing_key: &SigningKey) -> String { hex::encode(signing_key.verification_key().address_bytes()) } -/// Generates a new ED25519 keypair and prints the public key, private key, and address +/// Generates a new ED25519 keypair and prints the public key, address, +/// and output private key to file pub(crate) fn create_account() { let signing_key = get_new_signing_key(); let public_key_pretty = get_public_key_pretty(&signing_key); @@ -79,11 +82,12 @@ pub(crate) fn create_account() { println!("Create Sequencer Account"); println!(); - // TODO: don't print private keys to CLI, prefer writing to file: - // https://github.com/astriaorg/astria/issues/594 - println!("Private Key: {private_key_pretty:?}"); println!("Public Key: {public_key_pretty:?}"); println!("Address: {address_pretty:?}"); + fs::write("priv.key", private_key_pretty).expect("write private key to file error"); + println!( + "Private Key has been output into priv.key.\nNote: Do not share or lose this private key!" + ); } /// Gets the balance of a Sequencer account