Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions apps/web/src/components/SeedSave.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// "Print" / "Save as text file" for the recovery phrase (onboarding + Settings).
// Paper is the safe copy, so Print leads; the file is behind a warning, because
// file-stealing malware hunts for exactly this kind of file. Printing shows only
// the .seed-print sheet below (index.css hides the app), so a printout or "Save as
// PDF" holds the words and nothing else.
import { useState } from "react";
import { createPortal } from "react-dom";
import { saveSeedFile } from "../services/seed-file";

export default function SeedSave({ words }: { words: string[] }) {
const [asking, setAsking] = useState(false);
const [result, setResult] = useState<string | null>(null);

// The warning's own button is the click that opens the save dialog (it needs a
// fresh click, which a confirm() popup in between wouldn't give it).
async function save() {
setAsking(false);
setResult(null);
try {
const r = await saveSeedFile(words);
if (r === "saved") setResult("Saved.");
if (r === "downloaded") {
setResult(
"It's in your Downloads folder. Move it somewhere offline, like a USB stick, then delete it from Downloads.",
);
}
} catch (e) {
setResult(e instanceof Error ? `Couldn't save the file: ${e.message}` : "Couldn't save the file.");
}
}

const secondary = "rounded-lg bg-raised px-3 py-1.5 text-xs text-text-secondary transition-colors hover:bg-border-strong";
return (
<>
<div className="mt-3 flex flex-wrap gap-2">
<button
type="button"
onClick={() => window.print()}
className="rounded-lg bg-accent px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-accent-hover"
>
Print / save as PDF
</button>
<button type="button" onClick={() => setAsking(true)} disabled={asking} className={secondary + " disabled:opacity-40"}>
Save as text file
</button>
</div>
{asking ? (
<div className="mt-2 rounded-lg border border-warning p-3 text-xs">
<p className="text-warning">
Malware that steals files looks for exactly this kind of file. Anyone who gets it can take
over your account, and there&rsquo;s no way to lock them out again.
</p>
<p className="mt-1 text-text-secondary">
Save it straight to a USB stick or an encrypted drive — not Downloads, the Desktop or a
cloud-synced folder — and never email or message it.
</p>
<div className="mt-2 flex gap-2">
<button type="button" onClick={() => void save()} className={secondary}>
Save the file
</button>
<button type="button" onClick={() => setAsking(false)} className="px-2 text-text-muted hover:text-text-secondary">
Cancel
</button>
</div>
</div>
) : (
<p className="mt-2 text-xs text-text-muted">
Best: print it and keep the paper somewhere safe. A file or PDF opens your account just like
the words do.
</p>
)}
{result && <p className="mt-1 text-xs text-text-secondary">{result}</p>}
{createPortal(
<div className="seed-print">
<h1>Privex recovery phrase</h1>
<p>
Anyone who has these words can take over your Privex account. Keep this paper somewhere
safe. Privex will never ask you for these words.
</p>
<ol>
{words.map((w, i) => (
<li key={i}>{w}</li>
))}
</ol>
</div>,
document.body,
)}
</>
);
}
31 changes: 31 additions & 0 deletions apps/web/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,34 @@
66% { background-position: 8px -6px; }
100% { background-position: 0 0; }
}

/* Recovery-phrase printout (SeedSave): while it's on the page, printing shows only
it - black on white, whatever the theme. */
.seed-print {
display: none;
}
@media print {
html:has(.seed-print),
html:has(.seed-print) body {
background: #fff !important;
}
body:has(> .seed-print) > :not(.seed-print) {
display: none !important;
}
.seed-print {
display: block;
color: #000;
font: 12pt/1.5 system-ui, sans-serif;
}
.seed-print h1 {
font-size: 18pt;
font-weight: 600;
margin-bottom: 8pt;
}
.seed-print ol {
columns: 3;
margin-top: 16pt;
list-style: decimal inside;
font: 14pt/2 ui-monospace, monospace;
}
}
2 changes: 1 addition & 1 deletion apps/web/src/onboarding/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export async function completeRegistration(
}

/** STEP 6: ensure a live session (re-auth if the in-memory token was lost to a
* refresh), strip the mnemonic from storage, and enter the app. */
* refresh), mark onboarding done, and enter the app. */
export async function finishOnboarding(crypto: CryptoApi = workerCrypto): Promise<void> {
const bundle = await loadBundle();
if (!bundle) throw new Error("no identity to finalize");
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/onboarding/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// persisted AES-GCM-encrypted under the WebCrypto master key so a closed browser
// resumes with the SAME keys (stable px_id). Plaintext key material never lands
// in IndexedDB. A coarse progress marker lives in the (non-sensitive) settings
// table; the seed mnemonic is stripped from storage once onboarding completes.
// table. The seed mnemonic stays in the encrypted bundle (see finalizeIdentity).
import { db } from "../db";
import { getMasterKey } from "../crypto/keystore";
import { encryptString, decryptString } from "../db/encrypted-db";
Expand Down
103 changes: 59 additions & 44 deletions apps/web/src/screens/Onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
// server in the clear.
//
// Flow: welcome → keys (forge + identicon reveal) → register (PoW) → secure
// (recovery) → safety orientation → enter. finishOnboarding() strips the mnemonic
// and signs in, so it runs at the end of the recovery step; the safety step is a
// (recovery) → safety orientation → enter. finishOnboarding() signs in, so it
// runs at the end of the recovery step; the safety step is a
// post-signin orientation shown once (progress is already "done" on reload).
import { useEffect, useRef, useState, type ReactNode } from "react";
import { Link, useNavigate } from "react-router-dom";
import { completeRegistration, finishOnboarding, generateIdentity } from "../onboarding/flow";
import { loadBundle, loadProgress } from "../onboarding/store";
import { checkConfirm, pickConfirmIndices } from "../onboarding/seed-confirm";
import { enableOpaqueRecovery, opaqueRecoveryStatus } from "../services/recovery";
import { enableOpaqueRecovery, opaqueRecoveryStatus, PASSWORD_MANAGER_NOTE } from "../services/recovery";
import { db } from "../db";
import Avatar from "../components/Avatar";
import { SEED_SAVED_KEY } from "../components/FinishSetup";
import SeedSave from "../components/SeedSave";
import { useCopyToClipboard } from "../hooks/useCopyToClipboard";
import { ArrowLeftIcon, CheckIcon, KeyIcon, LockIcon, ShieldCheckIcon, WarningTriangleIcon } from "../components/icons";

Expand Down Expand Up @@ -150,6 +151,7 @@ export default function Onboarding() {
if (step === "password")
return (
<PasswordStep
userId={userId}
error={error}
onBack={() => {
setError(null);
Expand Down Expand Up @@ -344,10 +346,12 @@ function Registering({

// --- STEP 4 (sub): password recovery ---
function PasswordStep({
userId,
onSubmit,
onBack,
error,
}: {
userId: string;
onSubmit: (pw: string) => Promise<void>;
onBack: () => void;
error: string | null;
Expand Down Expand Up @@ -386,46 +390,56 @@ function PasswordStep({
your password can unlock — we can&rsquo;t read it.
</p>

<label htmlFor="onboarding-password" className="mt-6 block text-sm text-text-secondary">Password</label>
<input
id="onboarding-password"
type="password"
value={pw}
onChange={(e) => setPw(e.target.value)}
minLength={8}
autoComplete="new-password"
className="mt-1 w-full rounded-lg border border-border-strong bg-input px-3 py-2 outline-none focus:border-border-focus"
/>
{pw && scorer && (
<div className="mt-2">
<div className="h-1.5 w-full overflow-hidden rounded bg-input">
<div className={`h-full ${colors[score]}`} style={{ width: `${(score + 1) * 20}%` }} />
<form
onSubmit={(e) => {
e.preventDefault();
if (!busy && strongEnough && matches) void submit();
}}
>
{/* Lets a password manager file this password under your Privex ID. */}
<input type="text" name="username" autoComplete="username" value={userId} readOnly hidden />
<label htmlFor="onboarding-password" className="mt-6 block text-sm text-text-secondary">Password</label>
<input
id="onboarding-password"
type="password"
value={pw}
onChange={(e) => setPw(e.target.value)}
minLength={8}
autoComplete="new-password"
className="mt-1 w-full rounded-lg border border-border-strong bg-input px-3 py-2 outline-none focus:border-border-focus"
/>
{pw && scorer && (
<div className="mt-2">
<div className="h-1.5 w-full overflow-hidden rounded bg-input">
<div className={`h-full ${colors[score]}`} style={{ width: `${(score + 1) * 20}%` }} />
</div>
<p className="mt-1 text-xs text-text-secondary">
{labels[score]}
{!strongEnough && " - needs to be Strong or better"}
</p>
</div>
<p className="mt-1 text-xs text-text-secondary">
{labels[score]}
{!strongEnough && " - needs to be Strong or better"}
</p>
</div>
)}
)}

<label htmlFor="onboarding-confirm-password" className="mt-4 block text-sm text-text-secondary">Confirm password</label>
<input
id="onboarding-confirm-password"
type="password"
value={confirm}
onChange={(e) => setConfirm(e.target.value)}
autoComplete="new-password"
className="mt-1 w-full rounded-lg border border-border-strong bg-input px-3 py-2 outline-none focus:border-border-focus"
/>
{confirm && !matches && <p className="mt-1 text-xs text-danger">Passwords don&rsquo;t match.</p>}
<label htmlFor="onboarding-confirm-password" className="mt-4 block text-sm text-text-secondary">Confirm password</label>
<input
id="onboarding-confirm-password"
type="password"
value={confirm}
onChange={(e) => setConfirm(e.target.value)}
autoComplete="new-password"
className="mt-1 w-full rounded-lg border border-border-strong bg-input px-3 py-2 outline-none focus:border-border-focus"
/>
{confirm && !matches && <p className="mt-1 text-xs text-danger">Passwords don&rsquo;t match.</p>}
<p className="mt-4 text-xs text-text-muted">{PASSWORD_MANAGER_NOTE}</p>

<button
disabled={busy || !strongEnough || !matches}
onClick={() => void submit()}
className="mt-8 w-full rounded-lg bg-accent py-3 font-medium text-white transition-colors hover:bg-accent-hover disabled:cursor-not-allowed disabled:opacity-40"
>
{busy ? "Enabling…" : "Enable password recovery"}
</button>
<button
type="submit"
disabled={busy || !strongEnough || !matches}
className="mt-6 w-full rounded-lg bg-accent py-3 font-medium text-white transition-colors hover:bg-accent-hover disabled:cursor-not-allowed disabled:opacity-40"
>
{busy ? "Enabling…" : "Enable password recovery"}
</button>
</form>
{error && <p className="mt-3 text-sm text-danger">{error}</p>}
</Shell>
);
Expand Down Expand Up @@ -485,7 +499,7 @@ function RecoveryStep({
void db.settings.put({ key: SEED_SAVED_KEY, value: true });
void finish();
} else {
setConfirmError("Those words don't match. Check your written copy.");
setConfirmError("Those words don't match. Check your saved copy.");
}
}

Expand All @@ -506,8 +520,8 @@ function RecoveryStep({
{!revealed ? (
<>
<p className="mt-2 text-sm text-text-secondary">
24 words that <em>are</em> your account. Write them down and keep them offline — we
will never show them again, and never ask for them.
24 words that <em>are</em> your account. Keep a copy offline — on paper, or as a file
or printout. We&rsquo;ll never ask you for them.
</p>
<button
onClick={() => setRevealed(true)}
Expand All @@ -526,12 +540,13 @@ function RecoveryStep({
</div>
))}
</div>
<SeedSave words={words} />
<p className="mt-3 text-xs text-warning">Store these somewhere safe before continuing.</p>
<button
onClick={startConfirm}
className="mt-4 w-full rounded-lg bg-accent py-3 text-sm font-medium text-white transition-colors hover:bg-accent-hover"
>
I&rsquo;ve written them down
I&rsquo;ve saved them
</button>
</>
) : (
Expand Down
Loading
Loading