Hero Vault Cryptography Examples
This directory contains examples demonstrating the Hero Vault cryptography functionality integrated into the SAL project.
Overview
Hero Vault provides cryptographic operations including:
- Key space management (creation, loading, encryption, decryption)
 - Keypair management (creation, selection, listing)
 - Digital signatures (signing and verification)
 - Symmetric encryption (key generation, encryption, decryption)
 - Ethereum wallet functionality
 - Smart contract interactions
 - Key-value store with encryption
 
Example Files
example.rhai- Basic example demonstrating key management, signing, and encryptionadvanced_example.rhai- Advanced example with error handling, conditional logic, and more complex operationskey_persistence_example.rhai- Demonstrates creating and saving a key space to diskload_existing_space.rhai- Shows how to load a previously created key space and use its keypairscontract_example.rhai- Demonstrates loading a contract ABI and interacting with smart contractsagung_send_transaction.rhai- Demonstrates sending native tokens on the Agung networkagung_contract_with_args.rhai- Shows how to interact with contracts with arguments on Agung
Running the Examples
You can run the examples using the herodo tool that comes with the SAL project:
# Run a single example
herodo --path example.rhai
# Run all examples using the provided script
./run_examples.sh
Key Space Storage
Key spaces are stored in the ~/.hero-vault/key-spaces/ directory by default. Each key space is stored in a separate JSON file named after the key space (e.g., my_space.json).
Ethereum Functionality
The Hero Vault module provides comprehensive Ethereum wallet functionality:
- Creating and managing wallets for different networks
 - Sending ETH transactions
 - Checking balances
 - Interacting with smart contracts (read and write functions)
 - Support for multiple networks (Ethereum, Gnosis, Peaq, Agung, etc.)
 
Security
Key spaces are encrypted with ChaCha20Poly1305 using a key derived from the provided password. The encryption ensures that the key material is secure at rest.
Best Practices
- Use Strong Passwords: Since the security of your key spaces depends on the strength of your passwords, use strong, unique passwords.
 - Backup Key Spaces: Regularly backup your key spaces directory to prevent data loss.
 - Script Organization: Split your scripts into logical units, with separate scripts for key creation and key usage.
 - Error Handling: Always check the return values of functions to ensure operations succeeded before proceeding.
 - Network Selection: When working with Ethereum functionality, be explicit about which network you're targeting to avoid confusion.
 - Gas Management: For Ethereum transactions, consider gas costs and set appropriate gas limits.