Hook

Hook Integration

Elytro wallet hooks offer additional, customizable logic that can be executed at predefined points during the wallet's operation. Similar to hooks in software design, these hooks are triggered at specific checkpoints, allowing for additional checks and operations to be performed. This hook design enables a variety of use cases, such as enforcing daily spending limits and other tailored functionalities.

Implementing a New Hook

To integrate a new hook, your contract should inherit from the IHook interface. This interface defines the standard structure and functionalities for your hooks, ensuring they conform to the expected behavior within the Elytro wallet ecosystem.

import {IHook} from "@soulwallet-core/contracts/interface/IHook.sol";

contract NewHook is IHook {
    function preIsValidSignatureHook(bytes32 hash, bytes calldata hookSignature) external view {
        // Implement hook logic
    }

    function preUserOpValidationHook(
        UserOperation calldata userOp,
        bytes32 userOpHash,
        uint256 missingAccountFunds,
        bytes calldata hookSignature
    ) external {
        // Implement your hook-specific logic here
    }
}
  • preIsValidSignatureHook: This function allows you to implement logic that will be executed before a signature’s validity is confirmed. It can be used to perform additional checks or operations based on the provided hash and hook signature.

  • preUserOpValidationHook: This function is called before the validation of a UserOperation. It allows for custom logic to be implemented that can interact with the operation.

Last updated