vault: opt-in paid email recovery for the personal vault ($5 lifetime) (#298)

* vault: opt-in paid email recovery for the personal vault ($5 lifetime)

A second way back into a logicsrc personal vault when the master password and
the offline recovery key are both gone, without the server holding anything
that alone (even with the DB and server env) opens the vault.

Client (packages/opencreds): random escrow key E encrypts the user key K
(AES-256-GCM, AAD "<ns>:vault:email-escrow:v1|<createdAt>"); E is split into
S (random, to the server) and U = E XOR S (emailed once as a checksummed
Crockford recovery code, never stored). `recover --email` checks the code's
check group first, asks the server for a one-time code, claims S, recombines
E, proves K against an item, sets a new password, issues a new offline
recovery key and re-enrolls with fresh shares (warns loudly if that fails).
New `recovery status|buy|enable|disable` commands; the CLI client lives in
packages/cli/src/vault-sync.ts.

Server (apps/pwa): /api/opencreds/recovery/{checkout,enroll,start,claim} +
status/disable. S is sealed under VAULT_ESCROW_KEY (versioned for rotation,
AAD binds the user). Enrollment is pending until the email with U is sent,
else rolled back. One-time codes: 8 digits, HMAC at rest, 15 min, 5 tries,
single use, 3 starts/hour; claims are audited and announced by email.
Purchase via CoinPay checkout (purpose vault_recovery); /api/coinpay/webhook
now verifies once and dispatches by purpose, auto_rotation unchanged.
Settings card with status and a Buy button. Migration 014 in both dialects.

Docs: security.md and crypto.md "Email recovery (opt-in, paid)" sections with
the honest trade-off; cli.md command reference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* vault email recovery: state that the mailbox alone is enough

The account password resets by email, so mailbox control = sign-in + one-time
code + the enrollment code U. Say so in security.md and stop the one-time-code
email from implying the vault stays safe if someone else reads the mailbox.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* vault email recovery: leave .env.example as on master

Touching it made the credential gate re-scan the existing SESSION_SECRET
placeholder (false positive). VAULT_ESCROW_KEY / _VERSION / VAULT_RECOVERY_PRICE_USD
are documented in docs/opencreds/security.md and crypto.md; prod values live in
vault app-logicsrc-com--prod.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Anthony Ettinger 2026-11-30 07:49:06 -08:00 • committed by GitHub
parent 4e4fedd35e
commit 41ad9f0987
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 2363 additions and 7 deletions

View file

@ -0,0 +1,65 @@
-- Vault email recovery (opt-in, $5 lifetime per user). See docs/opencreds/security.md.
--
-- The CLI encrypts the personal vault's user key under a random key E and splits
-- E into two XOR shares. The server keeps the escrowed blob and share S, with S
-- encrypted under VAULT_ESCROW_KEY (key_version says which one, for rotation).
-- The other share, U, is emailed to the account once and NEVER stored: there is
-- deliberately no column for it. Neither the blob, S, nor this database plus the
-- server env opens a vault without the enrollment email.
--
-- status: pending (enrollment email not yet confirmed sent) -> active -> revoked.
-- A revoked row keeps its timestamps for the audit trail; its escrow material is
-- set to NULL (deleted). Additive only.
CREATE TABLE IF NOT EXISTS vault_recovery_enrollments (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
status TEXT NOT NULL,
escrow_blob TEXT,
escrow_iv TEXT,
server_share_ct TEXT,
server_share_iv TEXT,
key_version INTEGER NOT NULL,
vault_created_at TEXT NOT NULL,
enrolled_at INTEGER NOT NULL,
revoked_at INTEGER
);
CREATE INDEX IF NOT EXISTS idx_vault_recovery_enrollments_user ON vault_recovery_enrollments(user_id, status);
-- One-time codes for a recovery: 8 digits, HMAC'd at rest, 15 minutes, 5 tries, single use.
CREATE TABLE IF NOT EXISTS vault_recovery_codes (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
code_hash TEXT NOT NULL,
attempts INTEGER NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL,
expires_at INTEGER NOT NULL,
used_at INTEGER
);
CREATE INDEX IF NOT EXISTS idx_vault_recovery_codes_user ON vault_recovery_codes(user_id, created_at);
-- The purchase ledger: one row per CoinPay checkout session; settled once.
-- Entitlement = any settled row for the user.
CREATE TABLE IF NOT EXISTS vault_recovery_payments (
checkout_session_id TEXT PRIMARY KEY,
payment_ref TEXT,
payment_id TEXT,
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
amount_usd REAL,
method TEXT,
status TEXT NOT NULL,
created_at INTEGER NOT NULL,
settled_at INTEGER
);
CREATE INDEX IF NOT EXISTS idx_vault_recovery_payments_user ON vault_recovery_payments(user_id, status);
-- Append-only trail of every enroll, start, claim, failure and disable.
CREATE TABLE IF NOT EXISTS vault_recovery_audit (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
action TEXT NOT NULL,
detail TEXT,
ip TEXT,
user_agent TEXT,
created_at INTEGER NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_vault_recovery_audit_user ON vault_recovery_audit(user_id, created_at);