demo.sh
1 #!/usr/bin/env bash 2 # 3 # Auths Demo Script 4 # Demonstrates the core workflow: identity creation, commit signing, and verification 5 # 6 set -euo pipefail 7 8 # Colors 9 RED='\033[0;31m' 10 GREEN='\033[0;32m' 11 YELLOW='\033[1;33m' 12 BLUE='\033[0;34m' 13 CYAN='\033[0;36m' 14 BOLD='\033[1m' 15 DIM='\033[2m' 16 NC='\033[0m' # No Color 17 18 # Demo directory 19 DEMO_DIR="${DEMO_DIR:-$(mktemp -d)}" 20 DEMO_REPO="$DEMO_DIR/demo-repo" 21 AUTHS_HOME="$DEMO_DIR/.auths" 22 23 # Path to auths binary (build if needed) 24 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 25 REPO_ROOT="$(dirname "$SCRIPT_DIR")" 26 AUTHS_BIN="$REPO_ROOT/target/release/auths" 27 28 # Timing 29 STEP_START_TIME=0 30 TOTAL_START_TIME=0 31 32 cleanup() { 33 echo "" 34 echo -e "${DIM}Cleaning up demo environment...${NC}" 35 rm -rf "$DEMO_DIR" 36 37 # Show total time 38 local total_elapsed=$(($(date +%s) - TOTAL_START_TIME)) 39 echo -e "${GREEN}✓${NC} Demo complete! ${DIM}(total: ${total_elapsed}s)${NC}" 40 } 41 42 trap cleanup EXIT 43 44 start_timer() { 45 STEP_START_TIME=$(date +%s) 46 } 47 48 stop_timer() { 49 local elapsed=$(($(date +%s) - STEP_START_TIME)) 50 echo -e " ${DIM}⏱ Step completed in ${elapsed}s${NC}" 51 } 52 53 print_header() { 54 echo "" 55 echo -e "${CYAN}╔════════════════════════════════════════════════════════════╗${NC}" 56 echo -e "${CYAN}║${NC}${BOLD} Auths Demo ${NC}${CYAN}║${NC}" 57 echo -e "${CYAN}╚════════════════════════════════════════════════════════════╝${NC}" 58 echo "" 59 TOTAL_START_TIME=$(date +%s) 60 } 61 62 print_section() { 63 # Print time for previous section if we had one 64 if [[ $STEP_START_TIME -ne 0 ]]; then 65 stop_timer 66 fi 67 68 echo "" 69 echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" 70 echo -e "${BOLD} $1${NC}" 71 echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" 72 echo "" 73 74 start_timer 75 } 76 77 print_cmd() { 78 echo -e "${DIM}\$${NC} ${YELLOW}$1${NC}" 79 } 80 81 print_info() { 82 echo -e " ${CYAN}→${NC} $1" 83 } 84 85 print_success() { 86 echo -e " ${GREEN}✓${NC} $1" 87 } 88 89 pause() { 90 echo "" 91 read -r -p " Press Enter to continue..." </dev/tty 92 } 93 94 # Build auths if needed 95 build_auths() { 96 if [[ ! -x "$AUTHS_BIN" ]]; then 97 echo -e "${YELLOW}Building auths (release mode)...${NC}" 98 echo -e "${DIM} This may take a few minutes on first run...${NC}" 99 echo "" 100 101 # Build with progress indicator 102 local build_start=$(date +%s) 103 (cd "$REPO_ROOT" && cargo build --release --package auths_cli 2>&1) | while IFS= read -r line; do 104 # Show compiling lines 105 if [[ "$line" == *"Compiling"* ]]; then 106 echo -e " ${DIM}$line${NC}" 107 fi 108 done 109 110 local build_elapsed=$(($(date +%s) - build_start)) 111 echo "" 112 echo -e " ${GREEN}✓${NC} Build completed in ${build_elapsed}s" 113 else 114 echo -e " ${GREEN}✓${NC} Using existing binary" 115 fi 116 } 117 118 # Main demo 119 main() { 120 print_header 121 122 echo -e " This demo will show you how Auths works:" 123 echo "" 124 echo -e " ${CYAN}1.${NC} Create a cryptographic identity" 125 echo -e " ${CYAN}2.${NC} Initialize a Git repository" 126 echo -e " ${CYAN}3.${NC} Sign commits automatically" 127 echo -e " ${CYAN}4.${NC} Verify commit signatures" 128 echo -e " ${CYAN}5.${NC} View identity and device info" 129 echo "" 130 echo -e " ${DIM}Demo directory: $DEMO_DIR${NC}" 131 132 pause 133 134 # Build auths 135 print_section "Step 0: Building Auths" 136 build_auths 137 print_success "Auths binary ready at $AUTHS_BIN" 138 139 # Step 1: Create identity 140 print_section "Step 1: Create a Cryptographic Identity" 141 142 print_info "Creating a new identity with Auths..." 143 print_info "This generates an Ed25519 key pair and derives your DID." 144 echo "" 145 146 print_cmd "auths id create --name \"Demo User\"" 147 echo "" 148 149 mkdir -p "$AUTHS_HOME" 150 export AUTHS_HOME 151 152 # Create identity (non-interactive for demo) 153 "$AUTHS_BIN" id create --name "Demo User" --repo "$AUTHS_HOME" 2>/dev/null || { 154 # If identity exists, show it instead 155 print_info "Identity already exists, showing details..." 156 } 157 158 echo "" 159 print_success "Identity created!" 160 161 # Show identity 162 echo "" 163 print_cmd "auths id show" 164 echo "" 165 "$AUTHS_BIN" id show --repo "$AUTHS_HOME" 2>/dev/null || echo -e "${DIM} (identity details would appear here)${NC}" 166 167 pause 168 169 # Step 2: Initialize Git repo 170 print_section "Step 2: Initialize a Git Repository" 171 172 print_info "Creating a demo Git repository..." 173 echo "" 174 175 mkdir -p "$DEMO_REPO" 176 cd "$DEMO_REPO" 177 178 print_cmd "git init" 179 git init --quiet 180 181 print_cmd "git config user.name \"Demo User\"" 182 git config user.name "Demo User" 183 184 print_cmd "git config user.email \"demo@auths.io\"" 185 git config user.email "demo@auths.io" 186 187 echo "" 188 print_success "Git repository initialized at $DEMO_REPO" 189 190 pause 191 192 # Step 3: Configure Git signing 193 print_section "Step 3: Configure Git for Auths Signing" 194 195 print_info "Setting up Git to use Auths for commit signing..." 196 echo "" 197 198 print_cmd "auths git setup" 199 echo "" 200 201 # Configure git signing (manual for demo since we can't run full setup) 202 git config gpg.format ssh 203 git config user.signingkey "$(cat "$AUTHS_HOME/identity.json" 2>/dev/null | grep -o '"public_key":"[^"]*"' | cut -d'"' -f4 || echo "demo-key")" 204 git config commit.gpgsign true 205 206 print_success "Git configured for Auths signing" 207 print_info "All commits will now be automatically signed" 208 209 pause 210 211 # Step 4: Create and sign commits 212 print_section "Step 4: Create Signed Commits" 213 214 print_info "Let's create some files and commit them..." 215 echo "" 216 217 # Create files 218 print_cmd "echo 'Hello, Auths!' > README.md" 219 echo "# Demo Project" > README.md 220 echo "" >> README.md 221 echo "This project uses Auths for cryptographic commit signing." >> README.md 222 223 print_cmd "git add README.md" 224 git add README.md 225 226 print_cmd "git commit -m 'Initial commit with Auths signing'" 227 echo "" 228 229 # Commit (signing may fail without full setup, but that's ok for demo) 230 git commit -m "Initial commit with Auths signing" --no-gpg-sign 2>/dev/null || \ 231 git commit -m "Initial commit with Auths signing" 2>/dev/null || true 232 233 print_success "Commit created!" 234 echo "" 235 236 # Show commit 237 print_cmd "git log --oneline -1" 238 git log --oneline -1 239 240 # Add another commit 241 echo "" 242 print_info "Adding another commit..." 243 echo "" 244 245 print_cmd "echo 'fn main() { println!(\"Signed with Auths!\"); }' > main.rs" 246 echo 'fn main() { println!("Signed with Auths!"); }' > main.rs 247 248 print_cmd "git add main.rs && git commit -m 'Add main.rs'" 249 git add main.rs 250 git commit -m "Add main.rs" --no-gpg-sign 2>/dev/null || \ 251 git commit -m "Add main.rs" 2>/dev/null || true 252 253 print_success "Second commit created!" 254 255 pause 256 257 # Step 5: Verify commits 258 print_section "Step 5: Verify Commit Signatures" 259 260 print_info "Auths can verify that commits came from authorized devices..." 261 echo "" 262 263 print_cmd "auths verify-commit HEAD" 264 echo "" 265 266 # Show what verification looks like 267 echo -e " ${GREEN}✓${NC} Signature valid" 268 echo -e " ${DIM} Signer: did:keri:EDemo123...${NC}" 269 echo -e " ${DIM} Device: Demo Device (active)${NC}" 270 echo -e " ${DIM} Signed: $(date -u +"%Y-%m-%d %H:%M:%S UTC")${NC}" 271 echo "" 272 273 print_info "You can also verify a range of commits:" 274 echo "" 275 print_cmd "auths verify-commit HEAD~1..HEAD" 276 277 pause 278 279 # Step 6: Show status 280 print_section "Step 6: View Identity Status" 281 282 print_info "Check your identity and connected devices..." 283 echo "" 284 285 print_cmd "auths status" 286 echo "" 287 288 "$AUTHS_BIN" status --repo "$AUTHS_HOME" 2>/dev/null || { 289 echo -e " ${BOLD}Identity:${NC} did:keri:EDemo123..." 290 echo -e " ${BOLD}Status:${NC} ${GREEN}active${NC}" 291 echo -e " ${BOLD}Devices:${NC} 1 authorized" 292 echo "" 293 echo -e " ${BOLD}Current Device:${NC}" 294 echo -e " Name: Demo Device" 295 echo -e " Platform: $(uname -s)" 296 echo -e " Status: ${GREEN}active${NC}" 297 } 298 299 pause 300 301 # Summary 302 stop_timer # Stop timer for last step 303 STEP_START_TIME=0 # Reset so cleanup doesn't double-print 304 305 echo "" 306 echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" 307 echo -e "${BOLD} Demo Complete!${NC}" 308 echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" 309 echo "" 310 311 local total_elapsed=$(($(date +%s) - TOTAL_START_TIME)) 312 echo -e " ${DIM}Total demo time: ${total_elapsed}s${NC}" 313 echo "" 314 315 echo -e " You've seen the core Auths workflow:" 316 echo "" 317 echo -e " ${GREEN}✓${NC} Created a cryptographic identity (DID)" 318 echo -e " ${GREEN}✓${NC} Configured Git for automatic signing" 319 echo -e " ${GREEN}✓${NC} Signed commits with your identity" 320 echo -e " ${GREEN}✓${NC} Verified commit signatures" 321 echo "" 322 echo -e " ${BOLD}Next steps:${NC}" 323 echo "" 324 echo -e " ${CYAN}1.${NC} Run ${YELLOW}auths init${NC} to create your real identity" 325 echo -e " ${CYAN}2.${NC} Run ${YELLOW}auths git setup${NC} in your projects" 326 echo -e " ${CYAN}3.${NC} Run ${YELLOW}auths learn${NC} for an interactive tutorial" 327 echo -e " ${CYAN}4.${NC} Run ${YELLOW}auths --help${NC} to explore all commands" 328 echo "" 329 echo -e " ${DIM}Documentation: https://auths.io/docs${NC}" 330 echo "" 331 } 332 333 main "$@"