Struct secp256kfun::XOnly[][src]

pub struct XOnly(_);
Expand description

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

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());

Convenience method for calling from_bytes on a slice. Returns None if the length of the slice is not 32.

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());

Returns a reference to the internal 32-byte slice.

Converts an XOnly into a 32-byte array.

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();

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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

Deserialize this value from the given Serde deserializer. Read more

Displays as hex.

Performs the conversion.

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

The associated error which can be returned from parsing.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Asks the item to convert itself to bytes and add itself to hash.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Returns a new instance of the invocant that will be marked with M. Read more

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.