.. | ||
examples | ||
rhai | ||
README.md | ||
run_examples.sh |
WebAssembly Cryptography Module Scripts
This directory contains example scripts and documentation for the WebAssembly Cryptography Module's scripting and messaging capabilities.
Directory Structure
rhai/
: Example Rhai scripts that demonstrate the cryptographic operationsexamples/
: Documentation and code examples for messaging system integration
Rhai Scripts
The rhai/
directory contains example Rhai scripts that can be executed using the CLI:
crypto-cli script --path scripts/rhai/example.rhai
These scripts demonstrate how to use the cryptographic functions exposed to the Rhai scripting engine, including:
- Key space management
- Keypair operations
- Signing and verification
- Symmetric encryption and decryption
- Ethereum wallet operations
Messaging Examples
The examples/
directory contains documentation and code examples for integrating the WebAssembly Cryptography Module with messaging systems:
mycelium_example.md
: Example of using Mycelium for peer-to-peer, end-to-end encrypted messagingnats_example.md
: Example of using NATS for high-performance, client-server messaging
These examples demonstrate how to:
- Start a listener for remote script execution
- Send scripts from remote systems
- Process the results of script execution
- Implement security measures for remote execution
Creating Your Own Scripts
You can create your own Rhai scripts to automate cryptographic operations. The following functions are available in the scripting API:
Key Space Management
create_key_space(name)
: Create a new key spaceencrypt_key_space(password)
: Encrypt the current key spacedecrypt_key_space(encrypted, password)
: Decrypt and load a key space
Keypair Operations
create_keypair(name)
: Create a new keypairselect_keypair(name)
: Select a keypair for uselist_keypairs()
: List all keypairs in the current space
Cryptographic Operations
sign(message)
: Sign a message with the selected keypairverify(message, signature)
: Verify a signaturegenerate_key()
: Generate a symmetric 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 of the current wallet
Security Considerations
When using scripts, especially with remote execution via messaging systems, consider the following security measures:
- Script Validation: Validate scripts before execution to prevent malicious code
- Resource Limits: Set appropriate limits on script execution to prevent denial of service
- Authentication: Ensure that only authorized users or systems can execute scripts
- Sensitive Data: Be careful about what data is returned in script results
- Encryption: Use encrypted communication channels for remote script execution