From 51174f848899360482b7ac55e2407b7cff76ab9e Mon Sep 17 00:00:00 2001 From: frank Date: Thu, 9 Jun 2022 20:42:36 +0800 Subject: [PATCH] Use LoginWithConfig method to log in (#13414) --- .../im/status/ethereum/module/StatusModule.java | 12 ++++++++++++ .../react-native-status/ios/RCTStatus/RCTStatus.m | 13 +++++++++++++ src/status_im/keycard/simulated_keycard.cljs | 2 +- src/status_im/multiaccounts/login/core.cljs | 2 +- src/status_im/native_module/core.cljs | 10 ++++++++++ 5 files changed, 37 insertions(+), 2 deletions(-) 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 7a756707aa..d8a9d2c81a 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 @@ -370,6 +370,18 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL } } + @ReactMethod + public void loginWithConfig(final String accountData, final String password, final String configJSON) { + Log.d(TAG, "loginWithConfig"); + this.migrateKeyStoreDir(accountData, password); + String result = Statusgo.loginWithConfig(accountData, password, configJSON); + if (result.startsWith("{\"error\":\"\"")) { + Log.d(TAG, "LoginWithConfig result: " + result); + } else { + Log.e(TAG, "LoginWithConfig failed: " + result); + } + } + @ReactMethod public void exportUnencryptedDatabase(final String accountData, final String password, final Callback callback) { Log.d(TAG, "login"); diff --git a/modules/react-native-status/ios/RCTStatus/RCTStatus.m b/modules/react-native-status/ios/RCTStatus/RCTStatus.m index 5b53ef06c6..c6ccda0430 100644 --- a/modules/react-native-status/ios/RCTStatus/RCTStatus.m +++ b/modules/react-native-status/ios/RCTStatus/RCTStatus.m @@ -542,6 +542,19 @@ RCT_EXPORT_METHOD(login:(NSString *)accountData NSLog(@"%@", result); } +//////////////////////////////////////////////////////////////////// loginWithConfig +RCT_EXPORT_METHOD(loginWithConfig:(NSString *)accountData + password:(NSString *)password + configJSON:(NSString *)configJSON) { +#if DEBUG + NSLog(@"LoginWithConfig() method called"); +#endif + [self getExportDbFilePath]; + [self migrateKeystore:accountData password:password]; + NSString *result = StatusgoLoginWithConfig(accountData, password, configJSON); + NSLog(@"%@", result); +} + //////////////////////////////////////////////////////////////////// loginWithKeycard RCT_EXPORT_METHOD(loginWithKeycard:(NSString *)accountData password:(NSString *)password diff --git a/src/status_im/keycard/simulated_keycard.cljs b/src/status_im/keycard/simulated_keycard.cljs index 77f8609771..f6951175c5 100644 --- a/src/status_im/keycard/simulated_keycard.cljs +++ b/src/status_im/keycard/simulated_keycard.cljs @@ -432,7 +432,7 @@ (types/clj->json accounts-data))) (defn login [{:keys [key-uid multiaccount-data password]}] - (status/login key-uid multiaccount-data password)) + (status/login-with-config key-uid multiaccount-data password nil)) (defn send-transaction-with-signature [{:keys [transaction on-completed]}] diff --git a/src/status_im/multiaccounts/login/core.cljs b/src/status_im/multiaccounts/login/core.cljs index 0a8c587ce1..6f4a7070fc 100644 --- a/src/status_im/multiaccounts/login/core.cljs +++ b/src/status_im/multiaccounts/login/core.cljs @@ -63,7 +63,7 @@ (re-frame/reg-fx ::login (fn [[key-uid account-data hashed-password]] - (status/login key-uid account-data hashed-password))) + (status/login-with-config key-uid account-data hashed-password nil))) (re-frame/reg-fx ::export-db diff --git a/src/status_im/native_module/core.cljs b/src/status_im/native_module/core.cljs index 4a7195d004..612d3590bb 100644 --- a/src/status_im/native_module/core.cljs +++ b/src/status_im/native_module/core.cljs @@ -64,6 +64,16 @@ key-uid #(.login ^js (status) account-data hashed-password))) +(defn login-with-config + "NOTE: beware, the password has to be sha3 hashed" + [key-uid account-data hashed-password config] + (log/debug "[native-module] loginWithConfig") + (clear-web-data) + (let [config (if config (types/clj->json config) "")] + (init-keystore + key-uid + #(.loginWithConfig ^js (status) account-data hashed-password config)))) + (defn export-db "NOTE: beware, the password has to be sha3 hashed" [key-uid account-data hashed-password callback]