From fc16f588234d9281264ddfc7f5aa5af6bed4aa4d Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Fri, 6 Oct 2023 17:33:26 +0200 Subject: [PATCH] primitives: add TaprootPk::from(PublicKey) --- primitives/src/taproot.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/primitives/src/taproot.rs b/primitives/src/taproot.rs index 18d01caf..383e7d44 100644 --- a/primitives/src/taproot.rs +++ b/primitives/src/taproot.rs @@ -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, @@ -81,6 +81,10 @@ impl TaprootPk { pub fn to_byte_array(&self) -> [u8; 32] { self.0.serialize() } } +impl From for TaprootPk { + fn from(pubkey: PublicKey) -> Self { TaprootPk(pubkey.x_only_public_key().0) } +} + impl From for [u8; 32] { fn from(pk: TaprootPk) -> [u8; 32] { pk.to_byte_array() } }