Skip to content

K1Validator

aboudjem edited this page Jun 5, 2024 · 1 revision

K1Validator

Git Source

Inherits: IValidator

This contract is a simple validator for testing purposes, verifying user operation signatures against registered owners.

Table of Contents

State Variables

smartAccountOwners

Mapping of smart account addresses to their respective owner addresses

mapping(address => address) public smartAccountOwners;

Important

This mapping stores the owner of each smart account. Ensuring this mapping is correctly maintained is critical for the validation of user operations.

Functions

onInstall

Called upon module installation to set the owner of the smart account

function onInstall(bytes calldata data) external;

Parameters

Name Type Description
data bytes Encoded address of the owner

Caution

Ensure the provided data contains a valid owner address to prevent installation failures.

onUninstall

Called upon module uninstallation to remove the owner of the smart account

function onUninstall(bytes calldata) external;

isInitialized

Checks if the smart account is initialized with an owner

function isInitialized(address smartAccount) external view returns (bool);

Parameters

Name Type Description
smartAccount address The address of the smart account

Returns

Name Type Description
<none> bool True if the smart account has an owner, false otherwise

validateUserOp

Validates a user operation by checking the signature against the owner's address

function validateUserOp(PackedUserOperation calldata userOp, bytes32 userOpHash) external view returns (uint256);

Parameters

Name Type Description
userOp PackedUserOperation The user operation to validate
userOpHash bytes32 The hash of the user operation

Returns

Name Type Description
<none> uint256 The validation result (0 for success, 1 for failure)

isValidSignatureWithSender

Validates a signature with the sender's address

function isValidSignatureWithSender(address, bytes32 hash, bytes calldata data) external view returns (bytes4);

Parameters

Name Type Description
<none> address
hash bytes32 The hash of the data to validate
data bytes The signature data

Returns

Name Type Description
<none> bytes4 The magic value if the signature is valid, otherwise an invalid value

name

Returns the name of the module

function name() external pure returns (string memory);

Returns

Name Type Description
<none> string The name of the module

version

Returns the version of the module

function version() external pure returns (string memory);

Returns

Name Type Description
<none> string The version of the module

isModuleType

Checks if the module is of the specified type

function isModuleType(uint256 typeID) external pure returns (bool);

Parameters

Name Type Description
typeID uint256 The type ID to check

Returns

Name Type Description
<none> bool True if the module is of the specified type, false otherwise

Errors

NoOwnerProvided

Error to indicate that no owner was provided during installation

error NoOwnerProvided();

Warning

Ensure that the owner's address is provided during the installation of the validator. Failure to do so will result in the NoOwnerProvided error, preventing the module from being installed properly.