Skip to content

Commit dd86f2b

Browse files
committed
fix: invitee as the first message sender.
1 parent 6dff127 commit dd86f2b

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

src/chat_sdk/conversations/private_v1.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ proc wireCallbacks(convo: PrivateV1, deliveryAckCb: proc(
145145

146146

147147
proc initPrivateV1*(owner: Identity, participant: PublicKey, seedKey: array[32, byte],
148-
discriminator: string = "default", isSender: bool, deliveryAckCb: proc(
148+
discriminator: string = "default", inviter: bool, deliveryAckCb: proc(
149149
conversation: Conversation,
150150
msgId: string): Future[void] {.async.} = nil):
151151
PrivateV1 =
@@ -161,7 +161,7 @@ proc initPrivateV1*(owner: Identity, participant: PublicKey, seedKey: array[32,
161161
topic: derive_topic(participants, discriminator),
162162
participant: participant,
163163
discriminator: discriminator,
164-
doubleratchet: initDoubleratchet(seedKey, owner.privateKey.bytes, participant.bytes, isSender)
164+
doubleratchet: initDoubleratchet(seedKey, owner.privateKey.bytes, participant.bytes, inviter)
165165
)
166166

167167
result.wireCallbacks(deliveryAckCb)

src/chat_sdk/crypto.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ export PublicKey, PrivateKey, bytes, createRandomKey, loadPrivateKeyFromBytes, l
1212

1313
proc encrypt_plain*[T: EncryptableTypes](frame: T): EncryptedPayload =
1414
return EncryptedPayload(
15-
plaintext: Plaintext(payload: encode(frame)),
15+
plaintext: Plaintext(payload: proto_types.encode(frame)),
1616
)
1717

1818
proc decrypt_plain*[T: EncryptableTypes](ciphertext: Plaintext, t: typedesc[
1919
T]): Result[T, string] =
2020

21-
let obj = decode(ciphertext.payload, T)
21+
let obj = proto_types.decode(ciphertext.payload, T)
2222
if obj.isErr:
2323
return err("Protobuf decode failed: " & obj.error)
2424
result = ok(obj.get())

src/chat_sdk/inbox.nim

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import
1414
types,
1515
utils
1616

17+
import ../content_types
18+
1719
logScope:
1820
topics = "chat inbox"
1921

@@ -42,7 +44,7 @@ proc decrypt*(inbox: Inbox, encbytes: EncryptedPayload): Result[InboxV1Frame, st
4244
result = res_frame
4345

4446
proc wrap_env*(payload: EncryptedPayload, convo_id: string): WapEnvelopeV1 =
45-
let bytes = encode(payload)
47+
let bytes = proto_types.encode(payload)
4648
let salt = generateSalt()
4749

4850
return WapEnvelopeV1(
@@ -87,12 +89,16 @@ proc createPrivateV1FromInvite*[T: ConversationStore](client: T,
8789
topic = convo.getConvoId()
8890
client.addConversation(convo)
8991

92+
# TODO send a control frame instead
93+
discard convo.sendMessage(client.ds, initTextFrame("Hello").toContentFrame())
94+
95+
9096
proc handleFrame*[T: ConversationStore](convo: Inbox, client: T, bytes: seq[
9197
byte]) =
9298
## Dispatcher for Incoming `InboxV1Frames`.
9399
## Calls further processing depending on the kind of frame.
94100

95-
let enc = decode(bytes, EncryptedPayload).valueOr:
101+
let enc = proto_types.decode(bytes, EncryptedPayload).valueOr:
96102
raise newException(ValueError, "Failed to decode payload")
97103

98104
let frame = convo.decrypt(enc).valueOr:

src/content_types/all.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ proc initTextFrame*(text: string): TextFrame =
5656
result = TextFrame(encoding: ord(Utf8), text: text)
5757

5858

59+
60+
5961
proc `$`*(frame: TextFrame): string =
6062

6163
result = fmt"TextFrame(encoding:{TextEncoding(frame.encoding)} text:{frame.text})"

src/naxolotl/naxolotl.nim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ func kdfChain(self: Doubleratchet, chainKey: ChainKey): (MessageKey, ChainKey) =
7676
proc dhRatchetSend(self: var Doubleratchet) =
7777
# Perform DH Ratchet step when receiving a new peer key.
7878
info "dhRatchetSend DH Self: ", dhSelf = self.dhSelf
79+
self.dhSelf = generateKeypair().get()[0]
80+
info "dhRatchetSend new DH Self: ", dhSelf = self.dhSelf
7981
let dhOutput : DhDerivedKey = dhExchange(self.dhSelf, self.dhRemote).get()
8082
let (newRootKey, newChainKeySend) = kdfRoot(self, self.rootKey, dhOutput)
8183
self.rootKey = newRootKey
@@ -185,7 +187,7 @@ proc encrypt*(self: var Doubleratchet, plaintext: var seq[byte]) : (DrHeader, Ci
185187
encrypt(self, plaintext,@[])
186188

187189

188-
proc initDoubleratchet*(sharedSecret: array[32, byte], dhSelf: PrivateKey, dhRemote: PublicKey, isSending: bool = true): Doubleratchet =
190+
proc initDoubleratchet*(sharedSecret: array[32, byte], dhSelf: PrivateKey, dhRemote: PublicKey, inviter: bool = true): Doubleratchet =
189191

190192
info "Initializing Double Ratchet"
191193
info "DH Self: ", dhSelf = dhSelf
@@ -201,5 +203,5 @@ proc initDoubleratchet*(sharedSecret: array[32, byte], dhSelf: PrivateKey, dhRem
201203
skippedMessageKeys: initTable[(PublicKey, MsgCount), MessageKey]()
202204
)
203205

204-
if isSending:
206+
if not inviter:
205207
result.dhRatchetSend()

0 commit comments

Comments
 (0)