From 0ee1eddfb4147478e83b035f36208629c1bc3100 Mon Sep 17 00:00:00 2001 From: anhthii Date: Wed, 9 Jul 2025 16:13:37 +0700 Subject: [PATCH] Add setup_identities, initiator --- setup_identities.sh | 59 +++++++++++++++++++++++++++++++++++++++++++++ setup_initiator.sh | 41 +++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 setup_identities.sh create mode 100644 setup_initiator.sh diff --git a/setup_identities.sh b/setup_identities.sh new file mode 100644 index 0000000..708c961 --- /dev/null +++ b/setup_identities.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +# Number of nodes to create (default is 3) +NUM_NODES=3 + +echo "🚀 Setting up Node Identities..." + +# Create node directories and copy config files +echo "📁 Creating node directories..." +for i in $(seq 0 $((NUM_NODES-1))); do + mkdir -p "node$i/identity" + if [ ! -f "node$i/config.yaml" ]; then + cp config.yaml "node$i/" + fi + if [ ! -f "node$i/peers.json" ]; then + cp peers.json "node$i/" + fi +done + +# Generate identity for each node +echo "🔑 Generating identities for each node..." +for i in $(seq 0 $((NUM_NODES-1))); do + echo "📝 Generating identity for node$i..." + cd "node$i" + mpcium-cli generate-identity --node "node$i" + cd .. +done + +# Distribute identity files to all nodes +echo "🔄 Distributing identity files across nodes..." +for i in $(seq 0 $((NUM_NODES-1))); do + for j in $(seq 0 $((NUM_NODES-1))); do + if [ $i != $j ]; then + echo "📋 Copying node${i}_identity.json to node$j..." + cp "node$i/identity/node${i}_identity.json" "node$j/identity/" + fi + done +done + +echo "✨ Node identities setup complete!" +echo +echo "📂 Created folder structure:" +echo "├── node0" +echo "│ ├── config.yaml" +echo "│ ├── identity/" +echo "│ └── peers.json" +echo "├── node1" +echo "│ ├── config.yaml" +echo "│ ├── identity/" +echo "│ └── peers.json" +echo "└── node2" +echo " ├── config.yaml" +echo " ├── identity/" +echo " └── peers.json" +echo +echo "✅ You can now start your nodes with:" +echo "cd node0 && mpcium start -n node0" +echo "cd node1 && mpcium start -n node1" +echo "cd node2 && mpcium start -n node2" diff --git a/setup_initiator.sh b/setup_initiator.sh new file mode 100644 index 0000000..e9488b7 --- /dev/null +++ b/setup_initiator.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +echo "🚀 Setting up Event Initiator..." + +# Generate the event initiator +echo "📝 Generating event initiator..." +mpcium-cli generate-initiator + +# Extract the public key from the generated file +if [ -f "event_initiator.identity.json" ]; then + PUBLIC_KEY=$(grep -o '"public_key": *"[^"]*"' event_initiator.identity.json | cut -d'"' -f4) + + if [ -n "$PUBLIC_KEY" ]; then + echo "🔑 Found public key: $PUBLIC_KEY" + + # Update config.yaml + if [ -f "config.yaml" ]; then + echo "📝 Updating config.yaml..." + # Check if event_initiator_pubkey already exists + if grep -q "event_initiator_pubkey:" config.yaml; then + # Replace existing line + sed -i "s/event_initiator_pubkey: .*/event_initiator_pubkey: \"$PUBLIC_KEY\"/" config.yaml + else + # Add new line + echo "event_initiator_pubkey: \"$PUBLIC_KEY\"" >> config.yaml + fi + echo "✅ Successfully updated config.yaml" + else + echo "❌ Error: config.yaml not found. Please create it first." + exit 1 + fi + else + echo "❌ Error: Could not extract public key from event_initiator.identity.json" + exit 1 + fi +else + echo "❌ Error: event_initiator.identity.json not found" + exit 1 +fi + +echo "✨ Event Initiator setup complete!"