reach_core/wire/
envelope.rs1use chacha20poly1305::XNonce;
6use ecdh_omr::Blinded;
7#[cfg(feature = "server")]
8use rand_core::CryptoRngCore;
9
10use reach_aliases::*;
11use reach_proc_macros::{communicable, prosted};
12
13use crate::wire::{Request, Response, id_type, proto};
14
15#[communicable(Request::EnvelopeId)]
16#[prosted(proto::EnvelopeId, Decode, Encode, ProstTraits)]
17#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
18pub struct EnvelopeId {
19 pub id: ThreeTwo,
20}
21
22#[prosted(proto::CredentialVault, Decode, Encode, ProstTraits)]
23#[derive(Debug)]
24pub struct CredentialVault {
25 pub ec_public_key: X25519Public,
26 pub pq_ciphertext: MlKemCiphertext,
27 pub credentials_ciphertext: Vec<u8>,
28}
29
30#[communicable(Response::Envelope)]
31#[prosted(proto::Envelope, Decode, Encode, ProstTraits)]
32#[derive(Debug)]
33pub struct Envelope {
34 pub id: EnvelopeId,
35 pub credential_vaults: Vec<CredentialVault>,
36 pub nonce: XNonce,
37 pub message_vault_passport_ciphertext: Vec<u8>,
38}
39
40id_type!(EnvelopeId);
41
42#[derive(Debug)]
43#[prosted(proto::SealedEnvelopeId, Decode, Encode, ProstTraits)]
44pub struct SealedEnvelopeId {
45 pub ec_public_key: X25519Public,
46 pub pq_ciphertext: MlKemCiphertext,
47 pub envelope_id_ciphertext: Vec<u8>,
48}
49
50#[derive(Debug)]
51#[communicable(Request::AddEnvelope)]
52#[prosted(proto::EnvelopeSeed, Decode, Encode, ProstTraits)]
53pub struct EnvelopeSeed {
54 pub blinded_public_keys: Vec<BlindedPublicKey>,
55 pub credential_vaults: Vec<CredentialVault>,
56 pub nonce: XNonce,
57 pub message_vault_passport_ciphertext: Vec<u8>,
58}
59
60#[cfg(any(feature = "reachable", feature = "server"))]
61mod reachable_server {
62 use super::*;
63
64 pub struct EnvelopeIds {
65 pub ids: Vec<EnvelopeId>,
66 }
67
68 impl TryFrom<proto::EnvelopeIds> for EnvelopeIds {
69 type Error = crate::error::DecodeError;
70
71 fn try_from(from: proto::EnvelopeIds) -> Result<Self, Self::Error> {
72 Ok(Self {
73 ids: from
74 .ids
75 .into_iter()
76 .map(EnvelopeId::try_from)
77 .collect::<Result<_, _>>()?,
78 })
79 }
80 }
81
82 impl From<&EnvelopeIds> for proto::EnvelopeIds {
83 fn from(from: &EnvelopeIds) -> Self {
84 Self {
85 ids: from.ids.iter().map(proto::EnvelopeId::from).collect(),
86 }
87 }
88 }
89}
90
91#[cfg(any(feature = "reachable", feature = "server"))]
92pub use reachable_server::*;
93
94#[derive(Debug)]
95#[communicable(Request::RemoveEnvelopeIdHint)]
96#[prosted(proto::RemoveEnvelopeIdHint, Decode, Encode, ProstTraits)]
97pub struct RemoveEnvelopeIdHint {
98 pub envelope_id: EnvelopeId,
99 pub hint_removal_token: OneSix,
100}