From 292ab3533fbdec659c1e984853216c4578c465fb Mon Sep 17 00:00:00 2001 From: Hugo Trentesaux <hugo@trentesaux.fr> Date: Wed, 29 Nov 2023 20:17:57 +0100 Subject: [PATCH] display cesium pubkey --- src/commands/cesium.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/commands/cesium.rs b/src/commands/cesium.rs index bb071b1..94cc8f0 100644 --- a/src/commands/cesium.rs +++ b/src/commands/cesium.rs @@ -8,9 +8,9 @@ pub enum Subcommand { #[default] #[clap(hide = true)] Nothing, - /// Generate key pair with old style unsafe scrypt - Pubkey { id: String, pass: String }, - /// Prompt + /// Analyse a base58 pubkey and gives it in all its form + Pubkey { pubkey: String }, + /// Prompt for cesium input Prompt, } @@ -18,11 +18,19 @@ pub enum Subcommand { pub async fn handle_command(_data: Data, command: Subcommand) -> Result<(), GcliError> { match command { Subcommand::Nothing => {} - Subcommand::Pubkey { id, pass } => { - let keypair = pair_from_cesium(id, pass); - println!("Pubkey: {}", bs58::encode(keypair.pkey).into_string()); - let address: AccountId = keypair.pkey.into(); - println!("Address: {}", address.to_string()); + Subcommand::Pubkey { pubkey } => { + let raw_pubkey = bs58::decode(pubkey).into_vec().unwrap(); + let raw_pubkey: [u8; 32] = if raw_pubkey.len() > 32 { + return Err(GcliError::Input("invalid pubkey size".to_string())); + } else { + [vec![0; 32 - raw_pubkey.len()], raw_pubkey] + .concat() + .try_into() + .unwrap() + }; + println!("Pubkey (hex): 0x{}", hex::encode(raw_pubkey)); + let address: AccountId = sp_core::ed25519::Public(raw_pubkey).into(); + println!("Address (SS58): {}", address.to_string()); } Subcommand::Prompt => { let keypair = prompt_secret_cesium(); -- GitLab