Skip to content

Commit

Permalink
integrate status-go initKeystore native call
Browse files Browse the repository at this point in the history
- avoids having to start a node before login
  • Loading branch information
yenda committed Jul 31, 2019
1 parent 79f2eed commit f437048
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 29 deletions.
1 change: 1 addition & 0 deletions externs.js
Expand Up @@ -191,6 +191,7 @@ var TopLevel = {
"index" : function () {},
"indexOf" : function () {},
"init" : function () {},
"initKeystore" : function () {},
"injectJavaScript" : function () {},
"installApplet" : function () {},
"installAppletAndInitCard" : function () {},
Expand Down
Expand Up @@ -352,6 +352,28 @@ public void moveToInternalStorage(Callback callback) {
callback.invoke();
}

@ReactMethod
private void initKeystore() {
Activity currentActivity = getCurrentActivity();

final String keydir = currentActivity.getApplicationInfo().dataDir;
Log.d(TAG, "initKeystore");
if (!checkAvailability()) {
Log.e(TAG, "[initKeystore] Activity doesn't exist, cannot init keystore");
System.exit(0);
return;
}

Runnable r = new Runnable() {
@Override
public void run() {
Statusgo.initKeystore(keydir);
}
};

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

@ReactMethod
public void startNode(final String config) {
Log.d(TAG, "startNode");
Expand Down
6 changes: 6 additions & 0 deletions modules/react-native-status/desktop/rctstatus.cpp
Expand Up @@ -128,6 +128,12 @@ void RCTStatus::stopNode() {
logStatusGoResult("::stopNode StopNode", result);
}

void RCTStatus::initKeystore() {
aCInfo(RCTSTATUS) << "::initKeystore call";
QString rootDirPath = getDataStoragePath();
const char* result = initKeystore(rootDirPath);
logStatusGoResult("::initKeystore InitKeystore", result);
}

void RCTStatus::createAccount(QString password, double callbackId) {
Q_D(RCTStatus);
Expand Down
1 change: 1 addition & 0 deletions modules/react-native-status/desktop/rctstatus.h
Expand Up @@ -35,6 +35,7 @@ class RCTStatus : public QObject, public ModuleInterface {
QList<ModuleMethod*> methodsToExport() override;
QVariantMap constantsToExport() override;

Q_INVOKABLE void initKeystore();
Q_INVOKABLE void startNode(QString configString);
Q_INVOKABLE void stopNode();
Q_INVOKABLE void createAccount(QString password, double callbackId);
Expand Down
20 changes: 20 additions & 0 deletions modules/react-native-status/ios/RCTStatus/RCTStatus.m
Expand Up @@ -200,6 +200,26 @@ - (void)handleSignal:(NSString *)signal
});
}

////////////////////////////////////////////////////////////////////
#pragma mark - InitKeystore method
//////////////////////////////////////////////////////////////////// StopNode
RCT_EXPORT_METHOD(initKeystore) {
#if DEBUG
NSLog(@"initKeystore() method called");
#endif
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error = nil;
NSURL *rootUrl =[[fileManager
URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask]
lastObject];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
^(void)
{
NSString *res = StatusgoInitKeystore(rootUrl.path);
NSLog(@"StopNode result %@", res);
});
}

////////////////////////////////////////////////////////////////////
#pragma mark - Accounts method
//////////////////////////////////////////////////////////////////// createAccount
Expand Down
6 changes: 6 additions & 0 deletions src/status_im/init/core.cljs
Expand Up @@ -67,6 +67,7 @@
(fx/merge cofx
{:init/get-device-UUID nil
:init/get-supported-biometric-auth nil
:init/init-keystore nil
:init/restore-native-settings nil
:ui/listen-to-window-dimensions-change nil
:notifications/init nil
Expand Down Expand Up @@ -254,6 +255,11 @@
:init/restore-native-settings
restore-native-settings!)

(re-frame/reg-fx
:init/init-keystore
(fn []
(status/init-keystore)))

(re-frame/reg-fx
:init/get-device-UUID
(fn []
Expand Down
13 changes: 4 additions & 9 deletions src/status_im/multiaccounts/create/core.cljs
Expand Up @@ -164,15 +164,10 @@
(fx/merge {:db (dissoc db :intro-wizard)}
(navigation/navigate-to-cofx :home nil)))

(fx/defn init-key-generation [{:keys [db] :as cofx}]
(let [node-started? (= :started (:node/status db))]
(fx/merge
{:db (-> db
(assoc-in [:intro-wizard :generating-keys?] true)
(assoc :node/on-ready :start-onboarding))}
(if node-started?
{:intro-wizard/start-onboarding nil}
(node/initialize nil)))))
(fx/defn init-key-generation
[{:keys [db] :as cofx}]
{:db (assoc-in db [:intro-wizard :generating-keys?] true)
:intro-wizard/start-onboarding nil})

(fx/defn on-confirm-failure [{:keys [db] :as cofx}]
(do
Expand Down
3 changes: 3 additions & 0 deletions src/status_im/native_module/core.cljs
Expand Up @@ -3,6 +3,9 @@

(def adjust-resize 16)

(defn init-keystore []
(native-module/init-keystore))

(defn start-node [config]
(native-module/start-node config))

Expand Down
27 changes: 14 additions & 13 deletions src/status_im/native_module/impl/module.cljs
Expand Up @@ -10,6 +10,9 @@
(when (exists? (.-NativeModules rn-dependencies/react-native))
(.-Status (.-NativeModules rn-dependencies/react-native))))

(defn init-keystore []
(.initKeystore (status)))

(defonce listener-initialized (atom false))

(when-not @listener-initialized
Expand Down Expand Up @@ -63,22 +66,20 @@
(.recoverAccount (status) passphrase password on-result)))

(defn multiaccount-generate-and-derive-addresses [n mnemonic-length paths on-result]
(when (and @node-started (status))
(.multiAccountGenerateAndDeriveAddresses (status)
(types/clj->json {:n n
:mnemonicPhraseLength mnemonic-length
:bip39Passphrase ""
:paths paths})
on-result)))
(.multiAccountGenerateAndDeriveAddresses (status)
(types/clj->json {:n n
:mnemonicPhraseLength mnemonic-length
:bip39Passphrase ""
:paths paths})
on-result))

(defn multiaccount-store-derived [account-id paths password on-result]
(when (and @node-started (status))
(.multiAccountStoreDerived (status)
(types/clj->json {:accountID account-id
:paths paths
:password password})
(.multiAccountStoreDerived (status)
(types/clj->json {:accountID account-id
:paths paths
:password password})

on-result)))
on-result))

(defn login [address password main-account watch-addresses on-result]
(when (and @node-started (status))
Expand Down
5 changes: 1 addition & 4 deletions src/status_im/signals/core.cljs
Expand Up @@ -44,10 +44,7 @@
{:multiaccounts.recover/recover-multiaccount
[(security/mask-data passphrase) password]}))
:create-keycard-multiaccount
(hardwallet/create-keycard-multiaccount)
:start-onboarding
(fn []
{:intro-wizard/start-onboarding nil})))))
(hardwallet/create-keycard-multiaccount)))))

(fx/defn status-node-stopped
[{db :db}]
Expand Down
6 changes: 3 additions & 3 deletions status-go-version.json
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": "9de77b21b22aeca3c71050ed4f7809f500e63191",
"commit-sha1": "9de77b21b22aeca3c71050ed4f7809f500e63191",
"src-sha256": "1wpyijxqcq1c1ra6vp6sr8zg91r0awpdx5ypgdrvhlnl3mba4k1g"
"version": "init-keystore",
"commit-sha1": "61cb8791d5492a51f463f1ebfd2085f732b95897",
"src-sha256": "1a6gms1dgjgq6gc2k08625k93fkli58fi3crnavvi9f6g5c80rja"
}

0 comments on commit f437048

Please sign in to comment.