@@ -344,6 +344,22 @@ def deserialize(self, f: Readable) -> None:
344344 for i in range (0 , num_hashes ):
345345 leaf_hashes .add (vs .read (32 ))
346346 self .tap_bip32_paths [xonly ] = (leaf_hashes , KeyOriginInfo .deserialize (vs .read ()))
347+ elif key_type == PartiallySignedInput .PSBT_IN_TAP_INTERNAL_KEY :
348+ if key in key_lookup :
349+ raise PSBTSerializationError ("Duplicate key, input Taproot internal key already provided" )
350+ elif len (key ) != 1 :
351+ raise PSBTSerializationError ("Input Taproot internal key key is more than one byte type" )
352+ self .tap_internal_key = deser_string (f )
353+ if len (self .tap_internal_key ) != 32 :
354+ raise PSBTSerializationError ("Input Taproot internal key is not 32 bytes" )
355+ elif key_type == PartiallySignedInput .PSBT_IN_TAP_MERKLE_ROOT :
356+ if key in key_lookup :
357+ raise PSBTSerializationError ("Duplicate key, input Taproot merkle root already provided" )
358+ elif len (key ) != 1 :
359+ raise PSBTSerializationError ("Input Taproot merkle root key is more than one byte type" )
360+ self .tap_merkle_root = deser_string (f )
361+ if len (self .tap_merkle_root ) != 32 :
362+ raise PSBTSerializationError ("Input Taproot merkle root is not 32 bytes" )
347363 elif key_type == PartiallySignedInput .PSBT_IN_MUSIG2_PARTICIPANT_PUBKEYS :
348364 if key in key_lookup :
349365 raise PSBTSerializationError ("Duplicate key, input Musig2 participant pubkeys already provided" )
@@ -1131,12 +1147,24 @@ def convert_to_v2(self) -> None:
11311147 """
11321148 Sets this PSBT to version 2
11331149 """
1150+
1151+ if self .version == 0 :
1152+ # make sure fields that PSBT version 0 fields are not present
1153+ self .setup_from_tx (self .tx )
1154+
11341155 self ._convert_version (2 )
11351156
11361157 def convert_to_v0 (self ) -> None :
11371158 """
11381159 Sets this PSBT to version 0
11391160 """
1161+
1162+ if self .version == 2 :
1163+ # strip PSBT version 2 fields
1164+ self .tx_version = None
1165+ self .fallback_locktime = None
1166+ self .tx_modifiable = None
1167+
11401168 self ._convert_version (0 )
11411169 self .tx = self .get_unsigned_tx ()
11421170 self .explicit_version = False
0 commit comments