Struct secp256kfun::XOnly [−][src]
An XOnly
is the compressed representation of a Point<EvenY,S,Z>
which
only stores the x-coordinate of the point.
Using a Point<EvenY,..>
is usually the right choice as it serializes the
same way and can do everything an XOnly
can do and more. XOnly
exists
because sometimes all you need is the x-coordinate and you don’t want to
store the full point in memory.
Implementations
impl XOnly
[src]
pub fn from_bytes(bytes: [u8; 32]) -> Option<Self>
[src]
Converts a 32-byte big-endian encoded x-coordinate into an
XOnly
. Returns None
if the bytes do not represent a valid
x-coordinate on the curve.
Example
use secp256kfun::{marker::*, XOnly}; // note: x = 1 is on the curve. // choose the even y-corrdinate when decompressing assert!(XOnly::from_bytes([1u8; 32]).is_some());
pub fn from_slice(slice: &[u8]) -> Option<Self>
[src]
Convenience method for calling from_bytes
on a slice. Returns None
if the length of the slice is not 32.
pub fn random<R: RngCore + CryptoRng>(rng: &mut R) -> Self
[src]
Generates a random valid XOnly
from a random number generator.
Example
use secp256kfun::{marker::*, XOnly}; let random_x_coordinate = XOnly::random(&mut rand::thread_rng());
pub fn as_bytes(&self) -> &[u8; 32]
[src]
Returns a reference to the internal 32-byte slice.
pub fn into_bytes(self) -> [u8; 32]
[src]
Converts an XOnly
into a 32-byte array.
impl XOnly
[src]
pub fn to_point(&self) -> Point<EvenY, Public, NonZero>
[src]
Decompresses a XOnly
into a Point<EvenY,Public,NonZero>
.
The resulting point will have an even y-coordinate.
Example
use secp256kfun::{marker::*, XOnly}; let xonly = XOnly::random(&mut rand::thread_rng()); // get the point with a even y-coordinate let point_even_y = xonly.to_point();
pub fn from_scalar_mul<GT>(G: &Point<GT>, x: &mut Scalar<impl Secrecy>) -> Self
[src]
Multiplies G
by x
and then compresses the point to an XOnly
.
x
is mutable because it will be negated if, after the
multiplication, the resulting point doesn’t match Y
(negating it
ensures that it does).
Example
use secp256kfun::{marker::*, Scalar, XOnly, G}; use std::str::FromStr; let original = Scalar::<Secret>::from_str( "ee673d13de31533a375b41d9e57731d9bb4dbddbd6c1d2364f15be40fd783346", ) .unwrap(); let mut secret_key = original.clone(); let xonly_public_key = XOnly::from_scalar_mul(G, &mut secret_key); assert_ne!(secret_key, original); assert_eq!(-secret_key, original);
Trait Implementations
impl Clone for XOnly
[src]
impl Copy for XOnly
[src]
impl Debug for XOnly
[src]
fn fmt(&self, f: &mut Formatter<'_>) -> Result
[src]
Formats the type as hex and any markers on the type.
impl<'de> Deserialize<'de> for XOnly
[src]
fn deserialize<Deser: Deserializer<'de>>(
deserializer: Deser
) -> Result<XOnly, Deser::Error>
[src]
deserializer: Deser
) -> Result<XOnly, Deser::Error>
impl Display for XOnly
[src]
impl Eq for XOnly
[src]
impl From<XOnly> for Point<EvenY, Public, NonZero>
[src]
impl FromStr for XOnly
[src]
type Err = HexError
The associated error which can be returned from parsing.
fn from_str(hex: &str) -> Result<XOnly, HexError>
[src]
Parses the string as hex and interprets tries to convert the resulting byte array into the desired value.
impl Hash for XOnly
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl HashInto for XOnly
[src]
impl<T, Z, S> PartialEq<Point<T, S, Z>> for XOnly
[src]
fn eq(&self, rhs: &Point<T, S, Z>) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<XOnly> for XOnly
[src]
impl<T, Z, S> PartialEq<XOnly> for Point<T, S, Z>
[src]
impl Serialize for XOnly
[src]
impl StructuralEq for XOnly
[src]
Auto Trait Implementations
impl RefUnwindSafe for XOnly
impl Send for XOnly
impl Sync for XOnly
impl Unpin for XOnly
impl UnwindSafe for XOnly
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Mark for T
[src]
#[must_use]pub fn mark<M>(Self) -> <M as ChangeMark<T>>::Out where
M: ChangeMark<T>,
[src]
M: ChangeMark<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,