2025-07-05 14:54:19 -07:00
|
|
|
|
|
|
|
|
import crypto
|
2025-07-16 16:17:22 -07:00
|
|
|
import results
|
2025-07-05 14:54:19 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
Identity* = object
|
2025-09-15 00:42:07 -07:00
|
|
|
name*: string
|
|
|
|
|
privateKey*: PrivateKey # TODO: protect key exposure
|
2025-07-05 14:54:19 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#################################################
|
|
|
|
|
# Constructors
|
|
|
|
|
#################################################
|
|
|
|
|
|
|
|
|
|
proc createIdentity*(name: string): Identity =
|
2025-07-16 16:17:22 -07:00
|
|
|
let privKey = createRandomKey().get()
|
|
|
|
|
result = Identity(name: name, privateKey: privKey)
|
2025-07-05 14:54:19 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#################################################
|
|
|
|
|
# Parameter Access
|
|
|
|
|
#################################################
|
|
|
|
|
|
2025-07-16 16:17:22 -07:00
|
|
|
proc getPubkey*(self: Identity): PublicKey =
|
|
|
|
|
result = self.privateKey.getPublicKey()
|
2025-07-05 14:54:19 -07:00
|
|
|
|
2025-07-16 16:17:22 -07:00
|
|
|
proc getAddr*(self: Identity): string =
|
|
|
|
|
result = get_addr(self.getPubKey())
|
2025-07-05 14:54:19 -07:00
|
|
|
|
2025-08-15 07:31:19 -07:00
|
|
|
|
2025-12-10 23:59:37 -08:00
|
|
|
proc getName*(self: Identity): string =
|
2025-08-15 07:31:19 -07:00
|
|
|
result = self.name
|