diff --git a/conversations/src/context.rs b/conversations/src/context.rs index 393b6c3..e40f97c 100644 --- a/conversations/src/context.rs +++ b/conversations/src/context.rs @@ -1,6 +1,4 @@ -use std::rc::Rc; - -use crypto::PrekeyBundle; +use std::{collections::HashMap, rc::Rc, sync::Arc}; use crate::{ conversation::{ConversationId, ConversationIdOwned, ConversationStore}, @@ -34,7 +32,7 @@ impl Context { &mut self, remote_bundle: &Introduction, content: String, - ) -> (ConversationIdOwned, Vec) { + ) -> (ConversationIdOwned, Vec) { let (convo, payloads) = self .inbox .invite_to_private_convo(remote_bundle, content) diff --git a/conversations/src/inbox/inbox.rs b/conversations/src/inbox/inbox.rs index 73382d7..7853b6d 100644 --- a/conversations/src/inbox/inbox.rs +++ b/conversations/src/inbox/inbox.rs @@ -14,7 +14,13 @@ use crate::crypto::{Blake2b128, CopyBytes, Digest, PublicKey, StaticSecret}; use crate::identity::Identity; use crate::inbox::handshake::InboxHandshake; use crate::proto::{self}; -use crate::types::ContentData; +use crate::types::{ContentData, PayloadData}; + +/// Compute the deterministic Delivery_address for an installation +fn delivery_address_for_installation(_: PublicKey) -> String { + // TODO: Implement Delivery Address + "delivery_address".into() +} pub struct Inbox { ident: Rc, @@ -69,7 +75,7 @@ impl Inbox { &self, remote_bundle: &Introduction, initial_message: String, - ) -> Result<(PrivateV1Convo, Vec), ChatError> { + ) -> Result<(PrivateV1Convo, Vec), ChatError> { let mut rng = OsRng; // TODO: Include signature in introduction bundle. Manaully fill for now @@ -112,7 +118,16 @@ impl Inbox { }; } - Ok((convo, initial_payloads)) + // Convert Encrypted Payloads to PayloadData + let payload_data = initial_payloads + .iter() + .map(|p| PayloadData { + delivery_address: delivery_address_for_installation(remote_bundle.installation_key), + data: p.encode_to_vec(), + }) + .collect(); + + Ok((convo, payload_data)) } fn wrap_in_invite(payload: proto::EncryptedPayload) -> proto::InboxV1Frame { @@ -238,12 +253,12 @@ mod tests { .invite_to_private_convo(&bundle.into(), "hello".into()) .unwrap(); - let encrypted_payload = payloads + let payload = payloads .get(0) .expect("RemoteInbox::invite_to_private_convo did not generate any payloads"); let mut buf = Vec::new(); - encrypted_payload.encode(&mut buf).unwrap(); + payload.data.encode(&mut buf).unwrap(); // Test handle_frame with valid payload let result = raya_inbox.handle_frame(&buf);