Skip to main content

Module settings

Module settings 

Source
Expand description

Settings key-value store operations.

Functions§

commit_account_setup
Atomically commit the four settings written during new-account setup: the (possibly-encrypted) pkey, the encryption_enabled flag, the security_type (only when encrypted), and the (already-encrypted) seed phrase. Wrapping these in a single transaction makes the new-account flow crash-safe: either all four land or none do. The previous design wrote them through four separate set_sql_setting calls, which left a window where pkey was persisted but encryption_enabled was not — the next boot would then mis-interpret the encrypted blob as plaintext nsec and brick the account.
commit_bunker_account_setup
Atomically commit the four settings written during bunker new-account setup: the (possibly-encrypted) client keypair pkey, encryption_enabled, security_type, plus signer_type='bunker', the (possibly-encrypted) bunker_url, and the plaintext bunker_remote_pubkey. Wraps the whole commit in a transaction for the same reason as commit_account_setup — a half-written bunker account would brick login.
get_bunker_remote_pubkey
Read the cached remote signer pubkey (hex). Plaintext on disk — it’s public-key material with no secrecy implications, and keeping it readable before unlock lets the UI display “Connected to ” on the locked account picker without prompting for a password.
get_bunker_url
Read the bunker:// URL, decrypting it if the account uses encryption. Returns Ok(None) for local accounts (no row), or when decryption fails against an obviously-encrypted blob (likely the user hasn’t unlocked yet).
get_pkey
Get the stored private key (bech32 nsec).
get_seed
Get the stored seed phrase (may be encrypted).
get_signer_type
Read the active signer kind from settings. Missing rows pre-date migration 27 and are treated as "local" so pre-NIP-46 accounts behave unchanged.
get_sql_setting
Get a SQL setting by key.
remove_setting
Remove a setting by key.
set_bunker_remote_pubkey
Persist the cached remote signer pubkey (hex form). Updated after each successful bunker bootstrap — the bootstrap response carries the canonical pubkey, which may differ from any user-supplied form.
set_bunker_url
Persist the bunker:// URL, encrypting if the account uses encryption. The plaintext form is never written to disk for encrypted accounts.
set_pkey
Set the stored private key.
set_seed
Set the seed phrase (should be encrypted before calling).
set_signer_type
Persist the signer kind. Accepts the discriminator’s as_setting_str() form (“local” or “bunker”); other values are accepted but get_signer_type will treat them as local downstream.
set_sql_setting
Set a SQL setting key-value pair.