Skip to content

Commit 3ecedf8

Browse files
committed
Udpate chain code instruction
1 parent 20ef728 commit 3ecedf8

6 files changed

Lines changed: 76 additions & 16 deletions

File tree

INSTALLATION.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,47 @@ Detailed steps can be found in [SETUP.md](SETUP.md).
5656

5757
---
5858

59-
## chain_code setup (required)
59+
## chain_code setup (REQUIRED)
6060

61-
Generate one 32-byte hex chain code and set it in all configs:
61+
### What is chain_code?
62+
63+
The `chain_code` is a cryptographic parameter used for Hierarchical Deterministic (HD) wallet functionality. It enables mpcium to derive child keys from a parent key, allowing you to generate multiple wallet addresses from a single master key.
64+
65+
**Important Requirements:**
66+
- **All nodes in your MPC cluster MUST use the identical chain_code value**
67+
- Must be a 32-byte value represented as a 64-character hexadecimal string
68+
- Should be generated once and stored securely
69+
- Without a valid chain_code, mpcium nodes will fail to start
70+
71+
### How to generate and configure
72+
73+
Generate one 32-byte hex chain code and set it in all node configurations:
6274

6375
```bash
64-
cd /home/carmy/Documents/works/mpcium
76+
# Navigate to your mpcium directory
77+
cd /path/to/mpcium
78+
79+
# Generate a random 32-byte chain code and save it
6580
CC=$(openssl rand -hex 32) && echo "$CC" > .chain_code
81+
82+
# Apply to main config
6683
sed -i -E "s|^([[:space:]]*chain_code:).*|\1 \"$CC\"|" config.yaml
84+
85+
# Apply to all node configs
6786
for n in node0 node1 node2; do
6887
sed -i -E "s|^([[:space:]]*chain_code:).*|\1 \"$CC\"|" "$n/config.yaml"
6988
done
89+
90+
# Verify it was set correctly
91+
echo "Chain code configured: $CC"
92+
```
93+
94+
**Example config.yaml entry:**
95+
```yaml
96+
chain_code: "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2"
7097
```
7198
72-
Start nodes normally (no env export needed):
99+
Start nodes normally:
73100
74101
```bash
75102
cd node0 && mpcium start -n node0

README.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,12 @@ The application uses a YAML configuration file (`config.yaml`) with the followin
133133
- `event_initiator_pubkey`: Public key of the event initiator
134134
- `max_concurrent_keygen`: Maximum concurrent key generation operations
135135

136-
#### chain_code (required)
137-
- Mpcium derives child keys using a master chain code.
138-
- Provide a single 32-byte hex value in `config.yaml` under `chain_code`, and use the same value for all nodes.
139-
- Example to generate once and set:
140-
```bash
141-
CC=$(openssl rand -hex 32)
142-
sed -i -E "s|^([[:space:]]*chain_code:).*|\1 \"$CC\"|" config.yaml
143-
for n in node0 node1 node2; do
144-
sed -i -E "s|^([[:space:]]*chain_code:).*|\1 \"$CC\"|" "$n/config.yaml"
145-
done
146-
```
136+
#### chain_code (REQUIRED)
137+
- **Required** for Hierarchical Deterministic (HD) wallet functionality to derive child keys
138+
- Must be a 32-byte hexadecimal string (64 characters)
139+
- **All nodes MUST use the exact same chain_code value**
140+
- Generate with: `openssl rand -hex 32`
141+
- See [INSTALLATION.md](./INSTALLATION.md#chain_code-setup-required) for detailed setup instructions
147142

148143
## Installation
149144

config.prod.yaml.template

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ mpc_threshold: 1
1717
environment: production # Set to production for production environment
1818
backup_enabled: true
1919
event_initiator_pubkey: ""
20-
event_initiator_algorithm: ed25519 # ed25519 or p256
20+
event_initiator_algorithm: ed25519 # ed25519 or p256
21+
22+
# Chain Code for HD Wallet Child Key Derivation (REQUIRED)
23+
# This is used for hierarchical deterministic (HD) wallet functionality to derive child keys.
24+
# All nodes in the MPC cluster MUST use the same chain_code value.
25+
# Generate once with: openssl rand -hex 32
26+
# Store securely and use the same value across all nodes
27+
chain_code: ""
2128
backup_period_seconds: 300 # Seconds
2229
backup_dir: backups
2330
max_concurrent_keygen: 2

config.yaml.template

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ environment: development
88
badger_password: "F))ysJp?E]ol&I;^"
99
event_initiator_algorithm: "ed25519" # or "ed25519", default: ed25519
1010
event_initiator_pubkey: "event_initiator_pubkey"
11+
12+
# Chain Code for HD Wallet Child Key Derivation (REQUIRED)
13+
# This is used for hierarchical deterministic (HD) wallet functionality to derive child keys.
14+
# All nodes in the MPC cluster MUST use the same chain_code value.
15+
# Generate once with: openssl rand -hex 32
16+
# Example: chain_code: "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2"
17+
chain_code: ""
1118
db_path: "."
1219
backup_enabled: true
1320
backup_period_seconds: 300 # 5 minutes

deployments/systemd/setup-config.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,27 @@ validate_config_credentials() {
418418
else
419419
log_info "✓ event_initiator_pubkey configured"
420420
fi
421+
422+
# Check for required chain_code
423+
if ! grep -q "^chain_code:" "$config_file" || grep -q "^chain_code: *$" "$config_file" || grep -q '^chain_code: ""' "$config_file"; then
424+
log_error "❌ chain_code not configured in config.yaml"
425+
log_error " Generate with: openssl rand -hex 32"
426+
log_error " All nodes MUST use the same chain_code value"
427+
((errors++))
428+
else
429+
# Validate chain_code is 64 hex characters (32 bytes)
430+
local chain_code=$(grep "^chain_code:" "$config_file" | sed 's/chain_code: *//g' | sed 's/"//g' | sed "s/'//g" | sed 's/#.*//g' | sed 's/ *$//g')
431+
if [[ ${#chain_code} -ne 64 ]]; then
432+
log_error "❌ chain_code must be 64 hex characters (32 bytes), got ${#chain_code} characters"
433+
log_error " Generate with: openssl rand -hex 32"
434+
((errors++))
435+
elif ! [[ "$chain_code" =~ ^[0-9a-fA-F]{64}$ ]]; then
436+
log_error "❌ chain_code must be hexadecimal (0-9, a-f), got invalid characters"
437+
((errors++))
438+
else
439+
log_info "✓ chain_code configured (${#chain_code} hex chars)"
440+
fi
441+
fi
421442

422443
# Check for NATS configuration
423444
local nats_url=$(grep -A 10 "^nats:" "$config_file" | grep "url:" | sed 's/.*url: *//g' | sed 's/"//g' | sed "s/'//g" | sed 's/#.*//g' | sed 's/ *$//g')

e2e/config.test.yaml.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ nats:
1111
max_concurrent_keygen: 1
1212
max_concurrent_signing: 10
1313
session_warm_up_delay_ms: 500
14+
15+
# Chain Code for HD Wallet Child Key Derivation (REQUIRED)
16+
# All nodes MUST use the same chain_code value
1417
chain_code: "{{.CKDChainCode}}"

0 commit comments

Comments
 (0)