diff --git a/conversations/src/context.rs b/conversations/src/context.rs index 1a0f86f..49db263 100644 --- a/conversations/src/context.rs +++ b/conversations/src/context.rs @@ -41,9 +41,10 @@ impl Context { .invite_to_private_convo(remote_bundle, content) .unwrap_or_else(|_| todo!("Log/Surface Error")); + let remote_id = Inbox::inbox_identifier_for_key(remote_bundle.installation_key); let payload_bytes = payloads .into_iter() - .map(|p| p.to_envelope(convo.id().to_string())) + .map(|p| p.to_envelope(remote_id.clone())) .collect(); let convo_id = self.add_convo(Box::new(convo)); @@ -77,8 +78,7 @@ impl Context { // TODO: Impl Conversation hinting let convo_id = env.conversation_hint; - let enc = EncryptedPayload::decode(payload)?; - + let enc = EncryptedPayload::decode(env.payload)?; match convo_id { c if c == self.inbox.id() => self.dispatch_to_inbox(enc), c if self.store.has(&c) => self.dispatch_to_convo(&c, enc), diff --git a/conversations/src/inbox/inbox.rs b/conversations/src/inbox/inbox.rs index 66888b7..f03ff17 100644 --- a/conversations/src/inbox/inbox.rs +++ b/conversations/src/inbox/inbox.rs @@ -1,3 +1,4 @@ +use blake2::{Blake2b512, Digest}; use chat_proto::logoschat::encryption::EncryptedPayload; use hex; use prost::Message; @@ -43,7 +44,7 @@ impl<'a> std::fmt::Debug for Inbox { impl Inbox { pub fn new(ident: Rc) -> Self { - let local_convo_id = ident.address(); + let local_convo_id = Self::inbox_identifier_for_key(ident.public_key()); Self { ident, local_convo_id, @@ -216,6 +217,11 @@ impl Inbox { .get(key) .ok_or_else(|| return ChatError::UnknownEphemeralKey()) } + + pub fn inbox_identifier_for_key(pubkey: PublicKey) -> String { + // TODO: Implement ID according to spec + hex::encode(Blake2b512::digest(pubkey)) + } } impl Id for Inbox { diff --git a/conversations/src/inbox/introduction.rs b/conversations/src/inbox/introduction.rs index 0955e11..fc686dc 100644 --- a/conversations/src/inbox/introduction.rs +++ b/conversations/src/inbox/introduction.rs @@ -50,7 +50,7 @@ impl TryFrom<&[u8]> for Introduction { .map_err(|_| ChatError::InvalidKeyLength)?; let installation_key = PublicKey::from(installation_bytes); - let ephemeral_bytes: [u8; 32] = hex::decode(parts[1]) + let ephemeral_bytes: [u8; 32] = hex::decode(parts[2]) .map_err(|_| ChatError::BadParsing("ephemeral_key"))? .try_into() .map_err(|_| ChatError::InvalidKeyLength)?;