mirror of
https://github.com/logos-messaging/logos-chat.git
synced 2026-08-04 09:03:13 +00:00
Remove Identity files
This commit is contained in:
parent
fb1df125f5
commit
e5e88ec58e
@ -1,12 +1,10 @@
|
|||||||
import chat/[
|
import chat/[
|
||||||
client,
|
client,
|
||||||
delivery/waku_client,
|
delivery/waku_client,
|
||||||
identity,
|
|
||||||
types
|
types
|
||||||
]
|
]
|
||||||
|
|
||||||
export client, identity, waku_client
|
export client, waku_client
|
||||||
export identity.`$`
|
|
||||||
|
|
||||||
#export specific frames need by applications
|
#export specific frames need by applications
|
||||||
export MessageId
|
export MessageId
|
||||||
|
|||||||
@ -14,7 +14,6 @@ import # Foreign
|
|||||||
import #local
|
import #local
|
||||||
delivery/waku_client,
|
delivery/waku_client,
|
||||||
errors,
|
errors,
|
||||||
identity,
|
|
||||||
types,
|
types,
|
||||||
utils
|
utils
|
||||||
|
|
||||||
@ -53,12 +52,6 @@ type
|
|||||||
DeliveryAckCallback* = proc(conversation: Conversation,
|
DeliveryAckCallback* = proc(conversation: Conversation,
|
||||||
msgId: MessageId): Future[void] {.async.}
|
msgId: MessageId): Future[void] {.async.}
|
||||||
|
|
||||||
|
|
||||||
type KeyEntry* = object
|
|
||||||
keyType: string
|
|
||||||
privateKey: PrivateKey
|
|
||||||
timestamp: int64
|
|
||||||
|
|
||||||
type ChatClient* = ref object
|
type ChatClient* = ref object
|
||||||
libchatCtx: LibChat
|
libchatCtx: LibChat
|
||||||
ds*: WakuClient
|
ds*: WakuClient
|
||||||
|
|||||||
@ -1,61 +0,0 @@
|
|||||||
# Reference: https://github.com/vacp2p/mix/blob/main/src/curve25519.nim
|
|
||||||
|
|
||||||
|
|
||||||
import results
|
|
||||||
import bearssl/rand
|
|
||||||
import libp2p/crypto/curve25519
|
|
||||||
|
|
||||||
const FieldElementSize* = Curve25519KeySize
|
|
||||||
|
|
||||||
type FieldElement* = Curve25519Key
|
|
||||||
|
|
||||||
# Convert bytes to FieldElement
|
|
||||||
proc bytesToFieldElement*(bytes: openArray[byte]): Result[FieldElement, string] =
|
|
||||||
if bytes.len != FieldElementSize:
|
|
||||||
return err("Field element size must be 32 bytes")
|
|
||||||
ok(intoCurve25519Key(bytes))
|
|
||||||
|
|
||||||
# Convert FieldElement to bytes
|
|
||||||
proc fieldElementToBytes*(fe: FieldElement): seq[byte] =
|
|
||||||
fe.getBytes()
|
|
||||||
|
|
||||||
# Generate a random FieldElement
|
|
||||||
proc generateRandomFieldElement*(): Result[FieldElement, string] =
|
|
||||||
let rng = HmacDrbgContext.new()
|
|
||||||
if rng.isNil:
|
|
||||||
return err("Failed to creat HmacDrbgContext with system randomness")
|
|
||||||
ok(Curve25519Key.random(rng[]))
|
|
||||||
|
|
||||||
# Generate a key pair (private key and public key are both FieldElements)
|
|
||||||
proc generateKeyPair*(): Result[tuple[privateKey, publicKey: FieldElement], string] =
|
|
||||||
let privateKeyRes = generateRandomFieldElement()
|
|
||||||
if privateKeyRes.isErr:
|
|
||||||
return err(privateKeyRes.error)
|
|
||||||
let privateKey = privateKeyRes.get()
|
|
||||||
|
|
||||||
let publicKey = public(privateKey)
|
|
||||||
ok((privateKey, publicKey))
|
|
||||||
|
|
||||||
# Multiply a given Curve25519 point with a set of scalars
|
|
||||||
proc multiplyPointWithScalars*(
|
|
||||||
point: FieldElement, scalars: openArray[FieldElement]
|
|
||||||
): FieldElement =
|
|
||||||
var res = point
|
|
||||||
for scalar in scalars:
|
|
||||||
Curve25519.mul(res, scalar)
|
|
||||||
res
|
|
||||||
|
|
||||||
# Multiply the Curve25519 base point with a set of scalars
|
|
||||||
proc multiplyBasePointWithScalars*(
|
|
||||||
scalars: openArray[FieldElement]
|
|
||||||
): Result[FieldElement, string] =
|
|
||||||
if scalars.len <= 0:
|
|
||||||
return err("Atleast one scalar must be provided")
|
|
||||||
var res: FieldElement = public(scalars[0]) # Use the predefined base point
|
|
||||||
for i in 1 ..< scalars.len:
|
|
||||||
Curve25519.mul(res, scalars[i]) # Multiply with each scalar
|
|
||||||
ok(res)
|
|
||||||
|
|
||||||
# Compare two FieldElements
|
|
||||||
proc compareFieldElements*(a, b: FieldElement): bool =
|
|
||||||
a == b
|
|
||||||
@ -1,58 +0,0 @@
|
|||||||
import results
|
|
||||||
import libp2p/crypto/curve25519
|
|
||||||
import bearssl/rand
|
|
||||||
|
|
||||||
import ../utils
|
|
||||||
|
|
||||||
type PrivateKey* = 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 createRandomKey*(): Result[PrivateKey, string] =
|
|
||||||
let rng = HmacDrbgContext.new()
|
|
||||||
if rng.isNil:
|
|
||||||
return err("Failed to create HmacDrbgContext with system randomness")
|
|
||||||
ok(PrivateKey(bytes: Curve25519Key.random(rng[])))
|
|
||||||
|
|
||||||
proc loadPrivateKeyFromBytes*(bytes: openArray[byte]): Result[PrivateKey, string] =
|
|
||||||
if bytes.len != Curve25519KeySize:
|
|
||||||
return err("Private key size must be 32 bytes")
|
|
||||||
ok(PrivateKey(bytes: intoCurve25519Key(bytes)))
|
|
||||||
|
|
||||||
proc loadPublicKeyFromBytes*(bytes: openArray[byte]): Result[PublicKey, string] =
|
|
||||||
if bytes.len != Curve25519KeySize:
|
|
||||||
return err("Public key size must be 32 bytes")
|
|
||||||
ok(PublicKey(intoCurve25519Key(bytes)))
|
|
||||||
|
|
||||||
|
|
||||||
proc getPublicKey*(privateKey: PrivateKey): PublicKey =
|
|
||||||
PublicKey( public(privateKey.bytes))
|
|
||||||
|
|
||||||
|
|
||||||
proc Dh*(privateKey: PrivateKey, publicKey: PublicKey): Result[seq[
|
|
||||||
byte], string] =
|
|
||||||
|
|
||||||
var outputKey = publicKey.bytes
|
|
||||||
try:
|
|
||||||
Curve25519.mul(outputKey, privateKey.bytes)
|
|
||||||
except CatchableError as e:
|
|
||||||
return err("Failed to compute shared secret: " & e.msg)
|
|
||||||
|
|
||||||
return ok(outputKey.getBytes())
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,44 +0,0 @@
|
|||||||
|
|
||||||
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]}"
|
|
||||||
|
|
||||||
@ -1,3 +1,4 @@
|
|||||||
type MessageId* = string
|
type MessageId* = string
|
||||||
type Content* = seq[byte]
|
type Content* = seq[byte]
|
||||||
type ErrorType* = string
|
type ErrorType* = string
|
||||||
|
type PublicKey* = array[32, byte]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user