From 4fa487fa275b9d1fc1343c7852d763b899dcb74b Mon Sep 17 00:00:00 2001 From: cyan Date: Thu, 15 Aug 2024 01:41:22 +0200 Subject: [PATCH] seed fixes (#1594) * seed fixes + jCenter removal * set seed language to English if none show error when requesting seed --------- Co-authored-by: Omar Hatem --- cw_monero/lib/api/wallet.dart | 5 ++++- cw_monero/lib/api/wallet_manager.dart | 11 ++++++++++- cw_wownero/lib/api/wallet.dart | 5 ++++- cw_wownero/lib/api/wallet_manager.dart | 11 ++++++++++- lib/view_model/dashboard/dashboard_view_model.dart | 13 ++++++++----- 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/cw_monero/lib/api/wallet.dart b/cw_monero/lib/api/wallet.dart index 0f6e59c4e..973a38535 100644 --- a/cw_monero/lib/api/wallet.dart +++ b/cw_monero/lib/api/wallet.dart @@ -39,7 +39,7 @@ String getSeed() { if (polyseed != "") { return polyseed; } - final legacy = monero.Wallet_seed(wptr!, seedOffset: ''); + final legacy = getSeedLegacy("English"); return legacy; } @@ -49,6 +49,9 @@ String getSeedLegacy(String? language) { monero.Wallet_setSeedLanguage(wptr!, language: language ?? "English"); legacy = monero.Wallet_seed(wptr!, seedOffset: ''); } + if (monero.Wallet_status(wptr!) != 0) { + return monero.Wallet_errorString(wptr!); + } return legacy; } diff --git a/cw_monero/lib/api/wallet_manager.dart b/cw_monero/lib/api/wallet_manager.dart index ce4d41010..f06fe3e66 100644 --- a/cw_monero/lib/api/wallet_manager.dart +++ b/cw_monero/lib/api/wallet_manager.dart @@ -123,7 +123,16 @@ void restoreWalletFromKeysSync( int nettype = 0, int restoreHeight = 0}) { txhistory = null; - final newWptr = monero.WalletManager_createWalletFromKeys( + final newWptr = spendKey != "" + ? monero.WalletManager_createDeterministicWalletFromSpendKey( + wmPtr, + path: path, + password: password, + language: language, + spendKeyString: spendKey, + newWallet: true, // TODO(mrcyjanek): safe to remove + restoreHeight: restoreHeight) + : monero.WalletManager_createWalletFromKeys( wmPtr, path: path, password: password, diff --git a/cw_wownero/lib/api/wallet.dart b/cw_wownero/lib/api/wallet.dart index 96822dfe4..2ccd560ed 100644 --- a/cw_wownero/lib/api/wallet.dart +++ b/cw_wownero/lib/api/wallet.dart @@ -41,7 +41,7 @@ String getSeed() { if (polyseed != "") { return polyseed; } - final legacy = wownero.Wallet_seed(wptr!, seedOffset: ''); + final legacy = getSeedLegacy(null); return legacy; } @@ -51,6 +51,9 @@ String getSeedLegacy(String? language) { wownero.Wallet_setSeedLanguage(wptr!, language: language ?? "English"); legacy = wownero.Wallet_seed(wptr!, seedOffset: ''); } + if (wownero.Wallet_status(wptr!) != 0) { + return wownero.Wallet_errorString(wptr!); + } return legacy; } diff --git a/cw_wownero/lib/api/wallet_manager.dart b/cw_wownero/lib/api/wallet_manager.dart index 7915373bb..660433ba6 100644 --- a/cw_wownero/lib/api/wallet_manager.dart +++ b/cw_wownero/lib/api/wallet_manager.dart @@ -140,7 +140,16 @@ void restoreWalletFromKeysSync( int nettype = 0, int restoreHeight = 0}) { txhistory = null; - final newWptr = wownero.WalletManager_createWalletFromKeys( + final newWptr = spendKey != "" + ? wownero.WalletManager_createDeterministicWalletFromSpendKey( + wmPtr, + path: path, + password: password, + language: language, + spendKeyString: spendKey, + newWallet: true, // TODO(mrcyjanek): safe to remove + restoreHeight: restoreHeight) + : wownero.WalletManager_createWalletFromKeys( wmPtr, path: path, password: password, diff --git a/lib/view_model/dashboard/dashboard_view_model.dart b/lib/view_model/dashboard/dashboard_view_model.dart index 1baea76cd..e98412dce 100644 --- a/lib/view_model/dashboard/dashboard_view_model.dart +++ b/lib/view_model/dashboard/dashboard_view_model.dart @@ -362,12 +362,15 @@ abstract class DashboardViewModelBase with Store { if (wallet.type != WalletType.monero) return []; final keys = monero!.getKeys(wallet); List errors = [ - if (keys['privateSpendKey'] == List.generate(64, (index) => "0").join("")) "Private spend key is 0", + // leaving these commented out for now, I'll be able to fix that properly in the airgap update + // to not cause work duplication, this will do the job as well, it will be slightly less precise + // about what happened - but still enough. + // if (keys['privateSpendKey'] == List.generate(64, (index) => "0").join("")) "Private spend key is 0", if (keys['privateViewKey'] == List.generate(64, (index) => "0").join("")) "private view key is 0", - if (keys['publicSpendKey'] == List.generate(64, (index) => "0").join("")) "public spend key is 0", - if (keys['publicViewKey'] == List.generate(64, (index) => "0").join("")) "private view key is 0", - if (wallet.seed == null) "wallet seed is null", - if (wallet.seed == "") "wallet seed is empty", + // if (keys['publicSpendKey'] == List.generate(64, (index) => "0").join("")) "public spend key is 0", + if (keys['publicViewKey'] == List.generate(64, (index) => "0").join("")) "public view key is 0", + // if (wallet.seed == null) "wallet seed is null", + // if (wallet.seed == "") "wallet seed is empty", if (monero!.getSubaddressList(wallet).getAll(wallet)[0].address == "41d7FXjswpK1111111111111111111111111111111111111111111111111111111111111111111111111111112KhNi4") "primary address is invalid, you won't be able to receive / spend funds", ];