Skip to main content

clasp_crypto/
types.rs

1use serde::{Deserialize, Serialize};
2use zeroize::{Zeroize, ZeroizeOnDrop};
3
4/// E2E encrypted envelope that flows through CLASP as a normal map value.
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct E2EEnvelope {
7    /// Marker field, always 1.
8    pub _e2e: u8,
9    /// Base64-encoded ciphertext.
10    pub ct: String,
11    /// Base64-encoded IV (12 bytes for AES-GCM).
12    pub iv: String,
13    /// Envelope version.
14    pub v: u8,
15}
16
17/// Stored key material with metadata.
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(rename_all = "camelCase")]
20pub struct KeyData {
21    /// The group key in JWK JSON format (interop with JS).
22    pub key: serde_json::Value,
23    /// When this key was stored (Unix ms).
24    pub stored_at: u64,
25}
26
27/// Stored TOFU fingerprint record.
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(rename_all = "camelCase")]
30pub struct TofuRecord {
31    /// Hex fingerprint of the peer's ECDH public key.
32    pub fingerprint: String,
33    /// When this key was first seen (Unix ms).
34    pub first_seen: u64,
35}
36
37/// ECDH key pair: public key (SEC1 encoded) + private key (scalar bytes).
38/// Private key material is zeroed on drop. Not `Clone` to prevent
39/// uncontrolled duplication of private key material.
40#[derive(Zeroize, ZeroizeOnDrop)]
41pub struct ECDHKeyPair {
42    pub public_key: Vec<u8>,
43    pub private_key: Vec<u8>,
44}
45
46/// ECDSA signing key pair.
47/// Private key material is zeroed on drop. Not `Clone` to prevent
48/// uncontrolled duplication of private key material.
49#[derive(Zeroize, ZeroizeOnDrop)]
50pub struct SigningKeyPair {
51    pub public_key: Vec<u8>,
52    pub private_key: Vec<u8>,
53}
54
55/// Key exchange message sent between peers (camelCase for JS interop).
56#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(rename_all = "camelCase")]
58pub struct KeyExchangeMessage {
59    pub from_id: String,
60    pub encrypted_key: String,
61    pub iv: String,
62    /// ECDH public key in JWK JSON format (interop with JS).
63    pub sender_public_key: serde_json::Value,
64}
65
66/// Public key announcement (camelCase for JS interop).
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(rename_all = "camelCase")]
69pub struct PublicKeyAnnouncement {
70    /// ECDH public key in JWK JSON format.
71    pub public_key: serde_json::Value,
72    pub timestamp: u64,
73}