Add Coordinates constructor

This commit is contained in:
David Nevado 2022-03-12 15:46:43 +01:00
parent 8a3643682f
commit 8b101d67c4
No known key found for this signature in database
GPG key ID: 30807CB0B8A17E6C

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`.