diff --git a/clap-utils/src/input_parsers.rs b/clap-utils/src/input_parsers.rs index ecd773986..3451ab675 100644 --- a/clap-utils/src/input_parsers.rs +++ b/clap-utils/src/input_parsers.rs @@ -119,7 +119,7 @@ pub fn derivation_of(matches: &ArgMatches<'_>, name: &str) -> Option().unwrap(); + let account = parts.next().map(|account| account.parse::().unwrap()); let change = parts.next().map(|change| change.parse::().unwrap()); DerivationPath { account, change } }) @@ -308,7 +308,7 @@ mod tests { assert_eq!( derivation_of(&matches, "single"), Some(DerivationPath { - account: 2, + account: Some(2), change: Some(3) }) ); @@ -319,7 +319,7 @@ mod tests { assert_eq!( derivation_of(&matches, "single"), Some(DerivationPath { - account: 2, + account: Some(2), change: None }) ); @@ -330,7 +330,7 @@ mod tests { assert_eq!( derivation_of(&matches, "single"), Some(DerivationPath { - account: 2, + account: Some(2), change: Some(3) }) ); diff --git a/remote-wallet/src/ledger.rs b/remote-wallet/src/ledger.rs index 4937e2c4b..f96665cc9 100644 --- a/remote-wallet/src/ledger.rs +++ b/remote-wallet/src/ledger.rs @@ -193,6 +193,10 @@ impl LedgerWallet { match status { // These need to be aligned with solana Ledger app error codes, and clippy allowance removed 0x6700 => Err(RemoteWalletError::Protocol("Incorrect length")), + 0x6802 => Err(RemoteWalletError::Protocol("Invalid parameter")), + 0x6803 => Err(RemoteWalletError::Protocol( + "Overflow: message longer than MAX_MESSAGE_LENGTH", + )), 0x6982 => Err(RemoteWalletError::Protocol( "Security status not satisfied (Canceled by user)", )), @@ -361,16 +365,20 @@ pub fn is_valid_ledger(vendor_id: u16, product_id: u16) -> bool { fn extend_and_serialize(derivation_path: &DerivationPath) -> Vec { let byte = if derivation_path.change.is_some() { 4 - } else { + } else if derivation_path.account.is_some() { 3 + } else { + 2 }; let mut concat_derivation = vec![byte]; concat_derivation.extend_from_slice(&SOL_DERIVATION_PATH_BE); - concat_derivation.extend_from_slice(&[0x80, 0]); - concat_derivation.extend_from_slice(&derivation_path.account.to_be_bytes()); - if let Some(change) = derivation_path.change { + if let Some(account) = derivation_path.account { concat_derivation.extend_from_slice(&[0x80, 0]); - concat_derivation.extend_from_slice(&change.to_be_bytes()); + concat_derivation.extend_from_slice(&account.to_be_bytes()); + if let Some(change) = derivation_path.change { + concat_derivation.extend_from_slice(&[0x80, 0]); + concat_derivation.extend_from_slice(&change.to_be_bytes()); + } } concat_derivation } diff --git a/remote-wallet/src/remote_wallet.rs b/remote-wallet/src/remote_wallet.rs index 2895c1496..e6f2a3723 100644 --- a/remote-wallet/src/remote_wallet.rs +++ b/remote-wallet/src/remote_wallet.rs @@ -240,12 +240,12 @@ impl RemoteWalletInfo { coin ))); } - if let Some(account) = parts.next() { - derivation_path.account = account.replace("'", "").parse::().unwrap(); - derivation_path.change = parts - .next() - .and_then(|change| change.replace("'", "").parse::().ok()); - } + derivation_path.account = parts + .next() + .and_then(|account| account.replace("'", "").parse::().ok()); + derivation_path.change = parts + .next() + .and_then(|change| change.replace("'", "").parse::().ok()); } else { return Err(RemoteWalletError::InvalidDerivationPath( "Derivation path too short, missing coin number".to_string(), @@ -273,18 +273,23 @@ impl RemoteWalletInfo { #[derive(Default, PartialEq, Clone)] pub struct DerivationPath { - pub account: u16, + pub account: Option, pub change: Option, } impl fmt::Debug for DerivationPath { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let account = if let Some(account) = self.account { + format!("/{:?}'", account) + } else { + "".to_string() + }; let change = if let Some(change) = self.change { format!("/{:?}'", change) } else { "".to_string() }; - write!(f, "m/44'/501'/{:?}'{}", self.account, change) + write!(f, "m/44'/501'{}{}", account, change) } } @@ -328,7 +333,7 @@ mod tests { assert_eq!( derivation_path, DerivationPath { - account: 1, + account: Some(1), change: Some(2), } ); @@ -344,7 +349,7 @@ mod tests { assert_eq!( derivation_path, DerivationPath { - account: 1, + account: Some(1), change: Some(2), } );