mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Boltcard integration (#5419)
* Boltcard integration * Add API for boltcard registration
This commit is contained in:
32
BTCPayServer/Extensions/SettingsRepositoryExtensions.cs
Normal file
32
BTCPayServer/Extensions/SettingsRepositoryExtensions.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user