|
|
@ -333,24 +333,34 @@ class Abstract_Wallet(AddressSynchronizer, ABC): |
|
|
|
new_db.write(new_storage) |
|
|
|
return new_path |
|
|
|
|
|
|
|
def has_lightning(self): |
|
|
|
def has_lightning(self) -> bool: |
|
|
|
return bool(self.lnworker) |
|
|
|
|
|
|
|
def can_have_lightning(self): |
|
|
|
def can_have_lightning(self) -> bool: |
|
|
|
# we want static_remotekey to be a wallet address |
|
|
|
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.db.get('lightning_xprv') is None |
|
|
|
if self.db.get('lightning_privkey2'): |
|
|
|
return |
|
|
|
# TODO derive this deterministically from wallet.keystore at keystore generation time |
|
|
|
# probably along a hardened path ( lnd-equivalent would be m/1017'/coinType'/ ) |
|
|
|
seed = os.urandom(32) |
|
|
|
node = BIP32Node.from_rootseed(seed, xtype='standard') |
|
|
|
ln_xprv = node.to_xprv() |
|
|
|
self.db.put('lightning_privkey2', ln_xprv) |
|
|
|
assert self.db.get('lightning_privkey2') is None |
|
|
|
|
|
|
|
if self.can_have_deterministic_lightning(): |
|
|
|
ks = self.keystore |
|
|
|
assert isinstance(ks, keystore.BIP32_KeyStore) |
|
|
|
self.db.put('lightning_xprv', ks.get_lightning_xprv(password)) |
|
|
|
else: |
|
|
|
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): |
|
|
|
"""Stop all networking and save DB to disk.""" |
|
|
|