@@ -96,7 +96,7 @@ public async Task<LoginPayload> Authenticate(string domain)
9696 Resources = new List < string > ( ) ,
9797 Uri = $ "https://{ domain } ",
9898 Statement = "Please ensure that the domain above matches the URL of the current website." ,
99- Address = await GetSignerAddress ( ) ,
99+ Address = await GetAddress ( ) ,
100100 Domain = domain ,
101101 ChainId = ( await GetChainId ( ) ) . ToString ( ) ,
102102 Version = "1" ,
@@ -166,9 +166,13 @@ public async Task<string> Verify(LoginPayload payload)
166166 } ;
167167 var signature = payload . signature ;
168168 var validUser = await siwe . IsUserAddressRegistered ( siweMessage ) ;
169+ var msg = SiweMessageStringBuilder . BuildMessage ( siweMessage ) ;
169170 if ( validUser )
170171 {
171- if ( await siwe . IsMessageSignatureValid ( siweMessage , signature ) )
172+ string recoveredAddress = await RecoverAddress ( msg , signature ) ;
173+ Debug . Log ( $ "Recovered address: { recoveredAddress } ") ;
174+ Debug . Log ( $ "Message address: { siweMessage . Address } ") ;
175+ if ( recoveredAddress == siweMessage . Address )
172176 {
173177 if ( siwe . IsMessageTheSameAsSessionStored ( siweMessage ) )
174178 {
@@ -376,12 +380,25 @@ public async Task<TransactionResult> Transfer(string to, string amount, string c
376380 /// <returns>The signature of the message as a string.</returns>
377381 public async Task < string > Sign ( string message )
378382 {
383+ if ( ! await IsConnected ( ) )
384+ throw new Exception ( "No account connected!" ) ;
385+
379386 if ( Utils . IsWebGLBuild ( ) )
380387 {
381388 return await Bridge . InvokeRoute < string > ( getRoute ( "sign" ) , Utils . ToJsonStringArray ( message ) ) ;
382389 }
383390 else
384391 {
392+ if ( ThirdwebManager . Instance . SDK . session . ActiveWallet . GetProvider ( ) == WalletProvider . SmartWallet )
393+ {
394+ var sw = ThirdwebManager . Instance . SDK . session . ActiveWallet as Wallets . ThirdwebSmartWallet ;
395+ if ( ! sw . SmartWallet . IsDeployed && ! sw . SmartWallet . IsDeploying )
396+ {
397+ Debug . Log ( "SmartWallet not deployed, deploying before signing..." ) ;
398+ await sw . SmartWallet . ForceDeploy ( ) ;
399+ }
400+ }
401+
385402 return await ThirdwebManager . Instance . SDK . session . Request < string > ( "personal_sign" , message , await GetSignerAddress ( ) ) ;
386403 }
387404 }
@@ -397,7 +414,20 @@ public async Task<string> Sign(string message)
397414 public async Task < string > SignTypedDataV4 < T , TDomain > ( T data , TypedData < TDomain > typedData )
398415 where TDomain : IDomain
399416 {
400- if ( ThirdwebManager . Instance . SDK . session . ActiveWallet . GetSignerProvider ( ) == WalletProvider . LocalWallet )
417+ if ( ! await IsConnected ( ) )
418+ throw new Exception ( "No account connected!" ) ;
419+
420+ if ( ThirdwebManager . Instance . SDK . session . ActiveWallet . GetProvider ( ) == WalletProvider . SmartWallet )
421+ {
422+ var sw = ThirdwebManager . Instance . SDK . session . ActiveWallet as Wallets . ThirdwebSmartWallet ;
423+ if ( ! sw . SmartWallet . IsDeployed && ! sw . SmartWallet . IsDeploying )
424+ {
425+ Debug . Log ( "SmartWallet not deployed, deploying before signing..." ) ;
426+ await sw . SmartWallet . ForceDeploy ( ) ;
427+ }
428+ }
429+
430+ if ( ThirdwebManager . Instance . SDK . session . ActiveWallet . GetLocalAccount ( ) != null )
401431 {
402432 var signer = new Eip712TypedDataSigner ( ) ;
403433 var key = new EthECKey ( ThirdwebManager . Instance . SDK . session . ActiveWallet . GetLocalAccount ( ) . PrivateKey ) ;
@@ -441,6 +471,15 @@ public async Task<string> RecoverAddress(string message, string signature)
441471 else
442472 {
443473 var signer = new EthereumMessageSigner ( ) ;
474+ if ( ThirdwebManager . Instance . SDK . session . ActiveWallet . GetProvider ( ) == WalletProvider . SmartWallet )
475+ {
476+ var sw = ThirdwebManager . Instance . SDK . session . ActiveWallet as Wallets . ThirdwebSmartWallet ;
477+ bool isSigValid = await sw . SmartWallet . VerifySignature ( signer . HashPrefixedMessage ( System . Text . Encoding . UTF8 . GetBytes ( message ) ) , signature . HexStringToByteArray ( ) ) ;
478+ if ( isSigValid )
479+ {
480+ return await GetAddress ( ) ;
481+ }
482+ }
444483 var addressRecovered = signer . EncodeUTF8AndEcRecover ( message , signature ) ;
445484 return addressRecovered ;
446485 }
@@ -463,9 +502,9 @@ public async Task<TransactionResult> SendRawTransaction(TransactionRequest trans
463502 transactionRequest . data ,
464503 transactionRequest . to ,
465504 transactionRequest . from ,
466- new Nethereum . Hex . HexTypes . HexBigInteger ( BigInteger . Parse ( transactionRequest . gasLimit ) ) ,
467- new Nethereum . Hex . HexTypes . HexBigInteger ( BigInteger . Parse ( transactionRequest . gasPrice ) ) ,
468- new Nethereum . Hex . HexTypes . HexBigInteger ( transactionRequest . value )
505+ new HexBigInteger ( BigInteger . Parse ( transactionRequest . gasLimit ) ) ,
506+ new HexBigInteger ( BigInteger . Parse ( transactionRequest . gasPrice ) ) ,
507+ new HexBigInteger ( transactionRequest . value )
469508 ) ;
470509 var receipt = await ThirdwebManager . Instance . SDK . session . Web3 . Eth . TransactionManager . SendTransactionAndWaitForReceiptAsync ( input ) ;
471510 return receipt . ToTransactionResult ( ) ;
0 commit comments