mirror of
https://github.com/aljazceru/rabbit.git
synced 2025-12-17 14:04:21 +01:00
fix: allow domain-only nip05
This commit is contained in:
@@ -20,6 +20,7 @@ import { useRequestCommand } from '@/hooks/useCommandBus';
|
|||||||
import useModalState from '@/hooks/useModalState';
|
import useModalState from '@/hooks/useModalState';
|
||||||
import { useTranslation } from '@/i18n/useTranslation';
|
import { useTranslation } from '@/i18n/useTranslation';
|
||||||
import { genericEvent } from '@/nostr/event';
|
import { genericEvent } from '@/nostr/event';
|
||||||
|
import parseNip05Address from '@/nostr/parseNip05Address';
|
||||||
import parseTextNote, { toResolved } from '@/nostr/parseTextNote';
|
import parseTextNote, { toResolved } from '@/nostr/parseTextNote';
|
||||||
import useCommands from '@/nostr/useCommands';
|
import useCommands from '@/nostr/useCommands';
|
||||||
import useFollowers from '@/nostr/useFollowers';
|
import useFollowers from '@/nostr/useFollowers';
|
||||||
@@ -72,14 +73,7 @@ const ProfileDisplay: Component<ProfileDisplayProps> = (props) => {
|
|||||||
const { verification, query: verificationQuery } = useVerification(() =>
|
const { verification, query: verificationQuery } = useVerification(() =>
|
||||||
ensureNonNull([profile()?.nip05] as const)(([nip05]) => ({ nip05 })),
|
ensureNonNull([profile()?.nip05] as const)(([nip05]) => ({ nip05 })),
|
||||||
);
|
);
|
||||||
const nip05Identifier = () => {
|
const nip05Identifier = () => parseNip05Address(profile()?.nip05);
|
||||||
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 isVerified = () => verification()?.pubkey === props.pubkey;
|
const isVerified = () => verification()?.pubkey === props.pubkey;
|
||||||
const isMuted = () => isPubkeyMuted(props.pubkey);
|
const isMuted = () => isPubkeyMuted(props.pubkey);
|
||||||
|
|
||||||
|
|||||||
27
src/nostr/parseNip05Address.ts
Normal file
27
src/nostr/parseNip05Address.ts
Normal 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;
|
||||||
Reference in New Issue
Block a user