Keychain Storage Adapter
Persistent storage adapter for smart account credentials and sessions using the iOS/macOS Keychain.
This adapter uses the Security framework's Keychain Services API (SecItem*) to store credential and session data. Data is stored as generic password items with JSON payloads.
Keychain storage provides:
Encryption at rest by the OS
Access control via
kSecAttrAccessibleAfterFirstUnlockPersistence across app reinstalls (unless explicitly deleted)
iCloud Keychain sync (if the user has it enabled)
While UserDefaultsStorageAdapter is adequate for public key storage, this adapter is appropriate for use cases requiring stronger data protection.
Key scheme:
Service:
com.soneso.stellar.smartaccount(configurable)Account:
cred_{credentialId}for credentials,session_currentfor the session,credential_indexfor the credential ID list
Example:
val storage = KeychainStorageAdapter()
storage.save(credential)
val loaded = storage.get(credential.credentialId)Parameters
The Keychain service name for grouping items. Defaults to "com.soneso.stellar.smartaccount".
Functions
Clears the current session.
Retrieves a credential by its ID.
Retrieves all stored credentials.
Retrieves all credentials associated with a contract address.
Retrieves the current session.
Saves a credential to storage using upsert semantics.
Saves a session to storage.
Updates a credential with partial changes.