OZCredentialManager
public final class OZCredentialManager : OZCredentialManagerProtocol, @unchecked Sendable
Manages the lifecycle of stored Smart Account credentials.
OZCredentialManager provides operations for creating, querying, updating,
and deleting stored credentials, and for reconciling local credential state
with on-chain deployment status. The manager is the only supported entry
point for the application-visible side of credential storage; lower-level
access goes through the underlying OZStorageAdapter.
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 removed from local storage. Reconnection works through sessions or the indexer. Failed deployments can be retried by deleting the credential and creating a new one with the same identifier.
Usage
let manager = kit.credentialManager
// Get all credentials.
let all = try await manager.getAllCredentials()
// Get pending and failed credentials.
let pending = try await manager.getPendingCredentials()
// Sync a credential with on-chain state (deletes if deployed).
let isDeployed = try await manager.sync(credentialId: "base64url-id")
// Delete a pending credential.
try await manager.deleteCredential(credentialId: "base64url-id")
-
createPendingCredential(credentialId:AsynchronouspublicKey: contractId: nickname: transports: deviceType: backedUp: ) Creates a new pending credential and persists it to storage.
The credential is created with deployment status
pending,isPrimaryset tofalse(the wallet-creation flow is responsible for promoting a credential to primary), andcreatedAtset to the current wall-clock time in milliseconds since the Unix epoch.Validation
publicKeymust be exactlysecp256r1PublicKeySizebytes (uncompressed secp256r1).credentialIdmust not be empty.credentialIdmust be unique (no existing credential may share the identifier).
Throws
Throws:
InvalidInputwhen validation fails.AlreadyExistswhen a credential with the same identifier already exists.WriteFailedwhen persistence fails.
Declaration
Swift
public func createPendingCredential( credentialId: String, publicKey: Data, contractId: String, nickname: String? = nil, transports: [String]? = nil, deviceType: String? = nil, backedUp: Bool? = nil ) async throws -> OZStoredCredentialParameters
credentialIdBase64URL-encoded credential identifier (must be unique and non-empty).
publicKeyUncompressed secp256r1 public key (
secp256r1PublicKeySizebytes).contractIdSmart account contract address (
C…strkey).nicknameOptional user-friendly display name.
transportsOptional WebAuthn transport hints (e.g.
"usb","nfc","ble","internal").deviceTypeOptional authenticator device type (
"singleDevice"or"multiDevice").backedUpOptional flag indicating whether the passkey is backed up or synced.
Return Value
The persisted
OZStoredCredential. -
Saves a credential directly to storage with looser validation than
createPendingCredential(credentialId:publicKey:contractId:nickname:transports:deviceType:backedUp:).Unlike the create path this method does not check for duplicates, does not capture deployment-time WebAuthn metadata (
transports,deviceType,backedUp), and persistsisPrimary = false. AnilcontractIdis stored as the empty string to mirror the on-chain “not yet derived” sentinel used by other call sites.Validation
credentialIdmust not be empty.publicKeymust be exactlysecp256r1PublicKeySizebytes.
Declaration
Swift
public func saveCredential( credentialId: String, publicKey: Data, nickname: String? = nil, contractId: String? = nil ) async throws -> OZStoredCredentialParameters
credentialIdBase64URL-encoded credential identifier.
publicKeyUncompressed secp256r1 public key (
secp256r1PublicKeySizebytes).nicknameOptional user-friendly display name.
contractIdOptional smart account contract address.
nilis stored as the empty string.Return Value
The persisted
OZStoredCredential.
-
sync(credentialId:Asynchronous) Synchronises a single credential with on-chain contract state.
Queries the contract instance for the credential’s
contractIdvia Soroban RPC. When the contract instance exists the credential is removed from local storage (deployment is confirmed) and the method returnstrue. When the contract instance does not exist, when the credential has no associatedcontractId, or when the on-chain check fails for any reason (transport error, parse error, RPC error), the method returnsfalsewithout throwing.The on-chain check intentionally swallows errors: a pending-credentials sweep needs a binary answer, not a failure mode. The credential remains in storage in any non-deployed outcome.
Throws
NotFoundwhen no credential with the supplied identifier exists in storage.ReadFailedwhen reading the credential fails.
Declaration
Swift
@discardableResult public func sync(credentialId: String) async throws -> BoolParameters
credentialIdIdentifier of the credential to sync.
Return Value
truewhen the contract is deployed and the credential was removed from local storage, otherwisefalse. -
syncAll()AsynchronousSynchronises every stored credential with on-chain contract state.
Iterates the full credential set, invoking
sync(credentialId:)for each entry. Deployed credentials are removed from storage (and counted asdeployed); failed credentials are counted asfailed; everything else is counted aspending.Throws
ReadFailedwhen reading the credential set fails.Declaration
Swift
public func syncAll() async throws -> OZSyncResultReturn Value
An
OZSyncResultsummarising the deployment status counts.
-
deleteCredential(credentialId:Asynchronous) Deletes a pending credential from storage.
Before deletion the manager runs
sync(credentialId:)to confirm the contract has not been deployed on-chain. When the contract is already deployed the sync removes the credential and the deletion is rejected withInvalidbecause the wallet exists on-chain and the local entry is no longer authoritative.On successful deletion the manager emits a
credentialDeleted(credentialId:)event.Throws
NotFoundwhen no credential with the supplied identifier exists in storage.Invalidwhen the credential is already deployed on-chain.ReadFailedwhen reading the credential fails.WriteFailedwhen deletion fails.
Declaration
Swift
public func deleteCredential(credentialId: String) async throwsParameters
credentialIdIdentifier of the credential to delete.
-
getCredential(credentialId:Asynchronous) Retrieves a stored credential by its identifier.
Throws
ReadFailedwhen reading fails.Declaration
Swift
public func getCredential(credentialId: String) async throws -> OZStoredCredential?Parameters
credentialIdIdentifier of the credential to look up.
Return Value
The
OZStoredCredentialwhen present, otherwisenil. -
getCredentialsByContract(contractId:Asynchronous) Retrieves every credential associated with the supplied contract address.
Throws
ReadFailedwhen reading fails.Declaration
Swift
public func getCredentialsByContract(contractId: String) async throws -> [OZStoredCredential]Parameters
contractIdContract address to filter by.
Return Value
Credentials whose
contractIdmatches; empty when none match. -
getAllCredentials()AsynchronousRetrieves every stored credential, regardless of deployment status or associated contract.
Throws
ReadFailedwhen reading fails.Declaration
Swift
public func getAllCredentials() async throws -> [OZStoredCredential]Return Value
All stored credentials (empty when no credentials exist).
-
getForConnectedWallet()AsynchronousRetrieves every credential associated with the kit’s currently connected wallet.
Returns an empty list when no wallet is connected. The connected contract is queried through the kit’s
contractIdaccessor; concrete kits expose this through the Smart Account Kit’s connected-state API.Throws
ReadFailedwhen reading fails.Declaration
Swift
public func getForConnectedWallet() async throws -> [OZStoredCredential]Return Value
Credentials whose
contractIdmatches the connected wallet’s contract address (empty when not connected or when no credentials match). -
getPendingCredentials()AsynchronousRetrieves every credential whose deployment status is pending or failed.
Returned credentials have not been confirmed on-chain and may need attention (retry, sync, or delete).
Throws
ReadFailedwhen reading fails.Declaration
Swift
public func getPendingCredentials() async throws -> [OZStoredCredential]Return Value
Credentials with status
.pendingor.failed(empty when none match).
-
updateNickname(credentialId:Asynchronousnickname: ) Updates the nickname of a stored credential.
Overwrites the nickname when
nicknameis non-nil. Passingnilleaves the existing nickname unchanged (the partial-update path treatsnilas a no-op). The credential must exist before the update; the manager does not create a new credential as a side effect.Throws
NotFoundwhen the credential does not exist.WriteFailedwhen the update fails.
Declaration
Swift
public func updateNickname(credentialId: String, nickname: String?) async throwsParameters
credentialIdIdentifier of the credential to update.
nicknameNew nickname, or
nilto leave the existing nickname unchanged. -
clearAll()AsynchronousClears every credential from storage.
This operation is irreversible. Use with caution.
Throws
WriteFailedwhen clearing fails.Declaration
Swift
public func clearAll() async throws
View on GitHub
Install in Dash