WalletAddressCache

class WalletAddressCache(context: Context)

Persistent, per-network store for the wallet's public addresses.

The same BIP-39 seed produces different bech32m-encoded addresses on different Midnight networks, because the network prefix (mn_addr_preprod vs mn_addr_undeployed vs mn_addr_preview) is baked into the encoding. This cache keeps one entry per network so the wallet can display the correct address for whatever network the user has selected, without needing to re-derive from the seed (which requires biometric auth).

Storage: JSON file at <app filesDir>/kuira_wallet_address.json. Layout:

{
"UNDEPLOYED": {"unshielded": "...", "shielded": "..."},
"PREPROD": {"unshielded": "...", "shielded": "..."}
}

Missing networks are absent from the map. Legacy single-network files (from before per-network storage landed) are migrated on first read.

When is a network's entry populated?

  • At onboarding (new wallet or restore): the current network's entry is written after storeSeed succeeds.

  • At network switch: if the target network isn't in the cache, the MainActivity switch flow prompts biometric, loads the seed, derives fresh addresses, saves them, then restarts the app. The cache is never populated without the user's seed being unlocked.

Security note: addresses are public data. No encryption here — unlike the seed, losing this file just means a one-time re-derivation (which does require biometric). Storage lives in the same filesDir as the seed, which is excluded from Auto Backup via backup_rules.xml.

Threading: all I/O runs on Dispatchers.IO.

Constructors

Link copied to clipboard
constructor(context: Context)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
suspend fun clear()

Delete all cached addresses across every network. Called during wallet reset / wipe.

Link copied to clipboard
suspend fun hasAny(): Boolean

True if at least one network has cached addresses.

Link copied to clipboard
suspend fun load(network: MidnightNetwork): WalletAddresses?

Load cached addresses for network. Returns null if this network has no cached entry yet (e.g., onboarding ran on a different network and no switch has happened).

Link copied to clipboard
suspend fun save(network: MidnightNetwork, addresses: WalletAddresses)

Persist addresses for network. Other networks' entries are preserved — this call only updates (or inserts) the network entry.