diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java index a40015e38e..231075a33b 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java @@ -450,26 +450,6 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL StatusThreadPoolExecutor.getInstance().execute(r); } - @ReactMethod - public void createAccount(final String password, final Callback callback) { - Log.d(TAG, "createAccount"); - if (!checkAvailability()) { - callback.invoke(false); - return; - } - - Runnable r = new Runnable() { - @Override - public void run() { - String res = Statusgo.createAccount(password); - - callback.invoke(res); - } - }; - - StatusThreadPoolExecutor.getInstance().execute(r); - } - @ReactMethod public void sendDataNotification(final String dataPayloadJSON, final String tokensJSON, final Callback callback) { Log.d(TAG, "sendDataNotification"); diff --git a/modules/react-native-status/desktop/rctstatus.cpp b/modules/react-native-status/desktop/rctstatus.cpp index 102d5f5a48..1b0b8439a2 100644 --- a/modules/react-native-status/desktop/rctstatus.cpp +++ b/modules/react-native-status/desktop/rctstatus.cpp @@ -135,17 +135,6 @@ void RCTStatus::initKeystore() { logStatusGoResult("::initKeystore InitKeystore", result); } -void RCTStatus::createAccount(QString password, double callbackId) { - Q_D(RCTStatus); - qCInfo(RCTSTATUS) << "::createAccount call - callbackId:" << callbackId; - QtConcurrent::run([&](QString password, double callbackId) { - const char* result = CreateAccount(password.toUtf8().data()); - logStatusGoResult("::createAccount CreateAccount", result); - d->bridge->invokePromiseCallback(callbackId, QVariantList{result}); - }, password, callbackId); -} - - void RCTStatus::sendDataNotification(QString dataPayloadJSON, QString tokensJSON, double callbackId) { Q_D(RCTStatus); qCDebug(RCTSTATUS) << "::sendDataNotification call - callbackId:" << callbackId; diff --git a/modules/react-native-status/desktop/rctstatus.h b/modules/react-native-status/desktop/rctstatus.h index 098d67d591..3828c26e48 100644 --- a/modules/react-native-status/desktop/rctstatus.h +++ b/modules/react-native-status/desktop/rctstatus.h @@ -36,7 +36,6 @@ public: QVariantMap constantsToExport() override; Q_INVOKABLE void initKeystore(); - Q_INVOKABLE void createAccount(QString password, double callbackId); Q_INVOKABLE void sendDataNotification(QString dataPayloadJSON, QString tokensJSON, double callbackId); Q_INVOKABLE void sendLogs(QString dbJSON, QString jsLogs, double callbackId); Q_INVOKABLE void addPeer(QString enode, double callbackId); diff --git a/modules/react-native-status/ios/RCTStatus/RCTStatus.m b/modules/react-native-status/ios/RCTStatus/RCTStatus.m index 9cd5d59110..6a3a587b8d 100644 --- a/modules/react-native-status/ios/RCTStatus/RCTStatus.m +++ b/modules/react-native-status/ios/RCTStatus/RCTStatus.m @@ -128,18 +128,6 @@ RCT_EXPORT_METHOD(initKeystore) { }); } -//////////////////////////////////////////////////////////////////// -#pragma mark - Accounts method -//////////////////////////////////////////////////////////////////// createAccount -RCT_EXPORT_METHOD(createAccount:(NSString *)password - callback:(RCTResponseSenderBlock)callback) { -#if DEBUG - NSLog(@"CreateAccount() method called"); -#endif - NSString *result = StatusgoCreateAccount(password); - callback(@[result]); -} - //////////////////////////////////////////////////////////////////// #pragma mark - SendDataNotification method //////////////////////////////////////////////////////////////////// sendDataNotification diff --git a/src/status_im/native_module/core.cljs b/src/status_im/native_module/core.cljs index 1439a203c6..38d681fc15 100644 --- a/src/status_im/native_module/core.cljs +++ b/src/status_im/native_module/core.cljs @@ -1,130 +1,238 @@ (ns status-im.native-module.core - (:require [status-im.native-module.impl.module :as native-module])) + (:require [status-im.ui.components.react :as r] + [re-frame.core :as re-frame] + [status-im.react-native.js-dependencies :as rn-dependencies] + [clojure.string :as string] + [status-im.utils.platform :as platform] + [status-im.utils.types :as types])) + +(defn status [] + (when (exists? (.-NativeModules rn-dependencies/react-native)) + (.-Status (.-NativeModules rn-dependencies/react-native)))) (def adjust-resize 16) +(defn clear-web-data [] + (when (status) + (.clearCookies (status)) + (.clearStorageAPIs (status)))) + (defn init-keystore [] - (native-module/init-keystore)) + (.initKeystore (status))) (defn open-accounts [callback] - (native-module/open-accounts callback)) + (.openAccounts (status) #(callback (types/json->clj %)))) -(defn prepare-dir-and-update-config [config callback] - (native-module/prepare-dir-and-update-config config callback)) +(defn prepare-dir-and-update-config + [config callback] + (.prepareDirAndUpdateConfig (status) + config + #(callback (types/json->clj %)))) (defn save-account-and-login [multiaccount-data password config accounts-data] - (native-module/save-account-and-login multiaccount-data password config accounts-data)) + (clear-web-data) + (.saveAccountAndLogin (status) multiaccount-data password config accounts-data)) (defn login [account-data password] - (native-module/login account-data password)) + (clear-web-data) + (.login (status) account-data password)) -(defn logout - [] - (native-module/logout)) +(defn logout [] + (clear-web-data) + (.logout (status))) -(defn node-ready []) +(defonce listener + (.addListener r/device-event-emitter "gethEvent" + #(re-frame/dispatch [:signals/signal-received (.-jsonEvent %)]))) -(defn create-multiaccount [password callback] - (native-module/create-account password callback)) +(defn multiaccount-load-account + "this function is used after storing an account when you still want to + derive accounts from it, because saving an account flushes the loaded keys + from memory" + [address password callback] + (.multiAccountLoadAccount (status) + (types/clj->json {:address address + :password password}) + callback)) -(defn multiaccount-load-account [address password callback] - (native-module/multiaccount-load-account address password callback)) +(defn multiaccount-reset + "TODO: this function is not used anywhere + if usage isn't planned, remove" + [callback] + (.multiAccountReset (status) + callback)) -(defn multiaccount-reset [callback] - (native-module/multiaccount-reset callback)) +(defn multiaccount-derive-addresses + "NOTE: this should be named derive-accounts + this only derive addresses, they still need to be stored + with `multiaccount-store-derived` if you want to be able to + reuse the derived addresses later" + [account-id paths callback] + (when (status) + (.multiAccountDeriveAddresses (status) + (types/clj->json {:accountID account-id + :paths paths}) + callback))) -(defn multiaccount-derive-addresses [account-id paths callback] - (native-module/multiaccount-derive-addresses account-id paths callback)) +(defn multiaccount-store-account + "this stores the account and flush keys in memory so + in order to also store derived accounts like initial wallet + and chat accounts, you need to load the account again with + `multiaccount-load-account` before using `multiaccount-store-derived` + and the id of the account stored will have changed" + [account-id password callback] + (when (status) + (.multiAccountStoreAccount (status) + (types/clj->json {:accountID account-id + :password password}) + callback))) -(defn multiaccount-store-account [account-id password callback] - (native-module/multiaccount-store-account account-id password callback)) +(defn multiaccount-store-derived + [account-id paths password callback] + (.multiAccountStoreDerived (status) + (types/clj->json {:accountID account-id + :paths paths + :password password}) -(defn multiaccount-store-derived [account-id paths password callback] - (native-module/multiaccount-store-derived account-id paths password callback)) + callback)) -(defn multiaccount-generate-and-derive-addresses [n mnemonic-length paths callback] - (native-module/multiaccount-generate-and-derive-addresses n mnemonic-length paths callback)) +(defn multiaccount-generate-and-derive-addresses + "used to generate multiple multiaccounts for onboarding + NOTE: nothing is saved so you will need to use + `multiaccount-store-account` on the selected multiaccount + to store the key" + [n mnemonic-length paths callback] + (.multiAccountGenerateAndDeriveAddresses (status) + (types/clj->json {:n n + :mnemonicPhraseLength mnemonic-length + :bip39Passphrase "" + :paths paths}) + callback)) -(defn multiaccount-import-mnemonic [mnemonic password callback] - (native-module/multiaccount-import-mnemonic mnemonic password callback)) +(defn multiaccount-import-mnemonic + [mnemonic password callback] + (.multiAccountImportMnemonic (status) + (types/clj->json {:mnemonicPhrase mnemonic + :Bip39Passphrase password}) + + callback)) (defn verify [address password callback] - (native-module/verify address password callback)) + (.verify (status) address password callback)) (defn login-with-keycard [{:keys [whisper-private-key encryption-public-key on-result]}] - (native-module/login-with-keycard whisper-private-key encryption-public-key on-result)) + (clear-web-data) + (.loginWithKeycard (status) whisper-private-key encryption-public-key on-result)) (defn set-soft-input-mode [mode] - (native-module/set-soft-input-mode mode)) + (.setSoftInputMode (status) mode)) (defn call-rpc [payload callback] - (native-module/call-rpc payload callback)) + (.callRPC (status) payload callback)) (defn call-private-rpc [payload callback] - (native-module/call-private-rpc payload callback)) - -(defn sign-message [rpcParams callback] - (native-module/sign-message rpcParams callback)) - -(defn sign-typed-data [data account password callback] - (native-module/sign-typed-data data account password callback)) - -(defn send-transaction [rpcParams password callback] - (native-module/send-transaction rpcParams password callback)) + (.callPrivateRPC (status) payload callback)) (defn hash-transaction [rpcParams callback] - (native-module/hash-transaction rpcParams callback)) + (.hashTransaction (status) rpcParams callback)) (defn hash-message [message callback] - (native-module/hash-message message callback)) + (.hashMessage (status) message callback)) (defn hash-typed-data [data callback] - (native-module/hash-typed-data data callback)) + (.hashTypedData (status) data callback)) + +(defn sign-message [rpcParams callback] + (.signMessage (status) rpcParams callback)) + +(defn sign-typed-data [data account password callback] + (.signTypedData (status) data account password callback)) + +(defn send-transaction [rpcParams password callback] + (.sendTransaction (status) rpcParams password callback)) (defn send-transaction-with-signature [rpcParams sig callback] - (native-module/send-transaction-with-signature rpcParams sig callback)) + (.sendTransactionWithSignature (status) rpcParams sig callback)) -(defn send-data-notification [m callback] - (native-module/send-data-notification m callback)) +(defn send-data-notification + [{:keys [data-payload tokens] :as m} on-result] + (.sendDataNotification (status) data-payload tokens on-result)) (defn send-logs [dbJson js-logs callback] - (native-module/send-logs dbJson js-logs callback)) + (.sendLogs (status) dbJson js-logs callback)) -(defn add-peer [enode callback] - (native-module/add-peer enode callback)) +(defn add-peer [enode on-result] + (.addPeer (status) enode on-result)) (defn close-application [] - (native-module/close-application)) + (.closeApplication (status))) (defn connection-change [type expensive?] - (native-module/connection-change type expensive?)) + (.connectionChange (status) type (boolean expensive?))) (defn app-state-change [state] - (native-module/app-state-change state)) + (.appStateChange (status) state)) (defn get-device-UUID [callback] - (native-module/get-device-UUID callback)) + (.getDeviceUUID + (status) + (fn [UUID] + (callback (string/upper-case UUID))))) (defn set-blank-preview-flag [flag] - (native-module/set-blank-preview-flag flag)) + (.setBlankPreviewFlag (status) flag)) (defn is24Hour [] - (native-module/is24Hour)) + ;;NOTE: we have to check for status module because of tests + (when (status) + (.-is24Hour (status)))) (defn get-device-model-info [] - (native-module/get-device-model-info)) + ;;NOTE: we have to check for status module because of tests + (when (status) + {:model (.-model (status)) + :brand (.-brand (status)) + :build-id (.-buildId (status)) + :device-id (.-deviceId (status))})) -(def extract-group-membership-signatures native-module/extract-group-membership-signatures) +(defn extract-group-membership-signatures + [signature-pairs callback] + (.extractGroupMembershipSignatures (status) signature-pairs callback)) -(def sign-group-membership native-module/sign-group-membership) +(defn sign-group-membership [content callback] + (.signGroupMembership (status) content callback)) -(def update-mailservers native-module/update-mailservers) +(defn update-mailservers + [enodes on-result] + (.updateMailservers (status) enodes on-result)) -(def rooted-device? native-module/rooted-device?) +(defn chaos-mode-update [on on-result] + (.chaosModeUpdate (status) on on-result)) -(def chaos-mode-update native-module/chaos-mode-update) +(defn get-nodes-from-contract + [rpc-endpoint contract-address on-result] + (.getNodesFromContract (status) rpc-endpoint contract-address on-result)) -(def get-nodes-from-contract native-module/get-nodes-from-contract) +(defn rooted-device? [callback] + (cond + ;; we assume that iOS is safe by default + platform/ios? + (callback false) + + ;; we assume that Desktop is unsafe by default + ;; (theoretically, Desktop is always "rooted", by design + platform/desktop? + (callback true) + + ;; we check root on android + platform/android? + (if (status) + (.isDeviceRooted (status) callback) + ;; if module isn't initialized we return true to avoid degrading security + (callback true)) + + ;; in unknown scenarios we also consider the device rooted to avoid degrading security + :else (callback true))) diff --git a/src/status_im/native_module/impl/module.cljs b/src/status_im/native_module/impl/module.cljs deleted file mode 100644 index 87bff26f73..0000000000 --- a/src/status_im/native_module/impl/module.cljs +++ /dev/null @@ -1,236 +0,0 @@ -(ns status-im.native-module.impl.module - (:require [status-im.ui.components.react :as r] - [re-frame.core :as re-frame] - [status-im.react-native.js-dependencies :as rn-dependencies] - [clojure.string :as string] - [status-im.utils.platform :as platform] - [status-im.utils.types :as types])) - -(defn status [] - (when (exists? (.-NativeModules rn-dependencies/react-native)) - (.-Status (.-NativeModules rn-dependencies/react-native)))) - -(defn clear-web-data [] - (when (status) - (.clearCookies (status)) - (.clearStorageAPIs (status)))) - -(defn init-keystore [] - (.initKeystore (status))) - -(defn open-accounts [callback] - (.openAccounts (status) #(callback (types/json->clj %)))) - -(defn prepare-dir-and-update-config [config callback] - (.prepareDirAndUpdateConfig (status) - config - #(callback (types/json->clj %)))) - -(defn save-account-and-login - [multiaccount-data password config accounts-data] - (clear-web-data) - (.saveAccountAndLogin (status) multiaccount-data password config accounts-data)) - -(defn login - [account-data password] - (clear-web-data) - (.login (status) account-data password)) - -(defn logout [] - (clear-web-data) - (.logout (status))) - -(defonce listener-initialized (atom false)) - -(when-not @listener-initialized - (reset! listener-initialized true) - (.addListener r/device-event-emitter "gethEvent" - #(re-frame/dispatch [:signals/signal-received (.-jsonEvent %)]))) - -(defn node-ready []) - -(defonce account-creation? (atom false)) - -(defn create-account [password on-result] - (when (status) - (let [callback (fn [data] - (reset! account-creation? false) - (on-result data))] - (swap! account-creation? - (fn [creation?] - (if-not creation? - (do - (.createAccount (status) password callback) - true) - false)))))) - -(defn send-data-notification [{:keys [data-payload tokens] :as m} on-result] - (when (status) - (.sendDataNotification (status) data-payload tokens on-result))) - -(defn send-logs [dbJson js-logs callback] - (when (status) - (.sendLogs (status) dbJson js-logs callback))) - -(defn add-peer [enode on-result] - (when (status) - (.addPeer (status) enode on-result))) - -(defn multiaccount-generate-and-derive-addresses [n mnemonic-length paths on-result] - (.multiAccountGenerateAndDeriveAddresses (status) - (types/clj->json {:n n - :mnemonicPhraseLength mnemonic-length - :bip39Passphrase "" - :paths paths}) - on-result)) - -(defn multiaccount-derive-addresses [account-id paths on-result] - (when (status) - (.multiAccountDeriveAddresses (status) - (types/clj->json {:accountID account-id - :paths paths}) - on-result))) - -(defn multiaccount-store-account [account-id password on-result] - (when (status) - (.multiAccountStoreAccount (status) - (types/clj->json {:accountID account-id - :password password}) - on-result))) - -(defn multiaccount-load-account [address password on-result] - (when (status) - (.multiAccountLoadAccount (status) - (types/clj->json {:address address - :password password}) - on-result))) - -(defn multiaccount-reset [on-result] - (when (status) - (.multiAccountReset (status) - on-result))) - -(defn multiaccount-store-derived - [account-id paths password on-result] - (.multiAccountStoreDerived (status) - (types/clj->json {:accountID account-id - :paths paths - :password password}) - - on-result)) - -(defn multiaccount-import-mnemonic [mnemonic password on-result] - (when (status) - (.multiAccountImportMnemonic (status) - (types/clj->json {:mnemonicPhrase mnemonic - :Bip39Passphrase password}) - - on-result))) - -(defn verify [address password on-result] - (.verify (status) address password on-result)) - -(defn login-with-keycard [whisper-private-key encryption-public-key on-result] - (clear-web-data) - (.loginWithKeycard (status) whisper-private-key encryption-public-key on-result)) - -(defn set-soft-input-mode [mode] - (when (status) - (.setSoftInputMode (status) mode))) - -(defn call-rpc [payload callback] - (.callRPC (status) payload callback)) - -(defn call-private-rpc [payload callback] - (.callPrivateRPC (status) payload callback)) - -(defn sign-message [rpcParams callback] - (.signMessage (status) rpcParams callback)) - -(defn hash-transaction [rpcParams callback] - (.hashTransaction (status) rpcParams callback)) - -(defn hash-message [message callback] - (.hashMessage (status) message callback)) - -(defn hash-typed-data [data callback] - (.hashTypedData (status) data callback)) - -(defn sign-typed-data [data account password callback] - (.signTypedData (status) data account password callback)) - -(defn send-transaction [rpcParams password callback] - (.sendTransaction (status) rpcParams password callback)) - -(defn send-transaction-with-signature [rpcParams sig callback] - (.sendTransactionWithSignature (status) rpcParams sig callback)) - -(defn close-application [] - (.closeApplication (status))) - -(defn connection-change [type expensive?] - (.connectionChange (status) type (boolean expensive?))) - -(defn app-state-change [state] - (.appStateChange (status) state)) - -(defn get-device-UUID [callback] - (.getDeviceUUID - (status) - (fn [UUID] - (callback (string/upper-case UUID))))) - -(defn set-blank-preview-flag [flag] - (.setBlankPreviewFlag (status) flag)) - -(defn extract-group-membership-signatures [signature-pairs callback] - (when (status) - (.extractGroupMembershipSignatures (status) signature-pairs callback))) - -(defn sign-group-membership [content callback] - (when (status) - (.signGroupMembership (status) content callback))) - -(defn is24Hour [] - (when (status) - (.-is24Hour (status)))) - -(defn get-device-model-info [] - (when status - {:model (.-model status) - :brand (.-brand status) - :build-id (.-buildId status) - :device-id (.-deviceId status)})) - -(defn update-mailservers [enodes on-result] - (when (status) - (.updateMailservers (status) enodes on-result))) - -(defn chaos-mode-update [on on-result] - (when (status) - (.chaosModeUpdate (status) on on-result))) - -(defn get-nodes-from-contract [rpc-endpoint contract-address on-result] - (when (status) - (.getNodesFromContract (status) rpc-endpoint contract-address on-result))) - -(defn rooted-device? [callback] - (cond - ;; we assume that iOS is safe by default - platform/ios? - (callback false) - - ;; we assume that Desktop is unsafe by default - ;; (theoretically, Desktop is always "rooted", by design - platform/desktop? - (callback true) - - ;; we check root on android - platform/android? - (if (status) - (.isDeviceRooted (status) callback) - ;; if module isn't initialized we return true to avoid degrading security - (callback true)) - - ;; in unknown scenarios we also consider the device rooted to avoid degrading security - :else (callback true))) diff --git a/src/status_im/node/core.cljs b/src/status_im/node/core.cljs index ed16598446..49c322cd6c 100644 --- a/src/status_im/node/core.cljs +++ b/src/status_im/node/core.cljs @@ -186,11 +186,6 @@ (fn [[config callback]] (status/prepare-dir-and-update-config config callback))) -(re-frame/reg-fx - :node/ready - (fn [config] - (status/node-ready))) - (re-frame/reg-fx :node/les-show-debug-info (fn [[multiaccount]]