cleaner invitation step messages
This commit is contained in:
@@ -3,28 +3,32 @@ package files
|
||||
import (
|
||||
"os"
|
||||
|
||||
"forge.redroom.link/yves/meowlib"
|
||||
"forge.redroom.link/yves/meowlib/client"
|
||||
"forge.redroom.link/yves/meowlib/client/invitation/messages"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// Step1Write creates a pending peer and writes the InvitationInitPayload to a file.
|
||||
// format: "qr" writes a QR-code PNG; anything else writes a compressed binary .mwiv file.
|
||||
func Step1Write(contactName string, myNickname string, invitationMessage string, serverUids []string, format string) (*client.Peer, error) {
|
||||
payload, peer, err := messages.Step1InitiatorCreatesInviteeAndTempKey(contactName, myNickname, invitationMessage, serverUids)
|
||||
func Step1Write(contactName string, myNickname string, invitationMessage string, serverUids []string, format string) error {
|
||||
payloadBytes, err := messages.Step1InitiatorCreatesInviteeAndTempKey(contactName, myNickname, invitationMessage, serverUids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
var payload meowlib.InvitationInitPayload
|
||||
if err := proto.Unmarshal(payloadBytes, &payload); err != nil {
|
||||
return err
|
||||
}
|
||||
mynick := myNickname
|
||||
if mynick == "" {
|
||||
mynick = client.GetConfig().GetIdentity().Nickname
|
||||
}
|
||||
c := client.GetConfig()
|
||||
if format == "qr" {
|
||||
filename := c.StoragePath + string(os.PathSeparator) + peer.MyName + "-" + peer.Name + ".png"
|
||||
if err := payload.WriteQr(filename); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
filename := c.StoragePath + string(os.PathSeparator) + peer.MyName + "-" + peer.Name + ".mwiv"
|
||||
if err := payload.WriteCompressed(filename); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
filename := c.StoragePath + string(os.PathSeparator) + mynick + "-" + contactName + ".png"
|
||||
return payload.WriteQr(filename)
|
||||
}
|
||||
return peer, nil
|
||||
filename := c.StoragePath + string(os.PathSeparator) + mynick + "-" + contactName + ".mwiv"
|
||||
return payload.WriteCompressed(filename)
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
)
|
||||
|
||||
// Step2ReadAndAnswer reads an InvitationInitPayload from a .mwiv file, creates the
|
||||
// invitee's peer entry, and writes the encrypted ContactCard (PackedUserMessage) to a
|
||||
// .mwiv file for the initiator to pick up and process in step 3.
|
||||
// invitee's peer entry, and writes the serialized Invitation (step=2) to a .mwiv file
|
||||
// for the initiator to pick up and process in step 3.
|
||||
func Step2ReadAndAnswer(invitationFile string, nickname string, myNickname string, serverUids []string) error {
|
||||
if _, err := os.Stat(invitationFile); os.IsNotExist(err) {
|
||||
return err
|
||||
@@ -29,35 +29,23 @@ func Step2ReadAndAnswer(invitationFile string, nickname string, myNickname strin
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
payloadBytes, err := proto.Marshal(payload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mynick := myNickname
|
||||
if mynick == "" {
|
||||
mynick = client.GetConfig().GetIdentity().Nickname
|
||||
}
|
||||
|
||||
packed, peer, err := messages.Step2InviteeCreatesInitiatorAndEncryptedContactCard(payload, nickname, mynick, serverUids)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Wrap the PackedUserMessage in an Invitation so the initiator (step3) has the
|
||||
// invitee's public key available for signature verification without an extra file.
|
||||
packedBytes, err := proto.Marshal(packed)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
invitation := &meowlib.Invitation{
|
||||
Uuid: peer.InvitationId,
|
||||
Step: 2,
|
||||
From: peer.MyIdentity.Public,
|
||||
Payload: packedBytes,
|
||||
}
|
||||
out, err := proto.Marshal(invitation)
|
||||
// messages.Step2 returns a serialized Invitation ready to write directly to file.
|
||||
invBytes, err := messages.Step2InviteeCreatesInitiatorAndEncryptedContactCard(payloadBytes, nickname, mynick, serverUids)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c := client.GetConfig()
|
||||
filename := c.StoragePath + string(os.PathSeparator) + mynick + "-" + nickname + ".mwiv"
|
||||
return os.WriteFile(filename, out, 0600)
|
||||
return os.WriteFile(filename, invBytes, 0600)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user