mirror of
https://github.com/raspiblitz/raspiblitz.git
synced 2025-09-27 12:06:36 +02:00
Merge branch 'master' of https://github.com/rootzoll/raspiblitz
This commit is contained in:
@@ -116,6 +116,14 @@ if [ "${baseImage}" = "raspbian" ] || [ "${baseImage}" = "dietpi" ] ; then
|
||||
|
||||
fi
|
||||
|
||||
# remove some (big) packages that are not needed
|
||||
sudo apt-get remove -y --purge libreoffice* oracle-java* chromium-browser nuscratch scratch sonic-pi minecraft-pi plymouth python2
|
||||
sudo apt-get clean
|
||||
sudo apt-get -y autoremove
|
||||
|
||||
# make sure /usr/bin/python exists (and calls Python3.7 in Debian Buster)
|
||||
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1
|
||||
|
||||
# update debian
|
||||
echo ""
|
||||
echo "*** UPDATE DEBIAN ***"
|
||||
@@ -141,10 +149,6 @@ if [ "${baseImage}" = "raspbian" ]; then
|
||||
sudo raspi-config nonint do_wifi_country US
|
||||
# see https://github.com/rootzoll/raspiblitz/issues/428#issuecomment-472822840
|
||||
echo "max_usb_current=1" | sudo tee -a /boot/config.txt
|
||||
# extra: remove some big packages not needed
|
||||
sudo apt-get remove -y --purge libreoffice* oracle-java* chromium-browser nuscratch scratch sonic-pi minecraft-pi python-pygame plymouth
|
||||
sudo apt-get clean
|
||||
sudo apt-get -y autoremove
|
||||
fi
|
||||
|
||||
# special prepare when Ubuntu or Armbian
|
||||
@@ -284,8 +288,6 @@ sudo apt install -y sysbench
|
||||
|
||||
# check for dependencies on DietPi, Ubuntu, Armbian
|
||||
sudo apt-get install -y build-essential
|
||||
sudo apt-get install -y python-pip
|
||||
sudo apt-get install -y python-dev
|
||||
# rsync is needed to copy from HDD
|
||||
sudo apt install -y rsync
|
||||
# install ifconfig
|
||||
@@ -363,7 +365,7 @@ bitcoinVersion="0.19.0.1"
|
||||
laanwjPGP="01EA5486DE18A882D4C2684590C8019E36C2E964"
|
||||
|
||||
# prepare directories
|
||||
sudo rm -r /home/admin/download
|
||||
sudo rm -rf /home/admin/download
|
||||
sudo -u admin mkdir /home/admin/download
|
||||
cd /home/admin/download
|
||||
|
||||
@@ -589,20 +591,15 @@ fi
|
||||
|
||||
# prepare python for lnd api use
|
||||
# https://dev.lightning.community/guides/python-grpc/
|
||||
#
|
||||
|
||||
echo ""
|
||||
echo "*** LND API for Python ***"
|
||||
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 3
|
||||
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
|
||||
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 1
|
||||
echo "to switch between python2/3: sudo update-alternatives --config python"
|
||||
sudo apt-get -f -y install virtualenv
|
||||
sudo chown -R admin /home/admin
|
||||
sudo -u admin bash -c "cd; virtualenv python-env-lnd; source /home/admin/python-env-lnd/bin/activate; pip install grpcio grpcio-tools googleapis-common-protos pathlib2"
|
||||
|
||||
# This Python3 virtualenv includes the site-packages because access to the PyQt5
|
||||
# libs - which are installed system-wide (via apt-get) - is needed for TouchUI.
|
||||
sudo -u admin bash -c "cd; virtualenv -p python3 --system-site-packages python3-env-lnd"
|
||||
sudo -u admin bash -c "cd; python3 -m venv --system-site-packages python3-env-lnd"
|
||||
sudo -u admin bash -c "/home/admin/python3-env-lnd/bin/python3 -m pip install grpcio grpcio-tools googleapis-common-protos pathlib2"
|
||||
echo ""
|
||||
|
||||
echo ""
|
||||
@@ -700,7 +697,7 @@ echo "*** HARDENING ***"
|
||||
# based on https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_20_pi.md#hardening-your-pi
|
||||
|
||||
# fail2ban (no config required)
|
||||
sudo apt-get install -y fail2ban
|
||||
sudo apt-get install -y --no-install-recommends python3-systemd fail2ban
|
||||
|
||||
# *** BOOTSTRAP ***
|
||||
# see background README for details
|
||||
@@ -721,10 +718,6 @@ sudo systemctl enable background
|
||||
echo "*** Prepare TOR source+keys ***"
|
||||
sudo /home/admin/config.scripts/internet.tor.sh prepare
|
||||
echo ""
|
||||
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||
echo "If you see fails above .. please run again later on:"
|
||||
echo "sudo /home/admin/config.scripts/internet.tor.sh prepare"
|
||||
echo ""
|
||||
|
||||
# *** RASPIBLITZ IMAGE READY ***
|
||||
echo ""
|
||||
|
@@ -191,7 +191,7 @@ if [ ${walletExists} -eq 0 ]; then
|
||||
# generate wallet with seed and set passwordC
|
||||
clear
|
||||
echo "Generating new Wallet ...."
|
||||
source /home/admin/python-env-lnd/bin/activate
|
||||
source /home/admin/python3-env-lnd/bin/activate
|
||||
python /home/admin/config.scripts/lnd.initwallet.py new ${passwordC} > /home/admin/.seed.tmp
|
||||
source /home/admin/.seed.tmp
|
||||
sudo shred /home/admin/.pass.tmp 2>/dev/null
|
||||
@@ -353,7 +353,7 @@ to protect the seed words. Most users did not set this.
|
||||
if [ "${CHOICE}" == "SEED+SCB" ] || [ "${CHOICE}" == "ONLYSEED" ]; then
|
||||
|
||||
# trigger wallet recovery
|
||||
source /home/admin/python-env-lnd/bin/activate
|
||||
source /home/admin/python3-env-lnd/bin/activate
|
||||
source <(python /home/admin/config.scripts/lnd.initwallet.py seed ${passwordC} "${wordstring}" ${passwordD})
|
||||
|
||||
# check if wallet was created for real
|
||||
@@ -497,4 +497,4 @@ System will restart now.
|
||||
|
||||
sudo shutdown -r now
|
||||
|
||||
fi
|
||||
fi
|
||||
|
@@ -43,7 +43,7 @@ pip install BlitzTUI
|
||||
**or** consider using a virtual environment
|
||||
|
||||
```
|
||||
virtualenv -p python3 --system-site-packages venv
|
||||
python3 -m venv --system-site-packages venv
|
||||
source venv/bin/activate
|
||||
pip install BlitzTUI
|
||||
```
|
||||
|
@@ -14,11 +14,12 @@ fi
|
||||
|
||||
# check and load raspiblitz config
|
||||
# to know which network is running
|
||||
source /home/admin/raspiblitz.info
|
||||
source /mnt/hdd/raspiblitz.conf
|
||||
if [ ${#network} -eq 0 ]; then
|
||||
echo "FAIL - missing /mnt/hdd/raspiblitz.conf"
|
||||
exit 1
|
||||
if [ -f "/home/admin/raspiblitz.info" ]; then
|
||||
source /home/admin/raspiblitz.info
|
||||
fi
|
||||
|
||||
if [ -f "/mnt/hdd/raspiblitz.conf" ]; then
|
||||
source /mnt/hdd/raspiblitz.conf
|
||||
fi
|
||||
|
||||
echo "Detect Base Image ..."
|
||||
@@ -169,19 +170,25 @@ if [ "$1" = "prepare" ] || [ "$1" = "-prepare" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# if started with prepare
|
||||
# make sure the network was set (by sourcing raspiblitz.conf)
|
||||
if [ ${#network} -eq 0 ]; then
|
||||
echo "FAIL - unknwon network due to missing /mnt/hdd/raspiblitz.conf"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# if started with btcconf-on
|
||||
if [ "$1" = "btcconf-on" ]; then
|
||||
activateBitcoinOverTOR
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# if started with prepare
|
||||
# if started with btcconf-off
|
||||
if [ "$1" = "btcconf-off" ]; then
|
||||
deactivateBitcoinOverTOR
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# if started with prepare
|
||||
# if started with lndconf-on
|
||||
if [ "$1" = "lndconf-on" ]; then
|
||||
activateLndOverTOR
|
||||
exit 0
|
||||
@@ -356,6 +363,6 @@ if [ "$1" = "0" ] || [ "$1" = "off" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "FAIL - Unknown Paramter $1"
|
||||
echo "FAIL - Unknown Parameter $1"
|
||||
echo "may needs reboot to run normal again"
|
||||
exit 1
|
||||
exit 1
|
||||
|
@@ -1,204 +1,239 @@
|
||||
#!/usr/bin/python
|
||||
import codecs, os, sys, base64
|
||||
|
||||
# display config script info
|
||||
if len(sys.argv) <= 1 or sys.argv[1] == "-h" or sys.argv[1] == "help":
|
||||
print("# ! always activate virtual env first: source /home/admin/python-env-lnd/bin/activate")
|
||||
print("# ! and run with with: python /home/admin/config.scripts/lnd.initwallet.py")
|
||||
print("# creating or recovering the LND wallet")
|
||||
print("# lnd.winitwallet.py new [walletpassword] [?seedpassword]")
|
||||
print("# lnd.winitwallet.py seed [walletpassword] [\"seeds-words-seperated-spaces\"] [?seedpassword]")
|
||||
print("# lnd.winitwallet.py scb [walletpassword] [\"seeds-words-seperated-spaces\"] [filepathSCB] [?seedpassword]")
|
||||
print("err='missing parameters'")
|
||||
sys.exit(1)
|
||||
#!/usr/bin/env python3
|
||||
import binascii
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import grpc
|
||||
from lndlibs import rpc_pb2 as ln
|
||||
from lndlibs import rpc_pb2_grpc as lnrpc
|
||||
from pathlib2 import Path
|
||||
|
||||
walletpassword=""
|
||||
seedwords=""
|
||||
seedpassword=""
|
||||
filepathSCB=""
|
||||
if sys.version_info < (3, 0):
|
||||
print("Can't run on Python2")
|
||||
sys.exit()
|
||||
|
||||
mode=sys.argv[1]
|
||||
|
||||
if mode=="new":
|
||||
|
||||
print("# *** CREATING NEW LND WALLET ***")
|
||||
|
||||
if len(sys.argv)>2:
|
||||
walletpassword=sys.argv[2]
|
||||
if len(walletpassword)<8:
|
||||
print("err='wallet password is too short'")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("err='wallet password is too short'")
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv)>3:
|
||||
seedpassword=sys.argv[3]
|
||||
|
||||
elif mode=="seed" or mode=="scb":
|
||||
|
||||
if len(sys.argv)>2:
|
||||
walletpassword=sys.argv[2]
|
||||
if len(walletpassword)<8:
|
||||
print("err='wallet password is too short'")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("err='not correct amount of parameter - missing wallet password'")
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv)>3:
|
||||
seedwordString=sys.argv[3]
|
||||
seedwords=seedwordString.split(" ")
|
||||
if len(seedwords)<24:
|
||||
print("err='not 24 seed words seperated by just spaces (surrounded with \")'")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("err='not correct amount of parameter - missing seed string'")
|
||||
sys.exit(1)
|
||||
|
||||
if mode=="seed":
|
||||
|
||||
if len(sys.argv)>4:
|
||||
seedpassword=sys.argv[4]
|
||||
|
||||
elif mode=="scb":
|
||||
|
||||
if len(sys.argv)>4:
|
||||
filepathSCB=sys.argv[4]
|
||||
scbFile = Path(filepathSCB)
|
||||
if scbFile.is_file():
|
||||
print("# OK SCB file exists")
|
||||
else:
|
||||
print("err='the given filepathSCB - file does not exists or no permission'")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("err='not correct amount of parameter - missing seed filepathSCB'")
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv)>5:
|
||||
seedpassword=sys.argv[4]
|
||||
|
||||
else:
|
||||
|
||||
print("err='unkown mode parameter - run without any parameters to see options'")
|
||||
# display config script info
|
||||
if len(sys.argv) <= 1 or sys.argv[1] in ["-h", "--help", "help"]:
|
||||
print("# ! always activate virtual env first: source /home/admin/python3-env-lnd/bin/activate")
|
||||
print("# ! and run with with: python3 /home/admin/config.scripts/lnd.initwallet.py")
|
||||
print("# ! Or: /home/admin/python3-env-lnd/bin/python3 /home/admin/config.scripts/lnd.initwallet.py")
|
||||
print("# creating or recovering the LND wallet")
|
||||
print("# lnd.initwallet.py new [walletpassword] [?seedpassword]")
|
||||
print("# lnd.initwallet.py seed [walletpassword] [\"seeds-words-seperated-spaces\"] [?seedpassword]")
|
||||
print("# lnd.initwallet.py scb [walletpassword] [\"seeds-words-seperated-spaces\"] [filepathSCB] [?seedpassword]")
|
||||
print("err='missing parameters'")
|
||||
sys.exit(1)
|
||||
|
||||
os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
|
||||
cert = open('/mnt/hdd/lnd/tls.cert', 'rb').read()
|
||||
ssl_creds = grpc.ssl_channel_credentials(cert)
|
||||
channel = grpc.secure_channel('localhost:10009', ssl_creds)
|
||||
stub = lnrpc.WalletUnlockerStub(channel)
|
||||
if mode=="new":
|
||||
mode = sys.argv[1]
|
||||
|
||||
|
||||
def new(stub, wallet_password="", seed_entropy=None):
|
||||
if seed_entropy:
|
||||
# provide 16-bytes of static data to get reproducible seeds for TESTING!)
|
||||
print("WARNING: Use this for testing only!!")
|
||||
request = ln.GenSeedRequest(seed_entropy=seed_entropy)
|
||||
else:
|
||||
request = ln.GenSeedRequest()
|
||||
|
||||
request = ln.GenSeedRequest()
|
||||
try:
|
||||
response = stub.GenSeed(request)
|
||||
seedwords = response.cipher_seed_mnemonic
|
||||
seedwordsString=', '.join(seedwords)
|
||||
print("seedwords='"+seedwordsString+"'")
|
||||
seed_words = response.cipher_seed_mnemonic
|
||||
seed_words_str = ', '.join(seed_words)
|
||||
print("seedwords='" + seed_words_str + "'")
|
||||
|
||||
# add a 6x4 formatted version to the output
|
||||
seedwords6x4=""
|
||||
for i in range(0,len(seedwords)):
|
||||
seed_words_6x4 = ""
|
||||
for i in range(0, len(seed_words)):
|
||||
if i % 6 == 0 and i != 0:
|
||||
seedwords6x4=seedwords6x4+"\n"
|
||||
singleWord=str(i+1)+":"+seedwords[i]
|
||||
while len(singleWord)<12:
|
||||
singleWord=singleWord+" "
|
||||
seedwords6x4=seedwords6x4+singleWord
|
||||
print("seedwords6x4='"+seedwords6x4+"'")
|
||||
seed_words_6x4 = seed_words_6x4 + "\n"
|
||||
single_word = str(i + 1) + ":" + seed_words[i]
|
||||
while len(single_word) < 12:
|
||||
single_word = single_word + " "
|
||||
seed_words_6x4 = seed_words_6x4 + single_word
|
||||
print("seedwords6x4='" + seed_words_6x4 + "'")
|
||||
|
||||
except grpc.RpcError as rpc_error_call:
|
||||
code = rpc_error_call.code()
|
||||
print >> sys.stderr, code
|
||||
details = rpc_error_call.details()
|
||||
print(code, file=sys.stderr)
|
||||
details = rpc_error_call.details()
|
||||
print("err='RPCError GenSeedRequest'")
|
||||
print("errMore='"+details+"'")
|
||||
print("errMore='" + details + "'")
|
||||
sys.exit(1)
|
||||
except:
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
print >> sys.stderr, e
|
||||
print(e, file=sys.stderr)
|
||||
print("err='GenSeedRequest'")
|
||||
sys.exit(1)
|
||||
|
||||
request = ln.InitWalletRequest(
|
||||
wallet_password=walletpassword,
|
||||
cipher_seed_mnemonic=seedwords
|
||||
wallet_password=wallet_password.encode(),
|
||||
cipher_seed_mnemonic=seed_words
|
||||
)
|
||||
try:
|
||||
response = stub.InitWallet(request)
|
||||
except grpc.RpcError as rpc_error_call:
|
||||
code = rpc_error_call.code()
|
||||
print >> sys.stderr, code
|
||||
details = rpc_error_call.details()
|
||||
print("err='RPCError InitWallet'")
|
||||
print("errMore='"+details+"'")
|
||||
sys.exit(1)
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
print >> sys.stderr, e
|
||||
print("err='InitWallet'")
|
||||
sys.exit(1)
|
||||
|
||||
elif mode=="seed":
|
||||
|
||||
request = ln.InitWalletRequest(
|
||||
wallet_password=walletpassword,
|
||||
cipher_seed_mnemonic=seedwords,
|
||||
recovery_window=5000,
|
||||
aezeed_passphrase=seedpassword
|
||||
)
|
||||
|
||||
try:
|
||||
response = stub.InitWallet(request)
|
||||
except grpc.RpcError as rpc_error_call:
|
||||
code = rpc_error_call.code()
|
||||
print >> sys.stderr, code
|
||||
details = rpc_error_call.details()
|
||||
print(code, file=sys.stderr)
|
||||
details = rpc_error_call.details()
|
||||
print("err='RPCError InitWallet'")
|
||||
print("errMore='"+details+"'")
|
||||
sys.exit(1)
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
print >> sys.stderr, e
|
||||
print("err='InitWallet'")
|
||||
sys.exit(1)
|
||||
|
||||
elif mode=="scb":
|
||||
|
||||
import binascii
|
||||
with open(filepathSCB, 'rb') as f:
|
||||
content = f.read()
|
||||
scbHexString=binascii.hexlify(content)
|
||||
print(scbHexString)
|
||||
|
||||
request = ln.InitWalletRequest(
|
||||
wallet_password=walletpassword,
|
||||
cipher_seed_mnemonic=seedwords,
|
||||
recovery_window=5000,
|
||||
aezeed_passphrase=seedpassword,
|
||||
channel_backups=scbHexString
|
||||
)
|
||||
|
||||
try:
|
||||
response = stub.InitWallet(request)
|
||||
except grpc.RpcError as rpc_error_call:
|
||||
code = rpc_error_call.code()
|
||||
print >> sys.stderr, code
|
||||
details = rpc_error_call.details()
|
||||
print("err='RPCError InitWallet'")
|
||||
print("errMore='"+details+"'")
|
||||
print("errMore='" + details + "'")
|
||||
sys.exit(1)
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
print >> sys.stderr, e
|
||||
print(e, file=sys.stderr)
|
||||
print("err='InitWallet'")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def seed(stub, wallet_password="", seed_words="", seed_password=""):
|
||||
request = ln.InitWalletRequest(
|
||||
wallet_password=wallet_password.encode(),
|
||||
cipher_seed_mnemonic=[x.encode() for x in seed_words],
|
||||
recovery_window=5000,
|
||||
aezeed_passphrase=seed_password.encode()
|
||||
)
|
||||
|
||||
try:
|
||||
response = stub.InitWallet(request)
|
||||
except grpc.RpcError as rpc_error_call:
|
||||
code = rpc_error_call.code()
|
||||
print(code, file=sys.stderr)
|
||||
details = rpc_error_call.details()
|
||||
print("err='RPCError InitWallet'")
|
||||
print("errMore='" + details + "'")
|
||||
sys.exit(1)
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
print(e, file=sys.stderr)
|
||||
print("err='InitWallet'")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def scb(stub, wallet_password="", seed_words="", seed_password="", file_path_scb=""):
|
||||
with open(file_path_scb, 'rb') as f:
|
||||
content = f.read()
|
||||
scb_hex_str = binascii.hexlify(content)
|
||||
print(scb_hex_str)
|
||||
|
||||
request = ln.InitWalletRequest(
|
||||
wallet_password=wallet_password.encode(),
|
||||
cipher_seed_mnemonic=[x.encode() for x in seed_words],
|
||||
recovery_window=5000,
|
||||
aezeed_passphrase=seed_password.encode(),
|
||||
channel_backups=scb_hex_str.encode()
|
||||
)
|
||||
|
||||
try:
|
||||
response = stub.InitWallet(request)
|
||||
except grpc.RpcError as rpc_error_call:
|
||||
code = rpc_error_call.code()
|
||||
print(code, file=sys.stderr)
|
||||
details = rpc_error_call.details()
|
||||
print("err='RPCError InitWallet'")
|
||||
print("errMore='" + details + "'")
|
||||
sys.exit(1)
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
print(e, file=sys.stderr)
|
||||
print("err='InitWallet'")
|
||||
sys.exit(1)
|
||||
|
||||
# TODO(rootzoll) implement creating from seed/scb
|
||||
print("err='TODO: implement creating from seed/scb'")
|
||||
sys.exit(1)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def parse_args():
|
||||
wallet_password = ""
|
||||
seed_words = ""
|
||||
seed_password = ""
|
||||
filepath_scb = ""
|
||||
|
||||
if mode == "new":
|
||||
if len(sys.argv) > 2:
|
||||
wallet_password = sys.argv[2]
|
||||
if len(wallet_password) < 8:
|
||||
print("err='wallet password is too short'")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("err='wallet password is too short'")
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv) > 3:
|
||||
seed_password = sys.argv[3]
|
||||
|
||||
elif mode == "seed" or mode == "scb":
|
||||
|
||||
if len(sys.argv) > 2:
|
||||
wallet_password = sys.argv[2]
|
||||
if len(wallet_password) < 8:
|
||||
print("err='wallet password is too short'")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("err='not correct amount of parameter - missing wallet password'")
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv) > 3:
|
||||
seed_word_str = sys.argv[3]
|
||||
seed_words = seed_word_str.split(" ")
|
||||
if len(seed_words) < 24:
|
||||
print("err='not 24 seed words separated by just spaces (surrounded with \")'")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("err='not correct amount of parameter - missing seed string'")
|
||||
sys.exit(1)
|
||||
|
||||
if mode == "seed":
|
||||
|
||||
if len(sys.argv) > 4:
|
||||
seed_password = sys.argv[4]
|
||||
|
||||
elif mode == "scb":
|
||||
|
||||
if len(sys.argv) > 4:
|
||||
filepath_scb = sys.argv[4]
|
||||
scb_file = Path(filepath_scb)
|
||||
if scb_file.is_file():
|
||||
print("# OK SCB file exists")
|
||||
else:
|
||||
print("err='the given filepathSCB - file does not exists or no permission'")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("err='not correct amount of parameter - missing seed filepathSCB'")
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv) > 5:
|
||||
seed_password = sys.argv[4]
|
||||
|
||||
else:
|
||||
|
||||
print("err='unknown mode parameter - run without any parameters to see options'")
|
||||
sys.exit(1)
|
||||
|
||||
return wallet_password, seed_words, seed_password, filepath_scb
|
||||
|
||||
|
||||
def main():
|
||||
os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
|
||||
cert = open('/mnt/hdd/lnd/tls.cert', 'rb').read()
|
||||
ssl_creds = grpc.ssl_channel_credentials(cert)
|
||||
channel = grpc.secure_channel('localhost:10009', ssl_creds)
|
||||
stub = lnrpc.WalletUnlockerStub(channel)
|
||||
|
||||
wallet_password, seed_words, seed_password, file_path_scb = parse_args()
|
||||
|
||||
if mode == "new":
|
||||
print("# *** CREATING NEW LND WALLET ***")
|
||||
new(stub, wallet_password)
|
||||
|
||||
elif mode == "seed":
|
||||
print("# *** RECOVERING LND WALLET FROM SEED ***")
|
||||
seed(stub, wallet_password, seed_words, seed_password)
|
||||
|
||||
elif mode == "scb":
|
||||
print("# *** RECOVERING LND WALLET FROM SEED + SCB ***")
|
||||
scb(stub, wallet_password, seed_words, seed_password, file_path_scb)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
237
home.admin/config.scripts/lnd.initwallet2.py
Normal file
237
home.admin/config.scripts/lnd.initwallet2.py
Normal file
@@ -0,0 +1,237 @@
|
||||
#!/usr/bin/python
|
||||
import os
|
||||
import sys
|
||||
import binascii
|
||||
import grpc
|
||||
from lndlibs import rpc_pb2 as ln
|
||||
from lndlibs import rpc_pb2_grpc as lnrpc
|
||||
from pathlib2 import Path
|
||||
|
||||
print("This is the legacy - Python2 only - version.")
|
||||
if sys.version_info > (3, 0):
|
||||
print("Can't run on Python3")
|
||||
sys.exit()
|
||||
|
||||
# display config script info
|
||||
if len(sys.argv) <= 1 or sys.argv[1] == "-h" or sys.argv[1] == "help":
|
||||
print("# ! always activate virtual env first: source /home/admin/python-env-lnd/bin/activate")
|
||||
print("# ! and run with with: python /home/admin/config.scripts/lnd.initwallet.py")
|
||||
print("# creating or recovering the LND wallet")
|
||||
print("# lnd.initwallet.py new [walletpassword] [?seedpassword]")
|
||||
print("# lnd.initwallet.py seed [walletpassword] [\"seeds-words-seperated-spaces\"] [?seedpassword]")
|
||||
print("# lnd.initwallet.py scb [walletpassword] [\"seeds-words-seperated-spaces\"] [filepathSCB] [?seedpassword]")
|
||||
print("err='missing parameters'")
|
||||
sys.exit(1)
|
||||
|
||||
mode = sys.argv[1]
|
||||
|
||||
|
||||
def new(stub, wallet_password="", seed_entropy=None):
|
||||
if seed_entropy:
|
||||
# provide 16-bytes of static data to get reproducible seeds for TESTING!)
|
||||
print("WARNING: Use this for testing only!!")
|
||||
request = ln.GenSeedRequest(seed_entropy=seed_entropy)
|
||||
else:
|
||||
request = ln.GenSeedRequest()
|
||||
|
||||
try:
|
||||
response = stub.GenSeed(request)
|
||||
seed_words = response.cipher_seed_mnemonic
|
||||
seed_words_str = ', '.join(seed_words)
|
||||
print("seedwords='" + seed_words_str + "'")
|
||||
|
||||
# add a 6x4 formatted version to the output
|
||||
seed_words_6x4 = ""
|
||||
for i in range(0, len(seed_words)):
|
||||
if i % 6 == 0 and i != 0:
|
||||
seed_words_6x4 = seed_words_6x4 + "\n"
|
||||
single_word = str(i + 1) + ":" + seed_words[i]
|
||||
while len(single_word) < 12:
|
||||
single_word = single_word + " "
|
||||
seed_words_6x4 = seed_words_6x4 + single_word
|
||||
print("seedwords6x4='" + seed_words_6x4 + "'")
|
||||
|
||||
except grpc.RpcError as rpc_error_call:
|
||||
code = rpc_error_call.code()
|
||||
print >> sys.stderr, code
|
||||
details = rpc_error_call.details()
|
||||
print("err='RPCError GenSeedRequest'")
|
||||
print("errMore='" + details + "'")
|
||||
sys.exit(1)
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
print >> sys.stderr, e
|
||||
print("err='GenSeedRequest'")
|
||||
sys.exit(1)
|
||||
|
||||
request = ln.InitWalletRequest(
|
||||
wallet_password=wallet_password,
|
||||
cipher_seed_mnemonic=seed_words
|
||||
)
|
||||
try:
|
||||
response = stub.InitWallet(request)
|
||||
except grpc.RpcError as rpc_error_call:
|
||||
code = rpc_error_call.code()
|
||||
print >> sys.stderr, code
|
||||
details = rpc_error_call.details()
|
||||
print("err='RPCError InitWallet'")
|
||||
print("errMore='" + details + "'")
|
||||
sys.exit(1)
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
print >> sys.stderr, e
|
||||
print("err='InitWallet'")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def seed(stub, wallet_password="", seed_words="", seed_password=""):
|
||||
request = ln.InitWalletRequest(
|
||||
wallet_password=wallet_password,
|
||||
cipher_seed_mnemonic=seed_words,
|
||||
recovery_window=250,
|
||||
aezeed_passphrase=seed_password
|
||||
)
|
||||
|
||||
try:
|
||||
response = stub.InitWallet(request)
|
||||
except grpc.RpcError as rpc_error_call:
|
||||
code = rpc_error_call.code()
|
||||
print >> sys.stderr, code
|
||||
details = rpc_error_call.details()
|
||||
print("err='RPCError InitWallet'")
|
||||
print("errMore='" + details + "'")
|
||||
sys.exit(1)
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
print >> sys.stderr, e
|
||||
print("err='InitWallet'")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def scb(stub, wallet_password="", seed_words="", seed_password="", file_path_scb=""):
|
||||
with open(file_path_scb, 'rb') as f:
|
||||
content = f.read()
|
||||
scb_hex_str = binascii.hexlify(content)
|
||||
print(scb_hex_str)
|
||||
|
||||
request = ln.InitWalletRequest(
|
||||
wallet_password=wallet_password,
|
||||
cipher_seed_mnemonic=seed_words,
|
||||
recovery_window=250,
|
||||
aezeed_passphrase=seed_password,
|
||||
channel_backups=scb_hex_str
|
||||
)
|
||||
|
||||
try:
|
||||
response = stub.InitWallet(request)
|
||||
except grpc.RpcError as rpc_error_call:
|
||||
code = rpc_error_call.code()
|
||||
print >> sys.stderr, code
|
||||
details = rpc_error_call.details()
|
||||
print("err='RPCError InitWallet'")
|
||||
print("errMore='" + details + "'")
|
||||
sys.exit(1)
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
print >> sys.stderr, e
|
||||
print("err='InitWallet'")
|
||||
sys.exit(1)
|
||||
|
||||
print("err='TODO: implement creating from seed/scb'")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def parse_args():
|
||||
wallet_password = ""
|
||||
seed_words = ""
|
||||
seed_password = ""
|
||||
filepath_scb = ""
|
||||
|
||||
if mode == "new":
|
||||
|
||||
print("# *** CREATING NEW LND WALLET ***")
|
||||
|
||||
if len(sys.argv) > 2:
|
||||
wallet_password = sys.argv[2]
|
||||
if len(wallet_password) < 8:
|
||||
print("err='wallet password is too short'")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("err='wallet password is too short'")
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv) > 3:
|
||||
seed_password = sys.argv[3]
|
||||
|
||||
elif mode == "seed" or mode == "scb":
|
||||
|
||||
if len(sys.argv) > 2:
|
||||
wallet_password = sys.argv[2]
|
||||
if len(wallet_password) < 8:
|
||||
print("err='wallet password is too short'")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("err='not correct amount of parameter - missing wallet password'")
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv) > 3:
|
||||
seed_word_str = sys.argv[3]
|
||||
seed_words = seed_word_str.split(" ")
|
||||
if len(seed_words) < 24:
|
||||
print("err='not 24 seed words separated by just spaces (surrounded with \")'")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("err='not correct amount of parameter - missing seed string'")
|
||||
sys.exit(1)
|
||||
|
||||
if mode == "seed":
|
||||
|
||||
if len(sys.argv) > 4:
|
||||
seed_password = sys.argv[4]
|
||||
|
||||
elif mode == "scb":
|
||||
|
||||
if len(sys.argv) > 4:
|
||||
filepath_scb = sys.argv[4]
|
||||
scb_file = Path(filepath_scb)
|
||||
if scb_file.is_file():
|
||||
print("# OK SCB file exists")
|
||||
else:
|
||||
print("err='the given filepathSCB - file does not exists or no permission'")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("err='not correct amount of parameter - missing seed filepathSCB'")
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv) > 5:
|
||||
seed_password = sys.argv[4]
|
||||
|
||||
else:
|
||||
|
||||
print("err='unknown mode parameter - run without any parameters to see options'")
|
||||
sys.exit(1)
|
||||
|
||||
return wallet_password, seed_words, seed_password, filepath_scb
|
||||
|
||||
|
||||
def main():
|
||||
wallet_password, seed_words, seed_password, file_path_scb = parse_args()
|
||||
|
||||
os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
|
||||
cert = open('/mnt/hdd/lnd/tls.cert', 'rb').read()
|
||||
ssl_creds = grpc.ssl_channel_credentials(cert)
|
||||
channel = grpc.secure_channel('localhost:10009', ssl_creds)
|
||||
stub = lnrpc.WalletUnlockerStub(channel)
|
||||
|
||||
if mode == "new":
|
||||
new(stub, wallet_password)
|
||||
|
||||
elif mode == "seed":
|
||||
seed(stub, wallet_password, seed_words, seed_password)
|
||||
|
||||
elif mode == "scb":
|
||||
scb(stub, wallet_password, seed_words, seed_password, file_path_scb)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Reference in New Issue
Block a user