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

Made an extra check of derivation path to make sure it's not linking to the...

Made an extra check of derivation path to make sure it's not linking to the same SS58 Address as "root" suri when doing `vault import|migrate`
parent a44be2f0
Branches
Tags
1 merge request!41Adding db persistence for all SecretFormat of vault keys as well as supporting derivations
......@@ -768,33 +768,46 @@ where
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_suri,
)
.await?;
let crypto_type = map_secret_format_to_crypto_type(secret_format);
let _root_account =
vault_account::create_vault_account(db, &root_address, crypto_type, encrypted_suri).await?;
let derivation = if let Some(derivation_path) = derivation_path_opt {
// Root derivation
let derivation_address = derivation_address.unwrap();
// Extra check of derivation path to make sure it's not linking to the same SS58 Address as root
if root_address == derivation_address {
println!("Derivation path provided:'{derivation_path}' linked to the same SS58 Address than the base suri without derivation");
let root_derivation =
vault_derivation::create_root_vault_derivation(db, &root_address, name).await?;
println!("For that reason only the base suri was imported");
println!("Created: {}", root_derivation);
root_derivation
} else {
let _root_derivation =
vault_derivation::create_root_vault_derivation(db, &root_address, None).await?;
// Compute derivation !
let derivation = vault_derivation::ActiveModel {
address: Set(derivation_address.unwrap().clone()),
address: Set(derivation_address.clone()),
name: Set(name.cloned()),
path: Set(Some(derivation_path)),
root_address: Set(root_address.clone()),
};
let derivation = derivation.insert(db).await?;
println!("Created derivation {}", derivation);
println!("Created: {}", derivation);
derivation
}
} else {
let derivation =
vault_derivation::create_root_vault_derivation(db, &root_address, name).await?;
println!("Created derivation {}", derivation);
println!("Created: {}", derivation);
derivation
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment