fetchKeySavedStatus function

Future<bool> fetchKeySavedStatus(
  1. dynamic context, [
  2. dynamic onKeyStatusChanged(
    1. bool
    )?
])

This function verifies if an encryption key is available for the user by:

  1. Checking the encrypted key file in the POD
  2. 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;
  }
}