#!/bin/bash # Script to run the example Rhai scripts and demonstrate the WebAssembly Cryptography Module # Colors for output GREEN='\033[0;32m' BLUE='\033[0;34m' RED='\033[0;31m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Function to print section headers print_header() { echo -e "\n${BLUE}======================================${NC}" echo -e "${BLUE}$1${NC}" echo -e "${BLUE}======================================${NC}\n" } # Function to run a Rhai script run_script() { echo -e "${YELLOW}Running script: $1${NC}" echo -e "${YELLOW}------------------------${NC}" if [ -f "$1" ]; then echo -e "${GREEN}Script output:${NC}" crypto-cli script "$1" echo -e "\n${GREEN}Script execution completed.${NC}" else echo -e "${RED}Error: Script file not found: $1${NC}" fi } # Check if crypto-cli is installed if ! command -v crypto-cli &> /dev/null; then echo -e "${RED}Error: crypto-cli is not installed or not in PATH.${NC}" echo -e "${YELLOW}Please build and install the CLI first:${NC}" echo -e " cargo build --bin crypto-cli" echo -e " cargo install --path ." exit 1 fi # Print welcome message print_header "WebAssembly Cryptography Module Examples" echo -e "This script will run the example Rhai scripts to demonstrate the functionality of the WebAssembly Cryptography Module." echo -e "Make sure you have built and installed the CLI before running this script.\n" # Ask user which example to run echo -e "${YELLOW}Which example would you like to run?${NC}" echo -e "1. Basic example (key management, signing, encryption)" echo -e "2. Advanced example (error handling, multiple operations)" echo -e "3. Multi-script workflows (chaining scripts)" echo -e "4. Run all examples" echo -e "5. Exit" read -p "Enter your choice (1-4): " choice case $choice in 1) print_header "Running Basic Example" run_script "scripts/rhai/example.rhai" ;; 2) print_header "Running Advanced Example" run_script "scripts/rhai/advanced_example.rhai" ;; 3) print_header "Running Multi-Script Workflows" run_script "scripts/rhai/key_persistence_example.rhai" echo -e "\n" run_script "scripts/rhai/load_existing_space.rhai" ;; 4) print_header "Running All Examples" run_script "scripts/rhai/example.rhai" echo -e "\n" run_script "scripts/rhai/advanced_example.rhai" echo -e "\n" run_script "scripts/rhai/key_persistence_example.rhai" echo -e "\n" run_script "scripts/rhai/load_existing_space.rhai" ;; 5) echo -e "${YELLOW}Exiting...${NC}" exit 0 ;; *) echo -e "${RED}Invalid choice. Exiting...${NC}" exit 1 ;; esac # Print information about messaging examples print_header "Messaging System Examples" echo -e "To try the messaging system examples, you can:" echo -e "1. Start a listener for remote script execution:" echo -e " ${YELLOW}crypto-cli listen${NC}" echo -e "" echo -e "2. For Mycelium integration, see:" echo -e " ${YELLOW}scripts/examples/mycelium_example.md${NC}" echo -e "" echo -e "3. For NATS integration, see:" echo -e " ${YELLOW}scripts/examples/nats_example.md${NC}" echo -e "\n${GREEN}Thank you for trying the WebAssembly Cryptography Module examples!${NC}"