[][src]Struct secp256kfun::XOnly

pub struct XOnly(_);

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]

pub 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]

impl Display for XOnly[src]

pub fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Displays as hex.

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.

pub 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]

impl HashInto for XOnly[src]

impl<T, Z, S> PartialEq<Point<T, S, Z>> for XOnly[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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Mark for T[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.