Merge rust-bitcoin/rust-bitcoin#697: Use TapTweakHash::from_key_and_tweak() method in computing tweak for UntweakedPublicKey
5b21a9cb1f
Use TapTweakHash method for computing tweak (Noah) Pull request description: Quick follow up PR to #691 using a method from #677. ### Changes - Updated `UntweakedPublicKey::tap_tweak(...)` to use `TapTweakHash::from_key_and_tweak(...)` ACKs for top commit: Kixunil: ACK5b21a9cb1f
dr-orlovsky: utACK5b21a9cb1f
Tree-SHA512: d00455bba51981e9ec942a6cf69672666e227850d073b1fdcd92d2eb6ad553659fb2967aec2ce12d3ed109cee5fa125cdda649cddb25404f08adae2bfd3e19bb
This commit is contained in:
commit
95cf9b0a44
|
@ -524,7 +524,7 @@ impl Address {
|
||||||
pub fn p2tr<C: Verification>(
|
pub fn p2tr<C: Verification>(
|
||||||
secp: &Secp256k1<C>,
|
secp: &Secp256k1<C>,
|
||||||
internal_key: UntweakedPublicKey,
|
internal_key: UntweakedPublicKey,
|
||||||
merkle_root: Option<&TapBranchHash>,
|
merkle_root: Option<TapBranchHash>,
|
||||||
network: Network
|
network: Network
|
||||||
) -> Address {
|
) -> Address {
|
||||||
Address {
|
Address {
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
pub use secp256k1::schnorrsig::{PublicKey, KeyPair};
|
pub use secp256k1::schnorrsig::{PublicKey, KeyPair};
|
||||||
use secp256k1::{Secp256k1, Verification};
|
use secp256k1::{Secp256k1, Verification};
|
||||||
use hashes::{Hash, HashEngine};
|
use hashes::Hash;
|
||||||
use util::taproot::{TapBranchHash, TapTweakHash};
|
use util::taproot::{TapBranchHash, TapTweakHash};
|
||||||
|
|
||||||
/// Untweaked Schnorr public key
|
/// Untweaked Schnorr public key
|
||||||
|
@ -38,7 +38,7 @@ pub trait TapTweak {
|
||||||
/// * H is the hash function
|
/// * H is the hash function
|
||||||
/// * c is the commitment data
|
/// * c is the commitment data
|
||||||
/// * G is the generator point
|
/// * G is the generator point
|
||||||
fn tap_tweak<C: Verification>(&self, secp: &Secp256k1<C>, merkle_root: Option<&TapBranchHash>) -> TweakedPublicKey;
|
fn tap_tweak<C: Verification>(self, secp: &Secp256k1<C>, merkle_root: Option<TapBranchHash>) -> TweakedPublicKey;
|
||||||
|
|
||||||
/// Directly convert an UntweakedPublicKey to a TweakedPublicKey
|
/// Directly convert an UntweakedPublicKey to a TweakedPublicKey
|
||||||
///
|
///
|
||||||
|
@ -48,12 +48,9 @@ pub trait TapTweak {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TapTweak for UntweakedPublicKey {
|
impl TapTweak for UntweakedPublicKey {
|
||||||
fn tap_tweak<C: Verification>(&self, secp: &Secp256k1<C>, merkle_root: Option<&TapBranchHash>) -> TweakedPublicKey {
|
fn tap_tweak<C: Verification>(self, secp: &Secp256k1<C>, merkle_root: Option<TapBranchHash>) -> TweakedPublicKey {
|
||||||
// Compute the tweak
|
// Compute the tweak
|
||||||
let mut engine = TapTweakHash::engine();
|
let tweak_value = TapTweakHash::from_key_and_tweak(self, merkle_root).into_inner();
|
||||||
engine.input(&self.serialize());
|
|
||||||
merkle_root.map(|hash| engine.input(&hash));
|
|
||||||
let tweak_value: [u8; 32] = TapTweakHash::from_engine(engine).into_inner();
|
|
||||||
|
|
||||||
//Tweak the internal key by the tweak value
|
//Tweak the internal key by the tweak value
|
||||||
let mut output_key = self.clone();
|
let mut output_key = self.clone();
|
||||||
|
|
Loading…
Reference in New Issue