Use TapTweakHash method for computing tweak

This commit is contained in:
Noah 2021-11-25 09:45:27 +11:00
parent 5286d0ab0c
commit 5b21a9cb1f
2 changed files with 5 additions and 8 deletions

View File

@ -524,7 +524,7 @@ impl Address {
pub fn p2tr<C: Verification>(
secp: &Secp256k1<C>,
internal_key: UntweakedPublicKey,
merkle_root: Option<&TapBranchHash>,
merkle_root: Option<TapBranchHash>,
network: Network
) -> Address {
Address {

View File

@ -19,7 +19,7 @@
pub use secp256k1::schnorrsig::{PublicKey, KeyPair};
use secp256k1::{Secp256k1, Verification};
use hashes::{Hash, HashEngine};
use hashes::Hash;
use util::taproot::{TapBranchHash, TapTweakHash};
/// Untweaked Schnorr public key
@ -38,7 +38,7 @@ pub trait TapTweak {
/// * H is the hash function
/// * c is the commitment data
/// * 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
///
@ -48,12 +48,9 @@ pub trait TapTweak {
}
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
let mut engine = TapTweakHash::engine();
engine.input(&self.serialize());
merkle_root.map(|hash| engine.input(&hash));
let tweak_value: [u8; 32] = TapTweakHash::from_engine(engine).into_inner();
let tweak_value = TapTweakHash::from_key_and_tweak(self, merkle_root).into_inner();
//Tweak the internal key by the tweak value
let mut output_key = self.clone();