From d362885b85107b616447899d5eaaa5ba1b55c170 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Fri, 9 Dec 2022 12:16:46 +0100 Subject: [PATCH] qa: record the recovery xpub too --- tests/fixtures.py | 6 ++++-- tests/test_framework/lianad.py | 20 ++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/tests/fixtures.py b/tests/fixtures.py index 0fce44b2..4a6b6ebb 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -119,15 +119,17 @@ def lianad(bitcoind, directory): bitcoind_cookie = os.path.join(bitcoind.bitcoin_dir, "regtest", ".cookie") owner_hd = BIP32.from_seed(os.urandom(32), network="test") - owner_xpub = owner_hd.get_xpub() + recovery_hd = BIP32.from_seed(os.urandom(32), network="test") + owner_xpub, recovery_xpub = owner_hd.get_xpub(), recovery_hd.get_xpub() csv_value = 10 main_desc = Descriptor.from_str( - f"wsh(or_d(pk({owner_xpub}/<0;1>/*),and_v(v:pkh(tpubD9vQiBdDxYzU4cVFtApWj4devZrvcfWaPXX1zHdDc7GPfUsDKqGnbhraccfm7BAXgRgUbVQUV2v2o4NitjGEk7hpbuP85kvBrD4ahFDtNBJ/<0;1>/*),older({csv_value}))))" + f"wsh(or_d(pk({owner_xpub}/<0;1>/*),and_v(v:pkh({recovery_xpub}/<0;1>/*),older({csv_value}))))" ) lianad = Lianad( datadir, owner_hd, + recovery_hd, main_desc, bitcoind.rpcport, bitcoind_cookie, diff --git a/tests/test_framework/lianad.py b/tests/test_framework/lianad.py index c321a8f0..51a0007b 100644 --- a/tests/test_framework/lianad.py +++ b/tests/test_framework/lianad.py @@ -30,6 +30,7 @@ class Lianad(TailableProc): self, datadir, owner_hd, + recovery_hd, multi_desc, bitcoind_rpc_port, bitcoind_cookie_path, @@ -40,6 +41,7 @@ class Lianad(TailableProc): self.prefix = os.path.split(datadir)[-1] self.owner_hd = owner_hd + self.recovery_hd = recovery_hd self.multi_desc = multi_desc self.receive_desc, self.change_desc = multi_desc.singlepath_descriptors() @@ -63,15 +65,20 @@ class Lianad(TailableProc): f.write(f"cookie_path = '{bitcoind_cookie_path}'\n") f.write(f"addr = '127.0.0.1:{bitcoind_rpc_port}'\n") - def sign_psbt(self, psbt): - """Sign a transaction using the owner's key. - This will fill the 'partial_sigs' field of all inputs. + def sign_psbt(self, psbt, recovery=False): + """Sign a transaction. + + This will fill the 'partial_sigs' field of all inputs. Uses either the 'primary' + 'recovery' key as specified. :param psbt: PSBT of the transaction to be signed. :returns: PSBT with a signature in each input for the owner's key. """ assert isinstance(psbt, PSBT) + # Which key to sign the transaction with. + hd = self.recovery_hd if recovery else self.owner_hd + # Sign each input. for i, psbt_in in enumerate(psbt.i): # First, gather the needed information from the PSBT input. @@ -84,12 +91,9 @@ class Lianad(TailableProc): ] script_code = psbt_in.map[PSBT_IN_WITNESS_SCRIPT] - # Now sign the transaction with the key of the "owner" (the participant that - # can sign immediately without a timelock) + # Now sign the transaction. sighash = sighash_all_witness(script_code, psbt, i) - privkey = coincurve.PrivateKey( - self.owner_hd.get_privkey_from_path(der_path) - ) + privkey = coincurve.PrivateKey(hd.get_privkey_from_path(der_path)) pubkey = privkey.public_key.format() assert pubkey in psbt_in.map[PSBT_IN_BIP32_DERIVATION].keys(), ( der_path,