Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
wallet: backport [monero-bash v2.0.0] wallet creator
Browse files Browse the repository at this point in the history
  • Loading branch information
hinto-janai committed Sep 21, 2022
1 parent b658aac commit 844f283
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 175 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## Updates
* **Status:** Added `x/month`, `x/year`, `user` to P2Pool stats
* **Status:** Added `disk left`, `synced`, `white/grey peers` to Monero stats
* **Wallet:** All wallet types can now be created: `new, view, seed, json, spend, device, private, multisig`
* **Wallet:** Wallet names will wrap to stay within `5` wallets or `40` characters per line
* **Wallet:** Typing `exit` will exit wallet menu (only if 'exit' wallet doesn't exist)
* **Config:** Added more options to `monerod.conf` & `monero-wallet-cli.conf`
Expand Down
35 changes: 25 additions & 10 deletions monero-bash
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,36 @@ if [[ $interactive = "true" ]]; then
# SHOW WALLETS, SELECT
wallet_Count; wallet_List
while true; do
printf "${BYELLOW}%s${OFF}${BPURPLE}%s${OFF}%s" \
"[Select wallet] " "or " "[new|view|recover|exit] "
printf "${BYELLOW}%s${OFF}%s${BPURPLE}%s${OFF}%s${BRED}%s${OFF}" \
"[Select wallet]" " or " "[new]" " or " "[exit] "
read -r walletSelection

for i in ${walletList[*]}; do
# IF WALLET NAME COLLIDES WITH OPTION, ASK FOR CLARIFICATION
if [[ $walletSelection = $i && $walletSelection = "new" \
|| $walletSelection = $i && $walletSelection = "view" \
|| $walletSelection = $i && $walletSelection = "recover" ]]; then
wallet_Collision
if [[ $walletSelection = $i && $walletSelection = "new" ]]; then
echo "Wallet name is similar to option..."
while :; do
printf "${BYELLOW}%s${OFF}%s${BPURPLE}%s${OFF}" "SELECT " "or " "NEW? "
read selectNew
case $selectNew in
select|Select|SELECT)
printf "${BYELLOW}%s${BWHITE}%s${OFF}\n" "Selecting " "[$walletSelection]"
printf "%s" "Password: "
read -s -r walletPassword
printf "\n\n"
printf "${BYELLOW}%s${BWHITE}%s${OFF}\n" "Starting wallet " "[$walletSelection]"
wallet_Start
;;
new|New|NEW)
printf "\n${OFF}%s\n" "Creating new wallet..."
wallet::create
;;
*) print_Error "Invalid option" ;;
esac
done
# START WALLET IF MATCH
elif [[ $walletSelection = $i ]]; then
printf "%s\n" "Password: "
printf "%s" "Password: "
read -s -r walletPassword
printf "\n\n"
printf "${BYELLOW}%s${BWHITE}%s${OFF}\n" "Starting wallet " "[$walletSelection]"
Expand All @@ -179,9 +196,7 @@ if [[ $interactive = "true" ]]; then

# OR CATCH WALLET CREATION & ERROR INPUT
case $walletSelection in
new|New|NEW|"[new]"|"[New]") wallet_Create ; break ;;
view|View|VIEW|view-only|View-only|View-Only) wallet_View ; break ;;
recover|Recover|RECOVER|"[recover]"|"[Recover]") wallet_Recover ; break ;;
new|New|NEW) wallet::create; break;;
'exit'|'Exit'|'EXIT') exit 0;;
'exit()') printf "%s\n" "This isn't Python, but ok >_>"; exit 0;;
'exit(0);') printf "%s\n" "This isn't C, but ok >_>"; exit 0;;
Expand Down
284 changes: 121 additions & 163 deletions src/func/wallet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,184 +45,142 @@ wallet_Start()
# CD INTO .monero-bash SO FILES/LOGS GET CREATED THERE
cd "$dotMoneroBash"

# NORMAL WALLET CREATION
if [[ $createWallet = "true" ]]; then
"$binMonero/monero-wallet-cli" \
--generate-new-wallet "$wallets/$walletName" \
--password "$walletPassword" \
--mnemonic-language "$seedLanguage" \
--config-file "$config/monero-wallet-cli.conf"
error_Exit "Could not start monero-wallet-cli"

# VIEW WALLET CREATION
elif [[ $createView = "true" ]]; then
"$binMonero/monero-wallet-cli" \
--generate-from-view-key "$wallets/$walletName" \
--password "$walletPassword" \
--config-file "$config/monero-wallet-cli.conf"
error_Exit "Could not start monero-wallet-cli"

# WALLET RECOVERY WITH STANDARD SEED
elif [[ $recoverWallet = "true" ]]; then
"$binMonero/monero-wallet-cli" \
--generate-new-wallet "$wallets/$walletName" \
--password "$walletPassword" \
--restore-from-seed \
--electrum-seed "$walletSeed" \
--config-file "$config/monero-wallet-cli.conf"
error_Exit "Could not start monero-wallet-cli"
else

# IF NOT CREATING, START NORMALLY
"$binMonero/monero-wallet-cli" \
--wallet-file "$wallets/$walletSelection" \
--password "$walletPassword" \
--config-file "$config/monero-wallet-cli.conf"
error_Exit "Could not start monero-wallet-cli"
fi
# START NORMALLY
"$binMonero/monero-wallet-cli" \
--wallet-file "$wallets/$walletSelection" \
--password "$walletPassword" \
--config-file "$config/monero-wallet-cli.conf"
error_Exit "Could not start monero-wallet-cli"

# AUTO MONEROD STOP
[[ $AUTO_STOP_DAEMON = "true" ]]&& define_Monero&&process_Stop
exit 0
}

wallet_Template()
{
# WALLET NAME
while true ;do
OFF; echo -n "New wallet name: " ;IWHITE
read walletName
if [[ "$walletName" = *" "* || "$walletName" = "" ]]; then
print_Error "Wallet name cannot be empty or have spaces"
else
break
fi
done
# this much better wallet::create() function was
# stolen from [monero-bash v2.0.0] and slightly
# modified to work with the crusty old code
# that is [monero-bash v1.x.x] :D
# it allows for creation of all wallet types.
wallet::create() {
# CHECK IF MISSING BINARY
missing_MoneroCLI

# WALLET PASS
while true; do
OFF; echo -n "Wallet password: "
read -s walletPassword
echo
OFF; echo -n "Enter password again: "
read -s walletPasswordAgain
echo
if [[ "$walletPassword" = "$walletPasswordAgain" ]]; then
break
else
print_Error "Password was not the same!"
fi
done
}
wallet_Create()
{
wallet_Template
# CD INTO .monero-bash SO FILES/LOGS GET CREATED THERE
cd "$dotMoneroBash"

# WALLET SEED LANGUAGE
while true ;do
IRED; echo "Monero seed languages:" ;IWHITE
print_SeedLanguageList
OFF; echo -n "Pick seed language: " ;IWHITE
read seedLanguage
case "$seedLanguage" in
"0"|deutsch|Deutsch|german|German) seedLanguage="Deutsch" ;break ;;
"1"|english|English) seedLanguage="English" ;break ;;
"2"|español|Español|spanish|Spanish) seedLanguage="Español" ;break ;;
"3"|français|Français|french|French) seedLanguage="Français" ;break ;;
"4"|italiano|Italiano|italian|Italian) seedLanguage="Italiano" ;break ;;
"5"|nederlands|Nederlands|dutch|Dutch) seedLanguage="Nederlands" ;break ;;
"6"|português|Português|portuguese|Portuguese) seedLanguage="Português" ;break ;;
"7"|"русский язык"|russian|Russian) seedLanguage="русский язык" ;break ;;
"8"|日本語|にほんご|japanese|Japanese) seedLanguage="日本語" ;break ;;
"9"|"简体中文(中国)"|"简体中文"|"简体中文 (中国)"|chinese|Chinese) seedLanguage="简体中文 (中国)" ;break ;;
"10"|esperanto|Esperanto) seedLanguage="Esperanto" ;break ;;
"11"|lojban|Lojban) seedLanguage="Lojban" ;break ;;
*) print_Error "invalid input" ;;
# WALLET TYPES
while :; do
while :; do
echo
printf "${BPURPLE}%s${OFF}%s${BRED}%s${OFF}\n" \
"--generate-new-wallet " "| " "[new]" \
"--generate-from-view-key " "| " "[view]" \
"--restore-from-seed " "| " "[seed]" \
"--generate-from-json " "| " "[json]" \
"--generate-from-spend-key " "| " "[spend]" \
"--generate-from-device " "| " "[device]" \
"--generate-from-keys " "| " "[private]" \
"--generate-from-multisig-keys " "| " "[multisig]" \
""
printf "${BWHITE}%s${OFF}" "Which wallet type? "

read -r WALLET_TYPE
case "$WALLET_TYPE" in
--generate-new-wallet|*new*) WALLET_TYPE=new;break;;
--generate-from-view-key|*view*) WALLET_TYPE=view;break;;
--restore-from-seed|*seed*) WALLET_TYPE=seed;break;;
--generate-from-json|*json*) WALLET_TYPE=json;break;;
--generate-from-spend-key|*spend*) WALLET_TYPE=spend;break;;
--generate-from-device|*device*) WALLET_TYPE=device;break;;
--generate-from-keys|*private*) WALLET_TYPE=private;break;;
--generate-from-multisig-keys|*multi*) WALLET_TYPE=multisig;break;;
*) print_Error "Invalid wallet type!"
esac
done

# START monero-wallet-cli WITH CREATION VARIABLES SET
printf "\n\e[1;93m%s\e[1;97m%s\n" "Starting wallet " "[$walletName]";OFF
createWallet="true"
wallet_Start
}

# creation of view-only wallet
wallet_View()
{
BRED; echo "Creating [view] wallet..." ;OFF
wallet_Template

# START monero-wallet-cli WITH CREATION VARIABLES SET
printf "\n\e[1;93m%s\e[1;97m%s\n" "Starting wallet " "[$walletName]";OFF
createView="true"
wallet_Start
}

# recovery of wallet
wallet_Recover()
{
BRED; echo "Recovering wallet..." ;OFF
wallet_Template

# SEED INPUT
while true ;do
OFF; echo -n "Seed (24/25 words): "
read -r walletSeed ; echo
case $walletSeed in
"") print_Error "Empty input" ;;
*)
clear
n=1
for i in $walletSeed; do
if [[ $n -lt 10 ]]; then
printf "${n} | %s\n" "${i} "
else
printf "${n} | %s\n" "${i} "
fi
((n++))
done
BWHITE; echo -n "Is this correct? (Y/n) "
local YES_NO
read -r YES_NO
case $YES_NO in
y|Y|yes|Yes|YES|"") clear; break;;
*) echo;;
esac
printf "${BWHITE}%s${BRED}%s${BWHITE}%s${OFF}" \
"Create wallet type " \
"[${WALLET_TYPE}]" \
"? (Y/n) "
read yn
case $yn in
y|Y|yes|Yes|YES|""|" ") break;;
*) :;;
esac
done

# CONFIRM SEED
# Wallet name
while :; do
if [[ $WALLET_TYPE = json ]]; then
printf "${BWHITE}%s${OFF}" "JSON file path: "
read -r WALLET_NAME
case "$WALLET_NAME" in
"") print_Error "Empty input";;
*) break;;
esac
else
printf "${BWHITE}%s${OFF}" "Wallet name: "
read -r WALLET_NAME
case "$WALLET_NAME" in
"") print_Error "Empty input";;
*" "*) print_Error "Wallet name cannot have spaces";;
*) break;;
esac
fi
done

# START monero-wallet-cli WITH RECOVERY VARIABLES SET
printf "\n\e[1;93m%s\e[1;97m%s\n" "Starting wallet " "[$walletName]";OFF
recoverWallet="true"
wallet_Start
}
# Spacing
printf "\n${BPURPLE}%s${BWHITE}%s${OFF}\n" "Creating wallet " "[$WALLET_NAME]"

# if wallet name happens to be "new/view/recover"
wallet_Collision()
{
OFF; echo "Wallet name is similar to option..."
while true ;do
IBLUE; printf "SELECT "
OFF; printf "or "
IRED; printf "CREATE? " ;OFF
read selectCreate
case $selectCreate in
select|Select|SELECT)
OFF; echo "Selecting $walletSelection..."
echo -n "Password: "
read -s walletPassword && echo
wallet_Start
exit
;;
create|Create|CREATE)
break
;;
*) print_Error "Invalid option" ;;
esac
done
# Case wallet type
if case "$WALLET_TYPE" in
new)
"$binMonero/monero-wallet-cli" \
--generate-new-wallet "$wallets/$WALLET_NAME" \
--config-file "$config/monero-wallet-cli.conf"
;;
view)
"$binMonero/monero-wallet-cli" \
--generate-from-view-key "$wallets/$WALLET_NAME" \
--config-file "$config/monero-wallet-cli.conf"
;;
seed)
"$binMonero/monero-wallet-cli" \
--generate-new-wallet "$wallets/$WALLET_NAME" \
--config-file "$config/monero-wallet-cli.conf" \
--restore-from-seed
;;
json)
"$binMonero/monero-wallet-cli" \
--generate-from-json "$WALLET_NAME" \
--config-file "$config/monero-wallet-cli.conf"
;;
spend)
"$binMonero/monero-wallet-cli" \
--generate-from-spend-key "$wallets/$WALLET_NAME" \
--config-file "$config/monero-wallet-cli.conf"
;;
device)
"$binMonero/monero-wallet-cli" \
--generate-from-device "$wallets/$WALLET_NAME" \
--config-file "$config/monero-wallet-cli.conf"
;;
private)
"$binMonero/monero-wallet-cli" \
--generate-from-keys "$wallets/$WALLET_NAME" \
--config-file "$config/monero-wallet-cli.conf"
;;
multisig)
"$binMonero/monero-wallet-cli" \
--generate-from-multisig-keys "$wallets/$WALLET_NAME" \
--config-file "$config/monero-wallet-cli.conf"
;;
esac; then
exit 0
else
print_Error "monero-wallet-cli error has occurred"
exit 1
fi
}

wallet_Count()
Expand Down
4 changes: 2 additions & 2 deletions src/txt/hashlist
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
5251fb567a94db02bc8695fe5dff4efc912771f214c1668d9fdc6a535b22bfc8 monero-bash
8c450e8a4bd57fa26959da6ebccc8dd06ad46abad12212b2bc945c760c7932a1 monero-bash
3f2fbaa499d7f1808748e604a75e1f8bdc2b5c462b03cc912f51280250bf14a8 src/debug.sh
91464358f1358e3dfbf3968fad81a4fff95d6f3ce0961a1ba1ae7054b6998159 src/libtorsocks.so
7541df1f9fbb0874f04d2d6f853592ed1b4e91c1d6b0907e12d628bc61430069 src/README.md
Expand Down Expand Up @@ -45,7 +45,7 @@ b7c44f614290fa0f945c04a3425b6a92a5a16f5c821d5af27e945636d9b3d765 src/func/trap.
006ccaeb125e02894586af12172104bf1a40654ff82127f33f4c1e16be80537c src/func/verbose.sh
edf5de7d72be7e240b545f4753a01ca4b9f2f46e5bb476fffd0164461e6288e4 src/func/verify.sh
24155b08b4cd0f1908beaf70b1ad2c1713a39d1602c46bcbd11134cc241b5866 src/func/version.sh
ad7ebcefb22b10efb01b7afa1f0c782c311d928da27f72024746e521c312b2cc src/func/wallet.sh
d1738cb1702374e26ac9b2849848316a13bdfd1fd564c49754a4d94f867f4e80 src/func/wallet.sh
0d79e23f7d13a61a1281bbf09842ef0555d0b24950cac0f9ce73a17a92696010 src/func/warning.sh
04de74c033179c8fed827505a0648b6b1f34264467b522969728db06acb9e1bb src/func/watch.sh
ab8fb1f8a6536ce5c87f138457c47410145492b5bb764c18505d01a6e93a9b93 src/txt/state
Expand Down

0 comments on commit 844f283

Please sign in to comment.