1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2026-04-13 00:22:22 +00:00
This commit is contained in:
JKorf 2026-03-16 22:02:22 +01:00
parent f56853030e
commit 4a33819f8d
6 changed files with 48 additions and 48 deletions

View File

@ -64,7 +64,7 @@ namespace CryptoExchange.Net.UnitTests
public class TestAuthProvider : AuthenticationProvider<TestCredentials, HMACCredential> public class TestAuthProvider : AuthenticationProvider<TestCredentials, HMACCredential>
{ {
public override ApiCredentialsType[] SupportedCredentialTypes => [ApiCredentialsType.Hmac]; public override ApiCredentialsType[] SupportedCredentialTypes => [ApiCredentialsType.HMAC];
public TestAuthProvider(TestCredentials credentials) : base(credentials) public TestAuthProvider(TestCredentials credentials) : base(credentials)
{ {
@ -95,6 +95,6 @@ namespace CryptoExchange.Net.UnitTests
public TestCredentials(HMACCredential credential) : base(credential) { } public TestCredentials(HMACCredential credential) : base(credential) { }
/// <inheritdoc /> /// <inheritdoc />
public override ApiCredentials Copy() => new TestCredentials(Hmac!); public override ApiCredentials Copy() => new TestCredentials(HMAC!);
} }
} }

View File

@ -22,58 +22,58 @@ namespace CryptoExchange.Net.Authentication
/// <summary> /// <summary>
/// HMAC credentials /// HMAC credentials
/// </summary> /// </summary>
public HMACCredential? Hmac public HMACCredential? HMAC
{ {
get => (HMACCredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.Hmac); get => (HMACCredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.HMAC);
set => AddOrRemoveCredential(ApiCredentialsType.Hmac, value); set => AddOrRemoveCredential(ApiCredentialsType.HMAC, value);
} }
/// <summary> /// <summary>
/// RSA credentials /// RSA credentials
/// </summary> /// </summary>
public RSACredential? Rsa public RSACredential? RSA
{ {
get => (RSACredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.Rsa); get => (RSACredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.RSA);
set => AddOrRemoveCredential(ApiCredentialsType.Rsa, value); set => AddOrRemoveCredential(ApiCredentialsType.RSA, value);
} }
/// <summary> /// <summary>
/// RSA credentials in XML format /// RSA credentials in XML format
/// </summary> /// </summary>
public RSAXmlCredential? RsaXml public RSAXmlCredential? RSAXml
{ {
get => (RSAXmlCredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.Rsa); get => (RSAXmlCredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.RSA);
set => AddOrRemoveCredential(ApiCredentialsType.Rsa, value); set => AddOrRemoveCredential(ApiCredentialsType.RSA, value);
} }
#if NETSTANDARD2_1_OR_GREATER || NET7_0_OR_GREATER #if NETSTANDARD2_1_OR_GREATER || NET7_0_OR_GREATER
/// <summary> /// <summary>
/// RSA credentials in PEM/Base64 format /// RSA credentials in PEM/Base64 format
/// </summary> /// </summary>
public RSAPemCredential? RsaPem public RSAPemCredential? RSAPem
{ {
get => (RSAPemCredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.Rsa); get => (RSAPemCredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.RSA);
set => AddOrRemoveCredential(ApiCredentialsType.Rsa, value); set => AddOrRemoveCredential(ApiCredentialsType.RSA, value);
} }
#endif #endif
#if NET8_0_OR_GREATER #if NET8_0_OR_GREATER
/// <summary> /// <summary>
/// ED25519 credentials /// Ed25519 credentials
/// </summary> /// </summary>
public ED25519Credential? Ed25519 public Ed25519Credential? Ed25519
{ {
get => (ED25519Credential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.Ed25519); get => (Ed25519Credential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.Ed25519);
set => AddOrRemoveCredential(ApiCredentialsType.Ed25519, value); set => AddOrRemoveCredential(ApiCredentialsType.Ed25519, value);
} }
#endif #endif
/// <summary> /// <summary>
/// ECDSA credentials /// ECDsa credentials
/// </summary> /// </summary>
public ECDSACredential? Ecdsa public ECDsaCredential? ECDsa
{ {
get => (ECDSACredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.Ecdsa); get => (ECDsaCredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.ECDsa);
set => AddOrRemoveCredential(ApiCredentialsType.Ecdsa, value); set => AddOrRemoveCredential(ApiCredentialsType.ECDsa, value);
} }
/// <summary> /// <summary>
@ -111,7 +111,7 @@ namespace CryptoExchange.Net.Authentication
/// <summary> /// <summary>
/// DI constructor /// DI constructor
/// </summary> /// </summary>
[Obsolete("Parameterless constructor is only for deserialization purposes and should not be used directly. Use static ApiCredentials.HmacCredentials or similar instead.")] [Obsolete("Parameterless constructor is only for deserialization purposes and should not be used directly.")]
public ApiCredentials() { } public ApiCredentials() { }
/// <summary> /// <summary>

View File

@ -8,19 +8,19 @@
/// <summary> /// <summary>
/// HMAC credentials /// HMAC credentials
/// </summary> /// </summary>
Hmac, HMAC,
/// <summary> /// <summary>
/// RSA credentials /// RSA credentials
/// </summary> /// </summary>
Rsa, RSA,
/// <summary> /// <summary>
/// ED25519 credentials /// Ed25519 credentials
/// </summary> /// </summary>
Ed25519, Ed25519,
/// <summary> /// <summary>
/// ECDSA credentials /// ECDsa credentials
/// </summary> /// </summary>
Ecdsa, ECDsa,
/// <summary> /// <summary>
/// API key credentials /// API key credentials
/// </summary> /// </summary>

View File

@ -318,13 +318,13 @@ namespace CryptoExchange.Net.Authentication
/// <summary> /// <summary>
/// Ed25519 sign the data /// Ed25519 sign the data
/// </summary> /// </summary>
public string SignEd25519(ED25519Credential credential, string data, SignOutputType? outputType = null) public string SignEd25519(Ed25519Credential credential, string data, SignOutputType? outputType = null)
=> SignEd25519(credential, Encoding.ASCII.GetBytes(data), outputType); => SignEd25519(credential, Encoding.ASCII.GetBytes(data), outputType);
/// <summary> /// <summary>
/// Ed25519 sign the data /// Ed25519 sign the data
/// </summary> /// </summary>
public string SignEd25519(ED25519Credential credential, byte[] data, SignOutputType? outputType = null) public string SignEd25519(Ed25519Credential credential, byte[] data, SignOutputType? outputType = null)
{ {
var signKey = credential.GetSigningKey(); var signKey = credential.GetSigningKey();
var resultBytes = SignatureAlgorithm.Ed25519.Sign(signKey, data); var resultBytes = SignatureAlgorithm.Ed25519.Sign(signKey, data);
@ -513,7 +513,7 @@ namespace CryptoExchange.Net.Authentication
/// <returns></returns> /// <returns></returns>
protected string SignHMACSHA256(byte[] data, SignOutputType? outputType = null) protected string SignHMACSHA256(byte[] data, SignOutputType? outputType = null)
{ {
if (Credential.CredentialType != ApiCredentialsType.Hmac) if (Credential.CredentialType != ApiCredentialsType.HMAC)
throw new InvalidOperationException($"Invalid HMAC signing without HMAC credentials provided"); throw new InvalidOperationException($"Invalid HMAC signing without HMAC credentials provided");
return SignHMACSHA256((Credential as HMACCredential)!, data, outputType); return SignHMACSHA256((Credential as HMACCredential)!, data, outputType);
@ -536,7 +536,7 @@ namespace CryptoExchange.Net.Authentication
/// <returns></returns> /// <returns></returns>
protected string SignHMACSHA384(byte[] data, SignOutputType? outputType = null) protected string SignHMACSHA384(byte[] data, SignOutputType? outputType = null)
{ {
if (Credential.CredentialType != ApiCredentialsType.Hmac) if (Credential.CredentialType != ApiCredentialsType.HMAC)
throw new InvalidOperationException($"Invalid HMAC signing without HMAC credentials provided"); throw new InvalidOperationException($"Invalid HMAC signing without HMAC credentials provided");
return SignHMACSHA384((Credential as HMACCredential)!, data, outputType); return SignHMACSHA384((Credential as HMACCredential)!, data, outputType);
@ -559,7 +559,7 @@ namespace CryptoExchange.Net.Authentication
/// <returns></returns> /// <returns></returns>
protected string SignHMACSHA512(byte[] data, SignOutputType? outputType = null) protected string SignHMACSHA512(byte[] data, SignOutputType? outputType = null)
{ {
if (Credential.CredentialType != ApiCredentialsType.Hmac) if (Credential.CredentialType != ApiCredentialsType.HMAC)
throw new InvalidOperationException($"Invalid HMAC signing without HMAC credentials provided"); throw new InvalidOperationException($"Invalid HMAC signing without HMAC credentials provided");
return SignHMACSHA512((Credential as HMACCredential)!, data, outputType); return SignHMACSHA512((Credential as HMACCredential)!, data, outputType);
@ -573,7 +573,7 @@ namespace CryptoExchange.Net.Authentication
/// <returns></returns> /// <returns></returns>
protected string SignRSASHA256(byte[] data, SignOutputType? outputType = null) protected string SignRSASHA256(byte[] data, SignOutputType? outputType = null)
{ {
if (Credential.CredentialType != ApiCredentialsType.Rsa) if (Credential.CredentialType != ApiCredentialsType.RSA)
throw new InvalidOperationException($"Invalid RSA signing without RSA credentials provided"); throw new InvalidOperationException($"Invalid RSA signing without RSA credentials provided");
return SignRSASHA256((Credential as RSACredential)!, data, outputType); return SignRSASHA256((Credential as RSACredential)!, data, outputType);
@ -587,7 +587,7 @@ namespace CryptoExchange.Net.Authentication
/// <returns></returns> /// <returns></returns>
protected string SignRSASHA384(byte[] data, SignOutputType? outputType = null) protected string SignRSASHA384(byte[] data, SignOutputType? outputType = null)
{ {
if (Credential.CredentialType != ApiCredentialsType.Rsa) if (Credential.CredentialType != ApiCredentialsType.RSA)
throw new InvalidOperationException($"Invalid RSA signing without RSA credentials provided"); throw new InvalidOperationException($"Invalid RSA signing without RSA credentials provided");
return SignRSASHA384((Credential as RSACredential)!, data, outputType); return SignRSASHA384((Credential as RSACredential)!, data, outputType);
@ -601,7 +601,7 @@ namespace CryptoExchange.Net.Authentication
/// <returns></returns> /// <returns></returns>
protected string SignRSASHA512(byte[] data, SignOutputType? outputType = null) protected string SignRSASHA512(byte[] data, SignOutputType? outputType = null)
{ {
if (Credential.CredentialType != ApiCredentialsType.Rsa) if (Credential.CredentialType != ApiCredentialsType.RSA)
throw new InvalidOperationException($"Invalid RSA signing without RSA credentials provided"); throw new InvalidOperationException($"Invalid RSA signing without RSA credentials provided");
return SignRSASHA512((Credential as RSACredential)!, data, outputType); return SignRSASHA512((Credential as RSACredential)!, data, outputType);
@ -620,9 +620,9 @@ namespace CryptoExchange.Net.Authentication
public string SignEd25519(byte[] data, SignOutputType? outputType = null) public string SignEd25519(byte[] data, SignOutputType? outputType = null)
{ {
if (Credential.CredentialType != ApiCredentialsType.Ed25519) if (Credential.CredentialType != ApiCredentialsType.Ed25519)
throw new InvalidOperationException($"Invalid ED25519 signing without Ed25519 credentials provided"); throw new InvalidOperationException($"Invalid Ed25519 signing without Ed25519 credentials provided");
return SignEd25519((Credential as ED25519Credential)!, data, outputType); return SignEd25519((Credential as Ed25519Credential)!, data, outputType);
} }
#endif #endif
} }

View File

@ -63,7 +63,7 @@ namespace CryptoExchange.Net.Authentication
public string? Pass { get; set; } public string? Pass { get; set; }
/// <inheritdoc /> /// <inheritdoc />
public override ApiCredentialsType CredentialType => ApiCredentialsType.Hmac; public override ApiCredentialsType CredentialType => ApiCredentialsType.HMAC;
/// <summary> /// <summary>
/// ctor /// ctor
@ -105,7 +105,7 @@ namespace CryptoExchange.Net.Authentication
public string? Pass { get; set; } public string? Pass { get; set; }
/// <inheritdoc /> /// <inheritdoc />
public override ApiCredentialsType CredentialType => ApiCredentialsType.Rsa; public override ApiCredentialsType CredentialType => ApiCredentialsType.RSA;
/// <summary> /// <summary>
/// ctor /// ctor
@ -192,9 +192,9 @@ namespace CryptoExchange.Net.Authentication
#if NET8_0_OR_GREATER #if NET8_0_OR_GREATER
/// <summary> /// <summary>
/// Credentials in ED25519 format /// Credentials in Ed25519 format
/// </summary> /// </summary>
public class ED25519Credential : CredentialPair public class Ed25519Credential : CredentialPair
{ {
private NSec.Cryptography.Key? _signKey; private NSec.Cryptography.Key? _signKey;
@ -216,7 +216,7 @@ namespace CryptoExchange.Net.Authentication
/// <param name="key">Public key</param> /// <param name="key">Public key</param>
/// <param name="privateKey">Private key</param> /// <param name="privateKey">Private key</param>
/// <param name="pass">Passphrase</param> /// <param name="pass">Passphrase</param>
public ED25519Credential(string key, string privateKey, string? pass = null) : base(key) public Ed25519Credential(string key, string privateKey, string? pass = null) : base(key)
{ {
PrivateKey = privateKey; PrivateKey = privateKey;
Pass = pass; Pass = pass;
@ -243,9 +243,9 @@ namespace CryptoExchange.Net.Authentication
#endif #endif
/// <summary> /// <summary>
/// Credentials in ECDSA format /// Credentials in ECDsa format
/// </summary> /// </summary>
public class ECDSACredential : CredentialPair public class ECDsaCredential : CredentialPair
{ {
/// <summary> /// <summary>
/// Private key /// Private key
@ -257,7 +257,7 @@ namespace CryptoExchange.Net.Authentication
public string? Pass { get; set; } public string? Pass { get; set; }
/// <inheritdoc /> /// <inheritdoc />
public override ApiCredentialsType CredentialType => ApiCredentialsType.Ecdsa; public override ApiCredentialsType CredentialType => ApiCredentialsType.ECDsa;
/// <summary> /// <summary>
/// ctor /// ctor
@ -265,7 +265,7 @@ namespace CryptoExchange.Net.Authentication
/// <param name="key">Public key</param> /// <param name="key">Public key</param>
/// <param name="privateKey">Private key</param> /// <param name="privateKey">Private key</param>
/// <param name="pass">Passphrase</param> /// <param name="pass">Passphrase</param>
public ECDSACredential(string key, string privateKey, string? pass = null) : base(key) public ECDsaCredential(string key, string privateKey, string? pass = null) : base(key)
{ {
PrivateKey = privateKey; PrivateKey = privateKey;
Pass = pass; Pass = pass;

View File

@ -16,7 +16,7 @@ namespace CryptoExchange.Net.Authentication.Signing
{ {
/// <summary> /// <summary>
/// Encode EIP712 typed data according to the specification, with the provided primary type, domain fields and message fields. /// Encode EIP712 typed data according to the specification, with the provided primary type, domain fields and message fields.
/// The resulting byte array is the 0x19 0x01 prefix followed by the hash of the domain and the hash of the message, which can be signed with ECDSA secp256k1 to produce a signature that can be verified on chain with EIP712. /// The resulting byte array is the 0x19 0x01 prefix followed by the hash of the domain and the hash of the message, which can be signed with ECDsa secp256k1 to produce a signature that can be verified on chain with EIP712.
/// Note that this implementation does not support all possible EIP712 types, but it should cover most common use cases /// Note that this implementation does not support all possible EIP712 types, but it should cover most common use cases
/// </summary> /// </summary>
public static byte[] EncodeEip721( public static byte[] EncodeEip721(
@ -64,7 +64,7 @@ namespace CryptoExchange.Net.Authentication.Signing
/// <summary> /// <summary>
/// Encode EIP712 typed data according to the specification, with the provided primary type, domain fields and message fields. /// Encode EIP712 typed data according to the specification, with the provided primary type, domain fields and message fields.
/// The resulting byte array is the 0x19 0x01 prefix followed by the hash of the domain and the hash of the message, which can be signed with ECDSA secp256k1 to produce a signature that can be verified on chain with EIP712. /// The resulting byte array is the 0x19 0x01 prefix followed by the hash of the domain and the hash of the message, which can be signed with ECDsa secp256k1 to produce a signature that can be verified on chain with EIP712.
/// Note that this implementation does not support all possible EIP712 types, but it should cover most common use cases /// Note that this implementation does not support all possible EIP712 types, but it should cover most common use cases
/// </summary> /// </summary>
public static byte[] EncodeTypedDataRaw(CeTypedDataRaw typedData) public static byte[] EncodeTypedDataRaw(CeTypedDataRaw typedData)