ERC7913P256Verifier.sol 1021 B

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