Skip to content

Commit

Permalink
feat: add error codes to LibWallet for CipherSeed errors (#3578)
Browse files Browse the repository at this point in the history
Description
---
This PR adds explicit error codes to the LibWallet FFI interface to return the errors that can occur when invalid seed words are used during wallet recovery. 

The new error codes are:

- Code 429: KeyManagerError::InvalidData
- Code 430: KeyManagerError::VersionMismatch
- Code 431: KeyManagerError::DecryptionFailed
- Code 432: KeyManagerError::CrcError


How Has This Been Tested?
---
cargo test
  • Loading branch information
philipr-za authored Nov 17, 2021
1 parent 81f8c37 commit 2913804
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 17 additions & 2 deletions base_layer/wallet_ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ use tari_crypto::{
signatures::SchnorrSignatureError,
tari_utilities::{hex::HexError, ByteArrayError},
};
use tari_key_manager::error::MnemonicError;
use tari_key_manager::error::{KeyManagerError, MnemonicError};
use tari_wallet::{
contacts_service::error::{ContactsServiceError, ContactsServiceStorageError},
error::{WalletError, WalletStorageError},
output_manager_service::error::{OutputManagerError, OutputManagerStorageError},
transaction_service::error::{TransactionServiceError, TransactionStorageError},
};

use thiserror::Error;

const LOG_TARGET: &str = "wallet_ffi::error";
Expand Down Expand Up @@ -286,6 +285,22 @@ impl From<WalletError> for LibWalletError {
code: 428,
message: format!("{:?}", w),
},
WalletError::KeyManagerError(KeyManagerError::InvalidData) => Self {
code: 429,
message: format!("{:?}", w),
},
WalletError::KeyManagerError(KeyManagerError::VersionMismatch) => Self {
code: 430,
message: format!("{:?}", w),
},
WalletError::KeyManagerError(KeyManagerError::DecryptionFailed) => Self {
code: 431,
message: format!("{:?}", w),
},
WalletError::KeyManagerError(KeyManagerError::CrcError) => Self {
code: 432,
message: format!("{:?}", w),
},
// This is the catch all error code. Any error that is not explicitly mapped above will be given this code
_ => Self {
code: 999,
Expand Down
3 changes: 2 additions & 1 deletion base_layer/wallet_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,8 @@ pub unsafe extern "C" fn seed_words_push_word(
return if let Err(e) = CipherSeed::from_mnemonic(&(*seed_words).0, None) {
log::error!(
target: LOG_TARGET,
"Problem building valid private seed from seed phrase"
"Problem building valid private seed from seed phrase: {}",
e
);
error = LibWalletError::from(WalletError::KeyManagerError(e)).code;
ptr::swap(error_out, &mut error as *mut c_int);
Expand Down

0 comments on commit 2913804

Please sign in to comment.