Skip to content

feat: new deeplink status-im->status-app #4198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions protocol/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"math/rand"
"strings"
"time"

"github.com/status-im/status-go/deprecation"
Expand All @@ -16,6 +17,7 @@ import (
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/requests"
v1protocol "github.com/status-im/status-go/protocol/v1"
"github.com/status-im/status-go/services/utils"
)

var chatColors = []string{
Expand Down Expand Up @@ -501,18 +503,30 @@ func CreateCommunityChat(orgID, chatID string, orgChat *protobuf.CommunityChat,

func (c *Chat) DeepLink() string {
if c.OneToOne() {
return "status-im://p/" + c.ID
return "status-app://p/" + c.ID
}
if c.PrivateGroupChat() {
return "status-im://g/args?a2=" + c.ID
return "status-app://g/args?a2=" + c.ID
}

if c.CommunityChat() {
return "status-im://cc/" + c.ID
communityChannelID := strings.TrimPrefix(c.ID, c.CommunityID)
pubkey, err := types.DecodeHex(c.CommunityID)
if err != nil {
return ""
}

serializedCommunityID, err := utils.SerializePublicKey(pubkey)

if err != nil {
return ""
}

return "status-app://cc/" + communityChannelID + "#" + serializedCommunityID
}

if c.Public() {
return "status-im://" + c.ID
return "status-app://" + c.ID
}

return ""
Expand Down
10 changes: 10 additions & 0 deletions protocol/chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,13 @@ func (s *ChatTestSuite) TestUpdateFirstMessageTimestamp() {
setAndCheck(FirstMessageTimestampNoMessage, false, 200)
setAndCheck(100, true, 100)
}

func (s *ChatTestSuite) TestDeepLink() {
chat := &Chat{
CommunityID: "0x02b1188c997e666cd5505ffd5c4b5fdbe3084b78a486d8e709da3b32ad3708a89e",
ID: "0x02b1188c997e666cd5505ffd5c4b5fdbe3084b78a486d8e709da3b32ad3708a89ec432709e-fc73-440d-bb67-cb3a0929dfda",
ChatType: ChatTypeCommunityChat,
}

s.Require().Equal(chat.DeepLink(), "status-app://cc/c432709e-fc73-440d-bb67-cb3a0929dfda#zQ3shZL6dXiFCbDyxnXxwQa9v8QFC2q19subFtyxd7kVszMVo")
}
2 changes: 1 addition & 1 deletion protocol/local_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (n NotificationBody) toCommunityRequestToJoinNotification(id string) *local
Message: n.Contact.PrimaryName() + " wants to join message " + n.Community.Name(),
BodyType: localnotifications.TypeMessage,
Category: localnotifications.CategoryCommunityRequestToJoin,
Deeplink: "status-im://cr/" + n.Community.IDString(),
Deeplink: "status-app://cr/" + n.Community.IDString(),
Image: "",
}
}
16 changes: 1 addition & 15 deletions protocol/messenger_share_urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"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/types"
"github.com/status-im/status-go/protocol/common"
Expand Down Expand Up @@ -52,20 +51,7 @@ const baseShareURL = "https://status.app"
const channelUUIDRegExp = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$"

func (m *Messenger) SerializePublicKey(compressedKey types.HexBytes) (string, error) {
rawKey, err := crypto.DecompressPubkey(compressedKey)
if err != nil {
return "", err
}
pubKey := types.EncodeHex(crypto.FromECDSAPub(rawKey))

secp256k1Code := "0xe701"
base58btc := "z"
multiCodecKey := secp256k1Code + strings.TrimPrefix(pubKey, "0x")
cpk, err := multiformat.SerializePublicKey(multiCodecKey, base58btc)
if err != nil {
return "", err
}
return cpk, nil
return utils.SerializePublicKey(compressedKey)
}

func (m *Messenger) DeserializePublicKey(compressedKey string) (types.HexBytes, error) {
Expand Down
2 changes: 1 addition & 1 deletion services/local-notifications/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
type transactionState string

const (
walletDeeplinkPrefix = "status-im://wallet/"
walletDeeplinkPrefix = "status-app://wallet/"

failed transactionState = "failed"
inbound transactionState = "inbound"
Expand Down
17 changes: 17 additions & 0 deletions services/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,20 @@ func DeserializePublicKey(compressedKey string) (types.HexBytes, error) {

return crypto.CompressPubkey(pubKey), nil
}

func SerializePublicKey(compressedKey types.HexBytes) (string, error) {
rawKey, err := crypto.DecompressPubkey(compressedKey)
if err != nil {
return "", err
}
pubKey := types.EncodeHex(crypto.FromECDSAPub(rawKey))

secp256k1Code := "0xe701"
base58btc := "z"
multiCodecKey := secp256k1Code + strings.TrimPrefix(pubKey, "0x")
cpk, err := multiformat.SerializePublicKey(multiCodecKey, base58btc)
if err != nil {
return "", err
}
return cpk, nil
}