fetchKeySavedStatus function
- dynamic context, [
- dynamic onKeyStatusChanged()?
This function verifies if an encryption key is available for the user by:
- Checking the encrypted key file in the POD
- Verifying if a key exists in local storage
If a key exists, it triggers a callback to update the UI.
Implementation
Future<bool> fetchKeySavedStatus(context,
[Function(bool)? onKeyStatusChanged]) async {
try {
// Get the path to the encrypted key file.
final filePath = await getEncKeyPath();
// Read the file content from the POD using the security key manager
final fileContent = await readPod(
filePath,
context,
SecurityKeyManager(
onKeyStatusChanged:
onKeyStatusChanged ?? (_) {}, // Callback to update key status.
),
);
// Check if the file content is valid.
bool hasLocalKey = ![
SolidFunctionCallStatus.notLoggedIn,
SolidFunctionCallStatus.fail
].contains(fileContent);
// Return true if the key is saved locally or in the POD.
return await KeyManager.hasSecurityKey() || hasLocalKey;
} catch (e) {
return false;
}
}