fix: allow domain-only nip05

This commit is contained in:
Shusui MOYATANI
2024-02-10 01:36:03 +09:00
parent 471d8e764f
commit 393f5e0979
2 changed files with 29 additions and 8 deletions

View File

@@ -20,6 +20,7 @@ import { useRequestCommand } from '@/hooks/useCommandBus';
import useModalState from '@/hooks/useModalState';
import { useTranslation } from '@/i18n/useTranslation';
import { genericEvent } from '@/nostr/event';
import parseNip05Address from '@/nostr/parseNip05Address';
import parseTextNote, { toResolved } from '@/nostr/parseTextNote';
import useCommands from '@/nostr/useCommands';
import useFollowers from '@/nostr/useFollowers';
@@ -72,14 +73,7 @@ const ProfileDisplay: Component<ProfileDisplayProps> = (props) => {
const { verification, query: verificationQuery } = useVerification(() =>
ensureNonNull([profile()?.nip05] as const)(([nip05]) => ({ nip05 })),
);
const nip05Identifier = () => {
const ident = profile()?.nip05;
if (ident == null) return null;
const [user, domain] = ident.split('@');
if (domain == null) return null;
if (user === '_') return { domain, ident: domain };
return { user, domain, ident };
};
const nip05Identifier = () => parseNip05Address(profile()?.nip05);
const isVerified = () => verification()?.pubkey === props.pubkey;
const isMuted = () => isPubkeyMuted(props.pubkey);

View File

@@ -0,0 +1,27 @@
import { NIP05_REGEX } from 'nostr-tools/nip05';
export type ParsedNip05Address = {
user?: string;
domain: string;
ident: string;
};
const parseNip05Address = (ident: string | undefined): ParsedNip05Address | null => {
if (ident == null || ident.length === 0) return null;
const match = ident.match(NIP05_REGEX);
if (match == null) return null;
const [, user, domain] = match;
// (This is not standardized in NIP-05)
// local-part can be optional here. nip05 can contain only the domain name.
// This follows nostr-tools implementation.
if (user == null || user === '_') {
return { user: '_', domain, ident: domain };
}
return { user, domain, ident };
};
export default parseNip05Address;