ERC7913P256Verifier.sol 997 B

1234567891011121314151617181920212223242526
  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. contract ERC7913P256Verifier is IERC7913SignatureVerifier {
  9. /// @inheritdoc IERC7913SignatureVerifier
  10. function verify(bytes calldata key, bytes32 hash, bytes calldata signature) public view virtual returns (bytes4) {
  11. // Signature length may be 0x40 or 0x41.
  12. if (key.length == 0x40 && signature.length >= 0x40) {
  13. bytes32 qx = bytes32(key[0x00:0x20]);
  14. bytes32 qy = bytes32(key[0x20:0x40]);
  15. bytes32 r = bytes32(signature[0x00:0x20]);
  16. bytes32 s = bytes32(signature[0x20:0x40]);
  17. if (P256.verify(hash, r, s, qx, qy)) {
  18. return IERC7913SignatureVerifier.verify.selector;
  19. }
  20. }
  21. return 0xFFFFFFFF;
  22. }
  23. }