Skip to content

Commit

Permalink
consensus: improve InternalPk::to_output_pk API
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jul 16, 2024
1 parent 2d5818d commit 9318036
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
14 changes: 4 additions & 10 deletions consensus/src/taproot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,7 @@ impl InternalPk {
#[inline]
pub fn to_byte_array(&self) -> [u8; 32] { self.0.to_byte_array() }

#[deprecated(since = "0.10.9", note = "use to_output_pk")]
pub fn to_output_key(&self, merkle_root: Option<impl IntoTapHash>) -> XOnlyPublicKey {
let (pk, _) = self.to_output_pk(merkle_root);
pk.0.0
}

pub fn to_output_pk(&self, merkle_root: Option<impl IntoTapHash>) -> (OutputPk, Parity) {
pub fn to_output_pk(&self, merkle_root: Option<TapNodeHash>) -> (OutputPk, Parity) {
let mut engine = Sha256::from_tag(MIDSTATE_TAPTWEAK);
// always hash the key
engine.input_raw(&self.0.serialize());
Expand Down Expand Up @@ -672,18 +666,18 @@ impl TapScript {
}

impl ScriptPubkey {
pub fn p2tr(internal_key: InternalPk, merkle_root: Option<impl IntoTapHash>) -> Self {
pub fn p2tr(internal_key: InternalPk, merkle_root: Option<TapNodeHash>) -> Self {
let (output_key, _) = internal_key.to_output_pk(merkle_root);
Self::p2tr_tweaked(output_key)
}

pub fn p2tr_key_only(internal_key: InternalPk) -> Self {
let (output_key, _) = internal_key.to_output_pk(None::<TapNodeHash>);
let (output_key, _) = internal_key.to_output_pk(None);

Check warning on line 675 in consensus/src/taproot.rs

View check run for this annotation

Codecov / codecov/patch

consensus/src/taproot.rs#L675

Added line #L675 was not covered by tests
Self::p2tr_tweaked(output_key)
}

pub fn p2tr_scripted(internal_key: InternalPk, merkle_root: impl IntoTapHash) -> Self {
let (output_key, _) = internal_key.to_output_pk(Some(merkle_root));
let (output_key, _) = internal_key.to_output_pk(Some(merkle_root.into_tap_hash()));

Check warning on line 680 in consensus/src/taproot.rs

View check run for this annotation

Codecov / codecov/patch

consensus/src/taproot.rs#L680

Added line #L680 was not covered by tests
Self::p2tr_tweaked(output_key)
}

Expand Down
4 changes: 2 additions & 2 deletions dbc/src/tapret/xonlypk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl ConvolveCommit<mpc::Commitment, TapretProof, TapretFirst> for InternalPk {
mod test {
use std::str::FromStr;

use bc::LeafScript;
use bc::{IntoTapHash, LeafScript};
use commit_verify::mpc::Commitment;

use super::*;
Expand All @@ -115,7 +115,7 @@ mod test {
let tapret_commitment = TapretCommitment::with(msg, path_proof.nonce);
let script_commitment = TapScript::commit(&tapret_commitment);
let script_leaf = TapLeafHash::with_tap_script(&script_commitment);
let (real_key, _) = internal_pk.to_output_pk(Some(script_leaf));
let (real_key, _) = internal_pk.to_output_pk(Some(script_leaf.into_tap_hash()));

assert_eq!(outer_key, real_key);

Expand Down

0 comments on commit 9318036

Please sign in to comment.