@@ -224,6 +224,23 @@ def check_keypath(self, keypaths, master, derived, pubkey, fingerprint, path):
224224 key = map_keypath_get_bip32_key_from (keypaths , 0 , master )
225225 self .assertEqual (bip32_key_serialize (key , 0 ), bip32_key_serialize (derived , 0 ))
226226
227+ def check_taproot_keypath (self ):
228+ # TODO: add in-situ checks on the PSBT fields
229+ # BIP-0341 control block
230+ parity = hex_to_bytes ('55' )
231+ xonly = hex_to_bytes ('22' * 32 )
232+ bad_xonly = hex_to_bytes ('04' + '22' * 32 )
233+ path_elem = hex_to_bytes ('00' * 32 )
234+ bip341_control_block_verify (parity + xonly ) # No path, OK
235+ bip341_control_block_verify (parity + xonly + path_elem ) # 1 path element, OK
236+ for args in [
237+ None , # Null control block
238+ parity + bad_xonly + path_elem , # Bad x-only pubkey
239+ parity + bad_xonly + path_elem [:- 1 ], # Path length not modulo 32
240+ parity + bad_xonly + path_elem * 129 , # Path length too long
241+ ]:
242+ self .assertRaises (ValueError , lambda : bip341_control_block_verify (args ))
243+
227244 def check_txout (self , lhs , rhs ):
228245 self .assertEqual (tx_output_get_satoshi (lhs ), tx_output_get_satoshi (rhs ))
229246 self .assertEqual (tx_output_get_script (lhs ), tx_output_get_script (rhs ))
@@ -350,6 +367,7 @@ def test_psbt(self):
350367 map_keypath_add (dummy_keypaths , dummy_pubkey , dummy_fingerprint , dummy_path )
351368 self .check_keypath (dummy_keypaths , master , derived ,
352369 dummy_pubkey , dummy_fingerprint , dummy_path )
370+ self .check_taproot_keypath ()
353371
354372 empty_signatures = map_init (0 , None )
355373 dummy_signatures = map_init (0 , None ) # TODO: pubkey to sig map init
0 commit comments