From 0a13940742e15a3a7c9f2e0bee6c7cc0ad4474b2 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 27 Oct 2020 12:49:55 -0400 Subject: [PATCH] fix: signatures --- src/app/utilsView/view.nim | 3 +++ ui/app/AppLayouts/Browser/BrowserLayout.qml | 13 +++++++++++++ ui/app/AppLayouts/Browser/SignMessageModal.qml | 15 ++++++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/app/utilsView/view.nim b/src/app/utilsView/view.nim index e4cddf08bf..0b01b0c7fa 100644 --- a/src/app/utilsView/view.nim +++ b/src/app/utilsView/view.nim @@ -73,6 +73,9 @@ QtObject: proc hex2Ascii*(self: UtilsView, value: string): string {.slot.} = result = string.fromBytes(hexToSeqByte(value)) + proc ascii2Hex*(self: UtilsView, value: string): string {.slot.} = + result = "0x" & toHex(value) + proc hex2Eth*(self: UtilsView, value: string): string {.slot.} = return stripTrailingZeroes(status_utils.wei2Eth(stint.fromHex(StUint[256], value))) diff --git a/ui/app/AppLayouts/Browser/BrowserLayout.qml b/ui/app/AppLayouts/Browser/BrowserLayout.qml index df6fafe9e3..ba5cb40995 100644 --- a/ui/app/AppLayouts/Browser/BrowserLayout.qml +++ b/ui/app/AppLayouts/Browser/BrowserLayout.qml @@ -87,6 +87,13 @@ Rectangle { signal web3Response(string data); + function signValue(input){ + if(Utils.isHex(input) && Utils.startsWith0x(input)){ + return input + } + return utilsModel.ascii2Hex(input) + } + function postMessage(data) { var request; try { @@ -189,6 +196,12 @@ Rectangle { signDialog.signMessage = function (enteredPassword) { signDialog.interactedWith = true; request.payload.password = enteredPassword; + switch(request.payload.method){ + case Constants.personal_sign: + request.payload.params[0] = signValue(request.payload.params[0]); + case Constants.eth_sign: + request.payload.params[1] = signValue(request.payload.params[1]); + } const response = web3Provider.postMessage(JSON.stringify(request)); provider.web3Response(response); try { diff --git a/ui/app/AppLayouts/Browser/SignMessageModal.qml b/ui/app/AppLayouts/Browser/SignMessageModal.qml index 58d87b1539..ce1e0b2711 100644 --- a/ui/app/AppLayouts/Browser/SignMessageModal.qml +++ b/ui/app/AppLayouts/Browser/SignMessageModal.qml @@ -34,7 +34,16 @@ ModalPopup { } })); } - stack.reset() + } + + function displayValue(input){ + if(Utils.isHex(input) && Utils.startsWith0x(input)){ + if (input.length === bytes32Length){ + return input; + } + return utilsModel.hex2Ascii(input) + } + return input; } Item { @@ -52,9 +61,9 @@ ModalPopup { text: { switch(request.payload.method){ case Constants.personal_sign: - return request.payload.params[0].length === bytes32Length ? request.payload.params[0] : utilsModel.hex2Ascii(request.payload.params[0]); + return displayValue(request.payload.params[0]); case Constants.eth_sign: - return request.payload.params[1]; + return displayValue(request.payload.params[1]); case Constants.eth_signTypedData: case Constants.eth_signTypedData_v3: return JSON.stringify(request.payload.params[1]); // TODO: requires design