Skip to content
Snippets Groups Projects
Commit a44be2f0 authored by Nicolas80's avatar Nicolas80
Browse files

Added extra confirmation when importing a G1v1/Cesium key; showing the old G1v1 public key

parent 4752e207
No related branches found
No related tags found
1 merge request!41Adding db persistence for all SecretFormat of vault keys as well as supporting derivations
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())
}
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())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment