Skip to content

Commit

Permalink
Add methods from_affine & double to ProjectivePoint
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoletta committed Jan 2, 2024
1 parent c7cf22e commit a6da022
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/starknet-types-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ readme = "README.md"

[dependencies]
bitvec = { version = "1.0.1", default-features = false }
lambdaworks-math = {version = "0.3.0", default-features = false}
lambdaworks-math = {git = "https://github.com/lambdaclass/lambdaworks.git", rev = "55731492f8d919523a692265b1c34e7ca6387a0d", default-features = false}

num-traits = { version = "0.2.16", default-features = false }
num-bigint = { version = "0.4.4", default-features = false }
Expand Down
12 changes: 12 additions & 0 deletions crates/starknet-types-core/src/curve/projective_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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::InvalidPoint;
use lambdaworks_math::elliptic_curve::traits::FromAffine;
use lambdaworks_math::unsigned_integer::traits::IsUnsignedInteger;

/// Represents a projective point on the Stark elliptic curve.
Expand Down Expand Up @@ -33,6 +34,13 @@ impl ProjectivePoint {
Ok(AffinePoint(self.0.to_affine()))
}

pub fn from_affine(x: Felt, y: Felt) -> Result<Self, CurveError> {
Ok(Self(
ShortWeierstrassProjectivePoint::from_affine(x.0, y.0)
.map_err(CurveError::EllipticCurveError)?,
))
}

/// Returns the `x` coordinate of the point.
pub fn x(&self) -> Felt {
Felt(*self.0.x())
Expand All @@ -47,6 +55,10 @@ impl ProjectivePoint {
pub fn z(&self) -> Felt {
Felt(*self.0.z())
}

pub fn double(&self) -> Self {
Self(self.0.double())
}
}

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

0 comments on commit a6da022

Please sign in to comment.