From 4052d7edd5c3f7de3b0e05c917ff99dd52d000ca Mon Sep 17 00:00:00 2001 From: Matthew Fosse Date: Mon, 29 Apr 2024 14:16:06 -0700 Subject: [PATCH 1/2] change error state seed conditions into throwables [skip ci] --- lib/nano/cw_nano.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/nano/cw_nano.dart b/lib/nano/cw_nano.dart index f434a36d8..2d13dfcdf 100644 --- a/lib/nano/cw_nano.dart +++ b/lib/nano/cw_nano.dart @@ -107,8 +107,8 @@ class CWNano extends Nano { required DerivationType derivationType, }) { - if (mnemonic.split(" ").length == 12) { - derivationType = DerivationType.bip39; + if (mnemonic.split(" ").length == 12 && derivationType != DerivationType.bip39) { + throw Exception("Invalid mnemonic for derivation type!"); } return NanoRestoreWalletFromSeedCredentials( @@ -127,8 +127,8 @@ class CWNano extends Nano { required DerivationType derivationType, }) { - if (seedKey.length == 128) { - derivationType = DerivationType.bip39; + if (seedKey.length == 128 && derivationType != DerivationType.bip39) { + throw Exception("Invalid seed key length for derivation type!"); } return NanoRestoreWalletFromKeysCredentials( From a008c1f2dd37bc60ece185680d6e124099d97188 Mon Sep 17 00:00:00 2001 From: Matthew Fosse Date: Mon, 29 Apr 2024 14:39:14 -0700 Subject: [PATCH 2/2] litecoin fixes --- cw_bitcoin/lib/bitcoin_derivations.dart | 8 ++- .../screens/restore/wallet_restore_page.dart | 65 +++++++++---------- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/cw_bitcoin/lib/bitcoin_derivations.dart b/cw_bitcoin/lib/bitcoin_derivations.dart index e2e891dd3..576db6d6c 100644 --- a/cw_bitcoin/lib/bitcoin_derivations.dart +++ b/cw_bitcoin/lib/bitcoin_derivations.dart @@ -64,7 +64,7 @@ Map> bitcoin_derivations = { description: "Samourai Deposit", scriptType: "p2wpkh", ), - DerivationInfo( + DerivationInfo( derivationType: DerivationType.bip39, derivationPath: "m/84'/0'/0'", description: "Samourai Deposit", @@ -106,5 +106,11 @@ Map> bitcoin_derivations = { description: "Samourai Ricochet native segwit", scriptType: "p2wpkh", ), + DerivationInfo( + derivationType: DerivationType.bip39, + derivationPath: "m/84'/2'/0'", + description: "Default Litecoin", + scriptType: "p2wpkh", + ), ], }; diff --git a/lib/src/screens/restore/wallet_restore_page.dart b/lib/src/screens/restore/wallet_restore_page.dart index 2f0804f98..7eb2978cf 100644 --- a/lib/src/screens/restore/wallet_restore_page.dart +++ b/lib/src/screens/restore/wallet_restore_page.dart @@ -355,50 +355,47 @@ class WalletRestorePage extends BasePage { walletRestoreViewModel.state = IsExecutingState(); - List derivationTypes = - await walletRestoreViewModel.getDerivationTypes(_credentials()); DerivationInfo? dInfo; - if (derivationTypes.length > 1) { - // push screen to choose the derivation type: - List derivations = - await walletRestoreViewModel.getDerivationInfo(_credentials()); + // get info about the different derivations: + List derivations = + await walletRestoreViewModel.getDerivationInfo(_credentials()); - int derivationsWithHistory = 0; - int derivationWithHistoryIndex = 0; - for (int i = 0; i < derivations.length; i++) { - if (derivations[i].transactionsCount > 0) { - derivationsWithHistory++; - derivationWithHistoryIndex = i; - } + int derivationsWithHistory = 0; + int derivationWithHistoryIndex = 0; + for (int i = 0; i < derivations.length; i++) { + if (derivations[i].transactionsCount > 0) { + derivationsWithHistory++; + derivationWithHistoryIndex = i; } + } - // dInfo = await Navigator.of(context).pushNamed(Routes.restoreWalletChooseDerivation, - // arguments: derivations) as DerivationInfo?; - - if (derivationsWithHistory > 1) { - dInfo = await Navigator.of(context).pushNamed(Routes.restoreWalletChooseDerivation, - arguments: derivations) as DerivationInfo?; - } else if (derivationsWithHistory == 1) { - dInfo = derivations[derivationWithHistoryIndex]; - } else { - dInfo = walletRestoreViewModel.getCommonRestoreDerivation(); - } - - if (dInfo == null) { - walletRestoreViewModel.state = InitialExecutionState(); - return; - } - - this.derivationInfo = dInfo; + if (derivationsWithHistory > 1) { + dInfo = await Navigator.of(context).pushNamed( + Routes.restoreWalletChooseDerivation, + arguments: derivations, + ) as DerivationInfo?; + } else if (derivationsWithHistory == 1) { + dInfo = derivations[derivationWithHistoryIndex]; } // get the default derivation for this wallet type: - if (this.derivationInfo == null) { - this.derivationInfo = walletRestoreViewModel.getDefaultDerivation(); + if (dInfo == null) { + // we only return 1 derivation if we're pretty sure we know which one to use: + if (derivations.length == 1) { + dInfo = derivations.first; + } else { + // if we have multiple possible derivations, and none have histories + // we just default to the most common one: + dInfo = walletRestoreViewModel.getCommonRestoreDerivation(); + } } - walletRestoreViewModel.state = InitialExecutionState(); + this.derivationInfo = dInfo; + if (this.derivationInfo == null) { + walletRestoreViewModel.state = InitialExecutionState(); + return; + } walletRestoreViewModel.create(options: _credentials()); }