@veive-io/mod-hooks-as
v1.0.0
Published
Veive smart account hooks module
Downloads
8
Readme
Mod hooks
Overview
mod-hooks-as
is a core library in the Veive protocol, providing the framework for creating hook modules that execute pre-checks and post-checks around operations within Koinos blockchain smart accounts. These modules enable additional logic to be run before and after main operations, offering enhanced flexibility and security.
Components and Functional Description
1. ModHooks
Class
Description: The
ModHooks
class serves as the foundational class for all hook modules within the Veive ecosystem. It provides methods for implementing specific pre-check and post-check logic by derived classes.Key Methods:
pre_check
: Invoked before the main operation is executed, this method allows developers to implement custom logic to verify conditions or perform actions that should happen prior to the operation. For instance, it can enforce spending limits or additional authentication steps.post_check
: This method is called after the main operation is executed. It is used to implement logic that should occur post-operation, such as logging actions, updating internal states, or handling follow-up tasks.on_install
andon_uninstall
: Manage the installation and uninstallation of the hook module. These methods set up necessary resources or perform cleanup tasks when the module is added or removed.is_type
: Verifies if the module matches a specific type ID, confirming its identity and ensuring proper interaction with other components.
Use Case: The
ModHooks
class is foundational for creating hook modules that add security layers, auditing, or custom functionalities to smart accounts. For example, a hook module could enforce daily transaction limits or log outgoing transfers for auditing.
2. modhooks
Proto
- Description: The
modhooks
protocol buffer (proto) defines data structures and communication formats used by hook modules. - Purpose: It standardizes data exchange between the smart account and the hook modules, ensuring consistency and reliability in communication.
Usage and Integration
Integration in the Veive Protocol
The mod-hooks-as
library integrates seamlessly with the Veive protocol, enabling smart accounts to execute pre-checks and post-checks as part of the operation lifecycle.
Flow Integration:
- The
ModHooks
methodspre_check
andpost_check
are called at the appropriate times during an operation's lifecycle. This integration ensures that all necessary checks and actions are performed before and after operations, enhancing security and operational integrity.
Development and Customization:
- Developers can extend the
ModHooks
class to create custom hook modules that perform specific tasks, such as additional validation checks, logging, or state updates. This flexibility allows for a wide range of use cases and customizations, depending on the needs of the smart account and its operations.
Usage
Installation
To install the mod-hooks-as
library, use the following command:
yarn add @veive/mod-hooks-as
Scripts
Build
To compile the package, run:
yarn build
Contributing
Contributions are welcome! Please open an issue or submit a pull request on the GitHub repository.
License
This project is licensed under the MIT License. See the LICENSE file for details.