LocalStorageAdapter

class LocalStorageAdapter(keyPrefix: String = DEFAULT_KEY_PREFIX) : StorageAdapter

Storage adapter backed by the browser's localStorage API.

Provides persistent credential and session storage that survives page reloads and browser restarts. Data is serialized as JSON using hex encoding for byte arrays.

Limitations:

  • Storage is limited to approximately 5 MB per origin.

  • Data is not encrypted and is accessible to any script on the same origin.

  • Only available in browser environments (throws on Node.js).

For production applications with larger storage needs, consider IndexedDBStorageAdapter.

Key scheme:

  • Credentials: {prefix}cred_{credentialId_hex}

  • Credential index: {prefix}cred_index

  • Session: {prefix}session

Example:

val storage = LocalStorageAdapter()
storage.save(credential)
val retrieved = storage.get(credential.credentialId)

Parameters

keyPrefix

Prefix for all localStorage keys. Defaults to stellar_sa_.

Constructors

Link copied to clipboard
constructor(keyPrefix: String = DEFAULT_KEY_PREFIX)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open suspend override fun clear()

Clears all credentials from storage.

Link copied to clipboard
open suspend override fun clearSession()

Clears the current session.

Link copied to clipboard
open suspend override fun delete(credentialId: String)

Deletes a credential by its ID.

Link copied to clipboard
open suspend override fun get(credentialId: String): StoredCredential?

Retrieves a credential by its ID.

Link copied to clipboard
open suspend override fun getAll(): List<StoredCredential>

Retrieves all stored credentials.

Link copied to clipboard
open suspend override fun getByContract(contractId: String): List<StoredCredential>

Retrieves all credentials associated with a contract address.

Link copied to clipboard
open suspend override fun getSession(): StoredSession?

Retrieves the current session.

Link copied to clipboard
open suspend override fun save(credential: StoredCredential)

Saves a credential to storage using upsert semantics.

Link copied to clipboard
open suspend override fun saveSession(session: StoredSession)

Saves a session to storage.

Link copied to clipboard
open suspend override fun update(credentialId: String, updates: StoredCredentialUpdate)

Updates a credential with partial changes.