authenticate

open suspend override fun authenticate(context: Context): Result<Pair<PrivateKey, BiometricPrompt.CryptoObject?>>

Authenticates the device by retrieving the stored private key.

This method attempts to authenticate in the following order:

  1. If a cached key pair exists (from recent registration), uses it directly

  2. Otherwise, prompts for PIN and retrieves private key from storage

  3. Implements retry mechanism with configurable attempts

  4. Clears cached key pair after use for security

The method handles various error conditions including:

  • User cancellation during PIN entry

  • Invalid PIN attempts with retry logic

  • Missing or corrupted keystore data

  • File system errors

Return

Result containing Pair of PrivateKey and null BiometricPrompt.CryptoObject on success, or failure with appropriate exception

Parameters

context

Android context for any UI operations (not used in PIN auth)

See also