pub struct XOnlyPk(/* 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 XOnlyPk
impl XOnlyPk
pub fn from_byte_array(data: [u8; 32]) -> Result<XOnlyPk, InvalidPubkey<32>>
pub fn to_byte_array(&self) -> [u8; 32]
pub fn from_bytes(bytes: impl AsRef<[u8]>) -> Result<XOnlyPk, InvalidPubkey<33>>
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 keypair = Keypair::new(&secp, &mut rand::thread_rng());
let (mut public_key, _) = keypair.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<XOnlyPk> for InternalPk
impl AsRef<XOnlyPk> for InternalPk
Source§impl AsRef<XOnlyPublicKey> for XOnlyPk
impl AsRef<XOnlyPublicKey> for XOnlyPk
Source§fn as_ref(&self) -> &XOnlyPublicKey
fn as_ref(&self) -> &XOnlyPublicKey
Source§impl Borrow<XOnlyPk> for InternalPk
impl Borrow<XOnlyPk> for InternalPk
Source§impl Borrow<XOnlyPublicKey> for XOnlyPk
impl Borrow<XOnlyPublicKey> for XOnlyPk
Source§fn borrow(&self) -> &XOnlyPublicKey
fn borrow(&self) -> &XOnlyPublicKey
Source§impl<'de> Deserialize<'de> for XOnlyPk
impl<'de> Deserialize<'de> for XOnlyPk
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<XOnlyPk, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<XOnlyPk, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl From<CompressedPk> for XOnlyPk
impl From<CompressedPk> for XOnlyPk
Source§fn from(pubkey: CompressedPk) -> XOnlyPk
fn from(pubkey: CompressedPk) -> XOnlyPk
Source§impl From<InternalPk> for XOnlyPk
impl From<InternalPk> for XOnlyPk
Source§fn from(wrapped: InternalPk) -> XOnlyPk
fn from(wrapped: InternalPk) -> XOnlyPk
Source§impl From<XOnlyPk> for InternalPk
impl From<XOnlyPk> for InternalPk
Source§fn from(v: XOnlyPk) -> InternalPk
fn from(v: XOnlyPk) -> InternalPk
Source§impl From<XOnlyPk> for XOnlyPublicKey
impl From<XOnlyPk> for XOnlyPublicKey
Source§fn from(wrapped: XOnlyPk) -> XOnlyPublicKey
fn from(wrapped: XOnlyPk) -> XOnlyPublicKey
Source§impl From<XOnlyPublicKey> for XOnlyPk
impl From<XOnlyPublicKey> for XOnlyPk
Source§fn from(v: XOnlyPublicKey) -> XOnlyPk
fn from(v: XOnlyPublicKey) -> XOnlyPk
Source§impl Ord for XOnlyPk
impl Ord for XOnlyPk
Source§impl PartialOrd for XOnlyPk
impl PartialOrd for XOnlyPk
Source§impl Serialize for XOnlyPk
impl Serialize for XOnlyPk
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl StrictDecode for XOnlyPk
impl StrictDecode for XOnlyPk
fn strict_decode(reader: &mut impl TypedRead) -> Result<XOnlyPk, DecodeError>
fn strict_read(reader: impl ReadRaw) -> Result<Self, DecodeError>
Source§impl StrictDumb for XOnlyPk
impl StrictDumb for XOnlyPk
fn strict_dumb() -> XOnlyPk
Source§impl StrictEncode for XOnlyPk
impl StrictEncode for XOnlyPk
fn strict_encode<W>(&self, writer: W) -> Result<W, Error>where
W: TypedWrite,
fn strict_write(&self, writer: impl WriteRaw) -> Result<(), Error>
Source§impl StrictTuple for XOnlyPk
impl StrictTuple for XOnlyPk
const FIELD_COUNT: u8 = 1u8
fn strict_check_fields()
fn strict_type_info() -> TypeInfo<Self>
Source§impl StrictType for XOnlyPk
impl StrictType for XOnlyPk
const STRICT_LIB_NAME: &'static str = LIB_NAME_BITCOIN
fn strict_name() -> Option<TypeName>
Source§impl Wrapper for XOnlyPk
impl Wrapper for XOnlyPk
Source§type Inner = XOnlyPublicKey
type Inner = XOnlyPublicKey
Source§fn from_inner(inner: <XOnlyPk as Wrapper>::Inner) -> XOnlyPk
fn from_inner(inner: <XOnlyPk as Wrapper>::Inner) -> XOnlyPk
Source§fn as_inner(&self) -> &<XOnlyPk as Wrapper>::Inner
fn as_inner(&self) -> &<XOnlyPk as Wrapper>::Inner
Source§fn into_inner(self) -> <XOnlyPk as Wrapper>::Inner
fn into_inner(self) -> <XOnlyPk as Wrapper>::Inner
Source§impl WrapperMut for XOnlyPk
impl WrapperMut for XOnlyPk
impl Copy for XOnlyPk
impl Eq for XOnlyPk
impl StrictProduct for XOnlyPk
impl StructuralPartialEq for XOnlyPk
Auto Trait Implementations§
impl Freeze for XOnlyPk
impl RefUnwindSafe for XOnlyPk
impl Send for XOnlyPk
impl Sync for XOnlyPk
impl Unpin for XOnlyPk
impl UnwindSafe for XOnlyPk
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.