Explorar el Código

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

parazyd hace 4 años
padre
commit
4d5e6fef10
Se han modificado 1 ficheros con 10 adiciones y 1 borrados
  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 pasta_curves::{
+    arithmetic::CurveAffine,
     group::{
         ff::{Field, PrimeField},
-        Group, GroupEncoding,
+        Curve, Group, GroupEncoding,
     },
     pallas,
 };
@@ -82,6 +83,14 @@ impl PublicKey {
             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 {