mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-31 16:09:49 +00:00
fix missing encryption utils in hardware wallet functions [skip ci]
This commit is contained in:
parent
b082cd5f4e
commit
5a30aa98f9
7 changed files with 40 additions and 13 deletions
|
@ -105,6 +105,7 @@ class EthereumWalletService extends EVMChainWalletService<EthereumWallet> {
|
||||||
walletInfo: credentials.walletInfo!,
|
walletInfo: credentials.walletInfo!,
|
||||||
password: credentials.password!,
|
password: credentials.password!,
|
||||||
client: client,
|
client: client,
|
||||||
|
encryptionFileUtils: encryptionFileUtilsFor(isDirect),
|
||||||
);
|
);
|
||||||
|
|
||||||
await wallet.init();
|
await wallet.init();
|
||||||
|
|
|
@ -106,6 +106,7 @@ class PolygonWalletService extends EVMChainWalletService<PolygonWallet> {
|
||||||
walletInfo: credentials.walletInfo!,
|
walletInfo: credentials.walletInfo!,
|
||||||
password: credentials.password!,
|
password: credentials.password!,
|
||||||
client: client,
|
client: client,
|
||||||
|
encryptionFileUtils: encryptionFileUtilsFor(isDirect),
|
||||||
);
|
);
|
||||||
|
|
||||||
await wallet.init();
|
await wallet.init();
|
||||||
|
|
|
@ -3,7 +3,7 @@ import 'dart:core';
|
||||||
import 'dart:developer';
|
import 'dart:developer';
|
||||||
import 'package:cw_core/pathForWallet.dart';
|
import 'package:cw_core/pathForWallet.dart';
|
||||||
import 'package:cw_core/wallet_info.dart';
|
import 'package:cw_core/wallet_info.dart';
|
||||||
import 'package:cw_evm/file.dart';
|
import 'package:cw_core/encryption_file_utils.dart';
|
||||||
import 'package:cw_tron/tron_transaction_info.dart';
|
import 'package:cw_tron/tron_transaction_info.dart';
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
import 'package:cw_core/transaction_history.dart';
|
import 'package:cw_core/transaction_history.dart';
|
||||||
|
@ -14,7 +14,8 @@ class TronTransactionHistory = TronTransactionHistoryBase with _$TronTransaction
|
||||||
|
|
||||||
abstract class TronTransactionHistoryBase extends TransactionHistoryBase<TronTransactionInfo>
|
abstract class TronTransactionHistoryBase extends TransactionHistoryBase<TronTransactionInfo>
|
||||||
with Store {
|
with Store {
|
||||||
TronTransactionHistoryBase({required this.walletInfo, required String password})
|
TronTransactionHistoryBase(
|
||||||
|
{required this.walletInfo, required String password, required this.encryptionFileUtils})
|
||||||
: _password = password {
|
: _password = password {
|
||||||
transactions = ObservableMap<String, TronTransactionInfo>();
|
transactions = ObservableMap<String, TronTransactionInfo>();
|
||||||
}
|
}
|
||||||
|
@ -22,6 +23,7 @@ abstract class TronTransactionHistoryBase extends TransactionHistoryBase<TronTra
|
||||||
String _password;
|
String _password;
|
||||||
|
|
||||||
final WalletInfo walletInfo;
|
final WalletInfo walletInfo;
|
||||||
|
final EncryptionFileUtils encryptionFileUtils;
|
||||||
|
|
||||||
Future<void> init() async => await _load();
|
Future<void> init() async => await _load();
|
||||||
|
|
||||||
|
@ -33,7 +35,7 @@ abstract class TronTransactionHistoryBase extends TransactionHistoryBase<TronTra
|
||||||
String path = '$dirPath/$transactionsHistoryFileNameForWallet';
|
String path = '$dirPath/$transactionsHistoryFileNameForWallet';
|
||||||
final transactionMaps = transactions.map((key, value) => MapEntry(key, value.toJson()));
|
final transactionMaps = transactions.map((key, value) => MapEntry(key, value.toJson()));
|
||||||
final data = json.encode({'transactions': transactionMaps});
|
final data = json.encode({'transactions': transactionMaps});
|
||||||
await writeData(path: path, password: _password, data: data);
|
await encryptionFileUtils.write(path: path, password: _password, data: data);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
log('Error while saving ${walletInfo.type.name} transaction history: ${e.toString()}');
|
log('Error while saving ${walletInfo.type.name} transaction history: ${e.toString()}');
|
||||||
log(s.toString());
|
log(s.toString());
|
||||||
|
@ -51,7 +53,7 @@ abstract class TronTransactionHistoryBase extends TransactionHistoryBase<TronTra
|
||||||
String transactionsHistoryFileNameForWallet = 'tron_transactions.json';
|
String transactionsHistoryFileNameForWallet = 'tron_transactions.json';
|
||||||
final dirPath = await pathForWalletDir(name: walletInfo.name, type: walletInfo.type);
|
final dirPath = await pathForWalletDir(name: walletInfo.name, type: walletInfo.type);
|
||||||
String path = '$dirPath/$transactionsHistoryFileNameForWallet';
|
String path = '$dirPath/$transactionsHistoryFileNameForWallet';
|
||||||
final content = await read(path: path, password: _password);
|
final content = await encryptionFileUtils.read(path: path, password: _password);
|
||||||
if (content.isEmpty) {
|
if (content.isEmpty) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import 'package:bip39/bip39.dart' as bip39;
|
||||||
import 'package:blockchain_utils/blockchain_utils.dart';
|
import 'package:blockchain_utils/blockchain_utils.dart';
|
||||||
import 'package:cw_core/cake_hive.dart';
|
import 'package:cw_core/cake_hive.dart';
|
||||||
import 'package:cw_core/crypto_currency.dart';
|
import 'package:cw_core/crypto_currency.dart';
|
||||||
|
import 'package:cw_core/encryption_file_utils.dart';
|
||||||
import 'package:cw_core/node.dart';
|
import 'package:cw_core/node.dart';
|
||||||
import 'package:cw_core/pathForWallet.dart';
|
import 'package:cw_core/pathForWallet.dart';
|
||||||
import 'package:cw_core/pending_transaction.dart';
|
import 'package:cw_core/pending_transaction.dart';
|
||||||
|
@ -44,6 +45,7 @@ abstract class TronWalletBase
|
||||||
String? privateKey,
|
String? privateKey,
|
||||||
required String password,
|
required String password,
|
||||||
TronBalance? initialBalance,
|
TronBalance? initialBalance,
|
||||||
|
required this.encryptionFileUtils,
|
||||||
}) : syncStatus = const NotConnectedSyncStatus(),
|
}) : syncStatus = const NotConnectedSyncStatus(),
|
||||||
_password = password,
|
_password = password,
|
||||||
_mnemonic = mnemonic,
|
_mnemonic = mnemonic,
|
||||||
|
@ -55,7 +57,8 @@ abstract class TronWalletBase
|
||||||
),
|
),
|
||||||
super(walletInfo) {
|
super(walletInfo) {
|
||||||
this.walletInfo = walletInfo;
|
this.walletInfo = walletInfo;
|
||||||
transactionHistory = TronTransactionHistory(walletInfo: walletInfo, password: password);
|
transactionHistory = TronTransactionHistory(
|
||||||
|
walletInfo: walletInfo, password: password, encryptionFileUtils: encryptionFileUtils);
|
||||||
|
|
||||||
if (!CakeHive.isAdapterRegistered(TronToken.typeId)) {
|
if (!CakeHive.isAdapterRegistered(TronToken.typeId)) {
|
||||||
CakeHive.registerAdapter(TronTokenAdapter());
|
CakeHive.registerAdapter(TronTokenAdapter());
|
||||||
|
@ -65,6 +68,7 @@ abstract class TronWalletBase
|
||||||
final String? _mnemonic;
|
final String? _mnemonic;
|
||||||
final String? _hexPrivateKey;
|
final String? _hexPrivateKey;
|
||||||
final String _password;
|
final String _password;
|
||||||
|
final EncryptionFileUtils encryptionFileUtils;
|
||||||
|
|
||||||
late final Box<TronToken> tronTokensBox;
|
late final Box<TronToken> tronTokensBox;
|
||||||
|
|
||||||
|
@ -123,6 +127,7 @@ abstract class TronWalletBase
|
||||||
required String name,
|
required String name,
|
||||||
required String password,
|
required String password,
|
||||||
required WalletInfo walletInfo,
|
required WalletInfo walletInfo,
|
||||||
|
required EncryptionFileUtils encryptionFileUtils,
|
||||||
}) async {
|
}) async {
|
||||||
final path = await pathForWallet(name: name, type: walletInfo.type);
|
final path = await pathForWallet(name: name, type: walletInfo.type);
|
||||||
final jsonSource = await read(path: path, password: password);
|
final jsonSource = await read(path: path, password: password);
|
||||||
|
@ -137,6 +142,7 @@ abstract class TronWalletBase
|
||||||
mnemonic: mnemonic,
|
mnemonic: mnemonic,
|
||||||
privateKey: privateKey,
|
privateKey: privateKey,
|
||||||
initialBalance: balance,
|
initialBalance: balance,
|
||||||
|
encryptionFileUtils: encryptionFileUtils,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -563,4 +569,7 @@ abstract class TronWalletBase
|
||||||
_transactionsUpdateTimer?.cancel();
|
_transactionsUpdateTimer?.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get password => _password;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@ import 'package:cw_core/wallet_credentials.dart';
|
||||||
import 'package:cw_core/wallet_info.dart';
|
import 'package:cw_core/wallet_info.dart';
|
||||||
|
|
||||||
class TronNewWalletCredentials extends WalletCredentials {
|
class TronNewWalletCredentials extends WalletCredentials {
|
||||||
TronNewWalletCredentials({required String name, WalletInfo? walletInfo})
|
TronNewWalletCredentials({required String name, WalletInfo? walletInfo, String? password})
|
||||||
: super(name: name, walletInfo: walletInfo);
|
: super(name: name, walletInfo: walletInfo, password: password);
|
||||||
}
|
}
|
||||||
|
|
||||||
class TronRestoreWalletFromSeedCredentials extends WalletCredentials {
|
class TronRestoreWalletFromSeedCredentials extends WalletCredentials {
|
||||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:io';
|
||||||
|
|
||||||
import 'package:bip39/bip39.dart' as bip39;
|
import 'package:bip39/bip39.dart' as bip39;
|
||||||
import 'package:cw_core/balance.dart';
|
import 'package:cw_core/balance.dart';
|
||||||
|
import 'package:cw_core/encryption_file_utils.dart';
|
||||||
import 'package:cw_core/pathForWallet.dart';
|
import 'package:cw_core/pathForWallet.dart';
|
||||||
import 'package:cw_core/transaction_history.dart';
|
import 'package:cw_core/transaction_history.dart';
|
||||||
import 'package:cw_core/transaction_info.dart';
|
import 'package:cw_core/transaction_info.dart';
|
||||||
|
@ -21,11 +22,12 @@ class TronWalletService extends WalletService<
|
||||||
TronRestoreWalletFromSeedCredentials,
|
TronRestoreWalletFromSeedCredentials,
|
||||||
TronRestoreWalletFromPrivateKey,
|
TronRestoreWalletFromPrivateKey,
|
||||||
TronNewWalletCredentials> {
|
TronNewWalletCredentials> {
|
||||||
TronWalletService(this.walletInfoSource, {required this.client});
|
TronWalletService(this.walletInfoSource, {required this.client, required this.isDirect});
|
||||||
|
|
||||||
late TronClient client;
|
late TronClient client;
|
||||||
|
|
||||||
final Box<WalletInfo> walletInfoSource;
|
final Box<WalletInfo> walletInfoSource;
|
||||||
|
final bool isDirect;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
WalletType getType() => WalletType.tron;
|
WalletType getType() => WalletType.tron;
|
||||||
|
@ -43,6 +45,7 @@ class TronWalletService extends WalletService<
|
||||||
walletInfo: credentials.walletInfo!,
|
walletInfo: credentials.walletInfo!,
|
||||||
mnemonic: mnemonic,
|
mnemonic: mnemonic,
|
||||||
password: credentials.password!,
|
password: credentials.password!,
|
||||||
|
encryptionFileUtils: encryptionFileUtilsFor(isDirect),
|
||||||
);
|
);
|
||||||
|
|
||||||
await wallet.init();
|
await wallet.init();
|
||||||
|
@ -62,6 +65,7 @@ class TronWalletService extends WalletService<
|
||||||
name: name,
|
name: name,
|
||||||
password: password,
|
password: password,
|
||||||
walletInfo: walletInfo,
|
walletInfo: walletInfo,
|
||||||
|
encryptionFileUtils: encryptionFileUtilsFor(isDirect),
|
||||||
);
|
);
|
||||||
|
|
||||||
await wallet.init();
|
await wallet.init();
|
||||||
|
@ -75,6 +79,7 @@ class TronWalletService extends WalletService<
|
||||||
name: name,
|
name: name,
|
||||||
password: password,
|
password: password,
|
||||||
walletInfo: walletInfo,
|
walletInfo: walletInfo,
|
||||||
|
encryptionFileUtils: encryptionFileUtilsFor(isDirect),
|
||||||
);
|
);
|
||||||
|
|
||||||
await wallet.init();
|
await wallet.init();
|
||||||
|
@ -92,6 +97,7 @@ class TronWalletService extends WalletService<
|
||||||
password: credentials.password!,
|
password: credentials.password!,
|
||||||
privateKey: credentials.privateKey,
|
privateKey: credentials.privateKey,
|
||||||
walletInfo: credentials.walletInfo!,
|
walletInfo: credentials.walletInfo!,
|
||||||
|
encryptionFileUtils: encryptionFileUtilsFor(isDirect),
|
||||||
);
|
);
|
||||||
|
|
||||||
await wallet.init();
|
await wallet.init();
|
||||||
|
@ -114,6 +120,7 @@ class TronWalletService extends WalletService<
|
||||||
password: credentials.password!,
|
password: credentials.password!,
|
||||||
mnemonic: credentials.mnemonic,
|
mnemonic: credentials.mnemonic,
|
||||||
walletInfo: credentials.walletInfo!,
|
walletInfo: credentials.walletInfo!,
|
||||||
|
encryptionFileUtils: encryptionFileUtilsFor(isDirect),
|
||||||
);
|
);
|
||||||
|
|
||||||
await wallet.init();
|
await wallet.init();
|
||||||
|
@ -128,7 +135,11 @@ class TronWalletService extends WalletService<
|
||||||
final currentWalletInfo = walletInfoSource.values
|
final currentWalletInfo = walletInfoSource.values
|
||||||
.firstWhere((info) => info.id == WalletBase.idFor(currentName, getType()));
|
.firstWhere((info) => info.id == WalletBase.idFor(currentName, getType()));
|
||||||
final currentWallet = await TronWalletBase.open(
|
final currentWallet = await TronWalletBase.open(
|
||||||
password: password, name: currentName, walletInfo: currentWalletInfo);
|
password: password,
|
||||||
|
name: currentName,
|
||||||
|
walletInfo: currentWalletInfo,
|
||||||
|
encryptionFileUtils: encryptionFileUtilsFor(isDirect),
|
||||||
|
);
|
||||||
|
|
||||||
await currentWallet.renameWalletFiles(newName);
|
await currentWallet.renameWalletFiles(newName);
|
||||||
await saveBackup(newName);
|
await saveBackup(newName);
|
||||||
|
@ -153,7 +164,8 @@ class TronWalletService extends WalletService<
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo>> restoreFromHardwareWallet(TronNewWalletCredentials credentials) {
|
Future<WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo>>
|
||||||
|
restoreFromHardwareWallet(TronNewWalletCredentials credentials) {
|
||||||
// TODO: implement restoreFromHardwareWallet
|
// TODO: implement restoreFromHardwareWallet
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,15 +4,17 @@ class CWTron extends Tron {
|
||||||
@override
|
@override
|
||||||
List<String> getTronWordList(String language) => EVMChainMnemonics.englishWordlist;
|
List<String> getTronWordList(String language) => EVMChainMnemonics.englishWordlist;
|
||||||
|
|
||||||
WalletService createTronWalletService(Box<WalletInfo> walletInfoSource) =>
|
@override
|
||||||
TronWalletService(walletInfoSource, client: TronClient());
|
WalletService createTronWalletService(Box<WalletInfo> walletInfoSource, bool isDirect) =>
|
||||||
|
TronWalletService(walletInfoSource, client: TronClient(), isDirect: isDirect);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
WalletCredentials createTronNewWalletCredentials({
|
WalletCredentials createTronNewWalletCredentials({
|
||||||
required String name,
|
required String name,
|
||||||
WalletInfo? walletInfo,
|
WalletInfo? walletInfo,
|
||||||
|
String? password,
|
||||||
}) =>
|
}) =>
|
||||||
TronNewWalletCredentials(name: name, walletInfo: walletInfo);
|
TronNewWalletCredentials(name: name, walletInfo: walletInfo, password: password);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
WalletCredentials createTronRestoreWalletFromSeedCredentials({
|
WalletCredentials createTronRestoreWalletFromSeedCredentials({
|
||||||
|
|
Loading…
Reference in a new issue