-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement starknet_core_types::curve module (#8)
- Loading branch information
Showing
14 changed files
with
338 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
[workspace] | ||
members = [ | ||
"crates/stark-felt", | ||
"crates/starknet-types-core", | ||
"crates/starknet-types-rpc", | ||
] | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,31 @@ | ||
[package] | ||
name = "starknet-types-core" | ||
version = "0.0.2" | ||
version = "0.0.3" | ||
edition = "2021" | ||
license = "MIT" | ||
homepage = "https://github.com/starknet-io/types-rs" | ||
repository = "https://github.com/starknet-io/types-rs" | ||
categories = ["types", "math", "crypto"] | ||
keywords = ["stark", "zkp", "cairo"] | ||
description = "Starknet core types." | ||
description = "Core types representation for Starknet" | ||
readme = "README.md" | ||
|
||
[dependencies] | ||
bitvec = { version = "1.0.1", default-features = false } | ||
serde = { version = "1.0.163", optional = true, default-features = false } | ||
lambdaworks-math = { git = "https://github.com/lambdaclass/lambdaworks.git", rev = "f940e14ed17370d29fe129951448037d11b65ce8", default-features = false} | ||
|
||
|
||
arbitrary = { version = "1.3.0", optional = true, default-features = false } | ||
num-traits = { version = "0.2.16", default-features = false } | ||
|
||
[features] | ||
default = ["std", "serde", "curve"] | ||
curve = [] | ||
std = [] | ||
alloc = ["serde?/alloc"] | ||
arbitrary = ["std", "dep:arbitrary"] | ||
|
||
[dev-dependencies] | ||
proptest = "1.1.0" | ||
serde_test = "1.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use crate::curve::curve_errors::CurveError; | ||
use crate::felt::Felt; | ||
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::FromAffine; | ||
|
||
/// Represents a point on the Stark elliptic curve. | ||
/// Doc: https://docs.starkware.co/starkex/crypto/stark-curve.html | ||
#[repr(transparent)] | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct AffinePoint(pub(crate) ShortWeierstrassProjectivePoint<StarkCurve>); | ||
|
||
impl AffinePoint { | ||
pub fn new(x: Felt, y: Felt) -> Result<AffinePoint, CurveError> { | ||
Ok(Self(ShortWeierstrassProjectivePoint::from_affine( | ||
x.0, y.0, | ||
)?)) | ||
} | ||
|
||
/// The point at infinity. | ||
pub fn identity() -> AffinePoint { | ||
Self(ShortWeierstrassProjectivePoint::neutral_element()) | ||
} | ||
|
||
/// Returns the `x` coordinate of the point. | ||
pub fn x(&self) -> Felt { | ||
Felt(*self.0.x()) | ||
} | ||
|
||
/// Returns the `y` coordinate of the point. | ||
pub fn y(&self) -> Felt { | ||
Felt(*self.0.y()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn affine_point_identity() { | ||
let identity = AffinePoint::identity(); | ||
|
||
assert_eq!(identity.x(), Felt::from(0)); | ||
assert_eq!(identity.y(), Felt::from(1)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use core::fmt::Debug; | ||
use lambdaworks_math::elliptic_curve::traits::EllipticCurveError; | ||
|
||
#[derive(Debug, PartialEq, Eq)] | ||
pub enum CurveError { | ||
EllipticCurveError(EllipticCurveError), | ||
} | ||
|
||
impl From<EllipticCurveError> for CurveError { | ||
fn from(error: EllipticCurveError) -> CurveError { | ||
CurveError::EllipticCurveError(error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mod affine_point; | ||
mod curve_errors; | ||
mod projective_point; | ||
|
||
pub use self::affine_point::*; | ||
pub use self::curve_errors::*; | ||
pub use self::projective_point::*; |
Oops, something went wrong.