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());
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
Auto Trait Implementations
impl RefUnwindSafe for XOnly
impl UnwindSafe for XOnly
Blanket Implementations
Mutably borrows from an owned value. Read more
Returns a new instance of the invocant that will be marked with M
. Read more
type Output = T
type Output = T
Should always be Self