cake_wallet/lib/core/key_service.dart

49 lines
1.9 KiB
Dart
Raw Normal View History

2020-07-06 20:09:03 +00:00
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
2020-09-21 11:50:26 +00:00
import 'package:cake_wallet/entities/secret_store_key.dart';
import 'package:cake_wallet/entities/encrypt.dart';
2020-07-06 20:09:03 +00:00
class KeyService {
KeyService(this._secureStorage);
final FlutterSecureStorage _secureStorage;
2023-12-15 19:01:37 +00:00
Future<String> getWalletPasswordV2({required String walletName}) async {
final key =
generateStoreKeyFor(key: SecretStoreKey.moneroWalletPassword, walletName: walletName);
2020-07-06 20:09:03 +00:00
final encodedPassword = await _secureStorage.read(key: key);
2023-12-15 19:01:37 +00:00
return decodeWalletPasswordV2(password: encodedPassword!);
2020-07-06 20:09:03 +00:00
}
2023-12-15 19:01:37 +00:00
Future<void> saveWalletPasswordV2({required String walletName, required String password}) async {
final key =
generateStoreKeyFor(key: SecretStoreKey.moneroWalletPassword, walletName: walletName);
final encodedPassword = await encodeWalletPasswordV2(password: password);
await _secureStorage.delete(key: key);
await _secureStorage.write(key: key, value: encodedPassword);
}
Future<String> getWalletPasswordV1({required String walletName}) async {
final key =
generateStoreKeyFor(key: SecretStoreKey.moneroWalletPassword, walletName: walletName);
final encodedPassword = await _secureStorage.read(key: key);
return decodeWalletPasswordV1(password: encodedPassword!);
}
Future<void> saveWalletPasswordV1({required String walletName, required String password}) async {
final key =
generateStoreKeyFor(key: SecretStoreKey.moneroWalletPassword, walletName: walletName);
final encodedPassword = encodeWalletPasswordV1(password: password);
2020-07-06 20:09:03 +00:00
await _secureStorage.delete(key: key);
2020-07-06 20:09:03 +00:00
await _secureStorage.write(key: key, value: encodedPassword);
}
2023-07-12 23:20:11 +00:00
Future<void> deleteWalletPassword({required String walletName}) async {
2023-12-15 19:01:37 +00:00
final key =
generateStoreKeyFor(key: SecretStoreKey.moneroWalletPassword, walletName: walletName);
2023-07-12 23:20:11 +00:00
await _secureStorage.delete(key: key);
}
2020-07-06 20:09:03 +00:00
}