Vault: remote vault device role
Orientation for the Vault package: how the app keeps identities in an encrypted local vault, connects that vault to a remote vault server, and keeps the two in sync.

The Vault package implements the device role of Remote Vault Connect inside the mobile app. It is a port of the Go daemon's vault behaviour (backend/storage/vault), written in TypeScript because the app has no daemon. It keeps every identity in one encrypted file, can link that file to a person's remote vault through a browser approval, and then syncs so identities created on any device appear on all of them.

Responsibility

    Hold identities in an encrypted envelope on the device, keyed from the Keychain.

    Run the connect ceremony: mint a token, open the vault's browser page, poll for the approval, adopt the remote data key.

    Sync with optimistic concurrency: fetch, merge, upload, retry on conflict.

    Mirror identities between the vault state and the seed-keys Keychain map that the rest of the app signs with (Identity).

    Lock, unlock, switch back to local, and log out.

Files

File

Role

Page

src/vault/store.ts

VaultStore: the serialized state machine, on-device format, Keychain bridge

The store and on-device format

src/vault/sources.ts

The three vault* data sources

The store and on-device format

src/vault/connect.ts

Token, connect URL, mailbox payload, finishing a connection

Connect ceremony

src/vault/api.ts

HTTP client and error classes

API and sync

src/vault/sync.ts

One sync pass

API and sync

src/vault/merge.ts

State merge and equality

Merge and tombstones

vault.contract, vault.test.contract, pkg:vault blocks

Screens, tasks, actions, Contract tests

Screens and tasks

src/vault/__tests__/vault.test.ts

27 Bun tests against the mock vault

all of the above

The byte formats (envelope JSON, state codec, AEAD) live in Crypto: vault envelope and state codec.

How the pieces relate

flowchart TB UI["vault.contract screens and root tasks"] --> SRC["sources.ts: vaultRead, vaultStart, vaultCommand"] SRC --> ST["VaultStore in store.ts"] ST --> CN[connect.ts] ST --> SY[sync.ts] CN --> MG[merge.ts] SY --> MG CN --> API[api.ts] SY --> API API --> SRV[Vault server] ST --> FILE[("app:/data/vault/envelope.json")] ST --> KEK[("Keychain secret seed-vault-kek")] ST -->|publishes| KEYS[("Keychain secret seed-keys")] KEYS -->|reconciled into| ST ME[Me package] -->|edits| KEYS

Two copies of the identities

There are two stores, and understanding their order explains most of the design:

    The vault state (encrypted file) is the source of truth. It carries seeds, names, delegations, tombstones and fields from newer clients.

    The Keychain map seed-keys is the copy the app signs with. The vault publishes into it after the state is written.

Because the map is written second, it can be behind. The package therefore never infers a deletion from a missing key: only an explicit {removed: true} marker left by Me becomes a tombstone. This rule was introduced after an incident on 2026-11-26, recorded in the test file, where "a phone whose Keychain map was behind its vault state tombstoned 34 identities and, on the next completed connection, deleted them from the remote vault and every other device".

Grants and limits

    Grants in app.ts: secret.keep seed-vault-kek, fs.read app:/data/vault/envelope.json, fs.write app:/data/vault, plus the general network grants (Grants and capabilities).

    There is no master password: the vault opens with a Keychain key, because Argon2id needs WASM (Current limits and known gaps).

    Work that scales with the number of identities yields between items for the 100 ms turn budget.

Testing

Three layers cover the package: the Bun tests against the mock vault, three Contract tests, and the real vault compatibility suite against the repository's actual vault server and web UI.

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

Unsubscribe anytime

Comments