Use TapTweakHash method for computing tweak
This commit is contained in:
parent
5286d0ab0c
commit
5b21a9cb1f
|
@ -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