Skip to main content

Point

Struct Point 

Source
pub struct Point {
    pub x: BigNumber,
    pub y: BigNumber,
    pub inf: bool,
}
Expand description

A point on the secp256k1 curve in affine coordinates (x, y).

The point at infinity is represented by inf == true (x and y are zero).

Fields§

§x: BigNumber

The x-coordinate.

§y: BigNumber

The y-coordinate.

§inf: bool

Whether this is the point at infinity.

Implementations§

Source§

impl Point

Source

pub fn new(x: BigNumber, y: BigNumber) -> Self

Create a new point from x, y coordinates.

Source

pub fn infinity() -> Self

Create the point at infinity (identity element).

Source

pub fn is_infinity(&self) -> bool

Check if this is the point at infinity.

Source

pub fn validate(&self) -> bool

Validate that this point lies on the secp256k1 curve. Returns true if y^2 = x^3 + 7 (mod p).

Source

pub fn from_x(x: &BigNumber, odd: bool) -> Result<Self, PrimitivesError>

Recover a point from its x coordinate and y-parity. odd = true means y should be odd.

Source

pub fn from_der(bytes: &[u8]) -> Result<Self, PrimitivesError>

Parse a point from DER-encoded bytes (compressed or uncompressed).

Compressed format: 0x02/0x03 || x (33 bytes total) Uncompressed format: 0x04 || x || y (65 bytes total)

Source

pub fn from_string(hex: &str) -> Result<Self, PrimitivesError>

Parse a point from a hex string (DER encoded).

Source

pub fn to_der(&self, compressed: bool) -> Vec<u8>

Encode this point to DER format.

Compressed (33 bytes): 0x02/0x03 || x Uncompressed (65 bytes): 0x04 || x || y

Source

pub fn to_hex(&self) -> String

Encode to hex string (compressed DER).

Source

pub fn add(&self, other: &Point) -> Point

Add two points.

Source

pub fn mul(&self, k: &BigNumber) -> Point

Scalar multiplication: self * k.

Source

pub fn negate(&self) -> Point

Negate a point (same x, y = p - y).

Source

pub fn eq(&self, other: &Point) -> bool

Check equality of two points.

Source

pub fn dbl(&self) -> Point

Double this point (P + P = 2P).

Source

pub fn get_x(&self) -> BigNumber

Get x coordinate (clone).

Source

pub fn get_y(&self) -> BigNumber

Get y coordinate (clone).

Trait Implementations§

Source§

impl Clone for Point

Source§

fn clone(&self) -> Point

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Point

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Point

§

impl !RefUnwindSafe for Point

§

impl Send for Point

§

impl Sync for Point

§

impl Unpin for Point

§

impl UnsafeUnpin for Point

§

impl !UnwindSafe for Point

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.