This commit is contained in:
M 2020-06-20 10:10:00 +03:00
parent 719842964b
commit 81cee186db
94 changed files with 3786 additions and 3001 deletions

View file

@ -1,21 +1,41 @@
import 'package:flutter/foundation.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/core/setup_pin_code_state.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:cake_wallet/src/domain/common/secret_store_key.dart';
import 'package:cake_wallet/src/domain/common/encrypt.dart';
part 'auth_service.g.dart';
class AuthService with Store {
AuthService({this.secureStorage, this.sharedPreferences});
class AuthService = AuthServiceBase with _$AuthService;
final FlutterSecureStorage secureStorage;
final SharedPreferences sharedPreferences;
abstract class AuthServiceBase with Store {
@observable
SetupPinCodeState setupPinCodeState;
Future<void> setupPinCode({@required String pin}) async {}
Future<bool> authenticate({@required String pin}) async {
return false;
Future setPassword(String password) async {
final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
final encodedPassword = encodedPinCode(pin: password);
await secureStorage.write(key: key, value: encodedPassword);
}
void resetSetupPinCodeState() =>
setupPinCodeState = InitialSetupPinCodeState();
Future<bool> canAuthenticate() async {
final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
final walletName = sharedPreferences.getString('current_wallet_name') ?? '';
var password = '';
try {
password = await secureStorage.read(key: key);
} catch (e) {
print(e);
}
return walletName.isNotEmpty && password.isNotEmpty;
}
Future<bool> authenticate(String pin) async {
final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
final encodedPin = await secureStorage.read(key: key);
final decodedPin = decodedPinCode(pin: encodedPin);
return decodedPin == pin;
}
}