CW-194 Fixes for import backups v1

This commit is contained in:
M 2022-10-18 11:38:54 -04:00
parent 4ff98d30a2
commit a0294a16b2

View file

@ -160,7 +160,7 @@ class BackupService {
} }
final data = final data =
json.decode(preferencesFile.readAsStringSync()) as Map<String, Object>; json.decode(preferencesFile.readAsStringSync()) as Map<String, dynamic>;
String currentWalletName = data[PreferencesKey.currentWalletName] as String; String currentWalletName = data[PreferencesKey.currentWalletName] as String;
int currentWalletType = data[PreferencesKey.currentWalletType] as int; int currentWalletType = data[PreferencesKey.currentWalletType] as int;
@ -173,43 +173,87 @@ class BackupService {
currentWalletType = serializeToInt(_correctWallets.first.type); currentWalletType = serializeToInt(_correctWallets.first.type);
} }
final currentNodeId = data[PreferencesKey.currentNodeIdKey] as int?;
final currentBalanceDisplayMode = data[PreferencesKey.currentBalanceDisplayModeKey] as int?;
final currentFiatCurrency = data[PreferencesKey.currentFiatCurrencyKey] as String?;
final shouldSaveRecipientAddress = data[PreferencesKey.shouldSaveRecipientAddressKey] as bool?;
final currentTransactionPriorityKeyLegacy = data[PreferencesKey.currentTransactionPriorityKeyLegacy] as int?;
final allowBiometricalAuthentication = data[PreferencesKey.allowBiometricalAuthenticationKey] as bool?;
final currentBitcoinElectrumSererId = data[PreferencesKey.currentBitcoinElectrumSererIdKey] as int?;
final currentLanguageCode = data[PreferencesKey.currentLanguageCode] as String?;
final displayActionListMode = data[PreferencesKey.displayActionListModeKey] as int?;
final currentPinLength = data[PreferencesKey.currentPinLength] as int?;
final currentTheme = data[PreferencesKey.currentTheme] as int?;
final currentDefaultSettingsMigrationVersion = data[PreferencesKey.currentDefaultSettingsMigrationVersion] as int?;
final moneroTransactionPriority = data[PreferencesKey.moneroTransactionPriority] as int?;
final bitcoinTransactionPriority = data[PreferencesKey.bitcoinTransactionPriority] as int?;
await _sharedPreferences.setString(PreferencesKey.currentWalletName, await _sharedPreferences.setString(PreferencesKey.currentWalletName,
currentWalletName); currentWalletName);
await _sharedPreferences.setInt(PreferencesKey.currentNodeIdKey,
data[PreferencesKey.currentNodeIdKey] as int); if (currentNodeId != null)
await _sharedPreferences.setInt(PreferencesKey.currentBalanceDisplayModeKey, await _sharedPreferences.setInt(PreferencesKey.currentNodeIdKey,
data[PreferencesKey.currentBalanceDisplayModeKey] as int); currentNodeId);
if (currentBalanceDisplayMode != null)
await _sharedPreferences.setInt(PreferencesKey.currentBalanceDisplayModeKey,
currentBalanceDisplayMode);
await _sharedPreferences.setInt(PreferencesKey.currentWalletType, await _sharedPreferences.setInt(PreferencesKey.currentWalletType,
currentWalletType); currentWalletType);
await _sharedPreferences.setString(PreferencesKey.currentFiatCurrencyKey,
data[PreferencesKey.currentFiatCurrencyKey] as String); if (currentFiatCurrency != null)
await _sharedPreferences.setBool( await _sharedPreferences.setString(PreferencesKey.currentFiatCurrencyKey,
currentFiatCurrency);
if (shouldSaveRecipientAddress != null)
await _sharedPreferences.setBool(
PreferencesKey.shouldSaveRecipientAddressKey, PreferencesKey.shouldSaveRecipientAddressKey,
data[PreferencesKey.shouldSaveRecipientAddressKey] as bool); shouldSaveRecipientAddress);
await _sharedPreferences.setInt(
if (currentTransactionPriorityKeyLegacy != null)
await _sharedPreferences.setInt(
PreferencesKey.currentTransactionPriorityKeyLegacy, PreferencesKey.currentTransactionPriorityKeyLegacy,
data[PreferencesKey.currentTransactionPriorityKeyLegacy] as int); currentTransactionPriorityKeyLegacy);
await _sharedPreferences.setBool(
if (allowBiometricalAuthentication != null)
await _sharedPreferences.setBool(
PreferencesKey.allowBiometricalAuthenticationKey, PreferencesKey.allowBiometricalAuthenticationKey,
data[PreferencesKey.allowBiometricalAuthenticationKey] as bool); allowBiometricalAuthentication);
await _sharedPreferences.setInt(
if (currentBitcoinElectrumSererId != null)
await _sharedPreferences.setInt(
PreferencesKey.currentBitcoinElectrumSererIdKey, PreferencesKey.currentBitcoinElectrumSererIdKey,
data[PreferencesKey.currentBitcoinElectrumSererIdKey] as int); currentBitcoinElectrumSererId);
await _sharedPreferences.setString(PreferencesKey.currentLanguageCode,
data[PreferencesKey.currentLanguageCode] as String); if (currentLanguageCode != null)
await _sharedPreferences.setInt(PreferencesKey.displayActionListModeKey, await _sharedPreferences.setString(PreferencesKey.currentLanguageCode,
data[PreferencesKey.displayActionListModeKey] as int); currentLanguageCode);
await _sharedPreferences.setInt(PreferencesKey.currentPinLength,
data[PreferencesKey.currentPinLength] as int); if (displayActionListMode != null)
await _sharedPreferences.setInt( await _sharedPreferences.setInt(PreferencesKey.displayActionListModeKey,
PreferencesKey.currentTheme, data[PreferencesKey.currentTheme] as int); displayActionListMode);
await _sharedPreferences.setInt(
if (currentPinLength != null)
await _sharedPreferences.setInt(PreferencesKey.currentPinLength,
currentPinLength);
if (currentTheme != null)
await _sharedPreferences.setInt(
PreferencesKey.currentTheme, currentTheme);
if (currentDefaultSettingsMigrationVersion != null)
await _sharedPreferences.setInt(
PreferencesKey.currentDefaultSettingsMigrationVersion, PreferencesKey.currentDefaultSettingsMigrationVersion,
data[PreferencesKey.currentDefaultSettingsMigrationVersion] as int); currentDefaultSettingsMigrationVersion);
await _sharedPreferences.setInt(PreferencesKey.moneroTransactionPriority,
data[PreferencesKey.moneroTransactionPriority] as int); if (moneroTransactionPriority != null)
await _sharedPreferences.setInt(PreferencesKey.bitcoinTransactionPriority, await _sharedPreferences.setInt(PreferencesKey.moneroTransactionPriority,
data[PreferencesKey.bitcoinTransactionPriority] as int); moneroTransactionPriority);
if (bitcoinTransactionPriority != null)
await _sharedPreferences.setInt(PreferencesKey.bitcoinTransactionPriority,
bitcoinTransactionPriority);
await preferencesFile.delete(); await preferencesFile.delete();
} }
@ -283,7 +327,7 @@ class BackupService {
Future<String> _exportPreferencesJSON() async { Future<String> _exportPreferencesJSON() async {
// FIX-ME: Force unwrap // FIX-ME: Force unwrap
final preferences = <String, Object>{ final preferences = <String, dynamic>{
PreferencesKey.currentWalletName: PreferencesKey.currentWalletName:
_sharedPreferences.getString(PreferencesKey.currentWalletName)!, _sharedPreferences.getString(PreferencesKey.currentWalletName)!,
PreferencesKey.currentNodeIdKey: PreferencesKey.currentNodeIdKey:
@ -340,18 +384,15 @@ class BackupService {
} }
Future<Uint8List> _decrypt( Future<Uint8List> _decrypt(
Uint8List data, String secretKeySource, String nonceBase64) async { Uint8List data, String secretKeySource, String nonceBase64, {int macLength = 16}) async {
throw Exception('Unimplemented'); final secretKeyHash = await Cryptography.instance.sha256().hash(utf8.encode(secretKeySource));
//final secretKeyHash = await sha256.hash(utf8.encode(secretKeySource)); final secretKey = SecretKey(secretKeyHash.bytes);
//final secretKey = SecretKey(secretKeyHash.bytes); final nonce = base64.decode(nonceBase64).toList();
//final nonce = Nonce(base64.decode(nonceBase64)); final box = SecretBox(
//return await _cipher.decrypt(data, secretKey: secretKey, nonce: nonce); Uint8List.sublistView(data, 0, data.lengthInBytes - macLength).toList(),
nonce: nonce,
// final secretKeyHash = await Cryptography.instance.sha256().hash(utf8.encode(secretKeySource)); mac: Mac(Uint8List.sublistView(data, data.lengthInBytes - macLength)));
// final secretKey = SecretKey(secretKeyHash.bytes); final plainData = await _cipher.decrypt(box, secretKey: secretKey);
// final nonce = base64.decode(nonceBase64).toList(); return Uint8List.fromList(plainData);
// final box = SecretBox(data.toList(), nonce: nonce, mac: Mac);
// final plainData = await _cipher.decrypt(box, secretKey: secretKey);
// return Uint8List.fromList(plainData);
} }
} }