update docs

This commit is contained in:
2025-05-08 16:28:13 +03:00
parent a86a247180
commit 54f604f16a
5 changed files with 29 additions and 176 deletions

View File

@@ -1,11 +1,10 @@
# Crypto CLI and Rhai Scripting
# 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
- Command-line interface for cryptographic operations
- Interactive shell mode
- Simplified command-line interface for script execution
- Rhai scripting engine for automation
- Key management (create, list, import, export)
- Cryptographic operations (sign, verify, encrypt, decrypt)
@@ -19,85 +18,23 @@ Build the CLI tool using Cargo:
cargo build --release
```
The binary will be available at `target/release/crypto-cli`.
The binary will be available at `target/release/hero-vault`.
## Usage
### Command Line Interface
The CLI provides several subcommands for different operations:
#### Key Management
```bash
# Create a new key space
crypto-cli key create-space <name> [password]
# List available key spaces
crypto-cli key list-spaces
# Create a new keypair
crypto-cli key create-keypair <name>
# List available keypairs
crypto-cli key list-keypairs
# Export a keypair
crypto-cli key export <name> [output-file]
# Import a keypair
crypto-cli key import <name> [input-file]
```
#### Cryptographic Operations
```bash
# Sign a message
crypto-cli crypto sign <keypair> <message> [output-file]
# Verify a signature
crypto-cli crypto verify <signature> <message> [keypair]
# Encrypt data
crypto-cli crypto encrypt <recipient> <data> [output-file]
# Decrypt data
crypto-cli crypto decrypt <keypair> <data> [output-file]
```
#### Ethereum Operations
```bash
# Create an Ethereum wallet from a keypair
crypto-cli eth create <keypair>
# Get the Ethereum address for a keypair
crypto-cli eth address <keypair>
# Get the balance of an Ethereum address
crypto-cli eth balance <address> <network>
```
### Interactive Shell
Launch the interactive shell with:
```bash
crypto-cli shell
```
In the shell, you can run the same commands as in the CLI but without the `crypto-cli` prefix.
### Rhai Scripting
Execute Rhai scripts with:
The CLI has been simplified to directly process Rhai scripts:
```bash
# Execute a script file
crypto-cli script <path-to-script>
hero-vault path/to/script.rhai
# Execute an inline script
crypto-cli script --inline "create_keypair('test'); sign('Hello, world!');"
# 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
@@ -106,10 +43,10 @@ The Rhai scripting engine provides access to the following functions:
### Key Management
- `create_key_space(name)` - Create a new key space
- `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)` - Create a new keypair
- `create_keypair(name, password)` - Create a new keypair
- `select_keypair(name)` - Select a keypair for operations
- `list_keypairs()` - List available keypairs
@@ -126,39 +63,22 @@ The Rhai scripting engine provides access to the following functions:
- `create_ethereum_wallet()` - Create an Ethereum wallet
- `get_ethereum_address()` - Get the Ethereum address for the selected keypair
## Example Script
## Example Scripts
```rhai
// Create a key space and keypair
create_key_space("demo");
create_keypair("alice");
select_keypair("alice");
Example scripts are available in the `scripts/rhai` directory:
// Sign and verify a message
let message = "Hello, world!";
let signature = sign(message);
let is_valid = verify(message, signature);
print("Signature valid: " + is_valid);
// Symmetric encryption
let key = generate_key();
let ciphertext = encrypt(key, "Secret message");
let plaintext = decrypt(key, ciphertext);
print("Decrypted: " + plaintext);
// Ethereum operations
create_ethereum_wallet();
let address = get_ethereum_address();
print("Ethereum address: " + address);
```
- `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 `~/.crypto-cli/config.json`. You can specify a different configuration file with the `--config` option.
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
crypto-cli --verbose <command>
hero-vault --verbose path/to/script.rhai