ERC7913P256Verifier.sol 1.1 KB

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