Add isValidERC1271SignatureNow to SignatureChecker library (#3932)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: Francisco <fg@frang.io>
This commit is contained in:
@ -23,10 +23,23 @@ library SignatureChecker {
|
||||
*/
|
||||
function isValidSignatureNow(address signer, bytes32 hash, bytes memory signature) internal view returns (bool) {
|
||||
(address recovered, ECDSA.RecoverError error) = ECDSA.tryRecover(hash, signature);
|
||||
if (error == ECDSA.RecoverError.NoError && recovered == signer) {
|
||||
return true;
|
||||
}
|
||||
return
|
||||
(error == ECDSA.RecoverError.NoError && recovered == signer) ||
|
||||
isValidERC1271SignatureNow(signer, hash, signature);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Checks if a signature is valid for a given signer and data hash. The signature is validated
|
||||
* against the signer smart contract using ERC1271.
|
||||
*
|
||||
* NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus
|
||||
* change through time. It could return true at block N and false at block N+1 (or the opposite).
|
||||
*/
|
||||
function isValidERC1271SignatureNow(
|
||||
address signer,
|
||||
bytes32 hash,
|
||||
bytes memory signature
|
||||
) internal view returns (bool) {
|
||||
(bool success, bytes memory result) = signer.staticcall(
|
||||
abi.encodeWithSelector(IERC1271.isValidSignature.selector, hash, signature)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user