LNURL updates (#4501)

This commit is contained in:
d11n
2023-01-05 14:41:18 +01:00
committed by GitHub
parent 099d65032a
commit eb90fab640
5 changed files with 17 additions and 21 deletions

View File

@@ -1888,12 +1888,12 @@ namespace BTCPayServer.Tests
Assert.Equal(0.0000001m, fetchedReuqest.MaxSendable.ToDecimal(LightMoneyUnit.BTC)); Assert.Equal(0.0000001m, fetchedReuqest.MaxSendable.ToDecimal(LightMoneyUnit.BTC));
Assert.Equal(0.0000001m, fetchedReuqest.MinSendable.ToDecimal(LightMoneyUnit.BTC)); Assert.Equal(0.0000001m, fetchedReuqest.MinSendable.ToDecimal(LightMoneyUnit.BTC));
await Assert.ThrowsAsync<HttpRequestException>(async () => await Assert.ThrowsAsync<LNUrlException>(async () =>
{ {
await fetchedReuqest.SendRequest(new LightMoney(0.0000002m, LightMoneyUnit.BTC), await fetchedReuqest.SendRequest(new LightMoney(0.0000002m, LightMoneyUnit.BTC),
network, new HttpClient()); network, new HttpClient());
}); });
await Assert.ThrowsAsync<HttpRequestException>(async () => await Assert.ThrowsAsync<LNUrlException>(async () =>
{ {
await fetchedReuqest.SendRequest(new LightMoney(0.00000005m, LightMoneyUnit.BTC), await fetchedReuqest.SendRequest(new LightMoney(0.00000005m, LightMoneyUnit.BTC),
network, new HttpClient()); network, new HttpClient());
@@ -2014,7 +2014,6 @@ namespace BTCPayServer.Tests
var payoutsData = await ctx.Payouts.Where(p => p.PullPaymentDataId == pullPaymentId).ToListAsync(); var payoutsData = await ctx.Payouts.Where(p => p.PullPaymentDataId == pullPaymentId).ToListAsync();
Assert.True(payoutsData.All(p => p.State == PayoutState.Completed)); Assert.True(payoutsData.All(p => p.State == PayoutState.Completed));
}); });
} }
[Fact] [Fact]

View File

@@ -53,7 +53,7 @@
<PackageReference Include="Fido2" Version="2.0.2" /> <PackageReference Include="Fido2" Version="2.0.2" />
<PackageReference Include="Fido2.AspNet" Version="2.0.2" /> <PackageReference Include="Fido2.AspNet" Version="2.0.2" />
<PackageReference Include="HtmlSanitizer" Version="5.0.372" /> <PackageReference Include="HtmlSanitizer" Version="5.0.372" />
<PackageReference Include="LNURL" Version="0.0.27" /> <PackageReference Include="LNURL" Version="0.0.28" />
<PackageReference Include="MailKit" Version="3.3.0" /> <PackageReference Include="MailKit" Version="3.3.0" />
<PackageReference Include="BTCPayServer.NETCore.Plugins.Mvc" Version="1.4.4" /> <PackageReference Include="BTCPayServer.NETCore.Plugins.Mvc" Version="1.4.4" />
<PackageReference Include="QRCoder" Version="1.4.3" /> <PackageReference Include="QRCoder" Version="1.4.3" />

View File

@@ -63,12 +63,12 @@ namespace BTCPayServer
return false; return false;
} }
if (!global::LNURL.LNAuthRequest.VerifyChallenge(sig, pubKey, k1)) if (!LNURL.LNAuthRequest.VerifyChallenge(sig, pubKey, k1))
{ {
return false; return false;
} }
var newCredential = new Fido2Credential() {Name = name, ApplicationUserId = userId, Type = Fido2Credential.CredentialType.LNURLAuth, Blob = pubkeyBytes}; var newCredential = new Fido2Credential {Name = name, ApplicationUserId = userId, Type = Fido2Credential.CredentialType.LNURLAuth, Blob = pubkeyBytes};
await dbContext.Fido2Credentials.AddAsync(newCredential); await dbContext.Fido2Credentials.AddAsync(newCredential);
await dbContext.SaveChangesAsync(); await dbContext.SaveChangesAsync();
@@ -130,7 +130,7 @@ namespace BTCPayServer
{ {
return false; return false;
} }
if (!global::LNURL.LNAuthRequest.VerifyChallenge(sig, pubKey, k1)) if (!LNURL.LNAuthRequest.VerifyChallenge(sig, pubKey, k1))
{ {
return false; return false;
} }

View File

@@ -65,7 +65,7 @@ namespace BTCPayServer
TempData.SetStatusMessageModel(new StatusMessageModel TempData.SetStatusMessageModel(new StatusMessageModel
{ {
Severity = StatusMessageModel.StatusSeverity.Error, Severity = StatusMessageModel.StatusSeverity.Error,
Html = "The lightning node could not be registered." Html = "The Lightning node could not be registered."
}); });
return RedirectToList(); return RedirectToList();
@@ -103,10 +103,10 @@ namespace BTCPayServer
if (await _lnurlAuthService.CompleteCreation(name, userId, if (await _lnurlAuthService.CompleteCreation(name, userId,
ECDSASignature.FromDER(Encoders.Hex.DecodeData(sig)), new PubKey(key))) ECDSASignature.FromDER(Encoders.Hex.DecodeData(sig)), new PubKey(key)))
{ {
return Ok(new LNUrlStatusResponse() { Status = "OK" }); return Ok(new LNUrlStatusResponse { Status = "OK" });
} }
return BadRequest(new LNUrlStatusResponse() return BadRequest(new LNUrlStatusResponse
{ {
Reason = "The challenge could not be verified", Status = "ERROR" Reason = "The challenge could not be verified", Status = "ERROR"
}); });
@@ -127,10 +127,10 @@ namespace BTCPayServer
if (await _lnurlAuthService.CompleteLogin(userId, if (await _lnurlAuthService.CompleteLogin(userId,
ECDSASignature.FromDER(Encoders.Hex.DecodeData(sig)), new PubKey(key))) ECDSASignature.FromDER(Encoders.Hex.DecodeData(sig)), new PubKey(key)))
{ {
return Ok(new LNUrlStatusResponse() { Status = "OK" }); return Ok(new LNUrlStatusResponse { Status = "OK" });
} }
return BadRequest(new LNUrlStatusResponse() return BadRequest(new LNUrlStatusResponse
{ {
Reason = "The challenge could not be verified", Status = "ERROR" Reason = "The challenge could not be verified", Status = "ERROR"
}); });

View File

@@ -3,7 +3,6 @@ using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Abstractions.Constants; using BTCPayServer.Abstractions.Constants;
@@ -17,7 +16,6 @@ using BTCPayServer.Data.Payouts.LightningLike;
using BTCPayServer.Events; using BTCPayServer.Events;
using BTCPayServer.HostedServices; using BTCPayServer.HostedServices;
using BTCPayServer.Lightning; using BTCPayServer.Lightning;
using BTCPayServer.Models.AppViewModels;
using BTCPayServer.Payments; using BTCPayServer.Payments;
using BTCPayServer.Payments.Lightning; using BTCPayServer.Payments.Lightning;
using BTCPayServer.Plugins.PointOfSale.Models; using BTCPayServer.Plugins.PointOfSale.Models;
@@ -31,7 +29,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
using NBitcoin; using NBitcoin;
using NBitcoin.Crypto;
using Newtonsoft.Json; using Newtonsoft.Json;
using MarkPayoutRequest = BTCPayServer.HostedServices.MarkPayoutRequest; using MarkPayoutRequest = BTCPayServer.HostedServices.MarkPayoutRequest;
@@ -528,7 +525,7 @@ namespace BTCPayServer
if ((i.ReceiptOptions?.Enabled ??blob.ReceiptOptions.Enabled ) is true) if ((i.ReceiptOptions?.Enabled ??blob.ReceiptOptions.Enabled ) is true)
{ {
successAction = successAction =
new LNURLPayRequest.LNURLPayRequestCallbackResponse.LNURLPayRequestSuccessActionUrl() new LNURLPayRequest.LNURLPayRequestCallbackResponse.LNURLPayRequestSuccessActionUrl
{ {
Tag = "url", Tag = "url",
Description = "Thank you for your purchase. Here is your receipt", Description = "Thank you for your purchase. Here is your receipt",
@@ -582,16 +579,17 @@ namespace BTCPayServer
return BadRequest(new LNUrlStatusResponse return BadRequest(new LNUrlStatusResponse
{ {
Status = "ERROR", Status = "ERROR",
Reason = "Lightning node could not generate invoice with a VALID description hash" Reason = "Lightning node could not generate invoice with a valid description hash"
}); });
} }
} }
catch (Exception) catch (Exception ex)
{ {
return BadRequest(new LNUrlStatusResponse return BadRequest(new LNUrlStatusResponse
{ {
Status = "ERROR", Status = "ERROR",
Reason = "Lightning node could not generate invoice with description hash" Reason = "Lightning node could not generate invoice with description hash" + (
string.IsNullOrEmpty(ex.Message) ? "" : $": {ex.Message}")
}); });
} }
@@ -638,8 +636,7 @@ namespace BTCPayServer
Status = "ERROR", Reason = "Invoice not in a valid payable state" Status = "ERROR", Reason = "Invoice not in a valid payable state"
}); });
} }
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)] [Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
[HttpGet("~/stores/{storeId}/plugins/lightning-address")] [HttpGet("~/stores/{storeId}/plugins/lightning-address")]