Skip to content

Commit d48b605

Browse files
committed
feat(profiles): show Relay-verified full names
1 parent bbb9590 commit d48b605

4 files changed

Lines changed: 51 additions & 1 deletion

File tree

‎src/bundled/profiles/ProfilePanel.test.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ it("shows historical verification time and issuer, discloses cache, and hides di
647647
["username", "alice"],
648648
["issuer_label", "Example"],
649649
["verified_at", "1000000"],
650+
["full_name", "Alice Example"],
650651
],
651652
}),
652653
),
@@ -657,6 +658,7 @@ it("shows historical verification time and issuer, discloses cache, and hides di
657658
await screen.findByRole("heading", { name: "Alice · Example" }),
658659
).toBeVisible();
659660
expect(screen.getByText(/Name verified.*@alice/)).toBeVisible();
661+
expect(screen.getByText("Alice Example")).toBeVisible();
660662
await userEvent.setup().click(screen.getByRole("tab", { name: "Info" }));
661663
expect(screen.getByText("Name verified by Example")).toBeVisible();
662664
expect(screen.getByText(/Last verified/)).toHaveTextContent(/1970/);
@@ -666,6 +668,7 @@ it("shows historical verification time and issuer, discloses cache, and hides di
666668
expect(screen.getByText(/Cached evidence/)).toBeVisible();
667669
await act(async () => live.state({ status: "connected", routes: [] }));
668670
expect(screen.queryByText("Name verified by Example")).toBeNull();
671+
expect(screen.queryByText("Alice Example")).toBeNull();
669672
expect(screen.queryByText(/Cached verification/)).toBeNull();
670673
} finally {
671674
cleanup();

‎src/bundled/profiles/ProfilePanel.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,11 @@ function ProfileDetails({
431431
</div>
432432
<div className={styles.identity}>
433433
<h2 className="text-body-lg">{name}</h2>
434+
{profile?.verified?.fullName && (
435+
<p className="text-body-sm text-secondary">
436+
{profile.verified.fullName}
437+
</p>
438+
)}
434439
{profile?.verified && (
435440
<p className="text-body-sm text-secondary">
436441
{profile.verified.status === "checked" && (

‎src/features/relay/verified-profile.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,38 @@ it.each([
121121
expect(verifiedProfile(modified, authority, true)).toBeUndefined();
122122
});
123123

124+
it("accepts a Relay-signed optional full name and validates it with the same name rules", () => {
125+
expect(
126+
verifiedProfile(
127+
projection(10, alice.pubkey, [["full_name", "Alice Example"]]),
128+
authority,
129+
true,
130+
)?.fullName,
131+
).toBe("Alice Example");
132+
expect(
133+
verifiedProfile(projection(), authority, true)?.fullName,
134+
).toBeUndefined();
135+
for (const name of ["", " Alice", "A\nB", "A\u200dB", "a".repeat(65)]) {
136+
expect(
137+
verifiedProfile(
138+
projection(10, alice.pubkey, [["full_name", name]]),
139+
authority,
140+
true,
141+
),
142+
).toBeUndefined();
143+
}
144+
expect(
145+
verifiedProfile(
146+
projection(10, alice.pubkey, [
147+
["full_name", "Alice"],
148+
["full_name", "Other"],
149+
]),
150+
authority,
151+
true,
152+
),
153+
).toBeUndefined();
154+
});
155+
124156
function harness(
125157
refresh?: (signal: AbortSignal) => Promise<VerifiedProfileAuthority | null>,
126158
initial: VerifiedProfileAuthority | undefined = authority,

‎src/features/relay/verified-profile.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type VerifiedProfileAuthority = Readonly<{
1313
export type VerifiedProfile = Readonly<{
1414
displayName: string;
1515
username: string;
16+
fullName?: string;
1617
issuerLabel: string;
1718
verifiedAt: number;
1819
/** Observed on a completed current subscription, or retained while unreconciled. */
@@ -91,12 +92,19 @@ export function verifiedProfile(
9192
checked: boolean,
9293
): VerifiedProfile | undefined {
9394
const subject = verifiedProfileSubject(event, authority);
94-
if (!subject || event.content !== "" || event.tags.length !== 7) return;
95+
if (
96+
!subject ||
97+
event.content !== "" ||
98+
(event.tags.length !== 7 && event.tags.length !== 8)
99+
)
100+
return;
95101
const tags = new Map<string, string>();
96102
for (const entry of event.tags) {
97103
if (entry.length !== 2 || tags.has(entry[0] as string)) return;
98104
tags.set(entry[0] as string, entry[1] as string);
99105
}
106+
if (tags.size !== 7 + Number(tags.has("full_name"))) return;
107+
const fullName = tags.get("full_name");
100108
const displayName = tags.get("display_name");
101109
const username = tags.get("username");
102110
const issuerLabel = tags.get("issuer_label");
@@ -105,6 +113,7 @@ export function verifiedProfile(
105113
if (
106114
tags.get("p") !== subject ||
107115
tags.get("active") !== "true" ||
116+
(fullName !== undefined && !validVerifiedName(fullName)) ||
108117
!displayName ||
109118
!validVerifiedName(displayName) ||
110119
!username ||
@@ -120,6 +129,7 @@ export function verifiedProfile(
120129
return Object.freeze({
121130
displayName,
122131
username,
132+
...(fullName !== undefined ? { fullName } : {}),
123133
issuerLabel,
124134
verifiedAt,
125135
status: checked ? "checked" : "cached",

0 commit comments

Comments
 (0)