keystore: encapsulate "can_have_deterministic_lightning_xprv" logic
This commit is contained in:
@@ -545,7 +545,7 @@ class BaseWizard(Logger):
|
||||
|
||||
def create_keystore(self, seed, passphrase):
|
||||
k = keystore.from_seed(seed, passphrase, self.wallet_type == 'multisig')
|
||||
if self.wallet_type == 'standard' and self.seed_type == 'segwit':
|
||||
if k.can_have_deterministic_lightning_xprv():
|
||||
self.data['lightning_xprv'] = k.get_lightning_xprv(None)
|
||||
self.on_keystore(k)
|
||||
|
||||
|
||||
@@ -160,6 +160,9 @@ class KeyStore(Logger, ABC):
|
||||
return pubkey, list(path)
|
||||
return None, None
|
||||
|
||||
def can_have_deterministic_lightning_xprv(self) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
class Software_KeyStore(KeyStore):
|
||||
|
||||
@@ -620,7 +623,14 @@ class BIP32_KeyStore(Xpub, Deterministic_KeyStore):
|
||||
cK = ecc.ECPrivkey(k).get_public_key_bytes()
|
||||
return cK, k
|
||||
|
||||
def get_lightning_xprv(self, password):
|
||||
def can_have_deterministic_lightning_xprv(self):
|
||||
if (self.get_seed_type() == 'segwit'
|
||||
and self.get_bip32_node_for_xpub().xtype == 'p2wpkh'):
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_lightning_xprv(self, password) -> str:
|
||||
assert self.can_have_deterministic_lightning_xprv()
|
||||
xprv = self.get_master_private_key(password)
|
||||
rootnode = BIP32Node.from_xkey(xprv)
|
||||
node = rootnode.subkey_at_private_derivation("m/67'/")
|
||||
|
||||
@@ -3185,7 +3185,7 @@ def create_new_wallet(*, path, config: SimpleConfig, passphrase=None, password=N
|
||||
k = keystore.from_seed(seed, passphrase)
|
||||
db.put('keystore', k.dump())
|
||||
db.put('wallet_type', 'standard')
|
||||
if keystore.seed_type(seed) == 'segwit':
|
||||
if k.can_have_deterministic_lightning_xprv():
|
||||
db.put('lightning_xprv', k.get_lightning_xprv(None))
|
||||
if gap_limit is not None:
|
||||
db.put('gap_limit', gap_limit)
|
||||
@@ -3229,7 +3229,7 @@ def restore_wallet_from_text(text, *, path, config: SimpleConfig,
|
||||
k = keystore.from_master_key(text)
|
||||
elif keystore.is_seed(text):
|
||||
k = keystore.from_seed(text, passphrase)
|
||||
if keystore.seed_type(text) == 'segwit':
|
||||
if k.can_have_deterministic_lightning_xprv():
|
||||
db.put('lightning_xprv', k.get_lightning_xprv(None))
|
||||
else:
|
||||
raise Exception("Seed or key not recognized")
|
||||
|
||||
Reference in New Issue
Block a user