zebra_chain/serialization/
serde_helpers.rs
1use group::{ff::PrimeField, GroupEncoding};
2use halo2::pasta::pallas;
3#[derive(Deserialize, Serialize)]
4#[serde(remote = "jubjub::AffinePoint")]
5pub struct AffinePoint {
6 #[serde(getter = "jubjub::AffinePoint::to_bytes")]
7 bytes: [u8; 32],
8}
9
10impl From<AffinePoint> for jubjub::AffinePoint {
11 fn from(local: AffinePoint) -> Self {
12 jubjub::AffinePoint::from_bytes(local.bytes).unwrap()
13 }
14}
15
16#[derive(Deserialize, Serialize)]
17#[serde(remote = "jubjub::Fq")]
18pub struct Fq {
19 #[serde(getter = "jubjub::Fq::to_bytes")]
20 bytes: [u8; 32],
21}
22
23impl From<Fq> for jubjub::Fq {
24 fn from(local: Fq) -> Self {
25 jubjub::Fq::from_bytes(&local.bytes).unwrap()
26 }
27}
28
29#[derive(Deserialize, Serialize)]
30#[serde(remote = "pallas::Affine")]
31pub struct Affine {
32 #[serde(getter = "pallas::Affine::to_bytes")]
33 bytes: [u8; 32],
34}
35
36impl From<Affine> for pallas::Affine {
37 fn from(local: Affine) -> Self {
38 pallas::Affine::from_bytes(&local.bytes).unwrap()
39 }
40}
41
42#[derive(Deserialize, Serialize)]
43#[serde(remote = "pallas::Scalar")]
44pub struct Scalar {
45 #[serde(getter = "pallas::Scalar::to_repr")]
46 bytes: [u8; 32],
47}
48
49impl From<Scalar> for pallas::Scalar {
50 fn from(local: Scalar) -> Self {
51 pallas::Scalar::from_repr(local.bytes).unwrap()
52 }
53}
54
55#[derive(Deserialize, Serialize)]
56#[serde(remote = "pallas::Base")]
57pub struct Base {
58 #[serde(getter = "pallas::Base::to_repr")]
59 bytes: [u8; 32],
60}
61
62impl From<Base> for pallas::Base {
63 fn from(local: Base) -> Self {
64 pallas::Base::from_repr(local.bytes).unwrap()
65 }
66}