add factory reset option on new Keycard account

Signed-off-by: Michele Balistreri <michele@bitgamma.com>
This commit is contained in:
Michele Balistreri 2021-04-28 14:45:29 +03:00
parent a7660754fb
commit 0b8509949a
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
16 changed files with 98 additions and 46 deletions

View File

@ -628,7 +628,7 @@ EXTERNAL SOURCES:
CHECKOUT OPTIONS:
Keycard:
:commit: 75c956d64a7d9fdf63e1aac9c2f36237e792c3eb
:commit: abf2be41c70846ab6f11c8bd445faf81b0befc1f
:git: https://github.com/status-im/Keycard.swift.git
secp256k1:
:commit: 46a1fa30d9b8babeae85ff519050f42394ab5fcc

View File

@ -131,6 +131,7 @@
<array>
<string>A00000080400010101</string>
<string>A00000080400010301</string>
<string>A000000151000000</string>
</array>
<key>NFCReaderUsageDescription</key>
<string>Enable Keycard</string>

View File

@ -137,6 +137,7 @@
<array>
<string>A00000080400010101</string>
<string>A00000080400010301</string>
<string>A000000151000000</string>
</array>
<key>NFCReaderUsageDescription</key>
<string>Enable Keycard</string>

View File

@ -24,6 +24,7 @@
<array>
<string>A00000080400010101</string>
<string>A00000080400010301</string>
<string>A000000151000000</string>
</array>
<key>NFCReaderUsageDescription</key>
<string>Enable Keycard</string>

View File

@ -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.34",
"react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#v2.5.35",
"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",

View File

@ -99,6 +99,25 @@
[:keycard.callback/on-get-application-info-error
(error-object->map response)]))})))
(defn factory-reset [{:keys [on-success] :as args}]
(log/debug "[keycard] factory-reset")
(keycard/factory-reset
card
(merge
args
{:on-success
(fn [response]
(log/debug "[keycard response succ] get-application-info")
(re-frame/dispatch
[:keycard.callback/on-get-application-info-success
response on-success]))
:on-failure
(fn [response]
(log/debug "[keycard response fail] get-application-info")
(re-frame/dispatch
[:keycard.callback/on-get-application-info-error
(error-object->map response)]))})))
(defn install-applet []
(log/debug "[keycard] install-applet")
(keycard/install-applet

View File

@ -409,6 +409,13 @@
(navigation/navigate-to-cofx :keycard-recovery-pin nil)))
(show-wrong-keycard-alert true)))))
(fx/defn factory-reset
{:events [:keycard/factory-reset]}
[{:keys [db]} on-card-read]
(log/debug "[keycard] factory-reset")
{:db (update db :keycard dissoc :factory-reset-card?)
:keycard/factory-reset {:on-success on-card-read}})
;; Get application info
(fx/defn get-application-info

View File

@ -59,6 +59,10 @@
:keycard/get-application-info
card/get-application-info)
(re-frame/reg-fx
:keycard/factory-reset
card/factory-reset)
(re-frame/reg-fx
:keycard/check-nfc-support
card/check-nfc-support)

View File

@ -1,34 +0,0 @@
(ns status-im.keycard.ios-keycard
(:require [status-im.keycard.keycard :as keycard]))
(defrecord IOSKeycard []
keycard/Keycard
(check-nfc-support [this args])
(check-nfc-enabled [this args])
(open-nfc-settings [this])
(register-card-events [this args])
(on-card-disconnected [this callback])
(on-card-connected [this callback])
(remove-event-listener [this event])
(remove-event-listeners [this])
(get-application-info [this args])
(install-applet [this args])
(init-card [this args])
(install-applet-and-init-card [this args])
(pair [this args])
(generate-and-load-key [this args])
(unblock-pin [this args])
(verify-pin [this args])
(change-pin [this args])
(unpair [this args])
(delete [this args])
(remove-key [this args])
(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])
(login [this args])
(send-transaction-with-signature [this args]))

View File

@ -14,6 +14,7 @@
(remove-event-listener [this event])
(remove-event-listeners [this])
(get-application-info [this args])
(factory-reset [this args])
(install-applet [this args])
(install-cash-applet [this args])
(init-card [this args])

View File

@ -4,6 +4,7 @@
[status-im.i18n.i18n :as i18n]
[status-im.navigation :as navigation]
[status-im.utils.fx :as fx]
[status-im.utils.utils :as utils]
[status-im.keycard.common :as common]
[status-im.keycard.mnemonic :as mnemonic]
[taoensso.timbre :as log]
@ -274,6 +275,11 @@
{:mnemonic mnemonic
:pin pin'}})))
(fx/defn factory-reset-card-toggle
{:events [:keycard.onboarding.intro.ui/factory-reset-card-toggle]}
[{:keys [db] :as cofx} checked?]
{:db (assoc-in db [:keycard :factory-reset-card?] checked?)})
(fx/defn begin-setup-pressed
{:events [:keycard.onboarding.intro.ui/begin-setup-pressed]}
[{:keys [db] :as cofx}]
@ -282,14 +288,34 @@
{:db (-> db
(update :keycard
dissoc :secrets :card-state :multiaccount-wallet-address
:multiaccount-whisper-public-key
:application-info)
:multiaccount-whisper-public-key :application-info)
(assoc-in [:keycard :setup-step] :begin)
(assoc-in [:keycard :pin :on-verified] nil))}
(common/show-connection-sheet
{:on-card-connected :keycard/get-application-info
:on-card-read :keycard/check-card-state
:handler (common/get-application-info :keycard/check-card-state)})))
(if (get-in db [:keycard :factory-reset-card?])
(utils/show-confirmation {:title (i18n/label :t/keycard-factory-reset-title)
:content (i18n/label :t/keycard-factory-reset-text)
:confirm-button-text (i18n/label :t/yes)
:cancel-button-text (i18n/label :t/no)
:on-accept #(re-frame/dispatch [::factory-reset])
:on-cancel #(re-frame/dispatch [::factory-reset-cancel])})
(common/show-connection-sheet
{:on-card-connected :keycard/get-application-info
:on-card-read :keycard/check-card-state
:handler (common/get-application-info :keycard/check-card-state)}))))
(fx/defn factory-reset
{:events [::factory-reset]}
[cofx]
(common/show-connection-sheet
cofx
{:on-card-connected :keycard/factory-reset
:on-card-read :keycard/check-card-state
:handler (common/factory-reset :keycard/check-card-state)}))
(fx/defn factory-reset-cancel
{:events [::factory-reset-cancel]}
[{:keys [db] :as cofx}]
{:db (update db :keycard dissoc :factory-reset-card?)})
(fx/defn cancel-confirm
{:events [::cancel-confirm]}

View File

@ -107,6 +107,17 @@
(on-success info))))
(catch on-failure)))
(defn factory-reset
[{:keys [on-success on-failure]}]
(.. status-keycard
(factoryReset)
(then (fn [response]
(let [info (-> response
(js->clj :keywordize-keys true)
(update :key-uid ethereum/normalized-hex))]
(on-success info))))
(catch on-failure)))
(defn install-applet [{:keys [on-success on-failure]}]
(.. status-keycard
installApplet
@ -313,6 +324,8 @@
(set-pairings args))
(keycard/get-application-info [this args]
(get-application-info args))
(keycard/factory-reset [this args]
(factory-reset args))
(keycard/install-applet [this args]
(install-applet args))
(keycard/install-cash-applet [this args]

View File

@ -119,6 +119,7 @@
(log/debug "get-application-info")
(later #(on-success (get @state :application-info))))
(defn factory-reset [_])
(defn install-applet [_])
(defn install-cash-applet [_])
@ -459,6 +460,9 @@
(keycard/get-application-info [this args]
(log/debug "simulated card get-application-info")
(get-application-info args))
(keycard/factory-reset [this args]
(log/debug "simulated card factory-reset")
(get-application-info args))
(keycard/install-applet [this args]
(log/debug "simulated card install-applet")
(install-applet args))

View File

@ -11,13 +11,14 @@
[status-im.ui.components.topbar :as topbar]
[status-im.ui.screens.keycard.pin.views :as pin.views]
[status-im.ui.screens.keycard.styles :as styles]
[status-im.ui.components.checkbox.view :as checkbox]
[quo.core :as quo]
[status-im.constants :as constants])
(:require-macros [status-im.utils.views :refer [defview letsubs]]))
(defview intro []
(letsubs [flow [:keycard-flow]
{:keys [from-key-storage-and-migration?]} [:keycard]]
{:keys [from-key-storage-and-migration? factory-reset-card?]} [:keycard]]
[react/view styles/container
(when-not from-key-storage-and-migration?
[topbar/topbar])
@ -86,6 +87,11 @@
[react/text {:style {:color colors/gray
:padding-right 35}}
text]]]]))]
[react/view {:style {:flex-direction :row}}
[checkbox/checkbox {:checked? factory-reset-card?
:style {:margin-right 10}
:on-value-change #(re-frame/dispatch [:keycard.onboarding.intro.ui/factory-reset-card-toggle %])}]
[react/text (i18n/label :t/keycard-factory-reset)]]
[react/view {:margin-bottom 40}
[quo/button {:on-press #(re-frame/dispatch [:keycard.onboarding.intro.ui/begin-setup-pressed])}
(i18n/label :t/begin-set-up)]]]]))

View File

@ -714,6 +714,9 @@
"keycard-desc": "Own a Keycard? Store your keys on it; youll need it for transactions",
"keycard-dont-ask-card": "Don't ask for card to sign in",
"keycard-reset-passcode": "Reset passcode",
"keycard-factory-reset": "Return card to factory settings",
"keycard-factory-reset-title": "Are you sure you want to perform a factory reset?",
"keycard-factory-reset-text": "Performing this will delete any mnemonic phrase stored on the card. Make sure you have a backup of the mnemonic phrase you've been using with this Keycard.",
"keycard-enter-new-passcode": "Enter new passcode {{step}}/2",
"keycard-has-multiaccount-on-it": "This card is full. Each card can hold one main keypair",
"keycard-onboarding-finishing-header": "Finishing up",

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"
integrity sha512-Ls9qiNZzW/OLFoI25wfjjAcrf2DZ975hn2vr6U9gyuxi2nooVbzQeFoQS5vQcbCt9QX5NY8ASEEAtlLdIa6KVg==
"react-native-status-keycard@git+https://github.com/status-im/react-native-status-keycard.git#v2.5.34":
version "2.5.34"
resolved "git+https://github.com/status-im/react-native-status-keycard.git#b9f242aa11afbb6a79c269459c48e32a6091176c"
"react-native-status-keycard@git+https://github.com/status-im/react-native-status-keycard.git#v2.5.35":
version "2.5.35"
resolved "git+https://github.com/status-im/react-native-status-keycard.git#8cf7cbff803b080b2069202ea6179703b8c69d2e"
react-native-svg@^9.8.4:
version "9.13.6"