feat(storage): per-credential opt-in to keep ciphertext on-device only#10
Merged
Conversation
Adds a "Store on this device only" toggle to the Add Credential form.
Items the user opts in for are encrypted with the same vault key as
everything else, then persisted to the browser's IndexedDB instead of
sent to the server. The encryption story is unchanged — a locked vault
makes both server-fetched and local-only items unreadable.
For users who don't opt in (everyone, by default) the existing
zero-knowledge guarantee is unchanged.
## What's in the diff
### `packages/web/src/storage/` — new module
- `local.ts` — IndexedDB wrapper. Hand-rolled (no `idb` dep) to fit the
project's dependency-minimal style; ~150 lines including jsdoc.
- Records keyed by client-generated UUIDv4
- `vault` index (lowercased email) so two accounts sharing a browser
see disjoint items
- Atomic per-call transactions, descriptive errors, no silent failures
- `unified.ts` — facade exposing `listAll` / `createItem` / `deleteItem`
that fan out over the server vault and the local store. Returned
items carry a `location: "server" | "local"` tag set by the facade
(NOT a field inside the encrypted plaintext, so no migration of
existing items is needed).
- Local-store read failures fall back to an empty list with a console
warning so a corrupt local store can't block access to server items.
### Schema (no change)
`VaultLoginPlaintext` is unchanged. The storage location is metadata
about *where the ciphertext came from*, attached at list time on the
`DecryptedItem` wrapper type. Existing items are implicitly
`location: "server"`.
### UI
- AddCredentialForm grows a "Store on this device only" toggle with
warning copy: no sync, cleared if site data is cleared, single point
of failure. Toggle defaults off.
- CredentialsGrid renders a green `DEVICE` badge next to the name of
any local-only row. The badge is a sibling of the name span (not a
child) so it stays visible while the long name truncates with
ellipsis — verified in the regenerated screenshots.
- VaultPage wires through the unified facade so every list / create /
delete routes to the right store automatically. The bulk-delete
toolbar maps each selected id to its location before issuing the
per-store deletes.
Adjacent fix: bulk-delete toast captured `selected.size` AFTER
`setSelected(new Set())`, which would render "0 credential(s) deleted".
Captured the count first.
### Tests
- 8 new vitest tests in `tests/local-storage.test.ts` covering:
round-trip, vault-key lowercasing, per-vault isolation, ordering by
creation time, delete-and-report, count, ciphertext-shape contract,
per-row uniqueness. Total web tests: 56 passing (was 48).
- `fake-indexeddb/auto` polyfills `globalThis.indexedDB` for Node tests;
the production code runs unmodified.
### Docs
- `docs/USER_GUIDE.md` gains §5a explaining the toggle, what it stores,
and the explicit trade-off list (no sync, cleared by site-data wipe,
no off-device backup).
- `docs/preview/vault*.html` mockups updated to mirror the new live
DOM structure (`name-row` wrapper around the name + optional badge).
All preview screenshots regenerated.
### Bundle impact
CSS: 4.48 KB → 4.72 KB gzipped (+0.24 KB)
JS: 75.53 KB → 76.94 KB gzipped (+1.41 KB)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a Store on this device only toggle to the Add Credential form. Items the user opts in for are encrypted with the same vault key as everything else, then persisted to the browser's IndexedDB instead of sent to the server. The encryption story is unchanged — a locked vault makes both server-fetched and local-only items unreadable.
For users who don't opt in (everyone, by default) the existing zero-knowledge guarantee is unchanged.
Screenshots
The new toggle in the Add form, with the trade-off warning copy:
The grid now renders a green DEVICE badge next to the name of any local-only row (visible on
oracle-erp-bastionhere):What's in the diff
packages/web/src/storage/— new modulelocal.ts— IndexedDB wrapper. Hand-rolled (noidbdep) to fit the project's dependency-minimal style. Records keyed by client-generated UUIDv4, indexed by lowercasedvaultemail, atomic per-call transactions, descriptive errors.unified.ts— facade exposing+ "listAll" +/+ "createItem" +/+ "deleteItem" +that fan out over the server vault and the local store. Returned items carry a+ "location: "server" | "local"" +tag set by the facade (NOT a field inside the encrypted plaintext, so no migration of existing items is needed). Local-store read failures fall back to an empty list with a console warning so a corrupt local store can't block access to server items.Schema — unchanged
+ "VaultLoginPlaintext" +stays exactly as-is. The storage location is metadata attached at list time on the+ "DecryptedItem" +wrapper. Existing items are implicitly+ "location: "server"" +.UI
+ "DEVICE" +badge next to the name of any local-only row. Badge is a sibling of the name span (not a child) so it stays visible while the long name truncates with ellipsis.Adjacent fix
Bulk-delete toast captured
+ "selected.size" +after+ "setSelected(new Set())" +, which would render "0 credential(s) deleted". Captured the count first.Decisions made up front (per design discussion)
+ "local.ts" +is already a small module boundary, easy to swapVerification
+ "npm run typecheck --workspaces" +— clean across core / web / extension+ "npm test --workspaces" +— 56 passed (48 connect + 8 new local-storage tests)+ "npm run build --workspace=@passman/web" +— cleanTest plan
+ "DEVICE" +badge+ "passman-local-vault" +)🤖 Generated with Claude Code