mirror of
https://github.com/logos-messaging/logos-chat.git
synced 2026-05-09 14:09:39 +00:00
fix: invitee as the first message sender.
This commit is contained in:
parent
6dff127cab
commit
dd86f2b976
@ -145,7 +145,7 @@ proc wireCallbacks(convo: PrivateV1, deliveryAckCb: proc(
|
|||||||
|
|
||||||
|
|
||||||
proc initPrivateV1*(owner: Identity, participant: PublicKey, seedKey: array[32, byte],
|
proc initPrivateV1*(owner: Identity, participant: PublicKey, seedKey: array[32, byte],
|
||||||
discriminator: string = "default", isSender: bool, deliveryAckCb: proc(
|
discriminator: string = "default", inviter: bool, deliveryAckCb: proc(
|
||||||
conversation: Conversation,
|
conversation: Conversation,
|
||||||
msgId: string): Future[void] {.async.} = nil):
|
msgId: string): Future[void] {.async.} = nil):
|
||||||
PrivateV1 =
|
PrivateV1 =
|
||||||
@ -161,7 +161,7 @@ proc initPrivateV1*(owner: Identity, participant: PublicKey, seedKey: array[32,
|
|||||||
topic: derive_topic(participants, discriminator),
|
topic: derive_topic(participants, discriminator),
|
||||||
participant: participant,
|
participant: participant,
|
||||||
discriminator: discriminator,
|
discriminator: discriminator,
|
||||||
doubleratchet: initDoubleratchet(seedKey, owner.privateKey.bytes, participant.bytes, isSender)
|
doubleratchet: initDoubleratchet(seedKey, owner.privateKey.bytes, participant.bytes, inviter)
|
||||||
)
|
)
|
||||||
|
|
||||||
result.wireCallbacks(deliveryAckCb)
|
result.wireCallbacks(deliveryAckCb)
|
||||||
|
|||||||
@ -12,13 +12,13 @@ export PublicKey, PrivateKey, bytes, createRandomKey, loadPrivateKeyFromBytes, l
|
|||||||
|
|
||||||
proc encrypt_plain*[T: EncryptableTypes](frame: T): EncryptedPayload =
|
proc encrypt_plain*[T: EncryptableTypes](frame: T): EncryptedPayload =
|
||||||
return EncryptedPayload(
|
return EncryptedPayload(
|
||||||
plaintext: Plaintext(payload: encode(frame)),
|
plaintext: Plaintext(payload: proto_types.encode(frame)),
|
||||||
)
|
)
|
||||||
|
|
||||||
proc decrypt_plain*[T: EncryptableTypes](ciphertext: Plaintext, t: typedesc[
|
proc decrypt_plain*[T: EncryptableTypes](ciphertext: Plaintext, t: typedesc[
|
||||||
T]): Result[T, string] =
|
T]): Result[T, string] =
|
||||||
|
|
||||||
let obj = decode(ciphertext.payload, T)
|
let obj = proto_types.decode(ciphertext.payload, T)
|
||||||
if obj.isErr:
|
if obj.isErr:
|
||||||
return err("Protobuf decode failed: " & obj.error)
|
return err("Protobuf decode failed: " & obj.error)
|
||||||
result = ok(obj.get())
|
result = ok(obj.get())
|
||||||
|
|||||||
@ -14,6 +14,8 @@ import
|
|||||||
types,
|
types,
|
||||||
utils
|
utils
|
||||||
|
|
||||||
|
import ../content_types
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "chat inbox"
|
topics = "chat inbox"
|
||||||
|
|
||||||
@ -42,7 +44,7 @@ proc decrypt*(inbox: Inbox, encbytes: EncryptedPayload): Result[InboxV1Frame, st
|
|||||||
result = res_frame
|
result = res_frame
|
||||||
|
|
||||||
proc wrap_env*(payload: EncryptedPayload, convo_id: string): WapEnvelopeV1 =
|
proc wrap_env*(payload: EncryptedPayload, convo_id: string): WapEnvelopeV1 =
|
||||||
let bytes = encode(payload)
|
let bytes = proto_types.encode(payload)
|
||||||
let salt = generateSalt()
|
let salt = generateSalt()
|
||||||
|
|
||||||
return WapEnvelopeV1(
|
return WapEnvelopeV1(
|
||||||
@ -87,12 +89,16 @@ proc createPrivateV1FromInvite*[T: ConversationStore](client: T,
|
|||||||
topic = convo.getConvoId()
|
topic = convo.getConvoId()
|
||||||
client.addConversation(convo)
|
client.addConversation(convo)
|
||||||
|
|
||||||
|
# TODO send a control frame instead
|
||||||
|
discard convo.sendMessage(client.ds, initTextFrame("Hello").toContentFrame())
|
||||||
|
|
||||||
|
|
||||||
proc handleFrame*[T: ConversationStore](convo: Inbox, client: T, bytes: seq[
|
proc handleFrame*[T: ConversationStore](convo: Inbox, client: T, bytes: seq[
|
||||||
byte]) =
|
byte]) =
|
||||||
## Dispatcher for Incoming `InboxV1Frames`.
|
## Dispatcher for Incoming `InboxV1Frames`.
|
||||||
## Calls further processing depending on the kind of frame.
|
## Calls further processing depending on the kind of frame.
|
||||||
|
|
||||||
let enc = decode(bytes, EncryptedPayload).valueOr:
|
let enc = proto_types.decode(bytes, EncryptedPayload).valueOr:
|
||||||
raise newException(ValueError, "Failed to decode payload")
|
raise newException(ValueError, "Failed to decode payload")
|
||||||
|
|
||||||
let frame = convo.decrypt(enc).valueOr:
|
let frame = convo.decrypt(enc).valueOr:
|
||||||
|
|||||||
@ -56,6 +56,8 @@ proc initTextFrame*(text: string): TextFrame =
|
|||||||
result = TextFrame(encoding: ord(Utf8), text: text)
|
result = TextFrame(encoding: ord(Utf8), text: text)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
proc `$`*(frame: TextFrame): string =
|
proc `$`*(frame: TextFrame): string =
|
||||||
|
|
||||||
result = fmt"TextFrame(encoding:{TextEncoding(frame.encoding)} text:{frame.text})"
|
result = fmt"TextFrame(encoding:{TextEncoding(frame.encoding)} text:{frame.text})"
|
||||||
|
|||||||
@ -76,6 +76,8 @@ func kdfChain(self: Doubleratchet, chainKey: ChainKey): (MessageKey, ChainKey) =
|
|||||||
proc dhRatchetSend(self: var Doubleratchet) =
|
proc dhRatchetSend(self: var Doubleratchet) =
|
||||||
# Perform DH Ratchet step when receiving a new peer key.
|
# Perform DH Ratchet step when receiving a new peer key.
|
||||||
info "dhRatchetSend DH Self: ", dhSelf = self.dhSelf
|
info "dhRatchetSend DH Self: ", dhSelf = self.dhSelf
|
||||||
|
self.dhSelf = generateKeypair().get()[0]
|
||||||
|
info "dhRatchetSend new DH Self: ", dhSelf = self.dhSelf
|
||||||
let dhOutput : DhDerivedKey = dhExchange(self.dhSelf, self.dhRemote).get()
|
let dhOutput : DhDerivedKey = dhExchange(self.dhSelf, self.dhRemote).get()
|
||||||
let (newRootKey, newChainKeySend) = kdfRoot(self, self.rootKey, dhOutput)
|
let (newRootKey, newChainKeySend) = kdfRoot(self, self.rootKey, dhOutput)
|
||||||
self.rootKey = newRootKey
|
self.rootKey = newRootKey
|
||||||
@ -185,7 +187,7 @@ proc encrypt*(self: var Doubleratchet, plaintext: var seq[byte]) : (DrHeader, Ci
|
|||||||
encrypt(self, plaintext,@[])
|
encrypt(self, plaintext,@[])
|
||||||
|
|
||||||
|
|
||||||
proc initDoubleratchet*(sharedSecret: array[32, byte], dhSelf: PrivateKey, dhRemote: PublicKey, isSending: bool = true): Doubleratchet =
|
proc initDoubleratchet*(sharedSecret: array[32, byte], dhSelf: PrivateKey, dhRemote: PublicKey, inviter: bool = true): Doubleratchet =
|
||||||
|
|
||||||
info "Initializing Double Ratchet"
|
info "Initializing Double Ratchet"
|
||||||
info "DH Self: ", dhSelf = dhSelf
|
info "DH Self: ", dhSelf = dhSelf
|
||||||
@ -201,5 +203,5 @@ proc initDoubleratchet*(sharedSecret: array[32, byte], dhSelf: PrivateKey, dhRem
|
|||||||
skippedMessageKeys: initTable[(PublicKey, MsgCount), MessageKey]()
|
skippedMessageKeys: initTable[(PublicKey, MsgCount), MessageKey]()
|
||||||
)
|
)
|
||||||
|
|
||||||
if isSending:
|
if not inviter:
|
||||||
result.dhRatchetSend()
|
result.dhRatchetSend()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user