diff --git a/src/commands/cesium.rs b/src/commands/cesium.rs index 56a40439039d1d808e7cc9259c66ebb37515ea72..960db3478062f9e8ab6d009d549f61ec403437d9 100644 --- a/src/commands/cesium.rs +++ b/src/commands/cesium.rs @@ -1,5 +1,6 @@ use crate::*; use bs58; +use sp_core::ed25519::Pair as Ed25519Pair; /// define cesium subcommands #[derive(Clone, Default, Debug, clap::Parser)] @@ -34,11 +35,30 @@ pub async fn handle_command(_data: Data, command: Subcommand) -> Result<(), Gcli } Subcommand::Prompt => { let pair = prompt_secret_cesium(); - let public = pair.public(); - println!("Pubkey: {}", bs58::encode(public).into_string()); - let address: AccountId = public.into(); + println!( + "Pubkey: {}", + compute_g1v1_public_key_from_ed25519_pair(&pair)? + ); + let address: AccountId = pair.public().into(); println!("Address: {}", address); } } Ok(()) } + +/// Computes G1v1 public key from a KeyPair of type sp_core::ed25519::Pair - fails otherwise +pub fn compute_g1v1_public_key(key_pair: &KeyPair) -> Result<String, GcliError> { + match key_pair { + KeyPair::Sr25519(_) => Err(GcliError::Logic( + "key pair is not of type ed25519".to_string(), + )), + KeyPair::Ed25519(key_pair) => Ok(compute_g1v1_public_key_from_ed25519_pair(key_pair)?), + } +} + +/// Computes G1v1 public key from an ed25519 Pair +pub fn compute_g1v1_public_key_from_ed25519_pair( + ed25519_key_pair: &Ed25519Pair, +) -> Result<String, GcliError> { + Ok(bs58::encode(ed25519_key_pair.public()).into_string()) +} diff --git a/src/commands/vault.rs b/src/commands/vault.rs index e3fec9e778269f15264dbb0709aaa3ad1bc5e1b1..3a8b4f0113f3934f5a112136c8cd82445ed97de9 100644 --- a/src/commands/vault.rs +++ b/src/commands/vault.rs @@ -1,3 +1,4 @@ +use crate::commands::cesium::compute_g1v1_public_key; use crate::entities::vault_account::CryptoType; use crate::entities::{vault_account, vault_derivation}; use crate::*; @@ -201,9 +202,21 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE let vault_data_for_import = prompt_secret_and_compute_vault_data_to_import(secret_format)?; + //Extra check for SecretFormat::Cesium / G1v1Seed - showing the G1v1 cesium public key for confirmation + if secret_format == SecretFormat::Cesium { + println!( + "The G1v1 public key for the provided secret is: '{}'", + compute_g1v1_public_key(&vault_data_for_import.key_pair)? + ); + let confirmed = inputs::confirm_action("Is it the correct one (if not, you should try again to input Cesium id/password) ?".to_string())?; + if !confirmed { + return Ok(()); + } + } + let address_to_import = vault_data_for_import.key_pair.address().to_string(); - println!("Trying to import for address :'{}'", address_to_import); + println!("Trying to import for SS58 address :'{}'", address_to_import); if let Some(derivation) = vault_derivation::Entity::find_by_id(&address_to_import) .one(data.connection.as_ref().unwrap())