-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathSignerWebAuthn.sol
More file actions
50 lines (46 loc) · 1.85 KB
/
SignerWebAuthn.sol
File metadata and controls
50 lines (46 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {SignerP256} from "./SignerP256.sol";
import {WebAuthn} from "../WebAuthn.sol";
/**
* @dev Implementation of {SignerP256} that supports WebAuthn authentication assertions.
*
* This contract enables signature validation using WebAuthn authentication assertions,
* leveraging the P256 public key stored in the contract. It allows for both WebAuthn
* and raw P256 signature validation, providing compatibility with both signature types.
*
* The signature is expected to be an abi-encoded {WebAuthn-WebAuthnAuth} struct.
*
* Example usage:
*
* ```solidity
* contract MyAccountWebAuthn is Account, SignerWebAuthn, Initializable {
* function initialize(bytes32 qx, bytes32 qy) public initializer {
* _setSigner(qx, qy);
* }
* }
* ```
*
* IMPORTANT: Failing to call {_setSigner} either during construction (if used standalone)
* or during initialization (if used as a clone) may leave the signer either front-runnable or unusable.
*/
abstract contract SignerWebAuthn is SignerP256 {
/**
* @dev Validates a raw signature using the WebAuthn authentication assertion.
*
* In case the signature can't be validated, it falls back to the
* {SignerP256-_rawSignatureValidation} method for raw P256 signature validation by passing
* the raw `r` and `s` values from the signature.
*/
function _rawSignatureValidation(
bytes32 hash,
bytes calldata signature
) internal view virtual override returns (bool) {
(bytes32 qx, bytes32 qy) = signer();
(bool decodeSuccess, WebAuthn.WebAuthnAuth calldata auth) = WebAuthn.tryDecodeAuth(signature);
return
decodeSuccess
? WebAuthn.verifyMinimal(abi.encodePacked(hash), auth, qx, qy)
: super._rawSignatureValidation(hash, signature);
}
}