Files

48 lines
1.5 KiB
Go
Raw Permalink Normal View History

2026-04-11 22:05:30 +02:00
package messages
import (
"forge.redroom.link/yves/meowlib"
"forge.redroom.link/yves/meowlib/client"
2026-04-14 19:12:09 +02:00
"google.golang.org/protobuf/proto"
2026-04-11 22:05:30 +02:00
)
2026-04-14 19:12:09 +02:00
// Step2InviteeCreatesInitiatorAndEncryptedContactCard deserialises the step-1 payload bytes,
// creates the invitee's peer entry, builds and encrypts the invitee's ContactCard, and returns
// a serialized Invitation (step=2) whose Payload is the PackedUserMessage encrypted with the
// initiator's temporary public key. The bytes are transport-ready and consumed directly by
// Step3InitiatorFinalizesInviteeAndCreatesContactCard.
func Step2InviteeCreatesInitiatorAndEncryptedContactCard(payloadBytes []byte, nickname string, myNickname string, serverUids []string) ([]byte, error) {
2026-04-11 22:05:30 +02:00
mynick := myNickname
if mynick == "" {
mynick = client.GetConfig().GetIdentity().Nickname
}
2026-04-14 19:12:09 +02:00
var payload meowlib.InvitationInitPayload
if err := proto.Unmarshal(payloadBytes, &payload); err != nil {
return nil, err
}
peer, err := client.GetConfig().GetIdentity().InvitationStep2(mynick, nickname, serverUids, &payload)
2026-04-11 22:05:30 +02:00
if err != nil {
2026-04-14 19:12:09 +02:00
return nil, err
2026-04-12 13:38:15 +02:00
}
usermsg, err := peer.BuildInvitationStep2Message(peer.GetMyContact())
if err != nil {
2026-04-14 19:12:09 +02:00
return nil, err
2026-04-12 13:38:15 +02:00
}
packed, err := peer.ProcessOutboundUserMessage(usermsg)
if err != nil {
2026-04-14 19:12:09 +02:00
return nil, err
}
packedBytes, err := proto.Marshal(packed)
if err != nil {
return nil, err
}
inv := &meowlib.Invitation{
Uuid: payload.Uuid,
Step: 2,
From: peer.MyIdentity.Public,
Payload: packedBytes,
2026-04-11 22:05:30 +02:00
}
client.GetConfig().GetIdentity().Save()
2026-04-14 19:12:09 +02:00
return proto.Marshal(inv)
2026-04-11 22:05:30 +02:00
}