OZCredentialManager

Manages the lifecycle of smart account credentials.

OZCredentialManager provides operations for creating, querying, updating, and deleting stored credentials. It handles credential deployment state transitions and ensures data integrity through validation and error handling.

Credential State Machine:

pending --[deploy success]--> credential DELETED from storage
pending --[deploy failure]--> failed (deploymentError set)
pending --[sync discovers contract on-chain]--> credential DELETED from storage
failed --[deleteCredential]--> credential DELETED from storage

After successful deployment (or sync discovery), credentials are deleted from storage. Reconnection works via sessions or the indexer. Failed deployments can be retried by deleting the credential and creating a new one.

Thread Safety: All operations delegate to the StorageAdapter, which is responsible for thread-safety.

Example usage:

val manager = kit.credentialManager

// Get all credentials
val all = manager.getAllCredentials()

// Get pending and failed credentials
val pending = manager.getPendingCredentials()

// Sync a credential with on-chain state (deletes if deployed)
val isDeployed = manager.sync(credentialId = "base64url-id")

// Delete a pending credential
manager.deleteCredential(credentialId = "base64url-id")

Functions

Link copied to clipboard
suspend fun clearAll()

Clears all credentials from storage.

Link copied to clipboard
suspend fun createPendingCredential(credentialId: String, publicKey: ByteArray, contractId: String, nickname: String? = null, transports: List<String>? = null, deviceType: String? = null, backedUp: Boolean? = null): StoredCredential

Creates a new pending credential in storage.

Link copied to clipboard
suspend fun deleteCredential(credentialId: String)

Deletes a pending credential from storage.

Link copied to clipboard

Retrieves all stored credentials.

Link copied to clipboard
suspend fun getCredential(credentialId: String): StoredCredential?

Retrieves a credential by its ID.

Link copied to clipboard

Retrieves all credentials associated with a specific contract.

Link copied to clipboard

Retrieves credentials for the currently connected wallet.

Link copied to clipboard

Retrieves credentials that are pending deployment or have failed deployment.

Link copied to clipboard
suspend fun saveCredential(credentialId: String, publicKey: ByteArray, nickname: String? = null, contractId: String? = null): StoredCredential

Saves a credential to storage.

Link copied to clipboard
suspend fun sync(credentialId: String): Boolean

Syncs a credential with on-chain state.

Link copied to clipboard
suspend fun syncAll(): SyncResult

Syncs all stored credentials with on-chain state.

Link copied to clipboard
suspend fun updateNickname(credentialId: String, nickname: String?)

Updates the nickname of a credential.