cipher/public/index.html
maverick 34c7ef08eb Add multi-device key sync: QR device linking + encrypted recovery code
Answers 'how do you get keys to login elsewhere' — both mechanisms, Signal/WhatsApp style:

Server:
- migration 0002: key_backups (recovery blobs) + provisions (QR relay), ciphertext only
- routes/backup.js: POST/GET /api/backup, /backup/exists; provision new/get/complete
- routes/keys.js: POST /api/keys/reset — atomically wipe stale prekeys + install fresh
  (fixes Bad MAC: restore regenerates prekey IDs that INSERT-OR-IGNORE kept stale)

Crypto (crypto.js):
- exportIdentityBlob/importIdentityBlob (identity travels only encrypted)
- generateRecoveryCode (120-bit Crockford base32) + encrypt/decryptWithCode (PBKDF2 250k)
- ephemeral ECDH (P-256) encrypt/decrypt for QR transfer

Client (app.js): account-menu 'Set up recovery code' + 'Link a device' (camera scan
via BarcodeDetector or paste); auth-screen 'Restore with recovery code' + 'Link from
another device' (shows QR + code, polls, restores). Vendored qrcode-generator.

All verified live end-to-end (3-process isolated-store integration tests):
restore-from-code and QR-link both let a fresh device receive + decrypt messages.
SW cache v3->v4.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-22 13:04:46 +10:00

152 lines
8 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<meta name="theme-color" content="#0b141a" />
<title>Cipher — encrypted messaging</title>
<link rel="manifest" href="/manifest.webmanifest" />
<link rel="icon" href="/icons/icon.svg" type="image/svg+xml" />
<link rel="apple-touch-icon" href="/icons/icon.svg" />
<style>
:root {
--bg: #0b141a;
--panel: #111b21;
--panel-2: #202c33;
--accent: #00a884;
--accent-2: #005c4b;
--text: #e9edef;
--muted: #8696a0;
--bubble-in: #202c33;
--bubble-out: #005c4b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background: var(--bg); color: var(--text); height: 100dvh; overflow: hidden;
}
#app { height: 100dvh; }
/* ---- auth ---- */
.auth-card {
max-width: 360px; margin: 12vh auto 0; padding: 32px 24px;
background: var(--panel); border-radius: 16px; display: flex; flex-direction: column; gap: 12px;
box-shadow: 0 10px 40px rgba(0,0,0,.4);
}
.auth-card h1 { margin: 0; text-align: center; color: var(--accent); letter-spacing: .5px; }
.tagline { margin: 0 0 8px; text-align: center; color: var(--muted); font-size: 13px; }
.auth-card input {
padding: 12px 14px; border-radius: 10px; border: 1px solid var(--panel-2);
background: var(--panel-2); color: var(--text); font-size: 15px;
}
.auth-card input:focus { outline: 2px solid var(--accent); }
.auth-err { color: #f15c6d; font-size: 13px; min-height: 16px; text-align: center; }
button { cursor: pointer; font-size: 15px; padding: 12px 14px; border-radius: 10px; border: none; }
button.primary { background: var(--accent); color: #04140f; font-weight: 600; }
button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
button:disabled { opacity: .6; cursor: default; }
/* ---- shell ---- */
.shell { display: grid; grid-template-columns: 340px 1fr; height: 100dvh; }
.sidebar { background: var(--panel); border-right: 1px solid #0a0f13; display: flex; flex-direction: column; min-height: 0; }
.side-header { padding: 16px; border-bottom: 1px solid #0a0f13; }
.me { font-weight: 600; }
.handle { color: var(--muted); font-size: 13px; }
.new-chat { margin: 12px; background: var(--panel-2); color: var(--text); text-align: left; }
.chat-list { overflow-y: auto; flex: 1; }
.chat-item { display: flex; gap: 12px; padding: 12px 16px; cursor: pointer; align-items: center; }
.chat-item:hover { background: var(--panel-2); }
.avatar {
width: 42px; height: 42px; border-radius: 50%; background: var(--accent-2);
display: grid; place-items: center; font-weight: 700; color: var(--text); flex: none;
}
.chat-name { font-weight: 500; }
.chat-sub { color: var(--muted); font-size: 13px; }
/* ---- main ---- */
.main { display: flex; flex-direction: column; min-height: 0; background:
linear-gradient(rgba(11,20,26,.95), rgba(11,20,26,.95)); }
.empty { margin: auto; color: var(--muted); }
.chat-head { display: flex; gap: 12px; align-items: center; padding: 12px 16px; background: var(--panel); border-bottom: 1px solid #0a0f13; }
.back-btn { display: none; background: transparent; color: var(--text); font-size: 26px; line-height: 1; padding: 0 6px; }
.thread { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 65%; padding: 8px 10px 6px; border-radius: 10px; font-size: 14.5px; line-height: 1.35; position: relative; word-wrap: break-word; }
.bubble.in { background: var(--bubble-in); align-self: flex-start; border-top-left-radius: 2px; }
.bubble.out { background: var(--bubble-out); align-self: flex-end; border-top-right-radius: 2px; }
.bubble .time { font-size: 10.5px; color: var(--muted); text-align: right; margin-top: 2px; }
.media-img { max-width: 260px; border-radius: 8px; display: block; }
.media-file { color: var(--text); text-decoration: none; }
.composer { display: flex; gap: 10px; padding: 12px 16px; background: var(--panel); align-items: center; }
.composer input[type=text], .composer input:not([type]) {
flex: 1; padding: 11px 14px; border-radius: 20px; border: none; background: var(--panel-2); color: var(--text); font-size: 15px;
}
.composer input:focus { outline: none; }
.attach { cursor: pointer; font-size: 20px; user-select: none; }
.send { background: var(--accent); color: #04140f; font-weight: 600; border-radius: 20px; }
/* ---- modal ---- */
.modal-overlay {
position: fixed; inset: 0; background: rgba(0,0,0,.6);
display: grid; place-items: center; z-index: 100; padding: 20px;
}
.modal-card {
background: var(--panel); border-radius: 14px; padding: 24px;
width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px;
box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-title { margin: 0; font-size: 18px; }
.modal-input {
padding: 12px 14px; border-radius: 10px; border: 1px solid var(--panel-2);
background: var(--panel-2); color: var(--text); font-size: 15px;
}
.modal-input:focus { outline: 2px solid var(--accent); }
.modal-err { color: #f15c6d; font-size: 13px; min-height: 16px; }
.modal-note { color: var(--muted); font-size: 13px; line-height: 1.4; }
textarea.modal-input { resize: vertical; font-family: inherit; }
.code-box {
font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 18px; letter-spacing: 1px;
background: var(--panel-2); padding: 14px; border-radius: 10px; text-align: center;
word-break: break-all; user-select: all;
}
.code-box.small { font-size: 12px; letter-spacing: 0; }
.qr { display: block; width: 220px; height: 220px; margin: 0 auto; border-radius: 10px; background: #fff; }
.qr-video { width: 100%; max-width: 280px; border-radius: 10px; display: block; margin: 8px auto; background: #000; }
.auth-divider { text-align: center; color: var(--muted); font-size: 12px; margin-top: 6px; text-transform: uppercase; letter-spacing: 1px; }
.link-btn { background: transparent; color: var(--accent); border: none; padding: 6px; font-size: 14px; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.modal-actions button { padding: 10px 16px; }
/* ---- account menu ---- */
.side-header { cursor: pointer; }
.side-header:hover { background: var(--panel-2); }
.caret { color: var(--muted); font-size: 12px; }
.acct-row, .acct-action {
text-align: left; background: var(--panel-2); color: var(--text);
padding: 11px 14px; border-radius: 10px;
}
.acct-row.active { outline: 1px solid var(--accent); }
.acct-action { background: transparent; color: var(--accent); border: 1px solid var(--panel-2); }
.acct-action.danger { color: #f15c6d; border-color: #4a2a2f; }
/* ---- toasts ---- */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { padding: 12px 18px; border-radius: 10px; font-size: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.5); max-width: 90vw; }
.toast.error { background: #3a1c22; color: #ffb3bd; border: 1px solid #5a2a33; }
.toast.info { background: var(--panel-2); color: var(--text); }
@media (max-width: 720px) {
.shell { grid-template-columns: 1fr; }
/* Sidebar shows by default; hide it once a chat is open so the thread is full-width. */
.shell.chat-open .sidebar { display: none; }
.shell:not(.chat-open) .main { display: none; }
.back-btn { display: block; }
}
</style>
</head>
<body>
<div id="app"></div>
<script type="module" src="/js/app.js"></script>
</body>
</html>