@@ -32,6 +32,7 @@ import {
3232 Nonce ,
3333 ProviderOptions ,
3434 Signature ,
35+ SignatureVerifResult ,
3536 SimulateTransactionDetails ,
3637 SimulateTransactionResponse ,
3738 TransactionType ,
@@ -573,23 +574,59 @@ export class Account extends Provider implements AccountInterface {
573574 return getMessageHash ( typedData , this . address ) ;
574575 }
575576
576- public async verifyMessageHash ( hash : BigNumberish , signature : Signature ) : Promise < boolean > {
577+ public async verifyMessageHash (
578+ hash : BigNumberish ,
579+ signature : Signature
580+ ) : Promise < SignatureVerifResult > {
577581 try {
578- await this . callContract ( {
582+ const resp = await this . callContract ( {
579583 contractAddress : this . address ,
580584 entrypoint : 'isValidSignature' ,
581585 calldata : CallData . compile ( {
582586 hash : toBigInt ( hash ) . toString ( ) ,
583587 signature : formatSignature ( signature ) ,
584588 } ) ,
585589 } ) ;
586- return true ;
587- } catch {
588- return false ;
590+ // console.log('verifySign=', resp);
591+ if ( BigInt ( resp . result [ 0 ] ) === 0n ) {
592+ // OpenZeppelin 0.8.0 invalid signature
593+ return {
594+ isVerificationProcessed : true ,
595+ isSignatureValid : false ,
596+ } as SignatureVerifResult ;
597+ }
598+ // OpenZeppelin 0.8.0, ArgentX 0.3.0 & Braavos Cairo 0 valid signature
599+ return {
600+ isVerificationProcessed : true ,
601+ isSignatureValid : true ,
602+ } as SignatureVerifResult ;
603+ } catch ( err ) {
604+ // console.log('verifySign error=', err);
605+ if ( ( err as Error ) . message . includes ( 'argent/invalid-signature' ) ) {
606+ // ArgentX 0.3.0 invalid signature
607+ return {
608+ isVerificationProcessed : true ,
609+ isSignatureValid : false ,
610+ } as SignatureVerifResult ;
611+ }
612+ if ( ( err as Error ) . message . includes ( 'is invalid, with respect to the public key' ) ) {
613+ // Braavos Cairo 0 invalid signature
614+ return {
615+ isVerificationProcessed : true ,
616+ isSignatureValid : false ,
617+ } as SignatureVerifResult ;
618+ }
619+ return {
620+ isVerificationProcessed : false ,
621+ error : new Error ( 'Signature verification request is rejected by the network.' ) ,
622+ } as SignatureVerifResult ;
589623 }
590624 }
591625
592- public async verifyMessage ( typedData : TypedData , signature : Signature ) : Promise < boolean > {
626+ public async verifyMessage (
627+ typedData : TypedData ,
628+ signature : Signature
629+ ) : Promise < SignatureVerifResult > {
593630 const hash = await this . hashMessage ( typedData ) ;
594631 return this . verifyMessageHash ( hash , signature ) ;
595632 }
0 commit comments