feat(@desktop/general): Use compressed community key in deep links
Issue #8001
This commit is contained in:
parent
e687dad3c7
commit
1f2a050695
|
@ -2,6 +2,8 @@ import NimQml, strutils, chronicles
|
||||||
import ../eventemitter
|
import ../eventemitter
|
||||||
|
|
||||||
import ../../global/app_signals
|
import ../../global/app_signals
|
||||||
|
import ../../../app_service/common/conversion
|
||||||
|
import ../../../app_service/service/accounts/utils
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "urls-manager"
|
topics = "urls-manager"
|
||||||
|
@ -44,6 +46,11 @@ QtObject:
|
||||||
result.protocolUriOnStart = protocolUriOnStart
|
result.protocolUriOnStart = protocolUriOnStart
|
||||||
result.loggedIn = false
|
result.loggedIn = false
|
||||||
|
|
||||||
|
proc prepareCommunityId(self: UrlsManager, communityId: string): string =
|
||||||
|
if isCompressedPubKey(communityId):
|
||||||
|
return changeCommunityKeyCompression(communityId)
|
||||||
|
return communityId
|
||||||
|
|
||||||
proc onUrlActivated*(self: UrlsManager, urlRaw: string) {.slot.} =
|
proc onUrlActivated*(self: UrlsManager, urlRaw: string) {.slot.} =
|
||||||
if not self.loggedIn:
|
if not self.loggedIn:
|
||||||
self.protocolUriOnStart = urlRaw
|
self.protocolUriOnStart = urlRaw
|
||||||
|
@ -62,7 +69,7 @@ QtObject:
|
||||||
# Open community with `community_key`
|
# Open community with `community_key`
|
||||||
elif url.startsWith(UriFormatCommunity):
|
elif url.startsWith(UriFormatCommunity):
|
||||||
data.action = StatusUrlAction.OpenCommunity
|
data.action = StatusUrlAction.OpenCommunity
|
||||||
data.communityId = url[UriFormatCommunity.len .. url.len-1]
|
data.communityId = self.prepareCommunityId(url[UriFormatCommunity.len .. url.len-1])
|
||||||
|
|
||||||
# Open community which has a channel with `channel_key` and makes that channel active
|
# Open community which has a channel with `channel_key` and makes that channel active
|
||||||
elif url.startsWith(UriFormatCommunityChannel):
|
elif url.startsWith(UriFormatCommunityChannel):
|
||||||
|
|
|
@ -151,5 +151,18 @@ QtObject:
|
||||||
proc getCompressedPk*(self: Utils, publicKey: string): string {.slot.} =
|
proc getCompressedPk*(self: Utils, publicKey: string): string {.slot.} =
|
||||||
compressPk(publicKey)
|
compressPk(publicKey)
|
||||||
|
|
||||||
|
proc getDecompressedPk*(self: Utils, compressedKey: string): string {.slot.} =
|
||||||
|
decompressPk(compressedKey)
|
||||||
|
|
||||||
|
proc decompressCommunityKey*(self: Utils, publicKey: string): string {.slot.} =
|
||||||
|
decompressCommunityKey(publicKey)
|
||||||
|
|
||||||
|
proc compressCommunityKey*(self: Utils, publicKey: string): string {.slot.} =
|
||||||
|
compressCommunityKey(publicKey)
|
||||||
|
|
||||||
proc isCompressedPubKey*(self: Utils, publicKey: string): bool {.slot.} =
|
proc isCompressedPubKey*(self: Utils, publicKey: string): bool {.slot.} =
|
||||||
conversion.isCompressedPubKey(publicKey)
|
conversion.isCompressedPubKey(publicKey)
|
||||||
|
|
||||||
|
# Changes publicKey compression between 33-bytes and multiformat zQ..
|
||||||
|
proc changeCommunityKeyCompression*(self: Utils, publicKey: string): string {.slot.} =
|
||||||
|
changeCommunityKeyCompression(publicKey)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import json
|
import json
|
||||||
import ../../../backend/accounts as status_account
|
import ../../../backend/accounts as status_account
|
||||||
|
import ../../common/conversion
|
||||||
|
|
||||||
proc compressPk*(publicKey: string): string =
|
proc compressPk*(publicKey: string): string =
|
||||||
try:
|
try:
|
||||||
|
@ -11,8 +12,49 @@ proc compressPk*(publicKey: string): string =
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
echo "error: `compressPk` " & $e.name & " msg: " & $e.msg
|
echo "error: `compressPk` " & $e.name & " msg: " & $e.msg
|
||||||
|
|
||||||
|
proc decompressPk*(compressedKey: string): string =
|
||||||
|
try:
|
||||||
|
let response = status_account.decompressPk(compressedKey)
|
||||||
|
if(not response.error.isNil):
|
||||||
|
echo "error decompressPk: " & response.error.message
|
||||||
|
result = response.result
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
echo "error: `decompressPk` " & $e.name & " msg: " & $e.msg
|
||||||
|
|
||||||
|
proc decompressCommunityKey*(publicKey: string): string =
|
||||||
|
try:
|
||||||
|
let response = status_account.decompressCommunityKey(publicKey)
|
||||||
|
if(not response.error.isNil):
|
||||||
|
echo "error decompressCommunityKey: " & response.error.message
|
||||||
|
result = response.result
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
echo "error: `decompressCommunityKey` " & $e.name & " msg: " & $e.msg
|
||||||
|
|
||||||
|
proc compressCommunityKey*(publicKey: string): string =
|
||||||
|
try:
|
||||||
|
let response = status_account.compressCommunityKey(publicKey)
|
||||||
|
if(not response.error.isNil):
|
||||||
|
echo "error compressCommunityKey: " & response.error.message
|
||||||
|
result = response.result
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
echo "error: `compressCommunityKey` " & $e.name & " msg: " & $e.msg
|
||||||
|
|
||||||
proc generateAliasFromPk*(publicKey: string): string =
|
proc generateAliasFromPk*(publicKey: string): string =
|
||||||
return status_account.generateAlias(publicKey).result.getStr
|
return status_account.generateAlias(publicKey).result.getStr
|
||||||
|
|
||||||
proc isAlias*(value: string): bool =
|
proc isAlias*(value: string): bool =
|
||||||
return status_account.isAlias(value)
|
return status_account.isAlias(value)
|
||||||
|
|
||||||
|
# Changes publicKey compression between 33-bytes and multiformat zQ..
|
||||||
|
proc changeCommunityKeyCompression*(publicKey: string): string =
|
||||||
|
if isCompressedPubKey(publicKey):
|
||||||
|
# is zQ
|
||||||
|
let uncompressedKey = decompressPk(publicKey)
|
||||||
|
return compressCommunityKey(uncompressedKey)
|
||||||
|
else:
|
||||||
|
# is 33-bytes
|
||||||
|
let uncompressedKey = decompressCommunityKey(publicKey)
|
||||||
|
return compressPk(uncompressedKey)
|
|
@ -90,6 +90,28 @@ proc decompressPk*(publicKey: string): RpcResponse[string] =
|
||||||
response.removePrefix(secp256k1Code)
|
response.removePrefix(secp256k1Code)
|
||||||
result.result = "0x" & response
|
result.result = "0x" & response
|
||||||
|
|
||||||
|
proc decompressCommunityKey*(publicKey: string): RpcResponse[string] =
|
||||||
|
|
||||||
|
let response = status_go.decompressPublicKey(publicKey)
|
||||||
|
|
||||||
|
# json response indicates error
|
||||||
|
try:
|
||||||
|
let jsonReponse = parseJson(response)
|
||||||
|
result.error = RpcError(message: jsonReponse["error"].getStr())
|
||||||
|
except JsonParsingError as e:
|
||||||
|
result.result = response
|
||||||
|
|
||||||
|
proc compressCommunityKey*(publicKey: string): RpcResponse[string] =
|
||||||
|
|
||||||
|
let response = status_go.compressPublicKey(publicKey)
|
||||||
|
|
||||||
|
# json response indicates error
|
||||||
|
try:
|
||||||
|
let jsonReponse = parseJson(response)
|
||||||
|
result.error = RpcError(message: jsonReponse["error"].getStr())
|
||||||
|
except JsonParsingError as e:
|
||||||
|
result.result = response
|
||||||
|
|
||||||
proc compressPk*(publicKey: string): RpcResponse[string] =
|
proc compressPk*(publicKey: string): RpcResponse[string] =
|
||||||
let secp256k1Code = "0xe701"
|
let secp256k1Code = "0xe701"
|
||||||
let base58btc = "z"
|
let base58btc = "z"
|
||||||
|
|
|
@ -86,11 +86,11 @@ ColumnLayout {
|
||||||
|
|
||||||
StatusDescriptionListItem {
|
StatusDescriptionListItem {
|
||||||
title: qsTr("Share community")
|
title: qsTr("Share community")
|
||||||
subTitle: `${Constants.communityLinkPrefix}${root.community && root.community.id.substring(0, 4)}...${root.community && root.community.id.substring(root.community.id.length -2)}`
|
subTitle: Utils.getCommunityShareLink(root.community.id, true)
|
||||||
tooltip.text: qsTr("Copied!")
|
tooltip.text: qsTr("Copied!")
|
||||||
asset.name: "copy"
|
asset.name: "copy"
|
||||||
iconButton.onClicked: {
|
iconButton.onClicked: {
|
||||||
let link = `${Constants.communityLinkPrefix}${root.community.id}`
|
let link = Utils.getCommunityShareLink(root.community.id)
|
||||||
root.rootStore.copyToClipboard(link)
|
root.rootStore.copyToClipboard(link)
|
||||||
tooltip.visible = !tooltip.visible
|
tooltip.visible = !tooltip.visible
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,11 +46,11 @@ Column {
|
||||||
|
|
||||||
StatusDescriptionListItem {
|
StatusDescriptionListItem {
|
||||||
title: qsTr("Share community")
|
title: qsTr("Share community")
|
||||||
subTitle: `${Constants.communityLinkPrefix}${root.community.id.substring(0, 4)}...${root.community.id.substring(root.community.id.length -2)}`
|
subTitle: Utils.getCommunityShareLink(root.community.id, true)
|
||||||
tooltip.text: qsTr("Copied!")
|
tooltip.text: qsTr("Copied!")
|
||||||
asset.name: "copy"
|
asset.name: "copy"
|
||||||
iconButton.onClicked: {
|
iconButton.onClicked: {
|
||||||
let link = `${Constants.communityLinkPrefix}${root.community.id}`
|
let link = Utils.getCommunityShareLink(root.community.id)
|
||||||
root.copyToClipboard(link);
|
root.copyToClipboard(link);
|
||||||
tooltip.visible = !tooltip.visible
|
tooltip.visible = !tooltip.visible
|
||||||
}
|
}
|
||||||
|
|
|
@ -388,15 +388,13 @@ QtObject {
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
// Community
|
// Community
|
||||||
let index = link.lastIndexOf("/c/")
|
const communityId = Utils.getCommunityIdFromShareLink(link)
|
||||||
if (index > -1) {
|
if (communityId !== "") {
|
||||||
const communityId = link.substring(index + 3)
|
|
||||||
|
|
||||||
const communityName = getSectionNameById(communityId)
|
const communityName = getSectionNameById(communityId)
|
||||||
|
|
||||||
if (!communityName) {
|
if (!communityName) {
|
||||||
// Unknown community, fetch the info if possible
|
// Unknown community, fetch the info if possible
|
||||||
communitiesModuleInst.requestCommunityInfo(communityId)
|
root.requestCommunityInfo(communityId)
|
||||||
result.communityId = communityId
|
result.communityId = communityId
|
||||||
result.fetching = true
|
result.fetching = true
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -608,6 +608,19 @@ QtObject {
|
||||||
return colorForColorId(pubKeyColorId)
|
return colorForColorId(pubKeyColorId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCommunityShareLink(communityId, elided = false) {
|
||||||
|
if (communityId === "") {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
let compressedPk = communityId
|
||||||
|
if (!globalUtilsInst.isCompressedPubKey(compressedPk)) {
|
||||||
|
compressedPk = globalUtilsInst.changeCommunityKeyCompression(compressedPk)
|
||||||
|
}
|
||||||
|
return Constants.communityLinkPrefix +
|
||||||
|
(elided ? StatusQUtils.Utils.elideText(compressedPk, 4, 2) : compressedPk)
|
||||||
|
}
|
||||||
|
|
||||||
function getChatKeyFromShareLink(link) {
|
function getChatKeyFromShareLink(link) {
|
||||||
let index = link.lastIndexOf("/u/")
|
let index = link.lastIndexOf("/u/")
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
|
@ -616,6 +629,19 @@ QtObject {
|
||||||
return link.substring(index + 3)
|
return link.substring(index + 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCommunityIdFromShareLink(link) {
|
||||||
|
let index = link.lastIndexOf("/c/")
|
||||||
|
if (index === -1) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
const communityKey = link.substring(index + 3)
|
||||||
|
if (globalUtilsInst.isCompressedPubKey(communityKey)) {
|
||||||
|
// is zQ.., need to be converted to standard compression
|
||||||
|
return globalUtilsInst.changeCommunityKeyCompression(communityKey)
|
||||||
|
}
|
||||||
|
return communityKey
|
||||||
|
}
|
||||||
|
|
||||||
function getCompressedPk(publicKey) {
|
function getCompressedPk(publicKey) {
|
||||||
if (publicKey === "") {
|
if (publicKey === "") {
|
||||||
return ""
|
return ""
|
||||||
|
|
Loading…
Reference in New Issue