Skip to content

Commit bbedd9a

Browse files
committed
Update tui
1 parent 6a149e2 commit bbedd9a

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

examples/tui/tui.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,17 @@ proc setupChatSdk(app: ChatApp) =
133133

134134
let client = app.client
135135

136-
app.client.onNewMessage(proc(convo: Conversation, msg: ContentFrame) {.async.} =
136+
app.client.onNewMessage(proc(convo: Conversation, msg: ReceivedMessage) {.async.} =
137137
info "New Message: ", convoId = convo.id(), msg= msg
138138
app.logMsgs.add(LogEntry(level: "info",ts: now(), msg: "NewMsg"))
139139

140-
var contentStr = case msg.contentType
140+
var contentStr = case msg.content.contentType
141141
of text:
142-
decode(msg.bytes, TextFrame).get().text
142+
decode(msg.content.bytes, TextFrame).get().text
143143
of unknown:
144144
"<Unhandled Message Type>"
145145

146-
app.conversations[convo.id()].messages.add(Message(sender: "???", content: contentStr, timestamp: now()))
146+
app.conversations[convo.id()].messages.add(Message(sender: msg.sender.toHex(), content: contentStr, timestamp: now()))
147147
)
148148

149149
app.client.onNewConversation(proc(convo: Conversation) {.async.} =

src/chat_sdk.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import chat_sdk/[
22
client,
3+
crypto,
34
conversations,
45
delivery/waku_client,
56
identity,
@@ -12,3 +13,5 @@ export client, conversations, identity, links, waku_client
1213

1314
#export specific frames need by applications
1415
export ContentFrame, MessageId
16+
17+
export toHex

src/chat_sdk/crypto.nim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ proc decrypt_plain*[T: EncryptableTypes](ciphertext: Plaintext, t: typedesc[
2626
proc generate_key*(): PrivateKey =
2727
createRandomKey().get()
2828

29+
30+
proc toHex*(key: PublicKey): string =
31+
bytesToHex(key.bytes())
32+
2933
proc `$`*(key: PublicKey): string =
30-
let byteStr = bytesToHex(key.bytes())
31-
fmt"{byteStr[0..3]}..{byteStr[^4 .. ^1]}"
34+
let byteStr = toHex(key)
35+
fmt"{byteStr[0..3]}..{byteStr[^4 .. ^1]}"

src/chat_sdk/crypto/ecdh.nim

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ import ../utils
77
type PrivateKey* = object
88
bytes: Curve25519Key
99

10-
# type PublicKey* = object
11-
# bytes: Curve25519Key
12-
1310
type PublicKey* = distinct Curve25519Key # TODO: define outside of ECDH
1411

1512

13+
proc bytes*(key: PublicKey): array[Curve25519KeySize, byte] =
14+
cast[array[Curve25519KeySize, byte]](key)
15+
16+
proc get_addr*(pubkey: PublicKey): string =
17+
# TODO: Needs Spec
18+
result = hash_func(pubkey.bytes().bytesToHex())
1619

1720

1821
proc bytes*(key: PrivateKey): Curve25519Key =
1922
return key.bytes
2023

21-
proc bytes*(key: PublicKey): array[Curve25519KeySize, byte] =
22-
cast[array[Curve25519KeySize, byte]](key)
24+
2325

2426
proc createRandomKey*(): Result[PrivateKey, string] =
2527
let rng = HmacDrbgContext.new()
@@ -54,8 +56,3 @@ proc Dh*(privateKey: PrivateKey, publicKey: PublicKey): Result[seq[
5456
return ok(outputKey.getBytes())
5557

5658

57-
proc get_addr*(pubkey: PublicKey): string =
58-
# TODO: Needs Spec
59-
result = hash_func(pubkey.bytes().bytesToHex())
60-
61-

0 commit comments

Comments
 (0)