OZStorageAdapter
public protocol OZStorageAdapter : AnyObject, Sendable
Protocol for persisting smart account credentials and sessions.
Storage adapters provide a pluggable persistence layer for credentials and sessions. Implementations must be thread-safe and support concurrent access.
The default implementation is OZInMemoryStorageAdapter, which stores data in memory
only. Platform-specific implementations can provide persistent storage.
-
save(credential:Asynchronous) Saves a credential to storage using upsert semantics.
If a credential with the same ID already exists, it is overwritten.
Throws
SmartAccountStorageException.WriteFailedif saving fails.Declaration
Swift
func save(credential: OZStoredCredential) async throwsParameters
credentialThe credential to save.
-
get(credentialId:Asynchronous) Retrieves a credential by its ID.
Throws
SmartAccountStorageException.ReadFailedif reading fails.Declaration
Swift
func get(credentialId: String) async throws -> OZStoredCredential?Parameters
credentialIdThe credential ID.
Return Value
The credential, or
nilif not found. -
getByContract(contractId:Asynchronous) Retrieves all credentials associated with a contract address.
Throws
SmartAccountStorageException.ReadFailedif reading fails.Declaration
Swift
func getByContract(contractId: String) async throws -> [OZStoredCredential]Parameters
contractIdThe contract address.
Return Value
List of credentials (empty if none found).
-
getAll()AsynchronousRetrieves all stored credentials.
Throws
SmartAccountStorageException.ReadFailedif reading fails.Declaration
Swift
func getAll() async throws -> [OZStoredCredential]Return Value
List of all credentials.
-
delete(credentialId:Asynchronous) Deletes a credential by its ID. Does nothing if the credential does not exist.
Throws
SmartAccountStorageException.WriteFailedif deletion fails.Declaration
Swift
func delete(credentialId: String) async throwsParameters
credentialIdThe credential ID to delete.
-
update(credentialId:Asynchronousupdates: ) Updates a credential with partial changes. Only non-nil fields in the update are applied.
Throws
SmartAccountCredentialException.NotFoundif the credential is not found;SmartAccountStorageException.WriteFailedif updating fails.Declaration
Swift
func update(credentialId: String, updates: OZStoredCredentialUpdate) async throwsParameters
credentialIdThe credential ID to update.
updatesThe partial updates to apply.
-
clear()AsynchronousClears all credentials AND the stored session from storage. Equivalent to a hard reset of the adapter’s contents.
Throws
SmartAccountStorageException.WriteFailedif clearing fails.Declaration
Swift
func clear() async throws -
saveSession(_:Asynchronous) Saves a session to storage. Overwrites any previously stored session.
Throws
SmartAccountStorageException.WriteFailedif saving fails.Declaration
Swift
func saveSession(_ session: OZStoredSession) async throwsParameters
sessionThe session to save.
-
getSession()AsynchronousRetrieves the current session, returning
nilwhen no session exists or when the stored session has expired. Expired sessions are auto-cleared on read.Throws
SmartAccountStorageException.ReadFailedif reading fails.Declaration
Swift
func getSession() async throws -> OZStoredSession?Return Value
The session, or
nilif no session exists or the session is expired. -
clearSession()AsynchronousClears the current session.
Throws
SmartAccountStorageException.WriteFailedif clearing fails.Declaration
Swift
func clearSession() async throws
View on GitHub
Install in Dash