Banking Module Documentation for the Synnq Ecosystem
Overview
The Banking Module in the Synnq Ecosystem is designed to manage accounts, tokens, permissions, and secure transactions. It provides the foundational infrastructure for managing digital assets and permissions within the ecosystem. This document provides an overview of the key components and functionalities of the Banking Module, focusing on account management, token management, and permission control.
Components and Responsibilities
1. Account Management (KeyManager
)
The KeyManager
is responsible for generating and managing cryptographic keys, creating and maintaining wallets, and handling wallet permissions. It ensures the secure storage and retrieval of wallets and their associated data.
Key Functionalities:
-
Key Pair Generation: The
KeyManager
generates new key pairs, including a public key, private key, and mnemonic phrase. These keys are crucial for creating new wallets and signing transactions. -
Wallet Creation: Wallets are created with a unique address, derived from the public key and a prefix. The
KeyManager
also assigns initial balances and permissions to the wallet. -
Wallet Storage and Retrieval: Wallets are stored securely in a distributed storage system. The
KeyManager
can retrieve wallets based on their address or private key. -
Balance Management: The
KeyManager
manages the balances of various tokens within a wallet. It can update balances and check for sufficient funds before transactions are processed. -
Permission Handling: Each wallet has associated permissions that determine what actions the wallet owner can perform (e.g., minting tokens, creating coins). The
KeyManager
checks these permissions before executing sensitive operations. -
Signature Generation: The
KeyManager
can generate digital signatures using private keys, which are essential for authenticating transactions.
2. Token Management (TokenManager
)
The TokenManager
handles the creation, distribution, and management of tokens within the Synnq Ecosystem. It supports both the native coin and custom tokens created by users.
Key Functionalities:
-
Token Creation: The
TokenManager
allows the creation of new tokens with a specified initial supply. It also handles the creation of the native utility coin. -
Minting and Burning Tokens: Authorized users can mint new tokens or burn existing ones, effectively increasing or decreasing the total supply of a token.
-
Token Storage and Retrieval: Tokens are stored in the distributed storage system, and the
TokenManager
can retrieve tokens based on their symbol or other identifiers. -
Token Transfer: The
TokenManager
facilitates the transfer of tokens between wallets, updating the respective balances accordingly. -
Balance Queries: Users can query the balance of a specific token for any account. The
TokenManager
provides this functionality for both the native coin and other tokens. -
Blacklist Management: The
TokenManager
can add or remove tokens from a blacklist, preventing blacklisted tokens from being transferred or used within the ecosystem.
3. Permission Control (Permission
)
Permissions in the Synnq Ecosystem are tightly controlled through the Permission
struct, which is associated with specific roles. These permissions dictate what actions a wallet can perform, ensuring a secure and organized environment for asset management.
Key Functionalities:
-
Role-Based Permissions: Permissions are assigned based on predefined roles such as
SuperAdmin
,Admin
,User
,Owner
, andSubscriber
. Each role comes with a set of permissions that control the wallet's capabilities. -
Permission Checks: Before performing any sensitive action (e.g., minting tokens, creating coins), the system checks if the wallet has the necessary permissions.
-
Permission Updates: The
KeyManager
can update the permissions of a wallet, either modifying the existing permissions or assigning a new role altogether.
Use Cases and Workflows
Wallet Creation and Management
-
Create a Wallet:
- Generate a new key pair.
- Create a wallet with an initial balance and assign it a role.
- Store the wallet securely in the distributed storage.
-
Retrieve a Wallet:
- Fetch the wallet using its address or by deriving it from a private key.
-
Update Wallet Balance:
- Modify the balance of a specific token within the wallet.
- Save the updated wallet back to storage.
-
Check Permissions:
- Before executing any critical action, verify that the wallet has the necessary permissions based on its assigned role.
Token Management
-
Create a Token:
- Define the token's name, symbol, and initial supply.
- Store the token in the distributed storage.
- Update the wallet's balance to reflect the newly created tokens.
-
Mint Tokens:
- Increase the supply of a token by minting new units.
- Update the recipient's wallet balance accordingly.
-
Burn Tokens:
- Decrease the supply of a token by burning units.
- Update the wallet balance to reflect the burn.
-
Transfer Tokens:
- Move tokens from one wallet to another.
- Ensure that both the sender and receiver's wallet balances are updated.
Permission Management
-
Assign Roles:
- Assign a role to a wallet during creation or later as needed.
-
Check Role Permissions:
- Verify if a wallet's assigned role permits a specific action before executing it.
-
Update Permissions:
- Modify the permissions associated with a wallet by assigning it a new role or adjusting its existing permissions.
Error Handling and Security
The Banking Module includes robust error handling to manage potential issues such as insufficient funds, invalid keys, or unauthorized actions. All critical operations are logged for auditing and monitoring purposes, ensuring transparency and traceability within the ecosystem.