Connect to the real Nexa backend, replacing the mock lock toggle

Adds the wire-protocol WebSocket client (ws-client.ts) and the REST
auth flow (backend-client.ts) against the now-live backend, using a
locally-generated ed25519 keypair (identity.ts) as a stand-in wallet
signer until real wallet-extension integration is built.

lock-state.ts's setLockState is now applyLockState, called only by
the WS client on an incoming lock_state message -- the backend is
the sole source of truth for lock state, so there's no other writer
anymore. The popup's dev mock controls are replaced with a live
connection-status + lock-state display.

Verified end-to-end against the real backend (nonce -> verify -> /me
-> ws lock_state) using the same tweetnacl/bs58 libs shipped in the
extension.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YXiHuScXrjxBh7yFGAPq3B
This commit is contained in:
2026-09-07 09:10:18 +02:00
co-authored by claude
parent 5643eebde7
commit 3b6054f2f0
14 changed files with 371 additions and 98 deletions
+9 -4
View File
@@ -1,15 +1,20 @@
import type { LockState } from './types';
import type { ConnectionStatus, LockState } from './types';
/** browser.storage.local key backing the lock state seam in the background script. */
export const LOCK_STATE_STORAGE_KEY = 'nexa:lockState';
/**
* Typed message contracts between background <-> content scripts <-> popup.
* All lock-state reads/writes go through these so no module reaches into
* storage directly (see src/background/lock-state.ts).
* All lock-state reads go through these so no module reaches into storage
* directly (see src/background/lock-state.ts). There is deliberately no
* client-writable "set lock state" message: the backend is the sole source
* of truth for lock state (see the WebSocket protocol's "Ownership" section
* in ../../CLAUDE.md) — only the WS client (ws-client.ts) may apply a new
* lock state, and only because the server told it to.
*/
export type NexaMessage =
| { type: 'nexa:get-lock-state' }
| { type: 'nexa:set-lock-state'; state: LockState }
| { type: 'nexa:lock-state-changed'; state: LockState }
| { type: 'nexa:get-connection-status' }
| { type: 'nexa:connection-status-changed'; status: ConnectionStatus }
| { type: 'nexa:open-popup' };