diff --git a/Cargo.lock b/Cargo.lock index 3fb6295aa2..d9f64cf519 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3373,6 +3373,7 @@ dependencies = [ "minotari_ledger_wallet_common", "once_cell", "rand", + "semver", "serde", "tari_common", "tari_common_types", diff --git a/applications/minotari_ledger_wallet/comms/Cargo.toml b/applications/minotari_ledger_wallet/comms/Cargo.toml index 26b04d176a..b19eb454ec 100644 --- a/applications/minotari_ledger_wallet/comms/Cargo.toml +++ b/applications/minotari_ledger_wallet/comms/Cargo.toml @@ -13,7 +13,7 @@ tari_common_types = { path = "../../../base_layer/common_types" } tari_script = { path = "../../../infrastructure/tari_script" } minotari_ledger_wallet_common = { path = "../common" } - +semver = "1.0" borsh = "1.2" dialoguer = { version = "0.11" } ledger-transport = { git = "https://github.com/Zondax/ledger-rs", rev = "20e2a20" } diff --git a/applications/minotari_ledger_wallet/comms/src/accessor_methods.rs b/applications/minotari_ledger_wallet/comms/src/accessor_methods.rs index 8f87ffa37c..1d719dd922 100644 --- a/applications/minotari_ledger_wallet/comms/src/accessor_methods.rs +++ b/applications/minotari_ledger_wallet/comms/src/accessor_methods.rs @@ -26,6 +26,7 @@ use log::debug; use minotari_ledger_wallet_common::common_types::{AppSW, Instruction}; use once_cell::sync::Lazy; use rand::{rngs::OsRng, RngCore}; +use semver::Version; use tari_common::configuration::Network; use tari_common_types::{ key_branches::TransactionKeyManagerBranch, @@ -38,7 +39,7 @@ use tari_utilities::{hex::Hex, ByteArray}; use crate::{ error::LedgerDeviceError, - ledger_wallet::{Command, EXPECTED_NAME, EXPECTED_VERSION}, + ledger_wallet::{Command, EXPECTED_NAME, MIN_LEDGER_APP_VERSION}, }; const LOG_TARGET: &str = "ledger_wallet::accessor_methods"; @@ -91,16 +92,20 @@ fn verify() -> Result<(), LedgerDeviceError> { match ledger_get_version() { Ok(version) => { - if version != EXPECTED_VERSION { + let req = Version::parse(MIN_LEDGER_APP_VERSION) + .map_err(|e| LedgerDeviceError::ConversionError(e.to_string()))?; + let ledger_version = + Version::parse(&version).map_err(|e| LedgerDeviceError::ConversionError(e.to_string()))?; + if ledger_version < req { return Err(LedgerDeviceError::Processing(format!( - "'Minotari Wallet' application version mismatch: expected '{}', running '{}'.", - EXPECTED_VERSION, version + "'Minotari Wallet' application version check failed: min version '{}', running '{}'.", + MIN_LEDGER_APP_VERSION, version ))); } }, Err(e) => { return Err(LedgerDeviceError::Processing(format!( - "'Minotari Wallet' application version mismatch ({})", + "'Minotari Wallet' application version check ({})", e ))) }, @@ -601,15 +606,15 @@ pub fn ledger_get_one_sided_metadata_signature( let data = result.data(); Ok(ComAndPubSignature::new( Commitment::from_canonical_bytes(&data[1..33]) - .map_err(|e| LedgerDeviceError::ByteArrayError(e.to_string()))?, + .map_err(|e| LedgerDeviceError::ConversionError(e.to_string()))?, PublicKey::from_canonical_bytes(&data[33..65]) - .map_err(|e| LedgerDeviceError::ByteArrayError(e.to_string()))?, + .map_err(|e| LedgerDeviceError::ConversionError(e.to_string()))?, PrivateKey::from_canonical_bytes(&data[65..97]) - .map_err(|e| LedgerDeviceError::ByteArrayError(e.to_string()))?, + .map_err(|e| LedgerDeviceError::ConversionError(e.to_string()))?, PrivateKey::from_canonical_bytes(&data[97..129]) - .map_err(|e| LedgerDeviceError::ByteArrayError(e.to_string()))?, + .map_err(|e| LedgerDeviceError::ConversionError(e.to_string()))?, PrivateKey::from_canonical_bytes(&data[129..161]) - .map_err(|e| LedgerDeviceError::ByteArrayError(e.to_string()))?, + .map_err(|e| LedgerDeviceError::ConversionError(e.to_string()))?, )) }, Err(e) => Err(LedgerDeviceError::Instruction(format!( diff --git a/applications/minotari_ledger_wallet/comms/src/error.rs b/applications/minotari_ledger_wallet/comms/src/error.rs index 4a042f992f..5755356902 100644 --- a/applications/minotari_ledger_wallet/comms/src/error.rs +++ b/applications/minotari_ledger_wallet/comms/src/error.rs @@ -50,7 +50,7 @@ pub enum LedgerDeviceError { Processing(String), /// Conversion error to or from ledger #[error("Conversion failed: {0}")] - ByteArrayError(String), + ConversionError(String), /// Not yet supported #[error("Ledger is not fully supported")] NotSupported, @@ -60,7 +60,7 @@ pub enum LedgerDeviceError { impl From for LedgerDeviceError { fn from(e: ByteArrayError) -> Self { - LedgerDeviceError::ByteArrayError(e.to_string()) + LedgerDeviceError::ConversionError(e.to_string()) } } diff --git a/applications/minotari_ledger_wallet/comms/src/ledger_wallet.rs b/applications/minotari_ledger_wallet/comms/src/ledger_wallet.rs index 20c2e80806..300d1a22d2 100644 --- a/applications/minotari_ledger_wallet/comms/src/ledger_wallet.rs +++ b/applications/minotari_ledger_wallet/comms/src/ledger_wallet.rs @@ -31,7 +31,7 @@ use tari_utilities::ByteArray; use crate::error::LedgerDeviceError; pub const EXPECTED_NAME: &str = "minotari_ledger_wallet"; -pub const EXPECTED_VERSION: &str = env!("CARGO_PKG_VERSION"); +pub const MIN_LEDGER_APP_VERSION: &str = "1.4.0"; const WALLET_CLA: u8 = 0x80; struct HidManager {