webassembly/CLI_README.md
2025-05-08 16:28:13 +03:00

85 lines
2.5 KiB
Markdown

# 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:
```bash
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:
```bash
# 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 password
- `encrypt_key_space(password)` - Encrypt the current key space
- `decrypt_key_space(encrypted, password)` - Decrypt a key space
- `create_keypair(name, password)` - Create a new keypair
- `select_keypair(name)` - Select a keypair for operations
- `list_keypairs()` - List available keypairs
### Cryptographic Operations
- `sign(message)` - Sign a message with the selected keypair
- `verify(message, signature)` - Verify a signature
- `generate_key()` - Generate a symmetric encryption key
- `encrypt(key, message)` - Encrypt a message with a symmetric key
- `decrypt(key, ciphertext)` - Decrypt a message with a symmetric key
### Ethereum Operations
- `create_ethereum_wallet()` - Create an Ethereum wallet
- `get_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 operations
- `advanced_example.rhai` - Advanced cryptographic operations
- `key_persistence_example.rhai` - Persisting keys to disk
- `load_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:
```bash
hero-vault --verbose path/to/script.rhai