diff --git a/src/app/global/utils.nim b/src/app/global/utils.nim index 5341620512..b0abe5156b 100644 --- a/src/app/global/utils.nim +++ b/src/app/global/utils.nim @@ -141,3 +141,6 @@ QtObject: proc getColorHashAsJson*(self: Utils, publicKey: string): string {.slot.} = procs_from_visual_identity_service.getColorHashAsJson(publicKey) + + proc getCompressedPk*(self: Utils, publicKey: string): string {.slot.} = + procs_from_accounts.compressPk(publicKey) diff --git a/src/app_service/service/accounts/service.nim b/src/app_service/service/accounts/service.nim index 3548a9b28e..3fc7474dd0 100644 --- a/src/app_service/service/accounts/service.nim +++ b/src/app_service/service/accounts/service.nim @@ -46,6 +46,16 @@ proc getImportedAccount*(self: Service): GeneratedAccountDto = proc isFirstTimeAccountLogin*(self: Service): bool = return self.isFirstTimeAccountLogin +proc compressPk*(publicKey: string): string = + try: + let response = status_account.compressPk(publicKey) + if(not response.error.isNil): + error "error compressPk: ", errDescription = response.error.message + result = response.result + + except Exception as e: + error "error: ", procName="compressPk", errName = e.name, errDesription = e.msg + proc generateAliasFromPk*(publicKey: string): string = return status_account.generateAlias(publicKey).result.getStr diff --git a/src/backend/accounts.nim b/src/backend/accounts.nim index c811005900..a744e7c054 100644 --- a/src/backend/accounts.nim +++ b/src/backend/accounts.nim @@ -1,4 +1,4 @@ -import json, json_serialization, chronicles, nimcrypto +import json, json_serialization, chronicles, nimcrypto, strutils import ./core, ./utils import ./response_type @@ -52,6 +52,22 @@ proc generateAddresses*(paths: seq[string]): RpcResponse[JsonNode] {.raises: [Ex error "error doing rpc request", methodName = "generateAddresses", exception=e.msg raise newException(RpcException, e.msg) +proc compressPk*(publicKey: string): RpcResponse[string] = + let secp256k1Code = "0xe701" + let base58btc = "z" + var multiCodecKey = publicKey + multiCodecKey.removePrefix("0x") + multiCodecKey.insert(secp256k1Code) + + let response = status_go.multiformatSerializePublicKey(multiCodecKey, base58btc) + + # json response indicates error + try: + let jsonReponse = parseJson(response) + result.error = RpcError(message: jsonReponse["error"].getStr()) + except JsonParsingError as e: + result.result = response + proc generateAlias*(publicKey: string): RpcResponse[JsonNode] {.raises: [Exception].} = try: let response = status_go.generateAlias(publicKey) diff --git a/ui/imports/utils/Utils.qml b/ui/imports/utils/Utils.qml index abb1ab7db4..c405ee5809 100644 --- a/ui/imports/utils/Utils.qml +++ b/ui/imports/utils/Utils.qml @@ -618,6 +618,21 @@ QtObject { return JSON.parse(jsonObj) } + function getCompressedPk(publicKey) { + if (publicKey === "") { + return "" + } + return globalUtils.getCompressedPk(publicKey) + } + + function getElidedCompressedPk(publicKey) { + if (publicKey === "") { + return "" + } + let compressedPk = getCompressedPk(publicKey) + return compressedPk.substr(3, 3) + "..." + compressedPk.substr(compressedPk.length - 3) + } + function getTimeDifference(d1, d2) { var timeString = "" var day1Year = d1.getFullYear()