Peer invitation refactor, Contact invitationId, Qrcode compression

This commit is contained in:
ycc
2022-11-27 21:08:34 +01:00
parent 2516b41597
commit 8195a22300
10 changed files with 466 additions and 128 deletions

View File

@ -2,10 +2,12 @@ package client
import (
"encoding/json"
"errors"
"io/ioutil"
"forge.redroom.link/yves/meowlib"
"github.com/ProtonMail/gopenpgp/v2/helper"
"github.com/google/uuid"
)
const key = "3pw0c8#6ZG8{75b5;3?fe80$2"
@ -31,30 +33,64 @@ func CreateIdentity(nickname string) *Identity {
return &id
}
func (id *Identity) InvitePeer(MyName string, ContactName string, MessageServerIdxs []int) (*Peer, *meowlib.ContactCard) {
func (id *Identity) InvitePeer(MyName string, ContactName string, MessageServerIdxs []int) *meowlib.ContactCard {
var peer Peer
var myContactCard meowlib.ContactCard
peer.Me = meowlib.NewKeyPair()
peer.EncryptionKp = meowlib.NewKeyPair()
peer.LookupKp = meowlib.NewKeyPair()
peer.MyIdentity = meowlib.NewKeyPair()
peer.MyEncryptionKp = meowlib.NewKeyPair()
peer.MyLookupKp = meowlib.NewKeyPair()
peer.Name = ContactName
peer.InvitationId = uuid.New().String()
for _, i := range MessageServerIdxs {
srv := id.MessageServers.Servers[i].ServerData
myContactCard.PullServers = append(myContactCard.PullServers, &srv)
}
myContactCard.Name = MyName
myContactCard.ContactPublicKey = peer.Me.Public
myContactCard.EncryptionPublicKey = peer.EncryptionKp.Public
myContactCard.LookupPublicKey = peer.LookupKp.Public
myContactCard.ContactPublicKey = peer.MyIdentity.Public
myContactCard.EncryptionPublicKey = peer.MyEncryptionKp.Public
myContactCard.LookupPublicKey = peer.MyLookupKp.Public
myContactCard.InvitationId = peer.InvitationId
id.Peers = append(id.Peers, peer)
return &myContactCard
}
func (id *Identity) AnswerInvitation(MyName string, ContactName string, MessageServerIdxs []int, ReceivedContact *meowlib.ContactCard) *meowlib.ContactCard {
var peer Peer
var myContactCard meowlib.ContactCard
peer.MyIdentity = meowlib.NewKeyPair()
peer.MyEncryptionKp = meowlib.NewKeyPair()
peer.MyLookupKp = meowlib.NewKeyPair()
if ContactName != "" {
peer.Name = ContactName
} else {
peer.Name = ReceivedContact.Name
}
peer.Contact = *ReceivedContact
for _, i := range MessageServerIdxs {
srv := id.MessageServers.Servers[i].ServerData
myContactCard.PullServers = append(myContactCard.PullServers, &srv)
}
myContactCard.Name = MyName
myContactCard.ContactPublicKey = peer.MyIdentity.Public
myContactCard.EncryptionPublicKey = peer.MyEncryptionKp.Public
myContactCard.LookupPublicKey = peer.MyLookupKp.Public
myContactCard.InvitationId = peer.InvitationId
id.Peers = append(id.Peers, peer)
return &id.Peers[len(id.Peers)-1], &myContactCard
return &myContactCard
}
func (*Identity) FinalizeInvitation(peer *Peer, ReceivedContact *meowlib.ContactCard) {
peer.Contact = *ReceivedContact
func (id *Identity) FinalizeInvitation(ReceivedContact *meowlib.ContactCard) error {
for i, p := range id.Peers {
if p.InvitationId == ReceivedContact.InvitationId {
id.Peers[i].Contact = *ReceivedContact
return nil
}
}
return errors.New("no matching contact found for invitationId " + ReceivedContact.InvitationId)
}
func LoadIdentity(file string) (*Identity, error) {