Vault: screens and tasks
The two components in vault.contract with props and testIds, the pkg:vault state, resources, mutations, seven tasks and actions in app.contract, and the Contract tests that drive them.

vault.contract declares the vault's interface: a status list under Me and a modal sheet for the browser approval. The timing of the whole package (poll every 2 s, sync every 30 s, countdown, foreground sync) is not in TypeScript but in root tasks in app.contract, written in Contract. The store says so itself: "The root Contract task owns the two-second cadence."

Shapes and helpers

    VaultStatus: the fifteen fields answered by the store.

    VaultPage: {visibilityState}, the shape read from Exact's reserved exactPage() resource.

    vaultName(identity, profiles): profile name, then key name, then short id.

    vaultCountdown(ms): m:ss, never below zero.

The file reuses MeIdentity and MeProfile from Me: screens and components and Avatar from Shared components.

Components

VaultScreen

VaultScreen, route vault (/me/vault). Props: eid, active, status, loading, busy, failed, url, ids, profiles, current, and the actions editURL, connect, resume, command, create, importKey, switchTo, askLogout.

Section

Content

testIds

Storage

One of: loading text; the error with Retry; Locked with Unlock; or the mode (Local or Remote) and URL. In remote mode also Local N · Remote N · Synced N, the last sync time, any sync error and Sync now

vault-loading, vault-error, vault-retry, vault-locked, vault-unlock, vault-mode, vault-versions, vault-last-sync, vault-sync-error, vault-sync

Identities

Each identity links to its Me identity screen, with Current or a Use button; Create identity; Import recovery phrase or key

vault-empty, vault-current-<short id>, vault-create, vault-import

Remote vault, local mode

URL field (placeholder https://hyper.media/vault), connect error, Connect (or Restart connection while pending), Continue pending connection

vault-url, vault-connect-error, vault-connect, vault-resume

Remote vault, remote mode

Switch to local; Log out and clear this device

vault-local, vault-logout

Last section

Lock vault

vault-lock

Dialog vault-logout-confirmation

"Your identities remain in your remote vault and on your other devices."

vault-logout-confirm

The list's own testId is vault-screen, set only when the screen is active. Identities and remote sections are hidden while there is an error, while locked, or before the first status arrives.

VaultConnectScreen

VaultConnectScreen, route vault-connect (/me/vault/connect), presented as a modal. Props: eid, status, busy, now, and the actions retry, cancel, openBrowser.

It shows a status title (Approve this device, Connected or Connection stopped), and while pending: Open in browser, Link expires in m:ss, the selectable connect link and any poll warning. A connect error and Try again appear when stopped. testIds: vault-connect-screen, vault-connect-cancel, vault-connect-status, vault-open-browser, vault-expiry, vault-connect-link, vault-poll-warning, vault-connect-failed, vault-connect-retry.

Root declarations

Kind

Declaration

State

vaultURL = "https://hyper.media/vault", vaultNow = 0

Resources

vaultPage = exactPage(); vaultStatus = vaultRead(meIds) with time.epochAtZero

Mutations

vaultStarted (refreshes vaultStatus, then vaultAfterStart); vaultChanged (refreshes vaultStatus and meIds, then vaultAfterChange); vaultEdited (declared queue, refreshes both)

Derived

vaultBusy: any of the three mutations pending

Because vaultStatus takes meIds as an argument, it is asked again whenever the identity list changes (State, refresh and stale-reply patterns).

Tasks

Task

Runs when

Does

vaultTrackMe

vault open, no error, unlocked; keyed on every identity's id, key name and creation time

after 1 ms, vaultMeChanged: sends vaultCommand("edited", now) so Me edits reach the vault

vaultPoll

connection pending and page visible

every 2,000 ms, vaultPollTick

vaultCountdownTick

connection pending

every 1,000 ms, vaultClock updates vaultNow

vaultSyncTimer

connected, unlocked, page visible

every 30,000 ms, vaultSyncTick

vaultForeground

same condition

after 1 ms, vaultSyncTick: one sync each time the condition becomes true, for example on returning to the foreground

vaultRestoreIdentities

vault open; keyed on the vault's id list

after 1 ms, vaultRefreshIdentities

vaultConnectedReturn

connected while the connect sheet is on top

after 2,000 ms, back

Polling and syncing stop while the app is in the background, because both conditions require vaultPage.visibilityState == "visible".

Actions

pkg:vault actions:

    vaultEditURL(v) edits the URL field.

    vaultConnect sends vaultStarted = vaultStart(vaultURL, server, now). vaultAfterStart pushes the connect sheet (once) and calls openURL(connectUrl) when the reply is pending.

    vaultResume reopens the sheet; vaultOpenBrowser reopens the URL.

    vaultCommand(command), vaultPollTick and vaultSyncTick send vaultChanged = vaultCommand(...), each guarded by not vaultBusy, so ticks never overlap a running operation.

    vaultMeChanged sends the queued vaultEdited mutation, which is not guarded by vaultBusy (inferred intent: an edit is queued rather than dropped).

    vaultRefreshIdentities refreshes meIds, and when the current account is not in the vault (and the vault is healthy and unlocked) switches currentAccount to the vault's first identity.

    vaultCancel sends the cancel command and pops the sheet. vaultAskLogout opens the confirmation dialog.

Every command passes time.epochAtZero + performanceNow() as its time. The view switch wires both components; the screen's Create and Import buttons reuse Me's meOpenCreate and meOpenImport.

Contract tests

vault.test.contract starts at /me/vault with seed 42 and has 3 tests, with "Throwaway fixtures only":

    Local empty state, lock, and unlock.

    An invalid URL (with credentials) shows Invalid vault URL and stays local.

    A pending connection against http://127.0.0.1:4790/vault: the sheet shows Approve this device; fail fetch plus 6,000 ms produces the poll warning; 900,000 ms more gives connection token expired; Cancel returns to Local.

The third test needs the local test server, which mounts the mock vault. A completed approval is not driven here; that path is covered by the Bun tests and by the UI drives in the real vault compatibility suite. See Contract UI tests for the step vocabulary.

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime

Comments