From 34c5c8fd2f87aee093ad234bc4034963786bfc45 Mon Sep 17 00:00:00 2001 From: Slava <20563034+veaceslavdoina@users.noreply.github.com> Date: Wed, 9 Oct 2024 08:28:38 +0300 Subject: [PATCH] Accept user provided ethereum private key to save it locally --- scripts/generate.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/scripts/generate.sh b/scripts/generate.sh index 8baf431..4362726 100755 --- a/scripts/generate.sh +++ b/scripts/generate.sh @@ -6,7 +6,8 @@ key_file="eth.key" address_file="eth.address" url=https://key.codex.storage -# Generate +# Generate remote +generate_remote() { echo "Generating private key from remote <${url}>..." response=$(curl -s ${url}) @@ -21,3 +22,22 @@ address=$(cat ${address_file}) echo " * your private key has been saved to ${PWD}/${key_file}" echo " * your ethereum address has been saved to ${PWD}/${address_file}" echo " * your ethereum address is ${address}" +} + +# Use user provided private key +user_private_key() { + # Create file with required permissions + echo "${ETH_PRIVATE_KEY}" >"${key_file}" + chmod 600 "${key_file}" + + echo "Using provided private key..." + echo " * your private key has been saved to ${PWD}/${key_file}" + echo " * please use your key address to get the tokens" +} + +# Save keyrair +if [[ -z "${ETH_PRIVATE_KEY}" ]]; then + generate_remote +else + user_private_key +fi