mirror of
https://github.com/block/buzz.git
synced 2026-11-30 05:02:57 +00:00
fix(desktop): npub identity controls across profile, agents, and workflows (#7489)
🤖 ## Summary Building on #7488's npub foundation, this PR finishes the identity display change for the controls where you actually manage people and keys: profile, settings, agent access, and workflows. Everywhere in these surfaces, an identity key shows — and copies — as its canonical npub (npub is the human-readable encoding of a Nostr public key: the compact `npub1j57...fjmv` form where space is tight, the full npub where the whole key matters), and accepts npub as input. After this change: - Profile panel: the public-key row and the managed-by / declared-owner copies show the full npub. If a key can't be encoded, you see "Unavailable" with no copy button — never a raw or partial key. - Settings: the identity card shows and copies the npub. The hosted-communities account identity derives from the bound key (`pubkey_hex`) — the same authority as the mismatch gate and hosted operations — so the display can never disagree with what the app acts on; an unusable hex falls back to a neutral label instead of rendering the unverified server npub. The connected claim and a community's Connect action require that same usable bound key to match the local one — with no usable binding the card cannot claim connected or start Connect, while the community list, linking, and delete/rebind recovery stay available. - Hosted create/onboarding: the account and device identity rows in the create flow and owner onboarding derive from the same authoritative fields (bound key / local key), with the same neutral fallback; readiness requires a usable bound key that matches the local one. - Respond-to allowlist (controls who may respond to an agent): entries can be typed or pasted as hex or npub; both spellings of the same key are recognized as one entry and dedupe. Search results, chips, and remove buttons use the compact npub. - Workflow key fields: to/from keys display as npubs in the form and save back as canonical hex. Templates like `{{trigger.author}}`, roles, and free text pass through untouched; placeholders accept both spellings. - Recipient and agent dialogs: the verify popover is npub-only (the raw-hex line is gone); denied-membership screens never show a raw key. - The Rust-side truncated display name (used for native surfaces) shows the same compact npub, so those surfaces match the web UI. Internal representation is unchanged: keys are still stored, sent, and matched as canonical 64-character hex — npub is a display and input spelling, normalized to hex at the boundary, so existing data and integrations keep working. Bound-key usability and comparison use one normalized form (trimmed, lowercased, 64 hex characters; npub rejected), so padded or mixed-case spellings of the same key match. Display names, private keys, and event IDs are untouched. ## Details - `respondToAllowlist` / `RespondToField`: npub entries normalize to canonical hex; cross-form dedupe; compact npub in rows and chips; direct-add accepts npub and stores canonical hex. - `workflowFormTypes` / `WorkflowStepCard`: hex → npub for display, npub → canonical hex on save; templates, roles, and free text pass through in both directions (roundtrip-tested). - `UserProfilePanelFields`, `ProfileSettingsCard`, `HostedCommunitiesSettingsCard`, `MembershipDenied`, `SelectedRecipientChip`, `AddAgentToChannelDialog`: npub display and copy; invalid keys → "Unavailable" with no copy; hosted identity rows derive from the bound `pubkey_hex` (create/onboarding rows from the bound and local keys), never the unverified server npub; connected/readiness/Connect gates use the same usable-bound-key predicate, and the settings Connect invocation callback re-checks it before starting. - `src-tauri/src/commands/identity.rs`: `truncated_display_name` compacts to the first 8 + last 4 characters of the npub (above a 12-char threshold), mirroring `truncateNpub`. - e2e: profile key rows and clipboard polls assert npub forms and raw-hex suppression; the display-screenshots spec pins the npub-only popover; hosted specs drive the real settings card, create flow, and onboarding rows through their real providers, and the unlinked/npub-only identity cases assert no connected claim and no Connect action. ### Related issue - Fixes: N/A. No separate issue; the related work is the stack below. - Stack: builds on #7488 (shared npub foundation), now merged; this PR is rebased onto main and stands on its own. ### Testing At head `303c90ffa` (base: main `bfc38485`; 24 files, +1125/−146): - Focused unit suites (respondToAllowlist, workflowFormTypes, hostedCommunityApi bound-key helpers) green; mutation-checked — dropping allowlist canonicalization fails the dedupe case, and dropping bound-key normalization fails the npub-in-hex and padded same-key cases. - Full desktop unit suite 6,477/6,477, `desktop-typecheck`, `desktop-check` (formatting fixed narrowly with `biome check --write` on the touched files only), and a fresh E2E build at the current head; the add-community + hosted-communities-settings specs 18/18 and onboarding integration 69/69 on a fresh dedicated port, with focused new-case runs 4+4 covering padded same-key (ready, Connect kept — no false rebind) and npub-in-hex (neutral label, recovery, no Connect) across the settings card, create flow, and first-community onboarding, plus the unlinked-account settings regression asserting Connect cannot occur. - `cargo fmt`/clippy (both feature sets) and `cargo test identity` (71 pass) passed at the earlier full-change head; since then, the only production changes in this PR's delta are the hosted identity display authority and its fail-closed bound-key gating/normalization above (base-side fixes carry #7488's receipts) — every other change is test-only. ### Task provenance Buzz channel: `1f0e4a3d-7e01-4efe-bb16-843b357f85c9` Task: buzz://message?channel=1f0e4a3d-7e01-4efe-bb16-843b357f85c9&id=86b34eb4bd84a1472419e9af22636c011c0fe273e3c196f967d7a36996e149b6 --------- Signed-off-by: Logan Johnson <loganj@squareup.com> Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
This commit is contained in:
@@ -218,7 +218,7 @@ function StepConfigFields({
|
||||
onChange={(event) =>
|
||||
onUpdate({ ...step, to: event.target.value })
|
||||
}
|
||||
placeholder="e.g. {{trigger.author}} or hex pubkey"
|
||||
placeholder="e.g. {{trigger.author}}, npub1…, or hex pubkey"
|
||||
value={step.to ?? ""}
|
||||
/>
|
||||
</div>
|
||||
@@ -311,7 +311,7 @@ function StepConfigFields({
|
||||
onChange={(event) =>
|
||||
onUpdate({ ...step, from: event.target.value })
|
||||
}
|
||||
placeholder="Pubkey or role"
|
||||
placeholder="npub1…, hex pubkey, or role"
|
||||
value={step.from ?? ""}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -315,3 +315,74 @@ test("absent reply_in_thread parses as false", () => {
|
||||
assert.equal(parsed.ok, true);
|
||||
assert.equal(parsed.state.steps[0].replyInThread, false);
|
||||
});
|
||||
|
||||
// Handoff vectors, round-trip verified with nostr-tools nip19.
|
||||
const KEY_HEX =
|
||||
"ea9b4d7a7a78a3e3729e5568b14d764d4962be0e1f20f749bcf8d9dbbf9a9328";
|
||||
const KEY_NPUB =
|
||||
"npub1a2d567n60z37xu57245tzntkf4yk90swrus0wjdulrvah0u6jv5qusyp60";
|
||||
|
||||
test("stored hex to/from keys display as npubs in the form", () => {
|
||||
const parsed = yamlToFormState(
|
||||
`name: Keys
|
||||
trigger: { on: message_posted }
|
||||
steps: [{ id: s1, action: send_dm, to: ${KEY_HEX}, text: hi }, { id: s2, action: request_approval, from: ${KEY_HEX}, message: ok }]
|
||||
`,
|
||||
);
|
||||
assert.equal(parsed.ok, true);
|
||||
assert.equal(parsed.state.steps[0].to, KEY_NPUB);
|
||||
assert.equal(parsed.state.steps[1].from, KEY_NPUB);
|
||||
});
|
||||
|
||||
test("npub to/from keys serialize to canonical hex; other spellings pass through", () => {
|
||||
const dm = formStateToYaml({
|
||||
...DEFAULT_FORM_STATE,
|
||||
name: "Keys",
|
||||
steps: [{ id: "s1", action: "send_dm", to: KEY_NPUB, text: "hi" }],
|
||||
});
|
||||
assert.match(dm, new RegExp(`to: ${KEY_HEX}`));
|
||||
assert.doesNotMatch(dm, /npub1/);
|
||||
|
||||
const approval = formStateToYaml({
|
||||
...DEFAULT_FORM_STATE,
|
||||
name: "Keys",
|
||||
steps: [
|
||||
{ id: "s1", action: "request_approval", from: KEY_NPUB, message: "ok" },
|
||||
],
|
||||
});
|
||||
assert.match(approval, new RegExp(`from: ${KEY_HEX}`));
|
||||
|
||||
// A hex spelling serializes unchanged, and a corrupted-checksum npub is
|
||||
// never bound as an identity — it stays exactly as the author wrote it
|
||||
// for the YAML editor to surface.
|
||||
const hexDm = formStateToYaml({
|
||||
...DEFAULT_FORM_STATE,
|
||||
name: "Keys",
|
||||
steps: [{ id: "s1", action: "send_dm", to: KEY_HEX, text: "hi" }],
|
||||
});
|
||||
assert.match(hexDm, new RegExp(`to: ${KEY_HEX}`));
|
||||
|
||||
const corrupt = `${KEY_NPUB.slice(0, -2)}qq`;
|
||||
const corruptDm = formStateToYaml({
|
||||
...DEFAULT_FORM_STATE,
|
||||
name: "Keys",
|
||||
steps: [{ id: "s1", action: "send_dm", to: corrupt, text: "hi" }],
|
||||
});
|
||||
assert.match(corruptDm, new RegExp(`to: ${corrupt.replace(/\./g, "\\.")}`));
|
||||
});
|
||||
|
||||
test("templates and roles pass through both directions untouched", () => {
|
||||
const parsed = yamlToFormState(
|
||||
`name: Keys
|
||||
trigger: { on: message_posted }
|
||||
steps: [{ id: s1, action: send_dm, to: "{{trigger.author}}", text: hi }, { id: s2, action: request_approval, from: manager, message: ok }]
|
||||
`,
|
||||
);
|
||||
assert.equal(parsed.ok, true);
|
||||
assert.equal(parsed.state.steps[0].to, "{{trigger.author}}");
|
||||
assert.equal(parsed.state.steps[1].from, "manager");
|
||||
|
||||
const reserialized = formStateToYaml(parsed.state);
|
||||
assert.match(reserialized, /to: "\{\{trigger\.author\}\}"/);
|
||||
assert.match(reserialized, /from: manager/);
|
||||
});
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { stringify as yamlStringify, parse as yamlParse } from "yaml";
|
||||
|
||||
import {
|
||||
parsePubkeyInput as parseCanonicalPubkey,
|
||||
safeNpub,
|
||||
} from "@/shared/lib/nostrUtils";
|
||||
|
||||
import { cronExpressionError } from "./cronExpression";
|
||||
import {
|
||||
formatDurationSeconds,
|
||||
@@ -116,6 +121,29 @@ export const ACTION_LABELS: Record<ActionType, string> = {
|
||||
set_channel_topic: "Set Channel Topic",
|
||||
};
|
||||
|
||||
const EXACT_HEX_64 = /^[0-9a-fA-F]{64}$/;
|
||||
|
||||
/**
|
||||
* Display form of a DM recipient (`to`) or approver (`from`): an exact 64-char
|
||||
* hex pubkey from stored YAML is shown as its npub; npubs, templates
|
||||
* (`{{trigger.author}}`), roles, and any other free text pass through
|
||||
* unchanged. Encoding failures (non-canonical hex) keep the stored value.
|
||||
*/
|
||||
function keyDisplayValue(value: string | undefined): string | undefined {
|
||||
if (value === undefined || !EXACT_HEX_64.test(value)) return value;
|
||||
return safeNpub(value.toLowerCase()) ?? value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Storage form: an exact npub decodes back to the canonical hex pubkey so the
|
||||
* wire YAML keeps its machine-readable hex contract. Hex, templates, roles,
|
||||
* and any other free text pass through unchanged.
|
||||
*/
|
||||
function keyStorageValue(value: string): string {
|
||||
if (!value.trim().toLowerCase().startsWith("npub1")) return value;
|
||||
return parseCanonicalPubkey(value) ?? value;
|
||||
}
|
||||
|
||||
function toHeaderRows(
|
||||
headers: unknown,
|
||||
stepId: string,
|
||||
@@ -169,7 +197,7 @@ function actionFieldsForStep(step: StepFormState): Record<string, unknown> {
|
||||
if (step.replyInThread) fields.reply_in_thread = true;
|
||||
break;
|
||||
case "send_dm":
|
||||
if (step.to) fields.to = step.to;
|
||||
if (step.to) fields.to = keyStorageValue(step.to);
|
||||
if (step.text) fields.text = step.text;
|
||||
break;
|
||||
case "call_webhook":
|
||||
@@ -182,7 +210,7 @@ function actionFieldsForStep(step: StepFormState): Record<string, unknown> {
|
||||
if (step.body) fields.body = step.body;
|
||||
break;
|
||||
case "request_approval":
|
||||
if (step.from) fields.from = step.from;
|
||||
if (step.from) fields.from = keyStorageValue(step.from);
|
||||
if (step.message) fields.message = step.message;
|
||||
if (step.timeout) fields.timeout = step.timeout;
|
||||
break;
|
||||
@@ -624,14 +652,14 @@ export function yamlToFormState(
|
||||
text: step.text as string | undefined,
|
||||
channel: step.channel as string | undefined,
|
||||
replyInThread: step.reply_in_thread === true,
|
||||
to: step.to as string | undefined,
|
||||
to: keyDisplayValue(step.to as string | undefined),
|
||||
url: step.url as string | undefined,
|
||||
method: step.method as string | undefined,
|
||||
headers: toHeaderRows(step.headers, step.id),
|
||||
body: step.body as string | undefined,
|
||||
emoji: step.emoji as string | undefined,
|
||||
topic: step.topic as string | undefined,
|
||||
from: step.from as string | undefined,
|
||||
from: keyDisplayValue(step.from as string | undefined),
|
||||
message: step.message as string | undefined,
|
||||
timeout: step.timeout as string | undefined,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user