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
5 changes: 5 additions & 0 deletions docs/identity.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ client inputs must match that service's namespace. Synthetic HTTP/storage tests
do not establish live sign-in, KMS or installed-app
secure-storage acceptance. No backend provisioning or activation is part of this change.

Identity setup offers Restore when secure storage confirms that no local key is present.
The existing restore UI presents the current identity and explicit previous-identity
selection. Restoring a key does not enable automatic backup or change its saved
consent; no consent selection UI is added in this stack.

A shared credential blob can reduce repeated OS prompts by caching many credentials
after one read. For this one human key, one cached item retains that read-once benefit without
coupling human writes to agent credentials or old-app blob writers. This is not a
Expand Down
2 changes: 1 addition & 1 deletion src/bundled/hosted-communities/HostedCommunities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ export function HostedCommunities({
<div className="space-y-3">
<InlineHeader
title="Link this account to your Buzz identity"
subtitle="This Builderlab account isn’t linked to a Buzz identity yet. Connect this device’s key to create and own communities under it — Buzz signs a one-time challenge locally, so your private key never leaves this computer."
subtitle="This Builderlab account isn’t linked to a Buzz identity yet. Connect this device’s key to create and own communities under it — Buzz signs a one-time challenge locally. Connecting shares the signed proof and your public identity."
/>
<Button
variant="primary"
Expand Down
43 changes: 40 additions & 3 deletions src/features/identity/IdentitySetup.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { useState, useSyncExternalStore, type ReactNode } from "react";
import {
useEffect,
useState,
useSyncExternalStore,
type ReactNode,
} from "react";
import { isTauri } from "@tauri-apps/api/core";
import {
hasIntegratedWindowControls,
Expand All @@ -8,6 +13,7 @@ import { macTitleBarDragHandlers } from "../../app/shell/title-bar";
import { Button } from "../../shared/design-system/ui/Button";
import { Input } from "../../shared/design-system/ui/Input";
import type { Identity } from "./service";
import { RestoreIdentity } from "./RestoreIdentity";

export function IdentitySetup({
identity,
Expand All @@ -19,6 +25,25 @@ export function IdentitySetup({
const state = useSyncExternalStore(identity.subscribe, identity.snapshot);
const [importing, setImporting] = useState(false);
const [nsec, setNsec] = useState("");
const [backupAvailable, setBackupAvailable] = useState(false);
const missing = state.status === "missing";
useEffect(() => {
if (!missing) return;
let active = true;
void identity.backupAvailable().then(
(available) => active && setBackupAvailable(available),
() => active && setBackupAvailable(false),
);
return () => {
active = false;
};
}, [identity, missing]);
useEffect(
() => () => {
void identity.cancelRecovery();
},
[identity],
);
const macDesktop = isTauri() && /Mac/i.test(navigator.platform);
const integratedWindowControls = hasIntegratedWindowControls();
if (state.status === "ready") return children;
Expand Down Expand Up @@ -56,7 +81,9 @@ export function IdentitySetup({
automatically.
</p>
{state.error && <p role="alert">{state.error}</p>}
{importing ? (
{state.recovery ? (
<RestoreIdentity identity={identity} recovery={state.recovery} />
) : importing ? (
<form
onSubmit={(event) => {
event.preventDefault();
Expand Down Expand Up @@ -114,9 +141,19 @@ export function IdentitySetup({
>
Create a new identity
</Button>
{backupAvailable && (
<Button
disabled={state.busy}
onClick={() => void identity.beginRecovery()}
>
Restore from backup
</Button>
)}
</div>
)}
{state.busy && <p role="status">Saving your identity securely…</p>}
{state.busy && !state.recovery && (
<p role="status">Saving your identity securely…</p>
)}
</>
)}
</main>
Expand Down
119 changes: 119 additions & 0 deletions src/features/identity/RestoreIdentity.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { useState } from "react";
import { npubEncode } from "nostr-tools/nip19";
import { publicKeyLabels } from "../../shared/identity/public-key";
import { Button } from "../../shared/design-system/ui/Button";
import { Field } from "../../shared/design-system/ui/Field";
import { Radio, RadioGroup } from "../../shared/design-system/ui/RadioGroup";
import type { Identity, RecoveryState } from "./service";

export function RestoreIdentity({
identity,
recovery,
}: {
identity: Identity;
recovery: RecoveryState;
}) {
const [selected, setSelected] = useState<{
recovery: RecoveryState;
handle: string;
}>();
const candidates = recovery.status === "choosing" ? recovery.candidates : [];
const labels = publicKeyLabels(
candidates.map((candidate) => candidate.pubkey),
);
const current =
recovery.status === "choosing"
? candidates.find(
(candidate) => candidate.pubkey === recovery.currentPubkey,
)
: undefined;
const handle =
selected?.recovery === recovery ? selected.handle : current?.handle;
return (
<section className="flex flex-col gap-4" aria-label="Restore from backup">
{recovery.status === "waiting" ? (
<p role="status">Sign in in your browser to find your backups…</p>
) : recovery.status === "saving" ? (
<p role="status">Saving your identity securely…</p>
) : recovery.status === "canceling" ? (
<p role="status">Canceling recovery…</p>
) : recovery.status === "error" ? (
<p role="alert">{recovery.error}</p>
) : candidates.length === 0 ? (
<p role={recovery.failedCount ? "alert" : "status"}>
{recovery.failedCount
? "Your backups couldn’t be recovered. Try again."
: "No backups were found for this account."}
</p>
) : (
<>
<p>
{current
? "Choose the Buzz identity to restore on this device."
: recovery.currentPubkey
? "Your current identity isn’t in these backups. You can choose a previous identity."
: "Choose the Buzz identity to restore on this device."}
</p>
<p>This won’t change the identity linked to your account.</p>
{recovery.failedCount > 0 && (
<p role="status">Some backups couldn’t be recovered.</p>
)}
<Field label="Identity to restore" nativeLabel={false}>
<RadioGroup
aria-label="Identity to restore"
value={handle ?? null}
onValueChange={(value) =>
value && setSelected({ recovery, handle: value })
}
>
{candidates.map((candidate) => (
<Radio
key={candidate.handle}
value={candidate.handle}
label={labels.get(candidate.pubkey)}
description={
<>
{candidate.pubkey === current?.pubkey
? "Current identity"
: "Previous identity"}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit (optional): when currentPubkey is null (the account has no linked identity), every candidate is labelled "Previous identity", which the data doesn't support. Use a neutral label such as "Backed-up identity" in that case.

<code className="block break-all text-mono">
{npubEncode(candidate.pubkey)}
</code>
</>
}
/>
))}
</RadioGroup>
</Field>
</>
)}
<div className="flex flex-wrap gap-3">
<Button
disabled={
recovery.status === "saving" || recovery.status === "canceling"
}
onClick={() => void identity.cancelRecovery()}
>
{recovery.status === "waiting" ? "Cancel" : "Back"}
</Button>
{recovery.status === "choosing" && candidates.length > 0 ? (
<Button
variant="primary"
disabled={!handle}
onClick={() => handle && void identity.installRecovery(handle)}
>
Restore this identity
</Button>
) : recovery.status === "error" ||
(recovery.status === "choosing" && candidates.length === 0) ? (
<Button
variant="primary"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 [P3] Preserve focus while recovery changes views.

Try recovery again invokes cancellation, changes the phase to canceling, and unmounts the focused primary button. Entering restore and going Back similarly replace focused controls. Browser checks confirmed focus falls to body on entry and Back, although Tab still reaches useful controls and no keyboard trap was reproduced. Keep the focused control mounted and disabled during transitions, or explicitly move focus into the restore section and back to the entry control, consistent with DESIGN.md's focused-control guidance.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Non-blocking P3 follow-up. Focus loss was reproduced again at d031907 on entry, Back and cancellation-gated retry. Useful Tab navigation still works; no keyboard trap was demonstrated. Please preserve or restore focus; this does not block approval.

onClick={() => void identity.beginRecovery()}
>
Try recovery again
</Button>
) : null}
</div>
</section>
);
}
Loading
Loading