logos-chat/src/chat/identity.nim
Jazz Turner-Baggs 3bfba7cf25
Libchat library Integration (#55)
* chore: add smoke test and redesign CI workflow (#62)

Add a smoke test that validates the binary links all dependencies
at runtime by instantiating a client without networking. Redesign
CI into separate build and test jobs, with test gated on build.

* Add libchat module

* Add Context

* Add libchat

* Update to latest libchat

* Remove stale files

* Bump to latest Libchat

* Update imports

* Update client

* Update library to work with Libchat

* Fix examples

* Remove Tui Examples - Replace with logos-core

* Add Indentity Todo

* fix: add `build-libchat` as dependency for examples, tests, and library (#59)

The Rust liblogos_chat.so was not being built automatically, causing
runtime failures when loading the shared library.

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Add Todo for Sender data

* Updated error log

---------

Co-authored-by: osmaczko <33099791+osmaczko@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-02-18 22:20:14 +01:00

45 lines
1.0 KiB
Nim

import crypto/ecdh
import results
import strformat
import utils
export PublicKey, PrivateKey, loadPrivateKeyFromBytes, loadPublicKeyFromBytes
type
Identity* = object
name*: string
privateKey*: PrivateKey # TODO: protect key exposure
#################################################
# Constructors
#################################################
proc createIdentity*(name: string): Identity =
let privKey = createRandomKey().get()
result = Identity(name: name, privateKey: privKey)
#################################################
# Parameter Access
#################################################
proc getPubkey*(self: Identity): PublicKey =
result = self.privateKey.getPublicKey()
proc getAddr*(self: Identity): string =
result = get_addr(self.getPubKey())
proc getName*(self: Identity): string =
result = self.name
proc toHex(key: PublicKey): string =
bytesToHex(key.bytes())
proc `$`*(key: PublicKey): string =
let byteStr = toHex(key)
fmt"{byteStr[0..3]}..{byteStr[^4 .. ^1]}"