mirror of
https://github.com/lumina-rocks/lumina.git
synced 2026-04-17 02:47:06 +02:00
Refactor NIP05 verification logic: move verifyNIP05 function to nip05.ts and clean up NIP05Verification component
This commit is contained in:
@@ -1,45 +1,13 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { CheckCircle2, XCircle, Loader2 } from 'lucide-react';
|
||||
import { verifyNIP05 } from '@/lib/nip05';
|
||||
|
||||
interface NIP05VerificationProps {
|
||||
nip05: string;
|
||||
pubkey: string;
|
||||
}
|
||||
|
||||
async function verifyNIP05(nip05: string, pubkey: string): Promise<boolean> {
|
||||
try {
|
||||
// Parse the NIP-05 identifier (name@domain.com)
|
||||
const [name, domain] = nip05.split('@');
|
||||
if (!name || !domain) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fetch the .well-known/nostr.json file
|
||||
const url = `https://${domain}/.well-known/nostr.json?name=${encodeURIComponent(name)}`;
|
||||
const response = await fetch(url, {
|
||||
signal: AbortSignal.timeout(5000),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
// Check if the pubkey matches
|
||||
const verifiedPubkey = data.names?.[name];
|
||||
if (!verifiedPubkey) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compare pubkeys
|
||||
return verifiedPubkey.toLowerCase() === pubkey.toLowerCase();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function NIP05Verification({ nip05, pubkey }: NIP05VerificationProps) {
|
||||
const { data: isVerified, isLoading } = useQuery({
|
||||
queryKey: ['nip05-verification', nip05, pubkey],
|
||||
|
||||
@@ -33,6 +33,17 @@ export async function verifyAndGetPubkey(nip05: string): Promise<string | null>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that a NIP-05 identifier matches the given pubkey
|
||||
*/
|
||||
export async function verifyNIP05(nip05: string, pubkey: string): Promise<boolean> {
|
||||
const verifiedPubkey = await verifyAndGetPubkey(nip05);
|
||||
if (!verifiedPubkey) {
|
||||
return false;
|
||||
}
|
||||
return verifiedPubkey.toLowerCase() === pubkey.toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string looks like a NIP-05 identifier
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user