Skip to main content

fedimint_core/bls12_381_serde/
g1.rs

1use bls12_381::G1Affine;
2use serde::de::Error;
3use serde::{Deserializer, Serializer};
4
5pub fn serialize<S: Serializer>(point: &G1Affine, s: S) -> Result<S::Ok, S::Error> {
6    serdect::array::serialize_hex_lower_or_bin(&point.to_compressed(), s)
7}
8
9pub fn deserialize<'d, D: Deserializer<'d>>(d: D) -> Result<G1Affine, D::Error> {
10    let mut byte_array = [0; 48];
11
12    serdect::array::deserialize_hex_or_bin(&mut byte_array, d)?;
13
14    Option::from(G1Affine::from_compressed(&byte_array))
15        .ok_or_else(|| Error::custom("Could not decode compressed group element"))
16}