Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add webauthn authenticator id in the enable event #89

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ MIT

## Addresses

<details>
<summary>v TBD</summary>

| Name | Address |
| -------------------- | ------------------------------------------ |
| Kernel | 0xd3082872F8B06073A021b4602e022d5A070d7cfC |
| KernelFactory | 0x5de4839a76cf55d0c90e2061ef4386d962E15ae3 |
| SessionKeyValidator | 0xB8E3c4bEaACAd06f6092793012DA4a8cB23D6123 |
| ECDSA Validator | 0xd9AB5096a832b9ce79914329DAEE236f8Eea0390 |
| FclWebAuthnValidator | 0x42085b533b27B9AfDAF3864a38c72eF853943DAB |
| P256VerifierWrapper | 0x738e3257EE928637fE62c37F91D3e722C45Dcc7C |
</details>

<details>
<summary>v2.4</summary>

Expand Down
120 changes: 120 additions & 0 deletions broadcast/DeployDeterministic.s.sol/137/run-1710798757.json

Large diffs are not rendered by default.

120 changes: 120 additions & 0 deletions broadcast/DeployDeterministic.s.sol/137/run-latest.json

Large diffs are not rendered by default.

120 changes: 120 additions & 0 deletions broadcast/DeployDeterministic.s.sol/80002/run-1710798602.json

Large diffs are not rendered by default.

120 changes: 120 additions & 0 deletions broadcast/DeployDeterministic.s.sol/80002/run-latest.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions script/DeployDeterministic.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "./deterministic/Factory.s.sol";
import "./deterministic/SessionKey.s.sol";
import "./deterministic/Kernel2_2.s.sol";
import "./deterministic/Kernel2_3.s.sol";
import "./deterministic/FclWebAuthNValidator.s.sol";

contract DeployDeterministic is Script {
address constant DEPLOYER = 0x9775137314fE595c943712B0b336327dfa80aE8A;
Expand Down Expand Up @@ -35,6 +36,10 @@ contract DeployDeterministic is Script {
if (!factory.isAllowedImplementation(k23lite)) {
factory.setImplementation(k23lite, true);
}

// Deploy the webauthn fcl validators
FclWebAuthnValidatorDeploy.deployWebAuthnFclVerifier();

vm.stopBroadcast();
}
}
22 changes: 0 additions & 22 deletions script/DeployWebAuthnFclValidator.sol

This file was deleted.

51 changes: 51 additions & 0 deletions script/deterministic/FclWebAuthNValidator.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
pragma solidity ^0.8.0;

import "src/utils/P256VerifierWrapper.sol";
import "src/validator/webauthn//WebAuthnFclValidator.sol";
import "./DeterministicDeploy.s.sol";
import "forge-std/console.sol";

/// @dev Deterministic deployment of FclWebAuthNValidator
library FclWebAuthnValidatorDeploy {
address constant EXPECTED_P256_VERIFIER_VALIDATOR_ADDRESS = 0x738e3257EE928637fE62c37F91D3e722C45Dcc7C;

address constant EXPECTED_WEBAUTHN_VALIDATOR_ADDRESS = 0x42085b533b27B9AfDAF3864a38c72eF853943DAB;

bytes32 constant DEPLOYMENT_SALT = keccak256("WebAuthNValidator by Frak");

/// @dev Deploy the P256VerifierWrapper and WebAuthnFclValidator
function deployWebAuthnFclVerifier() internal {
// Check if the contract of the p256 verifier is already deployed
if (EXPECTED_P256_VERIFIER_VALIDATOR_ADDRESS.code.length == 0) {
_deployOnChainP256();
} else {
console.log("P256VerifierWrapper: already deployed");
}

// Deploy the WebAuthnFclValidator
if (EXPECTED_WEBAUTHN_VALIDATOR_ADDRESS.code.length == 0) {
_deployValidator();
} else {
console.log("WebAuthnFclValidator: already deployed");
}
}

/// @dev Deploy the P256VerifierWrapper contract
function _deployOnChainP256() private {
P256VerifierWrapper p256Wrapper = new P256VerifierWrapper{salt: DEPLOYMENT_SALT}();
require(
address(p256Wrapper) == EXPECTED_P256_VERIFIER_VALIDATOR_ADDRESS,
"FclWebAuthnValidatorDeploy: p256 wrapper address mismatch"
);
}

/// @dev Deploy the P256VerifierWrapper contract
function _deployValidator() private {
WebAuthnFclValidator validator =
new WebAuthnFclValidator{salt: DEPLOYMENT_SALT}(EXPECTED_P256_VERIFIER_VALIDATOR_ADDRESS);
require(
address(validator) == EXPECTED_WEBAUTHN_VALIDATOR_ADDRESS,
"FclWebAuthnValidatorDeploy: validator address mismatch"
);
}
}
7 changes: 4 additions & 3 deletions src/validator/webauthn/WebAuthnFclValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ struct WebAuthnFclValidatorStorage {
/// @notice Inspired by the cometh Gnosis Safe signer: https://github.com/cometh-game/p256-signer
contract WebAuthnFclValidator is IKernelValidator {
/// @dev Event emitted when the public key signing the WebAuthN user operation is changed for a given `kernel`.
event WebAuthnPublicKeyChanged(address indexed kernel, uint256 x, uint256 y);
/// @dev The `b64AuthenticatorId` param represent the webauthn authenticator id used to create this public key
event WebAuthnPublicKeyChanged(address indexed kernel, string indexed b64AuthenticatorId, uint256 x, uint256 y);

/// @dev Mapping of kernel address to each webAuthn specific storage
mapping(address kernel => WebAuthnFclValidatorStorage webAuthnStorage) private webAuthnValidatorStorage;
Expand All @@ -44,13 +45,13 @@ contract WebAuthnFclValidator is IKernelValidator {
/// @dev Enable this validator for a given `kernel` (msg.sender)
function enable(bytes calldata _data) external payable override {
// Extract the x & y coordinates of the public key from the `_data` bytes
(uint256 x, uint256 y) = abi.decode(_data, (uint256, uint256));
(string memory authenticatorId, uint256 x, uint256 y) = abi.decode(_data, (string, uint256, uint256));
// Update the pub key data
WebAuthnFclValidatorStorage storage kernelValidatorStorage = webAuthnValidatorStorage[msg.sender];
kernelValidatorStorage.x = x;
kernelValidatorStorage.y = y;
// Emit the update event
emit WebAuthnPublicKeyChanged(msg.sender, x, y);
emit WebAuthnPublicKeyChanged(msg.sender, authenticatorId, x, y);
}

/// @dev Validate a `_userOp` using a WebAuthn Signature for the kernel account who is the `_userOp` sender
Expand Down
6 changes: 4 additions & 2 deletions test/foundry/validator/WebAuthnFclValidator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ contract WebAuthnFclValidatorTest is KernelTestBase {
}

function getInitializeData() internal view override returns (bytes memory) {
return abi.encodeWithSelector(KernelStorage.initialize.selector, webAuthNValidator, abi.encode(x, y));
return abi.encodeWithSelector(
KernelStorage.initialize.selector, webAuthNValidator, abi.encode("authenticator-id", x, y)
);
}

function test_default_validator_enable() external override {
Expand All @@ -76,7 +78,7 @@ contract WebAuthnFclValidatorTest is KernelTestBase {
IKernel.execute.selector,
address(webAuthNValidator),
0,
abi.encodeWithSelector(webAuthNValidator.enable.selector, abi.encode(x, y)),
abi.encodeWithSelector(webAuthNValidator.enable.selector, abi.encode("authenticator-id", x, y)),
Operation.Call
)
);
Expand Down
Loading