From 4752e207c7416f80a941856d99bd6fff5e8abf7f Mon Sep 17 00:00:00 2001 From: Nicolas80 <nicolas.pmail@protonmail.com> Date: Sat, 4 Jan 2025 11:23:24 +0100 Subject: [PATCH] Renamed vault_account CryptoType enum values and encrypted_private_key field into encrypted_suri --- src/commands/vault.rs | 26 +++++++++++++------------- src/entities/vault_account.rs | 20 ++++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/commands/vault.rs b/src/commands/vault.rs index 3918f90..e3fec9e 100644 --- a/src/commands/vault.rs +++ b/src/commands/vault.rs @@ -274,7 +274,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE root_derivation.address )))?; - if vault_account.crypto_type == CryptoType::Ed25519Seed { + if vault_account.crypto_type == CryptoType::G1v1Seed { println!( "Only \"{}\" and \"{}\" format are supported for derivations", Into::<&str>::into(SecretFormat::Substrate), @@ -487,10 +487,10 @@ fn parse_prefix_and_derivation_path_from_string( fn map_secret_format_to_crypto_type(secret_format: SecretFormat) -> CryptoType { match secret_format { - SecretFormat::Seed => vault_account::CryptoType::Sr25519Seed, - SecretFormat::Substrate => vault_account::CryptoType::Sr25519Mnemonic, - SecretFormat::Predefined => vault_account::CryptoType::Sr25519Mnemonic, - SecretFormat::Cesium => vault_account::CryptoType::Ed25519Seed, + SecretFormat::Seed => vault_account::CryptoType::EntropyKdfSeed, + SecretFormat::Substrate => vault_account::CryptoType::Bip39Mnemonic, + SecretFormat::Predefined => vault_account::CryptoType::Bip39Mnemonic, + SecretFormat::Cesium => vault_account::CryptoType::G1v1Seed, } } @@ -565,9 +565,9 @@ where )))?; current_vault_format = match vault_account.crypto_type { - CryptoType::Sr25519Mnemonic => Some(SecretFormat::Substrate.into()), - CryptoType::Sr25519Seed => Some(SecretFormat::Seed.into()), - CryptoType::Ed25519Seed => Some(SecretFormat::Cesium.into()), + CryptoType::Bip39Mnemonic => Some(SecretFormat::Substrate.into()), + CryptoType::EntropyKdfSeed => Some(SecretFormat::Seed.into()), + CryptoType::G1v1Seed => Some(SecretFormat::Cesium.into()), }; } @@ -752,14 +752,14 @@ where ))); } - let encrypted_private_key = + let encrypted_suri = encrypt(root_secret_suri.as_bytes(), password.to_string()).map_err(|e| anyhow!(e))?; let _root_account = vault_account::create_vault_account( db, &root_address, map_secret_format_to_crypto_type(secret_format), - encrypted_private_key, + encrypted_suri, ) .await?; @@ -914,7 +914,7 @@ pub fn retrieve_suri_from_vault_account( ) -> Result<String, GcliError> { let password = inputs::prompt_password()?; - let cypher = &vault_account.encrypted_private_key; + let cypher = &vault_account.encrypted_suri; let secret_vec = decrypt(cypher, password.clone()).map_err(|e| GcliError::Input(e.to_string()))?; let secret_suri = String::from_utf8(secret_vec).map_err(|e| anyhow!(e))?; @@ -924,10 +924,10 @@ pub fn retrieve_suri_from_vault_account( pub fn compute_keypair(crypto_type: CryptoType, secret_suri: &str) -> Result<KeyPair, GcliError> { let key_pair = match crypto_type { - CryptoType::Sr25519Mnemonic | CryptoType::Sr25519Seed => { + CryptoType::Bip39Mnemonic | CryptoType::EntropyKdfSeed => { pair_from_sr25519_str(secret_suri)?.into() } - CryptoType::Ed25519Seed => pair_from_ed25519_str(secret_suri)?.into(), + CryptoType::G1v1Seed => pair_from_ed25519_str(secret_suri)?.into(), }; Ok(key_pair) } diff --git a/src/entities/vault_account.rs b/src/entities/vault_account.rs index 180b4c7..76d3463 100644 --- a/src/entities/vault_account.rs +++ b/src/entities/vault_account.rs @@ -17,7 +17,7 @@ pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub address: String, pub crypto_type: CryptoType, - pub encrypted_private_key: Vec<u8>, + pub encrypted_suri: Vec<u8>, } impl Display for Model { @@ -33,12 +33,12 @@ impl Display for Model { rename_all = "PascalCase" )] pub enum CryptoType { - /// The secret key or BIP39 mnemonic - Sr25519Mnemonic, - /// The 32B SR25519 seed without "0x" prefix - Sr25519Seed, - /// The 32B ED25519 seed without "0x" prefix (for cesium) - Ed25519Seed, + /// The BIP39 mnemonic phrase (?12 words) (SR25519) + Bip39Mnemonic, + /// The 32B hexadecimal seed with "0x" prefix (64+2 characters when unencrypted) (SR25519) + EntropyKdfSeed, + /// The 32B hexadecimal seed with "0x" prefix for cesium v1 (64+2 characters when unencrypted) (ED25519) + G1v1Seed, } #[derive(Copy, Clone, Debug, EnumIter)] @@ -68,7 +68,7 @@ pub async fn create_vault_account<C>( db: &C, address: &str, crypto_type: CryptoType, - encrypted_private_key: Vec<u8>, + encrypted_suri: Vec<u8>, ) -> Result<Model, GcliError> where C: ConnectionTrait, @@ -83,7 +83,7 @@ where inputs::confirm_action("Do you want to overwrite with the new encrypted key ?")?; if overwrite_key { let mut vault_account: ActiveModel = vault_account.into(); - vault_account.encrypted_private_key = Set(encrypted_private_key); + vault_account.encrypted_suri = Set(encrypted_suri); let vault_account = vault_account.update(db).await?; println!("Updated vault account {vault_account}"); @@ -96,7 +96,7 @@ where let vault_account = ActiveModel { address: Set(address.to_owned()), crypto_type: Set(crypto_type), - encrypted_private_key: Set(encrypted_private_key), + encrypted_suri: Set(encrypted_suri), }; let vault_account = vault_account.insert(db).await?; println!("Created vault account {}", vault_account); -- GitLab