mirror of
https://github.com/logos-messaging/nim-chat-poc.git
synced 2026-01-02 14:13:10 +00:00
34 lines
744 B
Nim
34 lines
744 B
Nim
|
|
import crypto
|
|
import results
|
|
|
|
|
|
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
|