Use PayloadData for outbound datatype (#23)

* Add Introductions (#22)

* Move to Payload data

* compute delivery_address
This commit is contained in:
Jazz Turner-Baggs 2026-01-28 07:07:35 +07:00
parent d40e72be9b
commit 4b1069a4a8
No known key found for this signature in database
2 changed files with 22 additions and 9 deletions

View File

@ -1,6 +1,4 @@
use std::rc::Rc; use std::{collections::HashMap, rc::Rc, sync::Arc};
use crypto::PrekeyBundle;
use crate::{ use crate::{
conversation::{ConversationId, ConversationIdOwned, ConversationStore}, conversation::{ConversationId, ConversationIdOwned, ConversationStore},
@ -34,7 +32,7 @@ impl Context {
&mut self, &mut self,
remote_bundle: &Introduction, remote_bundle: &Introduction,
content: String, content: String,
) -> (ConversationIdOwned, Vec<proto::EncryptedPayload>) { ) -> (ConversationIdOwned, Vec<PayloadData>) {
let (convo, payloads) = self let (convo, payloads) = self
.inbox .inbox
.invite_to_private_convo(remote_bundle, content) .invite_to_private_convo(remote_bundle, content)

View File

@ -14,7 +14,13 @@ use crate::crypto::{Blake2b128, CopyBytes, Digest, PublicKey, StaticSecret};
use crate::identity::Identity; use crate::identity::Identity;
use crate::inbox::handshake::InboxHandshake; use crate::inbox::handshake::InboxHandshake;
use crate::proto::{self}; 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 { pub struct Inbox {
ident: Rc<Identity>, ident: Rc<Identity>,
@ -69,7 +75,7 @@ impl Inbox {
&self, &self,
remote_bundle: &Introduction, remote_bundle: &Introduction,
initial_message: String, initial_message: String,
) -> Result<(PrivateV1Convo, Vec<proto::EncryptedPayload>), ChatError> { ) -> Result<(PrivateV1Convo, Vec<PayloadData>), ChatError> {
let mut rng = OsRng; let mut rng = OsRng;
// TODO: Include signature in introduction bundle. Manaully fill for now // 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 { fn wrap_in_invite(payload: proto::EncryptedPayload) -> proto::InboxV1Frame {
@ -238,12 +253,12 @@ mod tests {
.invite_to_private_convo(&bundle.into(), "hello".into()) .invite_to_private_convo(&bundle.into(), "hello".into())
.unwrap(); .unwrap();
let encrypted_payload = payloads let payload = payloads
.get(0) .get(0)
.expect("RemoteInbox::invite_to_private_convo did not generate any payloads"); .expect("RemoteInbox::invite_to_private_convo did not generate any payloads");
let mut buf = Vec::new(); let mut buf = Vec::new();
encrypted_payload.encode(&mut buf).unwrap(); payload.data.encode(&mut buf).unwrap();
// Test handle_frame with valid payload // Test handle_frame with valid payload
let result = raya_inbox.handle_frame(&buf); let result = raya_inbox.handle_frame(&buf);