Skip to content

Commit

Permalink
v4 go
Browse files Browse the repository at this point in the history
  • Loading branch information
flexsurfer committed Apr 16, 2021
1 parent b34d34e commit de2cdb0
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 7 deletions.
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
1 change: 1 addition & 0 deletions src/status_im/browser/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -402,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
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
4 changes: 2 additions & 2 deletions status-go-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"owner": "status-im",
"repo": "status-go",
"version": "chore/sign-typed-data-v4",
"commit-sha1": "beef4a7a2b69da9595e1a95cc181944f8ee93f94",
"src-sha256": "1clacysxjw0pwcfr7kj9mv0l9y8911i1rkcnjx1n4dymq3vd2w3a"
"commit-sha1": "ee6659cce7103bd989a758f156c5a18502a1239c",
"src-sha256": "0jccqk0hv3zla3lsz5zckxv63i6h98armk8w861abrdkajv5hxhn"
}

0 comments on commit de2cdb0

Please sign in to comment.