From 8b101d67c4408c1191dd0bb1ace2b9bc50b37553 Mon Sep 17 00:00:00 2001 From: David Nevado Date: Sat, 12 Mar 2022 15:46:43 +0100 Subject: [PATCH] Add `Coordinates` constructor --- src/arithmetic/curves.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/arithmetic/curves.rs b/src/arithmetic/curves.rs index ca94e58..44eced6 100644 --- a/src/arithmetic/curves.rs +++ b/src/arithmetic/curves.rs @@ -140,6 +140,11 @@ pub struct Coordinates { #[cfg(feature = "alloc")] impl Coordinates { + /// 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 { + // 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`.