2021-04-28 06:14:15 +02:00
|
|
|
using BTCPayServer.Data;
|
|
|
|
using BTCPayServer.Fido2.Models;
|
2021-04-20 07:06:32 +02:00
|
|
|
using NBXplorer;
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
2021-04-28 06:14:15 +02:00
|
|
|
namespace BTCPayServer.Fido2
|
2021-04-20 07:06:32 +02:00
|
|
|
{
|
|
|
|
public static class Fido2Extensions
|
2023-01-06 14:18:07 +01:00
|
|
|
{
|
2021-11-11 13:03:08 +01:00
|
|
|
public static Fido2CredentialBlob GetFido2Blob(this Fido2Credential credential)
|
2021-04-20 07:06:32 +02:00
|
|
|
{
|
2023-02-21 15:06:34 +09:00
|
|
|
return credential.HasTypedBlob<Fido2CredentialBlob>().GetBlob() ?? new Fido2CredentialBlob();
|
2021-04-20 07:06:32 +02:00
|
|
|
}
|
2023-02-21 15:06:34 +09:00
|
|
|
public static void SetBlob(this Fido2Credential credential, Fido2CredentialBlob descriptor)
|
2021-04-20 07:06:32 +02:00
|
|
|
{
|
2023-02-21 15:06:34 +09:00
|
|
|
var current = credential.GetFido2Blob();
|
|
|
|
var a = JObject.FromObject(current);
|
|
|
|
var b = JObject.FromObject(descriptor);
|
|
|
|
if (JObject.DeepEquals(a, b))
|
|
|
|
return;
|
2021-04-20 07:06:32 +02:00
|
|
|
credential.Type = Fido2Credential.CredentialType.FIDO2;
|
2023-02-21 15:06:34 +09:00
|
|
|
credential.HasTypedBlob<Fido2CredentialBlob>().SetBlob(descriptor);
|
2021-04-20 07:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|