Skip to content

Commit

Permalink
[#19946] feat: integrate generate key pair export connection
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsen-ghafouri committed May 17, 2024
1 parent bf99913 commit 8e6d7ba
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,12 @@ class NetworkManager(private val reactContext: ReactApplicationContext) : ReactC
utils.executeRunnableStatusGoMethod({ Statusgo.recover(rpcParams) }, callback)
}

@ReactMethod
fun getConnectionStringForExportingKeypairsKeystores(configJSON: String, callback: Callback) {
val jsonConfig = JSONObject(configJSON)
utils.executeRunnableStatusGoMethod(
{ Statusgo.getConnectionStringForExportingKeypairsKeystores(jsonConfig.toString()) },
callback)
}

}
12 changes: 12 additions & 0 deletions modules/react-native-status/ios/RCTStatus/NetworkManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,16 @@ @implementation NetworkManager
callback(@[result]);
}

RCT_EXPORT_METHOD(getConnectionStringForExportingKeypairsKeystores:(NSString *)configJSON
callback:(RCTResponseSenderBlock)callback) {

NSData *configData = [configJSON dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSMutableDictionary *configDict = [NSJSONSerialization JSONObjectWithData:configData options:NSJSONReadingMutableContainers error:&error];
NSString *modifiedConfigJSON = [Utils jsonStringWithPrettyPrint:NO fromDictionary:configDict];

NSString *result = StatusgoGetConnectionStringForExportingKeypairsKeystores(modifiedConfigJSON);
callback(@[result]);
}

@end
8 changes: 8 additions & 0 deletions src/native_module/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -601,3 +601,11 @@
(.createAccountFromMnemonicAndDeriveAccountsForPaths ^js (account-manager)
(types/clj->json mnemonic)
#(callback (types/json->clj %))))

(defn get-connection-string-for-exporting-keypairs-keystores
"Generates connection string form status-go for the purpose of exporting keypairs and keystores on sender side"
[config-json callback]
(log/info "[native-module] Fetching Export Keypairs Connection String"
{:fn :get-connection-string-for-exporting-keypairs-keystores
:config-json config-json})
(.getConnectionStringForExportingKeypairsKeystores ^js (network) config-json callback))
29 changes: 28 additions & 1 deletion src/status_im/contexts/settings/wallet/events.cljs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
(ns status-im.contexts.settings.wallet.events
(:require
[clojure.string :as string]
[native-module.core :as native-module]
[status-im.contexts.syncing.utils :as sync-utils]
[taoensso.timbre :as log]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
[utils.re-frame :as rf]
[utils.security.core :as security]))

(rf/reg-event-fx
:wallet/rename-keypair-success
Expand Down Expand Up @@ -30,3 +34,26 @@
:on-error #(log/info "failed to rename keypair " %)}]]]})

(rf/reg-event-fx :wallet/rename-keypair rename-keypair)

(defn key-pair-export-connection-string
[{:keys [db]} [{:keys [sha3-pwd keypair-key-uid callback]}]]
(let [error (get-in db [:profile/login :error])
handle-connection (fn [response]
(println response)
(when (sync-utils/valid-connection-string? response)
(callback response)
(rf/dispatch [:hide-bottom-sheet])))]
(when-not (and error (string/blank? error))
(let [key-uid (get-in db [:profile/profile :key-uid])
config-map (.stringify js/JSON
(clj->js {:senderConfig {:loggedInKeyUid key-uid
:keystorePath (native-module/keystore-dir)
:keypairsToExport [keypair-key-uid]
:password (security/safe-unmask-data
sha3-pwd)}
:serverConfig {:timeout 0}}))]
(native-module/get-connection-string-for-exporting-keypairs-keystores
config-map
handle-connection)))))

(rf/reg-event-fx :wallet/get-key-pair-export-connection key-pair-export-connection-string)
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@

(defn view
[props data]
[:<>
[quo/drawer-top props]
[quo/action-drawer
(when (= (:type props) :keypair)
[[{:icon :i/qr-code
:accessibility-label :show-key-pr-qr
:label (i18n/label :t/show-encrypted-qr-of-key-pairs)
:on-press #(on-show-qr data)}]
[{:icon :i/edit
:accessibility-label :rename-key-pair
:label (i18n/label :t/rename-key-pair)
:on-press #(on-rename-request data)}]])]])
(let [has-paired-device (rf/sub [:pairing/has-paired-devices])]
(println has-paired-device)
[:<>
[quo/drawer-top props]
[quo/action-drawer
[(when has-paired-device
[{:icon :i/qr-code
:accessibility-label :show-key-pr-qr
:label (i18n/label :t/show-encrypted-qr-of-key-pairs)
:on-press #(on-show-qr data)}])
(when (= (:type props) :keypair)
[{:icon :i/edit
:accessibility-label :rename-key-pair
:label (i18n/label :t/rename-key-pair)
:on-press #(on-rename-request data)}])]]]))
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@

(defn view
[]
(let [{:keys [customization-color]} (rf/sub [:profile/profile-with-image])
(let [{:keys [key-uid]} (rf/sub [:get-screen-params])
{:keys [customization-color]} (rf/sub [:profile/profile-with-image])
[code set-code] (rn/use-state nil)
validate-and-set-code (rn/use-callback (fn [connection-string]
(when (sync-utils/valid-connection-string?
connection-string)
(set-code connection-string))))
cleanup-clock (rn/use-callback #(set-code nil))
on-auth-success (fn [entered-password]
(rf/dispatch [:syncing/get-connection-string entered-password
validate-and-set-code]))]
on-auth-success (rn/use-callback (fn [entered-password]
(rf/dispatch
[:wallet/get-key-pair-export-connection
{:sha3-pwd entered-password
:keypair-key-uid key-uid
:callback validate-and-set-code}]))
[key-uid])]
[rn/view {:style (style/container-main)}
[rn/scroll-view
[quo/page-nav
Expand Down
6 changes: 6 additions & 0 deletions src/status_im/subs/pairing.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@
:<- [:syncing]
(fn [syncing]
(:pairing-status syncing)))

(re-frame/reg-sub
:pairing/has-paired-devices
:<- [:pairing/enabled-installations]
(fn [installations]
(> (count installations) 1)))

0 comments on commit 8e6d7ba

Please sign in to comment.