diff --git a/cw_ethereum/lib/ethereum_wallet.dart b/cw_ethereum/lib/ethereum_wallet.dart index f84ca638f..d428f5ce3 100644 --- a/cw_ethereum/lib/ethereum_wallet.dart +++ b/cw_ethereum/lib/ethereum_wallet.dart @@ -67,6 +67,7 @@ abstract class EthereumWalletBase walletInfo: walletInfo, password: password, encryptionFileUtils: encryptionFileUtils, + isFlatpak: isFlatpak, ); if (!CakeHive.isAdapterRegistered(Erc20Token.typeId)) { @@ -407,6 +408,7 @@ abstract class EthereumWalletBase privateKey: privateKey, initialBalance: balance, encryptionFileUtils: encryptionFileUtils, + isFlatpak: isFlatpak, ); } diff --git a/cw_haven/pubspec.lock b/cw_haven/pubspec.lock index b0a350cc7..6cdb923ed 100644 --- a/cw_haven/pubspec.lock +++ b/cw_haven/pubspec.lock @@ -113,6 +113,15 @@ packages: url: "https://pub.dev" source: hosted version: "8.4.3" + cake_backup: + dependency: transitive + description: + path: "." + ref: main + resolved-ref: "3aba867dcab6737f6707782f5db15d71f303db38" + url: "https://github.com/cake-tech/cake_backup.git" + source: git + version: "1.0.0+1" characters: dependency: transitive description: @@ -169,6 +178,22 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.2" + cryptography: + dependency: transitive + description: + name: cryptography + sha256: df156c5109286340817d21fa7b62f9140f17915077127dd70f8bd7a2a0997a35 + url: "https://pub.dev" + source: hosted + version: "2.5.0" + cupertino_icons: + dependency: transitive + description: + name: cupertino_icons + sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d + url: "https://pub.dev" + source: hosted + version: "1.0.6" cw_core: dependency: "direct main" description: @@ -623,6 +648,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.1" + tuple: + dependency: transitive + description: + name: tuple + sha256: a97ce2013f240b2f3807bcbaf218765b6f301c3eff91092bcfa23a039e7dd151 + url: "https://pub.dev" + source: hosted + version: "2.0.2" typed_data: dependency: transitive description: diff --git a/cw_nano/lib/nano_wallet.dart b/cw_nano/lib/nano_wallet.dart index 959a2ed44..eb2a237da 100644 --- a/cw_nano/lib/nano_wallet.dart +++ b/cw_nano/lib/nano_wallet.dart @@ -59,6 +59,7 @@ abstract class NanoWalletBase walletInfo: walletInfo, password: password, encryptionFileUtils: encryptionFileUtils, + isFlatpak: isFlatpak, ); if (!CakeHive.isAdapterRegistered(NanoAccount.typeId)) { CakeHive.registerAdapter(NanoAccountAdapter()); @@ -410,6 +411,7 @@ abstract class NanoWalletBase mnemonic: mnemonic, initialBalance: balance, encryptionFileUtils: encryptionFileUtils, + isFlatpak: isFlatpak, ); // init() should always be run after this! } diff --git a/cw_nano/pubspec.lock b/cw_nano/pubspec.lock index a42bb9ab4..9110b6970 100644 --- a/cw_nano/pubspec.lock +++ b/cw_nano/pubspec.lock @@ -137,6 +137,15 @@ packages: url: "https://pub.dev" source: hosted version: "8.6.1" + cake_backup: + dependency: transitive + description: + path: "." + ref: main + resolved-ref: "3aba867dcab6737f6707782f5db15d71f303db38" + url: "https://github.com/cake-tech/cake_backup.git" + source: git + version: "1.0.0+1" characters: dependency: transitive description: @@ -193,6 +202,22 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.3" + cryptography: + dependency: transitive + description: + name: cryptography + sha256: df156c5109286340817d21fa7b62f9140f17915077127dd70f8bd7a2a0997a35 + url: "https://pub.dev" + source: hosted + version: "2.5.0" + cupertino_icons: + dependency: transitive + description: + name: cupertino_icons + sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d + url: "https://pub.dev" + source: hosted + version: "1.0.6" cw_core: dependency: "direct main" description: @@ -773,6 +798,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.1" + tuple: + dependency: transitive + description: + name: tuple + sha256: a97ce2013f240b2f3807bcbaf218765b6f301c3eff91092bcfa23a039e7dd151 + url: "https://pub.dev" + source: hosted + version: "2.0.2" typed_data: dependency: transitive description: diff --git a/cw_polygon/lib/polygon_wallet.dart b/cw_polygon/lib/polygon_wallet.dart index 8b6133664..8188caecd 100644 --- a/cw_polygon/lib/polygon_wallet.dart +++ b/cw_polygon/lib/polygon_wallet.dart @@ -11,7 +11,6 @@ import 'package:cw_core/pending_transaction.dart'; import 'package:cw_core/sync_status.dart'; import 'package:cw_core/transaction_direction.dart'; import 'package:cw_core/transaction_priority.dart'; -import 'package:cw_core/utils/file.dart'; import 'package:cw_core/wallet_addresses.dart'; import 'package:cw_core/wallet_base.dart'; import 'package:cw_core/wallet_info.dart'; @@ -19,6 +18,7 @@ import 'package:cw_ethereum/erc20_balance.dart'; import 'package:cw_ethereum/ethereum_formatter.dart'; import 'package:cw_core/erc20_token.dart'; import 'package:cw_polygon/default_polygon_erc20_tokens.dart'; +import 'package:cw_core/encryption_file_utils.dart'; import 'package:cw_polygon/polygon_client.dart'; import 'package:cw_polygon/polygon_exceptions.dart'; import 'package:cw_polygon/polygon_formatter.dart'; @@ -48,6 +48,7 @@ abstract class PolygonWalletBase String? mnemonic, String? privateKey, required String password, + required EncryptionFileUtils encryptionFileUtils, ERC20Balance? initialBalance, required this.isFlatpak, }) : syncStatus = const NotConnectedSyncStatus(), @@ -55,13 +56,15 @@ abstract class PolygonWalletBase _mnemonic = mnemonic, _hexPrivateKey = privateKey, _isTransactionUpdating = false, + _encryptionFileUtils = encryptionFileUtils, _client = PolygonClient(), walletAddresses = PolygonWalletAddresses(walletInfo), balance = ObservableMap.of( {CryptoCurrency.maticpoly: initialBalance ?? ERC20Balance(BigInt.zero)}), super(walletInfo) { this.walletInfo = walletInfo; - transactionHistory = PolygonTransactionHistory(walletInfo: walletInfo, password: password); + transactionHistory = + PolygonTransactionHistory(walletInfo: walletInfo, password: password, isFlatpak: isFlatpak); if (!CakeHive.isAdapterRegistered(Erc20Token.typeId)) { CakeHive.registerAdapter(Erc20TokenAdapter()); @@ -76,6 +79,8 @@ abstract class PolygonWalletBase final String? _hexPrivateKey; final String _password; + final EncryptionFileUtils _encryptionFileUtils; + late final Box polygonErc20TokensBox; late final EthPrivateKey _polygonPrivateKey; @@ -314,7 +319,7 @@ abstract class PolygonWalletBase Future save() async { await walletAddresses.updateAddressesInBox(); final path = await makePath(); - await write(path: path, password: _password, data: toJSON()); + await _encryptionFileUtils.write(path: path, password: _password, data: toJSON()); await transactionHistory.save(); } @@ -358,9 +363,10 @@ abstract class PolygonWalletBase {required String name, required String password, required WalletInfo walletInfo, + required EncryptionFileUtils encryptionFileUtils, required bool isFlatpak}) async { final path = await pathForWallet(name: name, type: walletInfo.type, isFlatpak: isFlatpak); - final jsonSource = await read(path: path, password: password); + final jsonSource = await encryptionFileUtils.read(path: path, password: password); final data = json.decode(jsonSource) as Map; final mnemonic = data['mnemonic'] as String?; final privateKey = data['private_key'] as String?; @@ -372,6 +378,8 @@ abstract class PolygonWalletBase mnemonic: mnemonic, privateKey: privateKey, initialBalance: balance, + encryptionFileUtils: encryptionFileUtils, + isFlatpak: isFlatpak, ); } diff --git a/cw_polygon/lib/polygon_wallet_service.dart b/cw_polygon/lib/polygon_wallet_service.dart index 7fb6e724d..6e7edcedc 100644 --- a/cw_polygon/lib/polygon_wallet_service.dart +++ b/cw_polygon/lib/polygon_wallet_service.dart @@ -5,6 +5,7 @@ import 'package:cw_core/wallet_base.dart'; import 'package:cw_core/wallet_info.dart'; import 'package:cw_core/wallet_service.dart'; import 'package:cw_core/wallet_type.dart'; +import 'package:cw_core/encryption_file_utils.dart'; import 'package:cw_ethereum/ethereum_mnemonics.dart'; import 'package:cw_polygon/polygon_wallet.dart'; import 'package:bip39/bip39.dart' as bip39; @@ -14,9 +15,10 @@ import 'package:collection/collection.dart'; class PolygonWalletService extends WalletService { - PolygonWalletService(this.walletInfoSource, this.isFlatpak); + PolygonWalletService(this.walletInfoSource, this.isDirect, this.isFlatpak); final Box walletInfoSource; + final bool isDirect; final bool isFlatpak; @override @@ -28,6 +30,7 @@ class PolygonWalletService extends WalletService stringDoubleToBitcoinAmount(amount); - @override - WalletCredentials createBitcoinRestoreWalletFromSeedCredentials( - {required String name, required String mnemonic, required String password}) => - BitcoinRestoreWalletFromSeedCredentials(name: name, mnemonic: mnemonic, password: password); - - @override - WalletCredentials createBitcoinRestoreWalletFromWIFCredentials( - {required String name, - required String password, - required String wif, - WalletInfo? walletInfo}) => - BitcoinRestoreWalletFromWIFCredentials( - name: name, password: password, wif: wif, walletInfo: walletInfo); - - @override - WalletCredentials createBitcoinNewWalletCredentials( - {required String name, WalletInfo? walletInfo, String? password}) => - BitcoinNewWalletCredentials(name: name, walletInfo: walletInfo, password: password); - - @override - List getWordList() => wordlist; - - @override - Map getWalletKeys(Object wallet) { - final bitcoinWallet = wallet as ElectrumWallet; - final keys = bitcoinWallet.keys; - - return { - 'wif': keys.wif, - 'privateKey': keys.privateKey, - 'publicKey': keys.publicKey - }; - } - - @override - List getTransactionPriorities() => BitcoinTransactionPriority.all; - - @override - List getLitecoinTransactionPriorities() => LitecoinTransactionPriority.all; - - @override - TransactionPriority deserializeBitcoinTransactionPriority(int raw) => - BitcoinTransactionPriority.deserialize(raw: raw); - - @override - TransactionPriority deserializeLitecoinTransactionPriority(int raw) => - LitecoinTransactionPriority.deserialize(raw: raw); - - @override - int getFeeRate(Object wallet, TransactionPriority priority) { - final bitcoinWallet = wallet as ElectrumWallet; - return bitcoinWallet.feeRate(priority); - } - - @override - Future generateNewAddress(Object wallet) async { - final bitcoinWallet = wallet as ElectrumWallet; - await bitcoinWallet.walletAddresses.generateNewAddress(); - } - - @override - Object createBitcoinTransactionCredentials(List outputs, - {required TransactionPriority priority, int? feeRate}) => - BitcoinTransactionCredentials( - outputs - .map((out) => OutputInfo( - fiatAmount: out.fiatAmount, - cryptoAmount: out.cryptoAmount, - address: out.address, - note: out.note, - sendAll: out.sendAll, - extractedAddress: out.extractedAddress, - isParsedAddress: out.isParsedAddress, - formattedCryptoAmount: out.formattedCryptoAmount)) - .toList(), - priority: priority as BitcoinTransactionPriority, - feeRate: feeRate); - - @override - Object createBitcoinTransactionCredentialsRaw(List outputs, - {TransactionPriority? priority, required int feeRate}) => - BitcoinTransactionCredentials(outputs, - priority: priority != null ? priority as BitcoinTransactionPriority : null, - feeRate: feeRate); - - @override - List getAddresses(Object wallet) { - final bitcoinWallet = wallet as ElectrumWallet; - return bitcoinWallet.walletAddresses.addresses - .map((BitcoinAddressRecord addr) => addr.address) - .toList(); - } - - @override - String getAddress(Object wallet) { - final bitcoinWallet = wallet as ElectrumWallet; - return bitcoinWallet.walletAddresses.address; - } - - @override - String formatterBitcoinAmountToString({required int amount}) => - bitcoinAmountToString(amount: amount); - - @override - double formatterBitcoinAmountToDouble({required int amount}) => - bitcoinAmountToDouble(amount: amount); - - @override - int formatterStringDoubleToBitcoinAmount(String amount) => stringDoubleToBitcoinAmount(amount); - @override String bitcoinTransactionPriorityWithLabel(TransactionPriority priority, int rate) => (priority as BitcoinTransactionPriority).labelWithRate(rate); diff --git a/lib/polygon/cw_polygon.dart b/lib/polygon/cw_polygon.dart index b8bf6f0d5..98bfa0b42 100644 --- a/lib/polygon/cw_polygon.dart +++ b/lib/polygon/cw_polygon.dart @@ -5,8 +5,8 @@ class CWPolygon extends Polygon { List getPolygonWordList(String language) => EthereumMnemonics.englishWordlist; WalletService createPolygonWalletService( - Box walletInfoSource, bool isDirec, bool isFlatpak) => - PolygonWalletService(walletInfoSource, isFlatpak); + Box walletInfoSource, bool isDirect, bool isFlatpak) => + PolygonWalletService(walletInfoSource, isDirect, isFlatpak); @override WalletCredentials createPolygonNewWalletCredentials( diff --git a/tool/configure.dart b/tool/configure.dart index 7974419e3..9c4afe45b 100644 --- a/tool/configure.dart +++ b/tool/configure.dart @@ -637,7 +637,7 @@ import 'package:cw_ethereum/ethereum_mnemonics.dart'; const polygonContent = """ abstract class Polygon { List getPolygonWordList(String language); - WalletService createPolygonWalletService(Box walletInfoSource, bool isDirec, bool isFlatpak); + WalletService createPolygonWalletService(Box walletInfoSource, bool isDirect, bool isFlatpak); WalletCredentials createPolygonNewWalletCredentials({required String name, WalletInfo? walletInfo, String? password}); WalletCredentials createPolygonRestoreWalletFromSeedCredentials({required String name, required String mnemonic, required String password}); WalletCredentials createPolygonRestoreWalletFromPrivateKey({required String name, required String privateKey, required String password});