@@ -9,49 +9,59 @@ use std::ops::{Add, Mul};
99use super :: { BaseFieldElement , ScalarFieldElement } ;
1010use crate :: { StmResult , signature_scheme:: SchnorrSignatureError } ;
1111
12+ /// Represents a point in affine coordinates on the Jubjub curve
1213#[ derive( Clone ) ]
1314pub ( crate ) struct AffinePoint ( JubjubAffinePoint ) ;
1415
1516impl AffinePoint {
17+ /// Converts a projective point to its affine representation
1618 pub ( crate ) fn from_projective_point ( projective_point : ProjectivePoint ) -> Self {
1719 AffinePoint ( JubjubAffinePoint :: from ( projective_point. 0 ) )
1820 }
1921
22+ /// Retrieves the u-coordinate of the affine point
2023 pub ( crate ) fn get_u ( & self ) -> BaseFieldElement {
2124 BaseFieldElement ( self . 0 . get_u ( ) )
2225 }
2326
27+ /// Retrieves the v-coordinate of the affine point
2428 pub ( crate ) fn get_v ( & self ) -> BaseFieldElement {
2529 BaseFieldElement ( self . 0 . get_v ( ) )
2630 }
2731}
2832
2933impl From < & PrimeOrderProjectivePoint > for AffinePoint {
34+ /// Converts a prime order projective point to its affine representation
3035 fn from ( prime_order_projective_point : & PrimeOrderProjectivePoint ) -> Self {
3136 AffinePoint ( JubjubAffinePoint :: from ( JubjubExtended :: from (
3237 prime_order_projective_point. 0 ,
3338 ) ) )
3439 }
3540}
3641
42+ /// Represents a point in projective coordinates on the Jubjub curve
3743#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
3844pub ( crate ) struct ProjectivePoint ( pub ( crate ) JubjubExtended ) ;
3945
4046impl ProjectivePoint {
47+ /// Hashes input bytes to a projective point on the Jubjub curve
4148 pub ( crate ) fn hash_to_projective_point ( input : & [ u8 ] ) -> Self {
4249 ProjectivePoint ( JubjubExtended :: hash_to_point ( input) )
4350 }
4451
52+ /// Retrieves the (u, v) coordinates of the projective point in affine representation
4553 pub ( crate ) fn get_coordinates ( & self ) -> ( BaseFieldElement , BaseFieldElement ) {
4654 let affine_point = AffinePoint :: from_projective_point ( * self ) ;
4755
4856 ( affine_point. get_u ( ) , affine_point. get_v ( ) )
4957 }
5058
59+ /// Converts the projective point to its byte representation
5160 pub ( crate ) fn to_bytes ( self ) -> [ u8 ; 32 ] {
5261 self . 0 . to_bytes ( )
5362 }
5463
64+ /// Constructs a projective point from its byte representation
5565 pub ( crate ) fn from_bytes ( bytes : & [ u8 ] ) -> StmResult < Self > {
5666 let mut projective_point_bytes = [ 0u8 ; 32 ] ;
5767 projective_point_bytes
@@ -63,6 +73,7 @@ impl ProjectivePoint {
6373 }
6474 }
6575
76+ /// Checks if the projective point is of prime order
6677 pub ( crate ) fn is_prime_order ( self ) -> bool {
6778 self . 0 . is_prime_order ( ) . into ( )
6879 }
@@ -71,6 +82,7 @@ impl ProjectivePoint {
7182impl Add for ProjectivePoint {
7283 type Output = ProjectivePoint ;
7384
85+ /// Adds two projective points
7486 fn add ( self , other : ProjectivePoint ) -> ProjectivePoint {
7587 ProjectivePoint ( self . 0 + other. 0 )
7688 }
@@ -79,26 +91,31 @@ impl Add for ProjectivePoint {
7991impl Mul < ProjectivePoint > for ScalarFieldElement {
8092 type Output = ProjectivePoint ;
8193
94+ /// Multiplies a projective point by a scalar field element
95+ /// Returns the resulting projective point
8296 fn mul ( self , point : ProjectivePoint ) -> ProjectivePoint {
8397 ProjectivePoint ( point. 0 * self . 0 )
8498 }
8599}
86100
87101impl From < PrimeOrderProjectivePoint > for ProjectivePoint {
102+ /// Converts a prime order projective point to a projective point
88103 fn from ( prime_order_projective_point : PrimeOrderProjectivePoint ) -> Self {
89104 ProjectivePoint ( JubjubExtended :: from ( prime_order_projective_point. 0 ) )
90105 }
91106}
92107
108+ /// Represents a point of prime order in projective coordinates on the Jubjub curve
93109#[ derive( Debug , Clone , Copy , Default , PartialEq , Eq ) ]
94110pub ( crate ) struct PrimeOrderProjectivePoint ( pub ( crate ) JubjubSubgroup ) ;
95111
96112impl PrimeOrderProjectivePoint {
113+ /// Creates the generator point of the prime order subgroup
97114 pub ( crate ) fn create_generator ( ) -> Self {
98115 PrimeOrderProjectivePoint ( JubjubSubgroup :: generator ( ) )
99116 }
100117
101- /// Check if the given point is on the curve using its coordinates
118+ /// Checks if the given point is on the curve using its coordinates
102119 pub ( crate ) fn is_on_curve ( & self ) -> StmResult < PrimeOrderProjectivePoint > {
103120 let point_affine_representation = AffinePoint :: from ( self ) ;
104121 let ( x, y) = (
@@ -119,10 +136,12 @@ impl PrimeOrderProjectivePoint {
119136 Ok ( * self )
120137 }
121138
139+ /// Converts the prime order projective point to its byte representation
122140 pub ( crate ) fn to_bytes ( self ) -> [ u8 ; 32 ] {
123141 self . 0 . to_bytes ( )
124142 }
125143
144+ /// Constructs a prime order projective point from its byte representation
126145 pub ( crate ) fn from_bytes ( bytes : & [ u8 ] ) -> StmResult < Self > {
127146 let mut prime_order_projective_point_bytes = [ 0u8 ; 32 ] ;
128147 prime_order_projective_point_bytes
@@ -140,6 +159,7 @@ impl PrimeOrderProjectivePoint {
140159impl Add for PrimeOrderProjectivePoint {
141160 type Output = PrimeOrderProjectivePoint ;
142161
162+ /// Adds two prime order projective points
143163 fn add ( self , other : PrimeOrderProjectivePoint ) -> PrimeOrderProjectivePoint {
144164 PrimeOrderProjectivePoint ( self . 0 + other. 0 )
145165 }
@@ -148,6 +168,8 @@ impl Add for PrimeOrderProjectivePoint {
148168impl Mul < PrimeOrderProjectivePoint > for ScalarFieldElement {
149169 type Output = PrimeOrderProjectivePoint ;
150170
171+ /// Multiplies a prime order projective point by a scalar field element
172+ /// Returns the resulting prime order projective point
151173 fn mul ( self , point : PrimeOrderProjectivePoint ) -> PrimeOrderProjectivePoint {
152174 PrimeOrderProjectivePoint ( point. 0 * self . 0 )
153175 }
0 commit comments