wallet: change init_lightning to sometimes create deterministic LN keys
This commit is contained in:
@@ -1421,23 +1421,26 @@ class ElectrumWindow(App, Logger):
|
|||||||
"This means that you must save a backup of your wallet everytime you create a new channel.\n\n"
|
"This means that you must save a backup of your wallet everytime you create a new channel.\n\n"
|
||||||
"If you want to have recoverable channels, you must create a new wallet with an Electrum seed")
|
"If you want to have recoverable channels, you must create a new wallet with an Electrum seed")
|
||||||
self.show_info(msg)
|
self.show_info(msg)
|
||||||
else:
|
elif self.wallet.can_have_lightning():
|
||||||
if self.wallet.can_have_lightning():
|
root.dismiss()
|
||||||
root.dismiss()
|
if self.wallet.can_have_deterministic_lightning():
|
||||||
|
msg = messages.MSG_LIGHTNING_SCB_WARNING + "\n" + _("Create lightning keys?")
|
||||||
|
else:
|
||||||
msg = _(
|
msg = _(
|
||||||
"Warning: this wallet type does not support channel recovery from seed. "
|
"Warning: this wallet type does not support channel recovery from seed. "
|
||||||
"You will need to backup your wallet everytime you create a new wallet. "
|
"You will need to backup your wallet everytime you create a new wallet. "
|
||||||
"Create lightning keys?")
|
"Create lightning keys?")
|
||||||
d = Question(msg, self._enable_lightning, title=_('Enable Lightning?'))
|
d = Question(msg, self._enable_lightning, title=_('Enable Lightning?'))
|
||||||
d.open()
|
d.open()
|
||||||
else:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _enable_lightning(self, b):
|
def _enable_lightning(self, b):
|
||||||
if not b:
|
if not b:
|
||||||
return
|
return
|
||||||
|
self.protected(_("Create lightning keys?"), self.__enable_lightning, ())
|
||||||
|
|
||||||
|
def __enable_lightning(self, password):
|
||||||
wallet_path = self.get_wallet_path()
|
wallet_path = self.get_wallet_path()
|
||||||
self.wallet.init_lightning()
|
self.wallet.init_lightning(password=password)
|
||||||
self.show_info(_('Lightning keys have been initialized.'))
|
self.show_info(_('Lightning keys have been initialized.'))
|
||||||
self.stop_wallet()
|
self.stop_wallet()
|
||||||
self.load_wallet_by_name(wallet_path)
|
self.load_wallet_by_name(wallet_path)
|
||||||
|
|||||||
@@ -2386,12 +2386,21 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||||||
self.set_contact(line2.text(), line1.text())
|
self.set_contact(line2.text(), line1.text())
|
||||||
|
|
||||||
def init_lightning_dialog(self):
|
def init_lightning_dialog(self):
|
||||||
if self.question(_(
|
assert not self.wallet.has_lightning()
|
||||||
|
if self.wallet.can_have_deterministic_lightning():
|
||||||
|
msg = messages.MSG_LIGHTNING_SCB_WARNING + "\n" + _("Create lightning keys?")
|
||||||
|
else:
|
||||||
|
msg = _(
|
||||||
"Warning: this wallet type does not support channel recovery from seed. "
|
"Warning: this wallet type does not support channel recovery from seed. "
|
||||||
"You will need to backup your wallet everytime you create a new wallet. "
|
"You will need to backup your wallet everytime you create a new wallet. "
|
||||||
"Create lightning keys?")):
|
"Create lightning keys?")
|
||||||
self.wallet.init_lightning()
|
if self.question(msg):
|
||||||
self.show_message("Lightning keys created. Please restart Electrum")
|
self._init_lightning_dialog()
|
||||||
|
|
||||||
|
@protected
|
||||||
|
def _init_lightning_dialog(self, *, password):
|
||||||
|
self.wallet.init_lightning(password=password)
|
||||||
|
self.show_message("Lightning keys created. Please restart Electrum")
|
||||||
|
|
||||||
def show_wallet_info(self):
|
def show_wallet_info(self):
|
||||||
dialog = WindowModalDialog(self, _("Wallet Information"))
|
dialog = WindowModalDialog(self, _("Wallet Information"))
|
||||||
|
|||||||
@@ -333,24 +333,34 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
|
|||||||
new_db.write(new_storage)
|
new_db.write(new_storage)
|
||||||
return new_path
|
return new_path
|
||||||
|
|
||||||
def has_lightning(self):
|
def has_lightning(self) -> bool:
|
||||||
return bool(self.lnworker)
|
return bool(self.lnworker)
|
||||||
|
|
||||||
def can_have_lightning(self):
|
def can_have_lightning(self) -> bool:
|
||||||
# we want static_remotekey to be a wallet address
|
# we want static_remotekey to be a wallet address
|
||||||
return self.txin_type == 'p2wpkh'
|
return self.txin_type == 'p2wpkh'
|
||||||
|
|
||||||
def init_lightning(self):
|
def can_have_deterministic_lightning(self) -> bool:
|
||||||
|
if not self.can_have_lightning():
|
||||||
|
return False
|
||||||
|
if not self.keystore:
|
||||||
|
return False
|
||||||
|
return self.keystore.can_have_deterministic_lightning_xprv()
|
||||||
|
|
||||||
|
def init_lightning(self, *, password) -> None:
|
||||||
assert self.can_have_lightning()
|
assert self.can_have_lightning()
|
||||||
assert self.db.get('lightning_xprv') is None
|
assert self.db.get('lightning_xprv') is None
|
||||||
if self.db.get('lightning_privkey2'):
|
assert self.db.get('lightning_privkey2') is None
|
||||||
return
|
|
||||||
# TODO derive this deterministically from wallet.keystore at keystore generation time
|
if self.can_have_deterministic_lightning():
|
||||||
# probably along a hardened path ( lnd-equivalent would be m/1017'/coinType'/ )
|
ks = self.keystore
|
||||||
seed = os.urandom(32)
|
assert isinstance(ks, keystore.BIP32_KeyStore)
|
||||||
node = BIP32Node.from_rootseed(seed, xtype='standard')
|
self.db.put('lightning_xprv', ks.get_lightning_xprv(password))
|
||||||
ln_xprv = node.to_xprv()
|
else:
|
||||||
self.db.put('lightning_privkey2', ln_xprv)
|
seed = os.urandom(32)
|
||||||
|
node = BIP32Node.from_rootseed(seed, xtype='standard')
|
||||||
|
ln_xprv = node.to_xprv()
|
||||||
|
self.db.put('lightning_privkey2', ln_xprv)
|
||||||
|
|
||||||
async def stop(self):
|
async def stop(self):
|
||||||
"""Stop all networking and save DB to disk."""
|
"""Stop all networking and save DB to disk."""
|
||||||
|
|||||||
Reference in New Issue
Block a user