Refactor NIP-05 verification: extract handle-fetching logic into reusable NostrFetcherTrait and enhance UI to display all verified handles with improved feedback.

This commit is contained in:
HolgerHatGarKeineNode
2026-01-23 17:09:00 +01:00
parent dfb1c3fa0f
commit 4b9ad0f6ab
5 changed files with 115 additions and 77 deletions

View File

@@ -12,6 +12,37 @@ use swentel\nostr\Subscription\Subscription;
trait NostrFetcherTrait
{
/**
* Get all NIP-05 handles for a given pubkey from nostr.json
*
* @param string $pubkey The public key in hex format
* @return array Array of handles associated with the pubkey
*/
public function getNip05HandlesForPubkey(string $pubkey): array
{
try {
$response = \Illuminate\Support\Facades\Http::get(
'https://einundzwanzig.space/.well-known/nostr.json',
);
$data = $response->json();
if (! isset($data['names'])) {
return [];
}
$handles = [];
foreach ($data['names'] as $handle => $handlePubkey) {
if ($handlePubkey === $pubkey) {
$handles[] = $handle;
}
}
return $handles;
} catch (\Exception) {
return [];
}
}
public function fetchProfile($npubs)
{
$hex = collect([]);