fix: correct parsing shared url without data (#4283)
This commit is contained in:
parent
de12ca885c
commit
a178d724b1
|
@ -14,6 +14,7 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
|
|
||||||
|
"github.com/status-im/status-go/api/multiformat"
|
||||||
"github.com/status-im/status-go/eth-node/crypto"
|
"github.com/status-im/status-go/eth-node/crypto"
|
||||||
"github.com/status-im/status-go/eth-node/types"
|
"github.com/status-im/status-go/eth-node/types"
|
||||||
"github.com/status-im/status-go/images"
|
"github.com/status-im/status-go/images"
|
||||||
|
@ -1299,6 +1300,14 @@ func (o *Community) IDString() string {
|
||||||
return types.EncodeHex(o.ID())
|
return types.EncodeHex(o.ID())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *Community) UncompressedIDString() string {
|
||||||
|
return types.EncodeHex(crypto.FromECDSAPub(o.config.ID))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *Community) SerializedID() (string, error) {
|
||||||
|
return multiformat.SerializeLegacyKey(o.UncompressedIDString())
|
||||||
|
}
|
||||||
|
|
||||||
func (o *Community) StatusUpdatesChannelID() string {
|
func (o *Community) StatusUpdatesChannelID() string {
|
||||||
return o.IDString() + "-ping"
|
return o.IDString() + "-ping"
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,7 @@ func (u *StatusUnfurler) Unfurl() (*common.StatusLinkPreview, error) {
|
||||||
preview := new(common.StatusLinkPreview)
|
preview := new(common.StatusLinkPreview)
|
||||||
preview.URL = u.url
|
preview.URL = u.url
|
||||||
|
|
||||||
resp, err := u.m.ParseSharedURL(u.url)
|
resp, err := ParseSharedURL(u.url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse shared url: %w", err)
|
return nil, fmt.Errorf("failed to parse shared url: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
|
||||||
|
"github.com/status-im/status-go/api/multiformat"
|
||||||
"github.com/status-im/status-go/eth-node/crypto"
|
"github.com/status-im/status-go/eth-node/crypto"
|
||||||
"github.com/status-im/status-go/eth-node/types"
|
"github.com/status-im/status-go/eth-node/types"
|
||||||
"github.com/status-im/status-go/protocol/common"
|
"github.com/status-im/status-go/protocol/common"
|
||||||
|
@ -64,51 +65,48 @@ const channelUUIDRegExp = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9
|
||||||
|
|
||||||
var channelRegExp = regexp.MustCompile(channelUUIDRegExp)
|
var channelRegExp = regexp.MustCompile(channelUUIDRegExp)
|
||||||
|
|
||||||
func (m *Messenger) SerializePublicKey(compressedKey types.HexBytes) (string, error) {
|
func decodeCommunityID(serialisedPublicKey string) (string, error) {
|
||||||
|
deserializedCommunityID, err := multiformat.DeserializeCompressedKey(serialisedPublicKey)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
communityID, err := common.HexToPubkey(deserializedCommunityID)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return types.EncodeHex(crypto.CompressPubkey(communityID)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func serializePublicKey(compressedKey types.HexBytes) (string, error) {
|
||||||
return utils.SerializePublicKey(compressedKey)
|
return utils.SerializePublicKey(compressedKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) DeserializePublicKey(compressedKey string) (types.HexBytes, error) {
|
func deserializePublicKey(compressedKey string) (types.HexBytes, error) {
|
||||||
return utils.DeserializePublicKey(compressedKey)
|
return utils.DeserializePublicKey(compressedKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) ShareCommunityURLWithChatKey(communityID types.HexBytes) (string, error) {
|
func (m *Messenger) ShareCommunityURLWithChatKey(communityID types.HexBytes) (string, error) {
|
||||||
shortKey, err := m.SerializePublicKey(communityID)
|
shortKey, err := serializePublicKey(communityID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s/c#%s", baseShareURL, shortKey), nil
|
return fmt.Sprintf("%s/c#%s", baseShareURL, shortKey), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) prepareCommunityData(community *communities.Community) *CommunityURLData {
|
func parseCommunityURLWithChatKey(urlData string) (*URLDataResponse, error) {
|
||||||
return &CommunityURLData{
|
communityID, err := decodeCommunityID(urlData)
|
||||||
DisplayName: community.Identity().DisplayName,
|
|
||||||
Description: community.DescriptionText(),
|
|
||||||
MembersCount: uint32(community.MembersCount()),
|
|
||||||
Color: community.Identity().GetColor(),
|
|
||||||
TagIndices: community.TagsIndices(),
|
|
||||||
CommunityID: community.IDString(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Messenger) parseCommunityURLWithChatKey(urlData string) (*URLDataResponse, error) {
|
|
||||||
communityID, err := m.DeserializePublicKey(urlData)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
community, err := m.GetCommunityByID(communityID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if community == nil {
|
|
||||||
return nil, fmt.Errorf("community with communityID %s not found", communityID)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &URLDataResponse{
|
return &URLDataResponse{
|
||||||
Community: m.prepareCommunityData(community),
|
Community: &CommunityURLData{
|
||||||
Shard: community.Shard(),
|
CommunityID: communityID,
|
||||||
|
TagIndices: []uint32{},
|
||||||
|
},
|
||||||
|
Shard: nil,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +134,7 @@ func (m *Messenger) prepareEncodedCommunityData(community *communities.Community
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
shortKey, err := m.SerializePublicKey(community.ID())
|
shortKey, err := serializePublicKey(community.ID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
|
@ -167,8 +165,8 @@ func (m *Messenger) ShareCommunityURLWithData(communityID types.HexBytes) (strin
|
||||||
return fmt.Sprintf("%s/c/%s#%s", baseShareURL, data, shortKey), nil
|
return fmt.Sprintf("%s/c/%s#%s", baseShareURL, data, shortKey), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) parseCommunityURLWithData(data string, chatKey string) (*URLDataResponse, error) {
|
func parseCommunityURLWithData(data string, chatKey string) (*URLDataResponse, error) {
|
||||||
communityID, err := m.DeserializePublicKey(chatKey)
|
communityID, err := deserializePublicKey(chatKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -208,7 +206,7 @@ func (m *Messenger) ShareCommunityChannelURLWithChatKey(request *requests.Commun
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
shortKey, err := m.SerializePublicKey(request.CommunityID)
|
shortKey, err := serializePublicKey(request.CommunityID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -225,16 +223,7 @@ func (m *Messenger) ShareCommunityChannelURLWithChatKey(request *requests.Commun
|
||||||
return fmt.Sprintf("%s/cc/%s#%s", baseShareURL, request.ChannelID, shortKey), nil
|
return fmt.Sprintf("%s/cc/%s#%s", baseShareURL, request.ChannelID, shortKey), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) prepareCommunityChannelData(channel *protobuf.CommunityChat) *CommunityChannelURLData {
|
func parseCommunityChannelURLWithChatKey(channelID string, publicKey string) (*URLDataResponse, error) {
|
||||||
return &CommunityChannelURLData{
|
|
||||||
Emoji: channel.Identity.Emoji,
|
|
||||||
DisplayName: channel.Identity.DisplayName,
|
|
||||||
Description: channel.Identity.Description,
|
|
||||||
Color: channel.Identity.Color,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Messenger) parseCommunityChannelURLWithChatKey(channelID string, publickKey string) (*URLDataResponse, error) {
|
|
||||||
valid, err := regexp.MatchString(channelUUIDRegExp, channelID)
|
valid, err := regexp.MatchString(channelUUIDRegExp, channelID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -244,29 +233,20 @@ func (m *Messenger) parseCommunityChannelURLWithChatKey(channelID string, public
|
||||||
return nil, fmt.Errorf("channelID should be UUID, got %s", channelID)
|
return nil, fmt.Errorf("channelID should be UUID, got %s", channelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
communityID, err := m.DeserializePublicKey(publickKey)
|
communityID, err := decodeCommunityID(publicKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
community, err := m.GetCommunityByID(communityID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if community == nil {
|
|
||||||
return nil, fmt.Errorf("community with communityID %s not found", communityID)
|
|
||||||
}
|
|
||||||
|
|
||||||
channel, ok := community.Chats()[channelID]
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("channel with channelID %s not found", channelID)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &URLDataResponse{
|
return &URLDataResponse{
|
||||||
Community: m.prepareCommunityData(community),
|
Community: &CommunityURLData{
|
||||||
Channel: m.prepareCommunityChannelData(channel),
|
CommunityID: communityID,
|
||||||
Shard: community.Shard(),
|
TagIndices: []uint32{},
|
||||||
|
},
|
||||||
|
Channel: &CommunityChannelURLData{
|
||||||
|
ChannelUUID: channelID,
|
||||||
|
},
|
||||||
|
Shard: nil,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,7 +283,7 @@ func (m *Messenger) prepareEncodedCommunityChannelData(community *communities.Co
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
shortKey, err := m.SerializePublicKey(community.ID())
|
shortKey, err := serializePublicKey(community.ID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
|
@ -347,8 +327,8 @@ func (m *Messenger) ShareCommunityChannelURLWithData(request *requests.Community
|
||||||
return fmt.Sprintf("%s/cc/%s#%s", baseShareURL, data, shortKey), nil
|
return fmt.Sprintf("%s/cc/%s#%s", baseShareURL, data, shortKey), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) parseCommunityChannelURLWithData(data string, chatKey string) (*URLDataResponse, error) {
|
func parseCommunityChannelURLWithData(data string, chatKey string) (*URLDataResponse, error) {
|
||||||
communityID, err := m.DeserializePublicKey(chatKey)
|
communityID, err := deserializePublicKey(chatKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -396,7 +376,7 @@ func (m *Messenger) ShareUserURLWithChatKey(contactID string) (string, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
shortKey, err := m.SerializePublicKey(crypto.CompressPubkey(publicKey))
|
shortKey, err := serializePublicKey(crypto.CompressPubkey(publicKey))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -404,14 +384,8 @@ func (m *Messenger) ShareUserURLWithChatKey(contactID string) (string, error) {
|
||||||
return fmt.Sprintf("%s/u#%s", baseShareURL, shortKey), nil
|
return fmt.Sprintf("%s/u#%s", baseShareURL, shortKey), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) prepareContactData(contact *Contact) *ContactURLData {
|
func parseUserURLWithChatKey(urlData string) (*URLDataResponse, error) {
|
||||||
return &ContactURLData{
|
pubKeyBytes, err := deserializePublicKey(urlData)
|
||||||
DisplayName: contact.DisplayName,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Messenger) parseUserURLWithChatKey(urlData string) (*URLDataResponse, error) {
|
|
||||||
pubKeyBytes, err := m.DeserializePublicKey(urlData)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -421,15 +395,15 @@ func (m *Messenger) parseUserURLWithChatKey(urlData string) (*URLDataResponse, e
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
contactID := common.PubkeyToHex(pubKey)
|
serializedPublicKey, err := multiformat.SerializeLegacyKey(common.PubkeyToHex(pubKey))
|
||||||
|
if err != nil {
|
||||||
contact := m.GetContactByID(contactID)
|
return nil, err
|
||||||
if contact == nil {
|
|
||||||
return nil, ErrContactNotFound
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &URLDataResponse{
|
return &URLDataResponse{
|
||||||
Contact: m.prepareContactData(contact),
|
Contact: &ContactURLData{
|
||||||
|
PublicKey: serializedPublicKey,
|
||||||
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -441,7 +415,7 @@ func (m *Messenger) ShareUserURLWithENS(contactID string) (string, error) {
|
||||||
return fmt.Sprintf("%s/u#%s", baseShareURL, contact.EnsName), nil
|
return fmt.Sprintf("%s/u#%s", baseShareURL, contact.EnsName), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) parseUserURLWithENS(ensName string) (*URLDataResponse, error) {
|
func parseUserURLWithENS(ensName string) (*URLDataResponse, error) {
|
||||||
// TODO: fetch contact by ens name
|
// TODO: fetch contact by ens name
|
||||||
return nil, fmt.Errorf("not implemented yet")
|
return nil, fmt.Errorf("not implemented yet")
|
||||||
}
|
}
|
||||||
|
@ -452,7 +426,7 @@ func (m *Messenger) prepareEncodedUserData(contact *Contact) (string, string, er
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
shortKey, err := m.SerializePublicKey(crypto.CompressPubkey(pk))
|
shortKey, err := serializePublicKey(crypto.CompressPubkey(pk))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
|
@ -498,7 +472,7 @@ func (m *Messenger) ShareUserURLWithData(contactID string) (string, error) {
|
||||||
return fmt.Sprintf("%s/u/%s#%s", baseShareURL, data, shortKey), nil
|
return fmt.Sprintf("%s/u/%s#%s", baseShareURL, data, shortKey), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) parseUserURLWithData(data string, chatKey string) (*URLDataResponse, error) {
|
func parseUserURLWithData(data string, chatKey string) (*URLDataResponse, error) {
|
||||||
urlData, err := urls.DecodeDataURL(data)
|
urlData, err := urls.DecodeDataURL(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -542,14 +516,14 @@ func splitSharedURLData(data string) (string, string, error) {
|
||||||
return contents[0], contents[1], nil
|
return contents[0], contents[1], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) ParseSharedURL(url string) (*URLDataResponse, error) {
|
func ParseSharedURL(url string) (*URLDataResponse, error) {
|
||||||
|
|
||||||
if strings.HasPrefix(url, sharedURLUserPrefix) {
|
if strings.HasPrefix(url, sharedURLUserPrefix) {
|
||||||
chatKey := strings.TrimPrefix(url, sharedURLUserPrefix)
|
chatKey := strings.TrimPrefix(url, sharedURLUserPrefix)
|
||||||
if strings.HasPrefix(chatKey, "zQ3sh") {
|
if strings.HasPrefix(chatKey, "zQ3sh") {
|
||||||
return m.parseUserURLWithChatKey(chatKey)
|
return parseUserURLWithChatKey(chatKey)
|
||||||
}
|
}
|
||||||
return m.parseUserURLWithENS(chatKey)
|
return parseUserURLWithENS(chatKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(url, sharedURLUserPrefixWithData) {
|
if strings.HasPrefix(url, sharedURLUserPrefixWithData) {
|
||||||
|
@ -558,12 +532,12 @@ func (m *Messenger) ParseSharedURL(url string) (*URLDataResponse, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m.parseUserURLWithData(encodedData, chatKey)
|
return parseUserURLWithData(encodedData, chatKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(url, sharedURLCommunityPrefix) {
|
if strings.HasPrefix(url, sharedURLCommunityPrefix) {
|
||||||
chatKey := strings.TrimPrefix(url, sharedURLCommunityPrefix)
|
chatKey := strings.TrimPrefix(url, sharedURLCommunityPrefix)
|
||||||
return m.parseCommunityURLWithChatKey(chatKey)
|
return parseCommunityURLWithChatKey(chatKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(url, sharedURLCommunityPrefixWithData) {
|
if strings.HasPrefix(url, sharedURLCommunityPrefixWithData) {
|
||||||
|
@ -572,7 +546,7 @@ func (m *Messenger) ParseSharedURL(url string) (*URLDataResponse, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m.parseCommunityURLWithData(encodedData, chatKey)
|
return parseCommunityURLWithData(encodedData, chatKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(url, sharedURLChannelPrefixWithData) {
|
if strings.HasPrefix(url, sharedURLChannelPrefixWithData) {
|
||||||
|
@ -583,9 +557,9 @@ func (m *Messenger) ParseSharedURL(url string) (*URLDataResponse, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if channelRegExp.MatchString(encodedData) {
|
if channelRegExp.MatchString(encodedData) {
|
||||||
return m.parseCommunityChannelURLWithChatKey(encodedData, chatKey)
|
return parseCommunityChannelURLWithChatKey(encodedData, chatKey)
|
||||||
}
|
}
|
||||||
return m.parseCommunityChannelURLWithData(encodedData, chatKey)
|
return parseCommunityChannelURLWithData(encodedData, chatKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("not a status shared url")
|
return nil, fmt.Errorf("not a status shared url")
|
||||||
|
|
|
@ -3,14 +3,13 @@ package protocol
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
|
"github.com/status-im/status-go/api/multiformat"
|
||||||
"github.com/status-im/status-go/eth-node/crypto"
|
"github.com/status-im/status-go/eth-node/crypto"
|
||||||
"github.com/status-im/status-go/eth-node/types"
|
"github.com/status-im/status-go/eth-node/types"
|
||||||
"github.com/status-im/status-go/protocol/common"
|
|
||||||
"github.com/status-im/status-go/protocol/communities"
|
"github.com/status-im/status-go/protocol/communities"
|
||||||
"github.com/status-im/status-go/protocol/protobuf"
|
"github.com/status-im/status-go/protocol/protobuf"
|
||||||
"github.com/status-im/status-go/protocol/requests"
|
"github.com/status-im/status-go/protocol/requests"
|
||||||
|
@ -121,27 +120,6 @@ func (s *MessengerShareUrlsSuite) TestDecodeEncodeDataURL() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerShareUrlsSuite) TestSerializePublicKey() {
|
|
||||||
key, err := crypto.GenerateKey()
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
serializedKey, err := s.m.SerializePublicKey(crypto.CompressPubkey(&key.PublicKey))
|
|
||||||
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().Len(serializedKey, 49)
|
|
||||||
s.Require().True(strings.HasPrefix(serializedKey, "zQ3sh"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *MessengerShareUrlsSuite) TestDeserializePublicKey() {
|
|
||||||
serializedKey := "zQ3shPyZJnxZK4Bwyx9QsaksNKDYTPmpwPvGSjMYVHoXHeEgB"
|
|
||||||
|
|
||||||
shortKey, err := s.m.DeserializePublicKey(serializedKey)
|
|
||||||
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().Len(shortKey, 33)
|
|
||||||
s.Require().True(strings.HasPrefix(shortKey.String(), "0x"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *MessengerShareUrlsSuite) TestParseWrongUrls() {
|
func (s *MessengerShareUrlsSuite) TestParseWrongUrls() {
|
||||||
const notStatusSharedURLError = "not a status shared url"
|
const notStatusSharedURLError = "not a status shared url"
|
||||||
badURLs := map[string]string{
|
badURLs := map[string]string{
|
||||||
|
@ -153,7 +131,7 @@ func (s *MessengerShareUrlsSuite) TestParseWrongUrls() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for url, expectedError := range badURLs {
|
for url, expectedError := range badURLs {
|
||||||
urlData, err := s.m.ParseSharedURL(url)
|
urlData, err := ParseSharedURL(url)
|
||||||
s.Require().Error(err)
|
s.Require().Error(err)
|
||||||
s.Require().Equal(err.Error(), expectedError)
|
s.Require().Equal(err.Error(), expectedError)
|
||||||
s.Require().Nil(urlData)
|
s.Require().Nil(urlData)
|
||||||
|
@ -228,31 +206,32 @@ func (s *MessengerShareUrlsSuite) TestShareCommunityURLWithChatKey() {
|
||||||
url, err := s.m.ShareCommunityURLWithChatKey(community.ID())
|
url, err := s.m.ShareCommunityURLWithChatKey(community.ID())
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
shortKey, err := s.m.SerializePublicKey(community.ID())
|
shortID, err := community.SerializedID()
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
expectedURL := fmt.Sprintf("%s/c#%s", baseShareURL, shortKey)
|
expectedURL := fmt.Sprintf("%s/c#%s", baseShareURL, shortID)
|
||||||
s.Require().Equal(expectedURL, url)
|
s.Require().Equal(expectedURL, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerShareUrlsSuite) TestParseCommunityURLWithChatKey() {
|
func (s *MessengerShareUrlsSuite) TestParseCommunityURLWithChatKey() {
|
||||||
community := s.createCommunity()
|
community := s.createCommunity()
|
||||||
|
|
||||||
shortKey, err := s.m.SerializePublicKey(community.ID())
|
shortID, err := community.SerializedID()
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
url := fmt.Sprintf("%s/c#%s", baseShareURL, shortKey)
|
url := fmt.Sprintf("%s/c#%s", baseShareURL, shortID)
|
||||||
|
|
||||||
urlData, err := s.m.ParseSharedURL(url)
|
urlData, err := ParseSharedURL(url)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(urlData)
|
s.Require().NotNil(urlData)
|
||||||
|
|
||||||
s.Require().NotNil(urlData.Community)
|
s.Require().NotNil(urlData.Community)
|
||||||
s.Require().Equal(community.Identity().DisplayName, urlData.Community.DisplayName)
|
s.Require().Equal(community.IDString(), urlData.Community.CommunityID)
|
||||||
s.Require().Equal(community.DescriptionText(), urlData.Community.Description)
|
s.Require().Equal("", urlData.Community.DisplayName)
|
||||||
s.Require().Equal(uint32(community.MembersCount()), urlData.Community.MembersCount)
|
s.Require().Equal("", urlData.Community.Description)
|
||||||
s.Require().Equal(community.Identity().GetColor(), urlData.Community.Color)
|
s.Require().Equal(uint32(0), urlData.Community.MembersCount)
|
||||||
s.Require().Equal(community.TagsIndices(), urlData.Community.TagIndices)
|
s.Require().Equal("", urlData.Community.Color)
|
||||||
|
s.Require().Equal([]uint32{}, urlData.Community.TagIndices)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerShareUrlsSuite) TestShareCommunityURLWithData() {
|
func (s *MessengerShareUrlsSuite) TestShareCommunityURLWithData() {
|
||||||
|
@ -269,7 +248,7 @@ func (s *MessengerShareUrlsSuite) TestShareCommunityURLWithData() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerShareUrlsSuite) TestParseCommunityURLWithData() {
|
func (s *MessengerShareUrlsSuite) TestParseCommunityURLWithData() {
|
||||||
urlData, err := s.m.ParseSharedURL(communityURLWithData)
|
urlData, err := ParseSharedURL(communityURLWithData)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(urlData)
|
s.Require().NotNil(urlData)
|
||||||
|
|
||||||
|
@ -288,7 +267,7 @@ func (s *MessengerShareUrlsSuite) TestShareAndParseCommunityURLWithData() {
|
||||||
url, err := s.m.ShareCommunityURLWithData(community.ID())
|
url, err := s.m.ShareCommunityURLWithData(community.ID())
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
urlData, err := s.m.ParseSharedURL(url)
|
urlData, err := ParseSharedURL(url)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
s.Require().Equal(community.Identity().DisplayName, urlData.Community.DisplayName)
|
s.Require().Equal(community.Identity().DisplayName, urlData.Community.DisplayName)
|
||||||
|
@ -309,36 +288,34 @@ func (s *MessengerShareUrlsSuite) TestShareCommunityChannelURLWithChatKey() {
|
||||||
url, err := s.m.ShareCommunityChannelURLWithChatKey(request)
|
url, err := s.m.ShareCommunityChannelURLWithChatKey(request)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
shortKey, err := s.m.SerializePublicKey(community.ID())
|
shortID, err := community.SerializedID()
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
expectedURL := fmt.Sprintf("%s/cc/%s#%s", baseShareURL, channelID, shortKey)
|
expectedURL := fmt.Sprintf("%s/cc/%s#%s", baseShareURL, channelID, shortID)
|
||||||
s.Require().Equal(expectedURL, url)
|
s.Require().Equal(expectedURL, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerShareUrlsSuite) TestParseCommunityChannelURLWithChatKey() {
|
func (s *MessengerShareUrlsSuite) TestParseCommunityChannelURLWithChatKey() {
|
||||||
community, channel, channelID := s.createCommunityWithChannel()
|
const channelUUID = "003cdcd5-e065-48f9-b166-b1a94ac75a11"
|
||||||
|
const communityID = "0x02a3d2fdb9ac335917bf9d46b38d7496c00bbfadbaf832e8aa61d13ac2b4452084"
|
||||||
|
|
||||||
shortKey, err := s.m.SerializePublicKey(community.ID())
|
urlData, err := ParseSharedURL(channelURL)
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
url := fmt.Sprintf("%s/cc/%s#%s", baseShareURL, channelID, shortKey)
|
|
||||||
|
|
||||||
urlData, err := s.m.ParseSharedURL(url)
|
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(urlData)
|
s.Require().NotNil(urlData)
|
||||||
|
|
||||||
s.Require().NotNil(urlData.Community)
|
s.Require().NotNil(urlData.Community)
|
||||||
s.Require().Equal(community.Identity().DisplayName, urlData.Community.DisplayName)
|
s.Require().Equal(communityID, urlData.Community.CommunityID)
|
||||||
s.Require().Equal(community.DescriptionText(), urlData.Community.Description)
|
s.Require().Equal("", urlData.Community.DisplayName)
|
||||||
s.Require().Equal(uint32(community.MembersCount()), urlData.Community.MembersCount)
|
s.Require().Equal("", urlData.Community.Description)
|
||||||
s.Require().Equal(community.Identity().GetColor(), urlData.Community.Color)
|
s.Require().Equal(uint32(0), urlData.Community.MembersCount)
|
||||||
s.Require().Equal(community.TagsIndices(), urlData.Community.TagIndices)
|
s.Require().Equal("", urlData.Community.Color)
|
||||||
|
s.Require().Equal([]uint32{}, urlData.Community.TagIndices)
|
||||||
|
|
||||||
s.Require().NotNil(urlData.Channel)
|
s.Require().NotNil(urlData.Channel)
|
||||||
s.Require().Equal(channel.Identity.Emoji, urlData.Channel.Emoji)
|
s.Require().Equal(channelUUID, urlData.Channel.ChannelUUID)
|
||||||
s.Require().Equal(channel.Identity.DisplayName, urlData.Channel.DisplayName)
|
s.Require().Equal("", urlData.Channel.Emoji)
|
||||||
s.Require().Equal(channel.Identity.Color, urlData.Channel.Color)
|
s.Require().Equal("", urlData.Channel.DisplayName)
|
||||||
|
s.Require().Equal("", urlData.Channel.Color)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerShareUrlsSuite) TestShareCommunityChannelURLWithData() {
|
func (s *MessengerShareUrlsSuite) TestShareCommunityChannelURLWithData() {
|
||||||
|
@ -359,7 +336,7 @@ func (s *MessengerShareUrlsSuite) TestShareCommunityChannelURLWithData() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerShareUrlsSuite) TestParseCommunityChannelURLWithData() {
|
func (s *MessengerShareUrlsSuite) TestParseCommunityChannelURLWithData() {
|
||||||
urlData, err := s.m.ParseSharedURL(channelURLWithData)
|
urlData, err := ParseSharedURL(channelURLWithData)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(urlData)
|
s.Require().NotNil(urlData)
|
||||||
|
|
||||||
|
@ -382,7 +359,7 @@ func (s *MessengerShareUrlsSuite) TestShareAndParseCommunityChannelURLWithData()
|
||||||
url, err := s.m.ShareCommunityChannelURLWithData(request)
|
url, err := s.m.ShareCommunityChannelURLWithData(request)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
urlData, err := s.m.ParseSharedURL(url)
|
urlData, err := ParseSharedURL(url)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
s.Require().Equal(community.Identity().DisplayName, urlData.Community.DisplayName)
|
s.Require().Equal(community.Identity().DisplayName, urlData.Community.DisplayName)
|
||||||
|
@ -403,10 +380,7 @@ func (s *MessengerShareUrlsSuite) TestShareUserURLWithChatKey() {
|
||||||
url, err := s.m.ShareUserURLWithChatKey(contact.ID)
|
url, err := s.m.ShareUserURLWithChatKey(contact.ID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
publicKey, err := common.HexToPubkey(contact.ID)
|
shortKey, err := multiformat.SerializeLegacyKey(contact.ID)
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
shortKey, err := s.m.SerializePublicKey(crypto.CompressPubkey(publicKey))
|
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
expectedURL := fmt.Sprintf("%s/u#%s", baseShareURL, shortKey)
|
expectedURL := fmt.Sprintf("%s/u#%s", baseShareURL, shortKey)
|
||||||
|
@ -414,23 +388,13 @@ func (s *MessengerShareUrlsSuite) TestShareUserURLWithChatKey() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerShareUrlsSuite) TestParseUserURLWithChatKey() {
|
func (s *MessengerShareUrlsSuite) TestParseUserURLWithChatKey() {
|
||||||
_, contact := s.createContact()
|
urlData, err := ParseSharedURL(userURL)
|
||||||
|
|
||||||
publicKey, err := common.HexToPubkey(contact.ID)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
shortKey, err := s.m.SerializePublicKey(crypto.CompressPubkey(publicKey))
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
url := fmt.Sprintf("%s/u#%s", baseShareURL, shortKey)
|
|
||||||
|
|
||||||
urlData, err := s.m.ParseSharedURL(url)
|
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(urlData)
|
s.Require().NotNil(urlData)
|
||||||
|
|
||||||
s.Require().NotNil(urlData.Contact)
|
s.Require().NotNil(urlData.Contact)
|
||||||
s.Require().Equal(contact.DisplayName, urlData.Contact.DisplayName)
|
s.Require().Equal("", urlData.Contact.DisplayName)
|
||||||
s.Require().Equal(contact.Bio, urlData.Contact.Description)
|
s.Require().Equal("", urlData.Contact.Description)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerShareUrlsSuite) TestShareUserURLWithENS() {
|
func (s *MessengerShareUrlsSuite) TestShareUserURLWithENS() {
|
||||||
|
@ -449,7 +413,7 @@ func (s *MessengerShareUrlsSuite) TestShareUserURLWithENS() {
|
||||||
|
|
||||||
// url := fmt.Sprintf("%s/u#%s", baseShareURL, contact.EnsName)
|
// url := fmt.Sprintf("%s/u#%s", baseShareURL, contact.EnsName)
|
||||||
|
|
||||||
// urlData, err := s.m.ParseSharedURL(url)
|
// urlData, err := ParseSharedURL(url)
|
||||||
// s.Require().NoError(err)
|
// s.Require().NoError(err)
|
||||||
// s.Require().NotNil(urlData)
|
// s.Require().NotNil(urlData)
|
||||||
|
|
||||||
|
@ -459,7 +423,7 @@ func (s *MessengerShareUrlsSuite) TestShareUserURLWithENS() {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
func (s *MessengerShareUrlsSuite) TestParseUserURLWithData() {
|
func (s *MessengerShareUrlsSuite) TestParseUserURLWithData() {
|
||||||
urlData, err := s.m.ParseSharedURL(userURLWithData)
|
urlData, err := ParseSharedURL(userURLWithData)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NotNil(urlData)
|
s.Require().NotNil(urlData)
|
||||||
|
|
||||||
|
@ -484,16 +448,14 @@ func (s *MessengerShareUrlsSuite) TestShareUserURLWithData() {
|
||||||
|
|
||||||
func (s *MessengerShareUrlsSuite) TestShareAndParseUserURLWithData() {
|
func (s *MessengerShareUrlsSuite) TestShareAndParseUserURLWithData() {
|
||||||
_, contact := s.createContact()
|
_, contact := s.createContact()
|
||||||
pk, err := contact.PublicKey()
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
shortKey, err := s.m.SerializePublicKey(crypto.CompressPubkey(pk))
|
shortKey, err := multiformat.SerializeLegacyKey(contact.ID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
url, err := s.m.ShareUserURLWithData(contact.ID)
|
url, err := s.m.ShareUserURLWithData(contact.ID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
urlData, err := s.m.ParseSharedURL(url)
|
urlData, err := ParseSharedURL(url)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
s.Require().NotNil(urlData.Contact)
|
s.Require().NotNil(urlData.Contact)
|
||||||
|
|
|
@ -1,15 +1,9 @@
|
||||||
package requests
|
package requests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/status-im/status-go/eth-node/types"
|
"github.com/status-im/status-go/eth-node/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
ErrCommunityChannelShareURLCommunityInvalidID = errors.New("check-permission-to-join-community: invalid id")
|
|
||||||
)
|
|
||||||
|
|
||||||
type CommunityChannelShareURL struct {
|
type CommunityChannelShareURL struct {
|
||||||
CommunityID types.HexBytes
|
CommunityID types.HexBytes
|
||||||
ChannelID string
|
ChannelID string
|
||||||
|
|
|
@ -1560,7 +1560,7 @@ func (api *PublicAPI) ShareUserURLWithData(pubKey string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PublicAPI) ParseSharedURL(url string) (*protocol.URLDataResponse, error) {
|
func (api *PublicAPI) ParseSharedURL(url string) (*protocol.URLDataResponse, error) {
|
||||||
return api.service.messenger.ParseSharedURL(url)
|
return protocol.ParseSharedURL(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PublicAPI) Messenger() *protocol.Messenger {
|
func (api *PublicAPI) Messenger() *protocol.Messenger {
|
||||||
|
|
Loading…
Reference in New Issue