From a6da0223557c5756092be84b95d7a9f6c6f4ad00 Mon Sep 17 00:00:00 2001 From: Federica Date: Tue, 2 Jan 2024 16:49:43 -0300 Subject: [PATCH] Add methods from_affine & double to ProjectivePoint --- crates/starknet-types-core/Cargo.toml | 2 +- .../src/curve/projective_point.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/starknet-types-core/Cargo.toml b/crates/starknet-types-core/Cargo.toml index 01a451e..1b81280 100644 --- a/crates/starknet-types-core/Cargo.toml +++ b/crates/starknet-types-core/Cargo.toml @@ -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 } diff --git a/crates/starknet-types-core/src/curve/projective_point.rs b/crates/starknet-types-core/src/curve/projective_point.rs index 5d174fb..f5c1d39 100644 --- a/crates/starknet-types-core/src/curve/projective_point.rs +++ b/crates/starknet-types-core/src/curve/projective_point.rs @@ -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. @@ -33,6 +34,13 @@ impl ProjectivePoint { Ok(AffinePoint(self.0.to_affine())) } + pub fn from_affine(x: Felt, y: Felt) -> Result { + 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()) @@ -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 {