Merge rust-bitcoin/rust-bitcoin#4522: fix(taproot): raname `from_key_and_tweak` to `from_key_and_merkle_root`
d74eede260
fix(taproot): raname `from_key_and_tweak` to `from_key_and_merkle_root` (Luis Schwab) Pull request description: Closes #4236. ### Changelog - Rename `TapTweakHash::from_key_and_tweak` to `TapTweakHash::from_key_and_merkle_root`. The naming was just wrong, since a TapTweak takes in a public key and a Merkle root to produce a tweak. ACKs for top commit: apoelstra: ACK d74eede26064a40d70c7aeb3335b9a4a28eb6bd9; successfully ran local tests tcharding: ACKd74eede260
Tree-SHA512: 03fdb73758f965290c083165b23a0345325e475f159aa76ff141a9aa3251960041366ddf195b74cada7b289d4493190cf9b17130736002d48b6fac68941012fb
This commit is contained in:
commit
8985c9e5c4
|
@ -940,7 +940,7 @@ impl TapTweak for UntweakedPublicKey {
|
||||||
secp: &Secp256k1<C>,
|
secp: &Secp256k1<C>,
|
||||||
merkle_root: Option<TapNodeHash>,
|
merkle_root: Option<TapNodeHash>,
|
||||||
) -> (TweakedPublicKey, Parity) {
|
) -> (TweakedPublicKey, Parity) {
|
||||||
let tweak = TapTweakHash::from_key_and_tweak(self, merkle_root).to_scalar();
|
let tweak = TapTweakHash::from_key_and_merkle_root(self, merkle_root).to_scalar();
|
||||||
let (output_key, parity) = self.add_tweak(secp, &tweak).expect("Tap tweak failed");
|
let (output_key, parity) = self.add_tweak(secp, &tweak).expect("Tap tweak failed");
|
||||||
|
|
||||||
debug_assert!(self.tweak_add_check(secp, &output_key, parity, tweak));
|
debug_assert!(self.tweak_add_check(secp, &output_key, parity, tweak));
|
||||||
|
@ -970,7 +970,7 @@ impl TapTweak for UntweakedKeypair {
|
||||||
merkle_root: Option<TapNodeHash>,
|
merkle_root: Option<TapNodeHash>,
|
||||||
) -> TweakedKeypair {
|
) -> TweakedKeypair {
|
||||||
let (pubkey, _parity) = XOnlyPublicKey::from_keypair(&self);
|
let (pubkey, _parity) = XOnlyPublicKey::from_keypair(&self);
|
||||||
let tweak = TapTweakHash::from_key_and_tweak(pubkey, merkle_root).to_scalar();
|
let tweak = TapTweakHash::from_key_and_merkle_root(pubkey, merkle_root).to_scalar();
|
||||||
let tweaked = self.add_xonly_tweak(secp, &tweak).expect("Tap tweak failed");
|
let tweaked = self.add_xonly_tweak(secp, &tweak).expect("Tap tweak failed");
|
||||||
TweakedKeypair(tweaked)
|
TweakedKeypair(tweaked)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2009,7 +2009,7 @@ mod tests {
|
||||||
// tests
|
// tests
|
||||||
let keypair = secp256k1::Keypair::from_secret_key(secp, &internal_priv_key);
|
let keypair = secp256k1::Keypair::from_secret_key(secp, &internal_priv_key);
|
||||||
let (internal_key, _parity) = XOnlyPublicKey::from_keypair(&keypair);
|
let (internal_key, _parity) = XOnlyPublicKey::from_keypair(&keypair);
|
||||||
let tweak = TapTweakHash::from_key_and_tweak(internal_key, merkle_root);
|
let tweak = TapTweakHash::from_key_and_merkle_root(internal_key, merkle_root);
|
||||||
let tweaked_keypair = keypair.add_xonly_tweak(secp, &tweak.to_scalar()).unwrap();
|
let tweaked_keypair = keypair.add_xonly_tweak(secp, &tweak.to_scalar()).unwrap();
|
||||||
let mut sig_msg = Vec::new();
|
let mut sig_msg = Vec::new();
|
||||||
cache
|
cache
|
||||||
|
|
|
@ -95,9 +95,9 @@ impl From<TapLeafHash> for TapNodeHash {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TapTweakHash {
|
impl TapTweakHash {
|
||||||
/// Constructs a new BIP341 [`TapTweakHash`] from key and tweak. Produces `H_taptweak(P||R)` where
|
/// Constructs a new BIP341 [`TapTweakHash`] from key and Merkle root. Produces `H_taptweak(P||R)` where
|
||||||
/// `P` is the internal key and `R` is the Merkle root.
|
/// `P` is the internal key and `R` is the Merkle root.
|
||||||
pub fn from_key_and_tweak<K: Into<UntweakedPublicKey>>(
|
pub fn from_key_and_merkle_root<K: Into<UntweakedPublicKey>>(
|
||||||
internal_key: K,
|
internal_key: K,
|
||||||
merkle_root: Option<TapNodeHash>,
|
merkle_root: Option<TapNodeHash>,
|
||||||
) -> TapTweakHash {
|
) -> TapTweakHash {
|
||||||
|
@ -293,7 +293,7 @@ impl TaprootSpendInfo {
|
||||||
/// Returns the `TapTweakHash` for this [`TaprootSpendInfo`] i.e., the tweak using `internal_key`
|
/// Returns the `TapTweakHash` for this [`TaprootSpendInfo`] i.e., the tweak using `internal_key`
|
||||||
/// and `merkle_root`.
|
/// and `merkle_root`.
|
||||||
pub fn tap_tweak(&self) -> TapTweakHash {
|
pub fn tap_tweak(&self) -> TapTweakHash {
|
||||||
TapTweakHash::from_key_and_tweak(self.internal_key, self.merkle_root)
|
TapTweakHash::from_key_and_merkle_root(self.internal_key, self.merkle_root)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the internal key for this [`TaprootSpendInfo`].
|
/// Returns the internal key for this [`TaprootSpendInfo`].
|
||||||
|
@ -1305,7 +1305,7 @@ impl<Branch: AsRef<TaprootMerkleBranch> + ?Sized> ControlBlock<Branch> {
|
||||||
}
|
}
|
||||||
// compute the taptweak
|
// compute the taptweak
|
||||||
let tweak =
|
let tweak =
|
||||||
TapTweakHash::from_key_and_tweak(self.internal_key, Some(curr_hash)).to_scalar();
|
TapTweakHash::from_key_and_merkle_root(self.internal_key, Some(curr_hash)).to_scalar();
|
||||||
self.internal_key.tweak_add_check(secp, &output_key, self.output_key_parity, tweak)
|
self.internal_key.tweak_add_check(secp, &output_key, self.output_key_parity, tweak)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2103,7 +2103,7 @@ mod test {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.assume_checked();
|
.assume_checked();
|
||||||
|
|
||||||
let tweak = TapTweakHash::from_key_and_tweak(internal_key, merkle_root);
|
let tweak = TapTweakHash::from_key_and_merkle_root(internal_key, merkle_root);
|
||||||
let (output_key, _parity) = internal_key.tap_tweak(secp, merkle_root);
|
let (output_key, _parity) = internal_key.tap_tweak(secp, merkle_root);
|
||||||
let addr = Address::p2tr(secp, internal_key, merkle_root, KnownHrp::Mainnet);
|
let addr = Address::p2tr(secp, internal_key, merkle_root, KnownHrp::Mainnet);
|
||||||
let spk = addr.script_pubkey();
|
let spk = addr.script_pubkey();
|
||||||
|
|
Loading…
Reference in New Issue