handle multiple paired keycards with the same account

Signed-off-by: Michele Balistreri <michele@bitgamma.com>
This commit is contained in:
Michele Balistreri 2021-03-10 15:42:50 +03:00
parent 4e0ec35ea5
commit 77e6f83e2e
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
17 changed files with 134 additions and 139 deletions

View File

@ -61,7 +61,7 @@
"react-native-screens": "^2.10.1", "react-native-screens": "^2.10.1",
"react-native-shake": "^3.3.1", "react-native-shake": "^3.3.1",
"react-native-splash-screen": "^3.2.0", "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-svg": "^9.8.4",
"react-native-touch-id": "^4.4.1", "react-native-touch-id": "^4.4.1",
"react-native-webview": "git+https://github.com/status-im/react-native-webview.git#v10.9.2", "react-native-webview": "git+https://github.com/status-im/react-native-webview.git#v10.9.2",

View File

@ -76,6 +76,10 @@
{:code (.-code object) {:code (.-code object)
:error (.-message 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}] (defn get-application-info [{:keys [on-success] :as args}]
(log/debug "[keycard] get-application-info") (log/debug "[keycard] get-application-info")
(keycard/get-application-info (keycard/get-application-info

View File

@ -59,8 +59,7 @@
:on-card-connected :keycard/change-pin :on-card-connected :keycard/change-pin
:handler :handler
(fn [{:keys [db] :as cofx}] (fn [{:keys [db] :as cofx}]
(let [pairing (common/get-pairing db) (let [new-pin (common/vector->string
new-pin (common/vector->string
(get-in db [:keycard :pin :original])) (get-in db [:keycard :pin :original]))
current-pin (common/vector->string current-pin (common/vector->string
(get-in db [:keycard :pin :current]))] (get-in db [:keycard :pin :current]))]
@ -70,8 +69,7 @@
:keycard/change-pin :keycard/change-pin
{:new-pin new-pin {:new-pin new-pin
:current-pin current-pin :current-pin current-pin}})))}))))
:pairing pairing}})))}))))
(fx/defn on-change-pin-success (fx/defn on-change-pin-success
{:events [:keycard.callback/on-change-pin-success]} {:events [:keycard.callback/on-change-pin-success]}
@ -97,7 +95,6 @@
[{:keys [db] :as cofx} error] [{:keys [db] :as cofx} error]
(log/debug "[keycard] change pin error" error) (log/debug "[keycard] change pin error" error)
(let [tag-was-lost? (common/tag-lost? (:error error)) (let [tag-was-lost? (common/tag-lost? (:error error))
pairing (common/get-pairing db)
pin-retries (common/pin-retries (:error error))] pin-retries (common/pin-retries (:error error))]
(fx/merge cofx (fx/merge cofx
(if tag-was-lost? (if tag-was-lost?

View File

@ -329,16 +329,12 @@
(fx/defn get-keys-from-keycard (fx/defn get-keys-from-keycard
[{:keys [db]}] [{:keys [db]}]
(let [key-uid (get-in db [:multiaccounts/login :key-uid]) (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]))] pin (string/join (get-in db [:keycard :pin :login]))]
(log/debug "[keycard] get-keys-from-keycard" (log/debug "[keycard] get-keys-from-keycard"
"not nil pairing:" (boolean pairing)
", not empty pin:" (boolean (seq pin))) ", not empty pin:" (boolean (seq pin)))
(when (and pairing (when (seq pin)
(seq pin))
{:db (assoc-in db [:keycard :pin :status] :verifying) {:db (assoc-in db [:keycard :pin :status] :verifying)
:keycard/get-keys {:pairing pairing :keycard/get-keys {:pin pin}})))
:pin pin}})))
(fx/defn on-get-keys-success (fx/defn on-get-keys-success
{:events [:keycard.callback/on-get-keys-success]} {:events [:keycard.callback/on-get-keys-success]}
@ -417,17 +413,9 @@
(fx/defn get-application-info (fx/defn get-application-info
{:events [:keycard/get-application-info]} {:events [:keycard/get-application-info]}
[{:keys [db]} pairing on-card-read] [{:keys [db]} on-card-read]
(let [key-uid (log/debug "[keycard] get-application-info")
(when-not (:intro-wizard db) {:keycard/get-application-info {:on-success on-card-read}})
(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}}))
(fx/defn on-get-application-info-success (fx/defn on-get-application-info-success
{:events [:keycard.callback/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-connected (get-in db [:keycard :on-card-connected])
on-card-read (cond on-card-read (cond
should-read-instance-uid? :keycard/get-application-info should-read-instance-uid? :keycard/get-application-info
:else (get-in db [:keycard :on-card-read])) :else (get-in db [:keycard :on-card-read]))]
pairing (get-pairing db key-uid)]
(log/debug "[keycard] on-card-connected" on-card-connected (log/debug "[keycard] on-card-connected" on-card-connected
"on-card-read" on-card-read) "on-card-read" on-card-read)
(when on-card-connected (when on-card-connected
@ -512,7 +499,7 @@
(stash-on-card-connected) (stash-on-card-connected)
(when (and on-card-read (when (and on-card-read
(nil? on-card-connected)) (nil? on-card-connected))
(get-application-info pairing on-card-read)))))) (get-application-info on-card-read))))))
(fx/defn on-card-disconnected (fx/defn on-card-disconnected
{:events [::on-card-disconnected]} {:events [::on-card-disconnected]}
@ -546,13 +533,11 @@
{:on-card-connected (or on-card-connected :keycard/verify-pin) {:on-card-connected (or on-card-connected :keycard/verify-pin)
:handler :handler
(fn [{:keys [db] :as cofx}] (fn [{:keys [db] :as cofx}]
(let [pin (vector->string (get-in db [:keycard :pin pin-step])) (let [pin (vector->string (get-in db [:keycard :pin pin-step]))]
pairing (get-pairing db)]
(fx/merge (fx/merge
cofx cofx
{:db (assoc-in db [:keycard :pin :status] :verifying) {:db (assoc-in db [:keycard :pin :status] :verifying)
:keycard/verify-pin {:pin pin :keycard/verify-pin {:pin pin}})))}))))
:pairing pairing}})))}))))
(fx/defn navigete-to-keycard-settings (fx/defn navigete-to-keycard-settings
{:events [::navigate-to-keycard-settings]} {:events [::navigate-to-keycard-settings]}

View File

@ -11,6 +11,7 @@
[status-im.keycard.recovery :as recovery] [status-im.keycard.recovery :as recovery]
[status-im.keycard.sign :as sign] [status-im.keycard.sign :as sign]
[status-im.keycard.wallet :as wallet] [status-im.keycard.wallet :as wallet]
[status-im.keycard.card :as card]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im.multiaccounts.recover.core :as multiaccounts.recover] [status-im.multiaccounts.recover.core :as multiaccounts.recover]
[status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.multiaccounts.update.core :as multiaccounts.update]
@ -48,6 +49,16 @@
(common/listen-to-hardware-back-button) (common/listen-to-hardware-back-button)
(navigation/navigate-replace :keycard-recovery-pin nil))) (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 (fx/defn proceed-setup-with-initialized-card
[{:keys [db] :as cofx} flow instance-uid] [{:keys [db] :as cofx} flow instance-uid]
(log/debug "[keycard] proceed-setup-with-initialized-card" (log/debug "[keycard] proceed-setup-with-initialized-card"
@ -133,8 +144,7 @@
(fx/defn on-unblock-pin-success (fx/defn on-unblock-pin-success
{:events [:keycard.callback/on-unblock-pin-success]} {:events [:keycard.callback/on-unblock-pin-success]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [pairing (common/get-pairing db) (let [reset-pin (get-in db [:keycard :pin :reset])]
reset-pin (get-in db [:keycard :pin :reset])]
(fx/merge cofx (fx/merge cofx
{:db {:db
(-> db (-> db
@ -156,8 +166,7 @@
(fx/defn on-unblock-pin-error (fx/defn on-unblock-pin-error
{:events [:keycard.callback/on-unblock-pin-error]} {:events [:keycard.callback/on-unblock-pin-error]}
[{:keys [db] :as cofx} error] [{:keys [db] :as cofx} error]
(let [pairing (common/get-pairing db) (let [tag-was-lost? (common/tag-lost? (:error error))
tag-was-lost? (common/tag-lost? (:error error))
puk-retries (common/pin-retries (:error error))] puk-retries (common/pin-retries (:error error))]
(log/debug "[keycard] unblock pin error" error) (log/debug "[keycard] unblock pin error" error)
(when-not tag-was-lost? (when-not tag-was-lost?
@ -181,8 +190,7 @@
(fx/defn on-verify-pin-success (fx/defn on-verify-pin-success
{:events [:keycard.callback/on-verify-pin-success]} {:events [:keycard.callback/on-verify-pin-success]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [on-verified (get-in db [:keycard :pin :on-verified]) (let [on-verified (get-in db [:keycard :pin :on-verified])]
pairing (common/get-pairing db)]
(log/debug "[hardwaller] success pin verification. on-verified" on-verified) (log/debug "[hardwaller] success pin verification. on-verified" on-verified)
(fx/merge cofx (fx/merge cofx
{:db (update-in db [:keycard :pin] merge {:status nil {:db (update-in db [:keycard :pin] merge {:status nil
@ -202,7 +210,7 @@
:keycard/remove-key-with-unpair :keycard/remove-key-with-unpair
:keycard/unpair-and-delete :keycard/unpair-and-delete
:wallet.accounts/generate-new-keycard-account} on-verified) :wallet.accounts/generate-new-keycard-account} on-verified)
(common/get-application-info pairing nil)) (common/get-application-info nil))
(when on-verified (when on-verified
(common/dispatch-event on-verified)) (common/dispatch-event on-verified))
(clear-on-verify-handlers)))) (clear-on-verify-handlers))))
@ -258,13 +266,11 @@
(fn [{:keys [db]}] (fn [{:keys [db]}]
(let [puk (common/vector->string (get-in db [:keycard :pin :puk])) (let [puk (common/vector->string (get-in db [:keycard :pin :puk]))
pin (common/vector->string (get-in db [:keycard :pin :reset])) pin (common/vector->string (get-in db [:keycard :pin :reset]))
key-uid (get-in db [:keycard :application-info :key-uid]) key-uid (get-in db [:keycard :application-info :key-uid])]
pairing (common/get-pairing db key-uid)]
{:db (assoc-in db [:keycard :pin :status] :verifying) {:db (assoc-in db [:keycard :pin :status] :verifying)
:keycard/unblock-pin :keycard/unblock-pin
{:puk puk {:puk puk
:new-pin pin :new-pin pin}}))}))
:pairing pairing}}))}))
(def pin-code-length 6) (def pin-code-length 6)
(def puk-code-length 12) (def puk-code-length 12)
@ -392,6 +398,7 @@
(fx/defn on-retrieve-pairings-success (fx/defn on-retrieve-pairings-success
{:events [:keycard.callback/on-retrieve-pairings-success]} {:events [:keycard.callback/on-retrieve-pairings-success]}
[{:keys [db]} pairings] [{:keys [db]} pairings]
(card/set-pairings pairings)
{:db (assoc-in db [:keycard :pairings] pairings)}) {:db (assoc-in db [:keycard :pairings] pairings)})
;; When pairing to device has completed, we need to persist pairing data to ;; 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]) instance-uid (get-in db [:keycard :application-info :instance-uid])
multiaccount (common/find-multiaccount-by-keycard-instance-uid db instance-uid) multiaccount (common/find-multiaccount-by-keycard-instance-uid db instance-uid)
paired-on (utils.datetime/timestamp) paired-on (utils.datetime/timestamp)
pairings (assoc (get-in db [:keycard :pairings]) instance-uid {:pairing pairing pairings (-> (get-in db [:keycard :pairings])
:paired-on paired-on}) (dissoc (keyword instance-uid))
(assoc instance-uid {:pairing pairing :paired-on paired-on}))
next-step (if (= setup-step :pair) next-step (if (= setup-step :pair)
:begin :begin
:card-ready)] :card-ready)]
@ -479,10 +487,8 @@
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [app-info (get-in db [:keycard :application-info]) (let [app-info (get-in db [:keycard :application-info])
flow (get-in db [:keycard :flow]) flow (get-in db [:keycard :flow])
{:keys [instance-uid key-uid]} app-info {:keys [instance-uid key-uid paired?]} app-info
pairing (common/get-pairing db key-uid) card-state (common/get-card-state app-info)]
app-info' (if pairing (assoc app-info :paired? true) app-info)
card-state (common/get-card-state app-info')]
(log/debug "[keycard] check-card-state" (log/debug "[keycard] check-card-state"
"card-state" card-state "card-state" card-state
"flow" flow) "flow" flow)
@ -508,8 +514,8 @@
(= flow :import)) (= flow :import))
(if (common/find-multiaccount-by-key-uid db key-uid) (if (common/find-multiaccount-by-key-uid db key-uid)
(multiaccounts.recover/show-existing-multiaccount-alert key-uid) (multiaccounts.recover/show-existing-multiaccount-alert key-uid)
(if pairing (if paired?
(load-recovery-pin-screen) (load-recovery-pin-screen-with-pairings)
(recovery/load-pair-screen)))) (recovery/load-pair-screen))))
(when (= card-state :blank) (when (= card-state :blank)

View File

@ -8,6 +8,7 @@
(check-nfc-enabled [this args]) (check-nfc-enabled [this args])
(open-nfc-settings [this]) (open-nfc-settings [this])
(register-card-events [this args]) (register-card-events [this args])
(set-pairings [this args])
(on-card-disconnected [this callback]) (on-card-disconnected [this callback])
(on-card-connected [this callback]) (on-card-connected [this callback])
(remove-event-listener [this event]) (remove-event-listener [this event])

View File

@ -90,16 +90,16 @@
(get-in db [:keycard :application-info]) (get-in db [:keycard :application-info])
key-uid (get-in db [:keycard :application-info :key-uid]) 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 (get-in db [:multiaccounts/multiaccounts (get-in db [:multiaccounts/login :key-uid])])
multiaccount-key-uid (get multiaccount :key-uid) multiaccount-key-uid (get multiaccount :key-uid)
multiaccount-mismatch? (or (nil? multiaccount) multiaccount-mismatch? (or (nil? multiaccount)
(not= multiaccount-key-uid key-uid)) (not= multiaccount-key-uid key-uid))]
pairing (:keycard-pairing multiaccount)]
(log/debug "[keycard] login-with-keycard" (log/debug "[keycard] login-with-keycard"
"empty application info" (empty? application-info) "empty application info" (empty? application-info)
"no key-uid" (empty? key-uid) "no key-uid" (empty? key-uid)
"multiaccount-mismatch?" multiaccount-mismatch? "multiaccount-mismatch?" multiaccount-mismatch?
"no pairing" (empty? pairing)) "no pairing" paired?)
(cond (cond
(empty? application-info) (empty? application-info)
(fx/merge cofx (fx/merge cofx
@ -116,7 +116,7 @@
(common/hide-connection-sheet) (common/hide-connection-sheet)
(navigation/navigate-to-cofx :keycard-wrong nil)) (navigation/navigate-to-cofx :keycard-wrong nil))
(empty? pairing) (not paired?)
(fx/merge cofx (fx/merge cofx
(common/hide-connection-sheet) (common/hide-connection-sheet)
(navigation/navigate-to-cofx :keycard-unpaired nil)) (navigation/navigate-to-cofx :keycard-unpaired nil))
@ -138,7 +138,7 @@
{:sheet-options {:on-cancel [::common/cancel-sheet-confirm]} {:sheet-options {:on-cancel [::common/cancel-sheet-confirm]}
:on-card-connected :keycard/get-application-info :on-card-connected :keycard/get-application-info
:on-card-read :keycard/login-with-keycard :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 (fx/defn on-keycard-keychain-keys
{:events [:multiaccounts.login.callback/get-keycard-keys-success]} {:events [:multiaccounts.login.callback/get-keycard-keys-success]}

View File

@ -253,7 +253,7 @@
(fx/defn generate-and-load-key (fx/defn generate-and-load-key
{:events [:keycard/generate-and-load-key]} {:events [:keycard/generate-and-load-key]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [{:keys [pairing pin]} (let [{:keys [pin]}
(get-in db [:keycard :secrets]) (get-in db [:keycard :secrets])
{:keys [selected-id multiaccounts]} {:keys [selected-id multiaccounts]}
@ -272,7 +272,6 @@
(fx/merge cofx (fx/merge cofx
{:keycard/generate-and-load-key {:keycard/generate-and-load-key
{:mnemonic mnemonic {:mnemonic mnemonic
:pairing pairing
:pin pin'}}))) :pin pin'}})))
(fx/defn begin-setup-pressed (fx/defn begin-setup-pressed
@ -290,7 +289,7 @@
(common/show-connection-sheet (common/show-connection-sheet
{:on-card-connected :keycard/get-application-info {:on-card-connected :keycard/get-application-info
:on-card-read :keycard/check-card-state :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 (fx/defn cancel-confirm
{:events [::cancel-confirm]} {:events [::cancel-confirm]}

View File

@ -80,6 +80,9 @@
[callback] [callback]
(.addListener ^js event-emitter "keyCardOnNFCDisabled" callback)) (.addListener ^js event-emitter "keyCardOnNFCDisabled" callback))
(defn set-pairings [{:keys [pairings]}]
(.. status-keycard (setPairings (clj->js (or pairings {})))))
(defn register-card-events (defn register-card-events
[args] [args]
(doseq [listener @active-listeners] (doseq [listener @active-listeners]
@ -93,10 +96,10 @@
(on-nfc-disabled (:on-nfc-disabled args))])) (on-nfc-disabled (:on-nfc-disabled args))]))
(defn get-application-info (defn get-application-info
[{:keys [pairing on-success on-failure]}] [{:keys [on-success on-failure]}]
(.. status-keycard (.. status-keycard
(getApplicationInfo (str pairing)) (getApplicationInfo)
(then (fn [response] (then (fn [response]
(let [info (-> response (let [info (-> response
(js->clj :keywordize-keys true) (js->clj :keywordize-keys true)
@ -137,42 +140,41 @@
(catch on-failure)))) (catch on-failure))))
(defn generate-and-load-key (defn generate-and-load-key
[{:keys [mnemonic pairing pin on-success on-failure]}] [{:keys [mnemonic pin on-success on-failure]}]
(when pairing
(.. status-keycard (.. status-keycard
(generateAndLoadKey mnemonic pairing pin) (generateAndLoadKey mnemonic pin)
(then on-success) (then on-success)
(catch on-failure)))) (catch on-failure)))
(defn unblock-pin (defn unblock-pin
[{:keys [puk new-pin pairing on-success on-failure]}] [{:keys [puk new-pin on-success on-failure]}]
(when (and pairing new-pin puk) (when (and new-pin puk)
(.. status-keycard (.. status-keycard
(unblockPin pairing puk new-pin) (unblockPin puk new-pin)
(then on-success) (then on-success)
(catch on-failure)))) (catch on-failure))))
(defn verify-pin (defn verify-pin
[{:keys [pin pairing on-success on-failure]}] [{:keys [pin on-success on-failure]}]
(when (and pairing (not-empty pin)) (when (not-empty pin)
(.. status-keycard (.. status-keycard
(verifyPin pairing pin) (verifyPin pin)
(then on-success) (then on-success)
(catch on-failure)))) (catch on-failure))))
(defn change-pin (defn change-pin
[{:keys [current-pin new-pin pairing on-success on-failure]}] [{:keys [current-pin new-pin on-success on-failure]}]
(when (and pairing current-pin new-pin) (when (and current-pin new-pin)
(.. status-keycard (.. status-keycard
(changePin pairing current-pin new-pin) (changePin current-pin new-pin)
(then on-success) (then on-success)
(catch on-failure)))) (catch on-failure))))
(defn unpair (defn unpair
[{:keys [pin pairing on-success on-failure]}] [{:keys [pin on-success on-failure]}]
(when (and pairing pin) (when (and pin)
(.. status-keycard (.. status-keycard
(unpair pairing pin) (unpair pin)
(then on-success) (then on-success)
(catch on-failure)))) (catch on-failure))))
@ -183,61 +185,61 @@
(catch on-failure))) (catch on-failure)))
(defn remove-key (defn remove-key
[{:keys [pin pairing on-success on-failure]}] [{:keys [pin on-success on-failure]}]
(.. status-keycard (.. status-keycard
(removeKey pairing pin) (removeKey pin)
(then on-success) (then on-success)
(catch on-failure))) (catch on-failure)))
(defn remove-key-with-unpair (defn remove-key-with-unpair
[{:keys [pin pairing on-success on-failure]}] [{:keys [pin on-success on-failure]}]
(.. status-keycard (.. status-keycard
(removeKeyWithUnpair pairing pin) (removeKeyWithUnpair pin)
(then on-success) (then on-success)
(catch on-failure))) (catch on-failure)))
(defn export-key (defn export-key
[{:keys [pin pairing path on-success on-failure]}] [{:keys [pin path on-success on-failure]}]
(.. status-keycard (.. status-keycard
(exportKeyWithPath pairing pin path) (exportKeyWithPath pin path)
(then on-success) (then on-success)
(catch on-failure))) (catch on-failure)))
(defn unpair-and-delete (defn unpair-and-delete
[{:keys [pin pairing on-success on-failure]}] [{:keys [pin on-success on-failure]}]
(when (and pairing pin) (when (not-empty pin)
(.. status-keycard (.. status-keycard
(unpairAndDelete pairing pin) (unpairAndDelete pin)
(then on-success) (then on-success)
(catch on-failure)))) (catch on-failure))))
(defn import-keys (defn import-keys
[{:keys [pairing pin on-success on-failure]}] [{:keys [pin on-success on-failure]}]
(when (and pairing (not-empty pin)) (when (not-empty pin)
(.. status-keycard (.. status-keycard
(importKeys pairing pin) (importKeys pin)
(then on-success) (then on-success)
(catch on-failure)))) (catch on-failure))))
(defn get-keys (defn get-keys
[{:keys [pairing pin on-success on-failure]}] [{:keys [pin on-success on-failure]}]
(when (and pairing (not-empty pin)) (when (not-empty pin)
(.. status-keycard (.. status-keycard
(getKeys pairing pin) (getKeys pin)
(then on-success) (then on-success)
(catch on-failure)))) (catch on-failure))))
(defn sign (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) (log/debug "keycard sign" "path" path)
(when (and pairing pin hash) (when (and pin hash)
(if path (if path
(.. status-keycard (.. status-keycard
(signWithPath pairing pin path hash) (signWithPath pin path hash)
(then on-success) (then on-success)
(catch on-failure)) (catch on-failure))
(.. status-keycard (.. status-keycard
(sign pairing pin hash) (sign pin hash)
(then on-success) (then on-success)
(catch on-failure))))) (catch on-failure)))))
@ -291,6 +293,8 @@
(remove-event-listener event)) (remove-event-listener event))
(keycard/remove-event-listeners [this] (keycard/remove-event-listeners [this]
(remove-event-listeners)) (remove-event-listeners))
(keycard/set-pairings [this args]
(set-pairings args))
(keycard/get-application-info [this args] (keycard/get-application-info [this args]
(get-application-info args)) (get-application-info args))
(keycard/install-applet [this args] (keycard/install-applet [this args]

View File

@ -115,7 +115,7 @@
{:on-card-connected :keycard/get-application-info {:on-card-connected :keycard/get-application-info
:on-card-read :keycard/check-card-state :on-card-read :keycard/check-card-state
:sheet-options {:on-cancel [::cancel-pressed]} :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 (fx/defn recovery-success-finish-pressed
{:events [:keycard.recovery.success/finish-pressed]} {:events [:keycard.recovery.success/finish-pressed]}
@ -253,8 +253,7 @@
(assoc-in [:keycard :pin :status] :verifying) (assoc-in [:keycard :pin :status] :verifying)
(assoc-in [:keycard :secrets] {:pairing pairing' (assoc-in [:keycard :secrets] {:pairing pairing'
:paired-on (utils.datetime/timestamp)})) :paired-on (utils.datetime/timestamp)}))
:keycard/import-keys {:pairing pairing' :keycard/import-keys {:pin pin
:pin pin
:on-success :keycard.callback/on-generate-and-load-key-success}}))) :on-success :keycard.callback/on-generate-and-load-key-success}})))
(fx/defn load-recovering-key-screen (fx/defn load-recovering-key-screen

View File

@ -13,10 +13,9 @@
{:events [:keycard/sign]} {:events [:keycard/sign]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [card-connected? (get-in db [:keycard :card-connected?]) (let [card-connected? (get-in db [:keycard :card-connected?])
pairing (common/get-pairing db) key-uid (get-in db [:multiaccount :key-uid])
keycard-instance-uid (get-in db [:multiaccount :keycard-instance-uid]) keycard-key-uid (get-in db [:keycard :application-info :key-uid])
instance-uid (get-in db [:keycard :application-info :instance-uid]) keycard-match? (= key-uid keycard-key-uid)
keycard-match? (= keycard-instance-uid instance-uid)
hash (get-in db [:keycard :hash]) hash (get-in db [:keycard :hash])
data (get-in db [:keycard :data]) data (get-in db [:keycard :data])
typed? (get-in db [:keycard :typed?]) typed? (get-in db [:keycard :typed?])
@ -35,7 +34,6 @@
(assoc-in [:keycard :pin :status] :verifying)) (assoc-in [:keycard :pin :status] :verifying))
:keycard/sign {:hash (ethereum/naked-address hash) :keycard/sign {:hash (ethereum/naked-address hash)
:data data :data data
:pairing pairing
:typed? typed? :typed? typed?
:pin pin :pin pin
:path path}} :path path}}
@ -59,10 +57,9 @@
(normalize-signature %)]) (normalize-signature %)])
hash (ethereum/naked-address result) hash (ethereum/naked-address result)
card-connected? (get-in db [:keycard :card-connected?]) card-connected? (get-in db [:keycard :card-connected?])
pairing (common/get-pairing db) key-uid (get-in db [:multiaccount :key-uid])
multiaccount-keycard-instance-uid (get-in db [:multiaccount :keycard-instance-uid]) keycard-key-uid (get-in db [:keycard :application-info :key-uid])
instance-uid (get-in db [:keycard :application-info :instance-uid]) keycard-match? (= key-uid keycard-key-uid)
keycard-match? (= multiaccount-keycard-instance-uid instance-uid)
pin (common/vector->string (get-in db [:keycard :pin :sign]))] pin (common/vector->string (get-in db [:keycard :pin :sign]))]
(if (and card-connected? (if (and card-connected?
keycard-match?) keycard-match?)
@ -71,7 +68,6 @@
(assoc-in [:keycard :pin :status] :verifying)) (assoc-in [:keycard :pin :status] :verifying))
:keycard/sign {:hash (ethereum/naked-address hash) :keycard/sign {:hash (ethereum/naked-address hash)
:data (:data params) :data (:data params)
:pairing pairing
:pin pin :pin pin
:on-success on-success}} :on-success on-success}}
(fx/merge cofx (fx/merge cofx
@ -94,7 +90,7 @@
(assoc-in [:keycard :pin :sign] []) (assoc-in [:keycard :pin :sign] [])
(assoc-in [:keycard :pin :status] nil))} (assoc-in [:keycard :pin :status] nil))}
(common/clear-on-card-connected) (common/clear-on-card-connected)
(common/get-application-info (common/get-pairing db) nil) (common/get-application-info nil)
(common/hide-connection-sheet))) (common/hide-connection-sheet)))
(fx/defn sign-typed-data (fx/defn sign-typed-data
@ -149,11 +145,10 @@
(fx/defn prepare-to-sign (fx/defn prepare-to-sign
{:events [:keycard/prepare-to-sign]} {:events [:keycard/prepare-to-sign]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [pairing (common/get-pairing db)]
(common/show-connection-sheet (common/show-connection-sheet
cofx cofx
{:on-card-connected :keycard/prepare-to-sign {:on-card-connected :keycard/prepare-to-sign
:handler (common/get-application-info pairing :keycard/sign)}))) :handler (common/get-application-info :keycard/sign)}))
(fx/defn sign-message-completed (fx/defn sign-message-completed
[_ signature] [_ signature]
@ -184,7 +179,7 @@
(assoc-in [:keycard :pin :sign] []) (assoc-in [:keycard :pin :sign] [])
(assoc-in [:keycard :pin :status] nil))} (assoc-in [:keycard :pin :status] nil))}
(common/clear-on-card-connected) (common/clear-on-card-connected)
(common/get-application-info (common/get-pairing db) nil) (common/get-application-info nil)
(common/hide-connection-sheet)))) (common/hide-connection-sheet))))
(if transaction (if transaction
(send-transaction-with-signature (send-transaction-with-signature

View File

@ -47,7 +47,7 @@
:app-version "2.2" :app-version "2.2"
:secure-channel-pub-key "04c3071768912a515c00aeab7ceb8a5bfda91d036f4a4e60b7944cee3ca7fb67b6d118e8df1e2480b87fd636c6615253245bbbc93a6a407f155f2c58f76c96ef0e", :secure-channel-pub-key "04c3071768912a515c00aeab7ceb8a5bfda91d036f4a4e60b7944cee3ca7fb67b6d118e8df1e2480b87fd636c6615253245bbbc93a6a407f155f2c58f76c96ef0e",
:instance-uid "1b360b10a9a68b7d494e8f059059f118" :instance-uid "1b360b10a9a68b7d494e8f059059f118"
:paired? true :paired? false
:has-master-key? true :has-master-key? true
:initialized? true :initialized? true
:pin-retry-counter 3 :pin-retry-counter 3
@ -102,6 +102,9 @@
(on-card-connected (:on-card-connected args)) (on-card-connected (:on-card-connected args))
(on-card-disconnected (:on-card-disconnected args))) (on-card-disconnected (:on-card-disconnected args)))
(defn set-pairings [args]
(log/warn "set-pairings not implemented" args))
(defn remove-event-listener [id] (defn remove-event-listener [id]
(log/debug "remove-event-listener") (log/debug "remove-event-listener")
(swap! state update :on-card-connected dissoc id) (swap! state update :on-card-connected dissoc id)
@ -203,7 +206,9 @@
{:root-key root-data {:root-key root-data
:derived derived-data-extended}))))))))))) :derived derived-data-extended})))))))))))
(when (= password kk1-password) (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 (defn generate-and-load-key
[{:keys [pin on-success]}] [{:keys [pin on-success]}]
@ -212,6 +217,8 @@
pin pin
(:intro-wizard @re-frame.db/app-db))] (:intro-wizard @re-frame.db/app-db))]
(log/debug "[simulated kk] generate-and-load-key response" response) (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 (status/multiaccount-store-derived
id id
(:key-uid response) (:key-uid response)
@ -314,6 +321,8 @@
(later (later
(if @derived-acc (if @derived-acc
(let [[id keys] (multiaccount->keys pin @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 (status/multiaccount-store-derived
id id
(:key-uid keys) (:key-uid keys)
@ -428,6 +437,9 @@
(keycard/register-card-events [this args] (keycard/register-card-events [this args]
(log/debug "simulated card register-card-event") (log/debug "simulated card register-card-event")
(register-card-events args)) (register-card-events args))
(keycard/set-pairings [this args]
(log/debug "simulated card set-pairings")
(set-pairings args))
(keycard/on-card-connected [this callback] (keycard/on-card-connected [this callback]
(log/debug "simulated card on-card-connected") (log/debug "simulated card on-card-connected")
(on-card-connected callback)) (on-card-connected callback))

View File

@ -37,10 +37,8 @@
(fx/defn unpair (fx/defn unpair
{:events [:keycard/unpair]} {:events [:keycard/unpair]}
[{:keys [db]}] [{:keys [db]}]
(let [pin (common/vector->string (get-in db [:keycard :pin :current])) (let [pin (common/vector->string (get-in db [:keycard :pin :current]))]
pairing (common/get-pairing db)] {:keycard/unpair {:pin pin}}))
{:keycard/unpair {:pin pin
:pairing pairing}}))
(fx/defn unpair-and-delete (fx/defn unpair-and-delete
{:events [:keycard/unpair-and-delete]} {:events [:keycard/unpair-and-delete]}
@ -50,11 +48,9 @@
{:on-card-connected :keycard/unpair-and-delete {:on-card-connected :keycard/unpair-and-delete
:handler :handler
(fn [{:keys [db]}] (fn [{:keys [db]}]
(let [pin (common/vector->string (get-in db [:keycard :pin :current])) (let [pin (common/vector->string (get-in db [:keycard :pin :current]))]
pairing (common/get-pairing db)]
{:keycard/unpair-and-delete {:keycard/unpair-and-delete
{:pin pin {:pin pin}}))}))
:pairing pairing}}))}))
(fx/defn remove-pairing-from-multiaccount (fx/defn remove-pairing-from-multiaccount
[cofx {:keys [remove-instance-uid?]}] [cofx {:keys [remove-instance-uid?]}]
@ -108,11 +104,9 @@
{:on-card-connected :keycard/remove-key-with-unpair {:on-card-connected :keycard/remove-key-with-unpair
:handler :handler
(fn [{:keys [db]}] (fn [{:keys [db]}]
(let [pin (common/vector->string (get-in db [:keycard :pin :current])) (let [pin (common/vector->string (get-in db [:keycard :pin :current]))]
pairing (common/get-pairing db)]
{:keycard/remove-key-with-unpair {:keycard/remove-key-with-unpair
{:pin pin {:pin pin}}))}))
:pairing pairing}}))}))
(defn handle-account-removal [{:keys [db] :as cofx} keys-removed-from-card?] (defn handle-account-removal [{:keys [db] :as cofx} keys-removed-from-card?]
(let [key-uid (get-in db [:multiaccount :key-uid]) (let [key-uid (get-in db [:multiaccount :key-uid])

View File

@ -33,8 +33,7 @@
[{:keys [db]}] [{:keys [db]}]
(let [path-num (inc (get-in db [:multiaccount :latest-derived-path])) (let [path-num (inc (get-in db [:multiaccount :latest-derived-path]))
path (str constants/path-wallet-root "/" path-num) path (str constants/path-wallet-root "/" path-num)
pin (common/vector->string (get-in db [:keycard :pin :export-key])) pin (common/vector->string (get-in db [:keycard :pin :export-key]))]
pairing (common/get-pairing db)]
{:db {:db
(assoc-in (assoc-in
db [:keycard :on-export-success] db [:keycard :on-export-success]
@ -48,7 +47,7 @@
:public-key (str "0x" public-key) :public-key (str "0x" public-key)
:path path}))) :path path})))
:keycard/export-key {:pin pin :pairing pairing :path path}})) :keycard/export-key {:pin pin :path path}}))
(fx/defn verify-pin (fx/defn verify-pin
{:events [:wallet.accounts/verify-pin]} {:events [:wallet.accounts/verify-pin]}

View File

@ -438,7 +438,7 @@
(get-credentials % key-uid) (get-credentials % key-uid)
(and keycard-multiaccount? (and keycard-multiaccount?
(get-in db [:keycard :card-connected?])) (get-in db [:keycard :card-connected?]))
(keycard.common/get-application-info % nil nil)) (keycard.common/get-application-info % nil))
(open-login-callback nil)))) (open-login-callback nil))))
(fx/defn biometric-auth-done (fx/defn biometric-auth-done

View File

@ -116,7 +116,7 @@
(i18n/label :t/pair-this-card)] (i18n/label :t/pair-this-card)]
[react/view {:margin-top 27} [react/view {:margin-top 27}
[quo/button {:type :secondary [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)]]]]]) (i18n/label :t/dismiss)]]]]])
;; NOTE(Ferossgp): Seems like it should be in popover ;; NOTE(Ferossgp): Seems like it should be in popover

View File

@ -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" resolved "https://registry.yarnpkg.com/react-native-splash-screen/-/react-native-splash-screen-3.2.0.tgz#d47ec8557b1ba988ee3ea98d01463081b60fff45"
integrity sha512-Ls9qiNZzW/OLFoI25wfjjAcrf2DZ975hn2vr6U9gyuxi2nooVbzQeFoQS5vQcbCt9QX5NY8ASEEAtlLdIa6KVg== integrity sha512-Ls9qiNZzW/OLFoI25wfjjAcrf2DZ975hn2vr6U9gyuxi2nooVbzQeFoQS5vQcbCt9QX5NY8ASEEAtlLdIa6KVg==
"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":
version "2.5.32" version "2.5.33"
resolved "git+https://github.com/status-im/react-native-status-keycard.git#f602fadf800937fc1de92aa18c2e58c372eb1bed" resolved "git+https://github.com/status-im/react-native-status-keycard.git#d1098e969a1007919134e210781bdc57222bf8d3"
react-native-svg@^9.8.4: react-native-svg@^9.8.4:
version "9.13.6" version "9.13.6"