From b9111719f09a448d247465ce28058f9306acc853 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 24 Mar 2024 16:46:25 -0500 Subject: [PATCH] Nostr: allow setting a nip05 username --- src/features/edit-profile/index.tsx | 22 ++++++++++++++++++++++ src/locales/en.json | 2 ++ src/schemas/account.ts | 3 +++ src/utils/features.ts | 6 ++++++ 4 files changed, 33 insertions(+) diff --git a/src/features/edit-profile/index.tsx b/src/features/edit-profile/index.tsx index fbcebf02bb..03fe961aa4 100644 --- a/src/features/edit-profile/index.tsx +++ b/src/features/edit-profile/index.tsx @@ -55,6 +55,7 @@ const messages = defineMessages({ displayNamePlaceholder: { id: 'edit_profile.fields.display_name_placeholder', defaultMessage: 'Name' }, websitePlaceholder: { id: 'edit_profile.fields.website_placeholder', defaultMessage: 'Display a Link' }, locationPlaceholder: { id: 'edit_profile.fields.location_placeholder', defaultMessage: 'Location' }, + nip05Placeholder: { id: 'edit_profile.fields.nip05_placeholder', defaultMessage: 'user@{domain}' }, cancel: { id: 'common.cancel', defaultMessage: 'Cancel' }, }); @@ -75,6 +76,11 @@ interface AccountCredentialsSource { sensitive?: boolean; /** Default language to use for authored statuses. (ISO 6391) */ language?: string; + /** Nostr metadata. */ + nostr?: { + /** Nostr NIP-05 identifier. */ + nip05?: string; + }; } /** @@ -120,6 +126,8 @@ interface AccountCredentials { location?: string; /** User's birthday. */ birthday?: string; + /** Nostr NIP-05 identifier. */ + nip05?: string; } /** Convert an account into an update_credentials request object. */ @@ -142,6 +150,7 @@ const accountToCredentials = (account: Account): AccountCredentials => { website: account.website, location: account.location, birthday: account.pleroma?.birthday ?? undefined, + nip05: account.source?.nostr?.nip05 ?? '', }; }; @@ -308,6 +317,19 @@ const EditProfile: React.FC = () => { /> + {features.nip05 && ( + } + > + + + )} + {features.birthdays && ( } diff --git a/src/locales/en.json b/src/locales/en.json index 6739b3bc7a..3bf3aab9be 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -592,6 +592,8 @@ "edit_profile.fields.meta_fields.content_placeholder": "Content", "edit_profile.fields.meta_fields.label_placeholder": "Label", "edit_profile.fields.meta_fields_label": "Profile fields", + "edit_profile.fields.nip05_label": "Username", + "edit_profile.fields.nip05_placeholder": "user@{domain}", "edit_profile.fields.stranger_notifications_label": "Block notifications from strangers", "edit_profile.fields.website_label": "Website", "edit_profile.fields.website_placeholder": "Display a Link", diff --git a/src/schemas/account.ts b/src/schemas/account.ts index 725cffefa0..6065e6cc5f 100644 --- a/src/schemas/account.ts +++ b/src/schemas/account.ts @@ -94,6 +94,9 @@ const baseAccountSchema = z.object({ discoverable: z.boolean().catch(true), }).optional().catch(undefined), sms_verified: z.boolean().catch(false), + nostr: z.object({ + nip05: z.string().optional().catch(undefined), + }).optional().catch(undefined), }).optional().catch(undefined), statuses_count: z.number().catch(0), suspended: z.boolean().catch(false), diff --git a/src/utils/features.ts b/src/utils/features.ts index 66aa668543..60c3543783 100644 --- a/src/utils/features.ts +++ b/src/utils/features.ts @@ -722,6 +722,12 @@ const getInstanceFeatures = (instance: Instance) => { v.software === TAKAHE, ]), + /** + * Can set a Nostr username. + * @see PATCH /api/v1/accounts/update_credentials + */ + nip05: v.software === DITTO, + /** * Ability to sign Nostr events over websocket. * @see GET /api/v1/streaming?stream=nostr