seismic_enclave/request_types/
snapsync.rs

1use kbs_types::Tee;
2use serde::{Deserialize, Serialize};
3
4/// Struct representing the request to SnapSync
5///
6/// # Fields
7/// * `client_attestation` - The attestation of the enclave that is running
8///                          the client's node. This attestation must contain an
9///                          encryption key as its runtime data.
10#[derive(Debug, Serialize, Deserialize)]
11pub struct SnapSyncRequest {
12    pub tee: Tee,
13    pub client_attestation: Vec<u8>,
14    pub client_signing_pk: Vec<u8>,
15    pub policy_ids: Vec<String>,
16}
17/// Struct representing the response from SnapSync
18///
19/// # Fields
20/// * `server_attestation` - The attestation of the server enclave. This attestation must contain
21///                          an signing pk as its runtime data.
22/// * `encrypted_data` - The SnapSyncData, serialized and then encrypted under the clients key.
23/// * `signature` - a signature of the snapsync data under the server signing key
24#[derive(Debug, Serialize, Deserialize)]
25pub struct SnapSyncResponse {
26    pub server_attestation: Vec<u8>,
27    pub server_signing_pk: Vec<u8>,
28    pub encrypted_data: Vec<u8>,
29    pub nonce: Vec<u8>,
30    pub signature: Vec<u8>,
31}
32
33/// stuct representing the data required to SnapSync
34///
35/// # Fields
36/// * `io_sk` - The secret key of the enclave's IO encryption keypair
37/// * `state` - The private state necessary to SnapSync
38#[derive(Debug, Serialize, Deserialize)]
39pub struct SnapSyncData {
40    pub io_sk: Vec<u8>,
41    pub state: Vec<u8>,
42}
43
44#[allow(dead_code)]
45impl SnapSyncData {
46    // Serialize the struct to bytes
47    pub fn to_bytes(&self) -> Result<Vec<u8>, anyhow::Error> {
48        let bytes = bincode::serialize(self)?;
49        Ok(bytes)
50    }
51
52    // Deserialize the struct from bytes
53    pub fn from_bytes(bytes: &[u8]) -> Result<Self, anyhow::Error> {
54        let data = bincode::deserialize(bytes)?;
55        Ok(data)
56    }
57}