From 36a03b98ad1c6f1a3937dcf8aebe6f7e13304d77 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Mon, 8 Jul 2024 10:41:01 +0200 Subject: [PATCH 1/8] haven: backup seeds --- lib/entities/default_settings_migration.dart | 25 +++++++++++++++++++- lib/entities/haven_seed_store.dart | 19 +++++++++++++++ lib/main.dart | 20 +++++++++++++--- 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 lib/entities/haven_seed_store.dart diff --git a/lib/entities/default_settings_migration.dart b/lib/entities/default_settings_migration.dart index 3aad38179a..2fbd7a2b43 100644 --- a/lib/entities/default_settings_migration.dart +++ b/lib/entities/default_settings_migration.dart @@ -1,11 +1,15 @@ import 'dart:io' show Directory, File, Platform; import 'package:cake_wallet/bitcoin/bitcoin.dart'; +import 'package:cake_wallet/core/key_service.dart'; import 'package:cake_wallet/core/secure_storage.dart'; import 'package:cake_wallet/entities/exchange_api_mode.dart'; import 'package:cake_wallet/entities/fiat_api_mode.dart'; +import 'package:cake_wallet/entities/haven_seed_store.dart'; +import 'package:cw_core/cake_hive.dart'; import 'package:cw_core/pathForWallet.dart'; import 'package:cake_wallet/entities/secret_store_key.dart'; import 'package:cw_core/root_dir.dart'; +import 'package:cw_haven/haven_wallet_service.dart'; import 'package:hive/hive.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:cake_wallet/entities/preferences_key.dart'; @@ -49,7 +53,8 @@ Future defaultSettingsMigration( required Box powNodes, required Box walletInfoSource, required Box tradeSource, - required Box contactSource}) async { + required Box contactSource, + required Box havenSeedStore}) async { if (Platform.isIOS) { await ios_migrate_v1(walletInfoSource, tradeSource, contactSource); } @@ -245,6 +250,9 @@ Future defaultSettingsMigration( _fixNodesUseSSLFlag(nodes); await changeDefaultNanoNode(nodes, sharedPreferences); break; + case 40: + await _backupHavenSeeds(havenSeedStore); + default: break; } @@ -259,6 +267,21 @@ Future defaultSettingsMigration( await sharedPreferences.setInt(PreferencesKey.currentDefaultSettingsMigrationVersion, version); } +Future _backupHavenSeeds(Box havenSeedStore) async { + final walletInfoSource = await CakeHive.openBox(WalletInfo.boxName); + final wallets = walletInfoSource.values + .where((element) => element.type == WalletType.haven); + for (var w in wallets) { + final walletService = HavenWalletService(walletInfoSource); + final flutterSecureStorage = secureStorageShared; + final keyService = KeyService(flutterSecureStorage); + final password = await keyService.getWalletPassword(walletName: w.name); + final wallet = await walletService.openWallet(w.name, password); + havenSeedStore.add(HavenSeedStore(id: wallet.id, seed: wallet.seed)); + wallet.close(); + } +} + void _fixNodesUseSSLFlag(Box nodes) { for (Node node in nodes.values) { switch (node.uriRaw) { diff --git a/lib/entities/haven_seed_store.dart b/lib/entities/haven_seed_store.dart new file mode 100644 index 0000000000..52a156b6eb --- /dev/null +++ b/lib/entities/haven_seed_store.dart @@ -0,0 +1,19 @@ +import 'package:cw_core/hive_type_ids.dart'; +import 'package:hive/hive.dart'; + +part 'haven_seed_store.g.dart'; + +@HiveType(typeId: HavenSeedStore.typeId) +class HavenSeedStore extends HiveObject { + HavenSeedStore({required this.id, this.seed}); + + static const typeId = TRANSACTION_TYPE_ID; + static const boxName = 'HavenSeedStore'; + static const boxKey = 'havenSeedStoreKey'; + + @HiveField(0, defaultValue: '') + String id; + + @HiveField(2) + String? seed; +} diff --git a/lib/main.dart b/lib/main.dart index 014d5f0119..9e3214ac92 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -7,6 +7,7 @@ import 'package:cake_wallet/entities/contact.dart'; import 'package:cake_wallet/entities/default_settings_migration.dart'; import 'package:cake_wallet/entities/get_encryption_key.dart'; import 'package:cake_wallet/core/secure_storage.dart'; +import 'package:cake_wallet/entities/haven_seed_store.dart'; import 'package:cake_wallet/entities/language_service.dart'; import 'package:cake_wallet/entities/template.dart'; import 'package:cake_wallet/entities/transaction_description.dart'; @@ -167,6 +168,10 @@ Future initializeAppConfigs() async { CakeHive.registerAdapter(AnonpayInvoiceInfoAdapter()); } + if (!CakeHive.isAdapterRegistered(HavenSeedStore.typeId)) { + CakeHive.registerAdapter(HavenSeedStoreAdapter()); + } + final secureStorage = secureStorageShared; final transactionDescriptionsBoxKey = @@ -188,6 +193,12 @@ Future initializeAppConfigs() async { final anonpayInvoiceInfo = await CakeHive.openBox(AnonpayInvoiceInfo.boxName); final unspentCoinsInfoSource = await CakeHive.openBox(UnspentCoinsInfo.boxName); + final havenSeedStoreBoxKey = + await getEncryptionKey(secureStorage: secureStorage, forKey: HavenSeedStore.boxKey); + final havenSeedStore = await CakeHive.openBox( + HavenSeedStore.boxName, + encryptionKey: havenSeedStoreBoxKey); + await initialSetup( sharedPreferences: await SharedPreferences.getInstance(), nodes: nodes, @@ -203,7 +214,8 @@ Future initializeAppConfigs() async { transactionDescriptions: transactionDescriptions, secureStorage: secureStorage, anonpayInvoiceInfo: anonpayInvoiceInfo, - initialMigrationVersion: 39, + havenSeedStore: havenSeedStore, + initialMigrationVersion: 40, ); } @@ -222,7 +234,8 @@ Future initialSetup( required SecureStorage secureStorage, required Box anonpayInvoiceInfo, required Box unspentCoinsInfoSource, - int initialMigrationVersion = 15}) async { + required Box havenSeedStore, + int initialMigrationVersion = 15, }) async { LanguageService.loadLocaleList(); await defaultSettingsMigration( secureStorage: secureStorage, @@ -232,7 +245,8 @@ Future initialSetup( contactSource: contactSource, tradeSource: tradesSource, nodes: nodes, - powNodes: powNodes); + powNodes: powNodes, + havenSeedStore: havenSeedStore); await setup( walletInfoSource: walletInfoSource, nodeSource: nodes, From 892c1e8b2f5ec0f2d8903953914fb7872e120835 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Tue, 9 Jul 2024 10:07:56 +0200 Subject: [PATCH 2/8] haven backup fixes --- cw_core/lib/hive_type_ids.dart | 1 + lib/entities/default_settings_migration.dart | 3 ++- lib/entities/haven_seed_store.dart | 2 +- .../new_wallet/new_wallet_type_page.dart | 20 +++++++++---------- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/cw_core/lib/hive_type_ids.dart b/cw_core/lib/hive_type_ids.dart index 4da616a79c..612e2db128 100644 --- a/cw_core/lib/hive_type_ids.dart +++ b/cw_core/lib/hive_type_ids.dart @@ -18,3 +18,4 @@ const SPL_TOKEN_TYPE_ID = 16; const DERIVATION_INFO_TYPE_ID = 17; const TRON_TOKEN_TYPE_ID = 18; const HARDWARE_WALLET_TYPE_TYPE_ID = 19; +const HAVEN_SEED_STORE_TYPE_ID = 20; \ No newline at end of file diff --git a/lib/entities/default_settings_migration.dart b/lib/entities/default_settings_migration.dart index 2fbd7a2b43..0ae4e370d5 100644 --- a/lib/entities/default_settings_migration.dart +++ b/lib/entities/default_settings_migration.dart @@ -277,9 +277,10 @@ Future _backupHavenSeeds(Box havenSeedStore) async { final keyService = KeyService(flutterSecureStorage); final password = await keyService.getWalletPassword(walletName: w.name); final wallet = await walletService.openWallet(w.name, password); - havenSeedStore.add(HavenSeedStore(id: wallet.id, seed: wallet.seed)); + await havenSeedStore.add(HavenSeedStore(id: wallet.id, seed: wallet.seed)); wallet.close(); } + await havenSeedStore.flush(); } void _fixNodesUseSSLFlag(Box nodes) { diff --git a/lib/entities/haven_seed_store.dart b/lib/entities/haven_seed_store.dart index 52a156b6eb..f899799d84 100644 --- a/lib/entities/haven_seed_store.dart +++ b/lib/entities/haven_seed_store.dart @@ -7,7 +7,7 @@ part 'haven_seed_store.g.dart'; class HavenSeedStore extends HiveObject { HavenSeedStore({required this.id, this.seed}); - static const typeId = TRANSACTION_TYPE_ID; + static const typeId = HAVEN_SEED_STORE_TYPE_ID; static const boxName = 'HavenSeedStore'; static const boxKey = 'havenSeedStoreKey'; diff --git a/lib/src/screens/new_wallet/new_wallet_type_page.dart b/lib/src/screens/new_wallet/new_wallet_type_page.dart index 65c7bd59b7..9df9fea922 100644 --- a/lib/src/screens/new_wallet/new_wallet_type_page.dart +++ b/lib/src/screens/new_wallet/new_wallet_type_page.dart @@ -168,16 +168,16 @@ class WalletTypeFormState extends State { Future onTypeSelected() async { if (selected == null) throw Exception('Wallet Type is not selected yet.'); - if (selected == WalletType.haven && widget.isCreate) { - return await showPopUp( - context: context, - builder: (BuildContext context) => PopUpCancellableAlertDialog( - contentText: S.of(context).pause_wallet_creation, - actionButtonText: S.of(context).ok, - buttonAction: () => Navigator.of(context).pop(), - ), - ); - } + // if (selected == WalletType.haven && widget.isCreate) { + // return await showPopUp( + // context: context, + // builder: (BuildContext context) => PopUpCancellableAlertDialog( + // contentText: S.of(context).pause_wallet_creation, + // actionButtonText: S.of(context).ok, + // buttonAction: () => Navigator.of(context).pop(), + // ), + // ); + // } widget.onTypeSelected(context, selected!); } From a311a194f214bf29dd69f093271c1575035d8390 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Tue, 9 Jul 2024 10:08:54 +0200 Subject: [PATCH 3/8] ci fix --- .github/workflows/pr_test_build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr_test_build.yml b/.github/workflows/pr_test_build.yml index b0177965ef..285a48c1b0 100644 --- a/.github/workflows/pr_test_build.yml +++ b/.github/workflows/pr_test_build.yml @@ -67,7 +67,7 @@ jobs: ./install_ndk.sh source ./app_env.sh cakewallet chmod +x pubspec_gen.sh - ./app_config.sh + CW_WITH_HAVEN=true ./app_config.sh - name: Cache Externals id: cache-externals @@ -80,7 +80,7 @@ jobs: /opt/android/cake_wallet/cw_monero/ios/External /opt/android/cake_wallet/cw_shared_external/ios/External /opt/android/cake_wallet/scripts/monero_c/release - key: ${{ hashFiles('**/prepare_moneroc.sh' ,'**/build_monero_all.sh') }} + key: haven-${{ hashFiles('**/prepare_moneroc.sh' ,'**/build_monero_all.sh') }} - if: ${{ steps.cache-externals.outputs.cache-hit != 'true' }} name: Generate Externals From d13d7a55cea4e2cbd7444574f84736622cf275f1 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Tue, 9 Jul 2024 12:59:02 +0200 Subject: [PATCH 4/8] reorder build script --- .github/workflows/pr_test_build.yml | 2 +- .../new_wallet/new_wallet_type_page.dart | 20 +++++++++---------- scripts/android/build_all.sh | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/pr_test_build.yml b/.github/workflows/pr_test_build.yml index 07d9eed589..ffddd4ae9d 100644 --- a/.github/workflows/pr_test_build.yml +++ b/.github/workflows/pr_test_build.yml @@ -76,7 +76,7 @@ jobs: path: | /opt/android/cake_wallet/cw_haven/android/.cxx /opt/android/cake_wallet/scripts/monero_c/release - key: haven-${{ hashFiles('**/prepare_moneroc.sh' ,'**/build_monero_all.sh') }} + key: haven-v2-${{ hashFiles('**/prepare_moneroc.sh' ,'**/build_monero_all.sh') }} - if: ${{ steps.cache-externals.outputs.cache-hit != 'true' }} name: Generate Externals diff --git a/lib/src/screens/new_wallet/new_wallet_type_page.dart b/lib/src/screens/new_wallet/new_wallet_type_page.dart index 9df9fea922..65c7bd59b7 100644 --- a/lib/src/screens/new_wallet/new_wallet_type_page.dart +++ b/lib/src/screens/new_wallet/new_wallet_type_page.dart @@ -168,16 +168,16 @@ class WalletTypeFormState extends State { Future onTypeSelected() async { if (selected == null) throw Exception('Wallet Type is not selected yet.'); - // if (selected == WalletType.haven && widget.isCreate) { - // return await showPopUp( - // context: context, - // builder: (BuildContext context) => PopUpCancellableAlertDialog( - // contentText: S.of(context).pause_wallet_creation, - // actionButtonText: S.of(context).ok, - // buttonAction: () => Navigator.of(context).pop(), - // ), - // ); - // } + if (selected == WalletType.haven && widget.isCreate) { + return await showPopUp( + context: context, + builder: (BuildContext context) => PopUpCancellableAlertDialog( + contentText: S.of(context).pause_wallet_creation, + actionButtonText: S.of(context).ok, + buttonAction: () => Navigator.of(context).pop(), + ), + ); + } widget.onTypeSelected(context, selected!); } diff --git a/scripts/android/build_all.sh b/scripts/android/build_all.sh index ec70f02a60..62b8ac2709 100755 --- a/scripts/android/build_all.sh +++ b/scripts/android/build_all.sh @@ -9,7 +9,7 @@ DIR=$(dirname "$0") case $APP_ANDROID_TYPE in "monero.com") $DIR/build_monero_all.sh ;; - "cakewallet") $DIR/build_monero_all.sh - $DIR/build_haven_all.sh ;; + "cakewallet") $DIR/build_haven_all.sh + $DIR/build_monero_all.sh ;; "haven") $DIR/build_haven_all.sh ;; esac From 52b4fdf95bbfb0185aadb3823a2cc1cc18b4beb6 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Fri, 12 Jul 2024 07:00:35 +0200 Subject: [PATCH 5/8] disable haven --- .github/workflows/pr_test_build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr_test_build.yml b/.github/workflows/pr_test_build.yml index ffddd4ae9d..9fa8ad559b 100644 --- a/.github/workflows/pr_test_build.yml +++ b/.github/workflows/pr_test_build.yml @@ -67,7 +67,7 @@ jobs: ./install_ndk.sh source ./app_env.sh cakewallet chmod +x pubspec_gen.sh - CW_WITH_HAVEN=true ./app_config.sh + ./app_config.sh - name: Cache Externals id: cache-externals From 10b0eeab54919c1602437732ee21e8a5d9e0b862 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Mon, 15 Jul 2024 09:31:57 +0200 Subject: [PATCH 6/8] properly call cw_haven code --- lib/entities/default_settings_migration.dart | 17 +++++------------ lib/haven/cw_haven.dart | 17 +++++++++++++++++ tool/configure.dart | 11 ++++++++++- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/lib/entities/default_settings_migration.dart b/lib/entities/default_settings_migration.dart index 0ae4e370d5..62de69e071 100644 --- a/lib/entities/default_settings_migration.dart +++ b/lib/entities/default_settings_migration.dart @@ -5,6 +5,7 @@ import 'package:cake_wallet/core/secure_storage.dart'; import 'package:cake_wallet/entities/exchange_api_mode.dart'; import 'package:cake_wallet/entities/fiat_api_mode.dart'; import 'package:cake_wallet/entities/haven_seed_store.dart'; +import 'package:cake_wallet/haven/haven.dart'; import 'package:cw_core/cake_hive.dart'; import 'package:cw_core/pathForWallet.dart'; import 'package:cake_wallet/entities/secret_store_key.dart'; @@ -268,19 +269,11 @@ Future defaultSettingsMigration( } Future _backupHavenSeeds(Box havenSeedStore) async { - final walletInfoSource = await CakeHive.openBox(WalletInfo.boxName); - final wallets = walletInfoSource.values - .where((element) => element.type == WalletType.haven); - for (var w in wallets) { - final walletService = HavenWalletService(walletInfoSource); - final flutterSecureStorage = secureStorageShared; - final keyService = KeyService(flutterSecureStorage); - final password = await keyService.getWalletPassword(walletName: w.name); - final wallet = await walletService.openWallet(w.name, password); - await havenSeedStore.add(HavenSeedStore(id: wallet.id, seed: wallet.seed)); - wallet.close(); + final future = haven?.backupHavenSeeds(havenSeedStore); + if (future != null) { + await future; } - await havenSeedStore.flush(); + return; } void _fixNodesUseSSLFlag(Box nodes) { diff --git a/lib/haven/cw_haven.dart b/lib/haven/cw_haven.dart index 57c4e49c32..c54e47eb42 100644 --- a/lib/haven/cw_haven.dart +++ b/lib/haven/cw_haven.dart @@ -307,6 +307,23 @@ class CWHaven extends Haven { return havenTransactionInfo.accountIndex; } + @override + Future backupHavenSeeds(Box havenSeedStore) async { + final walletInfoSource = await CakeHive.openBox(WalletInfo.boxName); + final wallets = walletInfoSource.values + .where((element) => element.type == WalletType.haven); + for (var w in wallets) { + final walletService = HavenWalletService(walletInfoSource); + final flutterSecureStorage = secureStorageShared; + final keyService = KeyService(flutterSecureStorage); + final password = await keyService.getWalletPassword(walletName: w.name); + final wallet = await walletService.openWallet(w.name, password); + await havenSeedStore.add(HavenSeedStore(id: wallet.id, seed: wallet.seed)); + wallet.close(); + } + await havenSeedStore.flush(); + } + @override WalletService createHavenWalletService(Box walletInfoSource) { return HavenWalletService(walletInfoSource); diff --git a/tool/configure.dart b/tool/configure.dart index 853d064486..554e7eb824 100644 --- a/tool/configure.dart +++ b/tool/configure.dart @@ -618,7 +618,14 @@ import 'package:cw_core/output_info.dart'; import 'package:cake_wallet/view_model/send/output.dart'; import 'package:cw_core/wallet_service.dart'; import 'package:hive/hive.dart'; -import 'package:cw_core/crypto_currency.dart';"""; +import 'package:cw_core/crypto_currency.dart'; +import 'package:cake_wallet/core/key_service.dart'; +import 'package:cake_wallet/core/secure_storage.dart'; +import 'package:cake_wallet/entities/haven_seed_store.dart'; +import 'package:cw_core/cake_hive.dart'; +import 'package:cw_core/wallet_info.dart'; +import 'package:cw_core/wallet_type.dart'; +"""; const havenCWHeaders = """ import 'package:cw_core/get_height_by_date.dart'; import 'package:cw_core/monero_amount_format.dart'; @@ -641,6 +648,7 @@ import 'package:cw_haven/mnemonics/french.dart'; import 'package:cw_haven/mnemonics/italian.dart'; import 'package:cw_haven/haven_transaction_creation_credentials.dart'; import 'package:cw_haven/api/balance_list.dart'; +import 'package:cw_haven/haven_wallet_service.dart'; """; const havenCwPart = "part 'cw_haven.dart';"; const havenContent = """ @@ -741,6 +749,7 @@ abstract class Haven { void onStartup(); int getTransactionInfoAccountId(TransactionInfo tx); WalletService createHavenWalletService(Box walletInfoSource); + Future backupHavenSeeds(Box havenSeedStore); CryptoCurrency assetOfTransaction(TransactionInfo tx); List getAssetRate(); } From 2d169920bffd551fbf2984d16c6ea1964223104f Mon Sep 17 00:00:00 2001 From: cyan Date: Tue, 26 Nov 2024 11:42:16 +0000 Subject: [PATCH 7/8] [skip ci] update PR --- .github/workflows/pr_test_build.yml | 2 +- lib/entities/default_settings_migration.dart | 1 - scripts/android/build_all.sh | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr_test_build.yml b/.github/workflows/pr_test_build.yml index 9fa8ad559b..f37919e9d9 100644 --- a/.github/workflows/pr_test_build.yml +++ b/.github/workflows/pr_test_build.yml @@ -76,7 +76,7 @@ jobs: path: | /opt/android/cake_wallet/cw_haven/android/.cxx /opt/android/cake_wallet/scripts/monero_c/release - key: haven-v2-${{ hashFiles('**/prepare_moneroc.sh' ,'**/build_monero_all.sh') }} + key: ${{ hashFiles('**/prepare_moneroc.sh' ,'**/build_monero_all.sh') }} - if: ${{ steps.cache-externals.outputs.cache-hit != 'true' }} name: Generate Externals diff --git a/lib/entities/default_settings_migration.dart b/lib/entities/default_settings_migration.dart index 62de69e071..1ac20f3cf2 100644 --- a/lib/entities/default_settings_migration.dart +++ b/lib/entities/default_settings_migration.dart @@ -10,7 +10,6 @@ import 'package:cw_core/cake_hive.dart'; import 'package:cw_core/pathForWallet.dart'; import 'package:cake_wallet/entities/secret_store_key.dart'; import 'package:cw_core/root_dir.dart'; -import 'package:cw_haven/haven_wallet_service.dart'; import 'package:hive/hive.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:cake_wallet/entities/preferences_key.dart'; diff --git a/scripts/android/build_all.sh b/scripts/android/build_all.sh index 62b8ac2709..ec70f02a60 100755 --- a/scripts/android/build_all.sh +++ b/scripts/android/build_all.sh @@ -9,7 +9,7 @@ DIR=$(dirname "$0") case $APP_ANDROID_TYPE in "monero.com") $DIR/build_monero_all.sh ;; - "cakewallet") $DIR/build_haven_all.sh - $DIR/build_monero_all.sh ;; + "cakewallet") $DIR/build_monero_all.sh + $DIR/build_haven_all.sh ;; "haven") $DIR/build_haven_all.sh ;; esac From 560e98d93cebf98496b79d26108fb7aa7fcbc24c Mon Sep 17 00:00:00 2001 From: Omar Hatem Date: Wed, 11 Dec 2024 21:50:15 +0200 Subject: [PATCH 8/8] Update evm_chain_transaction_history.dart remove print --- cw_evm/lib/evm_chain_transaction_history.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/cw_evm/lib/evm_chain_transaction_history.dart b/cw_evm/lib/evm_chain_transaction_history.dart index 4a05746da0..7c46ebecc6 100644 --- a/cw_evm/lib/evm_chain_transaction_history.dart +++ b/cw_evm/lib/evm_chain_transaction_history.dart @@ -84,7 +84,6 @@ abstract class EVMChainTransactionHistoryBase _update(tx); } } - print('doneee'); } catch (e) { log(e.toString()); }