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 override ApiCredentialsType[] SupportedCredentialTypes => [ApiCredentialsType.Hmac];
public override ApiCredentialsType[] SupportedCredentialTypes => [ApiCredentialsType.HMAC];
public TestAuthProvider(TestCredentials credentials) : base(credentials)
{
@ -95,6 +95,6 @@ namespace CryptoExchange.Net.UnitTests
public TestCredentials(HMACCredential credential) : base(credential) { }
/// <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>
/// HMAC credentials
/// </summary>
public HMACCredential? Hmac
public HMACCredential? HMAC
{
get => (HMACCredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.Hmac);
set => AddOrRemoveCredential(ApiCredentialsType.Hmac, value);
get => (HMACCredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.HMAC);
set => AddOrRemoveCredential(ApiCredentialsType.HMAC, value);
}
/// <summary>
/// RSA credentials
/// </summary>
public RSACredential? Rsa
public RSACredential? RSA
{
get => (RSACredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.Rsa);
set => AddOrRemoveCredential(ApiCredentialsType.Rsa, value);
get => (RSACredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.RSA);
set => AddOrRemoveCredential(ApiCredentialsType.RSA, value);
}
/// <summary>
/// RSA credentials in XML format
/// </summary>
public RSAXmlCredential? RsaXml
public RSAXmlCredential? RSAXml
{
get => (RSAXmlCredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.Rsa);
set => AddOrRemoveCredential(ApiCredentialsType.Rsa, value);
get => (RSAXmlCredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.RSA);
set => AddOrRemoveCredential(ApiCredentialsType.RSA, value);
}
#if NETSTANDARD2_1_OR_GREATER || NET7_0_OR_GREATER
/// <summary>
/// RSA credentials in PEM/Base64 format
/// </summary>
public RSAPemCredential? RsaPem
public RSAPemCredential? RSAPem
{
get => (RSAPemCredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.Rsa);
set => AddOrRemoveCredential(ApiCredentialsType.Rsa, value);
get => (RSAPemCredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.RSA);
set => AddOrRemoveCredential(ApiCredentialsType.RSA, value);
}
#endif
#if NET8_0_OR_GREATER
/// <summary>
/// ED25519 credentials
/// Ed25519 credentials
/// </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);
}
#endif
/// <summary>
/// ECDSA credentials
/// ECDsa credentials
/// </summary>
public ECDSACredential? Ecdsa
public ECDsaCredential? ECDsa
{
get => (ECDSACredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.Ecdsa);
set => AddOrRemoveCredential(ApiCredentialsType.Ecdsa, value);
get => (ECDsaCredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.ECDsa);
set => AddOrRemoveCredential(ApiCredentialsType.ECDsa, value);
}
/// <summary>
@ -111,7 +111,7 @@ namespace CryptoExchange.Net.Authentication
/// <summary>
/// DI constructor
/// </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() { }
/// <summary>

View File

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

View File

@ -318,13 +318,13 @@ namespace CryptoExchange.Net.Authentication
/// <summary>
/// Ed25519 sign the data
/// </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);
/// <summary>
/// Ed25519 sign the data
/// </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 resultBytes = SignatureAlgorithm.Ed25519.Sign(signKey, data);
@ -513,7 +513,7 @@ namespace CryptoExchange.Net.Authentication
/// <returns></returns>
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");
return SignHMACSHA256((Credential as HMACCredential)!, data, outputType);
@ -536,7 +536,7 @@ namespace CryptoExchange.Net.Authentication
/// <returns></returns>
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");
return SignHMACSHA384((Credential as HMACCredential)!, data, outputType);
@ -559,7 +559,7 @@ namespace CryptoExchange.Net.Authentication
/// <returns></returns>
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");
return SignHMACSHA512((Credential as HMACCredential)!, data, outputType);
@ -573,7 +573,7 @@ namespace CryptoExchange.Net.Authentication
/// <returns></returns>
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");
return SignRSASHA256((Credential as RSACredential)!, data, outputType);
@ -587,7 +587,7 @@ namespace CryptoExchange.Net.Authentication
/// <returns></returns>
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");
return SignRSASHA384((Credential as RSACredential)!, data, outputType);
@ -601,7 +601,7 @@ namespace CryptoExchange.Net.Authentication
/// <returns></returns>
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");
return SignRSASHA512((Credential as RSACredential)!, data, outputType);
@ -620,9 +620,9 @@ namespace CryptoExchange.Net.Authentication
public string SignEd25519(byte[] data, SignOutputType? outputType = null)
{
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
}

View File

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

View File

@ -16,7 +16,7 @@ namespace CryptoExchange.Net.Authentication.Signing
{
/// <summary>
/// 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
/// </summary>
public static byte[] EncodeEip721(
@ -64,7 +64,7 @@ namespace CryptoExchange.Net.Authentication.Signing
/// <summary>
/// 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
/// </summary>
public static byte[] EncodeTypedDataRaw(CeTypedDataRaw typedData)