From 3e914256a072f44d47117ca17614d93be274d6d8 Mon Sep 17 00:00:00 2001 From: Alec Ananian <1013230+alecananian@users.noreply.github.com> Date: Thu, 24 Oct 2024 19:48:24 -0700 Subject: [PATCH] replace references to deprecated fields on user object (#130) --- Assets/Treasure/TDK/Runtime/API/Auth.cs | 6 ++-- .../TDK/Runtime/Identity/TDK.Identity.cs | 36 +++++++++---------- .../Runtime/Utils/TreasureLauncherUtils.cs | 4 +-- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Assets/Treasure/TDK/Runtime/API/Auth.cs b/Assets/Treasure/TDK/Runtime/API/Auth.cs index ec97d244..685678ee 100644 --- a/Assets/Treasure/TDK/Runtime/API/Auth.cs +++ b/Assets/Treasure/TDK/Runtime/API/Auth.cs @@ -56,7 +56,7 @@ public struct LogInResponse [Serializable] public struct User { - public struct Signer + public struct Session { public bool isAdmin; public string signer; @@ -67,9 +67,9 @@ public struct Signer } public string id; - public string smartAccountAddress; + public string address; public string email; - public List allActiveSigners; + public List sessions; } public partial class API diff --git a/Assets/Treasure/TDK/Runtime/Identity/TDK.Identity.cs b/Assets/Treasure/TDK/Runtime/Identity/TDK.Identity.cs index 62e62bdc..5e4331c4 100644 --- a/Assets/Treasure/TDK/Runtime/Identity/TDK.Identity.cs +++ b/Assets/Treasure/TDK/Runtime/Identity/TDK.Identity.cs @@ -98,7 +98,7 @@ await TDKServiceLocator.GetService().ActiveWallet.CreateSess ); } - private async Task> GetActiveSigners() + private async Task> GetUserSessions() { var thirdwebService = TDKServiceLocator.GetService(); var activeSignersTask = thirdwebService.ActiveWallet.GetAllActiveSigners(); @@ -106,7 +106,7 @@ await TDKServiceLocator.GetService().ActiveWallet.CreateSess await Task.WhenAll(activeSignersTask, allAdminsTask); var activeSigners = activeSignersTask.Result; var allAdmins = allAdminsTask.Result; - return activeSigners.Select(activeSigner => new User.Signer + return activeSigners.Select(activeSigner => new User.Session { isAdmin = allAdmins.Contains(activeSigner.Signer), signer = activeSigner.Signer, @@ -117,29 +117,29 @@ await TDKServiceLocator.GetService().ActiveWallet.CreateSess }).ToList(); } - private bool ValidateActiveSigner(string backendWallet, List callTargets, BigInteger nativeTokenLimitPerTransaction, User.Signer signer) + private bool ValidateSession(string backendWallet, List callTargets, BigInteger nativeTokenLimitPerTransaction, User.Session session) { var requestedCallTargets = callTargets.Select(callTarget => callTarget.ToLowerInvariant()); - var signerApprovedTargets = signer.approvedTargets.Select(approvedTarget => approvedTarget.ToLowerInvariant()); + var signerApprovedTargets = session.approvedTargets.Select(approvedTarget => approvedTarget.ToLowerInvariant()); var nowDate = Utils.GetUnixTimeStampNow(); var minEndDate = Utils.GetUnixTimeStampNow() + TDK.AppConfig.SessionMinDurationLeftSec; var maxEndDate = Utils.GetUnixTimeStampIn10Years(); return // Expected backend wallet is signer - signer.signer.ToLowerInvariant() == backendWallet.ToLowerInvariant() && + session.signer.ToLowerInvariant() == backendWallet.ToLowerInvariant() && // If this signer is an admin, they always have the required permissions - (signer.isAdmin || ( + (session.isAdmin || ( // Start date has passed - signer.startTimestamp < nowDate && + session.startTimestamp < nowDate && // Expiration date meets minimum time requirements - signer.endTimestamp >= minEndDate && + session.endTimestamp >= minEndDate && // Expiration date is not too far in the future (10 years because Thirdweb uses this for admins) // This check is to prevent sessions from being created with timestamps in milliseconds - signer.endTimestamp <= maxEndDate && + session.endTimestamp <= maxEndDate && // All requested targets are approved requestedCallTargets.All(callTarget => signerApprovedTargets.Contains(callTarget)) && // Native token limit per transaction is approved - signer.nativeTokenLimitPerTransaction >= nativeTokenLimitPerTransaction + session.nativeTokenLimitPerTransaction >= nativeTokenLimitPerTransaction )); } @@ -186,9 +186,9 @@ private async Task StartLauncherSessionRequest() var nativeTokenLimitPerTransaction = TDK.AppConfig.GetNativeTokenLimitPerTransaction(); // Check if any active signers match the call targets - var hasActiveSession = user.allActiveSigners.Any((signer) => + var hasActiveSession = user.sessions.Any((signer) => { - return ValidateActiveSigner( + return ValidateSession( backendWallet, callTargets, nativeTokenLimitPerTransaction, @@ -203,7 +203,7 @@ private async Task StartLauncherSessionRequest() } } - _address = user.smartAccountAddress; + _address = user.address; _authToken = authToken; TDKLogger.Log("Existing user session is valid"); @@ -280,10 +280,10 @@ public async Task StartUserSession(ChainId sessionChainId = ChainId.Unkn if (!didCreateSession && requiresSession) { var hasActiveSession = false; - List activeSigners = null; + List sessions = null; try { - activeSigners = await GetActiveSigners(); + sessions = await GetUserSessions(); } catch (Exception e) { @@ -292,12 +292,12 @@ public async Task StartUserSession(ChainId sessionChainId = ChainId.Unkn TDKLogger.LogError($"Error fetching active signers: {e}"); } - if (activeSigners != null && activeSigners.Count > 0) + if (sessions != null && sessions.Count > 0) { // Check if any active signers match the call targets - hasActiveSession = activeSigners.Any((signer) => + hasActiveSession = sessions.Any((signer) => { - return ValidateActiveSigner( + return ValidateSession( backendWallet, callTargets, nativeTokenLimitPerTransaction, diff --git a/Assets/Treasure/TDK/Runtime/Utils/TreasureLauncherUtils.cs b/Assets/Treasure/TDK/Runtime/Utils/TreasureLauncherUtils.cs index d58b2d7d..10923631 100644 --- a/Assets/Treasure/TDK/Runtime/Utils/TreasureLauncherUtils.cs +++ b/Assets/Treasure/TDK/Runtime/Utils/TreasureLauncherUtils.cs @@ -7,7 +7,7 @@ namespace Treasure public class TreasureLauncherUtils { private static bool hasParsedCommandLineArgs = false; - + private static string tdkAuthToken = null; public static string GetLauncherAuthToken() @@ -21,7 +21,7 @@ public static string GetWalletAddressFromJwt() // TODO check token expiration date? var content = GetLauncherAuthToken().Split('.')[1]; var jsonPayload = Decode(content); - return JsonConvert.DeserializeObject(jsonPayload)["ctx"]["smartAccountAddress"].ToString(); + return JsonConvert.DeserializeObject(jsonPayload)["ctx"]["address"].ToString(); } private static void ParseArgs()