Skip to content

Commit d379a9f

Browse files
committed
Fixed signatures and sighashes push to graph after checking if compute_key_path must be done
1 parent 3c5e9ae commit d379a9f

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

src/builder/protocol.rs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,14 +1586,14 @@ impl Protocol {
15861586
)?;
15871587

15881588
hashed_messages.push(Some(key_spend_hashed_message));
1589-
1590-
self.graph.update_hashed_messages(
1591-
transaction_name,
1592-
input_index as u32,
1593-
hashed_messages,
1594-
)?;
15951589
};
15961590

1591+
self.graph.update_hashed_messages(
1592+
transaction_name,
1593+
input_index as u32,
1594+
hashed_messages,
1595+
)?;
1596+
15971597
Ok(())
15981598
}
15991599

@@ -1748,12 +1748,12 @@ impl Protocol {
17481748
});
17491749

17501750
signatures.push(Some(key_spend_signature));
1751-
1752-
// Update signatures for the input
1753-
self.graph
1754-
.update_input_signatures(transaction_name, input_index as u32, signatures)?;
17551751
}
17561752

1753+
// Update signatures for the input
1754+
self.graph
1755+
.update_input_signatures(transaction_name, input_index as u32, signatures)?;
1756+
17571757
Ok(())
17581758
}
17591759

@@ -1942,11 +1942,11 @@ impl Protocol {
19421942
if compute_key_path {
19431943
// Compute a sighash and its signature for the key spend path.
19441944

1945-
// 1. Reconstruct the bitcoin::PublicKey from the XOnlyPublicKey to sign the message using the KeyManager.
1945+
// Reconstruct the bitcoin::PublicKey from the XOnlyPublicKey to sign the message using the KeyManager.
19461946
// Taproot internal keys always have an Even parity.
19471947
let full_public_key: PublicKey = internal_key.public_key(Parity::Even).into();
19481948

1949-
// 2. Compute and push a message hash for the key spend signature.
1949+
// Compute and push a message hash for the key spend signature.
19501950
let key_spend_hashed_message =
19511951
Message::from(sighasher.taproot_key_spend_signature_hash(
19521952
input_index,
@@ -1956,7 +1956,7 @@ impl Protocol {
19561956

19571957
hashed_messages.push(Some(key_spend_hashed_message));
19581958

1959-
// 3. Compute and push the key spend signature.
1959+
// Compute and push the key spend signature.
19601960
let (schnorr_signature, output_key) = key_manager.sign_schnorr_message_with_tap_tweak(
19611961
&key_spend_hashed_message,
19621962
&full_public_key,
@@ -1968,7 +1968,7 @@ impl Protocol {
19681968
sighash_type: *sighash_type,
19691969
});
19701970

1971-
// 4. Verify the signature:
1971+
// Verify the signature:
19721972
if !SignatureVerifier::new().verify_schnorr_signature(
19731973
&schnorr_signature,
19741974
&key_spend_hashed_message,
@@ -1978,17 +1978,18 @@ impl Protocol {
19781978
}
19791979

19801980
signatures.push(Some(key_spend_signature));
1981-
1982-
// 5. Update hashes and signatures for the input
1983-
self.graph.update_hashed_messages(
1984-
transaction_name,
1985-
input_index as u32,
1986-
hashed_messages,
1987-
)?;
1988-
self.graph
1989-
.update_input_signatures(transaction_name, input_index as u32, signatures)?;
19901981
};
19911982

1983+
// Update hashes and signatures for the input
1984+
self.graph.update_hashed_messages(
1985+
transaction_name,
1986+
input_index as u32,
1987+
hashed_messages,
1988+
)?;
1989+
1990+
self.graph
1991+
.update_input_signatures(transaction_name, input_index as u32, signatures)?;
1992+
19921993
Ok(())
19931994
}
19941995

0 commit comments

Comments
 (0)