diff --git a/libgm/client.go b/libgm/client.go index 931b9f0..f361da2 100644 --- a/libgm/client.go +++ b/libgm/client.go @@ -4,7 +4,6 @@ import ( "crypto/ecdsa" "crypto/rand" "crypto/sha256" - "encoding/base64" "fmt" "io" "net/http" @@ -14,7 +13,6 @@ import ( "github.com/google/uuid" "github.com/rs/zerolog" - "google.golang.org/protobuf/proto" "go.mau.fi/mautrix-gmessages/libgm/crypto" "go.mau.fi/mautrix-gmessages/libgm/events" @@ -133,34 +131,6 @@ func (c *Client) Connect() error { return nil } -func (c *Client) StartLogin() (string, error) { - registered, err := c.RegisterPhoneRelay() - if err != nil { - return "", err - } - c.AuthData.TachyonAuthToken = registered.AuthKeyData.TachyonAuthToken - go c.rpc.ListenReceiveMessages(false) - qr, err := c.GenerateQRCodeData(registered.GetPairingKey()) - if err != nil { - return "", fmt.Errorf("failed to generate QR code: %w", err) - } - return qr, nil -} - -func (c *Client) GenerateQRCodeData(pairingKey []byte) (string, error) { - urlData := &gmproto.URLData{ - PairingKey: pairingKey, - AESKey: c.AuthData.RequestCrypto.AESKey, - HMACKey: c.AuthData.RequestCrypto.HMACKey, - } - encodedURLData, err := proto.Marshal(urlData) - if err != nil { - return "", err - } - cData := base64.StdEncoding.EncodeToString(encodedURLData) - return util.QRCodeURLBase + cData, nil -} - func (c *Client) Disconnect() { c.rpc.CloseConnection() c.http.CloseIdleConnections() diff --git a/libgm/pair.go b/libgm/pair.go index 6275208..3e57189 100644 --- a/libgm/pair.go +++ b/libgm/pair.go @@ -3,6 +3,7 @@ package libgm import ( "bytes" "crypto/x509" + "encoding/base64" "fmt" "io" "net/http" @@ -15,6 +16,34 @@ import ( "go.mau.fi/mautrix-gmessages/libgm/util" ) +func (c *Client) StartLogin() (string, error) { + registered, err := c.RegisterPhoneRelay() + if err != nil { + return "", err + } + c.AuthData.TachyonAuthToken = registered.AuthKeyData.TachyonAuthToken + go c.rpc.ListenReceiveMessages(false) + qr, err := c.GenerateQRCodeData(registered.GetPairingKey()) + if err != nil { + return "", fmt.Errorf("failed to generate QR code: %w", err) + } + return qr, nil +} + +func (c *Client) GenerateQRCodeData(pairingKey []byte) (string, error) { + urlData := &gmproto.URLData{ + PairingKey: pairingKey, + AESKey: c.AuthData.RequestCrypto.AESKey, + HMACKey: c.AuthData.RequestCrypto.HMACKey, + } + encodedURLData, err := proto.Marshal(urlData) + if err != nil { + return "", err + } + cData := base64.StdEncoding.EncodeToString(encodedURLData) + return util.QRCodeURLBase + cData, nil +} + func (c *Client) handlePairingEvent(msg *IncomingRPCMessage) { switch evt := msg.Pair.Event.(type) { case *gmproto.RPCPairData_Paired: