Skip to content

Commit

Permalink
implement x(), y(), z() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pefontana committed Oct 23, 2023
1 parent a7bf4eb commit c9a337b
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion crates/starknet-types-core/src/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use lambdaworks_math::cyclic_group::IsGroup;
use lambdaworks_math::elliptic_curve::short_weierstrass::curves::stark_curve::StarkCurve;
use lambdaworks_math::elliptic_curve::short_weierstrass::point::ShortWeierstrassProjectivePoint;
use lambdaworks_math::elliptic_curve::traits::{EllipticCurveError, FromAffine};

use lambdaworks_math::field::element::FieldElement;
use lambdaworks_math::field::fields::fft_friendly::stark_252_prime_field::Stark252PrimeField;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProjectivePoint(ShortWeierstrassProjectivePoint<StarkCurve>);

Expand All @@ -28,6 +29,21 @@ impl ProjectivePoint {
*projective_point.0.y(),
)?))
}

/// Returns the `x` coordinate of the point.
pub fn x(&self) -> &FieldElement<Stark252PrimeField> {
self.0.y()
}

/// Returns the `y` coordinate of the point.
pub fn y(&self) -> &FieldElement<Stark252PrimeField> {
self.0.y()
}

/// Returns the `z` coordinate of the point.
pub fn z(&self) -> &FieldElement<Stark252PrimeField> {
self.0.y()
}
}

impl ops::Add<&ProjectivePoint> for &ProjectivePoint {
Expand All @@ -50,6 +66,20 @@ impl AffinePoint {
x.0, y.0,
)?))
}

pub fn identity() -> AffinePoint {
Self(ShortWeierstrassProjectivePoint::neutral_element())
}

/// Returns the `x` coordinate of the point.
pub fn x(&self) -> &FieldElement<Stark252PrimeField> {
self.0.y()
}

/// Returns the `y` coordinate of the point.
pub fn y(&self) -> &FieldElement<Stark252PrimeField> {
self.0.y()
}
}

impl ops::Add<&AffinePoint> for &AffinePoint {
Expand Down

0 comments on commit c9a337b

Please sign in to comment.