Merge pull request #34 from davidnevadoc/coordinates-pub

Add constructor for `Coordinates`
This commit is contained in:
Daira Hopwood 2022-03-24 11:19:46 +00:00 committed by GitHub
commit cc57a3b75b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -140,6 +140,11 @@ pub struct Coordinates<C: CurveAffine> {
#[cfg(feature = "alloc")]
impl<C: CurveAffine> Coordinates<C> {
/// Obtains a `Coordinates` value given $(x, y)$, failing if it is not on the curve.
pub fn from_xy(x: C::Base, y: C::Base) -> CtOption<Self> {
// We use CurveAffine::from_xy to validate the coordinates.
C::from_xy(x, y).map(|_| Coordinates { x, y })
}
/// Returns the x-coordinate.
///
/// Equivalent to `Coordinates::u`.