@@ -444,46 +444,43 @@ public async Task<string> Sign(string message)
444
444
}
445
445
if ( sw . SmartWallet . IsDeployed )
446
446
{
447
+ byte [ ] originalMsgHash = System . Text . Encoding . UTF8 . GetBytes ( message ) . HashPrefixedMessage ( ) ;
448
+ string swAddress = await GetAddress ( ) ;
449
+ bool factorySupports712 ;
450
+ string signature = null ;
447
451
try
448
452
{
449
- byte [ ] originalMsgHash = System . Text . Encoding . UTF8 . GetBytes ( message ) . HashPrefixedMessage ( ) ;
450
-
451
453
// if this fails it's a pre 712 factory
452
454
await TransactionManager . ThirdwebRead < Contracts . Account . ContractDefinition . GetMessageHashFunction , Contracts . Account . ContractDefinition . GetMessageHashOutputDTO > (
453
- await GetAddress ( ) ,
455
+ swAddress ,
454
456
new Contracts . Account . ContractDefinition . GetMessageHashFunction ( ) { Hash = originalMsgHash }
455
457
) ;
456
-
457
- string sig = await EIP712 . GenerateSignature_SmartAccount_AccountMessage ( "Account" , "1" , await GetChainId ( ) , await GetAddress ( ) , originalMsgHash ) ;
458
-
459
- bool isValid = await RecoverAddress ( message , sig ) == await GetAddress ( ) ;
460
- if ( isValid )
461
- {
462
- return sig ;
463
- }
464
- else
465
- {
466
- throw new Exception ( "Unable to verify signature on smart account, please make sure the smart account is deployed and the signature is valid." ) ;
467
- }
458
+ factorySupports712 = true ;
468
459
}
469
- catch ( Exception e )
460
+ catch
470
461
{
471
- ThirdwebDebug . LogWarning ( "Error signing message with smart account typed data, falling back to personal sign: " + e . Message ) ;
462
+ ThirdwebDebug . Log ( "Account does not support 712 signing, using personal_sign" ) ;
463
+ factorySupports712 = false ;
472
464
}
465
+
466
+ if ( factorySupports712 )
467
+ signature = await EIP712 . GenerateSignature_SmartAccount_AccountMessage ( "Account" , "1" , await GetChainId ( ) , swAddress , originalMsgHash ) ;
468
+ else
469
+ signature = await ThirdwebManager . Instance . SDK . session . Request < string > ( "personal_sign" , message , await GetSignerAddress ( ) ) ;
470
+
471
+ bool isValid = await RecoverAddress ( message , signature ) == swAddress ;
472
+ if ( isValid )
473
+ return signature ;
474
+ else
475
+ throw new Exception ( "Unable to verify signature on smart account, please make sure the smart account is deployed and the signature is valid." ) ;
473
476
}
474
477
else
475
478
{
476
479
throw new Exception ( "Smart account could not be deployed, unable to sign message." ) ;
477
480
}
478
481
}
479
482
480
- var sig2 = await ThirdwebManager . Instance . SDK . session . Request < string > ( "personal_sign" , message , await GetSignerAddress ( ) ) ;
481
- var verify = await RecoverAddress ( message , sig2 ) == await GetAddress ( ) ;
482
- if ( ! verify )
483
- {
484
- throw new Exception ( "Unable to verify signature, please make sure the wallet is unlocked and the signature is valid." ) ;
485
- }
486
- return sig2 ;
483
+ return await ThirdwebManager . Instance . SDK . session . Request < string > ( "personal_sign" , message , await GetSignerAddress ( ) ) ;
487
484
}
488
485
}
489
486
0 commit comments