[][src]Struct secp256kfun::XOnly

pub struct XOnly<YChoice = ()>(_, _);

An XOnly<Y> is the compressed representation of a Point<T,S,Z> which only stores the x-coordinate of the point.

The type parameter Y determines how to decompress the x-only into a point. Y is always a YChoice or () if the y-coordinate is unspecified (in which case it can't be decompressed).

Instead of using an XOnly<Y> it is often more practical to use a Point<T,S,Z> where T is set to a YChoice. For example, a Point<EvenY,..> can do everything an XOnly<EvenY> 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<Y> XOnly<Y>[src]

pub fn from_bytes(bytes: [u8; 32]) -> Option<Self>[src]

Converts a 32-byte big-endian encoded x-coordinate into an XOnly<Y>. 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::<EvenY>::from_bytes([1u8; 32]).is_some());
// choose the squaure y-corrdinate when decompressing
assert!(XOnly::<SquareY>::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<Y> from a random number generator.

Example

use secp256kfun::{marker::*, XOnly};
let random_x_coordinate = XOnly::<EvenY>::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<Y: YChoice> XOnly<Y>[src]

pub fn to_point(&self) -> Point<Y, Public, NonZero>[src]

Decompresses a XOnly<Y: YChoice> into a [Point<Y,Public,NonZero>]. The resulting point will have its y-coordinate chosen depending on Y and is marked as such.

Example

use secp256kfun::{marker::*, XOnly};
let xonly = XOnly::<EvenY>::random(&mut rand::thread_rng());
// get the point with a even y-coordinate
let point_even_y = xonly.to_point();
// get the point with a square y-coordinate
let point_square_y = xonly.mark::<SquareY>().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<Y: YChoice>. 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::<EvenY>::from_scalar_mul(G, &mut secret_key);
assert_ne!(secret_key, original);
assert_eq!(-secret_key, original);

Trait Implementations

impl<Y, YNew: YChoice> ChangeMark<XOnly<Y>> for YNew[src]

type Out = XOnly<YNew>

The result type of marking T with Self

impl<Y> ChangeMark<XOnly<Y>> for ()[src]

type Out = XOnly<()>

The result type of marking T with Self

impl<YChoice: Clone> Clone for XOnly<YChoice>[src]

impl<Y> Debug for XOnly<Y>[src]

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

Formats the type as hex and any markers on the type.

impl<'de, Y> Deserialize<'de> for XOnly<Y>[src]

impl<Y> Display for XOnly<Y>[src]

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

Displays as hex.

impl<Y: YChoice> From<XOnly<Y>> for Point<Y, Public, NonZero>[src]

impl<Y> FromStr for XOnly<Y>[src]

type Err = HexError

The associated error which can be returned from parsing.

fn from_str(hex: &str) -> Result<XOnly<Y>, HexError>[src]

Parses the string as hex and interprets tries to convert the resulting byte array into the desired value.

impl<Y> HashInto for XOnly<Y>[src]

impl<T, Z, S> PartialEq<Point<T, S, Z>> for XOnly<SquareY>[src]

impl<T, Z, S> PartialEq<XOnly<SquareY>> for Point<T, S, Z>[src]

impl<Y> PartialEq<XOnly<Y>> for XOnly<Y>[src]

impl<Y> Serialize for XOnly<Y>[src]

Auto Trait Implementations

impl<YChoice> RefUnwindSafe for XOnly<YChoice> where
    YChoice: RefUnwindSafe

impl<YChoice> Send for XOnly<YChoice> where
    YChoice: Send

impl<YChoice> Sync for XOnly<YChoice> where
    YChoice: Sync

impl<YChoice> Unpin for XOnly<YChoice> where
    YChoice: Unpin

impl<YChoice> UnwindSafe for XOnly<YChoice> where
    YChoice: UnwindSafe

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<Y, YNew> ChangeMark<XOnly<Y>> for YNew where
    YNew: YChoice
[src]

type Out = XOnly<YNew>

The result type of marking T with Self

impl<Y, YNew> ChangeMark<XOnly<Y>> for YNew where
    YNew: YChoice
[src]

type Out = XOnly<YNew>

The result type of marking T with Self

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.