From 4a33819f8dc27433132b71eb5cfb8bdfaaf28c20 Mon Sep 17 00:00:00 2001 From: JKorf Date: Mon, 16 Mar 2026 22:02:22 +0100 Subject: [PATCH] wip --- .../TestImplementations/TestBaseClient.cs | 4 +- .../Authentication/ApiCredentials.cs | 40 +++++++++---------- .../Authentication/ApiCredentialsType.cs | 10 ++--- .../Authentication/AuthenticationProvider.cs | 20 +++++----- .../Authentication/CredentialPair.cs | 18 ++++----- .../Signing/CeEip712TypedDataEncoder.cs | 4 +- 6 files changed, 48 insertions(+), 48 deletions(-) diff --git a/CryptoExchange.Net.UnitTests/TestImplementations/TestBaseClient.cs b/CryptoExchange.Net.UnitTests/TestImplementations/TestBaseClient.cs index ede8a9f..d43ccf8 100644 --- a/CryptoExchange.Net.UnitTests/TestImplementations/TestBaseClient.cs +++ b/CryptoExchange.Net.UnitTests/TestImplementations/TestBaseClient.cs @@ -64,7 +64,7 @@ namespace CryptoExchange.Net.UnitTests public class TestAuthProvider : AuthenticationProvider { - 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) { } /// - public override ApiCredentials Copy() => new TestCredentials(Hmac!); + public override ApiCredentials Copy() => new TestCredentials(HMAC!); } } diff --git a/CryptoExchange.Net/Authentication/ApiCredentials.cs b/CryptoExchange.Net/Authentication/ApiCredentials.cs index 5476462..ae2f506 100644 --- a/CryptoExchange.Net/Authentication/ApiCredentials.cs +++ b/CryptoExchange.Net/Authentication/ApiCredentials.cs @@ -22,58 +22,58 @@ namespace CryptoExchange.Net.Authentication /// /// HMAC credentials /// - 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); } /// /// RSA credentials /// - 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); } /// /// RSA credentials in XML format /// - 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 /// /// RSA credentials in PEM/Base64 format /// - 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 /// - /// ED25519 credentials + /// Ed25519 credentials /// - 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 /// - /// ECDSA credentials + /// ECDsa credentials /// - 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); } /// @@ -111,7 +111,7 @@ namespace CryptoExchange.Net.Authentication /// /// DI constructor /// - [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() { } /// diff --git a/CryptoExchange.Net/Authentication/ApiCredentialsType.cs b/CryptoExchange.Net/Authentication/ApiCredentialsType.cs index b60114f..d4367a8 100644 --- a/CryptoExchange.Net/Authentication/ApiCredentialsType.cs +++ b/CryptoExchange.Net/Authentication/ApiCredentialsType.cs @@ -8,19 +8,19 @@ /// /// HMAC credentials /// - Hmac, + HMAC, /// /// RSA credentials /// - Rsa, + RSA, /// - /// ED25519 credentials + /// Ed25519 credentials /// Ed25519, /// - /// ECDSA credentials + /// ECDsa credentials /// - Ecdsa, + ECDsa, /// /// API key credentials /// diff --git a/CryptoExchange.Net/Authentication/AuthenticationProvider.cs b/CryptoExchange.Net/Authentication/AuthenticationProvider.cs index c85aafb..35cccd8 100644 --- a/CryptoExchange.Net/Authentication/AuthenticationProvider.cs +++ b/CryptoExchange.Net/Authentication/AuthenticationProvider.cs @@ -318,13 +318,13 @@ namespace CryptoExchange.Net.Authentication /// /// Ed25519 sign the data /// - 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); /// /// Ed25519 sign the data /// - 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 } diff --git a/CryptoExchange.Net/Authentication/CredentialPair.cs b/CryptoExchange.Net/Authentication/CredentialPair.cs index 4368591..231dc2a 100644 --- a/CryptoExchange.Net/Authentication/CredentialPair.cs +++ b/CryptoExchange.Net/Authentication/CredentialPair.cs @@ -63,7 +63,7 @@ namespace CryptoExchange.Net.Authentication public string? Pass { get; set; } /// - public override ApiCredentialsType CredentialType => ApiCredentialsType.Hmac; + public override ApiCredentialsType CredentialType => ApiCredentialsType.HMAC; /// /// ctor @@ -105,7 +105,7 @@ namespace CryptoExchange.Net.Authentication public string? Pass { get; set; } /// - public override ApiCredentialsType CredentialType => ApiCredentialsType.Rsa; + public override ApiCredentialsType CredentialType => ApiCredentialsType.RSA; /// /// ctor @@ -192,9 +192,9 @@ namespace CryptoExchange.Net.Authentication #if NET8_0_OR_GREATER /// - /// Credentials in ED25519 format + /// Credentials in Ed25519 format /// - public class ED25519Credential : CredentialPair + public class Ed25519Credential : CredentialPair { private NSec.Cryptography.Key? _signKey; @@ -216,7 +216,7 @@ namespace CryptoExchange.Net.Authentication /// Public key /// Private key /// Passphrase - 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 /// - /// Credentials in ECDSA format + /// Credentials in ECDsa format /// - public class ECDSACredential : CredentialPair + public class ECDsaCredential : CredentialPair { /// /// Private key @@ -257,7 +257,7 @@ namespace CryptoExchange.Net.Authentication public string? Pass { get; set; } /// - public override ApiCredentialsType CredentialType => ApiCredentialsType.Ecdsa; + public override ApiCredentialsType CredentialType => ApiCredentialsType.ECDsa; /// /// ctor @@ -265,7 +265,7 @@ namespace CryptoExchange.Net.Authentication /// Public key /// Private key /// Passphrase - 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; diff --git a/CryptoExchange.Net/Authentication/Signing/CeEip712TypedDataEncoder.cs b/CryptoExchange.Net/Authentication/Signing/CeEip712TypedDataEncoder.cs index c81b1e3..086c6b6 100644 --- a/CryptoExchange.Net/Authentication/Signing/CeEip712TypedDataEncoder.cs +++ b/CryptoExchange.Net/Authentication/Signing/CeEip712TypedDataEncoder.cs @@ -16,7 +16,7 @@ namespace CryptoExchange.Net.Authentication.Signing { /// /// 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 /// public static byte[] EncodeEip721( @@ -64,7 +64,7 @@ namespace CryptoExchange.Net.Authentication.Signing /// /// 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 /// public static byte[] EncodeTypedDataRaw(CeTypedDataRaw typedData)