package payload import ( "go.mau.fi/mautrix-gmessages/libgm/binary" "go.mau.fi/mautrix-gmessages/libgm/crypto" "go.mau.fi/mautrix-gmessages/libgm/util" ) func RegisterPhoneRelay(jwk *crypto.JWK) ([]byte, *binary.AuthenticationContainer, error) { id := util.RandomUUIDv4() encryptedKeys, encryptErr := uncompressKey(jwk) if encryptErr != nil { return nil, nil, encryptErr } payloadData := &binary.AuthenticationContainer{ AuthMessage: &binary.AuthenticationMessage{ RequestID: id, Network: Network, ConfigVersion: ConfigMessage, }, BrowserDetails: BrowserDetailsMessage, Data: &binary.AuthenticationContainer_KeyData{ KeyData: &binary.KeyData{ EcdsaKeys: &binary.ECDSAKeys{ Field1: 2, EncryptedKeys: encryptedKeys, }, }, }, } encoded, err4 := binary.EncodeProtoMessage(payloadData) if err4 != nil { return nil, payloadData, err4 } return encoded, payloadData, nil } func uncompressKey(jwk *crypto.JWK) ([]byte, error) { decodedPrivateKey, err2 := jwk.PrivKeyB64Bytes() if err2 != nil { return nil, err2 } jwk.PrivateBytes = decodedPrivateKey uncompressedPublicKey, err3 := jwk.UncompressPubKey() if err3 != nil { return nil, err3 } var emptyByteArray []byte crypto.EncodeValues(&emptyByteArray, crypto.SequenceOne) crypto.EncodeValues(&emptyByteArray, crypto.SequenceTwo) var copiedByteArray []byte copiedByteArray = crypto.AppendByteSequence(copiedByteArray, emptyByteArray, uncompressedPublicKey) for _, value := range uncompressedPublicKey { copiedByteArray = crypto.HelperAppendBytes(copiedByteArray, value) } var encryptedKeys []byte encryptedKeys = crypto.AppendBytes(encryptedKeys, copiedByteArray[0:]) return encryptedKeys, nil }