[#10243] Handle wrong pin on keycard account creation
This commit is contained in:
parent
f1e83158d9
commit
45b296a2c5
|
@ -464,3 +464,23 @@
|
||||||
|
|
||||||
(defn keycard-multiaccount? [db]
|
(defn keycard-multiaccount? [db]
|
||||||
(boolean (get-in db [:multiaccount :keycard-pairing])))
|
(boolean (get-in db [:multiaccount :keycard-pairing])))
|
||||||
|
|
||||||
|
(fx/defn verify-pin
|
||||||
|
{:events [:hardwallet/verify-pin]}
|
||||||
|
[{:keys [db] :as cofx} {:keys [pin-step on-card-connected on-failure on-success]}]
|
||||||
|
(fx/merge
|
||||||
|
cofx
|
||||||
|
{:db (update-in db [:hardwallet :pin] assoc
|
||||||
|
:on-verified on-success
|
||||||
|
:on-verified-failure on-failure)}
|
||||||
|
(show-connection-sheet
|
||||||
|
{:on-card-connected (or on-card-connected :hardwallet/verify-pin)
|
||||||
|
:handler
|
||||||
|
(fn [{:keys [db] :as cofx}]
|
||||||
|
(let [pin (vector->string (get-in db [:hardwallet :pin pin-step]))
|
||||||
|
pairing (get-pairing db)]
|
||||||
|
(fx/merge
|
||||||
|
cofx
|
||||||
|
{:db (assoc-in db [:hardwallet :pin :status] :verifying)
|
||||||
|
:hardwallet/verify-pin {:pin pin
|
||||||
|
:pairing pairing}})))})))
|
||||||
|
|
|
@ -156,10 +156,10 @@
|
||||||
:puk []})}
|
:puk []})}
|
||||||
(common/hide-connection-sheet)))))
|
(common/hide-connection-sheet)))))
|
||||||
|
|
||||||
(fx/defn dispatch-on-verified-event
|
(fx/defn clear-on-verify-handlers
|
||||||
[{:keys [db]} event]
|
[{:keys [db]}]
|
||||||
{:dispatch [event]
|
{:db (update-in db [:hardwallet :pin]
|
||||||
:db (assoc-in db [:hardwallet :pin :on-verified] nil)})
|
dissoc :on-verified-failure :on-verified)})
|
||||||
|
|
||||||
(fx/defn on-verify-pin-success
|
(fx/defn on-verify-pin-success
|
||||||
{:events [:hardwallet.callback/on-verify-pin-success]}
|
{:events [:hardwallet.callback/on-verify-pin-success]}
|
||||||
|
@ -181,55 +181,51 @@
|
||||||
:hardwallet/generate-and-load-key
|
:hardwallet/generate-and-load-key
|
||||||
:hardwallet/remove-key-with-unpair
|
:hardwallet/remove-key-with-unpair
|
||||||
:hardwallet/unpair-and-delete
|
:hardwallet/unpair-and-delete
|
||||||
:hardwallet/generate-mnemonic} on-verified)
|
:hardwallet/generate-mnemonic
|
||||||
|
:wallet.accounts/generate-new-keycard-account} on-verified)
|
||||||
(common/get-application-info pairing nil))
|
(common/get-application-info pairing nil))
|
||||||
(when on-verified
|
(when on-verified
|
||||||
(dispatch-on-verified-event on-verified)))))
|
(common/dispatch-event on-verified))
|
||||||
|
(clear-on-verify-handlers))))
|
||||||
|
|
||||||
(fx/defn on-verify-pin-error
|
(fx/defn on-verify-pin-error
|
||||||
{:events [:hardwallet.callback/on-verify-pin-error]}
|
{:events [:hardwallet.callback/on-verify-pin-error]}
|
||||||
[{:keys [db] :as cofx} error]
|
[{:keys [db] :as cofx} error]
|
||||||
(let [tag-was-lost? (common/tag-lost? (:error error))
|
(let [tag-was-lost? (common/tag-lost? (:error error))
|
||||||
setup? (boolean (get-in db [:hardwallet :setup-step]))
|
setup? (boolean (get-in db [:hardwallet :setup-step]))
|
||||||
exporting? (get-in db [:hardwallet :on-export-success])]
|
on-verified-failure (get-in db [:hardwallet :pin :on-verified-failure])
|
||||||
|
exporting? (get-in db [:hardwallet :on-export-success])]
|
||||||
(log/debug "[hardwallet] verify pin error" error)
|
(log/debug "[hardwallet] verify pin error" error)
|
||||||
(when-not tag-was-lost?
|
(when-not tag-was-lost?
|
||||||
(if (re-matches common/pin-mismatch-error (:error error))
|
(if (re-matches common/pin-mismatch-error (:error error))
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
{:db (update-in db [:hardwallet :pin] merge {:status :error
|
{:db (update-in db [:hardwallet :pin]
|
||||||
:enter-step :current
|
merge
|
||||||
:puk []
|
{:status :error
|
||||||
:current []
|
:enter-step :current
|
||||||
:original []
|
:puk []
|
||||||
:confirmation []
|
:current []
|
||||||
:sign []
|
:original []
|
||||||
:error-label :t/pin-mismatch})}
|
:confirmation []
|
||||||
|
:sign []
|
||||||
|
:error-label :t/pin-mismatch})}
|
||||||
(common/hide-connection-sheet)
|
(common/hide-connection-sheet)
|
||||||
(when-not setup?
|
(when (and (not setup?)
|
||||||
|
(not on-verified-failure))
|
||||||
(if exporting?
|
(if exporting?
|
||||||
(navigation/navigate-back)
|
(navigation/navigate-back)
|
||||||
(navigation/navigate-to-cofx :enter-pin-settings nil)))
|
(navigation/navigate-to-cofx :enter-pin-settings nil)))
|
||||||
(common/get-application-info (common/get-pairing db) nil))
|
(common/get-application-info (common/get-pairing db) nil)
|
||||||
|
(when on-verified-failure
|
||||||
|
(fn [_] {:utils/dispatch-later
|
||||||
|
[{:dispatch [on-verified-failure]
|
||||||
|
:ms 200}]}))
|
||||||
|
(clear-on-verify-handlers))
|
||||||
|
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
(common/hide-connection-sheet)
|
(common/hide-connection-sheet)
|
||||||
(common/show-wrong-keycard-alert true))))))
|
(common/show-wrong-keycard-alert true)
|
||||||
|
(clear-on-verify-handlers))))))
|
||||||
(fx/defn verify-pin
|
|
||||||
{:events [:hardwallet/verify-pin]}
|
|
||||||
[cofx]
|
|
||||||
(common/show-connection-sheet
|
|
||||||
cofx
|
|
||||||
{:on-card-connected :hardwallet/verify-pin
|
|
||||||
:handler
|
|
||||||
(fn [{:keys [db] :as cofx}]
|
|
||||||
(let [pin (common/vector->string (get-in db [:hardwallet :pin :current]))
|
|
||||||
pairing (common/get-pairing db)]
|
|
||||||
(fx/merge
|
|
||||||
cofx
|
|
||||||
{:db (assoc-in db [:hardwallet :pin :status] :verifying)
|
|
||||||
:hardwallet/verify-pin {:pin pin
|
|
||||||
:pairing pairing}})))}))
|
|
||||||
|
|
||||||
(fx/defn unblock-pin
|
(fx/defn unblock-pin
|
||||||
{:events [:hardwallet/unblock-pin]}
|
{:events [:hardwallet/unblock-pin]}
|
||||||
|
@ -313,7 +309,7 @@
|
||||||
|
|
||||||
(and (= enter-step :current)
|
(and (= enter-step :current)
|
||||||
(= pin-code-length numbers-entered))
|
(= pin-code-length numbers-entered))
|
||||||
(verify-pin)
|
(common/verify-pin :current)
|
||||||
|
|
||||||
(and (= enter-step :export-key)
|
(and (= enter-step :export-key)
|
||||||
(= pin-code-length numbers-entered))
|
(= pin-code-length numbers-entered))
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
(ns status-im.hardwallet.wallet
|
(ns status-im.hardwallet.wallet
|
||||||
(:require [status-im.ethereum.core :as ethereum]
|
(:require [status-im.ethereum.core :as ethereum]
|
||||||
[status-im.utils.fx :as fx]
|
[status-im.utils.fx :as fx]
|
||||||
|
[status-im.ui.screens.wallet.add-new.views :as add-new.views]
|
||||||
[status-im.hardwallet.common :as common]
|
[status-im.hardwallet.common :as common]
|
||||||
[status-im.constants :as constants]
|
[status-im.constants :as constants]
|
||||||
[status-im.ethereum.eip55 :as eip55]
|
[status-im.ethereum.eip55 :as eip55]
|
||||||
|
@ -8,42 +9,51 @@
|
||||||
|
|
||||||
(fx/defn show-pin-sheet
|
(fx/defn show-pin-sheet
|
||||||
{:events [:hardwallet/new-account-pin-sheet]}
|
{:events [:hardwallet/new-account-pin-sheet]}
|
||||||
[{:keys [db] :as cofx} sheet-options]
|
[{:keys [db] :as cofx}]
|
||||||
(fx/merge
|
(fx/merge
|
||||||
cofx
|
cofx
|
||||||
{:db (assoc-in db [:hardwallet :pin :enter-step] :export-key)}
|
{:db (-> db
|
||||||
(bottom-sheet/show-bottom-sheet sheet-options)))
|
(assoc-in [:hardwallet :pin :enter-step] :export-key)
|
||||||
|
(update-in [:hardwallet :pin] dissoc :export-key))}
|
||||||
|
(bottom-sheet/show-bottom-sheet
|
||||||
|
{:view {:content add-new.views/pin
|
||||||
|
:height 256}})))
|
||||||
|
|
||||||
(fx/defn hide-pin-sheet
|
(fx/defn hide-pin-sheet
|
||||||
{:events [:hardwallet/hide-new-account-pin-sheet]}
|
{:events [:hardwallet/hide-new-account-pin-sheet]}
|
||||||
[{:keys [db] :as cofx}]
|
[cofx]
|
||||||
(fx/merge
|
(fx/merge
|
||||||
cofx
|
cofx
|
||||||
{:utils/dispatch-later
|
{: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
|
[{:ms 200
|
||||||
:dispatch [:wallet.accounts/generate-new-keycard-account]}]}
|
:dispatch [:wallet.accounts/verify-pin]}]}
|
||||||
(bottom-sheet/hide-bottom-sheet)))
|
(bottom-sheet/hide-bottom-sheet)))
|
||||||
|
|
||||||
(fx/defn generate-new-keycard-account
|
(fx/defn generate-new-keycard-account
|
||||||
{:events [:wallet.accounts/generate-new-keycard-account]}
|
{:events [:wallet.accounts/generate-new-keycard-account]}
|
||||||
[cofx]
|
[{:keys [db]}]
|
||||||
(common/show-connection-sheet
|
(let [path-num (inc (get-in db [:multiaccount :latest-derived-path]))
|
||||||
cofx
|
path (str constants/path-wallet-root "/" path-num)
|
||||||
{:on-card-connected :wallet.accounts/generate-new-keycard-account
|
pin (common/vector->string (get-in db [:hardwallet :pin :export-key]))
|
||||||
:handler
|
pairing (common/get-pairing db)]
|
||||||
(fn [{:keys [db]}]
|
{:db
|
||||||
(let [path-num (inc (get-in db [:multiaccount :latest-derived-path]))
|
(assoc-in
|
||||||
path (str constants/path-wallet-root "/" path-num)
|
db [:hardwallet :on-export-success]
|
||||||
pin (common/vector->string (get-in db [:hardwallet :pin :export-key]))
|
#(vector :wallet.accounts/account-stored
|
||||||
pairing (common/get-pairing db)]
|
{;; Strip leading 04 prefix denoting uncompressed key format
|
||||||
{:db
|
:address (eip55/address->checksum (str "0x" (ethereum/public-key->address (subs % 2))))
|
||||||
(assoc-in
|
:public-key (str "0x" %)
|
||||||
db [:hardwallet :on-export-success]
|
:path path}))
|
||||||
#(vector :wallet.accounts/account-stored
|
|
||||||
{;; Strip leading 04 prefix denoting uncompressed key format
|
|
||||||
:address (eip55/address->checksum (str "0x" (ethereum/public-key->address (subs % 2))))
|
|
||||||
:public-key (str "0x" %)
|
|
||||||
:path path}))
|
|
||||||
|
|
||||||
:hardwallet/export-key {:pin pin :pairing pairing :path path}}))}))
|
:hardwallet/export-key {:pin pin :pairing pairing :path path}}))
|
||||||
|
|
||||||
|
(fx/defn verify-pin
|
||||||
|
{:events [:wallet.accounts/verify-pin]}
|
||||||
|
[cofx]
|
||||||
|
(common/verify-pin
|
||||||
|
cofx
|
||||||
|
{:pin-step :export-key
|
||||||
|
:on-card-connected :wallet.accounts/generate-new-keycard-account
|
||||||
|
:on-success :wallet.accounts/generate-new-keycard-account
|
||||||
|
:on-failure :hardwallet/new-account-pin-sheet}))
|
||||||
|
|
|
@ -17,8 +17,7 @@
|
||||||
[status-im.ethereum.core :as ethereum]
|
[status-im.ethereum.core :as ethereum]
|
||||||
[status-im.utils.security :as security]
|
[status-im.utils.security :as security]
|
||||||
[clojure.string :as string]
|
[clojure.string :as string]
|
||||||
[status-im.utils.platform :as platform]
|
[status-im.utils.platform :as platform]))
|
||||||
[taoensso.timbre :as log]))
|
|
||||||
|
|
||||||
(defn- request-camera-permissions []
|
(defn- request-camera-permissions []
|
||||||
(let [options {:handler :wallet.add-new/qr-scanner-result}]
|
(let [options {:handler :wallet.add-new/qr-scanner-result}]
|
||||||
|
|
Loading…
Reference in New Issue