CW-580: BIP39 Wallets Shared Seed Implementation: "One Seed - Multiple Wallets" (#1307)

* feat: Implement creating new BIP39 wallet with same seed used for other owned BIP39 wallets

* feat: Use same seed for BIP39 Wallets

* Update pre_existing_seeds_page.dart

* Feat: BIP39 Same seed wallet creation using the Common Parent Wallet Strategy

* feat: Finalize implementing preexisting seeds

* feat: Implement shared bip39 wallet seed for Bitcoin wallet type

* feat: Implement shared bip39 wallet seed for Litecoin wallet type

* feat: Implement shared bip39 wallet seed for BitcoinCash wallet type

* feat: Implement shared bip39 wallet seed for Nano wallet type, although disabled entry for now

* fix: Remove non bip39 seed wallet type from listing

* feat: Implement grouped and single wallets lists in wallets listing page and implement editing and saving group names

* fix: Issue where the ontap always references the leadwallet, also make shared seed wallets section header only display when the multi wallet groups list is not empty

* fix: Add translation and adjust the way the groups display

* feat: Activate bip39 as an option for creating Nano wallet types

* fix: Handle edgecase with creating new wallet with group address, handle case where only bip39 derivation type is allowed with child wallets, activate nano wallet type for shared seed

* chore: Modify the UI to fit adjustment made on figma

* fix: Disposed box triggering error in hive and causing wallet list view to display error

* fix: Switch wallet groups title in wallets list page and also fix issue with renaming groups

* Update lib/reactions/bip39_wallet_utils.dart [skip ci]

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>

* Update lib/router.dart [skip ci]

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>

* fix: Review fixes: Combine New Wallet Page Type arguments into a single model

* fix: Review fixes: Add failure guard when fetching mnemonic for selected wallet in pre-existing wallets page

* fix: Review fixes - Add loading indicator when mnemonic is being selected for wallet

* fix: Review fixes - Modify variable name to avoid clashes

* fix: Review fixes - Access WalletManager through dependency injection instead of service location

* fix: Review fixes - Add testnet to convertWalletInfoToWalletlistItem function, and adjust according where used

* fix: Review fixes - Add walletPassword to nano, tron and wownero wallets and confirm it is properly handled as it should be

* fix: Remove leadWallet, modify filtering flow to reflect this and not depend on leadWallet, and adjust privacy settings

* fix: Review Fixes - Modify restore flow to reflect current nature of bip39 as default for majority of wallet types

* fix: QA Fixes - Modify preexisting page to display wallet group names if set, and display them in incremental order if not set

* fix: Add wallet group description page and rename pre-existingseeds page to wallet group display page

* fix: Product Fix - Rename pre-existing seeds file name to wallet group display filename

* fix: Product fix - Separate multiwallets groups from single wallets and display separately

* fix - Product Fix - Add empty state for wallet group listing when creating a new wallet, adjust CTAs across buttons relating to the flow also

---------

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
David Adegoke
2024-09-20 21:25:08 +03:00
committed by GitHub
co-authored by Omar Hatem
parent 3a391f10a3
commit 4e2e5e708c
87 changed files with 2152 additions and 430 deletions
@@ -46,17 +46,30 @@ abstract class AdvancedPrivacySettingsViewModelBase with Store {
case WalletType.litecoin:
return _settingsStore.bitcoinSeedType == BitcoinSeedType.bip39;
case WalletType.nano:
case WalletType.banano:
return _settingsStore.nanoSeedType == NanoSeedType.bip39;
case WalletType.monero:
case WalletType.wownero:
case WalletType.none:
case WalletType.haven:
case WalletType.nano:
case WalletType.banano:
return false;
}
}
bool get hasSeedTypeOption => [WalletType.monero, WalletType.wownero].contains(type);
bool get isMoneroSeedTypeOptionsEnabled => [
WalletType.monero,
WalletType.wownero,
].contains(type);
bool get isBitcoinSeedTypeOptionsEnabled => [
WalletType.bitcoin,
WalletType.litecoin,
].contains(type);
bool get isNanoSeedTypeOptionsEnabled => [WalletType.nano].contains(type);
bool get hasPassphraseOption => [
WalletType.bitcoin,
@@ -0,0 +1,16 @@
import 'package:cw_core/wallet_info.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
part 'new_wallet_type_view_model.g.dart';
class NewWalletTypeViewModel = NewWalletTypeViewModelBase with _$NewWalletTypeViewModel;
abstract class NewWalletTypeViewModelBase with Store {
NewWalletTypeViewModelBase(this._walletInfoSource);
@computed
bool get hasExisitingWallet => _walletInfoSource.isNotEmpty;
final Box<WalletInfo> _walletInfoSource;
}
@@ -23,6 +23,13 @@ abstract class SeedSettingsViewModelBase with Store {
void setBitcoinSeedType(BitcoinSeedType derivationType) =>
_appStore.settingsStore.bitcoinSeedType = derivationType;
@computed
NanoSeedType get nanoSeedType => _appStore.settingsStore.nanoSeedType;
@action
void setNanoSeedType(NanoSeedType derivationType) =>
_appStore.settingsStore.nanoSeedType = derivationType;
@computed
String? get passphrase => this._seedSettingsStore.passphrase;
+13 -4
View File
@@ -99,6 +99,7 @@ abstract class WalletCreationVMBase with Store {
showIntroCakePayCard: (!walletCreationService.typeExists(type)) && type != WalletType.haven,
derivationInfo: credentials.derivationInfo ?? getDefaultCreateDerivation(),
hardwareWalletType: credentials.hardwareWalletType,
parentAddress: credentials.parentAddress,
);
credentials.walletInfo = walletInfo;
@@ -117,12 +118,16 @@ abstract class WalletCreationVMBase with Store {
}
DerivationInfo? getDefaultCreateDerivation() {
final useBip39 = seedSettingsViewModel.bitcoinSeedType.type == DerivationType.bip39;
final useBip39ForBitcoin = seedSettingsViewModel.bitcoinSeedType.type == DerivationType.bip39;
final useBip39ForNano = seedSettingsViewModel.nanoSeedType.type == DerivationType.bip39;
switch (type) {
case WalletType.nano:
if (useBip39ForNano) {
return DerivationInfo(derivationType: DerivationType.bip39);
}
return DerivationInfo(derivationType: DerivationType.nano);
case WalletType.bitcoin:
if (useBip39) {
if (useBip39ForBitcoin) {
return DerivationInfo(
derivationType: DerivationType.bip39,
derivationPath: "m/84'/0'/0'",
@@ -132,7 +137,7 @@ abstract class WalletCreationVMBase with Store {
}
return bitcoin!.getElectrumDerivations()[DerivationType.electrum]!.first;
case WalletType.litecoin:
if (useBip39) {
if (useBip39ForBitcoin) {
return DerivationInfo(
derivationType: DerivationType.bip39,
derivationPath: "m/84'/2'/0'",
@@ -148,9 +153,13 @@ abstract class WalletCreationVMBase with Store {
DerivationInfo? getCommonRestoreDerivation() {
final useElectrum = seedSettingsViewModel.bitcoinSeedType.type == DerivationType.electrum;
final useNanoStandard = seedSettingsViewModel.nanoSeedType.type == DerivationType.nano;
switch (this.type) {
case WalletType.nano:
return DerivationInfo(derivationType: DerivationType.nano);
if (useNanoStandard) {
return DerivationInfo(derivationType: DerivationType.nano);
}
return DerivationInfo(derivationType: DerivationType.bip39);
case WalletType.bitcoin:
if (useElectrum) {
return bitcoin!.getElectrumDerivations()[DerivationType.electrum]!.first;
@@ -0,0 +1,165 @@
import 'package:cake_wallet/core/wallet_loading_service.dart';
import 'package:cake_wallet/entities/wallet_group.dart';
import 'package:cake_wallet/entities/wallet_manager.dart';
import 'package:cake_wallet/reactions/bip39_wallet_utils.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/view_model/wallet_list/wallet_list_item.dart';
import 'package:cake_wallet/view_model/wallet_list/wallet_list_view_model.dart';
import 'package:cake_wallet/wallet_types.g.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:mobx/mobx.dart';
part 'wallet_groups_display_view_model.g.dart';
class WalletGroupsDisplayViewModel = WalletGroupsDisplayViewModelBase
with _$WalletGroupsDisplayViewModel;
abstract class WalletGroupsDisplayViewModelBase with Store {
WalletGroupsDisplayViewModelBase(
this._appStore,
this._walletLoadingService,
this._walletManager,
this.walletListViewModel, {
required this.type,
}) : isFetchingMnemonic = false,
multiWalletGroups = ObservableList<WalletGroup>(),
singleWalletsList = ObservableList<WalletInfo>() {
reaction((_) => _appStore.wallet, (_) => updateWalletInfoSourceList());
updateWalletInfoSourceList();
}
final WalletType type;
final AppStore _appStore;
final WalletManager _walletManager;
final WalletLoadingService _walletLoadingService;
final WalletListViewModel walletListViewModel;
@observable
ObservableList<WalletGroup> multiWalletGroups;
@observable
ObservableList<WalletInfo> singleWalletsList;
@observable
WalletGroup? selectedWalletGroup;
@observable
WalletInfo? selectedSingleWallet;
@observable
String? parentAddress;
@observable
bool isFetchingMnemonic;
@computed
bool get hasNoFilteredWallet {
return singleWalletsList.isEmpty && multiWalletGroups.isEmpty;
}
@action
Future<String?> getSelectedWalletMnemonic() async {
WalletListItem walletToUse;
bool isGroupSelected = selectedWalletGroup != null;
if (isGroupSelected) {
walletToUse = convertWalletInfoToWalletListItem(selectedWalletGroup!.wallets.first);
} else {
walletToUse = convertWalletInfoToWalletListItem(selectedSingleWallet!);
}
try {
isFetchingMnemonic = true;
final wallet = await _walletLoadingService.load(
walletToUse.type,
walletToUse.name,
);
parentAddress =
isGroupSelected ? selectedWalletGroup!.parentAddress : selectedSingleWallet!.address;
return wallet.seed;
} catch (e) {
return null;
} finally {
isFetchingMnemonic = false;
}
}
@action
void selectWalletGroup(WalletGroup walletGroup) {
selectedWalletGroup = walletGroup;
selectedSingleWallet = null;
}
@action
void selectSingleWallet(WalletInfo singleWallet) {
selectedSingleWallet = singleWallet;
selectedWalletGroup = null;
}
@action
void updateWalletInfoSourceList() {
List<WalletGroup> wallets = [];
multiWalletGroups.clear();
singleWalletsList.clear();
_walletManager.updateWalletGroups();
final walletGroups = _walletManager.walletGroups;
// Iterate through the wallet groups to filter and categorize wallets
for (var group in walletGroups) {
// Handle group wallet filtering
bool shouldExcludeGroup = group.wallets.any((wallet) {
// Check for non-BIP39 wallet types
bool isNonBIP39Wallet = !isBIP39Wallet(wallet.type);
// Check for nano derivation type
bool isNanoDerivationType = wallet.type == WalletType.nano &&
wallet.derivationInfo?.derivationType == DerivationType.nano;
// Check for electrum derivation type
bool isElectrumDerivationType =
(wallet.type == WalletType.bitcoin || wallet.type == WalletType.litecoin) &&
wallet.derivationInfo?.derivationType == DerivationType.electrum;
// Check that selected wallet type is not present already in group
bool isSameTypeAsSelectedWallet = wallet.type == type;
// Exclude if any of these conditions are true
return isNonBIP39Wallet ||
isNanoDerivationType ||
isElectrumDerivationType ||
isSameTypeAsSelectedWallet;
});
if (shouldExcludeGroup) continue;
// If the group passes the filters, add it to the wallets list
wallets.add(group);
}
for (var group in wallets) {
if (group.wallets.length == 1) {
singleWalletsList.add(group.wallets.first);
} else {
multiWalletGroups.add(group);
}
}
}
WalletListItem convertWalletInfoToWalletListItem(WalletInfo info) {
return WalletListItem(
name: info.name,
type: info.type,
key: info.key,
isCurrent: info.name == _appStore.wallet?.name && info.type == _appStore.wallet?.type,
isEnabled: availableWalletTypes.contains(info.type),
isTestnet: info.network?.toLowerCase().contains('testnet') ?? false,
);
}
}
@@ -1,4 +1,5 @@
import 'package:cake_wallet/core/wallet_loading_service.dart';
import 'package:cake_wallet/entities/wallet_manager.dart';
import 'package:cake_wallet/view_model/wallet_list/wallet_list_view_model.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/di.dart';
@@ -18,8 +19,11 @@ class WalletEditRenamePending extends WalletEditViewModelState {}
class WalletEditDeletePending extends WalletEditViewModelState {}
abstract class WalletEditViewModelBase with Store {
WalletEditViewModelBase(this._walletListViewModel, this._walletLoadingService)
: state = WalletEditViewModelInitialState(),
WalletEditViewModelBase(
this._walletListViewModel,
this._walletLoadingService,
this._walletManager,
) : state = WalletEditViewModelInitialState(),
newName = '';
@observable
@@ -30,13 +34,30 @@ abstract class WalletEditViewModelBase with Store {
final WalletListViewModel _walletListViewModel;
final WalletLoadingService _walletLoadingService;
final WalletManager _walletManager;
@action
Future<void> changeName(WalletListItem walletItem, {String? password}) async {
Future<void> changeName(
WalletListItem walletItem, {
String? password,
String? groupParentAddress,
bool isWalletGroup = false,
}) async {
state = WalletEditRenamePending();
await _walletLoadingService.renameWallet(
walletItem.type, walletItem.name, newName,
password: password);
if (isWalletGroup) {
_walletManager.updateWalletGroups();
_walletManager.setGroupName(groupParentAddress!, newName);
} else {
await _walletLoadingService.renameWallet(
walletItem.type,
walletItem.name,
newName,
password: password,
);
}
_walletListViewModel.updateList();
}
@@ -1,5 +1,7 @@
import 'package:cake_wallet/core/wallet_loading_service.dart';
import 'package:cake_wallet/entities/wallet_group.dart';
import 'package:cake_wallet/entities/wallet_list_order_types.dart';
import 'package:cake_wallet/entities/wallet_manager.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/store/app_store.dart';
@@ -17,7 +19,10 @@ abstract class WalletListViewModelBase with Store {
this._walletInfoSource,
this._appStore,
this._walletLoadingService,
) : wallets = ObservableList<WalletListItem>() {
this._walletManager,
) : wallets = ObservableList<WalletListItem>(),
multiWalletGroups = ObservableList<WalletGroup>(),
singleWalletsList = ObservableList<WalletListItem>() {
setOrderType(_appStore.settingsStore.walletListOrder);
reaction((_) => _appStore.wallet, (_) => updateList());
updateList();
@@ -26,6 +31,15 @@ abstract class WalletListViewModelBase with Store {
@observable
ObservableList<WalletListItem> wallets;
// @observable
// ObservableList<WalletGroup> walletGroups;
@observable
ObservableList<WalletGroup> multiWalletGroups;
@observable
ObservableList<WalletListItem> singleWalletsList;
@computed
bool get shouldRequireTOTP2FAForAccessingWallet =>
_appStore.settingsStore.shouldRequireTOTP2FAForAccessingWallet;
@@ -35,6 +49,7 @@ abstract class WalletListViewModelBase with Store {
_appStore.settingsStore.shouldRequireTOTP2FAForCreatingNewWallets;
final AppStore _appStore;
final WalletManager _walletManager;
final Box<WalletInfo> _walletInfoSource;
final WalletLoadingService _walletLoadingService;
@@ -53,18 +68,23 @@ abstract class WalletListViewModelBase with Store {
@action
void updateList() {
wallets.clear();
multiWalletGroups.clear();
singleWalletsList.clear();
wallets.addAll(
_walletInfoSource.values.map(
(info) => WalletListItem(
name: info.name,
type: info.type,
key: info.key,
isCurrent: info.name == _appStore.wallet?.name && info.type == _appStore.wallet?.type,
isEnabled: availableWalletTypes.contains(info.type),
isTestnet: info.network?.toLowerCase().contains('testnet') ?? false,
),
),
_walletInfoSource.values.map((info) => convertWalletInfoToWalletListItem(info)),
);
//========== Split into shared seed groups and single wallets list
_walletManager.updateWalletGroups();
for (var group in _walletManager.walletGroups) {
if (group.wallets.length == 1) {
singleWalletsList.add(convertWalletInfoToWalletListItem(group.wallets.first));
} else {
multiWalletGroups.add(group);
}
}
}
Future<void> reorderAccordingToWalletList() async {
@@ -158,4 +178,15 @@ abstract class WalletListViewModelBase with Store {
break;
}
}
WalletListItem convertWalletInfoToWalletListItem(WalletInfo info) {
return WalletListItem(
name: info.name,
type: info.type,
key: info.key,
isCurrent: info.name == _appStore.wallet?.name && info.type == _appStore.wallet?.type,
isEnabled: availableWalletTypes.contains(info.type),
isTestnet: info.network?.toLowerCase().contains('testnet') ?? false,
);
}
}
+62 -19
View File
@@ -1,8 +1,9 @@
import 'package:cake_wallet/core/new_wallet_arguments.dart';
import 'package:cake_wallet/ethereum/ethereum.dart';
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/bitcoin_cash/bitcoin_cash.dart';
import 'package:cake_wallet/core/wallet_creation_service.dart';
import 'package:cake_wallet/entities/seed_type.dart';
import 'package:cake_wallet/ethereum/ethereum.dart';
import 'package:cake_wallet/haven/haven.dart';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/nano/nano.dart';
@@ -28,16 +29,17 @@ class WalletNewVM = WalletNewVMBase with _$WalletNewVM;
abstract class WalletNewVMBase extends WalletCreationVM with Store {
WalletNewVMBase(
AppStore appStore,
WalletCreationService walletCreationService,
Box<WalletInfo> walletInfoSource,
this.advancedPrivacySettingsViewModel,
SeedSettingsViewModel seedSettingsViewModel,
{required WalletType type})
: selectedMnemonicLanguage = '',
AppStore appStore,
WalletCreationService walletCreationService,
Box<WalletInfo> walletInfoSource,
this.advancedPrivacySettingsViewModel,
SeedSettingsViewModel seedSettingsViewModel, {
required this.newWalletArguments,
}) : selectedMnemonicLanguage = '',
super(appStore, walletInfoSource, walletCreationService, seedSettingsViewModel,
type: type, isRecovery: false);
type: newWalletArguments!.type, isRecovery: false);
final NewWalletArguments? newWalletArguments;
final AdvancedPrivacySettingsViewModel advancedPrivacySettingsViewModel;
@observable
@@ -62,6 +64,10 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store {
return seedSettingsViewModel.bitcoinSeedType == BitcoinSeedType.bip39
? advancedPrivacySettingsViewModel.seedPhraseLength.value
: 24;
case WalletType.nano:
return seedSettingsViewModel.nanoSeedType == NanoSeedType.bip39
? advancedPrivacySettingsViewModel.seedPhraseLength.value
: 24;
default:
return 24;
}
@@ -83,31 +89,68 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store {
password: walletPassword,
isPolyseed: options.last as bool);
case WalletType.bitcoin:
return bitcoin!.createBitcoinNewWalletCredentials(
name: name, password: walletPassword, passphrase: passphrase);
case WalletType.litecoin:
return bitcoin!.createBitcoinNewWalletCredentials(
name: name, password: walletPassword, passphrase: passphrase);
name: name,
password: walletPassword,
passphrase: passphrase,
mnemonic: newWalletArguments!.mnemonic,
parentAddress: newWalletArguments!.parentAddress,
);
case WalletType.haven:
return haven!.createHavenNewWalletCredentials(
name: name, language: options!.first as String, password: walletPassword);
case WalletType.ethereum:
return ethereum!.createEthereumNewWalletCredentials(name: name, password: walletPassword);
return ethereum!.createEthereumNewWalletCredentials(
name: name,
password: walletPassword,
mnemonic: newWalletArguments!.mnemonic,
parentAddress: newWalletArguments!.parentAddress,
);
case WalletType.bitcoinCash:
return bitcoinCash!.createBitcoinCashNewWalletCredentials(
name: name, password: walletPassword, passphrase: passphrase);
name: name,
password: walletPassword,
passphrase: passphrase,
mnemonic: newWalletArguments!.mnemonic,
parentAddress: newWalletArguments!.parentAddress,
);
case WalletType.nano:
case WalletType.banano:
return nano!.createNanoNewWalletCredentials(name: name);
return nano!.createNanoNewWalletCredentials(
name: name,
password: walletPassword,
mnemonic: newWalletArguments!.mnemonic,
parentAddress: newWalletArguments!.parentAddress,
);
case WalletType.polygon:
return polygon!.createPolygonNewWalletCredentials(name: name, password: walletPassword);
return polygon!.createPolygonNewWalletCredentials(
name: name,
password: walletPassword,
mnemonic: newWalletArguments!.mnemonic,
parentAddress: newWalletArguments!.parentAddress,
);
case WalletType.solana:
return solana!.createSolanaNewWalletCredentials(name: name, password: walletPassword);
return solana!.createSolanaNewWalletCredentials(
name: name,
password: walletPassword,
mnemonic: newWalletArguments!.mnemonic,
parentAddress: newWalletArguments!.parentAddress,
);
case WalletType.tron:
return tron!.createTronNewWalletCredentials(name: name);
return tron!.createTronNewWalletCredentials(
name: name,
password: walletPassword,
mnemonic: newWalletArguments!.mnemonic,
parentAddress: newWalletArguments!.parentAddress,
);
case WalletType.wownero:
return wownero!.createWowneroNewWalletCredentials(
name: name, language: options!.first as String, isPolyseed: options.last as bool);
name: name,
password: walletPassword,
language: options!.first as String,
isPolyseed: options.last as bool,
);
case WalletType.none:
throw Exception('Unexpected type: ${type.toString()}');
}