Fix restore from backup using 6 digit-pin

Godwin Asuquo committed Nov 24, 2022 at 16:34 UTC 7874009854a53fdbd8db3f099e826b27d6f725db
2 files changed +8 -2
lib/core/backup_service.dart
+5 -1
@@ -1,6 +1,7 @@
1 import 'dart:convert';
2 import 'dart:io';
3 import 'dart:typed_data';
4 +import 'package:cake_wallet/store/settings_store.dart';
5 import 'package:cw_core/wallet_type.dart';
6 import 'package:flutter/foundation.dart';
7 import 'package:hive/hive.dart';
@@ -20,7 +21,7 @@ import 'package:cake_backup/backup.dart' as cake_backup;
21
22 class BackupService {
23 BackupService(this._flutterSecureStorage, this._walletInfoSource,
23 - this._keyService, this._sharedPreferences)
24 + this._keyService, this._sharedPreferences, this._settingsStore)
25 : _cipher = Cryptography.instance.chacha20Poly1305Aead(),
26 _correctWallets = <WalletInfo>[];
27
@@ -33,6 +34,7 @@ class BackupService {
34 final FlutterSecureStorage _flutterSecureStorage;
35 final SharedPreferences _sharedPreferences;
36 final Box<WalletInfo> _walletInfoSource;
37 + final SettingsStore _settingsStore;
38 final KeyService _keyService;
39 List<WalletInfo> _correctWallets;
40
@@ -301,6 +303,7 @@ class BackupService {
303 as Map<String, dynamic>;
304 final keychainWalletsInfo = keychainJSON['wallets'] as List;
305 final decodedPin = keychainJSON['pin'] as String;
306 + _settingsStore.pinCodeLength = decodedPin.length;
307 final pinCodeKey = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
308 final backupPasswordKey =
309 generateStoreKeyFor(key: SecretStoreKey.backupPassword);
@@ -331,6 +334,7 @@ class BackupService {
334 final keychainWalletsInfo = keychainJSON['wallets'] as List;
335 final decodedPin = keychainJSON['pin'] as String;
336 final pinCodeKey = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
337 + _settingsStore.pinCodeLength = decodedPin.length;
338 final backupPasswordKey =
339 generateStoreKeyFor(key: SecretStoreKey.backupPassword);
340 final backupPassword = keychainJSON[backupPasswordKey] as String;
lib/di.dart
+3 -1
@@ -586,7 +586,9 @@ Future setup(
586 getIt.get<FlutterSecureStorage>(),
587 _walletInfoSource,
588 getIt.get<KeyService>(),
589 - getIt.get<SharedPreferences>()));
589 + getIt.get<SharedPreferences>(),
590 + getIt.get<SettingsStore>(),
591 + ));
592
593 getIt.registerFactory(() => BackupViewModel(getIt.get<FlutterSecureStorage>(),
594 getIt.get<SecretStore>(), getIt.get<BackupService>()));