From 2068861bb88b57fcfb3dcd683229763c16853e57 Mon Sep 17 00:00:00 2001 From: Kukks Date: Thu, 6 Apr 2023 10:10:12 +0200 Subject: [PATCH] fix nostr plugin --- .../BTCPayServer.Plugins.NIP05.csproj | 2 +- .../Nip5Controller.cs | 18 ++++++++++++------ .../Nip5StoreSettings.cs | 16 ++++++++-------- .../Views/Nip5/Edit.cshtml | 10 +++++++--- .../Views/Shared/Nip05Nav.cshtml | 2 +- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/Plugins/BTCPayServer.Plugins.NIP05/BTCPayServer.Plugins.NIP05.csproj b/Plugins/BTCPayServer.Plugins.NIP05/BTCPayServer.Plugins.NIP05.csproj index de50433..0eb6d77 100644 --- a/Plugins/BTCPayServer.Plugins.NIP05/BTCPayServer.Plugins.NIP05.csproj +++ b/Plugins/BTCPayServer.Plugins.NIP05/BTCPayServer.Plugins.NIP05.csproj @@ -11,7 +11,7 @@ Nostr Allows you to verify your nostr account with NIP5 and zap like the rest of the crazies - 1.0.4 + 1.0.5 diff --git a/Plugins/BTCPayServer.Plugins.NIP05/Nip5Controller.cs b/Plugins/BTCPayServer.Plugins.NIP05/Nip5Controller.cs index caabe4c..4b7527a 100644 --- a/Plugins/BTCPayServer.Plugins.NIP05/Nip5Controller.cs +++ b/Plugins/BTCPayServer.Plugins.NIP05/Nip5Controller.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Caching.Memory; +using NBitcoin.DataEncoders; using NBitcoin.Secp256k1; using NNostr.Client; using NNostr.Client.Protocols; @@ -66,10 +67,14 @@ public class Nip5Controller : Controller { try { - - var note = (NIP19.NosteProfileNote)settings.PubKey.FromNIP19Note() ; - settings.PubKey = note.PubKey; - settings.Relays = (settings.Relays ?? new string[0])?.Concat(note.Relays).ToArray(); + if (!HexEncoder.IsWellFormed(settings.PubKey)) + { + + var note = (NIP19.NosteProfileNote) settings.PubKey.FromNIP19Note(); + settings.PubKey = note.PubKey; + settings.Relays = (settings.Relays ?? Array.Empty())?.Concat(note.Relays).ToArray(); + + } } catch (Exception) { @@ -100,7 +105,8 @@ k = settings.PrivateKey.FromNIP19Nsec(); k = NostrExtensions.ParseKey(settings.PrivateKey); } - + + settings.PrivateKey = k.ToHex(); if (string.IsNullOrEmpty(settings.PubKey)) { @@ -113,7 +119,7 @@ k = settings.PrivateKey.FromNIP19Nsec(); catch (Exception e) { - ModelState.AddModelError(nameof(settings.PubKey), "invalid private key"); + ModelState.AddModelError(nameof(settings.PrivateKey), "invalid private key"); } } diff --git a/Plugins/BTCPayServer.Plugins.NIP05/Nip5StoreSettings.cs b/Plugins/BTCPayServer.Plugins.NIP05/Nip5StoreSettings.cs index 58130ce..2b0e28a 100644 --- a/Plugins/BTCPayServer.Plugins.NIP05/Nip5StoreSettings.cs +++ b/Plugins/BTCPayServer.Plugins.NIP05/Nip5StoreSettings.cs @@ -3,13 +3,13 @@ using System.ComponentModel.DataAnnotations; namespace BTCPayServer.Plugins.NIP05 { -} + public class Nip5StoreSettings + { + [Required] public string PubKey { get; set; } + + public string? PrivateKey { get; set; } + [Required] public string Name { get; set; } -public class Nip5StoreSettings -{ - [Required] public string PubKey { get; set; } - public string PrivateKey { get; set; } - [Required] public string Name { get; set; } - - public string[]? Relays { get; set; } + public string[]? Relays { get; set; } + } } \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.NIP05/Views/Nip5/Edit.cshtml b/Plugins/BTCPayServer.Plugins.NIP05/Views/Nip5/Edit.cshtml index dca6d5b..2f28f53 100644 --- a/Plugins/BTCPayServer.Plugins.NIP05/Views/Nip5/Edit.cshtml +++ b/Plugins/BTCPayServer.Plugins.NIP05/Views/Nip5/Edit.cshtml @@ -1,6 +1,9 @@ @using BTCPayServer.Abstractions.Extensions +@using BTCPayServer.Abstractions.TagHelpers @using Microsoft.AspNetCore.Mvc.TagHelpers -@model Nip5StoreSettings +@using BTCPayServer.Abstractions.Contracts +@model BTCPayServer.Plugins.NIP05.Nip5StoreSettings +@inject IScopeProvider ScopeProvider @{ ViewData.SetActivePage("Nostr", "Nostr", "Nostr"); } @@ -26,8 +29,9 @@
- -

You'll also need to enable a lightning address with the same name.

+ +

You'll also need to enable a lightning address with the same name.

+
diff --git a/Plugins/BTCPayServer.Plugins.NIP05/Views/Shared/Nip05Nav.cshtml b/Plugins/BTCPayServer.Plugins.NIP05/Views/Shared/Nip05Nav.cshtml index 31d9260..f6ef3cf 100644 --- a/Plugins/BTCPayServer.Plugins.NIP05/Views/Shared/Nip05Nav.cshtml +++ b/Plugins/BTCPayServer.Plugins.NIP05/Views/Shared/Nip05Nav.cshtml @@ -13,7 +13,7 @@ permission="@Policies.CanModifyStoreSettings"> - NIP05 + Nostr }