mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 09:54:30 +01:00
d050c8e3b2
* Boltcard integration * Add API for boltcard registration
43 lines
1.3 KiB
C#
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>());
|
|
}
|
|
}
|
|
}
|