btcpayserver/BTCPayServer/APDUVaultTransport.cs
Nicolas Dorier d050c8e3b2
Boltcard integration (#5419)
* Boltcard integration

* Add API for boltcard registration
2023-12-06 09:17:58 +09:00

43 lines
1.3 KiB
C#

using Newtonsoft.Json.Linq;
using System.Net.WebSockets;
using System.Threading.Tasks;
using System.Threading;
using BTCPayServer.NTag424;
using NBitcoin.DataEncoders;
using System;
using SocketIOClient;
namespace BTCPayServer
{
public class APDUVaultTransport : IAPDUTransport
{
private readonly VaultClient _vaultClient;
public APDUVaultTransport(VaultClient vaultClient)
{
_vaultClient = vaultClient;
}
public async Task WaitForCard(CancellationToken cancellationToken)
{
await _vaultClient.SendVaultRequest("/wait-for-card", null, cancellationToken);
}
public async Task WaitForRemoved(CancellationToken cancellationToken)
{
await _vaultClient.SendVaultRequest("/wait-for-disconnected", null, cancellationToken);
}
public async Task<NtagResponse> SendAPDU(byte[] apdu, CancellationToken cancellationToken)
{
var resp = await _vaultClient.SendVaultRequest("/",
new JObject()
{
["apdu"] = Encoders.Hex.EncodeData(apdu)
}, cancellationToken);
var data = Encoders.Hex.DecodeData(resp["data"].Value<string>());
return new NtagResponse(data, resp["status"].Value<ushort>());
}
}
}