From 38218e38da2f6b83aa50caa9dd6342fe846f33a5 Mon Sep 17 00:00:00 2001 From: Jazz Turner-Baggs <473256+jazzz@users.noreply.github.com> Date: Wed, 15 Oct 2025 16:13:06 -0700 Subject: [PATCH] Update tui --- examples/tui/tui.nim | 8 ++++---- src/chat_sdk.nim | 3 +++ src/chat_sdk/crypto.nim | 8 ++++++-- src/chat_sdk/crypto/ecdh.nim | 17 +++++++---------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/examples/tui/tui.nim b/examples/tui/tui.nim index aed02b6..3b9cac9 100644 --- a/examples/tui/tui.nim +++ b/examples/tui/tui.nim @@ -133,17 +133,17 @@ proc setupChatSdk(app: ChatApp) = let client = app.client - app.client.onNewMessage(proc(convo: Conversation, msg: ContentFrame) {.async.} = + app.client.onNewMessage(proc(convo: Conversation, msg: ReceivedMessage) {.async.} = info "New Message: ", convoId = convo.id(), msg= msg app.logMsgs.add(LogEntry(level: "info",ts: now(), msg: "NewMsg")) - var contentStr = case msg.contentType + var contentStr = case msg.content.contentType of text: - decode(msg.bytes, TextFrame).get().text + decode(msg.content.bytes, TextFrame).get().text of unknown: "" - app.conversations[convo.id()].messages.add(Message(sender: "???", content: contentStr, timestamp: now())) + app.conversations[convo.id()].messages.add(Message(sender: msg.sender.toHex(), content: contentStr, timestamp: now())) ) app.client.onNewConversation(proc(convo: Conversation) {.async.} = diff --git a/src/chat_sdk.nim b/src/chat_sdk.nim index 0487404..de9b9ac 100644 --- a/src/chat_sdk.nim +++ b/src/chat_sdk.nim @@ -1,5 +1,6 @@ import chat_sdk/[ client, + crypto, conversations, delivery/waku_client, identity, @@ -12,3 +13,5 @@ export client, conversations, identity, links, waku_client #export specific frames need by applications export ContentFrame, MessageId + +export toHex diff --git a/src/chat_sdk/crypto.nim b/src/chat_sdk/crypto.nim index affccce..44e5aa3 100644 --- a/src/chat_sdk/crypto.nim +++ b/src/chat_sdk/crypto.nim @@ -26,6 +26,10 @@ proc decrypt_plain*[T: EncryptableTypes](ciphertext: Plaintext, t: typedesc[ proc generate_key*(): PrivateKey = createRandomKey().get() + +proc toHex*(key: PublicKey): string = + bytesToHex(key.bytes()) + proc `$`*(key: PublicKey): string = - let byteStr = bytesToHex(key.bytes()) - fmt"{byteStr[0..3]}..{byteStr[^4 .. ^1]}" \ No newline at end of file + let byteStr = toHex(key) + fmt"{byteStr[0..3]}..{byteStr[^4 .. ^1]}" diff --git a/src/chat_sdk/crypto/ecdh.nim b/src/chat_sdk/crypto/ecdh.nim index d8c51ee..8237fbe 100644 --- a/src/chat_sdk/crypto/ecdh.nim +++ b/src/chat_sdk/crypto/ecdh.nim @@ -7,19 +7,21 @@ import ../utils type PrivateKey* = object bytes: Curve25519Key -# type PublicKey* = object -# bytes: Curve25519Key - type PublicKey* = distinct Curve25519Key # TODO: define outside of ECDH +proc bytes*(key: PublicKey): array[Curve25519KeySize, byte] = + cast[array[Curve25519KeySize, byte]](key) + +proc get_addr*(pubkey: PublicKey): string = + # TODO: Needs Spec + result = hash_func(pubkey.bytes().bytesToHex()) proc bytes*(key: PrivateKey): Curve25519Key = return key.bytes -proc bytes*(key: PublicKey): array[Curve25519KeySize, byte] = - cast[array[Curve25519KeySize, byte]](key) + proc createRandomKey*(): Result[PrivateKey, string] = let rng = HmacDrbgContext.new() @@ -54,8 +56,3 @@ proc Dh*(privateKey: PrivateKey, publicKey: PublicKey): Result[seq[ return ok(outputKey.getBytes()) -proc get_addr*(pubkey: PublicKey): string = - # TODO: Needs Spec - result = hash_func(pubkey.bytes().bytesToHex()) - -