2.5 KiB
2.5 KiB
Hero Vault CLI and Rhai Scripting
This module adds CLI and Rhai scripting capabilities to the WebAssembly Cryptography Module, allowing for command-line operations and scripting of cryptographic functions.
Features
- Simplified command-line interface for script execution
- Rhai scripting engine for automation
- Key management (create, list, import, export)
- Cryptographic operations (sign, verify, encrypt, decrypt)
- Ethereum wallet integration
Installation
Build the CLI tool using Cargo:
cargo build --release
The binary will be available at target/release/hero-vault
.
Usage
Command Line Interface
The CLI has been simplified to directly process Rhai scripts:
# Execute a script file
hero-vault path/to/script.rhai
# Enable verbose output
hero-vault --verbose path/to/script.rhai
# Specify a custom config file
hero-vault --config custom-config.json path/to/script.rhai
Rhai Scripting API
The Rhai scripting engine provides access to the following functions:
Key Management
create_key_space(name, password)
- Create a new key space with passwordencrypt_key_space(password)
- Encrypt the current key spacedecrypt_key_space(encrypted, password)
- Decrypt a key spacecreate_keypair(name, password)
- Create a new keypairselect_keypair(name)
- Select a keypair for operationslist_keypairs()
- List available keypairs
Cryptographic Operations
sign(message)
- Sign a message with the selected keypairverify(message, signature)
- Verify a signaturegenerate_key()
- Generate a symmetric encryption keyencrypt(key, message)
- Encrypt a message with a symmetric keydecrypt(key, ciphertext)
- Decrypt a message with a symmetric key
Ethereum Operations
create_ethereum_wallet()
- Create an Ethereum walletget_ethereum_address()
- Get the Ethereum address for the selected keypair
Example Scripts
Example scripts are available in the scripts/rhai
directory:
example.rhai
- Basic key management and cryptographic operationsadvanced_example.rhai
- Advanced cryptographic operationskey_persistence_example.rhai
- Persisting keys to diskload_existing_space.rhai
- Loading an existing key space
Configuration
The CLI uses a configuration file located at ~/.hero-vault/config.json
. You can specify a different configuration file with the --config
option.
Verbose Mode
Use the --verbose
flag to enable verbose output:
hero-vault --verbose path/to/script.rhai