Skip to content

Commit 19a98a2

Browse files
committed
Add time to message prior to signing
1 parent c8af861 commit 19a98a2

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

Assets/MoralisWeb3ApiSdk/Example/DemoScene.unity

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47696,7 +47696,7 @@ PrefabInstance:
4769647696
objectReference: {fileID: 71058177}
4769747697
- target: {fileID: 6266890725912523073, guid: 116667ed98661304da1568439e2a3426, type: 3}
4769847698
propertyPath: Web3RpcNodeUrl
47699-
value: RPC NODE URL
47699+
value: RPC NODE URI
4770047700
objectReference: {fileID: 0}
4770147701
- target: {fileID: 6266890725912523073, guid: 116667ed98661304da1568439e2a3426, type: 3}
4770247702
propertyPath: MoralisServerURI

Assets/MoralisWeb3ApiSdk/Example/Scripts/MainMenuScript.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,27 @@ public async void WalletConnectHandler(WCSessionData data)
171171
Debug.Log("Wallet connection received");
172172
// Extract wallet address from the Wallet Connect Session data object.
173173
string address = data.accounts[0].ToLower();
174+
string appId = MoralisInterface.GetClient().ApplicationId;
175+
long serverTime = 0;
176+
177+
// Retrieve server time from Moralis Server for message signature
178+
Dictionary<string, object> serverTimeResponse = await MoralisInterface.GetClient().Cloud.RunAsync<Dictionary<string, object>>("getServerTime", new Dictionary<string, object>());
179+
180+
if (serverTimeResponse == null || !serverTimeResponse.ContainsKey("dateTime") ||
181+
!long.TryParse(serverTimeResponse["dateTime"].ToString(), out serverTime))
182+
{
183+
Debug.Log("Failed to retrieve server time from Moralis Server!");
184+
}
174185

175186
Debug.Log($"Sending sign request for {address} ...");
176187

177-
string response = await walletConnect.Session.EthPersonalSign(address, "Moralis Authentication");
188+
string signMessage = $"Moralis Authentication\n\nId: {appId}:{serverTime}";
189+
string response = await walletConnect.Session.EthPersonalSign(address, signMessage);
178190

179191
Debug.Log($"Signature {response} for {address} was returned.");
180192

181-
string appId = MoralisInterface.GetClient().ApplicationId;
182-
// Retrieve server time for authentication.
183-
long serverTime = await MoralisInterface.GetClient().Cloud.RunAsync<long>("getServerTime", new Dictionary<string, object>());
184193
// Create moralis auth data from message signing response.
185-
Dictionary<string, object> authData = new Dictionary<string, object> { { "id", address }, { "signature", response }, { "data", $"Moralis Authentication\n\nId: {appId}:{serverTime}" } };
194+
Dictionary<string, object> authData = new Dictionary<string, object> { { "id", address }, { "signature", response }, { "data", signMessage } };
186195

187196
Debug.Log("Logging in user.");
188197

0 commit comments

Comments
 (0)