raspiblitz/home.admin/config.scripts/lnd.initwallet.py

110 lines
3 KiB
Python
Raw Normal View History

2019-04-12 02:06:16 +01:00
#!/usr/bin/python
2019-04-12 03:02:01 +01:00
import codecs, grpc, os, sys, base64
2019-04-12 11:48:51 +01:00
from lndlibs import rpc_pb2 as ln
from lndlibs import rpc_pb2_grpc as lnrpc
2019-04-12 01:15:31 +01:00
# display config script info
if len(sys.argv) <= 1 or sys.argv[1] == "-h" or sys.argv[1] == "help":
2019-04-12 02:06:16 +01:00
print("# creating or recovering the LND wallet")
print("# lnd.winitwallet.py new [walletpassword] [?seedpassword]")
print("# lnd.winitwallet.py seed [walletpassword] [seedstring] [?seedpassword]")
print("# lnd.winitwallet.py scb [walletpassword] [seedstring] [filepathSCB] [?seedpassword]")
print("err='missing parameters'")
2019-04-12 01:15:31 +01:00
sys.exit(1)
walletpassword=""
seedwords=""
seedpassword=""
filepathSCB=""
mode=sys.argv[1]
if mode=="new":
2019-04-12 02:06:16 +01:00
print("# *** CREATING NEW LND WALLET ***")
2019-04-12 02:08:36 +01:00
if len(sys.argv)>2:
2019-04-12 02:06:16 +01:00
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)
2019-04-12 02:08:36 +01:00
if len(sys.argv)>3:
2019-04-12 02:06:16 +01:00
seedpassword=sys.argv[3]
2019-04-12 01:15:31 +01:00
elif mode=="seed":
2019-04-12 02:06:16 +01:00
print("err='TODO: implement creating from seed'")
sys.exit(1)
2019-04-12 01:15:31 +01:00
elif mode=="scb":
2019-04-12 02:06:16 +01:00
print("err='TODO: implement creating from seed/scb'")
sys.exit(1)
2019-04-12 01:15:31 +01:00
else:
2019-04-12 02:06:16 +01:00
print("err='unkown mode parameter - run without any parameters to see options'")
2019-04-12 01:15:31 +01:00
sys.exit(1)
2019-04-12 02:06:16 +01:00
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)
2019-04-12 02:48:57 +01:00
if mode=="new":
2019-04-12 11:15:11 +01:00
request = ln.GenSeedRequest()
2019-04-12 13:03:01 +01:00
try:
response = stub.GenSeed(request)
seedwords = response.cipher_seed_mnemonic
2019-04-15 01:33:29 +01:00
seedwordsString=', '.join(seedwords)
2019-04-12 13:03:01 +01:00
print("seedwords='"+seedwordsString+"'")
2019-04-15 01:15:57 +01:00
# add a 6x4 formatted version to the output
seedwords6x4=""
for i in range(0,len(seedwords)):
2019-04-15 01:25:02 +01:00
if i % 6 == 0 and i != 0:
2019-04-15 01:15:57 +01:00
seedwords6x4=seedwords6x4+"\n"
2019-04-15 01:25:02 +01:00
singleWord=str(i+1)+":"+seedwords[i]
while len(singleWord)<12:
2019-04-15 01:15:57 +01:00
singleWord=singleWord+" "
seedwords6x4=seedwords6x4+singleWord
print("seedwords6x4='"+seedwords6x4+"'")
2019-04-12 13:19:57 +01:00
except grpc.RpcError as err:
2019-04-12 13:31:16 +01:00
# - wallet might already exist
print("err='grpc.RpcError'")
print >> sys.stderr, err
sys.exit(1)
2019-04-12 13:09:10 +01:00
except Exception as err:
2019-04-12 13:31:16 +01:00
print("err='GenSeedRequest'")
2019-04-12 13:19:57 +01:00
print >> sys.stderr, err
2019-04-12 13:31:16 +01:00
sys.exit(1)
2019-04-12 11:12:50 +01:00
2019-04-12 12:47:09 +01:00
request = ln.InitWalletRequest(
wallet_password=walletpassword,
cipher_seed_mnemonic=seedwords
)
2019-04-12 13:03:01 +01:00
try:
response = stub.InitWallet(request)
except:
e = sys.exc_info()[0]
2019-04-12 13:04:54 +01:00
print >> sys.stderr, e
2019-04-12 13:03:01 +01:00
print("err='Failed: RPC InitWallet'")
2019-04-12 13:31:16 +01:00
sys.exit(1)
2019-04-12 02:48:57 +01:00
elif mode=="seed":
print("err='TODO: implement creating from seed'")
sys.exit(1)
elif mode=="scb":
print("err='TODO: implement creating from seed/scb'")
sys.exit(1)