Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Thirdweb.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@

#region InAppWallet - OAuth

// var inAppWalletOAuth = await InAppWallet.Create(client: client, authProvider: AuthProvider.Github);
// var inAppWalletOAuth = await InAppWallet.Create(client: client, authProvider: AuthProvider.TikTok);
// if (!await inAppWalletOAuth.IsConnected())
// {
// _ = await inAppWalletOAuth.LoginWithOauth(
Expand Down
18 changes: 9 additions & 9 deletions Thirdweb.Tests/Thirdweb.Utils/Thirdweb.Utils.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public void GenerateSIWE_ReturnsCorrectValue()
Domain = "thirdweb.com",
IssuedAt = "0",
ExpirationTime = "0",
InvalidBefore = "0"
InvalidBefore = "0",
};
var expectedSIWE =
"thirdweb.com wants you to sign in with your Ethereum account:\n0x0000000000000000000000000000000000000000\n\n\nVersion: 1\nChain ID: 421614\nNonce: 0\nIssued At: 0\nExpiration Time: 0\nNot Before: 0";
Expand All @@ -252,7 +252,7 @@ public void GenerateSIWE_WithAllOptional_ReturnsCorrectValue()
InvalidBefore = "0",
Statement = "This is a statement",
Uri = "https://thirdweb.com",
Resources = new List<string>() { "resource1", "resource2" }
Resources = new List<string>() { "resource1", "resource2" },
};
var expectedSIWE =
"thirdweb.com wants you to sign in with your Ethereum account:\n0x0000000000000000000000000000000000000000\n\nThis is a statement\n\nURI: https://thirdweb.com\nVersion: 1\nChain ID: 421614\nNonce: 0\nIssued At: 0\nExpiration Time: 0\nNot Before: 0\nResources:\n- resource1\n- resource2";
Expand All @@ -273,7 +273,7 @@ public void GenerateSIWE_WithResources_ReturnsCorrectValue()
IssuedAt = "0",
ExpirationTime = "0",
InvalidBefore = "0",
Resources = new List<string>() { "resource1", "resource2" }
Resources = new List<string>() { "resource1", "resource2" },
};
var expectedSIWE =
"thirdweb.com wants you to sign in with your Ethereum account:\n0x0000000000000000000000000000000000000000\n\n\nVersion: 1\nChain ID: 421614\nNonce: 0\nIssued At: 0\nExpiration Time: 0\nNot Before: 0\nResources:\n- resource1\n- resource2";
Expand All @@ -300,7 +300,7 @@ public void GenerateSIWE_ThrowsOnNullDomain()
Domain = null!,
IssuedAt = "0",
ExpirationTime = "0",
InvalidBefore = "0"
InvalidBefore = "0",
};
_ = Assert.Throws<ArgumentNullException>(() => Utils.GenerateSIWE(loginPayloadData));
}
Expand All @@ -317,7 +317,7 @@ public void GenerateSIWE_ThrowsOnNullAddress()
Domain = "thirdweb.com",
IssuedAt = "0",
ExpirationTime = "0",
InvalidBefore = "0"
InvalidBefore = "0",
};
_ = Assert.Throws<ArgumentNullException>(() => Utils.GenerateSIWE(loginPayloadData));
}
Expand All @@ -334,7 +334,7 @@ public void GenerateSIWE_ThrowsOnNullVersion()
Domain = "thirdweb.com",
IssuedAt = "0",
ExpirationTime = "0",
InvalidBefore = "0"
InvalidBefore = "0",
};
_ = Assert.Throws<ArgumentNullException>(() => Utils.GenerateSIWE(loginPayloadData));
}
Expand All @@ -351,7 +351,7 @@ public void GenerateSIWE_ThrowsOnNullChainId()
Domain = "thirdweb.com",
IssuedAt = "0",
ExpirationTime = "0",
InvalidBefore = "0"
InvalidBefore = "0",
};
_ = Assert.Throws<ArgumentNullException>(() => Utils.GenerateSIWE(loginPayloadData));
}
Expand All @@ -368,7 +368,7 @@ public void GenerateSIWE_ThrowsOnNullNonce()
Domain = "thirdweb.com",
IssuedAt = "0",
ExpirationTime = "0",
InvalidBefore = "0"
InvalidBefore = "0",
};
_ = Assert.Throws<ArgumentNullException>(() => Utils.GenerateSIWE(loginPayloadData));
}
Expand All @@ -385,7 +385,7 @@ public void GenerateSIWE_ThrowsOnNullIssuedAt()
Domain = "thirdweb.com",
IssuedAt = null!,
ExpirationTime = "0",
InvalidBefore = "0"
InvalidBefore = "0",
};
_ = Assert.Throws<ArgumentNullException>(() => Utils.GenerateSIWE(loginPayloadData));
}
Expand Down
2 changes: 1 addition & 1 deletion Thirdweb/Thirdweb.RPC/ThirdwebRPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public async Task<TResponse> SendRequestAsync<TResponse>(string method, params o
{
Method = method,
Params = parameters,
Id = requestId
Id = requestId,
};

lock (this._responseLock)
Expand Down
8 changes: 4 additions & 4 deletions Thirdweb/Thirdweb.Utils/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ public static async Task<bool> IsEip155Enforced(ThirdwebClient client, BigIntege
"chainid no support",
"chainid (0)",
"chainid(0)",
"invalid sender"
"invalid sender",
};

if (errorSubstrings.Any(errorMsg.Contains))
Expand Down Expand Up @@ -1156,7 +1156,7 @@ public static (ThirdwebTransactionInput transactionInput, string signature) Deco
maxPriorityFeePerGas: maxPriorityFeePerGas
)
{
AuthorizationList = authorizations
AuthorizationList = authorizations,
},
signature.CreateStringSignature()
);
Expand Down Expand Up @@ -1186,7 +1186,7 @@ public static List<EIP7702Authorization> DecodeAutorizationList(byte[] authoriza
Nonce = new HexBigInteger(decodedItem[2].RLPData.ToBigIntegerFromRLPDecoded()).HexValue,
YParity = signature.V.BytesToHex(),
R = signature.R.BytesToHex(),
S = signature.S.BytesToHex()
S = signature.S.BytesToHex(),
};
authorizationLists.Add(authorizationListItem);
}
Expand Down Expand Up @@ -1221,7 +1221,7 @@ public static async void TrackTransaction(ThirdwebTransaction transaction, strin
walletAddress = await wallet.GetAddress().ConfigureAwait(false),
walletType = wallet.WalletId,
contractAddress = transaction.Input.To,
gasPrice = transaction.Input.GasPrice?.Value ?? transaction.Input.MaxFeePerGas?.Value
gasPrice = transaction.Input.GasPrice?.Value ?? transaction.Input.MaxFeePerGas?.Value,
}
),
Encoding.UTF8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public enum ExecutionMode
{
EOA,
EIP7702,
EIP7702Sponsored
EIP7702Sponsored,
}

/// <summary>
Expand Down Expand Up @@ -137,6 +137,7 @@ public static async Task<EcosystemWallet> Create(
Thirdweb.AuthProvider.Line => "Line",
Thirdweb.AuthProvider.Guest => "Guest",
Thirdweb.AuthProvider.X => "X",
Thirdweb.AuthProvider.TikTok => "TikTok",
Thirdweb.AuthProvider.Coinbase => "Coinbase",
Thirdweb.AuthProvider.Github => "Github",
Thirdweb.AuthProvider.Twitch => "Twitch",
Expand Down Expand Up @@ -195,7 +196,7 @@ public static async Task<EcosystemWallet> Create(
executionMode
)
{
Address = userAddress
Address = userAddress,
};
}
catch
Expand All @@ -216,7 +217,7 @@ public static async Task<EcosystemWallet> Create(
executionMode
)
{
Address = null
Address = null,
};
}
}
Expand Down Expand Up @@ -316,8 +317,8 @@ private async Task<string> PostAuth(Server.VerifyResult result)

private async Task<string> MigrateShardToEnclave(Server.VerifyResult authResult)
{
var (address, encryptedPrivateKeyB64, ivB64, kmsCiphertextB64) = await this.EmbeddedWallet
.GenerateEncryptionDataAsync(authResult.AuthToken, this.LegacyEncryptionKey ?? authResult.RecoveryCode)
var (address, encryptedPrivateKeyB64, ivB64, kmsCiphertextB64) = await this
.EmbeddedWallet.GenerateEncryptionDataAsync(authResult.AuthToken, this.LegacyEncryptionKey ?? authResult.RecoveryCode)
.ConfigureAwait(false);

var url = $"{ENCLAVE_PATH}/migrate";
Expand All @@ -326,7 +327,7 @@ private async Task<string> MigrateShardToEnclave(Server.VerifyResult authResult)
address,
encryptedPrivateKeyB64,
ivB64,
kmsCiphertextB64
kmsCiphertextB64,
};
var requestContent = new StringContent(JsonConvert.SerializeObject(payload), Encoding.UTF8, "application/json");

Expand Down Expand Up @@ -492,7 +493,7 @@ public async Task<ThirdwebTransactionReceipt> CreateSessionKey(
ExpiresAt = Utils.GetUnixTimeStampNow() + durationInSeconds,
CallPolicies = callPolicies ?? new List<CallSpec>(),
TransferPolicies = transferPolicies ?? new List<TransferSpec>(),
Uid = uid ?? Guid.NewGuid().ToByteArray()
Uid = uid ?? Guid.NewGuid().ToByteArray(),
};

var userWalletAddress = await this.GetAddress();
Expand Down Expand Up @@ -643,8 +644,8 @@ public async Task<List<LinkedAccount>> UnlinkAccount(LinkedAccount accountToUnli
Email = linkedAccount.Details?.Email,
Address = linkedAccount.Details?.Address,
Phone = linkedAccount.Details?.Phone,
Id = linkedAccount.Details?.Id
}
Id = linkedAccount.Details?.Id,
},
}
);
}
Expand Down Expand Up @@ -744,6 +745,7 @@ public async Task<List<LinkedAccount>> LinkAccount(
case "Telegram":
case "Line":
case "X":
case "TikTok":
case "Coinbase":
case "Github":
case "Twitch":
Expand All @@ -770,8 +772,8 @@ public async Task<List<LinkedAccount>> LinkAccount(
Email = linkedAccount.Details?.Email,
Address = linkedAccount.Details?.Address,
Phone = linkedAccount.Details?.Phone,
Id = linkedAccount.Details?.Id
}
Id = linkedAccount.Details?.Id,
},
}
);
}
Expand All @@ -794,8 +796,8 @@ public async Task<List<LinkedAccount>> GetLinkedAccounts()
Email = linkedAccount.Details?.Email,
Address = linkedAccount.Details?.Address,
Phone = linkedAccount.Details?.Phone,
Id = linkedAccount.Details?.Id
}
Id = linkedAccount.Details?.Id,
},
}
);
}
Expand Down Expand Up @@ -838,11 +840,9 @@ public async Task SendOTP()
}

var serverRes =
string.IsNullOrEmpty(this.Email) && string.IsNullOrEmpty(this.PhoneNumber)
? throw new Exception("Email or Phone Number is required for OTP login")
: this.Email == null
? await this.EmbeddedWallet.VerifyPhoneOtpAsync(this.PhoneNumber, otp).ConfigureAwait(false)
: await this.EmbeddedWallet.VerifyEmailOtpAsync(this.Email, otp).ConfigureAwait(false);
string.IsNullOrEmpty(this.Email) && string.IsNullOrEmpty(this.PhoneNumber) ? throw new Exception("Email or Phone Number is required for OTP login")
: this.Email == null ? await this.EmbeddedWallet.VerifyPhoneOtpAsync(this.PhoneNumber, otp).ConfigureAwait(false)
: await this.EmbeddedWallet.VerifyEmailOtpAsync(this.Email, otp).ConfigureAwait(false);

return serverRes;
}
Expand Down Expand Up @@ -1258,22 +1258,19 @@ public async Task<string> SignTransaction(ThirdwebTransactionInput transaction)
maxPriorityFeePerGas = transaction.MaxPriorityFeePerGas,
chainId = transaction.ChainId,
authorizationList = transaction.AuthorizationList != null && transaction.AuthorizationList.Count > 0
? transaction.AuthorizationList
.Select(
authorization =>
new
{
chainId = authorization.ChainId.HexToNumber(),
address = authorization.Address,
nonce = authorization.Nonce.HexToNumber().ToString(),
yParity = authorization.YParity.HexToNumber(),
r = authorization.R.HexToNumber().ToString(),
s = authorization.S.HexToNumber().ToString()
}
)
? transaction
.AuthorizationList.Select(authorization => new
{
chainId = authorization.ChainId.HexToNumber(),
address = authorization.Address,
nonce = authorization.Nonce.HexToNumber().ToString(),
yParity = authorization.YParity.HexToNumber(),
r = authorization.R.HexToNumber().ToString(),
s = authorization.S.HexToNumber().ToString(),
})
.ToArray()
: null
}
: null,
},
};

var url = $"{ENCLAVE_PATH}/sign-transaction";
Expand Down Expand Up @@ -1308,8 +1305,8 @@ public async Task<string> SendTransaction(ThirdwebTransactionInput transaction)
{
Target = transaction.To,
Value = transaction.Value?.Value ?? BigInteger.Zero,
Data = transaction.Data.HexToBytes()
}
Data = transaction.Data.HexToBytes(),
},
};

switch (this.ExecutionMode)
Expand Down Expand Up @@ -1441,7 +1438,7 @@ public async Task<EIP7702Authorization> SignAuthorization(BigInteger chainId, st
{
address = contractAddress,
chainId,
nonce
nonce,
};

var requestContent = new StringContent(JsonConvert.SerializeObject(payload), Encoding.UTF8, "application/json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,12 @@ internal override async Task<string> FetchAuthShareAsync(string authToken)
// embedded-wallet/embedded-wallet-shares GET
private async Task<SharesGetResponse> FetchRemoteSharesAsync(string authToken, bool wantsRecoveryShare)
{
Dictionary<string, string> queryParams =
new()
{
{ "getEncryptedAuthShare", "true" },
{ "getEncryptedRecoveryShare", wantsRecoveryShare ? "true" : "false" },
{ "useSealedSecret", "false" }
};
Dictionary<string, string> queryParams = new()
{
{ "getEncryptedAuthShare", "true" },
{ "getEncryptedRecoveryShare", wantsRecoveryShare ? "true" : "false" },
{ "useSealedSecret", "false" },
};
var uri = MakeUri2023("/embedded-wallet/embedded-wallet-shares", queryParams);
var response = await this.SendHttpWithAuthAsync(uri, authToken).ConfigureAwait(false);
await CheckStatusCodeAsync(response).ConfigureAwait(false);
Expand Down Expand Up @@ -201,7 +200,7 @@ internal override async Task<VerifyResult> VerifyGuestAsync(string sessionId)
// login/oauthprovider
internal override Task<string> FetchHeadlessOauthLoginLinkAsync(string authProvider, string platform)
{
return Task.FromResult(MakeUri2024($"/login/{authProvider}", new Dictionary<string, string> { { "clientId", this._clientId }, { "platform", platform } }).ToString());
return Task.FromResult(MakeUri2024($"/login/{authProvider.ToLower()}", new Dictionary<string, string> { { "clientId", this._clientId }, { "platform", platform } }).ToString());
}

// login/email
Expand Down Expand Up @@ -389,7 +388,7 @@ private static async Task<T> DeserializeAsync<T>(ThirdwebHttpResponseMessage res

private static Uri MakeUri2024(string path, IDictionary<string, string> parameters = null)
{
UriBuilder b = new(ROOT_URL) { Path = API_ROOT_PATH_2024 + path, };
UriBuilder b = new(ROOT_URL) { Path = API_ROOT_PATH_2024 + path };
if (parameters != null && parameters.Any())
{
var queryString = string.Join('&', parameters.Select((p) => $"{p.Key}={Uri.EscapeDataString(p.Value)}"));
Expand All @@ -400,7 +399,7 @@ private static Uri MakeUri2024(string path, IDictionary<string, string> paramete

private static Uri MakeUri2023(string path, IDictionary<string, string> parameters = null)
{
UriBuilder b = new(ROOT_URL) { Path = API_ROOT_PATH_2023 + path, };
UriBuilder b = new(ROOT_URL) { Path = API_ROOT_PATH_2023 + path };
if (parameters != null && parameters.Any())
{
var queryString = string.Join('&', parameters.Select((p) => $"{p.Key}={Uri.EscapeDataString(p.Value)}"));
Expand All @@ -418,7 +417,7 @@ private static StringContent MakeHttpContent(object data)

private static string Serialize(object data)
{
JsonSerializer jsonSerializer = new() { NullValueHandling = NullValueHandling.Ignore, };
JsonSerializer jsonSerializer = new() { NullValueHandling = NullValueHandling.Ignore };
StringWriter stringWriter = new();
jsonSerializer.Serialize(stringWriter, data);
var rv = stringWriter.ToString();
Expand Down
1 change: 1 addition & 0 deletions Thirdweb/Thirdweb.Wallets/InAppWallet/InAppWallet.Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum AuthProvider
Line,
Guest,
X,
TikTok,
Coinbase,
Github,
Twitch,
Expand Down
Loading
Loading