Bump version to v0.1.9 — fix account switch read-only bug (root cause)

Root cause: switchAccount fetched the nsec from the OS keychain on every
switch. Any keychain failure (timeout, Windows Credential Manager quirk,
no entry yet) silently fell through to loginWithPubkey → read-only mode.

Fix: cache each NDKPrivateKeySigner in-memory (_signerCache map) the
moment loginWithNsec succeeds. switchAccount checks the cache first;
the OS keychain is now only consulted at startup (restoreSession). Signers
are pure crypto objects with no session state — safe to reuse indefinitely.

Verified with a 9-switch stress test across 3 accounts (A1→A2→A3→A1→
A2→A1→A3→A2→A1): hasSigner=true and correct pubkey on every switch.

Also adds dev tooling:
- src/lib/tauri-dev-mock.ts: localStorage-backed keychain + SQLite stubs
  so the frontend can run in a plain browser for Playwright testing
- src/main.tsx: import mock first in DEV mode (no-op in production)
- test/gen-accounts.mjs: generates 3 deterministic test keypairs

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jure
2026-03-11 15:11:03 +01:00
parent cdf1a0b4a2
commit fdb7aab9d1
9 changed files with 158 additions and 5 deletions

40
src/lib/tauri-dev-mock.ts Normal file
View File

@@ -0,0 +1,40 @@
/**
* Dev-only mock for Tauri's invoke() — lets the frontend run in a plain browser.
*
* Provides:
* - localStorage-backed keychain (store_nsec / load_nsec / delete_nsec)
* - No-op SQLite stubs (db_save_notes / db_load_feed / db_save_profile / db_load_profile)
*
* Injected before any invoke() call only when import.meta.env.DEV is true and
* Tauri internals are not already present (i.e. running in browser, not Tauri window).
*/
if (import.meta.env.DEV && !(window as any).__TAURI_INTERNALS__) {
const keychainKey = (pubkey: string) => `__dev_nsec_${pubkey}`;
const mockInvoke = async (cmd: string, args: Record<string, unknown> = {}): Promise<unknown> => {
switch (cmd) {
case "store_nsec":
localStorage.setItem(keychainKey(args.pubkey as string), args.nsec as string);
return null;
case "load_nsec":
return localStorage.getItem(keychainKey(args.pubkey as string)) ?? null;
case "delete_nsec":
localStorage.removeItem(keychainKey(args.pubkey as string));
return null;
case "db_save_notes":
case "db_save_profile":
return null;
case "db_load_feed":
return [];
case "db_load_profile":
return null;
default:
console.warn("[tauri-dev-mock] unhandled invoke:", cmd, args);
return null;
}
};
(window as any).__TAURI_INTERNALS__ = { invoke: mockInvoke };
console.info("[tauri-dev-mock] active — using localStorage keychain");
}