serialize pubkey

This commit is contained in:
kilic
2024-08-02 16:46:09 +03:00
parent 27f3058df3
commit 0a81df83b0

View File

@@ -51,6 +51,17 @@ impl<TE: TECurveConfig> PublicKey<TE> {
pub fn xy(&self) -> (&TE::BaseField, &TE::BaseField) { pub fn xy(&self) -> (&TE::BaseField, &TE::BaseField) {
self.as_ref().xy().unwrap() self.as_ref().xy().unwrap()
} }
pub fn to_bytes(&self) -> Vec<u8> {
let mut bytes = Vec::new();
self.serialize_compressed(&mut bytes).unwrap();
bytes
}
pub fn from_bytes(bytes: &[u8]) -> Result<Self, Box<dyn ark_std::error::Error>> {
let point = Affine::<TE>::deserialize_compressed(bytes)?;
Ok(Self(point))
}
} }
impl<TE: TECurveConfig> From<Affine<TE>> for PublicKey<TE> { impl<TE: TECurveConfig> From<Affine<TE>> for PublicKey<TE> {