Merge rust-bitcoin/rust-bitcoin#778: Fixups for taproot improvements
62a27a51e2
Document that serde impl of LeafVersion uses u8 in consensus encoding (Dr Maxim Orlovsky)73e6ce4e53
Re-export Witness at crate level. Closes #770 (Dr Maxim Orlovsky)6364ebd927
Code style fixups to taproot key functions (Dr Maxim Orlovsky)7514f2ca18
Tweaked -> untweaked keys conversions (Dr Maxim Orlovsky) Pull request description: This addresses @Kixunil review comments in #696 post-merge Update: also closes nits from issues #764 and #770 ACKs for top commit: Kixunil: ACK62a27a51e2
sanket1729: utACK62a27a51e2
Tree-SHA512: 2f10393abab41d1c82f4733d83bf85bd82e268a2891c156eb89744c0fc444fdfec4d60deec2dda6fde2e5881989625c18b9c5ca21d360018edba69b6d2a85eae
This commit is contained in:
commit
b2de2bc33d
|
@ -344,9 +344,6 @@ impl Script {
|
|||
}
|
||||
|
||||
/// Generates P2TR for key spending path for a known [`TweakedPublicKey`].
|
||||
///
|
||||
/// NB: Make sure that the used key is indeed tweaked (for instance, it comes from `rawtr`
|
||||
/// descriptor content); otherwise please use [`Script::new_v1_p2tr`] method.
|
||||
pub fn new_v1_p2tr_tweaked(output_key: TweakedPublicKey) -> Script {
|
||||
Script::new_witness_program(WitnessVersion::V1, &output_key.serialize())
|
||||
}
|
||||
|
@ -414,7 +411,7 @@ impl Script {
|
|||
|
||||
#[inline]
|
||||
fn witness_version(&self) -> Option<WitnessVersion> {
|
||||
WitnessVersion::from_opcode(self.0[0].into()).ok()
|
||||
self.0.get(0).and_then(|opcode| WitnessVersion::from_opcode(opcodes::All::from(*opcode)).ok())
|
||||
}
|
||||
|
||||
/// Checks whether a script pubkey is a p2sh output
|
||||
|
|
|
@ -124,6 +124,7 @@ pub use blockdata::transaction::TxIn;
|
|||
pub use blockdata::transaction::TxOut;
|
||||
pub use blockdata::transaction::OutPoint;
|
||||
pub use blockdata::transaction::EcdsaSigHashType;
|
||||
pub use blockdata::witness::Witness;
|
||||
pub use consensus::encode::VarInt;
|
||||
pub use network::constants::Network;
|
||||
pub use util::Error;
|
||||
|
|
|
@ -128,12 +128,11 @@ impl TapTweak for UntweakedKeyPair {
|
|||
///
|
||||
/// # Returns
|
||||
/// The tweaked key and its parity.
|
||||
fn tap_tweak<C: Verification>(self, secp: &Secp256k1<C>, merkle_root: Option<TapBranchHash>) -> TweakedKeyPair {
|
||||
fn tap_tweak<C: Verification>(mut self, secp: &Secp256k1<C>, merkle_root: Option<TapBranchHash>) -> TweakedKeyPair {
|
||||
let pubkey = XOnlyPublicKey::from_keypair(&self);
|
||||
let tweak_value = TapTweakHash::from_key_and_tweak(pubkey, merkle_root).into_inner();
|
||||
let mut output_key = self.clone();
|
||||
output_key.tweak_add_assign(&secp, &tweak_value).expect("Tap tweak failed");
|
||||
TweakedKeyPair(output_key)
|
||||
self.tweak_add_assign(&secp, &tweak_value).expect("Tap tweak failed");
|
||||
TweakedKeyPair(self)
|
||||
}
|
||||
|
||||
fn dangerous_assume_tweaked(self) -> TweakedKeyPair {
|
||||
|
@ -189,6 +188,20 @@ impl TweakedKeyPair {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<TweakedPublicKey> for XOnlyPublicKey {
|
||||
#[inline]
|
||||
fn from(pair: TweakedPublicKey) -> Self {
|
||||
pair.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TweakedKeyPair> for KeyPair {
|
||||
#[inline]
|
||||
fn from(pair: TweakedKeyPair) -> Self {
|
||||
pair.0
|
||||
}
|
||||
}
|
||||
|
||||
/// A BIP340-341 serialized schnorr signature with the corresponding hash type.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
|
|
|
@ -869,6 +869,7 @@ impl fmt::UpperHex for LeafVersion {
|
|||
}
|
||||
}
|
||||
|
||||
/// Serializes LeafVersion as u8 using consensus encoding
|
||||
#[cfg(feature = "serde")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
|
||||
impl ::serde::Serialize for LeafVersion {
|
||||
|
@ -880,6 +881,7 @@ impl ::serde::Serialize for LeafVersion {
|
|||
}
|
||||
}
|
||||
|
||||
/// Deserializes LeafVersion as u8 using consensus encoding
|
||||
#[cfg(feature = "serde")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
|
||||
impl<'de> ::serde::Deserialize<'de> for LeafVersion {
|
||||
|
|
Loading…
Reference in New Issue