ERC7913WebAuthnVerifier.sol 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.24;
  3. import {WebAuthn} from "../WebAuthn.sol";
  4. import {IERC7913SignatureVerifier} from "../../../interfaces/IERC7913.sol";
  5. /**
  6. * @dev ERC-7913 signature verifier that supports WebAuthn authentication assertions.
  7. *
  8. * This verifier enables the validation of WebAuthn signatures using P256 public keys.
  9. * The key is expected to be a 64-byte concatenation of the P256 public key coordinates (qx || qy).
  10. * The signature is expected to be an abi-encoded {WebAuthn-WebAuthnAuth} struct.
  11. *
  12. * Uses {WebAuthn-verifyMinimal} for signature verification, which performs the essential
  13. * WebAuthn checks: type validation, challenge matching, and cryptographic signature verification.
  14. *
  15. * NOTE: Wallets that may require default P256 validation may install a P256 verifier separately.
  16. */
  17. contract ERC7913WebAuthnVerifier is IERC7913SignatureVerifier {
  18. /// @inheritdoc IERC7913SignatureVerifier
  19. function verify(bytes calldata key, bytes32 hash, bytes calldata signature) public view virtual returns (bytes4) {
  20. (bool decodeSuccess, WebAuthn.WebAuthnAuth calldata auth) = WebAuthn.tryDecodeAuth(signature);
  21. return
  22. decodeSuccess &&
  23. key.length == 0x40 &&
  24. WebAuthn.verify(abi.encodePacked(hash), auth, bytes32(key[0x00:0x20]), bytes32(key[0x20:0x40]))
  25. ? IERC7913SignatureVerifier.verify.selector
  26. : bytes4(0xFFFFFFFF);
  27. }
  28. }