From 77e6f83e2e779680ded258aba686e955cf428499 Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Wed, 10 Mar 2021 15:42:50 +0300 Subject: [PATCH] handle multiple paired keycards with the same account Signed-off-by: Michele Balistreri --- package.json | 2 +- src/status_im/keycard/card.cljs | 4 + src/status_im/keycard/change_pin.cljs | 7 +- src/status_im/keycard/common.cljs | 33 +++----- src/status_im/keycard/core.cljs | 44 ++++++----- src/status_im/keycard/keycard.cljs | 1 + src/status_im/keycard/login.cljs | 10 +-- src/status_im/keycard/onboarding.cljs | 5 +- src/status_im/keycard/real_keycard.cljs | 82 ++++++++++---------- src/status_im/keycard/recovery.cljs | 5 +- src/status_im/keycard/sign.cljs | 29 +++---- src/status_im/keycard/simulated_keycard.cljs | 16 +++- src/status_im/keycard/unpair.cljs | 18 ++--- src/status_im/keycard/wallet.cljs | 7 +- src/status_im/multiaccounts/login/core.cljs | 2 +- src/status_im/ui/screens/keycard/views.cljs | 2 +- yarn.lock | 6 +- 17 files changed, 134 insertions(+), 139 deletions(-) diff --git a/package.json b/package.json index 34e68d2086..ddd4d85b0d 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.32", + "react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#v2.5.33", "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 707dd5b7b9..fd37208898 100644 --- a/src/status_im/keycard/card.cljs +++ b/src/status_im/keycard/card.cljs @@ -76,6 +76,10 @@ {:code (.-code object) :error (.-message object)}) +(defn set-pairings [pairings] + (log/debug "[keycard] open-nfc-settings") + (keycard/set-pairings card {:pairings pairings})) + (defn get-application-info [{:keys [on-success] :as args}] (log/debug "[keycard] get-application-info") (keycard/get-application-info diff --git a/src/status_im/keycard/change_pin.cljs b/src/status_im/keycard/change_pin.cljs index 5e23db4ac4..0512dc1252 100644 --- a/src/status_im/keycard/change_pin.cljs +++ b/src/status_im/keycard/change_pin.cljs @@ -59,8 +59,7 @@ :on-card-connected :keycard/change-pin :handler (fn [{:keys [db] :as cofx}] - (let [pairing (common/get-pairing db) - new-pin (common/vector->string + (let [new-pin (common/vector->string (get-in db [:keycard :pin :original])) current-pin (common/vector->string (get-in db [:keycard :pin :current]))] @@ -70,8 +69,7 @@ :keycard/change-pin {:new-pin new-pin - :current-pin current-pin - :pairing pairing}})))})))) + :current-pin current-pin}})))})))) (fx/defn on-change-pin-success {:events [:keycard.callback/on-change-pin-success]} @@ -97,7 +95,6 @@ [{:keys [db] :as cofx} error] (log/debug "[keycard] change pin error" error) (let [tag-was-lost? (common/tag-lost? (:error error)) - pairing (common/get-pairing db) pin-retries (common/pin-retries (:error error))] (fx/merge cofx (if tag-was-lost? diff --git a/src/status_im/keycard/common.cljs b/src/status_im/keycard/common.cljs index eb28349ca8..162301e52a 100644 --- a/src/status_im/keycard/common.cljs +++ b/src/status_im/keycard/common.cljs @@ -329,16 +329,12 @@ (fx/defn get-keys-from-keycard [{:keys [db]}] (let [key-uid (get-in db [:multiaccounts/login :key-uid]) - pairing (get-in db [:multiaccounts/multiaccounts key-uid :keycard-pairing]) pin (string/join (get-in db [:keycard :pin :login]))] (log/debug "[keycard] get-keys-from-keycard" - "not nil pairing:" (boolean pairing) ", not empty pin:" (boolean (seq pin))) - (when (and pairing - (seq pin)) + (when (seq pin) {:db (assoc-in db [:keycard :pin :status] :verifying) - :keycard/get-keys {:pairing pairing - :pin pin}}))) + :keycard/get-keys {:pin pin}}))) (fx/defn on-get-keys-success {:events [:keycard.callback/on-get-keys-success]} @@ -417,17 +413,9 @@ (fx/defn get-application-info {:events [:keycard/get-application-info]} - [{:keys [db]} pairing on-card-read] - (let [key-uid - (when-not (:intro-wizard db) - (get-in - db [:keycard :application-info :key-uid] - (get-in db [:multiaccounts/login :key-uid]))) - pairing' (or pairing (some->> key-uid (get-pairing db)))] - (log/debug "[keycard] get-application-info" - "pairing" pairing') - {:keycard/get-application-info {:pairing pairing' - :on-success on-card-read}})) + [{:keys [db]} on-card-read] + (log/debug "[keycard] get-application-info") + {:keycard/get-application-info {:on-success on-card-read}}) (fx/defn on-get-application-info-success {:events [:keycard.callback/on-get-application-info-success]} @@ -499,8 +487,7 @@ on-card-connected (get-in db [:keycard :on-card-connected]) on-card-read (cond should-read-instance-uid? :keycard/get-application-info - :else (get-in db [:keycard :on-card-read])) - pairing (get-pairing db key-uid)] + :else (get-in db [:keycard :on-card-read]))] (log/debug "[keycard] on-card-connected" on-card-connected "on-card-read" on-card-read) (when on-card-connected @@ -512,7 +499,7 @@ (stash-on-card-connected) (when (and on-card-read (nil? on-card-connected)) - (get-application-info pairing on-card-read)))))) + (get-application-info on-card-read)))))) (fx/defn on-card-disconnected {:events [::on-card-disconnected]} @@ -546,13 +533,11 @@ {:on-card-connected (or on-card-connected :keycard/verify-pin) :handler (fn [{:keys [db] :as cofx}] - (let [pin (vector->string (get-in db [:keycard :pin pin-step])) - pairing (get-pairing db)] + (let [pin (vector->string (get-in db [:keycard :pin pin-step]))] (fx/merge cofx {:db (assoc-in db [:keycard :pin :status] :verifying) - :keycard/verify-pin {:pin pin - :pairing pairing}})))})))) + :keycard/verify-pin {:pin pin}})))})))) (fx/defn navigete-to-keycard-settings {:events [::navigate-to-keycard-settings]} diff --git a/src/status_im/keycard/core.cljs b/src/status_im/keycard/core.cljs index f4a0e5f2b1..47693cca6e 100644 --- a/src/status_im/keycard/core.cljs +++ b/src/status_im/keycard/core.cljs @@ -11,6 +11,7 @@ [status-im.keycard.recovery :as recovery] [status-im.keycard.sign :as sign] [status-im.keycard.wallet :as wallet] + [status-im.keycard.card :as card] [status-im.i18n.i18n :as i18n] [status-im.multiaccounts.recover.core :as multiaccounts.recover] [status-im.multiaccounts.update.core :as multiaccounts.update] @@ -48,6 +49,16 @@ (common/listen-to-hardware-back-button) (navigation/navigate-replace :keycard-recovery-pin nil))) +(fx/defn load-recovery-pin-screen-with-pairings + [{:keys [db] :as cofx}] + (let [instance-uid (get-in db [:keycard :application-info :instance-uid]) + {:keys [pairing paired-on]} (get-in db [:keycard :pairings (keyword instance-uid)])] + (fx/merge cofx + {:db (-> db + (assoc-in [:keycard :secrets :pairing] pairing) + (assoc-in [:keycard :secrets :paired-on] paired-on))} + (load-recovery-pin-screen)))) + (fx/defn proceed-setup-with-initialized-card [{:keys [db] :as cofx} flow instance-uid] (log/debug "[keycard] proceed-setup-with-initialized-card" @@ -133,8 +144,7 @@ (fx/defn on-unblock-pin-success {:events [:keycard.callback/on-unblock-pin-success]} [{:keys [db] :as cofx}] - (let [pairing (common/get-pairing db) - reset-pin (get-in db [:keycard :pin :reset])] + (let [reset-pin (get-in db [:keycard :pin :reset])] (fx/merge cofx {:db (-> db @@ -156,8 +166,7 @@ (fx/defn on-unblock-pin-error {:events [:keycard.callback/on-unblock-pin-error]} [{:keys [db] :as cofx} error] - (let [pairing (common/get-pairing db) - tag-was-lost? (common/tag-lost? (:error error)) + (let [tag-was-lost? (common/tag-lost? (:error error)) puk-retries (common/pin-retries (:error error))] (log/debug "[keycard] unblock pin error" error) (when-not tag-was-lost? @@ -181,8 +190,7 @@ (fx/defn on-verify-pin-success {:events [:keycard.callback/on-verify-pin-success]} [{:keys [db] :as cofx}] - (let [on-verified (get-in db [:keycard :pin :on-verified]) - pairing (common/get-pairing db)] + (let [on-verified (get-in db [:keycard :pin :on-verified])] (log/debug "[hardwaller] success pin verification. on-verified" on-verified) (fx/merge cofx {:db (update-in db [:keycard :pin] merge {:status nil @@ -202,7 +210,7 @@ :keycard/remove-key-with-unpair :keycard/unpair-and-delete :wallet.accounts/generate-new-keycard-account} on-verified) - (common/get-application-info pairing nil)) + (common/get-application-info nil)) (when on-verified (common/dispatch-event on-verified)) (clear-on-verify-handlers)))) @@ -258,13 +266,11 @@ (fn [{:keys [db]}] (let [puk (common/vector->string (get-in db [:keycard :pin :puk])) pin (common/vector->string (get-in db [:keycard :pin :reset])) - key-uid (get-in db [:keycard :application-info :key-uid]) - pairing (common/get-pairing db key-uid)] + key-uid (get-in db [:keycard :application-info :key-uid])] {:db (assoc-in db [:keycard :pin :status] :verifying) :keycard/unblock-pin {:puk puk - :new-pin pin - :pairing pairing}}))})) + :new-pin pin}}))})) (def pin-code-length 6) (def puk-code-length 12) @@ -392,6 +398,7 @@ (fx/defn on-retrieve-pairings-success {:events [:keycard.callback/on-retrieve-pairings-success]} [{:keys [db]} pairings] + (card/set-pairings pairings) {:db (assoc-in db [:keycard :pairings] pairings)}) ;; When pairing to device has completed, we need to persist pairing data to @@ -409,8 +416,9 @@ instance-uid (get-in db [:keycard :application-info :instance-uid]) multiaccount (common/find-multiaccount-by-keycard-instance-uid db instance-uid) paired-on (utils.datetime/timestamp) - pairings (assoc (get-in db [:keycard :pairings]) instance-uid {:pairing pairing - :paired-on paired-on}) + pairings (-> (get-in db [:keycard :pairings]) + (dissoc (keyword instance-uid)) + (assoc instance-uid {:pairing pairing :paired-on paired-on})) next-step (if (= setup-step :pair) :begin :card-ready)] @@ -479,10 +487,8 @@ [{:keys [db] :as cofx}] (let [app-info (get-in db [:keycard :application-info]) flow (get-in db [:keycard :flow]) - {:keys [instance-uid key-uid]} app-info - pairing (common/get-pairing db key-uid) - app-info' (if pairing (assoc app-info :paired? true) app-info) - card-state (common/get-card-state app-info')] + {:keys [instance-uid key-uid paired?]} app-info + card-state (common/get-card-state app-info)] (log/debug "[keycard] check-card-state" "card-state" card-state "flow" flow) @@ -508,8 +514,8 @@ (= flow :import)) (if (common/find-multiaccount-by-key-uid db key-uid) (multiaccounts.recover/show-existing-multiaccount-alert key-uid) - (if pairing - (load-recovery-pin-screen) + (if paired? + (load-recovery-pin-screen-with-pairings) (recovery/load-pair-screen)))) (when (= card-state :blank) diff --git a/src/status_im/keycard/keycard.cljs b/src/status_im/keycard/keycard.cljs index 76d9a1ae0f..dd71457c28 100644 --- a/src/status_im/keycard/keycard.cljs +++ b/src/status_im/keycard/keycard.cljs @@ -8,6 +8,7 @@ (check-nfc-enabled [this args]) (open-nfc-settings [this]) (register-card-events [this args]) + (set-pairings [this args]) (on-card-disconnected [this callback]) (on-card-connected [this callback]) (remove-event-listener [this event]) diff --git a/src/status_im/keycard/login.cljs b/src/status_im/keycard/login.cljs index 260ea821d9..9f8d9b1b21 100644 --- a/src/status_im/keycard/login.cljs +++ b/src/status_im/keycard/login.cljs @@ -90,16 +90,16 @@ (get-in db [:keycard :application-info]) key-uid (get-in db [:keycard :application-info :key-uid]) + paired? (get-in db [:keycard :application-info :paired?]) multiaccount (get-in db [:multiaccounts/multiaccounts (get-in db [:multiaccounts/login :key-uid])]) multiaccount-key-uid (get multiaccount :key-uid) multiaccount-mismatch? (or (nil? multiaccount) - (not= multiaccount-key-uid key-uid)) - pairing (:keycard-pairing multiaccount)] + (not= multiaccount-key-uid key-uid))] (log/debug "[keycard] login-with-keycard" "empty application info" (empty? application-info) "no key-uid" (empty? key-uid) "multiaccount-mismatch?" multiaccount-mismatch? - "no pairing" (empty? pairing)) + "no pairing" paired?) (cond (empty? application-info) (fx/merge cofx @@ -116,7 +116,7 @@ (common/hide-connection-sheet) (navigation/navigate-to-cofx :keycard-wrong nil)) - (empty? pairing) + (not paired?) (fx/merge cofx (common/hide-connection-sheet) (navigation/navigate-to-cofx :keycard-unpaired nil)) @@ -138,7 +138,7 @@ {:sheet-options {:on-cancel [::common/cancel-sheet-confirm]} :on-card-connected :keycard/get-application-info :on-card-read :keycard/login-with-keycard - :handler (common/get-application-info nil :keycard/login-with-keycard)})) + :handler (common/get-application-info :keycard/login-with-keycard)})) (fx/defn on-keycard-keychain-keys {:events [:multiaccounts.login.callback/get-keycard-keys-success]} diff --git a/src/status_im/keycard/onboarding.cljs b/src/status_im/keycard/onboarding.cljs index ddbc9bc5e3..e6fd2f0645 100644 --- a/src/status_im/keycard/onboarding.cljs +++ b/src/status_im/keycard/onboarding.cljs @@ -253,7 +253,7 @@ (fx/defn generate-and-load-key {:events [:keycard/generate-and-load-key]} [{:keys [db] :as cofx}] - (let [{:keys [pairing pin]} + (let [{:keys [pin]} (get-in db [:keycard :secrets]) {:keys [selected-id multiaccounts]} @@ -272,7 +272,6 @@ (fx/merge cofx {:keycard/generate-and-load-key {:mnemonic mnemonic - :pairing pairing :pin pin'}}))) (fx/defn begin-setup-pressed @@ -290,7 +289,7 @@ (common/show-connection-sheet {:on-card-connected :keycard/get-application-info :on-card-read :keycard/check-card-state - :handler (common/get-application-info nil :keycard/check-card-state)}))) + :handler (common/get-application-info :keycard/check-card-state)}))) (fx/defn cancel-confirm {:events [::cancel-confirm]} diff --git a/src/status_im/keycard/real_keycard.cljs b/src/status_im/keycard/real_keycard.cljs index 9491984b3f..0a17850cb3 100644 --- a/src/status_im/keycard/real_keycard.cljs +++ b/src/status_im/keycard/real_keycard.cljs @@ -80,6 +80,9 @@ [callback] (.addListener ^js event-emitter "keyCardOnNFCDisabled" callback)) +(defn set-pairings [{:keys [pairings]}] + (.. status-keycard (setPairings (clj->js (or pairings {}))))) + (defn register-card-events [args] (doseq [listener @active-listeners] @@ -93,10 +96,10 @@ (on-nfc-disabled (:on-nfc-disabled args))])) (defn get-application-info - [{:keys [pairing on-success on-failure]}] + [{:keys [on-success on-failure]}] (.. status-keycard - (getApplicationInfo (str pairing)) + (getApplicationInfo) (then (fn [response] (let [info (-> response (js->clj :keywordize-keys true) @@ -137,42 +140,41 @@ (catch on-failure)))) (defn generate-and-load-key - [{:keys [mnemonic pairing pin on-success on-failure]}] - (when pairing - (.. status-keycard - (generateAndLoadKey mnemonic pairing pin) - (then on-success) - (catch on-failure)))) + [{:keys [mnemonic pin on-success on-failure]}] + (.. status-keycard + (generateAndLoadKey mnemonic pin) + (then on-success) + (catch on-failure))) (defn unblock-pin - [{:keys [puk new-pin pairing on-success on-failure]}] - (when (and pairing new-pin puk) + [{:keys [puk new-pin on-success on-failure]}] + (when (and new-pin puk) (.. status-keycard - (unblockPin pairing puk new-pin) + (unblockPin puk new-pin) (then on-success) (catch on-failure)))) (defn verify-pin - [{:keys [pin pairing on-success on-failure]}] - (when (and pairing (not-empty pin)) + [{:keys [pin on-success on-failure]}] + (when (not-empty pin) (.. status-keycard - (verifyPin pairing pin) + (verifyPin pin) (then on-success) (catch on-failure)))) (defn change-pin - [{:keys [current-pin new-pin pairing on-success on-failure]}] - (when (and pairing current-pin new-pin) + [{:keys [current-pin new-pin on-success on-failure]}] + (when (and current-pin new-pin) (.. status-keycard - (changePin pairing current-pin new-pin) + (changePin current-pin new-pin) (then on-success) (catch on-failure)))) (defn unpair - [{:keys [pin pairing on-success on-failure]}] - (when (and pairing pin) + [{:keys [pin on-success on-failure]}] + (when (and pin) (.. status-keycard - (unpair pairing pin) + (unpair pin) (then on-success) (catch on-failure)))) @@ -183,61 +185,61 @@ (catch on-failure))) (defn remove-key - [{:keys [pin pairing on-success on-failure]}] + [{:keys [pin on-success on-failure]}] (.. status-keycard - (removeKey pairing pin) + (removeKey pin) (then on-success) (catch on-failure))) (defn remove-key-with-unpair - [{:keys [pin pairing on-success on-failure]}] + [{:keys [pin on-success on-failure]}] (.. status-keycard - (removeKeyWithUnpair pairing pin) + (removeKeyWithUnpair pin) (then on-success) (catch on-failure))) (defn export-key - [{:keys [pin pairing path on-success on-failure]}] + [{:keys [pin path on-success on-failure]}] (.. status-keycard - (exportKeyWithPath pairing pin path) + (exportKeyWithPath pin path) (then on-success) (catch on-failure))) (defn unpair-and-delete - [{:keys [pin pairing on-success on-failure]}] - (when (and pairing pin) + [{:keys [pin on-success on-failure]}] + (when (not-empty pin) (.. status-keycard - (unpairAndDelete pairing pin) + (unpairAndDelete pin) (then on-success) (catch on-failure)))) (defn import-keys - [{:keys [pairing pin on-success on-failure]}] - (when (and pairing (not-empty pin)) + [{:keys [pin on-success on-failure]}] + (when (not-empty pin) (.. status-keycard - (importKeys pairing pin) + (importKeys pin) (then on-success) (catch on-failure)))) (defn get-keys - [{:keys [pairing pin on-success on-failure]}] - (when (and pairing (not-empty pin)) + [{:keys [pin on-success on-failure]}] + (when (not-empty pin) (.. status-keycard - (getKeys pairing pin) + (getKeys pin) (then on-success) (catch on-failure)))) (defn sign - [{:keys [pairing pin path hash on-success on-failure]}] + [{:keys [pin path hash on-success on-failure]}] (log/debug "keycard sign" "path" path) - (when (and pairing pin hash) + (when (and pin hash) (if path (.. status-keycard - (signWithPath pairing pin path hash) + (signWithPath pin path hash) (then on-success) (catch on-failure)) (.. status-keycard - (sign pairing pin hash) + (sign pin hash) (then on-success) (catch on-failure))))) @@ -291,6 +293,8 @@ (remove-event-listener event)) (keycard/remove-event-listeners [this] (remove-event-listeners)) + (keycard/set-pairings [this args] + (set-pairings args)) (keycard/get-application-info [this args] (get-application-info args)) (keycard/install-applet [this args] diff --git a/src/status_im/keycard/recovery.cljs b/src/status_im/keycard/recovery.cljs index 3195f5bf5e..2414e6a6c2 100644 --- a/src/status_im/keycard/recovery.cljs +++ b/src/status_im/keycard/recovery.cljs @@ -115,7 +115,7 @@ {:on-card-connected :keycard/get-application-info :on-card-read :keycard/check-card-state :sheet-options {:on-cancel [::cancel-pressed]} - :handler (common/get-application-info nil :keycard/check-card-state)}))) + :handler (common/get-application-info :keycard/check-card-state)}))) (fx/defn recovery-success-finish-pressed {:events [:keycard.recovery.success/finish-pressed]} @@ -253,8 +253,7 @@ (assoc-in [:keycard :pin :status] :verifying) (assoc-in [:keycard :secrets] {:pairing pairing' :paired-on (utils.datetime/timestamp)})) - :keycard/import-keys {:pairing pairing' - :pin pin + :keycard/import-keys {:pin pin :on-success :keycard.callback/on-generate-and-load-key-success}}))) (fx/defn load-recovering-key-screen diff --git a/src/status_im/keycard/sign.cljs b/src/status_im/keycard/sign.cljs index c97806aefa..45a585e76c 100644 --- a/src/status_im/keycard/sign.cljs +++ b/src/status_im/keycard/sign.cljs @@ -13,10 +13,9 @@ {:events [:keycard/sign]} [{:keys [db] :as cofx}] (let [card-connected? (get-in db [:keycard :card-connected?]) - pairing (common/get-pairing db) - keycard-instance-uid (get-in db [:multiaccount :keycard-instance-uid]) - instance-uid (get-in db [:keycard :application-info :instance-uid]) - keycard-match? (= keycard-instance-uid instance-uid) + key-uid (get-in db [:multiaccount :key-uid]) + keycard-key-uid (get-in db [:keycard :application-info :key-uid]) + keycard-match? (= key-uid keycard-key-uid) hash (get-in db [:keycard :hash]) data (get-in db [:keycard :data]) typed? (get-in db [:keycard :typed?]) @@ -35,7 +34,6 @@ (assoc-in [:keycard :pin :status] :verifying)) :keycard/sign {:hash (ethereum/naked-address hash) :data data - :pairing pairing :typed? typed? :pin pin :path path}} @@ -59,10 +57,9 @@ (normalize-signature %)]) hash (ethereum/naked-address result) card-connected? (get-in db [:keycard :card-connected?]) - pairing (common/get-pairing db) - multiaccount-keycard-instance-uid (get-in db [:multiaccount :keycard-instance-uid]) - instance-uid (get-in db [:keycard :application-info :instance-uid]) - keycard-match? (= multiaccount-keycard-instance-uid instance-uid) + key-uid (get-in db [:multiaccount :key-uid]) + keycard-key-uid (get-in db [:keycard :application-info :key-uid]) + keycard-match? (= key-uid keycard-key-uid) pin (common/vector->string (get-in db [:keycard :pin :sign]))] (if (and card-connected? keycard-match?) @@ -71,7 +68,6 @@ (assoc-in [:keycard :pin :status] :verifying)) :keycard/sign {:hash (ethereum/naked-address hash) :data (:data params) - :pairing pairing :pin pin :on-success on-success}} (fx/merge cofx @@ -94,7 +90,7 @@ (assoc-in [:keycard :pin :sign] []) (assoc-in [:keycard :pin :status] nil))} (common/clear-on-card-connected) - (common/get-application-info (common/get-pairing db) nil) + (common/get-application-info nil) (common/hide-connection-sheet))) (fx/defn sign-typed-data @@ -149,11 +145,10 @@ (fx/defn prepare-to-sign {:events [:keycard/prepare-to-sign]} [{:keys [db] :as cofx}] - (let [pairing (common/get-pairing db)] - (common/show-connection-sheet - cofx - {:on-card-connected :keycard/prepare-to-sign - :handler (common/get-application-info pairing :keycard/sign)}))) + (common/show-connection-sheet + cofx + {:on-card-connected :keycard/prepare-to-sign + :handler (common/get-application-info :keycard/sign)})) (fx/defn sign-message-completed [_ signature] @@ -184,7 +179,7 @@ (assoc-in [:keycard :pin :sign] []) (assoc-in [:keycard :pin :status] nil))} (common/clear-on-card-connected) - (common/get-application-info (common/get-pairing db) nil) + (common/get-application-info nil) (common/hide-connection-sheet)))) (if transaction (send-transaction-with-signature diff --git a/src/status_im/keycard/simulated_keycard.cljs b/src/status_im/keycard/simulated_keycard.cljs index ab328dfcb8..424bd2d884 100644 --- a/src/status_im/keycard/simulated_keycard.cljs +++ b/src/status_im/keycard/simulated_keycard.cljs @@ -47,7 +47,7 @@ :app-version "2.2" :secure-channel-pub-key "04c3071768912a515c00aeab7ceb8a5bfda91d036f4a4e60b7944cee3ca7fb67b6d118e8df1e2480b87fd636c6615253245bbbc93a6a407f155f2c58f76c96ef0e", :instance-uid "1b360b10a9a68b7d494e8f059059f118" - :paired? true + :paired? false :has-master-key? true :initialized? true :pin-retry-counter 3 @@ -102,6 +102,9 @@ (on-card-connected (:on-card-connected args)) (on-card-disconnected (:on-card-disconnected args))) +(defn set-pairings [args] + (log/warn "set-pairings not implemented" args)) + (defn remove-event-listener [id] (log/debug "remove-event-listener") (swap! state update :on-card-connected dissoc id) @@ -203,7 +206,9 @@ {:root-key root-data :derived derived-data-extended}))))))))))) (when (= password kk1-password) - (later #(on-success (str (rand-int 10000000)))))) + (do + (swap! state assoc-in [:application-info :paired?] true) + (later #(on-success (str (rand-int 10000000))))))) (defn generate-and-load-key [{:keys [pin on-success]}] @@ -212,6 +217,8 @@ pin (:intro-wizard @re-frame.db/app-db))] (log/debug "[simulated kk] generate-and-load-key response" response) + (swap! state assoc-in + [:application-info :key-uid] (:key-uid response)) (status/multiaccount-store-derived id (:key-uid response) @@ -314,6 +321,8 @@ (later (if @derived-acc (let [[id keys] (multiaccount->keys pin @derived-acc)] + (swap! state assoc-in + [:application-info :key-uid] (:key-uid keys)) (status/multiaccount-store-derived id (:key-uid keys) @@ -428,6 +437,9 @@ (keycard/register-card-events [this args] (log/debug "simulated card register-card-event") (register-card-events args)) + (keycard/set-pairings [this args] + (log/debug "simulated card set-pairings") + (set-pairings args)) (keycard/on-card-connected [this callback] (log/debug "simulated card on-card-connected") (on-card-connected callback)) diff --git a/src/status_im/keycard/unpair.cljs b/src/status_im/keycard/unpair.cljs index 7077d1aa9b..64b9b687df 100644 --- a/src/status_im/keycard/unpair.cljs +++ b/src/status_im/keycard/unpair.cljs @@ -37,10 +37,8 @@ (fx/defn unpair {:events [:keycard/unpair]} [{:keys [db]}] - (let [pin (common/vector->string (get-in db [:keycard :pin :current])) - pairing (common/get-pairing db)] - {:keycard/unpair {:pin pin - :pairing pairing}})) + (let [pin (common/vector->string (get-in db [:keycard :pin :current]))] + {:keycard/unpair {:pin pin}})) (fx/defn unpair-and-delete {:events [:keycard/unpair-and-delete]} @@ -50,11 +48,9 @@ {:on-card-connected :keycard/unpair-and-delete :handler (fn [{:keys [db]}] - (let [pin (common/vector->string (get-in db [:keycard :pin :current])) - pairing (common/get-pairing db)] + (let [pin (common/vector->string (get-in db [:keycard :pin :current]))] {:keycard/unpair-and-delete - {:pin pin - :pairing pairing}}))})) + {:pin pin}}))})) (fx/defn remove-pairing-from-multiaccount [cofx {:keys [remove-instance-uid?]}] @@ -108,11 +104,9 @@ {:on-card-connected :keycard/remove-key-with-unpair :handler (fn [{:keys [db]}] - (let [pin (common/vector->string (get-in db [:keycard :pin :current])) - pairing (common/get-pairing db)] + (let [pin (common/vector->string (get-in db [:keycard :pin :current]))] {:keycard/remove-key-with-unpair - {:pin pin - :pairing pairing}}))})) + {:pin pin}}))})) (defn handle-account-removal [{:keys [db] :as cofx} keys-removed-from-card?] (let [key-uid (get-in db [:multiaccount :key-uid]) diff --git a/src/status_im/keycard/wallet.cljs b/src/status_im/keycard/wallet.cljs index 3cee934764..740efa1cc0 100644 --- a/src/status_im/keycard/wallet.cljs +++ b/src/status_im/keycard/wallet.cljs @@ -19,7 +19,7 @@ (fx/defn verify-pin-with-delay [cofx] {:utils/dispatch-later - ;; We need to give previous sheet some time to be fully hidden + ;; We need to give previous sheet some time to be fully hidden [{:ms 200 :dispatch [:wallet.accounts/verify-pin]}]}) @@ -33,8 +33,7 @@ [{:keys [db]}] (let [path-num (inc (get-in db [:multiaccount :latest-derived-path])) path (str constants/path-wallet-root "/" path-num) - pin (common/vector->string (get-in db [:keycard :pin :export-key])) - pairing (common/get-pairing db)] + pin (common/vector->string (get-in db [:keycard :pin :export-key]))] {:db (assoc-in db [:keycard :on-export-success] @@ -48,7 +47,7 @@ :public-key (str "0x" public-key) :path path}))) - :keycard/export-key {:pin pin :pairing pairing :path path}})) + :keycard/export-key {:pin pin :path path}})) (fx/defn verify-pin {:events [:wallet.accounts/verify-pin]} diff --git a/src/status_im/multiaccounts/login/core.cljs b/src/status_im/multiaccounts/login/core.cljs index ffd622562e..f9815d45b8 100644 --- a/src/status_im/multiaccounts/login/core.cljs +++ b/src/status_im/multiaccounts/login/core.cljs @@ -438,7 +438,7 @@ (get-credentials % key-uid) (and keycard-multiaccount? (get-in db [:keycard :card-connected?])) - (keycard.common/get-application-info % nil nil)) + (keycard.common/get-application-info % nil)) (open-login-callback nil)))) (fx/defn biometric-auth-done diff --git a/src/status_im/ui/screens/keycard/views.cljs b/src/status_im/ui/screens/keycard/views.cljs index 8f475c3479..5e128df436 100644 --- a/src/status_im/ui/screens/keycard/views.cljs +++ b/src/status_im/ui/screens/keycard/views.cljs @@ -116,7 +116,7 @@ (i18n/label :t/pair-this-card)] [react/view {:margin-top 27} [quo/button {:type :secondary - :on-press #(re-frame/dispatch [:keycard.login.ui/dismiss-pressed])} + :on-press #(re-frame/dispatch [:navigate-back])} (i18n/label :t/dismiss)]]]]]) ;; NOTE(Ferossgp): Seems like it should be in popover diff --git a/yarn.lock b/yarn.lock index 9d3e3a37e7..3a26730e61 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.32": - version "2.5.32" - resolved "git+https://github.com/status-im/react-native-status-keycard.git#f602fadf800937fc1de92aa18c2e58c372eb1bed" +"react-native-status-keycard@git+https://github.com/status-im/react-native-status-keycard.git#v2.5.33": + version "2.5.33" + resolved "git+https://github.com/status-im/react-native-status-keycard.git#d1098e969a1007919134e210781bdc57222bf8d3" react-native-svg@^9.8.4: version "9.13.6"