Skip to content
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

[#11925] Can't connect Hermez wallet dApp to Status wallet #11943

Merged
merged 2 commits into from
Apr 19, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,25 @@ public void run() {
StatusThreadPoolExecutor.getInstance().execute(r);
}

@ReactMethod
public void signTypedDataV4(final String data, final String account, final String password, final Callback callback) {
Log.d(TAG, "signTypedDataV4");
if (!checkAvailability()) {
callback.invoke(false);
return;
}

Runnable r = new Runnable() {
@Override
public void run() {
String res = Statusgo.signTypedDataV4(data, account, password);
callback.invoke(res);
}
};

StatusThreadPoolExecutor.getInstance().execute(r);
}

@ReactMethod
public void setAdjustResize() {
Log.d(TAG, "setAdjustResize");
Expand Down
14 changes: 14 additions & 0 deletions modules/react-native-status/ios/RCTStatus/RCTStatus.m
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,20 @@ - (void) migrateKeystore:(NSString *)accountData
callback(@[result]);
}

////////////////////////////////////////////////////////////////////
#pragma mark - SignTypedDataV4
//////////////////////////////////////////////////////////////////// signTypedDataV4
RCT_EXPORT_METHOD(signTypedDataV4:(NSString *)data
account:(NSString *)account
password:(NSString *)password
callback:(RCTResponseSenderBlock)callback) {
#if DEBUG
NSLog(@"SignTypedDataV4() method called");
#endif
NSString *result = StatusgoSignTypedDataV4(data, account, password);
callback(@[result]);
}

////////////////////////////////////////////////////////////////////
#pragma mark - SignGroupMembership
//////////////////////////////////////////////////////////////////// signGroupMembership
Expand Down
5 changes: 5 additions & 0 deletions resources/js/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
this._events[name].forEach(cb => cb(data));
}
EthereumProvider.prototype.enable = function () {
if (window.statusAppDebug) { console.log("enable"); }
return sendAPIrequest('web3');
};

Expand All @@ -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.');
}
Expand Down Expand Up @@ -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) {})
}
Expand All @@ -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.');
}
Expand Down
8 changes: 5 additions & 3 deletions src/status_im/browser/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,15 @@
{:browser/send-to-bridge message})

(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-sign-typed-data constants/web3-sign-typed-data-v3 constants/web3-sign-typed-data-v4
constants/web3-personal-sign
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)))
Expand All @@ -401,6 +402,7 @@
(if message?
{:message {:address address
:data data
:v4 (= constants/web3-sign-typed-data-v4 method)
:typed? typed?
:pinless? (= method constants/web3-keycard-sign-typed-data)
:from dapps-address}}
Expand Down
2 changes: 2 additions & 0 deletions src/status_im/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@

(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")
(def ^:const web3-sign-typed-data-v4 "eth_signTypedData_v4")

(def ^:const web3-keycard-sign-typed-data "keycard_signTypedData")

Expand Down
8 changes: 7 additions & 1 deletion src/status_im/native_module/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,15 @@
(defn sign-typed-data
"NOTE: beware, the password has to be sha3 hashed"
[data account hashed-password callback]
(log/debug "[native-module] clear-web-data")
(log/debug "[native-module] sign-typed-data")
(.signTypedData ^js (status) data account hashed-password callback))

(defn sign-typed-data-v4
"NOTE: beware, the password has to be sha3 hashed"
[data account hashed-password callback]
(log/debug "[native-module] sign-typed-data-v4")
(.signTypedDataV4 ^js (status) data account hashed-password callback))

(defn send-logs [dbJson js-logs callback]
(log/debug "[native-module] send-logs")
(.sendLogs ^js (status) dbJson js-logs callback))
Expand Down
11 changes: 7 additions & 4 deletions src/status_im/signing/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@

(re-frame/reg-fx
:signing.fx/sign-typed-data
(fn [{:keys [data account on-completed hashed-password]}]
(status/sign-typed-data data account hashed-password on-completed)))
(fn [{:keys [v4 data account on-completed hashed-password]}]
(if v4
(status/sign-typed-data-v4 data account hashed-password on-completed)
(status/sign-typed-data data account hashed-password on-completed))))

(defn get-contact [db to]
(let [to (utils.hex/normalize-hex to)]
Expand All @@ -68,15 +70,16 @@

(fx/defn sign-message
[{{:signing/keys [sign tx] :as db} :db}]
(let [{{:keys [data typed? from]} :message} tx
(let [{{:keys [data typed? from v4]} :message} tx
{:keys [in-progress? password]} sign
from (or from (ethereum/default-address db))
hashed-password (ethereum/sha3 (security/safe-unmask-data password))]
(when-not in-progress?
(merge
{:db (update db :signing/sign assoc :error nil :in-progress? true)}
(if typed?
{:signing.fx/sign-typed-data {:data data
{:signing.fx/sign-typed-data {:v4 v4
:data data
:account from
:hashed-password hashed-password
:on-completed #(re-frame/dispatch [:signing/sign-message-completed %])}}
Expand Down
1 change: 1 addition & 0 deletions src/status_im/utils/config.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/status_im/utils/js_resources.cljs
Original file line number Diff line number Diff line change
@@ -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))
6 changes: 3 additions & 3 deletions status-go-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "status-im",
"repo": "status-go",
"version": "v0.76.3",
"commit-sha1": "0e048081b0cb9f8324f4b64b1b042185a6798141",
"src-sha256": "1p0y8af3pzyab3f0qphyy1sm0x5m8c7kg05n0qrfpxsydy7sh1v4"
"version": "v0.76.4",
"commit-sha1": "ddc93981a7403bdc4ce205524789d5731cd58116",
"src-sha256": "0ijs1x20hkg7x2dnwjkbqn11pi7g1pm6bx3g62wwwfvk26qz4g6s"
}