FakeAuthenticator

class FakeAuthenticator(val origin: String, random: Random = Random.Default)

In-memory platform authenticator producing cryptographically valid WebAuthn responses (ES256, attestation "none"), so they pass real server verifiers.

Like a platform authenticator it checks the options' RP ID against origin: an http(s) origin's host must equal the RP ID or be a subdomain of it (otherwise PasskeyError.Misconfigured); for other origins (e.g. Android android:apk-key-hash:...) the options must name the RP ID explicitly (otherwise PasskeyError.InvalidOptions).

Safe to call from concurrent coroutines: every operation runs under one lock.

Extensions: prf and largeBlob are supported (toggle with prfSupported / largeBlobSupported); outputs appear in clientExtensionResults as on real platforms. PRF is deterministic and test-only: HMAC-SHA256(secret, SHA-256("WebAuthn PRF" || 0x00 || salt)), mirroring the WebAuthn salt hashing, where secret is derived from the credential id (so it is predictable; never use this as real key material). The same passkey and salt always give the same 32 bytes; different salts or passkeys give different ones. Large blobs are kept in memory per passkey (FakeCredential.largeBlob).

Constructors

Link copied to clipboard
constructor(origin: String, random: Random = Random.Default)

Properties

Link copied to clipboard

Whether new passkeys can get large-blob storage. When false, registration reports largeBlob.supported = false, or fails with PasskeyError.NotSupported if support is required. Default true. Set from test code, not concurrently with operations.

Link copied to clipboard

the web origin written into clientDataJSON, e.g. https://example.com.

Link copied to clipboard

Whether the prf extension is supported. When false, registration reports prf.enabled = false and sign-in returns no PRF results. Default true. Set from test code, not concurrently with operations.

Link copied to clipboard

Snapshot of the passkeys currently stored, oldest first.

Functions

Link copied to clipboard
suspend fun register(optionsJson: String, conditional: Boolean = false): String

Creates a passkey for creation options optionsJson and returns RegistrationResponseJSON. An existing passkey for the same RP ID and user.id is replaced, as platform providers do.

Link copied to clipboard
suspend fun remove(rpId: String, credentialId: String)

Deletes the passkey with base64url credentialId on rpId, if stored. Ids are compared by their bytes (padding and standard-alphabet ids match). Throws PasskeyException with PasskeyError.InvalidOptions for an undecodable id.

Link copied to clipboard
suspend fun retainOnly(rpId: String, userHandle: String, credentialIds: List<String>)

Deletes every passkey of userHandle on rpId whose id is not in credentialIds. Ids are compared by their bytes. Throws PasskeyException with PasskeyError.InvalidOptions for an undecodable id.

Link copied to clipboard
suspend fun signIn(optionsJson: String): String

Signs request options optionsJson with the most recent matching passkey and returns AuthenticationResponseJSON. Throws PasskeyException with PasskeyError.NoCredentials if none matches, PasskeyError.InvalidOptions for malformed options, or PasskeyError.Misconfigured if the RP ID does not match origin.