Created
March 4, 2021 10:09
-
-
Save microdog/483825d3c2653c8baeb95e0200013ae3 to your computer and use it in GitHub Desktop.
Migrate clef keystore generated by bee-clef to lightkdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
parse_json() { echo "$1" | sed -e 's/[{}]/''/g' | sed -e 's/", "/'\",\"'/g' | sed -e 's/" ,"/'\",\"'/g' | sed -e 's/" , "/'\",\"'/g' | sed -e 's/","/'\"---SEPERATOR---\"'/g' | awk -F=':' -v RS='---SEPERATOR---' "\$1~/\"$2\"/ {print}" | sed -e "s/\"$2\"://" | tr -d "\n\t" | sed -e 's/\\"/"/g' | sed -e 's/\\\\/\\/g' | sed -e 's/^[ \t]*//g' | sed -e 's/^"//' -e 's/"$//'; } | |
chk_command() { | |
if ! command -v "$1" &>/dev/null; then | |
echo "missing clef: $1" | |
exit 1 | |
fi | |
} | |
DATA="$1" | |
DATA="${DATA:-$(pwd)}" | |
CLEF="${CLEF:-clef}" | |
ADDRESS="0x$(parse_json "$(cat "$DATA"/keystore/*)" address)" | |
SECRET="$(cat "$DATA"/password)" | |
chk_command "$CLEF" | |
echo "Using data dir: $DATA" | |
echo "Migrating master key..." | |
$CLEF --keystore "$DATA"/keystore --configdir "$DATA" --stdio-ui --lightkdf migratekey >/dev/null 2>&1 <<EOF | |
$SECRET | |
$SECRET | |
$SECRET | |
EOF | |
echo "Migrating account($ADDRESS)..." | |
$CLEF --keystore "$DATA"/keystore --configdir "$DATA" --stdio-ui --lightkdf migrateaccount "$ADDRESS" >/dev/null 2>&1 <<EOF | |
$SECRET | |
EOF | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment