diff --git a/package.json b/package.json index e52b74ec66..2860ac55f6 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "react-native-screens": "^2.10.1", "react-native-shake": "^3.3.1", "react-native-splash-screen": "^3.2.0", - "react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#v2.5.30", + "react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#v2.5.31", "react-native-svg": "^9.8.4", "react-native-touch-id": "^4.4.1", "react-native-webview": "git+https://github.com/status-im/react-native-webview.git#v10.9.2", diff --git a/src/status_im/keycard/card.cljs b/src/status_im/keycard/card.cljs index 715f359206..f3c35cef8f 100644 --- a/src/status_im/keycard/card.cljs +++ b/src/status_im/keycard/card.cljs @@ -336,24 +336,43 @@ (re-frame/dispatch [:keycard.callback/on-delete-error (error-object->map response)]))}))) +(defn import-keys [{:keys [on-success] :as args}] + (log/debug "[keycard] import-keys") + (keycard/import-keys + card + (assoc + args + :on-success + (fn [response] + (log/debug "[keycard response succ] import-keys") + (re-frame/dispatch + [(or on-success :keycard.callback/on-generate-and-load-key-success) + response])) + :on-failure + (fn [response] + (log/warn "[keycard response fail] import-keys" + (error-object->map response)) + (re-frame/dispatch [:keycard.callback/on-get-keys-error + (error-object->map response)]))))) + (defn get-keys [{:keys [on-success] :as args}] (log/debug "[keycard] get-keys") (keycard/get-keys card - (merge + (assoc args - {:on-success - (fn [response] - (log/debug "[keycard response succ] get-keys") - (re-frame/dispatch - [(or on-success :keycard.callback/on-get-keys-success) - response])) - :on-failure - (fn [response] - (log/debug "[keycard response fail] get-keys" - (error-object->map response)) - (re-frame/dispatch [:keycard.callback/on-get-keys-error - (error-object->map response)]))}))) + :on-success + (fn [response] + (log/debug "[keycard response succ] get-keys") + (re-frame/dispatch + [(or on-success :keycard.callback/on-get-keys-success) + response])) + :on-failure + (fn [response] + (log/warn "[keycard response fail] get-keys" + (error-object->map response)) + (re-frame/dispatch [:keycard.callback/on-get-keys-error + (error-object->map response)]))))) (defn sign [{:keys [on-success on-failure] :as args}] (log/debug "[keycard] sign") diff --git a/src/status_im/keycard/common.cljs b/src/status_im/keycard/common.cljs index 4784ba9dbe..eb28349ca8 100644 --- a/src/status_im/keycard/common.cljs +++ b/src/status_im/keycard/common.cljs @@ -356,6 +356,9 @@ (-> db (assoc-in [:keycard :pin :status] nil) (assoc-in [:keycard :pin :login] []) + (update-in [:keycard :application-info] assoc + :puk-retry-counter 5 + :pin-retry-counter 3) (assoc-in [:keycard :multiaccount] (update account-data :whisper-public-key ethereum/normalized-hex)) (assoc-in [:keycard :flow] nil) @@ -365,7 +368,6 @@ :identicon identicon :name name)) - :keycard/get-application-info {:pairing (get-pairing db key-uid)} :keycard/login-with-keycard {:multiaccount-data multiaccount-data :password encryption-public-key :chat-key whisper-private-key diff --git a/src/status_im/keycard/fx.cljs b/src/status_im/keycard/fx.cljs index 43fc9aae4b..c81e591961 100644 --- a/src/status_im/keycard/fx.cljs +++ b/src/status_im/keycard/fx.cljs @@ -131,6 +131,10 @@ :keycard/unpair-and-delete card/unpair-and-delete) +(re-frame/reg-fx + :keycard/import-keys + card/import-keys) + (re-frame/reg-fx :keycard/get-keys card/get-keys) diff --git a/src/status_im/keycard/ios_keycard.cljs b/src/status_im/keycard/ios_keycard.cljs index 60fcdfd73e..f5c738924c 100644 --- a/src/status_im/keycard/ios_keycard.cljs +++ b/src/status_im/keycard/ios_keycard.cljs @@ -26,6 +26,7 @@ (remove-key-with-unpair [this args]) (export-key [this args]) (unpair-and-delete [this args]) + (import-keys [this args]) (get-keys [this args]) (sign [this args]) (save-multiaccount-and-login [this args]) diff --git a/src/status_im/keycard/keycard.cljs b/src/status_im/keycard/keycard.cljs index da6cdde68e..76d9a1ae0f 100644 --- a/src/status_im/keycard/keycard.cljs +++ b/src/status_im/keycard/keycard.cljs @@ -28,6 +28,7 @@ (remove-key-with-unpair [this args]) (export-key [this args]) (unpair-and-delete [this args]) + (import-keys [this args]) (get-keys [this args]) (sign [this args]) (sign-typed-data [this args]) diff --git a/src/status_im/keycard/real_keycard.cljs b/src/status_im/keycard/real_keycard.cljs index e70d0df9f8..9491984b3f 100644 --- a/src/status_im/keycard/real_keycard.cljs +++ b/src/status_im/keycard/real_keycard.cljs @@ -211,6 +211,14 @@ (then on-success) (catch on-failure)))) +(defn import-keys + [{:keys [pairing pin on-success on-failure]}] + (when (and pairing (not-empty pin)) + (.. status-keycard + (importKeys pairing pin) + (then on-success) + (catch on-failure)))) + (defn get-keys [{:keys [pairing pin on-success on-failure]}] (when (and pairing (not-empty pin)) @@ -315,6 +323,8 @@ (export-key args)) (keycard/unpair-and-delete [this args] (unpair-and-delete args)) + (keycard/import-keys [this args] + (import-keys args)) (keycard/get-keys [this args] (get-keys args)) (keycard/sign [this args] diff --git a/src/status_im/keycard/recovery.cljs b/src/status_im/keycard/recovery.cljs index acf647d2f4..cc54101b25 100644 --- a/src/status_im/keycard/recovery.cljs +++ b/src/status_im/keycard/recovery.cljs @@ -250,9 +250,9 @@ (assoc-in [:keycard :pin :status] :verifying) (assoc-in [:keycard :secrets] {:pairing pairing' :paired-on (utils.datetime/timestamp)})) - :keycard/get-keys {:pairing pairing' - :pin pin - :on-success :keycard.callback/on-generate-and-load-key-success}}))) + :keycard/import-keys {:pairing pairing' + :pin pin + :on-success :keycard.callback/on-generate-and-load-key-success}}))) (fx/defn load-recovering-key-screen {:events [:keycard/load-recovering-key-screen]} diff --git a/src/status_im/keycard/simulated_keycard.cljs b/src/status_im/keycard/simulated_keycard.cljs index 6e349cac6b..ab328dfcb8 100644 --- a/src/status_im/keycard/simulated_keycard.cljs +++ b/src/status_im/keycard/simulated_keycard.cljs @@ -336,6 +336,8 @@ #js {:code "EUNSPECIFIED" :message "Unexpected error SW, 0x63C2"}))))) +(def import-keys get-keys) + (defn sign [{:keys [pin hash data path typed? on-success on-failure]}] (if (= pin (get @state :pin)) (later @@ -483,6 +485,9 @@ (keycard/unpair-and-delete [this args] (log/debug "simulated card unpair-and-delete") (unpair-and-delete args)) + (keycard/import-keys [this args] + (log/debug "simulated card import-keys") + (import-keys args)) (keycard/get-keys [this args] (log/debug "simulated card get-keys") (get-keys args)) diff --git a/yarn.lock b/yarn.lock index f1a537ca3a..b333934b70 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6751,9 +6751,9 @@ react-native-splash-screen@^3.2.0: resolved "https://registry.yarnpkg.com/react-native-splash-screen/-/react-native-splash-screen-3.2.0.tgz#d47ec8557b1ba988ee3ea98d01463081b60fff45" integrity sha512-Ls9qiNZzW/OLFoI25wfjjAcrf2DZ975hn2vr6U9gyuxi2nooVbzQeFoQS5vQcbCt9QX5NY8ASEEAtlLdIa6KVg== -"react-native-status-keycard@git+https://github.com/status-im/react-native-status-keycard.git#v2.5.30": - version "2.5.30" - resolved "git+https://github.com/status-im/react-native-status-keycard.git#958adb1e72dea1db989b4bf4663efe04ed8b2c0c" +"react-native-status-keycard@git+https://github.com/status-im/react-native-status-keycard.git#v2.5.31": + version "2.5.31" + resolved "git+https://github.com/status-im/react-native-status-keycard.git#67ba4d5596ae3f7fd123c0f1c925e98e8def493f" react-native-svg@^9.8.4: version "9.13.6"