Skip to content

Commit abe39c0

Browse files
committed
Update to match new rotating secret key model
1 parent 6b4afc1 commit abe39c0

File tree

4 files changed

+11
-34
lines changed

4 files changed

+11
-34
lines changed

Thirdweb.Tests/Thirdweb.Client/Thirdweb.Client.Tests.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ public void NoSecretKeyNoClientId()
1515
public void SecretKeyInitialization()
1616
{
1717
var client = ThirdwebClient.Create(secretKey: this.SecretKey);
18-
Assert.NotNull(client.ClientId);
1918
Assert.NotNull(client.SecretKey);
2019
Assert.Null(client.BundleId);
21-
Assert.Equal(client.ClientId, Utils.ComputeClientIdFromSecretKey(client.SecretKey));
20+
Assert.Null(client.ClientId);
2221
Assert.Equal(client.SecretKey, this.SecretKey);
2322
}
2423

@@ -49,8 +48,7 @@ public void ClientIdAndSecretKeyInitialization()
4948
Assert.NotNull(client.ClientId);
5049
Assert.NotNull(client.SecretKey);
5150
Assert.Null(client.BundleId);
52-
Assert.NotEqual(client.ClientId, clientId);
53-
Assert.Equal(client.ClientId, Utils.ComputeClientIdFromSecretKey(client.SecretKey));
51+
Assert.Equal(client.ClientId, clientId);
5452
Assert.Equal(client.SecretKey, this.SecretKey);
5553
}
5654

@@ -74,10 +72,10 @@ public void SecretKeyAndBundleIdInitialization()
7472
var client = ThirdwebClient.Create(secretKey: this.SecretKey, bundleId: bundleId);
7573
Assert.NotNull(client.SecretKey);
7674
Assert.NotNull(client.BundleId);
77-
Assert.NotNull(client.ClientId);
75+
Assert.Null(client.ClientId);
7876
Assert.Equal(client.SecretKey, this.SecretKey);
7977
Assert.Equal(client.BundleId, bundleId);
80-
Assert.Equal(client.ClientId, Utils.ComputeClientIdFromSecretKey(client.SecretKey));
78+
Assert.Null(client.ClientId);
8179
}
8280

8381
[Fact(Timeout = 120000)]

Thirdweb.Tests/Thirdweb.Utils/Thirdweb.Utils.Tests.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ public class UtilsTests : BaseTests
88
public UtilsTests(ITestOutputHelper output)
99
: base(output) { }
1010

11-
[Fact(Timeout = 120000)]
12-
public void ComputeClientIdFromSecretKey()
13-
{
14-
Assert.True(Utils.ComputeClientIdFromSecretKey(this.SecretKey).Length == 32);
15-
}
16-
1711
[Fact(Timeout = 120000)]
1812
public void HexConcat()
1913
{

Thirdweb/Thirdweb.Client/ThirdwebClient.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ private ThirdwebClient(
4444

4545
if (!string.IsNullOrEmpty(secretKey))
4646
{
47-
this.ClientId = Utils.ComputeClientIdFromSecretKey(secretKey);
4847
this.SecretKey = secretKey;
4948
}
50-
else
49+
50+
if (!string.IsNullOrEmpty(clientId))
5151
{
5252
this.ClientId = clientId;
5353
}
@@ -61,9 +61,12 @@ private ThirdwebClient(
6161
{ "x-sdk-name", sdkName ?? "Thirdweb.NET" },
6262
{ "x-sdk-os", sdkOs ?? System.Runtime.InteropServices.RuntimeInformation.OSDescription },
6363
{ "x-sdk-platform", sdkPlatform ?? "dotnet" },
64-
{ "x-sdk-version", sdkVersion ?? Constants.VERSION },
65-
{ "x-client-id", this.ClientId },
64+
{ "x-sdk-version", sdkVersion ?? Constants.VERSION }
6665
};
66+
if (!string.IsNullOrEmpty(this.ClientId))
67+
{
68+
defaultHeaders.Add("x-client-id", this.ClientId);
69+
}
6770
if (!string.IsNullOrEmpty(this.BundleId))
6871
{
6972
defaultHeaders.Add("x-bundle-id", this.BundleId);

Thirdweb/Thirdweb.Utils/Utils.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Globalization;
22
using System.Numerics;
3-
using System.Security.Cryptography;
43
using System.Text;
54
using System.Text.RegularExpressions;
65
using ADRaffy.ENSNormalize;
@@ -31,23 +30,6 @@ public static partial class Utils
3130
private static readonly Dictionary<string, string> _ensCache = new();
3231
private static readonly List<string[]> _errorSubstringsComposite = new() { new string[] { "account", "not found!" }, new[] { "wrong", "chainid" } };
3332

34-
/// <summary>
35-
/// Computes the client ID from the given secret key.
36-
/// </summary>
37-
/// <param name="secretKey">The secret key.</param>
38-
/// <returns>The computed client ID.</returns>
39-
public static string ComputeClientIdFromSecretKey(string secretKey)
40-
{
41-
#if NETSTANDARD
42-
using var sha256 = SHA256.Create();
43-
var hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(secretKey));
44-
return BitConverter.ToString(hash).Replace("-", "").ToLower()[..32];
45-
#else
46-
var hash = SHA256.HashData(Encoding.UTF8.GetBytes(secretKey));
47-
return BitConverter.ToString(hash).Replace("-", "").ToLower()[..32];
48-
#endif
49-
}
50-
5133
// public static byte[] StringToSha256(string bytes)
5234
// {
5335
// #if NETSTANDARD

0 commit comments

Comments
 (0)