Browse Source

crypto/keypair: Add methods to get x and y from PublicKey.

parazyd 4 years ago
parent
commit
4d5e6fef10
1 changed files with 10 additions and 1 deletions
  1. 10 1
      src/crypto/keypair.rs

+ 10 - 1
src/crypto/keypair.rs

@@ -2,9 +2,10 @@ use std::{convert::TryFrom, io, str::FromStr};
 
 
 use halo2_gadgets::ecc::chip::FixedPoint;
 use halo2_gadgets::ecc::chip::FixedPoint;
 use pasta_curves::{
 use pasta_curves::{
+    arithmetic::CurveAffine,
     group::{
     group::{
         ff::{Field, PrimeField},
         ff::{Field, PrimeField},
-        Group, GroupEncoding,
+        Curve, Group, GroupEncoding,
     },
     },
     pallas,
     pallas,
 };
 };
@@ -82,6 +83,14 @@ impl PublicKey {
             None => Err(Error::PublicKeyFromBytes),
             None => Err(Error::PublicKeyFromBytes),
         }
         }
     }
     }
+
+    pub fn x(&self) -> pallas::Base {
+        *self.0.to_affine().coordinates().unwrap().x()
+    }
+
+    pub fn y(&self) -> pallas::Base {
+        *self.0.to_affine().coordinates().unwrap().y()
+    }
 }
 }
 
 
 impl FromStr for PublicKey {
 impl FromStr for PublicKey {