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;
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
Future<String> getWalletPassword({required String walletName}) async {
|
2020-07-06 20:09:03 +00:00
|
|
|
final key = generateStoreKeyFor(
|
|
|
|
key: SecretStoreKey.moneroWalletPassword, walletName: walletName);
|
|
|
|
final encodedPassword = await _secureStorage.read(key: key);
|
2022-10-12 17:09:57 +00:00
|
|
|
return decodeWalletPassword(password: encodedPassword!);
|
2020-07-06 20:09:03 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
Future<void> saveWalletPassword({required String walletName, required String password}) async {
|
2020-07-06 20:09:03 +00:00
|
|
|
final key = generateStoreKeyFor(
|
|
|
|
key: SecretStoreKey.moneroWalletPassword, walletName: walletName);
|
|
|
|
final encodedPassword = encodeWalletPassword(password: password);
|
|
|
|
|
|
|
|
await _secureStorage.write(key: key, value: encodedPassword);
|
|
|
|
}
|
2023-07-12 23:20:11 +00:00
|
|
|
|
|
|
|
Future<void> deleteWalletPassword({required String walletName}) async {
|
|
|
|
final key = generateStoreKeyFor(
|
|
|
|
key: SecretStoreKey.moneroWalletPassword, walletName: walletName);
|
|
|
|
|
|
|
|
await _secureStorage.delete(key: key);
|
|
|
|
}
|
2020-07-06 20:09:03 +00:00
|
|
|
}
|