add qr wipe option

This commit is contained in:
Kukks 2024-03-11 08:55:37 +01:00
parent 4adfcb2de4
commit b46bf8c910
No known key found for this signature in database
GPG key ID: 8E5530D9D1C93097
4 changed files with 31 additions and 3 deletions

View file

@ -9,11 +9,14 @@ using BTCPayServer.Controllers.Greenfield;
using BTCPayServer.Data; using BTCPayServer.Data;
using BTCPayServer.HostedServices; using BTCPayServer.HostedServices;
using BTCPayServer.Models; using BTCPayServer.Models;
using BTCPayServer.NTag424;
using BTCPayServer.Plugins.BoltcardBalance.ViewModels; using BTCPayServer.Plugins.BoltcardBalance.ViewModels;
using BTCPayServer.Plugins.BoltcardFactory; using BTCPayServer.Plugins.BoltcardFactory;
using BTCPayServer.Services; using BTCPayServer.Services;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using NBitcoin.DataEncoders;
using Newtonsoft.Json.Linq;
namespace BTCPayServer.Plugins.BoltcardBalance.Controllers namespace BTCPayServer.Plugins.BoltcardBalance.Controllers
{ {
@ -59,12 +62,14 @@ namespace BTCPayServer.Plugins.BoltcardBalance.Controllers
var registration = await _dbContextFactory.GetBoltcardRegistration(issuerKey, boltData, true); var registration = await _dbContextFactory.GetBoltcardRegistration(issuerKey, boltData, true);
if (registration is null) if (registration is null)
return NotFound(); return NotFound();
return await GetBalanceView(registration.PullPaymentId, p); return await GetBalanceView(registration, p, issuerKey);
} }
[NonAction] [NonAction]
public async Task<IActionResult> GetBalanceView(string ppId, string p) public async Task<IActionResult> GetBalanceView(BoltcardDataExtensions.BoltcardRegistration registration, string p, IssuerKey issuerKey)
{ {
using var ctx = _dbContextFactory.CreateContext(); var ppId = registration.PullPaymentId;
var boltCardKeys = issuerKey.CreatePullPaymentCardKey(registration.UId, registration.Version, ppId).DeriveBoltcardKeys(issuerKey);
await using var ctx = _dbContextFactory.CreateContext();
var pp = await ctx.PullPayments.FindAsync(ppId); var pp = await ctx.PullPayments.FindAsync(ppId);
if (pp is null) if (pp is null)
return NotFound(); return NotFound();
@ -91,6 +96,17 @@ namespace BTCPayServer.Plugins.BoltcardBalance.Controllers
LNUrlBech32 = bech32LNUrl.AbsoluteUri, LNUrlBech32 = bech32LNUrl.AbsoluteUri,
LNUrlPay = Url.Action(nameof(UIBoltcardController.GetPayRequest), "UIBoltcard", new { p }, "lnurlp"), LNUrlPay = Url.Action(nameof(UIBoltcardController.GetPayRequest), "UIBoltcard", new { p }, "lnurlp"),
BoltcardKeysResetLink = $"boltcard://reset?url={GetBoltcardDeeplinkUrl(pp.Id, OnExistingBehavior.KeepVersion)}", BoltcardKeysResetLink = $"boltcard://reset?url={GetBoltcardDeeplinkUrl(pp.Id, OnExistingBehavior.KeepVersion)}",
WipeData = JObject.FromObject(new
{
version = registration.Version,
action = "wipe",
K0 = Encoders.Hex.EncodeData(boltCardKeys.AppMasterKey.ToBytes()).ToUpperInvariant(),
K1 = Encoders.Hex.EncodeData(boltCardKeys.EncryptionKey.ToBytes()).ToUpperInvariant(),
K2 = Encoders.Hex.EncodeData(boltCardKeys.AuthenticationKey.ToBytes()).ToUpperInvariant(),
K3 = Encoders.Hex.EncodeData(boltCardKeys.K3.ToBytes()).ToUpperInvariant(),
K4 = Encoders.Hex.EncodeData(boltCardKeys.K4.ToBytes()).ToUpperInvariant(),
}).ToString(Newtonsoft.Json.Formatting.None),
PullPaymentLink = Url.Action(nameof(UIPullPaymentController.ViewPullPayment), "UIPullPayment", new { pullPaymentId = pp.Id }, Request.Scheme, Request.Host.ToString()) PullPaymentLink = Url.Action(nameof(UIPullPaymentController.ViewPullPayment), "UIPullPayment", new { pullPaymentId = pp.Id }, Request.Scheme, Request.Host.ToString())
}; };
foreach (var payout in payouts) foreach (var payout in payouts)

View file

@ -21,5 +21,6 @@ namespace BTCPayServer.Plugins.BoltcardBalance.ViewModels
public string PullPaymentLink { get; set; } public string PullPaymentLink { get; set; }
public string LNUrlPay { get; set; } public string LNUrlPay { get; set; }
public string WipeData{ get; set; }
} }
} }

View file

@ -38,6 +38,11 @@
<div class="boltcard-reset boltcard-details mt-3 mt-sm-0 w-100 text-center"> <div class="boltcard-reset boltcard-details mt-3 mt-sm-0 w-100 text-center">
<a class="btn btn-outline-danger" href="@Model.BoltcardKeysResetLink">Reset Boltcard</a> <a class="btn btn-outline-danger" href="@Model.BoltcardKeysResetLink">Reset Boltcard</a>
<p class="text-secondary mt-2">Requires installing the <a href="https://play.google.com/store/apps/details?id=com.lightningnfcapp&hl=en&gl=US">Bolt Card Creator app</a></p> <p class="text-secondary mt-2">Requires installing the <a href="https://play.google.com/store/apps/details?id=com.lightningnfcapp&hl=en&gl=US">Bolt Card Creator app</a></p>
<button type="button" class="btn btn-link" id="show-wipe-qr">Show QR instead</button>
<div id="wipe-qr" class="d-none">
<vc:qr-code data="@Model.WipeData" />
</div>
</div> </div>
</div> </div>

View file

@ -216,6 +216,12 @@
document.querySelector(".boltcard-reset").classList.add("d-none"); document.querySelector(".boltcard-reset").classList.add("d-none");
} }
}); });
delegate('click', "#show-wipe-qr", ()=>{
document.getElementById("wipe-qr").classList.remove("d-none");
document.getElementById("show-wipe-qr").classList.add("d-none");
});
} }
catch (e) { catch (e) {
handleError(e); handleError(e);