diff --git a/examples/pingpong.nim b/examples/pingpong.nim index bc39980..83a457a 100644 --- a/examples/pingpong.nim +++ b/examples/pingpong.nim @@ -82,7 +82,7 @@ proc main() {.async.} = # Perform OOB Introduction: Raya -> Saro let raya_bundle = raya.createIntroBundle() - discard await saro.newPrivateConversation(raya_bundle, initTextFrame("Init").toContentFrame()) + discard await saro.newPrivateConversation(raya_bundle, initTextFrame("Init").toContentFrame().toBytes()) await sleepAsync(20.seconds) # Run for some time diff --git a/src/chat/client.nim b/src/chat/client.nim index fb3bb58..02e2c73 100644 --- a/src/chat/client.nim +++ b/src/chat/client.nim @@ -186,7 +186,7 @@ proc getConversation*(client: Client, convoId: string): Conversation = result = client.conversations[convoId] proc newPrivateConversation*(client: Client, - introBundle: IntroBundle, content: ContentFrame): Future[Option[ChatError]] {.async.} = + introBundle: IntroBundle, content: Content): Future[Option[ChatError]] {.async.} = ## Creates a private conversation with the given `IntroBundle`. ## `IntroBundles` are provided out-of-band. let remote_pubkey = loadPublicKeyFromBytes(introBundle.ident).get() diff --git a/src/chat/conversations/private_v1.nim b/src/chat/conversations/private_v1.nim index c2384ef..9e8b264 100644 --- a/src/chat/conversations/private_v1.nim +++ b/src/chat/conversations/private_v1.nim @@ -23,7 +23,8 @@ import convo_type import message import ../../naxolotl as nax - + +const TopicPrefixPrivateV1 = "/convo/private/" type ReceivedPrivateV1Message* = ref object of ReceivedMessage @@ -43,7 +44,7 @@ type proc derive_topic(participant: PublicKey): string = ## Derives a topic from the participants' public keys. - return "/convo/private/" & participant.get_addr() + return TopicPrefixPrivateV1 & participant.get_addr() proc getTopicInbound*(self: PrivateV1): string = ## Returns the topic where the local client is listening for messages @@ -53,6 +54,17 @@ proc getTopicOutbound*(self: PrivateV1): string = ## Returns the topic where the remote recipient is listening for messages return derive_topic(self.participant) +## Parses the topic to extract the conversation ID. +proc parseTopic*(topic: string): Result[string, ChatError] = + if not topic.startsWith(TopicPrefixPrivateV1): + return err(ChatError(code: errTopic, context: "Invalid topic prefix")) + + let id = topic.split('/')[^1] + if id == "": + return err(ChatError(code: errTopic, context: "Empty conversation ID")) + + return ok(id) + proc allParticipants(self: PrivateV1): seq[PublicKey] = return @[self.owner.getPubkey(), self.participant] @@ -255,7 +267,7 @@ proc initPrivateV1Sender*(sender:Identity, ds: WakuClient, participant: PublicKey, seedKey: array[32, byte], - content: ContentFrame, + content: Content, deliveryAckCb: proc(conversation: Conversation, msgId: string): Future[void] {.async.} = nil): (PrivateV1, EncryptedPayload) = let convo = initPrivateV1(sender, ds, participant, seedKey, "default", true, deliveryAckCb) diff --git a/src/chat/inbox.nim b/src/chat/inbox.nim index dcf4e27..9549ade 100644 --- a/src/chat/inbox.nim +++ b/src/chat/inbox.nim @@ -11,6 +11,7 @@ import conversations, conversation_store, crypto, + delivery/waku_client, errors, identity, proto_types, @@ -104,7 +105,7 @@ proc newPrivateInvite(initator_static: PublicKey, ################################################# ## Establish a PrivateConversation with a remote client -proc inviteToPrivateConversation*(self: Inbox, ds: Wakuclient, remote_static: PublicKey, remote_ephemeral: PublicKey, content: ContentFrame ) : Future[PrivateV1] {.async.} = +proc inviteToPrivateConversation*(self: Inbox, ds: Wakuclient, remote_static: PublicKey, remote_ephemeral: PublicKey, content: Content ) : Future[PrivateV1] {.async.} = # Create SeedKey # TODO: Update key derivations when noise is integrated var local_ephemeral = generateKey()