Browse Source

wallet: change init_lightning to sometimes create deterministic LN keys

patch-4
SomberNight 4 years ago
parent
commit
537ec92460
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 13
      electrum/gui/kivy/main_window.py
  2. 15
      electrum/gui/qt/main_window.py
  3. 24
      electrum/wallet.py

13
electrum/gui/kivy/main_window.py

@ -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)

15
electrum/gui/qt/main_window.py

@ -2386,11 +2386,20 @@ 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._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") self.show_message("Lightning keys created. Please restart Electrum")
def show_wallet_info(self): def show_wallet_info(self):

24
electrum/wallet.py

@ -333,20 +333,30 @@ 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
assert isinstance(ks, keystore.BIP32_KeyStore)
self.db.put('lightning_xprv', ks.get_lightning_xprv(password))
else:
seed = os.urandom(32) seed = os.urandom(32)
node = BIP32Node.from_rootseed(seed, xtype='standard') node = BIP32Node.from_rootseed(seed, xtype='standard')
ln_xprv = node.to_xprv() ln_xprv = node.to_xprv()

Loading…
Cancel
Save