diff --git a/base_layer/common_types/src/lib.rs b/base_layer/common_types/src/lib.rs index b59c151e4a..d77413e2af 100644 --- a/base_layer/common_types/src/lib.rs +++ b/base_layer/common_types/src/lib.rs @@ -21,7 +21,7 @@ // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // This is the string used to derive the comms/spend key of the wallet -pub const COMMS: &str = "comms"; +pub const WALLET_COMMS_AND_SPEND_KEY_BRANCH: &str = "comms"; pub mod burnt_proof; pub mod chain_metadata; diff --git a/base_layer/core/src/transactions/key_manager/inner.rs b/base_layer/core/src/transactions/key_manager/inner.rs index d88c22a775..bbfc55efb3 100644 --- a/base_layer/core/src/transactions/key_manager/inner.rs +++ b/base_layer/core/src/transactions/key_manager/inner.rs @@ -62,7 +62,7 @@ use tari_key_manager::{ }, }; use tari_script::CheckSigSchnorrSignature; -use tari_utilities::{hex::Hex, ByteArray}; +use tari_utilities::ByteArray; use tokio::sync::RwLock; const LOG_TARGET: &str = "c::bn::key_manager::key_manager_service"; @@ -281,38 +281,37 @@ where TBackend: KeyManagerBackend + 'static pub(crate) async fn get_private_key(&self, key_id: &TariKeyId) -> Result { match key_id { KeyId::Managed { branch, index } => { - // ledger has special rules here - if let WalletType::Ledger(wallet) = &self.wallet_type { - // In the event we're asking for the view key, and we use a ledger, reference the stored key - if &TransactionKeyManagerBranch::DataEncryption.get_branch_key() == branch { - return wallet - .view_key - .clone() - .ok_or(KeyManagerServiceError::LedgerViewKeyInaccessible); - } - - // If we're trying to access any of the private keys, just say no bueno - if &TransactionKeyManagerBranch::Spend.get_branch_key() == branch || - &TransactionKeyManagerBranch::SenderOffset.get_branch_key() == branch - { - return Err(KeyManagerServiceError::LedgerPrivateKeyInaccessible); - } - }; + match &self.wallet_type { + WalletType::Software => {}, + WalletType::Ledger(wallet) => { + if &TransactionKeyManagerBranch::DataEncryption.get_branch_key() == branch { + return wallet + .view_key + .clone() + .ok_or(KeyManagerServiceError::LedgerViewKeyInaccessible); + } - // imported wallet type has special rules here - if let WalletType::Imported(wallet) = &self.wallet_type { - if &TransactionKeyManagerBranch::DataEncryption.get_branch_key() == branch { - return Ok(wallet.view_key.clone()); - } + // If we're trying to access any of the private keys, just say no bueno + if &TransactionKeyManagerBranch::Spend.get_branch_key() == branch || + &TransactionKeyManagerBranch::SenderOffset.get_branch_key() == branch + { + return Err(KeyManagerServiceError::LedgerPrivateKeyInaccessible); + } + }, + WalletType::Imported(wallet) => { + if &TransactionKeyManagerBranch::DataEncryption.get_branch_key() == branch { + return Ok(wallet.view_key.clone()); + } - // If we're trying to access any of the private keys, just say no bueno - if &TransactionKeyManagerBranch::Spend.get_branch_key() == branch { - return wallet - .private_spend_key - .clone() - .ok_or(KeyManagerServiceError::ImportedPrivateKeyInaccessible); - } - }; + // If we're trying to access any of the private keys, just say no bueno + if &TransactionKeyManagerBranch::Spend.get_branch_key() == branch { + return wallet + .private_spend_key + .clone() + .ok_or(KeyManagerServiceError::ImportedPrivateKeyInaccessible); + } + }, + } let km = self .key_managers @@ -436,9 +435,7 @@ where TBackend: KeyManagerBackend + 'static pub async fn import_key(&self, private_key: PrivateKey) -> Result { let public_key = PublicKey::from_secret_key(&private_key); - let hex_key = public_key.to_hex(); self.db.insert_imported_key(public_key.clone(), private_key)?; - trace!(target: LOG_TARGET, "Imported key {}", hex_key); let key_id = KeyId::Imported { key: public_key }; Ok(key_id) } diff --git a/base_layer/core/src/transactions/key_manager/interface.rs b/base_layer/core/src/transactions/key_manager/interface.rs index 58af0bfcfb..ac998082c7 100644 --- a/base_layer/core/src/transactions/key_manager/interface.rs +++ b/base_layer/core/src/transactions/key_manager/interface.rs @@ -27,7 +27,7 @@ use digest::consts::U64; use strum_macros::EnumIter; use tari_common_types::{ types::{ComAndPubSignature, Commitment, PrivateKey, PublicKey, RangeProof, Signature}, - COMMS, + WALLET_COMMS_AND_SPEND_KEY_BRANCH, }; use tari_comms::types::CommsDHKE; use tari_crypto::{hashing::DomainSeparatedHash, ristretto::RistrettoComSig}; @@ -82,7 +82,7 @@ impl TransactionKeyManagerBranch { TransactionKeyManagerBranch::KernelNonce => "kernel nonce".to_string(), TransactionKeyManagerBranch::SenderOffset => "sender offset".to_string(), TransactionKeyManagerBranch::SenderOffsetLedger => "sender offset ledger".to_string(), - TransactionKeyManagerBranch::Spend => COMMS.to_string(), + TransactionKeyManagerBranch::Spend => WALLET_COMMS_AND_SPEND_KEY_BRANCH.to_string(), } } @@ -95,7 +95,7 @@ impl TransactionKeyManagerBranch { "sender offset" => TransactionKeyManagerBranch::SenderOffset, "sender offset ledger" => TransactionKeyManagerBranch::SenderOffsetLedger, "nonce" => TransactionKeyManagerBranch::Nonce, - COMMS => TransactionKeyManagerBranch::Spend, + WALLET_COMMS_AND_SPEND_KEY_BRANCH => TransactionKeyManagerBranch::Spend, _ => TransactionKeyManagerBranch::Nonce, } } diff --git a/base_layer/key_manager/src/key_manager_service/interface.rs b/base_layer/key_manager/src/key_manager_service/interface.rs index ab3a6ea414..b66a518d39 100644 --- a/base_layer/key_manager/src/key_manager_service/interface.rs +++ b/base_layer/key_manager/src/key_manager_service/interface.rs @@ -26,7 +26,7 @@ use std::{fmt, str::FromStr}; use serde::{Deserialize, Serialize}; use strum_macros::EnumIter; -use tari_common_types::COMMS; +use tari_common_types::WALLET_COMMS_AND_SPEND_KEY_BRANCH; use tari_crypto::keys::{PublicKey, SecretKey}; use tari_utilities::{hex::Hex, ByteArray}; @@ -43,7 +43,7 @@ impl KeyManagerBranch { /// recovery. pub fn get_branch_key(self) -> String { match self { - KeyManagerBranch::Comms => COMMS.to_string(), + KeyManagerBranch::Comms => WALLET_COMMS_AND_SPEND_KEY_BRANCH.to_string(), } } } diff --git a/base_layer/key_manager/src/key_manager_service/service.rs b/base_layer/key_manager/src/key_manager_service/service.rs index 560ee2d556..352b6e3351 100644 --- a/base_layer/key_manager/src/key_manager_service/service.rs +++ b/base_layer/key_manager/src/key_manager_service/service.rs @@ -31,7 +31,7 @@ use tari_crypto::{ hashing::DomainSeparatedHasher, keys::{PublicKey, SecretKey}, }; -use tari_utilities::{hex::Hex, ByteArray}; +use tari_utilities::ByteArray; use crate::{ cipher_seed::CipherSeed, @@ -217,9 +217,7 @@ where pub async fn import_key(&self, private_key: PK::K) -> Result, KeyManagerServiceError> { let public_key = PK::from_secret_key(&private_key); - let hex_key = public_key.to_hex(); self.db.insert_imported_key(public_key.clone(), private_key)?; - trace!(target: LOG_TARGET, "Imported key {}", hex_key); let key_id = KeyId::Imported { key: public_key }; Ok(key_id) }