From 0a81df83b07de326013791829d9d6e01639fd51f Mon Sep 17 00:00:00 2001 From: kilic Date: Fri, 2 Aug 2024 16:46:09 +0300 Subject: [PATCH] serialize pubkey --- src/eddsa.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/eddsa.rs b/src/eddsa.rs index e83f68b..253d2ab 100644 --- a/src/eddsa.rs +++ b/src/eddsa.rs @@ -51,6 +51,17 @@ impl PublicKey { pub fn xy(&self) -> (&TE::BaseField, &TE::BaseField) { self.as_ref().xy().unwrap() } + + pub fn to_bytes(&self) -> Vec { + let mut bytes = Vec::new(); + self.serialize_compressed(&mut bytes).unwrap(); + bytes + } + + pub fn from_bytes(bytes: &[u8]) -> Result> { + let point = Affine::::deserialize_compressed(bytes)?; + Ok(Self(point)) + } } impl From> for PublicKey {