Skip to content

Commit

Permalink
Find code pair client type and name from device props
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jul 18, 2023
1 parent 46ec444 commit efef6f1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mdtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func handleCmd(cmd string, args []string) {
log.Errorf("Usage: pair-phone <number>")
return
}
linkingCode, err := cli.PairPhone(args[0], true, whatsmeow.PairClientUnknown, "whatsmeow")
linkingCode, err := cli.PairPhone(args[0], true)
if err != nil {
panic(err)
}
Expand Down
30 changes: 29 additions & 1 deletion pair-code.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"golang.org/x/crypto/pbkdf2"

waBinary "go.mau.fi/whatsmeow/binary"
waProto "go.mau.fi/whatsmeow/binary/proto"
"go.mau.fi/whatsmeow/store"
"go.mau.fi/whatsmeow/types"
"go.mau.fi/whatsmeow/util/hkdfutil"
"go.mau.fi/whatsmeow/util/keys"
Expand All @@ -40,6 +42,29 @@ const (
PairClientOtherWebClient
)

func platformTypeToPairClientType(platformType waProto.DeviceProps_PlatformType) PairClientType {
switch platformType {
case waProto.DeviceProps_CHROME:
return PairClientChrome
case waProto.DeviceProps_EDGE:
return PairClientEdge
case waProto.DeviceProps_FIREFOX:
return PairClientFirefox
case waProto.DeviceProps_IE:
return PairClientIE
case waProto.DeviceProps_OPERA:
return PairClientOpera
case waProto.DeviceProps_SAFARI:
return PairClientSafari
case waProto.DeviceProps_DESKTOP:
return PairClientElectron
case waProto.DeviceProps_UWP:
return PairClientUWP
default:
return PairClientOtherWebClient
}
}

var notNumbers = regexp.MustCompile("[^0-9]")
var linkingBase32 = base32.NewEncoding("123456789ABCDEFGHJKLMNPQRSTVWXYZ")

Expand Down Expand Up @@ -67,7 +92,10 @@ func generateCompanionEphemeralKey() (ephemeralKeyPair *keys.KeyPair, ephemeralK
return
}

func (cli *Client) PairPhone(phone string, showPushNotification bool, clientType PairClientType, clientDisplayName string) (string, error) {
func (cli *Client) PairPhone(phone string, showPushNotification bool) (string, error) {
clientType := platformTypeToPairClientType(store.DeviceProps.GetPlatformType())
clientDisplayName := store.DeviceProps.GetOs()

ephemeralKeyPair, ephemeralKey, encodedLinkingCode := generateCompanionEphemeralKey()
phone = notNumbers.ReplaceAllString(phone, "")
jid := types.NewJID(phone, types.DefaultUserServer)
Expand Down

0 comments on commit efef6f1

Please sign in to comment.