Skip to content

Commit

Permalink
primitives: add TaprootPk::from(PublicKey)
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Oct 6, 2023
1 parent 7c10f61 commit fc16f58
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion primitives/src/taproot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use std::{cmp, io, slice, vec};
use amplify::confinement::{Confined, U32};
use amplify::{confinement, Bytes32, Wrapper};
use commit_verify::{DigestExt, Sha256};
use secp256k1::{Scalar, XOnlyPublicKey};
use secp256k1::{PublicKey, Scalar, XOnlyPublicKey};
use strict_encoding::{
DecodeError, ReadTuple, StrictDecode, StrictEncode, StrictProduct, StrictTuple, StrictType,
TypeName, TypedRead, TypedWrite, WriteTuple,
Expand Down Expand Up @@ -81,6 +81,10 @@ impl TaprootPk {
pub fn to_byte_array(&self) -> [u8; 32] { self.0.serialize() }
}

impl From<PublicKey> for TaprootPk {
fn from(pubkey: PublicKey) -> Self { TaprootPk(pubkey.x_only_public_key().0) }
}

impl From<TaprootPk> for [u8; 32] {
fn from(pk: TaprootPk) -> [u8; 32] { pk.to_byte_array() }
}
Expand Down

0 comments on commit fc16f58

Please sign in to comment.