From 082997dbdec6ba90d64c55e86d9a21146a76fcd4 Mon Sep 17 00:00:00 2001 From: Tan Chee Keong Date: Mon, 19 Oct 2026 15:12:29 +0800 Subject: [PATCH] revise backup files --- README.md | 2 +- dkg/entrypoint.sh | 7 ++++--- operator/entrypoint.sh | 19 +++++++------------ 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 3ad2e86..2e84718 100644 --- a/README.md +++ b/README.md @@ -17,4 +17,4 @@ If you have a registered operator, you should already have a private key with yo Anchor will start to run and after a short time, you should see that Anchor will display the operator id on the log. Note that the upload option will only appear once on a fresh install and it can't be modified afterwards without deleting the whole Anchor package. ### Backup your key -There is a `BACKUP` tab in the Anchor package. It enables you to download the Anchor data which includes the public-private key pair. We strongly recommend you to make a backup copy of the key pair. Once you go to the `BACKUP` tab, click on `Download backup`. This will download a compressed file. After extracting the file, under the folder `keys` lies the private key, named `encrpted_private_key.json` and the password text file. You can then backup the private key file with your preferred backup option. \ No newline at end of file +There is a `BACKUP` tab in the Anchor package. It enables you to download the Anchor data which includes the public-private key pair. We strongly recommend you to make a backup copy of the key pair. Once you go to the `BACKUP` tab, click on `Download backup`. This will download a compressed file. After extracting the file, under the folder `keys` lies the private key, named `encrypted_private_key.json` and the password file, named `private_key_password`. Once the operator is registered and the operator id is known to the DKG service, the backup folder also contains `operator_id.txt`. \ No newline at end of file diff --git a/dkg/entrypoint.sh b/dkg/entrypoint.sh index d8b2adf..4d9389c 100644 --- a/dkg/entrypoint.sh +++ b/dkg/entrypoint.sh @@ -6,8 +6,8 @@ DKG_OUTPUT_DIR=${DKG_DATA_DIR}/output DKG_CERT_DIR=${DKG_DATA_DIR}/ssl PRIVATE_KEY_FILE=${OPERATOR_CONFIG_DIR}/encrypted_private_key.json -PRIVATE_KEY_PASSWORD_FILE=${OPERATOR_CONFIG_DIR}/password.txt -OPERATOR_ID_FILE=/data/dkg/operator_id.txt +PRIVATE_KEY_PASSWORD_FILE=${OPERATOR_CONFIG_DIR}/private_key_password +OPERATOR_ID_FILE=${OPERATOR_CONFIG_DIR}/operator_id.txt DKG_CONFIG_FILE=${DKG_CONFIG_DIR}/dkg-config.yml DKG_LOG_FILE=${DKG_LOGS_DIR}/dkg.log @@ -61,7 +61,8 @@ get_operator_id() { fetch_operator_id_from_api() { echo "[INFO] OPERATOR_ID not provided. Fetching OPERATOR_ID from the API..." - PUBLIC_KEY=$(jq -r '.pubKey' "${PRIVATE_KEY_FILE}") + # Anchor generates keys with '.pubkey', SSV with '.pubKey' + PUBLIC_KEY=$(jq -r '.pubkey // .pubKey' "${PRIVATE_KEY_FILE}") # If the PUBLIC_KEY is empty, try extracting using the '.publicKey' field (for previous SSV versions) if [ -z "$PUBLIC_KEY" ] || [ "$PUBLIC_KEY" = "null" ]; then diff --git a/operator/entrypoint.sh b/operator/entrypoint.sh index 1ba9704..00a9a39 100755 --- a/operator/entrypoint.sh +++ b/operator/entrypoint.sh @@ -9,16 +9,16 @@ EXECUTION_RPC=$(get_execution_rpc_api_url_from_global_env "$NETWORK") EXECUTION_WS=$(get_execution_ws_url_from_global_env "$NETWORK") BEACON_NODES=$(get_beacon_api_url_from_global_env "$NETWORK") -PASSWORD_FILE_PATH="/root/keys/password.txt" +PASSWORD_FILE_PATH="/root/keys/private_key_password" KEY_FILE_PATH="/root/keys/encrypted_private_key.json" -PUBLIC_KEY_FILE_PATH="/root/keys/public_key.txt" sleep 1 post_pubkey_to_dappmanager() { - PUBLIC_KEY=$(cat "$PUBLIC_KEY_FILE_PATH") + # The public key is embedded in the encrypted private key file + PUBLIC_KEY=$(jq -r '.pubkey // .pubKey // empty' "$KEY_FILE_PATH") if [ -z "$PUBLIC_KEY" ]; then - echo "[ERROR - entrypoint] Public key not found at ${PUBLIC_KEY_FILE_PATH}, skipping Dappmanager post" + echo "[ERROR - entrypoint] Public key not found in ${KEY_FILE_PATH}, skipping Dappmanager post" return 1 fi @@ -37,7 +37,7 @@ post_pubkey_to_dappmanager() { echo "PUBLIC_KEY=${PUBLIC_KEY}" } -# If Import Operator, save the EXISTING_PASSWORD to the password.txt at first import +# In Import Operator, save the EXISTING_PASSWORD to the password file at first import # Later when Anchor is starting it will use --password-file flag to decrypt the private key if [ "${SETUP_MODE}" = "Import Operator" ]; then @@ -53,13 +53,6 @@ if [ "${SETUP_MODE}" = "Import Operator" ]; then echo "[DEBUG] encrypted_private_key.json doesn't exist, restarting" exit 1 fi - - # Extract the public key from the imported encrypted_private_key.json - PUBLIC_KEY=$(jq -r '.pubkey // .pubKey // empty' "$KEY_FILE_PATH") - # Only writing the file when non-empty - if [ -n "$PUBLIC_KEY" ]; then - echo "$PUBLIC_KEY" > "$PUBLIC_KEY_FILE_PATH" - fi fi # If New Operator, generate a new public-private key pair during the first time setup @@ -73,6 +66,8 @@ if [ "${SETUP_MODE}" = "New Operator" ]; then echo "$NEW_PASSWORD" > "$PASSWORD_FILE_PATH" echo "[INFO - entrypoint] Generating new public-private key pair" anchor keygen --encrypt --password-file="$PASSWORD_FILE_PATH" --data-dir /root/keys + # keygen also writes public_key.txt, remove it to keep it out of the backup files + rm -f /root/keys/public_key.txt fi fi