@@ -4494,8 +4494,10 @@ int wally_psbt_get_input_signature_hash(struct wally_psbt *psbt, size_t index,
44944494 const struct wally_psbt_input * inp = psbt_get_input (psbt , index );
44954495 const struct wally_tx_output * utxo = utxo_from_input (psbt , inp );
44964496 size_t is_pset ;
4497- uint32_t sighash , sig_flags ;
4497+ uint32_t sighash ;
44984498 const bool is_taproot = is_taproot_input (psbt , inp );
4499+ /* FIXME: Determine segwitness in a smarter way (e.g. prevout script */
4500+ const bool is_segwit = inp -> witness_utxo != NULL ;
44994501 int ret ;
45004502
45014503 if (!tx || !inp || !utxo || flags )
@@ -4514,22 +4516,24 @@ int wally_psbt_get_input_signature_hash(struct wally_psbt *psbt, size_t index,
45144516 else if (sighash & 0xffffff00 )
45154517 return WALLY_EINVAL ;
45164518
4517- if (is_taproot ) {
4519+ if (is_taproot || is_segwit ) {
45184520 struct wally_map scripts , assets , values ;
45194521 struct wally_map * assets_p = is_pset ? & assets : NULL ;
45204522
4521- #ifdef BUILD_ELEMENTS
4522- if (is_pset && mem_is_zero (psbt -> genesis_blockhash , sizeof (psbt -> genesis_blockhash )))
4523- return WALLY_EINVAL ; /* Genesis blockhash is required for taproot */
4524- #endif
4523+ if (is_taproot ) {
4524+ /* FIXME: Support script path spends */
4525+ script = NULL ;
4526+ script_len = 0 ;
4527+ }
45254528 ret = get_signing_data (psbt , & scripts , assets_p , & values );
45264529 if (ret == WALLY_OK )
45274530 ret = wally_tx_get_input_signature_hash (tx , index ,
45284531 & scripts , assets_p , & values ,
4529- NULL , 0 , 0 , WALLY_NO_CODESEPARATOR ,
4530- NULL , 0 ,
4532+ script , script_len ,
4533+ 0 , WALLY_NO_CODESEPARATOR , NULL , 0 ,
45314534 psbt -> genesis_blockhash , sizeof (psbt -> genesis_blockhash ),
4532- sighash , WALLY_SIGTYPE_SW_V1 ,
4535+ sighash ,
4536+ is_taproot ? WALLY_SIGTYPE_SW_V1 : WALLY_SIGTYPE_SW_V0 ,
45334537 psbt -> signing_cache , bytes_out , len );
45344538
45354539 wally_free (scripts .items ); /* No need to clear the value pointers */
@@ -4539,18 +4543,16 @@ int wally_psbt_get_input_signature_hash(struct wally_psbt *psbt, size_t index,
45394543 return ret ;
45404544 }
45414545
4542- sig_flags = inp -> witness_utxo ? WALLY_TX_FLAG_USE_WITNESS : 0 ;
4543-
45444546#ifdef BUILD_ELEMENTS
45454547 if (is_pset )
45464548 return wally_tx_get_elements_signature_hash (tx , index ,
45474549 script , script_len ,
45484550 utxo -> value , utxo -> value_len ,
4549- sighash , sig_flags , bytes_out ,
4551+ sighash , 0 , bytes_out ,
45504552 len );
45514553#endif
45524554 return wally_tx_get_btc_signature_hash (tx , index , script , script_len ,
4553- utxo -> satoshi , sighash , sig_flags ,
4555+ utxo -> satoshi , sighash , 0 ,
45544556 bytes_out , len );
45554557}
45564558
0 commit comments