From 54f604f16a8aed22b0dd07cb34d94d0a0994c868 Mon Sep 17 00:00:00 2001 From: Sameh Abouelsaad Date: Thu, 8 May 2025 16:28:13 +0300 Subject: [PATCH] update docs --- CLI_README.md | 120 ++++++---------------------------- README.md | 11 ++-- scripts/README.md | 6 +- scripts/rhai/README.md | 2 +- src/bin/test_serialization.rs | 66 ------------------- 5 files changed, 29 insertions(+), 176 deletions(-) delete mode 100644 src/bin/test_serialization.rs diff --git a/CLI_README.md b/CLI_README.md index 7a965a7..69292b9 100644 --- a/CLI_README.md +++ b/CLI_README.md @@ -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 [password] - -# List available key spaces -crypto-cli key list-spaces - -# Create a new keypair -crypto-cli key create-keypair - -# List available keypairs -crypto-cli key list-keypairs - -# Export a keypair -crypto-cli key export [output-file] - -# Import a keypair -crypto-cli key import [input-file] -``` - -#### Cryptographic Operations - -```bash -# Sign a message -crypto-cli crypto sign [output-file] - -# Verify a signature -crypto-cli crypto verify [keypair] - -# Encrypt data -crypto-cli crypto encrypt [output-file] - -# Decrypt data -crypto-cli crypto decrypt [output-file] -``` - -#### Ethereum Operations - -```bash -# Create an Ethereum wallet from a keypair -crypto-cli eth create - -# Get the Ethereum address for a keypair -crypto-cli eth address - -# Get the balance of an Ethereum address -crypto-cli eth balance
-``` - -### 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 +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 +hero-vault --verbose path/to/script.rhai diff --git a/README.md b/README.md index b9ac87c..9956509 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,13 @@ This project provides a WebAssembly module written in Rust that offers cryptographic functionality for web applications. -## Planned Enhancements +## Features -We are planning significant enhancements to this module, including: -- Command Line Interface (CLI) -- Rhai scripting capabilities -- Messaging system integration (Mycelium or NATS) +- **WebAssembly Module** - Core cryptographic functionality for web applications +- **Command Line Interface (CLI)** - Simplified CLI for executing Rhai scripts +- **Rhai Scripting** - Powerful scripting capabilities for automation -For details, see the [Enhancement Specification](ENHANCEMENT_SPEC.md). +For CLI usage details, see the [CLI README](CLI_README.md). ## Features diff --git a/scripts/README.md b/scripts/README.md index ea25590..04144fe 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -12,7 +12,7 @@ This directory contains example scripts and documentation for the WebAssembly Cr The `rhai/` directory contains example Rhai scripts that can be executed using the CLI: ```bash -crypto-cli script --path scripts/rhai/example.rhai +hero-vault scripts/rhai/example.rhai ``` These scripts demonstrate how to use the cryptographic functions exposed to the Rhai scripting engine, including: @@ -43,13 +43,13 @@ You can create your own Rhai scripts to automate cryptographic operations. The f ### Key Space 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 and load a key space ### Keypair Operations -- `create_keypair(name)`: Create a new keypair +- `create_keypair(name, password)`: Create a new keypair - `select_keypair(name)`: Select a keypair for use - `list_keypairs()`: List all keypairs in the current space diff --git a/scripts/rhai/README.md b/scripts/rhai/README.md index 45c57d7..0bdef9d 100644 --- a/scripts/rhai/README.md +++ b/scripts/rhai/README.md @@ -43,7 +43,7 @@ if load_key_space(space_name, password) { ## Key Space Storage -Key spaces are stored in the `~/.crypto-cli/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`). +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`). ## Security diff --git a/src/bin/test_serialization.rs b/src/bin/test_serialization.rs deleted file mode 100644 index 53d4e7e..0000000 --- a/src/bin/test_serialization.rs +++ /dev/null @@ -1,66 +0,0 @@ -use webassembly::core::keypair::{KeySpace, KeyPair}; -use webassembly::core::symmetric; -use std::fs; -use serde_json; - -fn main() -> Result<(), Box> { - // Create a key space - let mut space = KeySpace::new("test-space"); - - // Add a keypair - let keypair = KeyPair::new("test-keypair"); - space.keypairs.insert("test-keypair".to_string(), keypair); - - // Print the key space - println!("Key space: {:?}", space); - - // Serialize the key space directly to see what it looks like - let direct_serialized = serde_json::to_string_pretty(&space)?; - println!("Direct serialized key space:\n{}", direct_serialized); - - // Encrypt the key space - let password = "test123"; - let encrypted_space = symmetric::encrypt_key_space(&space, password)?; - - // Serialize the encrypted space - let serialized = symmetric::serialize_encrypted_space(&encrypted_space)?; - - // Write to file - fs::write("test_keyspace.json", &serialized)?; - println!("Wrote encrypted key space to test_keyspace.json"); - - // Read from file - let serialized = fs::read_to_string("test_keyspace.json")?; - - // Deserialize the encrypted space - let encrypted_space = symmetric::deserialize_encrypted_space(&serialized)?; - println!("Deserialized encrypted space: {:?}", encrypted_space.metadata); - - // Decrypt the key space - let decrypted_data = symmetric::decrypt_symmetric( - &symmetric::derive_key_from_password(password), - &encrypted_space.encrypted_data - )?; - - println!("Decrypted data length: {}", decrypted_data.len()); - println!("Decrypted data preview: {:?}", &decrypted_data[..20]); - - // Try to deserialize manually - match serde_json::from_slice::(&decrypted_data) { - Ok(space) => { - println!("Manual deserialization successful!"); - println!("Decrypted key space: {:?}", space); - println!("Keypairs: {:?}", space.list_keypairs()); - }, - Err(e) => { - println!("Manual deserialization error: {}", e); - // Try to print the decrypted data as a string to see what's wrong - match std::str::from_utf8(&decrypted_data) { - Ok(s) => println!("Decrypted data as string: {}", s), - Err(_) => println!("Decrypted data is not valid UTF-8"), - } - } - } - - Ok(()) -}