pub struct TaprootPk(/* private fields */);
Expand description
Generic taproot x-only (BIP-340) public key - a wrapper around
XOnlyPublicKey
providing APIs compatible with the rest of the library.
Should be used everywhere when InternalPk
and OutputPk
do not apply:
as an output of BIP32 key derivation functions, inside tapscripts/
leafscripts etc.
Implementations§
source§impl TaprootPk
impl TaprootPk
pub fn from_byte_array(data: [u8; 32]) -> Result<Self, InvalidPubkey>
pub fn to_byte_array(&self) -> [u8; 32]
Methods from Deref<Target = XOnlyPublicKey>§
sourcepub fn cmp_fast_unstable(&self, other: &XOnlyPublicKey) -> Ordering
pub fn cmp_fast_unstable(&self, other: &XOnlyPublicKey) -> Ordering
Like cmp::Cmp
but faster and with no guarantees across library versions.
The Cmp
implementation for FFI types is stable but slow because it first
serializes self
and other
before comparing them. This function provides a faster
comparison if you know that your types come from the same library version.
sourcepub fn eq_fast_unstable(&self, other: &XOnlyPublicKey) -> bool
pub fn eq_fast_unstable(&self, other: &XOnlyPublicKey) -> bool
Like cmp::Eq
but faster and with no guarantees across library versions.
The Eq
implementation for FFI types is stable but slow because it first serializes
self
and other
before comparing them. This function provides a faster equality
check if you know that your types come from the same library version.
sourcepub fn as_ptr(&self) -> *const XOnlyPublicKey
👎Deprecated since 0.25.0: Use Self::as_c_ptr if you need to access the FFI layer
pub fn as_ptr(&self) -> *const XOnlyPublicKey
Obtains a raw const pointer suitable for use with FFI functions.
sourcepub fn as_mut_ptr(&mut self) -> *mut XOnlyPublicKey
👎Deprecated since 0.25.0: Use Self::as_mut_c_ptr if you need to access the FFI layer
pub fn as_mut_ptr(&mut self) -> *mut XOnlyPublicKey
Obtains a raw mutable pointer suitable for use with FFI functions.
sourcepub fn serialize(&self) -> [u8; 32]
pub fn serialize(&self) -> [u8; 32]
Serializes the key as a byte-encoded x coordinate value (32 bytes).
sourcepub fn tweak_add_check<V>(
&self,
secp: &Secp256k1<V>,
tweaked_key: &XOnlyPublicKey,
tweaked_parity: Parity,
tweak: Scalar
) -> boolwhere
V: Verification,
pub fn tweak_add_check<V>( &self, secp: &Secp256k1<V>, tweaked_key: &XOnlyPublicKey, tweaked_parity: Parity, tweak: Scalar ) -> boolwhere V: Verification,
Verifies that a tweak produced by XOnlyPublicKey::add_tweak
was computed correctly.
Should be called on the original untweaked key. Takes the tweaked key and output parity from
XOnlyPublicKey::add_tweak
as input.
Currently this is not much more efficient than just recomputing the tweak and checking equality. However, in future this API will support batch verification, which is significantly faster, so it is wise to design protocols with this in mind.
Returns
True if tweak and check is successful, false otherwise.
Examples
use secp256k1::{Secp256k1, KeyPair, Scalar};
let secp = Secp256k1::new();
let tweak = Scalar::random();
let mut key_pair = KeyPair::new(&secp, &mut rand::thread_rng());
let (mut public_key, _) = key_pair.x_only_public_key();
let original = public_key;
let (tweaked, parity) = public_key.add_tweak(&secp, &tweak).expect("Improbable to fail with a randomly generated tweak");
assert!(original.tweak_add_check(&secp, &tweaked, parity, tweak));
sourcepub fn public_key(&self, parity: Parity) -> PublicKey
pub fn public_key(&self, parity: Parity) -> PublicKey
Returns the PublicKey
for this XOnlyPublicKey
.
This is equivalent to using [PublicKey::from_xonly_and_parity(self, parity)
].
Trait Implementations§
source§impl AsRef<XOnlyPublicKey> for TaprootPk
impl AsRef<XOnlyPublicKey> for TaprootPk
source§fn as_ref(&self) -> &XOnlyPublicKey
fn as_ref(&self) -> &XOnlyPublicKey
source§impl Borrow<XOnlyPublicKey> for TaprootPk
impl Borrow<XOnlyPublicKey> for TaprootPk
source§fn borrow(&self) -> &XOnlyPublicKey
fn borrow(&self) -> &XOnlyPublicKey
source§impl<'de> Deserialize<'de> for TaprootPk
impl<'de> Deserialize<'de> for TaprootPk
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl From<TaprootPk> for XOnlyPublicKey
impl From<TaprootPk> for XOnlyPublicKey
source§impl From<XOnlyPublicKey> for TaprootPk
impl From<XOnlyPublicKey> for TaprootPk
source§fn from(v: XOnlyPublicKey) -> Self
fn from(v: XOnlyPublicKey) -> Self
source§impl Ord for TaprootPk
impl Ord for TaprootPk
source§impl PartialEq for TaprootPk
impl PartialEq for TaprootPk
source§impl PartialOrd for TaprootPk
impl PartialOrd for TaprootPk
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl StrictDecode for TaprootPk
impl StrictDecode for TaprootPk
fn strict_decode(reader: &mut impl TypedRead) -> Result<Self, DecodeError>
fn strict_read(lim: usize, reader: impl Read) -> Result<Self, DecodeError>
source§impl StrictDumb for TaprootPk
impl StrictDumb for TaprootPk
fn strict_dumb() -> Self
source§impl StrictEncode for TaprootPk
impl StrictEncode for TaprootPk
fn strict_encode<W: TypedWrite>(&self, writer: W) -> Result<W>
fn strict_write(&self, lim: usize, writer: impl Write) -> Result<usize, Error>
source§impl StrictTuple for TaprootPk
impl StrictTuple for TaprootPk
const FIELD_COUNT: u8 = 1u8
fn strict_check_fields()
fn strict_type_info() -> TypeInfo<Self>
source§impl StrictType for TaprootPk
impl StrictType for TaprootPk
const STRICT_LIB_NAME: &'static str = LIB_NAME_BITCOIN
fn strict_name() -> Option<TypeName>
source§impl Wrapper for TaprootPk
impl Wrapper for TaprootPk
§type Inner = XOnlyPublicKey
type Inner = XOnlyPublicKey
source§fn from_inner(inner: Self::Inner) -> Self
fn from_inner(inner: Self::Inner) -> Self
source§fn as_inner(&self) -> &Self::Inner
fn as_inner(&self) -> &Self::Inner
source§fn into_inner(self) -> Self::Inner
fn into_inner(self) -> Self::Inner
source§impl WrapperMut for TaprootPk
impl WrapperMut for TaprootPk
source§fn as_inner_mut(&mut self) -> &mut <Self as Wrapper>::Inner
fn as_inner_mut(&mut self) -> &mut <Self as Wrapper>::Inner
impl Copy for TaprootPk
impl Eq for TaprootPk
impl StrictProduct for TaprootPk
impl StructuralEq for TaprootPk
impl StructuralPartialEq for TaprootPk
Auto Trait Implementations§
impl RefUnwindSafe for TaprootPk
impl Send for TaprootPk
impl Sync for TaprootPk
impl Unpin for TaprootPk
impl UnwindSafe for TaprootPk
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.