fedimint_core/
backup.rs

1//! Federation-stored client backups
2//!
3//! Federations can store client-encrypted backups to help
4//! clients recover from a snapshot, instead of a blank slate.
5use std::time::SystemTime;
6
7use fedimint_core::encoding::{Decodable, Encodable};
8use fedimint_core::{impl_db_lookup, impl_db_record};
9use serde::{Deserialize, Serialize};
10
11use crate::db::DbKeyPrefix;
12
13/// Key used to store user's ecash backups
14#[derive(Debug, Clone, Copy, Encodable, Decodable, Serialize)]
15pub struct ClientBackupKey(pub secp256k1::PublicKey);
16
17#[derive(Debug, Encodable, Decodable)]
18pub struct ClientBackupKeyPrefix;
19
20impl_db_record!(
21    key = ClientBackupKey,
22    value = ClientBackupSnapshot,
23    db_prefix = DbKeyPrefix::ClientBackup,
24);
25impl_db_lookup!(key = ClientBackupKey, query_prefix = ClientBackupKeyPrefix);
26
27/// User's backup, received at certain time, containing encrypted payload
28#[derive(Debug, Clone, PartialEq, Eq, Encodable, Decodable, Serialize, Deserialize)]
29pub struct ClientBackupSnapshot {
30    pub timestamp: SystemTime,
31    #[serde(with = "fedimint_core::hex::serde")]
32    pub data: Vec<u8>,
33}