Vault lifecycle and persistence
A vault is an encrypted store that the app creates, opens, changes, and closes as one user session. The frontend works with safe entry metadata and one revealed entry at a time, while the native side owns the vault key, encrypted database, and durable writes. For the wider data model and sync view, see Vault data and sync, Workspace and sync, and Import, export, and backup.
Vault lifecycle
Creation and opening
The creation and opening flow turns a password or biometric result into an active vault session. Creation makes a new empty vault; opening an existing vault returns the metadata needed to draw the main view and reports whether the vault has sync enabled. First-run restore follows the same session contract after it installs a vault from Drive or a backup file.
The frontend uses the result from setupCreate, setupRestoreFromDrive, setupRestoreFromFile, unlock, or a workspace operation to enter the main view. A workspace switch can return null instead. This means the target is selected but still needs its lock screen and a password.
flowchart LR
A[Create or choose a vault] --> B[Native side proves access]
B --> C[Open encrypted store]
C --> D[Return entry metadata and sync state]
D --> E[Frontend enters main view]
B --> F[Access fails]
F --> G[Keep vault locked]
References: src/…/auth.ts• L4-7 src/…/setup.ts• L39-64 src/…/types.ts• L184-187 src-tauri/…/session.rs• L264-301 src-tauri/…/auth.rs• L25-118
Active session
The active session is the boundary between an open vault and the rest of the app. The native side keeps the vault key and the open encrypted store in memory. The frontend keeps only the current metadata list and short-lived UI state, so locking or changing workspaces can remove vault-specific data without relying on the frontend to erase secrets.
Every successful open replaces the current session. The session also records whether the vault can sync. A lock clears the key and closes the store, then emits vault:locked; the frontend responds by clearing rows, selection, archive data, and other vault-specific state before showing the lock screen.
References: src/…/app.ts• L239-262 src/…/events.ts• L59-66 src/…/vault.ts• L17-51 src-tauri/…/session.rs• L54-73 src-tauri/…/session.rs• L132-148 src-tauri/…/session.rs• L196-258
Workspace transitions
Each workspace has its own vault and store. Selecting or creating a workspace closes the current session before the new workspace becomes active. If the native side already has the target key, the operation returns an unlock result; otherwise it ends on the target workspace's lock screen.
The frontend treats a successful workspace create or restore like an unlock: it clears the previous session, loads the returned metadata, enters the main view, and refreshes the workspace list. This keeps data from one vault from appearing while another vault is active.
References: src/…/workspace.ts• L16-46 src/…/workspace.ts• L38-71 src/…/workspace.ts• L96-111 src-tauri/…/workspace.rs• L50-178 src-tauri/…/workspace.rs• L257-384
Entry lifecycle
Metadata and reveal
The list view uses EntryMeta, which contains identity and display data but not entry secrets. The frontend asks the native side to reveal one entry when a detail or edit view needs it. The native side decrypts that entry for the request and returns a redacted form for passkeys, whose private keys remain native-only.
This split lets the app show and filter a vault without loading every secret into the webview. It also makes the reveal operation the clear boundary for sensitive entry data.
References: src/…/types.ts• L151-182 src/…/vault.ts• L4-8 src-tauri/…/vault.rs• L14-30 src-tauri/…/session.rs• L54-61
Entry save
The frontend sends a complete entry draft through saveEntry. The frontend store assigns identity and timestamps for new or changed entries, then calls the native command. The native side rejects private passkey keys supplied by the webview. For a redacted passkey entry, it restores the matching protected keys from the row being replaced, seals the completed entry, and upserts one row. It returns refreshed metadata so the frontend can update its list without a second read.
After a successful save, the frontend selects the saved row, corrects filters that would hide it, schedules sync when enabled, and starts its audit work. A save is therefore both a durable vault change and a state transition for the current view.
References: src/…/vault.ts• L126-155 src/…/vault.ts• L7-9 src-tauri/…/vault.rs• L32-95 src-tauri/…/models.rs• L164-220
Targeted entry changes
Some changes do not need a full reveal and save. The frontend can change an entry's favorite state through a metadata-only request, while password-history clearing is handled natively so the rest of the protected entry remains unchanged. Both calls return refreshed metadata for the current view.
These operations still change durable vault state. The native side therefore keeps them inside the active session and gives each result back to the frontend as the new source for that row.
References: src/…/vault.ts• L22-30 src-tauri/…/vault.rs• L97-122 src-tauri/…/vault.rs• L165-177
Entry archive and restore
Delete moves an entry out of the live list by creating a tombstone rather than immediately removing its record. The Archive loads tombstone metadata only when its view opens. Restore makes the row live again, while purge discards the tombstoned contents permanently.
The frontend updates the live list or archive from the command result and schedules sync after each durable change. The native store retains tombstones because they carry deletion state to other devices.
References: src/…/vault.ts• L10-20 src/…/vault.ts• L158-195 src-tauri/…/vault.rs• L124-162 src-tauri/…/mod.rs• L121-143
Persistence responsibilities
Native encrypted storage
The native store is the source of truth for vault data. It persists queryable entry metadata beside an opaque encrypted payload, and it protects the database at rest with the vault key. The key and payload cipher are derived from the vault's active key scheme; the frontend never owns either one.
The vault is a complete durable file set, not only the main database file. Its SQLite side files and key or recovery sidecars must stay with the database when a workspace moves. The key-derivation descriptor is the source of truth for opening the vault and is written atomically so a crash cannot leave an incomplete opening record. On iOS, the app can place this data in the shared app-group location so the app and its AutoFill extension use the same vault.
References: src-tauri/…/mod.rs• L1-7 src-tauri/…/mod.rs• L55-89 src-tauri/…/vault.rs• L31-65 src-tauri/…/storage.rs• L11-28 src-tauri/…/storage.rs• L30-63 src-tauri/…/storage.rs• L102-132 src-tauri/…/storage.rs• L330-356 src-tauri/…/storage.rs• L397-469
Frontend state ownership
The frontend store represents what the open vault puts on screen: live metadata, archive metadata, selection, editor state, and audit state. It does not replace native persistence. Its job is to apply command results immediately, keep the current view coherent, and discard all vault-specific state when the session ends.
The app-level store keeps state that can survive a lock, such as the current flow, preferences, and sync status. It also debounces sync requests after writes. A lock cancels the pending request because the next unlock performs a fresh sync.
References: src/…/vault.ts• L17-51 src/…/vault.ts• L105-119 src/…/app.ts• L13-17 src/…/app.ts• L239-253 src/…/app.ts• L301-334
Save and sync boundary
Saving an entry changes the local vault first. If sync is configured, the frontend schedules one whole-vault sync after a short quiet period instead of sending a snapshot for every quick edit. A lock drops the timer, but it does not lose the local write; the next unlock starts a sync again.
The backend can also report a merged metadata list after another device changes the vault. The frontend replaces its list and refreshes the audit, so local display state follows the durable store rather than treating sync as a separate copy of the vault.
References: src/…/vault.ts• L143-165 src/…/vault.ts• L184-208 src/…/app.ts• L264-279 src/…/app.ts• L301-337 src/…/events.ts• L40-47 src/…/events.ts• L20-33
Vault transfer
The vault supports two transfer paths. An encrypted import merges entries from a separate file into the currently open vault, while an export creates a restorable snapshot of the current vault. The native side verifies the source or vault password and places imported data under the active vault's protection before it updates the store.
The frontend receives the refreshed metadata list from the import call, so it can replace its view without a second read. Export uses the same vault snapshot form as restore, which keeps backup and first-run restore on one lifecycle path. A revealed environment entry can also be written to a user-selected file on desktop; that file action is separate from vault persistence.
References: src/…/vault.ts• L32-56 src-tauri/…/vault.rs• L183-249 src-tauri/…/vault.rs• L252-345
Change checklist
When these files or sections are changed, remember to consider these:
- Keep every command that opens a vault aligned with
UnlockResult; the frontend uses both the metadata list andsyncConfiguredto enter the main view. - Keep
vault:lockedas the single frontend lock signal. Any new path that closes a session must clear vault state and refresh the lock-screen probe through that event. - Keep entry saves aligned across
Entry,EntryMeta, native row creation, and the redacted passkey round trip. A field added to one side can otherwise vanish or expose data at the IPC boundary. - Keep metadata-only writes aligned with the row returned to the frontend. A change that updates the native row without returning fresh metadata can leave filters and selection stale.
- Keep tombstone, restore, and purge behavior aligned with sync record export. Removing tombstones too early can prevent another device from learning about a deletion.
- Keep workspace path moves together with the database side files and key-derivation sidecars. A partial move can pair a database with the wrong opening data.
- Keep import and export password checks aligned with the active session key. A transfer that opens under one key but writes under another can create data that the vault cannot later read.
- Keep the save path's sync scheduling and lock cleanup paired. A delayed request must never publish a vault after its session has ended.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Wrong password during open | The vault stays locked and the failed attempt can increase lockout delay. | The native open maps only a wrong database key to InvalidPassword; other open errors keep their own failure. |
| Lock or workspace switch while vault rows are displayed | Old rows could appear under a new or locked vault. | vault:locked drives clearSession, which resets vault state and favicon data before the lock view is shown. |
| Save of an entry with an unknown or invented passkey private key | The save could replace a native signing key or create a credential that cannot sign. | Native save rejects supplied private keys and restores existing keys by credential id. |
| Metadata-only update returns stale row data | The visible list can show the old favorite or password-history state until another refresh. | Native targeted writes return refreshed EntryMeta values. |
| Crash during key-descriptor or sidecar write | The next launch could fail to open the database or read the required key settings. | Sidecar writes use a temporary file, sync, and atomic replacement. |
| Import or export uses a password for another vault | The operation could expose or produce a snapshot that does not belong to the active vault. | Import decrypts the source file first; export compares the derived key with the unlocked session key. |
| Sync starts after a session ends | Data could be published with the wrong vault key or workspace. | Lock cancels the pending frontend timer; native session changes invalidate stale work. |
| Tombstone is removed instead of retained during delete | Other devices may keep a deleted entry after merge. | Delete marks the row deleted; purge is a separate permanent action. |
| A workspace move finds the same vault file at both locations | One vault could overwrite another, or database side files could be paired with the wrong database. | Moves refuse collisions and move database, WAL, SHM, and sidecars as separate reversible paths. |
Key files
| File | Why to read it |
|---|---|
| src/…/auth.ts | Defines the frontend contract for unlock and lock operations. |
| src/…/setup.ts | Defines first-run creation and restore contracts. |
| src/…/vault.ts | Defines reveal, save, targeted updates, archive, restore, purge, transfer, and file-save calls. |
| src/…/types.ts | Defines the entry, metadata, workspace, and unlock result shapes shared by the frontend. |
| src/…/app.ts | Shows app-level flow, lock handling, session cleanup, and write-to-sync scheduling. |
| src/…/vault.ts | Shows frontend ownership of metadata, selection, saves, archive state, and local reactions to writes. |
| src/…/events.ts | Shows how native lock and merge events update frontend state. |
| src-tauri/…/auth.rs | Connects unlock and lock commands to the native session. |
| src-tauri/…/vault.rs | Connects entry API calls to native reveal, seal, row, tombstone, transfer, and file-save operations. |
| src-tauri/…/session.rs | Defines the in-memory session and its open, clear, lease, and lock behavior. |
| src-tauri/…/mod.rs | Defines the durable vault-store contract and record shape. |
| src-tauri/…/storage.rs | Defines vault file layout, workspace moves, and durable sidecar handling. |
| src-tauri/…/vault.rs | Defines the vault key and per-entry payload boundary. |