@@ -1283,8 +1283,10 @@ function getHashForSig(inputIndex, input, cache, forValidate, sighashTypes) {
12831283function getAllTaprootHashesForSig ( inputIndex , input , inputs , cache ) {
12841284 const allPublicKeys = [ ] ;
12851285 if ( input . tapInternalKey ) {
1286- const outputKey = ( 0 , bip371_1 . tweakInternalPubKey ) ( inputIndex , input ) ;
1287- allPublicKeys . push ( outputKey ) ;
1286+ const key = getPrevoutTaprootKey ( inputIndex , input , cache ) ;
1287+ if ( key ) {
1288+ allPublicKeys . push ( key ) ;
1289+ }
12881290 }
12891291 if ( input . tapScriptSig ) {
12901292 const tapScriptPubkeys = input . tapScriptSig . map ( tss => tss . pubkey ) ;
@@ -1295,8 +1297,12 @@ function getAllTaprootHashesForSig(inputIndex, input, inputs, cache) {
12951297 ) ;
12961298 return allHashes . flat ( ) ;
12971299}
1300+ function getPrevoutTaprootKey ( inputIndex , input , cache ) {
1301+ const { script } = getScriptAndAmountFromUtxo ( inputIndex , input , cache ) ;
1302+ return ( 0 , psbtutils_1 . isP2TR ) ( script ) ? script . subarray ( 2 , 34 ) : null ;
1303+ }
12981304function trimTaprootSig ( signature ) {
1299- return signature . length === 64 ? signature : signature . subarray ( 1 ) ;
1305+ return signature . length === 64 ? signature : signature . subarray ( 0 , 64 ) ;
13001306}
13011307function getTaprootHashesForSig (
13021308 inputIndex ,
@@ -1318,7 +1324,8 @@ function getTaprootHashesForSig(
13181324 const values = prevOuts . map ( o => o . value ) ;
13191325 const hashes = [ ] ;
13201326 if ( input . tapInternalKey && ! tapLeafHashToSign ) {
1321- const outputKey = ( 0 , bip371_1 . tweakInternalPubKey ) ( inputIndex , input ) ;
1327+ const outputKey =
1328+ getPrevoutTaprootKey ( inputIndex , input , cache ) || Buffer . from ( [ ] ) ;
13221329 if ( ( 0 , bip371_1 . toXOnly ) ( pubkey ) . equals ( outputKey ) ) {
13231330 const tapKeyHash = unsignedTx . hashForWitnessV1 (
13241331 inputIndex ,
0 commit comments