CredLinkCryptoHandler

Platform-native CredLink cryptography and key material handling. Android uses Keystore + BouncyCastle; iOS uses CryptoKit + Keychain via Swift adapters.

Implementations produce PKOC wire payloads only; CredLinkExchangeStateMachine performs GATT writes.

Functions

Link copied to clipboard

PKOC step B (phone side): generates a fresh P-256 ephemeral key pair, stores it, and returns the bridge ephemeral public key write payload (TLV tag 0x07).

abstract suspend fun buildLegacyEncryptedAuthenticationPayload(device: CredLinkDevice, lockSignature: ByteArray, isTimeSync: Boolean, trueTimeManager: ITrueTimeManager): ByteArray?

PKOC step C (phone side): verifies the lock signature, signs the authentication message, and returns the AES-GCM encrypted write payload (IV + ciphertext TLVs).

Link copied to clipboard
abstract suspend fun buildLegacyExchangeInitiatorPayload(phoneKeysAlias: String, operationType: BlueLinkOperationType): ByteArray?

Builds Legacy credential exchange step-A initiator TLVs: long-term public key (tag 0x01) and time-sync flag (tag 0x09).

Link copied to clipboard
abstract suspend fun buildPresentationInitiationPayload(device: CredLinkDevice, phoneKeysAlias: String): ByteArray?

First step for Token Unlock flow. This function initiates the Function builds the token-unlock Initiation payload using the keypair persisted in secure enclave linked to the provided phoneKeyAlias. Function also generates transaction ephemeral keys and persists that in session memory for use

Link copied to clipboard
abstract suspend fun buildPresentationPresentPayload(device: CredLinkDevice, challengeBytes: ByteArray, tokenUnlockPass: TokenUnlockPass): ByteArray?

Using the TokenUnlockPass, function fetches the access documents for the reader's reader group identifier and builds the encrypted PresentationPresent payload and sends it to the device. Note: Function uses the ephemeral keys as the secure credentials for encryption.

Link copied to clipboard
abstract fun clearAllDevices()
Link copied to clipboard
abstract fun clearDevice(deviceId: UInt)
Link copied to clipboard
open suspend fun deleteLongTermKeyPair(phoneKeysAlias: String): Boolean
Link copied to clipboard
abstract suspend fun deleteTokenUnlockPass(phoneKeysAlias: String): Boolean

Deletes the persisted token unlock pass persisted at the provided phoneKeyAlias in the bridge's secure enclave, returning a boolean value indicating success

Link copied to clipboard
abstract fun extractWirePublicKey(encodedPublicKey: ByteArray): ByteArray
Link copied to clipboard
abstract suspend fun fetchTokenUnlockPass(phoneKeysAlias: String): TokenUnlockPass?

Fetches the persisted Token Unlock pass persisted at the provided phoneKeyAlias in the bridge's secure enclave. Null is returned if no pass is found for the provided phoneKeyAlias Note: Secure access document data is decrypted after fetching

Link copied to clipboard
abstract suspend fun generateLongTermKeyPair(): Pair<ByteArray, ByteArray>?
Link copied to clipboard
abstract suspend fun getPrivateKeyEncoded(phoneKeysAlias: String): ByteArray?
Link copied to clipboard
abstract suspend fun getPublicKeyEncoded(phoneKeysAlias: String): ByteArray?
Link copied to clipboard
open suspend fun hasLongTermPrivateKey(phoneKeysAlias: String): Boolean

True when a long-term private key is present for phoneKeysAlias (may not be exportable).

Link copied to clipboard
abstract fun onDeviceEphemeralKeyReceived(device: CredLinkDevice, ephemeralKeyBytes: ByteArray)

PKOC step A (phone side): handler for processing device's ephemeral key bytes

Link copied to clipboard

Accepts the encrypted PresentationPayload from the device and decrypts it using the transaction ephemeral keys to get the Token Unlock credential exchange response. Note: Incomplete results are treated as access denied responses.

Link copied to clipboard
abstract fun publicKeyToHex(wirePublicKey: ByteArray): String
Link copied to clipboard
abstract suspend fun purgeExpiredTokenUnlockPasses(aliasPrefix: String, nowEpochSeconds: Long): Int
Link copied to clipboard
abstract suspend fun registerDevice(device: CredLinkDevice, phoneKeysAlias: String): Boolean

Shared Crypto Functions

Link copied to clipboard
abstract suspend fun saveLongTermKeyPair(phoneKeysAlias: String, publicKey: ByteArray, privateKey: ByteArray): Boolean
Link copied to clipboard
abstract suspend fun storeTokenUnlockPass(phoneKeysAlias: String, pass: TokenUnlockPass): Boolean

Accepts the secure Token Unlock pass and persists this in the bridge's secure enclave under the provided phoneKeyAlias and returns a boolean value indicating success persisting the pass. Note: Secure access document data is encrypted before storing for security reasons

abstract fun tokenUnlockVerifyAndExtractReaderPublicKey(readerCertificate: ByteArray, readerGroupIdentifier: ByteArray, readerGroupSubIdentifier: ByteArray, tokenUnlockPass: TokenUnlockPass): ByteArray?

Verifies the lock's provided reader certificate for the requested reader group and returns the P-256 uncompressed public key for the reader cert. Function also accepts reader group data via TokenUnlockPass. Function returns null if trust cannot be verified with the device / if the reader groups list does not contain device's reader group identifier.