Skip to content

Commit 5e33c5d

Browse files
committed
Merge branch 'main' into firekeeper/7702-hackathon
2 parents f9eca66 + 869e48c commit 5e33c5d

File tree

11 files changed

+154
-131
lines changed

11 files changed

+154
-131
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
4-
<DefaultVersion>2.17.0</DefaultVersion>
4+
<DefaultVersion>2.17.2</DefaultVersion>
55
<DefaultTargetFrameworks>netstandard2.1;net6.0;net7.0;net8.0</DefaultTargetFrameworks>
66
</PropertyGroup>
77

Lines changed: 99 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
using System.Numerics;
1+
// using System.Numerics;
22
using Thirdweb.AI;
33

44
namespace Thirdweb.Tests.AI;
55

66
public class NebulaTests : BaseTests
77
{
8-
private const string NEBULA_TEST_CONTRACT = "0xe2cb0eb5147b42095c2FfA6F7ec953bb0bE347D8";
9-
private const string NEBULA_TEST_USDC_ADDRESS = "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238";
10-
private const int NEBULA_TEST_CHAIN = 11155111;
8+
// private const string NEBULA_TEST_CONTRACT = "0xe2cb0eb5147b42095c2FfA6F7ec953bb0bE347D8";
9+
// private const string NEBULA_TEST_USDC_ADDRESS = "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238";
10+
// private const int NEBULA_TEST_CHAIN = 11155111;
1111

1212
public NebulaTests(ITestOutputHelper output)
1313
: base(output) { }
@@ -33,104 +33,104 @@ public async Task Create_ResumesSession()
3333
Assert.Equal(sessionId, nebula.SessionId);
3434
}
3535

36-
[Fact(Timeout = 120000)]
37-
public async Task Chat_Single_ReturnsResponse()
38-
{
39-
var nebula = await ThirdwebNebula.Create(this.Client);
40-
var response = await nebula.Chat(
41-
message: "What's the symbol of this contract?",
42-
context: new NebulaContext(contractAddresses: new List<string> { NEBULA_TEST_CONTRACT }, chainIds: new List<BigInteger> { NEBULA_TEST_CHAIN })
43-
);
44-
Assert.NotNull(response);
45-
Assert.NotNull(response.Message);
46-
Assert.Contains("CAT", response.Message);
47-
}
36+
// [Fact(Timeout = 120000)]
37+
// public async Task Chat_Single_ReturnsResponse()
38+
// {
39+
// var nebula = await ThirdwebNebula.Create(this.Client);
40+
// var response = await nebula.Chat(
41+
// message: "What's the symbol of this contract?",
42+
// context: new NebulaContext(contractAddresses: new List<string> { NEBULA_TEST_CONTRACT }, chainIds: new List<BigInteger> { NEBULA_TEST_CHAIN })
43+
// );
44+
// Assert.NotNull(response);
45+
// Assert.NotNull(response.Message);
46+
// Assert.Contains("CAT", response.Message);
47+
// }
4848

49-
[Fact(Timeout = 120000)]
50-
public async Task Chat_Single_NoContext_ReturnsResponse()
51-
{
52-
var nebula = await ThirdwebNebula.Create(this.Client);
53-
var response = await nebula.Chat(message: $"What's the symbol of this contract: {NEBULA_TEST_CONTRACT} (Sepolia)?");
54-
Assert.NotNull(response);
55-
Assert.NotNull(response.Message);
56-
Assert.Contains("CAT", response.Message);
57-
}
49+
// [Fact(Timeout = 120000)]
50+
// public async Task Chat_Single_NoContext_ReturnsResponse()
51+
// {
52+
// var nebula = await ThirdwebNebula.Create(this.Client);
53+
// var response = await nebula.Chat(message: $"What's the symbol of this contract: {NEBULA_TEST_CONTRACT} (Sepolia)?");
54+
// Assert.NotNull(response);
55+
// Assert.NotNull(response.Message);
56+
// Assert.Contains("CAT", response.Message);
57+
// }
5858

59-
[Fact(Timeout = 120000)]
60-
public async Task Chat_Multiple_ReturnsResponse()
61-
{
62-
var nebula = await ThirdwebNebula.Create(this.Client);
63-
var response = await nebula.Chat(
64-
messages: new List<NebulaChatMessage>
65-
{
66-
new("What's the symbol of this contract?", NebulaChatRole.User),
67-
new("The symbol is CAT", NebulaChatRole.Assistant),
68-
new("What's the name of this contract?", NebulaChatRole.User),
69-
},
70-
context: new NebulaContext(contractAddresses: new List<string> { NEBULA_TEST_CONTRACT }, chainIds: new List<BigInteger> { NEBULA_TEST_CHAIN })
71-
);
72-
Assert.NotNull(response);
73-
Assert.NotNull(response.Message);
74-
Assert.Contains("CatDrop", response.Message, StringComparison.OrdinalIgnoreCase);
75-
}
59+
// [Fact(Timeout = 120000)]
60+
// public async Task Chat_Multiple_ReturnsResponse()
61+
// {
62+
// var nebula = await ThirdwebNebula.Create(this.Client);
63+
// var response = await nebula.Chat(
64+
// messages: new List<NebulaChatMessage>
65+
// {
66+
// new("What's the symbol of this contract?", NebulaChatRole.User),
67+
// new("The symbol is CAT", NebulaChatRole.Assistant),
68+
// new("What's the name of this contract?", NebulaChatRole.User),
69+
// },
70+
// context: new NebulaContext(contractAddresses: new List<string> { NEBULA_TEST_CONTRACT }, chainIds: new List<BigInteger> { NEBULA_TEST_CHAIN })
71+
// );
72+
// Assert.NotNull(response);
73+
// Assert.NotNull(response.Message);
74+
// Assert.Contains("CatDrop", response.Message, StringComparison.OrdinalIgnoreCase);
75+
// }
7676

77-
[Fact(Timeout = 120000)]
78-
public async Task Chat_UnderstandsWalletContext()
79-
{
80-
var wallet = await PrivateKeyWallet.Generate(this.Client);
81-
var expectedAddress = await wallet.GetAddress();
82-
var nebula = await ThirdwebNebula.Create(this.Client);
83-
var response = await nebula.Chat(message: "What is my wallet address?", wallet: wallet);
84-
Assert.NotNull(response);
85-
Assert.NotNull(response.Message);
86-
Assert.Contains(expectedAddress, response.Message);
87-
}
77+
// [Fact(Timeout = 120000)]
78+
// public async Task Chat_UnderstandsWalletContext()
79+
// {
80+
// var wallet = await PrivateKeyWallet.Generate(this.Client);
81+
// var expectedAddress = await wallet.GetAddress();
82+
// var nebula = await ThirdwebNebula.Create(this.Client);
83+
// var response = await nebula.Chat(message: "What is my wallet address?", wallet: wallet);
84+
// Assert.NotNull(response);
85+
// Assert.NotNull(response.Message);
86+
// Assert.Contains(expectedAddress, response.Message);
87+
// }
8888

89-
[Fact(Timeout = 120000)]
90-
public async Task Execute_ReturnsMessageAndReceipt()
91-
{
92-
var signer = await PrivateKeyWallet.Generate(this.Client);
93-
var wallet = await SmartWallet.Create(signer, NEBULA_TEST_CHAIN);
94-
var nebula = await ThirdwebNebula.Create(this.Client);
95-
var response = await nebula.Execute(
96-
new List<NebulaChatMessage>
97-
{
98-
new("What's the address of vitalik.eth", NebulaChatRole.User),
99-
new("The address of vitalik.eth is 0xd8dA6BF26964aF8E437eEa5e3616511D7G3a3298", NebulaChatRole.Assistant),
100-
new("Approve 1 USDC to them", NebulaChatRole.User),
101-
},
102-
wallet: wallet,
103-
context: new NebulaContext(contractAddresses: new List<string>() { NEBULA_TEST_USDC_ADDRESS })
104-
);
105-
Assert.NotNull(response);
106-
Assert.NotNull(response.Message);
107-
Assert.NotNull(response.TransactionReceipts);
108-
Assert.NotEmpty(response.TransactionReceipts);
109-
Assert.NotNull(response.TransactionReceipts[0].TransactionHash);
110-
Assert.True(response.TransactionReceipts[0].TransactionHash.Length == 66);
111-
}
89+
// [Fact(Timeout = 120000)]
90+
// public async Task Execute_ReturnsMessageAndReceipt()
91+
// {
92+
// var signer = await PrivateKeyWallet.Generate(this.Client);
93+
// var wallet = await SmartWallet.Create(signer, NEBULA_TEST_CHAIN);
94+
// var nebula = await ThirdwebNebula.Create(this.Client);
95+
// var response = await nebula.Execute(
96+
// new List<NebulaChatMessage>
97+
// {
98+
// new("What's the address of vitalik.eth", NebulaChatRole.User),
99+
// new("The address of vitalik.eth is 0xd8dA6BF26964aF8E437eEa5e3616511D7G3a3298", NebulaChatRole.Assistant),
100+
// new("Approve 1 USDC to them", NebulaChatRole.User),
101+
// },
102+
// wallet: wallet,
103+
// context: new NebulaContext(contractAddresses: new List<string>() { NEBULA_TEST_USDC_ADDRESS })
104+
// );
105+
// Assert.NotNull(response);
106+
// Assert.NotNull(response.Message);
107+
// Assert.NotNull(response.TransactionReceipts);
108+
// Assert.NotEmpty(response.TransactionReceipts);
109+
// Assert.NotNull(response.TransactionReceipts[0].TransactionHash);
110+
// Assert.True(response.TransactionReceipts[0].TransactionHash.Length == 66);
111+
// }
112112

113-
[Fact(Timeout = 120000)]
114-
public async Task Execute_ReturnsMessageAndReceipts()
115-
{
116-
var signer = await PrivateKeyWallet.Generate(this.Client);
117-
var wallet = await SmartWallet.Create(signer, NEBULA_TEST_CHAIN);
118-
var nebula = await ThirdwebNebula.Create(this.Client);
119-
var response = await nebula.Execute(
120-
new List<NebulaChatMessage>
121-
{
122-
new("What's the address of vitalik.eth", NebulaChatRole.User),
123-
new("The address of vitalik.eth is 0xd8dA6BF26964aF8E437eEa5e3616511D7G3a3298", NebulaChatRole.Assistant),
124-
new("Approve 1 USDC to them", NebulaChatRole.User),
125-
},
126-
wallet: wallet,
127-
context: new NebulaContext(contractAddresses: new List<string>() { NEBULA_TEST_USDC_ADDRESS })
128-
);
129-
Assert.NotNull(response);
130-
Assert.NotNull(response.Message);
131-
Assert.NotNull(response.TransactionReceipts);
132-
Assert.NotEmpty(response.TransactionReceipts);
133-
Assert.NotNull(response.TransactionReceipts[0].TransactionHash);
134-
Assert.True(response.TransactionReceipts[0].TransactionHash.Length == 66);
135-
}
113+
// [Fact(Timeout = 120000)]
114+
// public async Task Execute_ReturnsMessageAndReceipts()
115+
// {
116+
// var signer = await PrivateKeyWallet.Generate(this.Client);
117+
// var wallet = await SmartWallet.Create(signer, NEBULA_TEST_CHAIN);
118+
// var nebula = await ThirdwebNebula.Create(this.Client);
119+
// var response = await nebula.Execute(
120+
// new List<NebulaChatMessage>
121+
// {
122+
// new("What's the address of vitalik.eth", NebulaChatRole.User),
123+
// new("The address of vitalik.eth is 0xd8dA6BF26964aF8E437eEa5e3616511D7G3a3298", NebulaChatRole.Assistant),
124+
// new("Approve 1 USDC to them", NebulaChatRole.User),
125+
// },
126+
// wallet: wallet,
127+
// context: new NebulaContext(contractAddresses: new List<string>() { NEBULA_TEST_USDC_ADDRESS })
128+
// );
129+
// Assert.NotNull(response);
130+
// Assert.NotNull(response.Message);
131+
// Assert.NotNull(response.TransactionReceipts);
132+
// Assert.NotEmpty(response.TransactionReceipts);
133+
// Assert.NotNull(response.TransactionReceipts[0].TransactionHash);
134+
// Assert.True(response.TransactionReceipts[0].TransactionHash.Length == 66);
135+
// }
136136
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public void ClientIdAndSecretKeyInitialization()
4949
Assert.NotNull(client.ClientId);
5050
Assert.NotNull(client.SecretKey);
5151
Assert.Null(client.BundleId);
52-
Assert.NotEqual(client.ClientId, clientId);
53-
Assert.Equal(client.ClientId, Utils.ComputeClientIdFromSecretKey(client.SecretKey));
52+
Assert.Equal(client.ClientId, clientId);
53+
Assert.NotEqual(client.ClientId, Utils.ComputeClientIdFromSecretKey(client.SecretKey));
5454
Assert.Equal(client.SecretKey, this.SecretKey);
5555
}
5656

Thirdweb/Thirdweb.Client/ThirdwebClient.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,9 @@ private ThirdwebClient(
4242
throw new InvalidOperationException("ClientId or SecretKey must be provided");
4343
}
4444

45-
if (!string.IsNullOrEmpty(secretKey))
46-
{
47-
this.ClientId = Utils.ComputeClientIdFromSecretKey(secretKey);
48-
this.SecretKey = secretKey;
49-
}
50-
else
51-
{
52-
this.ClientId = clientId;
53-
}
54-
45+
// Respects provided clientId if any, otherwise computes it from secretKey
46+
this.ClientId = !string.IsNullOrEmpty(clientId) ? clientId : (string.IsNullOrEmpty(secretKey) ? null : Utils.ComputeClientIdFromSecretKey(secretKey));
47+
this.SecretKey = secretKey;
5548
this.BundleId = bundleId;
5649

5750
this.FetchTimeoutOptions = fetchTimeoutOptions ?? new TimeoutOptions();

Thirdweb/Thirdweb.Extensions/ThirdwebExtensions.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -984,9 +984,17 @@ public static async Task<List<BigInteger>> ERC1155_BalanceOfBatch(this ThirdwebC
984984
throw new ArgumentNullException(nameof(contract));
985985
}
986986

987-
return ownerAddresses == null || tokenIds == null
988-
? throw new ArgumentException("Owner addresses and token IDs must be provided")
989-
: await ThirdwebContract.Read<List<BigInteger>>(contract, "balanceOfBatch", ownerAddresses, tokenIds);
987+
if (ownerAddresses == null || tokenIds == null)
988+
{
989+
throw new ArgumentException("Owner addresses and token IDs must be provided");
990+
}
991+
992+
if (ownerAddresses.Length != tokenIds.Length)
993+
{
994+
throw new ArgumentException("Owner addresses and token IDs must have the same length");
995+
}
996+
997+
return await ThirdwebContract.Read<List<BigInteger>>(contract, "balanceOfBatch", ownerAddresses, tokenIds);
990998
}
991999

9921000
/// <summary>
@@ -1487,19 +1495,21 @@ public static async Task<List<NFT>> ERC1155_GetOwnedNFTs(this ThirdwebContract c
14871495

14881496
var balanceOfBatch = await contract.ERC1155_BalanceOfBatch(ownerArray.ToArray(), tokenIds.ToArray()).ConfigureAwait(false);
14891497

1490-
var ownerNftTasks = new List<Task<NFT>>();
1498+
var ownedNftTasks = new List<Task<NFT>>();
1499+
var ownedBalances = new List<BigInteger>();
14911500
for (var i = 0; i < balanceOfBatch.Count; i++)
14921501
{
14931502
if (balanceOfBatch[i] > 0)
14941503
{
1495-
ownerNftTasks.Add(contract.ERC1155_GetNFT(tokenIds[i]));
1504+
ownedNftTasks.Add(contract.ERC1155_GetNFT(tokenIds[i]));
1505+
ownedBalances.Add(balanceOfBatch[i]);
14961506
}
14971507
}
14981508

1499-
var ownerNfts = await Task.WhenAll(ownerNftTasks).ConfigureAwait(false);
1509+
var ownerNfts = await Task.WhenAll(ownedNftTasks).ConfigureAwait(false);
15001510
for (var i = 0; i < ownerNfts.Length; i++)
15011511
{
1502-
ownerNfts[i].QuantityOwned = balanceOfBatch[i];
1512+
ownerNfts[i].QuantityOwned = ownedBalances[i];
15031513
}
15041514
return ownerNfts.ToList();
15051515
}

Thirdweb/Thirdweb.Utils/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public static class Constants
44
{
5-
public const string VERSION = "2.17.0";
5+
public const string VERSION = "2.17.2";
66

77
public const string IERC20_INTERFACE_ID = "0x36372b07";
88
public const string IERC721_INTERFACE_ID = "0x80ac58cd";

Thirdweb/Thirdweb.Utils/Utils.Types.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Newtonsoft.Json;
2+
using System.Numerics;
23

34
namespace Thirdweb;
45

@@ -31,10 +32,10 @@ public class ThirdwebChainData
3132
public string ShortName { get; set; }
3233

3334
[JsonProperty("chainId")]
34-
public int ChainId { get; set; }
35+
public BigInteger ChainId { get; set; }
3536

3637
[JsonProperty("networkId")]
37-
public int NetworkId { get; set; }
38+
public BigInteger NetworkId { get; set; }
3839

3940
[JsonProperty("slug")]
4041
public string Slug { get; set; }

Thirdweb/Thirdweb.Utils/Utils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ internal static byte[] ToByteArrayForRLPEncoding(this BigInteger value)
11941194
return value.ToBytesForRLPEncoding();
11951195
}
11961196

1197-
internal static async void TrackTransaction(ThirdwebTransaction transaction, string transactionHash)
1197+
public static async void TrackTransaction(ThirdwebTransaction transaction, string transactionHash)
11981198
{
11991199
try
12001200
{
@@ -1225,7 +1225,7 @@ internal static async void TrackTransaction(ThirdwebTransaction transaction, str
12251225
}
12261226
}
12271227

1228-
internal static async void TrackConnection(IThirdwebWallet wallet)
1228+
public static async void TrackConnection(IThirdwebWallet wallet)
12291229
{
12301230
try
12311231
{

Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ string walletSecret
8080
/// <param name="siweSigner">The SIWE signer wallet for SIWE authentication.</param>
8181
/// <param name="legacyEncryptionKey">The encryption key that is no longer required but was used in the past. Only pass this if you had used custom auth before this was deprecated.</param>
8282
/// <param name="walletSecret">The wallet secret for Backend authentication.</param>
83+
/// <param name="twAuthTokenOverride">The auth token to use for the session. This will automatically connect using a raw thirdweb auth token.</param>
8384
/// <returns>A task that represents the asynchronous operation. The task result contains the created in-app wallet.</returns>
8485
/// <exception cref="ArgumentException">Thrown when required parameters are not provided.</exception>
8586
public static async Task<EcosystemWallet> Create(
@@ -92,7 +93,8 @@ public static async Task<EcosystemWallet> Create(
9293
string storageDirectoryPath = null,
9394
IThirdwebWallet siweSigner = null,
9495
string legacyEncryptionKey = null,
95-
string walletSecret = null
96+
string walletSecret = null,
97+
string twAuthTokenOverride = null
9698
)
9799
{
98100
if (client == null)
@@ -154,6 +156,10 @@ public static async Task<EcosystemWallet> Create(
154156

155157
storageDirectoryPath ??= Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Thirdweb", "EcosystemWallet");
156158
var embeddedWallet = new EmbeddedWallet(client, storageDirectoryPath, ecosystemId, ecosystemPartnerId);
159+
if (!string.IsNullOrWhiteSpace(twAuthTokenOverride))
160+
{
161+
CreateEnclaveSession(embeddedWallet, twAuthTokenOverride, email, phoneNumber, authproviderStr, null);
162+
}
157163

158164
try
159165
{

0 commit comments

Comments
 (0)