2023-03-30 22:33:59 +00:00
|
|
|
import 'package:cake_wallet/core/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);
|
|
|
|
|
2023-03-30 22:33:59 +00:00
|
|
|
final SecureStorage _secureStorage;
|
2020-07-06 20:09:03 +00:00
|
|
|
|
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
|
|
|
}
|