lit_node_core/traits/encoding/
bls.rs1use super::{BeBytes, CompressedBytes, LeBytes};
2use lit_rust_crypto::blsful::inner_types::{G1Projective, G2Projective, Scalar};
3
4impl CompressedBytes for G1Projective {
5 fn to_compressed(&self) -> Vec<u8> {
6 self.to_compressed().to_vec()
7 }
8
9 fn from_compressed(bytes: &[u8]) -> Option<Self> {
10 if bytes.len() != 48 {
11 return None;
12 }
13 let bytes: [u8; 48] = bytes.try_into().ok()?;
14 Option::from(Self::from_compressed(&bytes))
15 }
16 fn to_uncompressed(&self) -> Vec<u8> {
17 self.to_uncompressed().to_vec()
18 }
19
20 fn from_uncompressed(bytes: &[u8]) -> Option<Self> {
21 if bytes.len() != 96 {
22 return None;
23 }
24 let bytes: [u8; 96] = bytes.try_into().ok()?;
25 Option::from(Self::from_uncompressed(&bytes))
26 }
27}
28
29impl CompressedBytes for G2Projective {
30 fn to_compressed(&self) -> Vec<u8> {
31 self.to_compressed().to_vec()
32 }
33
34 fn from_compressed(bytes: &[u8]) -> Option<Self> {
35 if bytes.len() != 96 {
36 return None;
37 }
38 let bytes: [u8; 96] = bytes.try_into().ok()?;
39 Option::from(Self::from_compressed(&bytes))
40 }
41 fn to_uncompressed(&self) -> Vec<u8> {
42 self.to_uncompressed().to_vec()
43 }
44
45 fn from_uncompressed(bytes: &[u8]) -> Option<Self> {
46 if bytes.len() != 192 {
47 return None;
48 }
49 let bytes: [u8; 192] = bytes.try_into().ok()?;
50 Option::from(Self::from_uncompressed(&bytes))
51 }
52}
53
54impl BeBytes for Scalar {
55 fn to_be_bytes(&self) -> Vec<u8> {
56 self.to_be_bytes().to_vec()
57 }
58
59 fn from_be_bytes(bytes: &[u8]) -> Option<Self> {
60 Option::from(Scalar::from_be_bytes(bytes.try_into().ok()?))
61 }
62}
63
64impl LeBytes for Scalar {
65 fn to_le_bytes(&self) -> Vec<u8> {
66 self.to_le_bytes().to_vec()
67 }
68
69 fn from_le_bytes(bytes: &[u8]) -> Option<Self> {
70 Option::from(Scalar::from_le_bytes(bytes.try_into().ok()?))
71 }
72}
73
74impl CompressedBytes for Scalar {
75 fn to_compressed(&self) -> Vec<u8> {
76 self.to_be_bytes().to_vec()
77 }
78
79 fn from_compressed(bytes: &[u8]) -> Option<Self> {
80 Option::from(Scalar::from_be_bytes(bytes.try_into().ok()?))
81 }
82}