Skip to content

Commit

Permalink
✨ Add webauthn authenticator id in the enable event
Browse files Browse the repository at this point in the history
  • Loading branch information
KONFeature committed Mar 4, 2024
1 parent 3118026 commit 7cf4583
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
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

0 comments on commit 7cf4583

Please sign in to comment.