Boltcard integration (#5419)

* Boltcard integration

* Add API for boltcard registration
This commit is contained in:
Nicolas Dorier
2023-12-06 09:17:58 +09:00
committed by GitHub
parent b13f140b86
commit d050c8e3b2
25 changed files with 981 additions and 74 deletions

View File

@@ -0,0 +1,32 @@
#nullable enable
using BTCPayServer.NTag424;
using BTCPayServer.Services;
using static BTCPayServer.Controllers.UIBoltcardController;
using System.Threading.Tasks;
namespace BTCPayServer;
public static class SettingsRepositoryExtensions
{
public static async Task<IssuerKey> GetIssuerKey(this SettingsRepository settingsRepository, BTCPayServerEnvironment env)
{
var settings = await settingsRepository.GetSettingAsync<BoltcardSettings>(nameof(BoltcardSettings));
AESKey issuerKey;
if (settings?.IssuerKey is byte[] bytes)
{
issuerKey = new AESKey(bytes);
}
else
{
issuerKey = env.CheatMode && env.IsDeveloping ? FixedKey() : AESKey.Random();
settings = new BoltcardSettings() { IssuerKey = issuerKey.ToBytes() };
await settingsRepository.UpdateSetting(settings, nameof(BoltcardSettings));
}
return new IssuerKey(issuerKey);
}
internal static AESKey FixedKey()
{
byte[] v = new byte[16];
v[0] = 1;
return new AESKey(v);
}
}