From 7f839f952db5088a39295ee4e627817229ee6f6b Mon Sep 17 00:00:00 2001 From: andrey Date: Thu, 25 Mar 2021 10:48:11 +0100 Subject: [PATCH] eth_sign support --- resources/js/provider.js | 5 +++++ src/status_im/browser/core.cljs | 4 ++-- src/status_im/constants.cljs | 1 + src/status_im/utils/config.cljs | 1 + src/status_im/utils/js_resources.cljs | 4 +++- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/resources/js/provider.js b/resources/js/provider.js index 9384e2c37c..43e22edaf1 100644 --- a/resources/js/provider.js +++ b/resources/js/provider.js @@ -178,6 +178,7 @@ this._events[name].forEach(cb => cb(data)); } EthereumProvider.prototype.enable = function () { + if (window.statusAppDebug) { console.log("enable"); } return sendAPIrequest('web3'); }; @@ -187,6 +188,7 @@ EthereumProvider.prototype.request = function (requestArguments) { + if (window.statusAppDebug) { console.log("request: " + JSON.stringify(requestArguments)); } if (!requestArguments) { return new Error('Request is not valid.'); } @@ -232,12 +234,14 @@ // (DEPRECATED) Support for legacy send method EthereumProvider.prototype.send = function (method, params = []) { + if (window.statusAppDebug) { console.log("send (legacy): " + method);} return this.request({method: method, params: params}); } // (DEPRECATED) Support for legacy sendSync method EthereumProvider.prototype.sendSync = function (payload) { + if (window.statusAppDebug) { console.log("sendSync (legacy)" + JSON.stringify(payload));} if (payload.method == "eth_uninstallFilter"){ this.sendAsync(payload, function (res, err) {}) } @@ -252,6 +256,7 @@ // (DEPRECATED) Support for legacy sendAsync method EthereumProvider.prototype.sendAsync = function (payload, callback) { + if (window.statusAppDebug) { console.log("sendAsync (legacy)" + JSON.stringify(payload));} if (!payload) { return new Error('Request is not valid.'); } diff --git a/src/status_im/browser/core.cljs b/src/status_im/browser/core.cljs index d98ef89b3f..c241ddbfef 100644 --- a/src/status_im/browser/core.cljs +++ b/src/status_im/browser/core.cljs @@ -382,13 +382,13 @@ (defn web3-sign-message? [method] (#{constants/web3-sign-typed-data constants/web3-sign-typed-data-v3 constants/web3-personal-sign - constants/web3-keycard-sign-typed-data} method)) + constants/web3-eth-sign constants/web3-keycard-sign-typed-data} method)) (fx/defn web3-send-async [cofx {:keys [method params id] :as payload} message-id] (let [message? (web3-sign-message? method) dapps-address (get-in cofx [:db :multiaccount :dapps-address]) - typed? (not= constants/web3-personal-sign method)] + typed? (and (not= constants/web3-personal-sign method) (not= constants/web3-eth-sign method))] (if (or message? (= constants/web3-send-transaction method)) (let [[address data] (cond (and (= method constants/web3-keycard-sign-typed-data) (not (vector? params))) diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index 0c070dca02..1c7cf74a2d 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -74,6 +74,7 @@ (def ^:const web3-send-transaction "eth_sendTransaction") (def ^:const web3-personal-sign "personal_sign") +(def ^:const web3-eth-sign "eth_sign") (def ^:const web3-sign-typed-data "eth_signTypedData") (def ^:const web3-sign-typed-data-v3 "eth_signTypedData_v3") diff --git a/src/status_im/utils/config.cljs b/src/status_im/utils/config.cljs index 812de65163..c3e7502fab 100644 --- a/src/status_im/utils/config.cljs +++ b/src/status_im/utils/config.cljs @@ -49,6 +49,7 @@ (def communities-management-enabled? (and (enabled? (get-config :COMMUNITIES_MANAGEMENT_ENABLED "0")) communities-enabled?)) (def database-management-enabled? (enabled? (get-config :DATABASE_MANAGEMENT_ENABLED "0"))) +(def debug-webview? (enabled? (get-config :DEBUG_WEBVIEW "0"))) ;; CONFIG VALUES (def log-level diff --git a/src/status_im/utils/js_resources.cljs b/src/status_im/utils/js_resources.cljs index fd8cc2f88a..c7d699c848 100644 --- a/src/status_im/utils/js_resources.cljs +++ b/src/status_im/utils/js_resources.cljs @@ -1,7 +1,9 @@ (ns status-im.utils.js-resources - (:require-macros [status-im.utils.slurp :refer [slurp]])) + (:require-macros [status-im.utils.slurp :refer [slurp]]) + (:require [status-im.utils.config :as config])) (def provider-file (slurp "resources/js/provider.js")) (defn ethereum-provider [network-id] (str "window.statusAppNetworkId = \"" network-id "\";" + (when config/debug-webview? "window.statusAppDebug = true;") provider-file))