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