Overview
The Key-Value Storage API provides persistent storage for wallet configuration, preferences, and security-critical data. All values are strongly typed and validated against a predefined schema.Storage Architecture
Value Types
The storage system supports five primitive types:- int32 - 32-bit integer values
- int64 - 64-bit long integer values
- double - 64-bit floating point values
- string - UTF-8 string values
- bool - Boolean true/false values
- null - Explicit null values
Schema Classification
Each key in the storage schema is classified with:Determines backup behavior:
NoAutoBackup- Not included in automatic backupsSyncAutoBackup- Backed up synchronouslyAsyncAutoBackup- Backed up asynchronously
Security level for backed up data:
NotApplicable- No backup security requirementPlain- Backed up without encryptionAuthenticated- Backed up with authenticationEncrypted- Backed up with encryption
Whether the data is security-critical
The data type for this key (int32, int64, double, string, or bool)
RPC Methods
Save
Store or update a single key-value pair. Request:SaveRequest
The key to store. Must be defined in the storage schema.
The value to store. Can be one of: null_value, double_value, int_value, long_value, string_value, or bool_value.
google.protobuf.Empty
Example Value Types:
Get
Retrieve a value by its key. Request:GetRequest
The key to retrieve. Must be defined in the storage schema.
GetResponse
The stored value, typed according to the schema definition. Returns null_value if the key exists but has no value.
Delete
Remove a key-value pair from storage. Request:DeleteRequest
The key to delete. Must be defined in the storage schema.
google.protobuf.Empty
SaveBatch
Store or update multiple key-value pairs in a single operation. Request:SaveBatchRequest
A map of keys to values. All keys must be defined in the storage schema.
google.protobuf.Empty
Struct Definition:
GetBatch
Retrieve multiple values by their keys. Request:GetBatchRequest
List of keys to retrieve. All keys must be defined in the storage schema.
GetBatchResponse
A map of keys to their stored values. Missing keys are omitted from the result.
GetByPrefix
Retrieve all key-value pairs where the key starts with a given prefix. Request:GetByPrefixRequest
The key prefix to match. Returns all keys beginning with this string.
GetBatchResponse
A map of matching keys to their stored values. Returns an empty map if no keys match.
Predefined Storage Keys
The following keys are predefined in the storage schema:User Preferences
Whether the wallet balance is hidden in the UI
- Backup: NoAutoBackup
- Security Critical: No
Night mode preference setting
- Backup: NoAutoBackup
- Security Critical: No
Whether user has opted in to biometric authentication
- Backup: NoAutoBackup
- Security Critical: No
Length of the user’s PIN
- Backup: NoAutoBackup
- Security Critical: No
Security Card Data
Serialized extended public key from the NFC security card
- Backup: AsyncAutoBackup
- Security Critical: No
Security card secret in hexadecimal format (mock Houston only)
- Backup: AsyncAutoBackup
- Security Critical: No
Number of times the security card has been used
- Backup: AsyncAutoBackup
- Security Critical: No
Pairing slot identifier for the security card
- Backup: AsyncAutoBackup
- Security Critical: No
Encrypted Keys
Unverified encrypted Muun key (prototype)
- Backup: AsyncAutoBackup (Plain)
- Security Critical: No
Verified encrypted Muun key (prototype)
- Backup: AsyncAutoBackup (Authenticated)
- Security Critical: Yes
Encrypted user key (prototype)
- Backup: AsyncAutoBackup (Authenticated)
- Security Critical: Yes
Feature Flags
Override for NFC Card V2 feature flag
- Backup: AsyncAutoBackup
- Security Critical: No
Mock Houston Keys
Last random private key in hex (temporary, for mock Houston)
- Backup: AsyncAutoBackup
- Security Critical: No
Unix timestamp in milliseconds of last challenge (temporary)
- Backup: AsyncAutoBackup
- Security Critical: No
Implementation Details
Type Conversion
Values are stored as strings in the underlying database and converted to/from their typed representations using the schema’s ValueType definition:- IntType: Converts between int32 and string using base-10 parsing
- LongType: Converts between int64 and string using base-10 parsing
- DoubleType: Converts between float64 and string using standard float parsing
- StringType: Stores strings directly without conversion
- BoolType: Converts between bool and string (“true”/“false”)
Validation
All operations validate that:- The requested key exists in the storage schema
- The provided value type matches the schema’s ValueType
- Type conversion succeeds before storage
Database Backend
Storage is backed by a SQLite database using thewalletdb package. The KeyValueStorage wrapper provides:
- Automatic connection management
- Type-safe conversion between Go types and database strings
- Schema-based validation
Error Handling
Storage operations may return errors for:- Unknown Key: Key not defined in storage schema
- Type Mismatch: Value type doesn’t match schema definition
- Conversion Error: Failed to convert value to/from string
- Database Error: Underlying database operation failed
Source References
- Protobuf definition:
libwallet/presentation/api/wallet_service.proto:29-35 - Storage implementation:
libwallet/storage/storage.go - Schema definition:
libwallet/storage/schema.go