Update tui

This commit is contained in:
Jazz Turner-Baggs 2025-10-15 16:13:06 -07:00
parent e76556dc39
commit 38218e38da
4 changed files with 20 additions and 16 deletions

View File

@ -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:
"<Unhandled Message Type>"
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.} =

View File

@ -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

View File

@ -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]}"
let byteStr = toHex(key)
fmt"{byteStr[0..3]}..{byteStr[^4 .. ^1]}"

View File

@ -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())