cake_wallet/lib/core/key_service.dart
Adegoke David 6ae0f37b9c
CW-597-AuthService-Bug (#1346)
* fix: AuthService keychain bug fix

* fix: Fetch read implementation

* fix: Simplify logic for retries

* Minor enhancement

---------

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2024-03-26 12:37:52 +02:00

33 lines
1.3 KiB
Dart

import 'package:cake_wallet/core/secure_storage.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:cake_wallet/entities/secret_store_key.dart';
import 'package:cake_wallet/entities/encrypt.dart';
class KeyService {
KeyService(this._secureStorage);
final FlutterSecureStorage _secureStorage;
Future<String> getWalletPassword({required String walletName}) async {
final key = generateStoreKeyFor(
key: SecretStoreKey.moneroWalletPassword, walletName: walletName);
final encodedPassword = await readSecureStorage(_secureStorage, key);
return decodeWalletPassword(password: encodedPassword!);
}
Future<void> saveWalletPassword({required String walletName, required String password}) async {
final key = generateStoreKeyFor(
key: SecretStoreKey.moneroWalletPassword, walletName: walletName);
final encodedPassword = encodeWalletPassword(password: password);
await _secureStorage.delete(key: key);
await _secureStorage.write(key: key, value: encodedPassword);
}
Future<void> deleteWalletPassword({required String walletName}) async {
final key = generateStoreKeyFor(
key: SecretStoreKey.moneroWalletPassword, walletName: walletName);
await _secureStorage.delete(key: key);
}
}