forest/lotus_json/
signature.rs1use super::*;
5use crate::shim::crypto::{Signature, SignatureType};
6
7#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
8#[serde(rename_all = "PascalCase")]
9#[schemars(rename = "Signature")]
10pub struct SignatureLotusJson {
11 #[schemars(with = "LotusJson<SignatureType>")]
12 #[serde(with = "crate::lotus_json")]
13 r#type: SignatureType,
14 #[schemars(with = "LotusJson<Vec<u8>>")]
15 #[serde(with = "crate::lotus_json")]
16 data: Vec<u8>,
17}
18
19#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
20#[serde(rename_all = "PascalCase")]
21#[schemars(rename = "Signature")]
22pub struct SignatureV2LotusJson {
23 #[schemars(with = "LotusJson<fvm_shared2::crypto::signature::SignatureType>")]
24 #[serde(with = "crate::lotus_json")]
25 r#type: fvm_shared2::crypto::signature::SignatureType,
26 #[schemars(with = "LotusJson<Vec<u8>>")]
27 #[serde(with = "crate::lotus_json")]
28 data: Vec<u8>,
29}
30
31#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
32#[serde(rename_all = "PascalCase")]
33#[schemars(rename = "Signature")]
34pub struct SignatureV3LotusJson {
35 #[schemars(with = "LotusJson<fvm_shared3::crypto::signature::SignatureType>")]
36 #[serde(with = "crate::lotus_json")]
37 r#type: fvm_shared3::crypto::signature::SignatureType,
38 #[schemars(with = "LotusJson<Vec<u8>>")]
39 #[serde(with = "crate::lotus_json")]
40 data: Vec<u8>,
41}
42
43#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
44#[serde(rename_all = "PascalCase")]
45#[schemars(rename = "Signature")]
46pub struct SignatureV4LotusJson {
47 #[schemars(with = "LotusJson<fvm_shared4::crypto::signature::SignatureType>")]
48 #[serde(with = "crate::lotus_json")]
49 r#type: fvm_shared4::crypto::signature::SignatureType,
50 #[schemars(with = "LotusJson<Vec<u8>>")]
51 #[serde(with = "crate::lotus_json")]
52 data: Vec<u8>,
53}
54
55impl HasLotusJson for Signature {
56 type LotusJson = SignatureLotusJson;
57
58 #[cfg(test)]
59 fn snapshots() -> Vec<(serde_json::Value, Self)> {
60 vec![(
61 json!({"Type": 2, "Data": "aGVsbG8gd29ybGQh"}),
62 Signature {
63 sig_type: crate::shim::crypto::SignatureType::Bls,
64 bytes: Vec::from_iter(*b"hello world!"),
65 },
66 )]
67 }
68
69 fn into_lotus_json(self) -> Self::LotusJson {
70 let Self { sig_type, bytes } = self;
71 Self::LotusJson {
72 r#type: sig_type,
73 data: bytes,
74 }
75 }
76
77 fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
78 let Self::LotusJson { r#type, data } = lotus_json;
79 Self {
80 sig_type: r#type,
81 bytes: data,
82 }
83 }
84}
85
86impl HasLotusJson for fvm_shared2::crypto::signature::Signature {
87 type LotusJson = SignatureV2LotusJson;
88
89 #[cfg(test)]
90 fn snapshots() -> Vec<(serde_json::Value, Self)> {
91 vec![(
92 json!({"Type": 2, "Data": "aGVsbG8gd29ybGQh"}),
93 Self {
94 sig_type: fvm_shared2::crypto::signature::SignatureType::BLS,
95 bytes: Vec::from_iter(*b"hello world!"),
96 },
97 )]
98 }
99
100 fn into_lotus_json(self) -> Self::LotusJson {
101 SignatureV2LotusJson {
102 r#type: self.sig_type,
103 data: self.bytes,
104 }
105 }
106
107 fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
108 Self {
109 sig_type: lotus_json.r#type,
110 bytes: lotus_json.data,
111 }
112 }
113}
114
115impl HasLotusJson for fvm_shared3::crypto::signature::Signature {
116 type LotusJson = SignatureV3LotusJson;
117
118 #[cfg(test)]
119 fn snapshots() -> Vec<(serde_json::Value, Self)> {
120 vec![(
121 json!({"Type": 1, "Data": "aGVsbG8gd29ybGQh"}),
122 Self {
123 sig_type: fvm_shared3::crypto::signature::SignatureType::Secp256k1,
124 bytes: Vec::from_iter(*b"hello world!"),
125 },
126 )]
127 }
128
129 fn into_lotus_json(self) -> Self::LotusJson {
130 SignatureV3LotusJson {
131 r#type: self.sig_type,
132 data: self.bytes,
133 }
134 }
135
136 fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
137 Self {
138 sig_type: lotus_json.r#type,
139 bytes: lotus_json.data,
140 }
141 }
142}
143
144impl HasLotusJson for fvm_shared4::crypto::signature::Signature {
145 type LotusJson = SignatureV4LotusJson;
146
147 #[cfg(test)]
148 fn snapshots() -> Vec<(serde_json::Value, Self)> {
149 vec![(
150 json!({"Type": 1, "Data": "aGVsbG8gd29ybGQh"}),
151 Self {
152 sig_type: fvm_shared4::crypto::signature::SignatureType::Secp256k1,
153 bytes: Vec::from_iter(*b"hello world!"),
154 },
155 )]
156 }
157
158 fn into_lotus_json(self) -> Self::LotusJson {
159 SignatureV4LotusJson {
160 r#type: self.sig_type,
161 data: self.bytes,
162 }
163 }
164
165 fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
166 Self {
167 sig_type: lotus_json.r#type,
168 bytes: lotus_json.data,
169 }
170 }
171}