@@ -28,6 +28,11 @@ echo "🔐 Generating random password for badger encryption..."
2828BADGER_PASSWORD=$( < /dev/urandom tr -dc ' A-Za-z0-9' | head -c 32)
2929echo " ✅ Generated password: $BADGER_PASSWORD "
3030
31+ # Generate chain_code (32-byte hex value, 64 hex characters)
32+ echo " 🔐 Generating chain_code (32-byte hex)..."
33+ CHAIN_CODE=$( openssl rand -hex 32)
34+ echo " ✅ Generated chain_code: $CHAIN_CODE "
35+
3136# Generate config.test.yaml from template
3237echo " 📝 Generating config.test.yaml from template..."
3338if [ ! -f " config.test.yaml.template" ]; then
@@ -43,6 +48,7 @@ ESCAPED_PASSWORD=$(printf '%s\n' "$BADGER_PASSWORD" | sed 's/[[\.*^$()+?{|]/\\&/
4348
4449sed -e " s/{{\.BadgerPassword}}/$ESCAPED_PASSWORD /g" \
4550 -e " s/{{\.EventInitiatorPubkey}}/$TEMP_PUBKEY /g" \
51+ -e " s/{{\.CKDChainCode}}/$CHAIN_CODE /g" \
4652 config.test.yaml.template > config.test.yaml
4753
4854echo " ✅ Generated config.test.yaml from template"
@@ -106,20 +112,35 @@ if [ -f "test_event_initiator.identity.json" ]; then
106112 PUBKEY=$( cat test_event_initiator.identity.json | jq -r ' .public_key' )
107113 echo " 📝 Updating config files with event initiator public key and password..."
108114
109- # Update all test node config files with the actual public key and password
115+ # Update all test node config files with the actual public key, password, and chain_code
110116 for i in $( seq 0 $(( NUM_NODES- 1 )) ) ; do
111117 # Update public key using sed with | as delimiter (safer than /)
112118 sed_inplace " s|event_initiator_pubkey:.*|event_initiator_pubkey: $PUBKEY |g" " $BASE_DIR /test_node$i /config.yaml"
113119 # Update password using sed with | as delimiter and escaped password
114120 sed_inplace " s|badger_password:.*|badger_password: $ESCAPED_PASSWORD |g" " $BASE_DIR /test_node$i /config.yaml"
121+ # Update chain_code
122+ if grep -q ' ^\s*chain_code:' " $BASE_DIR /test_node$i /config.yaml" ; then
123+ sed_inplace " s|chain_code:.*|chain_code: \" $CHAIN_CODE \" |g" " $BASE_DIR /test_node$i /config.yaml"
124+ else
125+ printf ' \nchain_code: "%s"\n' " $CHAIN_CODE " >> " $BASE_DIR /test_node$i /config.yaml"
126+ fi
115127 done
116128
117129 # Also update the main config.test.yaml
118130 sed_inplace " s|event_initiator_pubkey:.*|event_initiator_pubkey: $PUBKEY |g" " $BASE_DIR /config.test.yaml"
119131 sed_inplace " s|badger_password:.*|badger_password: $ESCAPED_PASSWORD |g" " $BASE_DIR /config.test.yaml"
132+ # Update chain_code in config.test.yaml if it was replaced with placeholder
133+ if grep -q ' {{\.CKDChainCode}}' " $BASE_DIR /config.test.yaml" 2> /dev/null; then
134+ sed_inplace " s|{{\.CKDChainCode}}|$CHAIN_CODE |g" " $BASE_DIR /config.test.yaml"
135+ elif grep -q ' ^\s*chain_code:' " $BASE_DIR /config.test.yaml" ; then
136+ sed_inplace " s|chain_code:.*|chain_code: \" $CHAIN_CODE \" |g" " $BASE_DIR /config.test.yaml"
137+ else
138+ printf ' \nchain_code: "%s"\n' " $CHAIN_CODE " >> " $BASE_DIR /config.test.yaml"
139+ fi
120140
121141 echo " ✅ Event initiator public key updated: $PUBKEY "
122142 echo " ✅ Badger password updated: $BADGER_PASSWORD "
143+ echo " ✅ Chain code updated: $CHAIN_CODE "
123144else
124145 echo " ❌ Failed to generate event initiator identity"
125146 exit 1
0 commit comments