Connecting is a three-party ceremony between the app, the person's browser and the vault server. The app never sees a password or a session: it receives a device credential through a one-time encrypted mailbox. The device side is src/vault/connect.ts, a port of the Go daemon's StartConnection, PollConnection, HandleConnection and finishConnection, driven by VaultStore.start and VaultStore.poll in the store.
Sequence
sequenceDiagram
participant A as App
participant B as Browser
participant V as Vault server
A->>A: mint 32 random token bytes
A->>B: open vault URL /connect with the token in the fragment
B->>V: person signs in and approves this device
B->>V: post payload encrypted with the token to the mailbox
loop every 2 s while pending and visible
A->>V: GET api/vault-connect/connectId
V-->>A: 404, or found with the payload, once
end
A->>A: decrypt payload with the token, check the vault URL
A->>V: GET api/vault with the bearer
V-->>A: version, encryptedData, credentials
A->>A: unwrap remote DEK with the secret, merge local and remote
opt merged state differs from remote
A->>V: POST api/vault with the expected version
end
A->>A: store secret in Keychain, persist envelope, publish keysToken and URL
mintPendingConnection(vaultUrl, now, siteName) returns a PendingConnection "held in memory only":
Field | Value |
|---|---|
| 32 random bytes and their unpadded base64url |
|
|
|
|
|
|
| the mailbox ciphertext, once read |
The token "rides ONLY in the fragment", so it is never sent to the server; the server only learns its hash. The root action passes the current Seed server as siteName.
normalizeVaultOriginURL(raw) applies the desktop app's rules: http or https only, no user info, query or fragment, and trailing slashes removed. Anything else throws Invalid vault URL.
Constant | Value |
|---|---|
| 15 minutes |
| 2,000 ms (the root task uses the same literal) |
|
|
Starting
VaultStore.start refuses when locked (Unlock the vault first.) or already remote (Switch to local before connecting another vault.). It zeroes any previous token, increments a generation counter and stores the new pending connection. The root contract then pushes the connect sheet and opens the URL in the browser (Screens and tasks).
Polling
VaultStore.poll(now) does one step; the cadence belongs to a root task.
If now >= expireTime, zero the token and stop with connection token expired.
If no payload is held yet, call getVaultConnect. Not found means keep waiting. After 3 consecutive failed checks a warning appears: Cannot reach the vault server (...).
decodeConnectPayload decrypts the payload with the token bytes (XChaCha20-Poly1305) and requires vaultUrl, userId, credentialId and a 32-byte secret.
The payload's vault URL must equal the pending one, else Vault URL mismatch.
reconcile, then finishConnection.
Store the secret in the Keychain bundle, adopt the merged state and the remote DEK, set the remote sync state and credentials, rebaseKeys, persist, publishKeys.
Finishing
finishConnectionAttempt:
fetches the snapshot with the bearer built from the credential (API and sync),
finds this device's secret credential and decrypts its wrappedDEK with the secret (failure: Failed to decrypt wrapped DEK for the remote credential.),
decrypts and deserializes the remote state (an empty vault is an empty state),
warms account ids, merges local into remote,
uploads only when the merged state is not semantically equal to the remote state,
returns the adopted DEK, merged state, versions, lastSyncTime in Unix seconds and the merged credential list.
The device adopts the remote vault's DEK; its own local DEK is discarded. A VaultWriteConflictError (HTTP 409) restarts the whole attempt, up to 3 times, refetching each time.
Between phases the function calls yieldCryptoTurn(): "Each phase from here is its own turn: together they exceed Exact's per-turn budget for a real-size vault." See The 100 ms turn budget.
mergeCredentialLists unions credential entries, deduplicated on kind, id and wrapped DEK. cleanupOldCredential deletes a superseded credential on the server, best effort; in this snapshot only the real-vault suite calls it.
Interruption, retry and cancel
The mailbox can be read only once, so the app keeps the encrypted approval in memory until it finishes. retryableConnectionError decides what happens on failure:
Failure | Result |
|---|---|
Transport error ( | Stay pending, keep the payload, show |
Authentication refusal, URL mismatch, undecryptable or invalid payload, bad key | Stop: clear the pending connection and set |
"Only transport failures may reuse approval; authentication and cryptographic refusals fail closed." A retry refetches the remote version, so an upload whose reply was lost is not repeated.
cancel() increments generation, zeroes the token and clears the pending connection. Every await in poll re-checks the generation, so a late reply can neither report a failure nor connect the device. In finally, a connection that is no longer pending has its token zeroed and its payload deleted. The background and history of these rules are in Real vault compatibility suite.
Tests
In vault.test.ts: the full path from token to identities in Me; a wrong mailbox key as a one-time refusal; URL mismatch; an aborted snapshot retried with exactly one mailbox read; a cached approval expiring after 15 minutes; a lost upload reply not uploading twice; a 401 stopping; cancellation suppressing a late reply. Further down: token expiry without creating a remote credential, URL boundary cases, and cancelling while the mailbox request is in flight. The approval itself is simulated by the mock vault.
Do you like what you are reading? Subscribe to receive updates.
Unsubscribe anytime