From 1442ae358c0fdef9424da5d067504d1272008b1d Mon Sep 17 00:00:00 2001 From: Firekeeper <0xFirekeeper@gmail.com> Date: Fri, 14 Feb 2025 02:40:36 +0700 Subject: [PATCH] Rotating Secret Keys V2 Support (#131) --- .../Thirdweb.Client/Thirdweb.Client.Tests.cs | 4 ++-- Thirdweb/Thirdweb.Client/ThirdwebClient.cs | 13 +++---------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Thirdweb.Tests/Thirdweb.Client/Thirdweb.Client.Tests.cs b/Thirdweb.Tests/Thirdweb.Client/Thirdweb.Client.Tests.cs index 29f9670..cc62e8a 100644 --- a/Thirdweb.Tests/Thirdweb.Client/Thirdweb.Client.Tests.cs +++ b/Thirdweb.Tests/Thirdweb.Client/Thirdweb.Client.Tests.cs @@ -49,8 +49,8 @@ public void ClientIdAndSecretKeyInitialization() Assert.NotNull(client.ClientId); Assert.NotNull(client.SecretKey); Assert.Null(client.BundleId); - Assert.NotEqual(client.ClientId, clientId); - Assert.Equal(client.ClientId, Utils.ComputeClientIdFromSecretKey(client.SecretKey)); + Assert.Equal(client.ClientId, clientId); + Assert.NotEqual(client.ClientId, Utils.ComputeClientIdFromSecretKey(client.SecretKey)); Assert.Equal(client.SecretKey, this.SecretKey); } diff --git a/Thirdweb/Thirdweb.Client/ThirdwebClient.cs b/Thirdweb/Thirdweb.Client/ThirdwebClient.cs index 62dc2e6..094641c 100644 --- a/Thirdweb/Thirdweb.Client/ThirdwebClient.cs +++ b/Thirdweb/Thirdweb.Client/ThirdwebClient.cs @@ -42,16 +42,9 @@ private ThirdwebClient( throw new InvalidOperationException("ClientId or SecretKey must be provided"); } - if (!string.IsNullOrEmpty(secretKey)) - { - this.ClientId = Utils.ComputeClientIdFromSecretKey(secretKey); - this.SecretKey = secretKey; - } - else - { - this.ClientId = clientId; - } - + // Respects provided clientId if any, otherwise computes it from secretKey + this.ClientId = !string.IsNullOrEmpty(clientId) ? clientId : (string.IsNullOrEmpty(secretKey) ? null : Utils.ComputeClientIdFromSecretKey(secretKey)); + this.SecretKey = secretKey; this.BundleId = bundleId; this.FetchTimeoutOptions = fetchTimeoutOptions ?? new TimeoutOptions();