mirror of
https://github.com/raspiblitz/raspiblitz.git
synced 2025-09-28 04:26:28 +02:00
refactor blitz.mnemonic.py
This commit is contained in:
@@ -367,12 +367,18 @@ if [ "${lightning}" == "cln" ]; then
|
||||
|
||||
source <(sudo /home/admin/config.scripts/cln.hsmtool.sh seed-force mainnet "${seedwords}")
|
||||
|
||||
# check if wallet really got created
|
||||
walletExistsNow = $(sudo ls /home/bitcoin/.lightning/bitcoin/hsm_secret 2>/dev/null | grep -c "hsm_secret")
|
||||
if [ $walletExistsNow -eq 0 ]; then
|
||||
sed -i "s/^state=.*/state=error/g" ${infoFile}
|
||||
sed -i "s/^message=.*/message='setup: seed maybe wrong'/g" ${infoFile}
|
||||
echo "FAIL: setup: no cln wallet created - seed maybe wrong" >> ${logFile}
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# NEW WALLET
|
||||
else
|
||||
|
||||
# sudo /home/admin/config.scripts/cln.hsmtool.sh seed-force mainnet "dad march erode large digital fun lift squirrel zebra order label inquiry distance tube predict benefit skin insect mistake bullet solar ostrich shiver road"
|
||||
|
||||
# generate new wallet
|
||||
source <(sudo /home/admin/config.scripts/cln.hsmtool.sh new-force mainnet)
|
||||
|
||||
@@ -384,6 +390,15 @@ if [ "${lightning}" == "cln" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# check if wallet really got created
|
||||
walletExistsNow = $(sudo ls /home/bitcoin/.lightning/bitcoin/hsm_secret 2>/dev/null | grep -c "hsm_secret")
|
||||
if [ $walletExistsNow -eq 0 ]; then
|
||||
sed -i "s/^state=.*/state=error/g" ${infoFile}
|
||||
sed -i "s/^message=.*/message='setup: no cln wallet created'/g" ${infoFile}
|
||||
echo "FAIL: setup: no cln wallet created" >> ${logFile}
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# write created seedwords into SETUPFILE to be displayed to user on final setup later
|
||||
echo "seedwordsNEW='${seedwords}'" >> ${setupFile}
|
||||
echo "seedwords6x4NEW='${seedwords6x4}'" >> ${setupFile}
|
||||
|
@@ -1,20 +1,55 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import sys
|
||||
from mnemonic import Mnemonic
|
||||
|
||||
mnemo = Mnemonic("english")
|
||||
seedwords = mnemo.generate(strength=256)
|
||||
# display config script info
|
||||
if len(sys.argv) <= 1 or sys.argv[1] == "-h" or sys.argv[1] == "help":
|
||||
print("tool for seed words")
|
||||
print("blitz.mnemonic.py generate")
|
||||
print("blitz.mnemonic.py test \"[SEEDWORDS-SPACE-SEPERATED]\"")
|
||||
sys.exit(1)
|
||||
|
||||
print("seedwords='" + seedwords + "'")
|
||||
#######################
|
||||
# GENERATE SEED WORDS
|
||||
#######################
|
||||
def generate():
|
||||
|
||||
# add a 6x4 formatted version to the output
|
||||
wordlist = list(seedwords.split(" "))
|
||||
seed_words_6x4 = ""
|
||||
for i in range(0, len(wordlist)):
|
||||
if i % 6 == 0 and i != 0:
|
||||
seed_words_6x4 = seed_words_6x4 + "\n"
|
||||
single_word = str(i + 1) + ":" + wordlist[i]
|
||||
while len(single_word) < 12:
|
||||
single_word = single_word + " "
|
||||
seed_words_6x4 = seed_words_6x4 + single_word
|
||||
print("seedwords6x4='" + seed_words_6x4 + "'")
|
||||
mnemo = Mnemonic("english")
|
||||
seedwords = mnemo.generate(strength=256)
|
||||
|
||||
print("seedwords='" + seedwords + "'")
|
||||
|
||||
# add a 6x4 formatted version to the output
|
||||
wordlist = list(seedwords.split(" "))
|
||||
seed_words_6x4 = ""
|
||||
for i in range(0, len(wordlist)):
|
||||
if i % 6 == 0 and i != 0:
|
||||
seed_words_6x4 = seed_words_6x4 + "\n"
|
||||
single_word = str(i + 1) + ":" + wordlist[i]
|
||||
while len(single_word) < 12:
|
||||
single_word = single_word + " "
|
||||
seed_words_6x4 = seed_words_6x4 + single_word
|
||||
print("seedwords6x4='" + seed_words_6x4 + "'")
|
||||
|
||||
|
||||
#######################
|
||||
# TEST SEED WORDS
|
||||
#######################
|
||||
def test(words):
|
||||
|
||||
seed = mnemo.to_seed(words, passphrase="")
|
||||
|
||||
def main():
|
||||
if sys.argv[1] == "generate":
|
||||
generate()
|
||||
|
||||
elif sys.argv[1] == "test":
|
||||
test(sys.argv[2])
|
||||
|
||||
else:
|
||||
# UNKNOWN PARAMETER
|
||||
print("error='unknown parameter'")
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@@ -163,12 +163,12 @@ if [ "$1" = "new" ] || [ "$1" = "new-force" ] || [ "$1" = "seed" ] || [ "$1" = "
|
||||
if [ "$1" = "new" ]; then
|
||||
seedPassword="$3"
|
||||
# get 24 words
|
||||
source <(python /home/admin/config.scripts/blitz.mnemonic.py)
|
||||
source <(python /home/admin/config.scripts/blitz.mnemonic.py generate)
|
||||
#TODO seedwords to cln.backup.sh seed-export-gui
|
||||
/home/admin/config.scripts/cln.backup.sh seed-export-gui "${seedwords6x4}"
|
||||
elif [ "$1" = "new-force" ]; then
|
||||
# get 24 words
|
||||
source <(python /home/admin/config.scripts/blitz.mnemonic.py)
|
||||
source <(python /home/admin/config.scripts/blitz.mnemonic.py generate)
|
||||
echo "seedwords='${seedwords}'"
|
||||
echo "seedwords6x4='${seedwords6x4}'"
|
||||
elif [ "$1" = "seed" ] || [ "$1" = "seed-force" ]; then
|
||||
|
Reference in New Issue
Block a user