|
1 | 1 | use crate::{ |
2 | 2 | event::event_interface::EventInterface, |
3 | 3 | messages::{ |
4 | | - encoding::{encode_message, MESSAGE_CIPHERTEXT_LEN, MESSAGE_EXPANDED_METADATA_LEN}, |
5 | | - encryption::{aes128::AES128, message_encryption::MessageEncryption}, |
| 4 | + encoding::{encode_message, MESSAGE_EXPANDED_METADATA_LEN}, |
6 | 5 | msg_type::PRIVATE_EVENT_MSG_TYPE_ID, |
7 | 6 | }, |
8 | | - oracle::random::random, |
9 | 7 | }; |
10 | | -use protocol_types::{address::AztecAddress, traits::{Serialize, ToField}}; |
| 8 | +use protocol_types::traits::{Serialize, ToField}; |
11 | 9 |
|
12 | 10 | global PRIVATE_EVENT_RESERVED_FIELDS: u32 = 1; |
13 | 11 | global PRIVATE_EVENT_RANDOMNESS_INDEX: u32 = 0; |
14 | 12 |
|
15 | | -/// Creates an encrypted private event message (i.e. one of type `PRIVATE_EVENT_MSG_TYPE_ID`) by encoding the contents |
16 | | -/// of the event and then encrypting them for `recipient`. |
17 | | -pub fn to_encrypted_private_event_message<Event>( |
18 | | - event: Event, |
19 | | - recipient: AztecAddress, |
20 | | -) -> ([Field; MESSAGE_CIPHERTEXT_LEN], Field) |
21 | | -where |
22 | | - Event: EventInterface + Serialize, |
23 | | -{ |
24 | | - // In private events, we automatically inject randomness to prevent event commitment preimage attacks and event |
25 | | - // commitment collisions (the commitments are included in the nullifier tree and duplicate nullifiers are by |
26 | | - // definition not allowed). |
27 | | - // Safety: We use the randomness to preserve the privacy of the event recipient by preventing brute-forcing, |
28 | | - // so a malicious sender could use non-random values to make the event less private. But they already know |
29 | | - // the full event pre-image anyway, and so the recipient already trusts them to not disclose this information. |
30 | | - // We can therefore assume that the sender will cooperate in the random value generation. |
31 | | - let randomness = unsafe { random() }; |
32 | | - |
33 | | - let plaintext = private_event_to_message_plaintext(event, randomness); |
34 | | - |
35 | | - (AES128::encrypt(plaintext, recipient), randomness) |
36 | | -} |
37 | | - |
| 13 | +/// Creates the plaintext for a private event message (i.e. one of type [PRIVATE_EVENT_MSG_TYPE_ID]). |
38 | 14 | pub fn private_event_to_message_plaintext<Event>( |
39 | 15 | event: Event, |
40 | 16 | randomness: Field, |
|
0 commit comments