mirror of
https://github.com/logos-messaging/nim-chat-poc.git
synced 2026-01-02 14:13:10 +00:00
Added PrivateInvite for initiation testing
This commit is contained in:
parent
db47ffd5a4
commit
470590bb07
@ -3,5 +3,9 @@ syntax = "proto3";
|
||||
package umbra.invite;
|
||||
|
||||
message InvitePrivateV1 {
|
||||
repeated string participants = 1;
|
||||
bytes initiator = 1;
|
||||
bytes initiator_ephemeral = 2;
|
||||
bytes participant = 3;
|
||||
int32 participant_ephemeral_id= 4;
|
||||
string discriminator = 5;
|
||||
}
|
||||
|
||||
@ -33,13 +33,13 @@ type
|
||||
|
||||
|
||||
type
|
||||
Client* = object
|
||||
Client* = ref object
|
||||
ident: Identity
|
||||
key_store: Table[string, KeyEntry] # Keyed by HexEncoded Public Key
|
||||
conversations: Table[string, ConvoWrapper] # Keyed by conversation ID
|
||||
|
||||
|
||||
proc process_invite*(self: Client, invite: InvitePrivateV1)
|
||||
proc process_invite*(self: var Client, invite: InvitePrivateV1)
|
||||
|
||||
|
||||
#################################################
|
||||
@ -73,6 +73,11 @@ proc default_inbox_conversation_id*(self: Client): string =
|
||||
## Returns the default inbox address for the client.
|
||||
result = conversation_id_for(self.ident.getPubkey())
|
||||
|
||||
|
||||
proc getConversations*(self: Client): Table[string, ConvoWrapper] =
|
||||
## Returns the conversations table for the client.
|
||||
result = self.conversations
|
||||
|
||||
#################################################
|
||||
# Methods
|
||||
#################################################
|
||||
@ -115,7 +120,11 @@ proc createPrivateConvo*(self: Client, intro_bundle: IntroBundle): TransportMess
|
||||
let dst_convo_topic = topic_inbox(dest_pubkey.get_addr())
|
||||
|
||||
let invite = InvitePrivateV1(
|
||||
participants: @[self.ident.getAddr(), dest_pubkey.get_addr()],
|
||||
initiator: @(self.ident.getPubkey().toRawCompressed()),
|
||||
initiator_ephemeral: @[0, 0], # TODO: Add ephemeral
|
||||
participant: @(dest_pubkey.toRawCompressed()),
|
||||
participant_ephemeral_id: intro_bundle.ephemeral_id,
|
||||
discriminator: "test"
|
||||
)
|
||||
let env = wrap_env(encrypt(InboxV1Frame(invite_private_v1: invite,
|
||||
recipient: "")), convo_id)
|
||||
@ -171,5 +180,24 @@ proc recv*(self: var Client, transport_message: TransportMessage): seq[
|
||||
|
||||
|
||||
|
||||
proc process_invite*(self: Client, invite: InvitePrivateV1) =
|
||||
proc process_invite*(self: var Client, invite: InvitePrivateV1) =
|
||||
debug "Callback Invoked", invite = invite
|
||||
|
||||
# Does this match one of my accounts??
|
||||
|
||||
let convo = initPrivateV1(
|
||||
self.ident,
|
||||
PublicKey.fromRaw(invite.initiator).get(),
|
||||
# PublicKey.fromRaw(invite.initiator_ephemeral).get(),
|
||||
# invite.participant_ephemeral_id,
|
||||
invite.discriminator,
|
||||
)
|
||||
|
||||
info "Creating PrivateV1 conversation", topic = convo.get_topic
|
||||
self.conversations[convo.get_topic()] = ConvoWrapper(
|
||||
convo_type: PrivateV1Type,
|
||||
privateV1: convo
|
||||
)
|
||||
|
||||
echo self.conversations
|
||||
|
||||
|
||||
@ -1,4 +1,47 @@
|
||||
import ../identity
|
||||
import ../crypto
|
||||
import ../utils
|
||||
|
||||
import std/[sequtils, strutils]
|
||||
import std/algorithm
|
||||
import blake2
|
||||
import sugar
|
||||
|
||||
type
|
||||
PrivateV1* = object
|
||||
# Placeholder for PrivateV1 conversation type
|
||||
name*: string
|
||||
owner: Identity
|
||||
topic: string
|
||||
participants: seq[PublicKey]
|
||||
discriminator: string
|
||||
|
||||
proc get_topic*(self: PrivateV1): string =
|
||||
## Returns the topic for the PrivateV1 conversation.
|
||||
return self.topic
|
||||
|
||||
proc derive_topic(participants: seq[PublicKey], discriminator: string): string =
|
||||
## Derives a topic from the participants' public keys.
|
||||
# This is a placeholder implementation.
|
||||
var addrs = participants.map(x => x.get_addr());
|
||||
addrs.sort()
|
||||
addrs.add(discriminator)
|
||||
let raw = addrs.join("|")
|
||||
|
||||
return "/convo/private/" & getBlake2b(raw, 18, "")
|
||||
|
||||
|
||||
|
||||
|
||||
proc initPrivateV1*(owner: Identity, participant: PublicKey,
|
||||
discriminator: string = "default"): PrivateV1 =
|
||||
|
||||
var participants = @[owner.getPubkey(), participant];
|
||||
|
||||
return PrivateV1(
|
||||
owner: owner,
|
||||
topic: derive_topic(participants, discriminator),
|
||||
participants: participants,
|
||||
discriminator: discriminator
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ export secp256k1
|
||||
|
||||
|
||||
type KeyPair* = SkKeyPair
|
||||
|
||||
type PublicKey* = SkPublicKey
|
||||
|
||||
|
||||
proc encrypt_plain*[T: EncryptableTypes](frame: T): EncryptedPayload =
|
||||
|
||||
@ -40,6 +40,7 @@ type
|
||||
IntroBundle {.proto3.} = object
|
||||
ident* {.fieldNumber: 1.}: seq[byte]
|
||||
ephemeral* {.fieldNumber: 2.}: seq[byte]
|
||||
ephemeral_id* {.fieldNumber: 3.}: int32
|
||||
|
||||
|
||||
export IntroBundle
|
||||
@ -50,7 +51,7 @@ type
|
||||
topic* {.fieldNumber: 1.}: string
|
||||
payload* {.fieldNumber: 2.}: seq[byte]
|
||||
|
||||
|
||||
# Place holder for a transport channel
|
||||
proc sendTo*(topic: string, payload: seq[byte]): TransportMessage =
|
||||
result = TransportMessage(topic: topic, payload: payload)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user