@@ -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 \n Id: { 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 \n Id: { 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