15
15
16
16
# Standard library imports
17
17
from dataclasses import dataclass
18
- from typing import Any , Mapping
18
+ from typing import Any , List , Mapping , Tuple , cast
19
19
20
20
from btclib .alias import Octets
21
21
from btclib .bip32 .key_origin import (
54
54
serialize_hd_key_paths ,
55
55
serialize_leaf_scripts ,
56
56
serialize_taproot_bip32 ,
57
- taproot_bip32_from_dict ,
58
57
taproot_bip32_to_dict ,
59
58
)
60
59
from btclib .script import Witness
@@ -319,6 +318,14 @@ def to_dict(self, check_validity: bool = True) -> dict[str, Any]:
319
318
def from_dict (
320
319
cls : type [PsbtIn ], dict_ : Mapping [str , Any ], check_validity : bool = True
321
320
) -> PsbtIn :
321
+ hd_key_paths = cast (
322
+ Mapping [Octets , BIP32KeyOrigin ],
323
+ decode_from_bip32_derivs (dict_ ["bip32_derivs" ]),
324
+ )
325
+ taproot_hd_key_paths = cast (
326
+ Mapping [Octets , Tuple [List [Octets ], BIP32KeyOrigin ]],
327
+ decode_from_bip32_derivs (dict_ ["taproot_hd_key_paths" ]),
328
+ )
322
329
return cls (
323
330
Tx .from_dict (dict_ ["non_witness_utxo" ], False )
324
331
if dict_ ["non_witness_utxo" ]
@@ -330,8 +337,7 @@ def from_dict(
330
337
dict_ ["sig_hash" ],
331
338
dict_ ["redeem_script" ],
332
339
dict_ ["witness_script" ],
333
- # FIXME
334
- decode_from_bip32_derivs (dict_ ["bip32_derivs" ]), # type: ignore
340
+ hd_key_paths ,
335
341
dict_ ["final_script_sig" ],
336
342
Witness .from_dict (dict_ ["final_script_witness" ], False ),
337
343
dict_ ["ripemd160_preimages" ],
@@ -341,7 +347,7 @@ def from_dict(
341
347
dict_ ["taproot_key_spend_signature" ],
342
348
dict_ ["taproot_script_spend_signatures" ],
343
349
dict_ ["taproot_leaf_scripts" ],
344
- taproot_bip32_from_dict ( dict_ [ " taproot_hd_key_paths" ]), # type: ignore
350
+ taproot_hd_key_paths ,
345
351
dict_ ["taproot_internal_key" ],
346
352
dict_ ["taproot_merkle_root" ],
347
353
dict_ ["unknown" ],
@@ -526,7 +532,10 @@ def parse(
526
532
elif k [:1 ] == PSBT_IN_TAP_LEAF_SCRIPT :
527
533
taproot_leaf_scripts [k [1 :]] = parse_leaf_script (v )
528
534
elif k [:1 ] == PSBT_IN_TAP_BIP32_DERIVATION :
529
- taproot_hd_key_paths [k [1 :]] = parse_taproot_bip32 (v ) # type: ignore
535
+ taproot_hd_key_path = cast (
536
+ Tuple [List [Octets ], BIP32KeyOrigin ], parse_taproot_bip32 (v )
537
+ )
538
+ taproot_hd_key_paths [k [1 :]] = taproot_hd_key_path
530
539
elif k [:1 ] == PSBT_IN_TAP_INTERNAL_KEY :
531
540
taproot_internal_key = deserialize_bytes (k , v , "taproot internal key" )
532
541
elif k [:1 ] == PSBT_IN_TAP_MERKLE_ROOT :
0 commit comments