Skip to content

Commit

Permalink
consensus: add InternalPk and OutputPk::to_xonly_pk method
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jul 16, 2024
1 parent 9318036 commit 743e4d5
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions consensus/src/taproot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,17 @@ impl InternalPk {
XOnlyPk::from_byte_array(data).map(Self)
}

#[inline]
pub fn from_bytes(bytes: impl AsRef<[u8]>) -> Result<Self, InvalidPubkey<33>> {
XOnlyPk::from_bytes(bytes).map(Self)
}

#[inline]
pub fn to_byte_array(&self) -> [u8; 32] { self.0.to_byte_array() }

#[inline]
pub fn to_xonly_pk(&self) -> XOnlyPk { self.0 }

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

View check run for this annotation

Codecov / codecov/patch

consensus/src/taproot.rs#L177

Added line #L177 was not covered by tests

pub fn to_output_pk(&self, merkle_root: Option<TapNodeHash>) -> (OutputPk, Parity) {
let mut engine = Sha256::from_tag(MIDSTATE_TAPTWEAK);
// always hash the key
Expand Down Expand Up @@ -223,10 +227,15 @@ impl OutputPk {
XOnlyPk::from_byte_array(data).map(Self)
}

#[inline]
pub fn from_bytes(bytes: impl AsRef<[u8]>) -> Result<Self, InvalidPubkey<33>> {
XOnlyPk::from_bytes(bytes).map(Self)
}

#[inline]
pub fn to_xonly_pk(&self) -> XOnlyPk { self.0 }

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

View check run for this annotation

Codecov / codecov/patch

consensus/src/taproot.rs#L236

Added line #L236 was not covered by tests

#[inline]
pub fn to_script_pubkey(&self) -> ScriptPubkey { ScriptPubkey::p2tr_tweaked(*self) }

#[inline]
Expand Down

0 comments on commit 743e4d5

Please sign in to comment.