ERC7913P256Verifier.sol 1.1 KB

1234567891011121314151617181920212223242526272829
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v5.4.0) (utils/cryptography/verifiers/ERC7913P256Verifier.sol)
  3. pragma solidity ^0.8.20;
  4. import {P256} from "../P256.sol";
  5. import {IERC7913SignatureVerifier} from "../../../interfaces/IERC7913.sol";
  6. /**
  7. * @dev ERC-7913 signature verifier that support P256 (secp256r1) keys.
  8. *
  9. * @custom:stateless
  10. */
  11. contract ERC7913P256Verifier is IERC7913SignatureVerifier {
  12. /// @inheritdoc IERC7913SignatureVerifier
  13. function verify(bytes calldata key, bytes32 hash, bytes calldata signature) public view virtual returns (bytes4) {
  14. // Signature length may be 0x40 or 0x41.
  15. if (key.length == 0x40 && signature.length >= 0x40) {
  16. bytes32 qx = bytes32(key[0x00:0x20]);
  17. bytes32 qy = bytes32(key[0x20:0x40]);
  18. bytes32 r = bytes32(signature[0x00:0x20]);
  19. bytes32 s = bytes32(signature[0x20:0x40]);
  20. if (P256.verify(hash, r, s, qx, qy)) {
  21. return IERC7913SignatureVerifier.verify.selector;
  22. }
  23. }
  24. return 0xFFFFFFFF;
  25. }
  26. }