support npub, nprofile imports for nip5

This commit is contained in:
Kukks
2023-03-15 10:11:33 +01:00
parent 2f43abcdf4
commit 43c41b7e08
2 changed files with 36 additions and 2 deletions

View File

@@ -11,7 +11,7 @@
<PropertyGroup>
<Product>Nostr NIP5</Product>
<Description>Allows you to verify your nostr account</Description>
<Version>1.0.2</Version>
<Version>1.0.3</Version>
</PropertyGroup>
<!-- Plugin development properties -->
<PropertyGroup>
@@ -37,4 +37,7 @@
<ItemGroup>
<Folder Include="Resources" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NNostr.Client" Version="0.0.24" />
</ItemGroup>
</Project>

View File

@@ -10,6 +10,8 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using NNostr.Client;
using NNostr.Client.Protocols;
namespace BTCPayServer.Plugins.NIP05;
@@ -54,13 +56,42 @@ public class Nip5Controller : Controller
return RedirectToAction("Edit", new {storeId});
}
try
{
settings.PubKey = settings.PubKey.Trim();
settings.PubKey = settings.PubKey.FromNIP19Npub().ToHex();
}
catch (Exception)
{
try
{
var note = (NIP19.NosteProfileNote)settings.PubKey.FromNIP19Note() ;
settings.PubKey = note.PubKey;
settings.Relays = (settings.Relays ?? new string[0])?.Concat(note.Relays).ToArray();
}
catch (Exception)
{
}
}
try
{
NostrExtensions.ParsePubKey(settings.PubKey);
}
catch (Exception e)
{
ModelState.AddModelError(nameof(settings.PubKey), "invalid public key");
}
if (!ModelState.IsValid)
{
return View(settings);
}
settings.Relays = settings.Relays
?.Where(s => !string.IsNullOrEmpty(s) && Uri.TryCreate(s, UriKind.Absolute, out _)).ToArray();
?.Where(s => !string.IsNullOrEmpty(s) && Uri.TryCreate(s, UriKind.Absolute, out _)).Distinct().ToArray();
var found = await Get(settings.Name.ToLowerInvariant());
if (found.storeId is not null && storeId != found.storeId)
{