[−][src]Struct secp256kfun::XOnly
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
fn change_mark(xonly: XOnly<Y>) -> Self::Out
[src]
impl<Y> ChangeMark<XOnly<Y>> for ()
[src]
type Out = XOnly<()>
The result type of marking T
with Self
fn change_mark(xonly: XOnly<Y>) -> Self::Out
[src]
impl<YChoice: Clone> Clone for XOnly<YChoice>
[src]
impl<Y> Debug for XOnly<Y>
[src]
impl<'de, Y> Deserialize<'de> for XOnly<Y>
[src]
fn deserialize<Deser: Deserializer<'de>>(
deserializer: Deser
) -> Result<XOnly<Y>, Deser::Error>
[src]
deserializer: Deser
) -> Result<XOnly<Y>, Deser::Error>
impl<Y> Display for XOnly<Y>
[src]
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]
fn eq(&self, rhs: &Point<T, S, Z>) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T, Z, S> PartialEq<XOnly<SquareY>> for Point<T, S, Z>
[src]
fn eq(&self, rhs: &XOnly<SquareY>) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[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,
YChoice: RefUnwindSafe,
impl<YChoice> Send for XOnly<YChoice> where
YChoice: Send,
YChoice: Send,
impl<YChoice> Sync for XOnly<YChoice> where
YChoice: Sync,
YChoice: Sync,
impl<YChoice> Unpin for XOnly<YChoice> where
YChoice: Unpin,
YChoice: Unpin,
impl<YChoice> UnwindSafe for XOnly<YChoice> where
YChoice: UnwindSafe,
YChoice: UnwindSafe,
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,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<Y, YNew> ChangeMark<XOnly<Y>> for YNew where
YNew: YChoice,
[src]
YNew: YChoice,
type Out = XOnly<YNew>
The result type of marking T
with Self
fn change_mark(XOnly<Y>) -> <YNew as ChangeMark<XOnly<Y>>>::Out
[src]
impl<Y, YNew> ChangeMark<XOnly<Y>> for YNew where
YNew: YChoice,
[src]
YNew: YChoice,
type Out = XOnly<YNew>
The result type of marking T
with Self
fn change_mark(XOnly<Y>) -> <YNew as ChangeMark<XOnly<Y>>>::Out
[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]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.
fn to_owned(&self) -> T
[src]
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.
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>,