zkgroup/crypto/
receipt_struct.rs1use curve25519_dalek_signal::scalar::Scalar;
7use serde::{Deserialize, Serialize};
8
9use crate::common::sho::Sho;
10use crate::common::simple_types::{ReceiptLevel, ReceiptSerialBytes, Timestamp};
11
12#[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
20pub struct ReceiptStruct {
21 pub(crate) receipt_serial_bytes: ReceiptSerialBytes,
22 pub(crate) receipt_expiration_time: Timestamp,
23 pub(crate) receipt_level: ReceiptLevel,
24}
25
26impl ReceiptStruct {
27 pub fn new(
28 receipt_serial_bytes: ReceiptSerialBytes,
29 receipt_expiration_time: Timestamp,
30 receipt_level: ReceiptLevel,
31 ) -> Self {
32 Self {
33 receipt_serial_bytes,
34 receipt_expiration_time,
35 receipt_level,
36 }
37 }
38
39 pub fn calc_m1(&self) -> Scalar {
40 Self::calc_m1_from(self.receipt_expiration_time, self.receipt_level)
41 }
42
43 pub fn calc_m1_from(receipt_expiration_time: Timestamp, receipt_level: ReceiptLevel) -> Scalar {
44 let mut bytes =
45 [0u8; std::mem::size_of::<Timestamp>() + std::mem::size_of::<ReceiptLevel>()];
46 bytes[..std::mem::size_of::<Timestamp>()]
47 .copy_from_slice(&receipt_expiration_time.to_be_bytes());
48 bytes[std::mem::size_of::<Timestamp>()..].copy_from_slice(&receipt_level.to_be_bytes());
49 let mut sho = Sho::new(b"Signal_ZKGroup_20210919_Receipt_CalcM1", &bytes);
50 sho.get_scalar()
51 }
52}