lit_node_core/traits/encoding/
redpallas.rs1use super::{BeBytes, CompressedBytes, LeBytes};
2use lit_rust_crypto::{
3 group::GroupEncoding,
4 pallas::{Point, Scalar},
5};
6
7impl CompressedBytes for Point {
8 fn to_compressed(&self) -> Vec<u8> {
9 self.to_bytes().to_vec()
10 }
11
12 fn from_compressed(bytes: &[u8]) -> Option<Self> {
13 let mut repr = <Point as GroupEncoding>::Repr::default();
14 if repr.len() != bytes.len() {
15 return None;
16 }
17 repr.copy_from_slice(bytes);
18 Option::from(Self::from_bytes(&repr))
19 }
20}
21
22impl BeBytes for Scalar {
23 fn to_be_bytes(&self) -> Vec<u8> {
24 self.to_be_bytes().to_vec()
25 }
26
27 fn from_be_bytes(bytes: &[u8]) -> Option<Self> {
28 Option::from(Self::from_be_bytes(&bytes.try_into().ok()?))
29 }
30}
31
32impl LeBytes for Scalar {
33 fn to_le_bytes(&self) -> Vec<u8> {
34 self.to_le_bytes().to_vec()
35 }
36
37 fn from_le_bytes(bytes: &[u8]) -> Option<Self> {
38 Option::from(Self::from_le_bytes(bytes.try_into().ok()?))
39 }
40}
41
42impl CompressedBytes for Scalar {
43 fn to_compressed(&self) -> Vec<u8> {
44 self.to_le_bytes().to_vec()
45 }
46
47 fn from_compressed(bytes: &[u8]) -> Option<Self> {
48 Option::from(Self::from_le_bytes(bytes.try_into().ok()?))
49 }
50}