[#13992] Delete account only after moving keys to keyacard

This commit is contained in:
Roman Volosovskyi 2022-09-30 11:20:24 +02:00
parent faaf6d5f94
commit 7f1e83672e
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
8 changed files with 97 additions and 46 deletions

View File

@ -505,3 +505,6 @@
(defn set-nfc-message [args]
(keycard/set-nfc-message card args))
(defn delete-multiaccount-before-migration [args]
(keycard/delete-multiaccount-before-migration card args))

View File

@ -210,3 +210,7 @@
(re-frame/reg-fx
:keycard/save-multiaccount-and-login
card/save-multiaccount-and-login)
(re-frame/reg-fx
:keycard/delete-multiaccount-before-migration
card/delete-multiaccount-before-migration)

View File

@ -38,4 +38,5 @@
(sign-typed-data [this args])
(save-multiaccount-and-login [this args])
(login [this args])
(send-transaction-with-signature [this args]))
(send-transaction-with-signature [this args])
(delete-multiaccount-before-migration [this args]))

View File

@ -269,7 +269,9 @@
(fx/merge cofx
{:keycard/generate-and-load-key
{:mnemonic mnemonic
:pin pin'}})))
:pin pin'
:key-uid (:key-uid multiaccount)
:delete-multiaccount? (get-in db [:keycard :delete-account?])}})))
(fx/defn factory-reset-card-toggle
{:events [:keycard.onboarding.intro.ui/factory-reset-card-toggle]}

View File

@ -6,6 +6,7 @@
[status-im.native-module.core :as status]
[status-im.utils.platform :as platform]
[status-im.utils.types :as types]
[clojure.string :as string]
[taoensso.timbre :as log]))
(defonce event-emitter (if platform/ios?
@ -296,6 +297,16 @@
[{:keys [transaction signature on-completed]}]
(status/send-transaction-with-signature transaction signature on-completed))
(defn delete-multiaccount-before-migration
[{:keys [key-uid on-success on-error]}]
(status/delete-multiaccount
key-uid
(fn [result]
(let [{:keys [error]} (types/json->clj result)]
(if-not (string/blank? error)
(on-error error)
(on-success))))))
(defrecord RealKeycard []
keycard/Keycard
(keycard/start-nfc [_this args]
@ -373,4 +384,6 @@
(keycard/login [_this args]
(login args))
(keycard/send-transaction-with-signature [_this args]
(send-transaction-with-signature args)))
(send-transaction-with-signature args))
(keycard/delete-multiaccount-before-migration [_ args]
(delete-multiaccount-before-migration args)))

View File

@ -15,6 +15,7 @@
[status-im.ethereum.core :as ethereum]
[status-im.bottom-sheet.core :as bottom-sheet]
[status-im.native-module.core :as status]
[status-im.popover.core :as popover]
[status-im.utils.types :as types]
[status-im.utils.security :as security]
[status-im.utils.keychain.core :as keychain]
@ -146,6 +147,9 @@
(intro-wizard)))
(fx/defn create-keycard-multiaccount
{:events [::create-keycard-multiaccount]
:interceptors [(re-frame/inject-cofx :random-guid-generator)
(re-frame/inject-cofx ::multiaccounts.create/get-signing-phrase)]}
[{:keys [db] :as cofx}]
(let [{{:keys [multiaccount secrets flow]} :keycard} db
{:keys [address
@ -271,6 +275,19 @@
(dissoc :recovered-account?))
::finish-migration [account settings password encryption-pass login-params]}))
(fx/defn delete-multiaccount
[{:keys [db]}]
(let [key-uid (get-in db [:multiaccounts/login :key-uid])]
{:keycard/delete-multiaccount-before-migration
{:key-uid key-uid
:on-error #(re-frame/dispatch [::delete-multiaccount-error %])
:on-success #(re-frame/dispatch [::create-keycard-multiaccount])}}))
(fx/defn handle-delete-multiaccount-error
{:events [::delete-multiaccount-error]}
[cofx _]
(popover/show-popover cofx {:view :transfer-multiaccount-unknown-error}))
(fx/defn on-generate-and-load-key-success
{:events [:keycard.callback/on-generate-and-load-key-success]
:interceptors [(re-frame/inject-cofx :random-guid-generator)
@ -304,6 +321,10 @@
(common/hide-connection-sheet)
(cond backup? (on-backup-success backup?)
migration? (migrate-account)
(get-in db [:keycard :delete-account?])
(delete-multiaccount)
:else (create-keycard-multiaccount)))))
(fx/defn on-generate-and-load-key-error
@ -330,7 +351,8 @@
(assoc-in [:keycard :pin :status] :verifying)
(assoc-in [:keycard :secrets] {:pairing pairing'
:paired-on (utils.datetime/timestamp)}))
:keycard/import-keys {:pin pin
:keycard/import-keys
{:pin pin
:on-success :keycard.callback/on-generate-and-load-key-success}})))
(fx/defn load-recovering-key-screen

View File

@ -247,13 +247,27 @@
(later #(on-success (str (rand-int 10000000))))))
(defn generate-and-load-key
[{:keys [pin on-success]}]
[{:keys [pin on-success key-uid delete-multiaccount?]}]
(when (= pin (get @state :pin))
(let [[id response] (multiaccount->keys
(: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))
(let [deletion-wrapper
(if delete-multiaccount?
(fn [on-deletion-success]
(js/alert "OH SHEET")
(status/delete-multiaccount
key-uid
(fn [result]
(let [{:keys [error]} (types/json->clj result)]
(if-not (string/blank? error)
(log/error error)
(on-deletion-success))))))
(fn [cb] (cb)))]
(deletion-wrapper
(fn []
(status/multiaccount-store-derived
id
(:key-uid response)
@ -262,7 +276,7 @@
constants/path-whisper
constants/path-default-wallet]
account-password
#(on-success response)))))
#(on-success response))))))))
(defn unblock-pin
[{:keys [puk new-pin on-success on-failure]}]
@ -438,6 +452,10 @@
[{:keys [transaction on-completed]}]
(status/send-transaction transaction account-password on-completed))
(defn delete-multiaccount-before-migration
[{:keys [on-success]}]
(on-success))
(defrecord SimulatedKeycard []
keycard/Keycard
(keycard/start-nfc [_this args]
@ -547,4 +565,7 @@
(login args))
(keycard/send-transaction-with-signature [_this args]
(log/debug "simulated card send-transaction-with-signature")
(send-transaction-with-signature args)))
(send-transaction-with-signature args))
(keycard/delete-multiaccount-before-migration [_ args]
(log/debug "simulated card delete-multiaccount-before-migration")
(delete-multiaccount-before-migration args)))

View File

@ -133,17 +133,6 @@
[{:keys [db]} selected?]
{:db (assoc-in db [:multiaccounts/key-storage :keycard-storage-selected?] selected?)})
(re-frame/reg-fx
::delete-multiaccount
(fn [{:keys [key-uid on-success on-error]}]
(native-module/delete-multiaccount
key-uid
(fn [result]
(let [{:keys [error]} (types/json->clj result)]
(if-not (string/blank? error)
(on-error error)
(on-success)))))))
(re-frame/reg-fx
::delete-imported-key
(fn [{:keys [key-uid address password on-success on-error]}]
@ -158,15 +147,6 @@
(on-error error)
(on-success))))))))
(fx/defn delete-multiaccount-and-init-keycard-onboarding
{:events [::delete-multiaccount-and-init-keycard-onboarding]}
[{:keys [db] :as cofx}]
(let [{:keys [key-uid]} (-> db :multiaccounts/login)]
{:db (assoc-in db [:multiaccounts/key-storage :reset-db-checked?] true)
::delete-multiaccount {:key-uid key-uid
:on-error #(re-frame/dispatch [::delete-multiaccount-error %])
:on-success #(re-frame/dispatch [::delete-multiaccount-success])}}))
#_"Multiaccount has been deleted from device. We now need to emulate the restore seed phrase process, and make the user land on Keycard setup screen.
To ensure that keycard setup works, we need to:
1. Import multiaccount, derive required keys and save them at the correct location in app-db
@ -182,13 +162,21 @@ The exact events dispatched for this flow if consumed from the UI are:
We don't need to take the exact steps, just set the required state and redirect to correct screen
"
(fx/defn import-multiaccount
{:events [::delete-multiaccount-success]}
[{:keys [db] :as cofx}]
{:dispatch [:bottom-sheet/hide]
::multiaccounts.recover/import-multiaccount {:passphrase (get-in db [:multiaccounts/key-storage :seed-phrase])
::multiaccounts.recover/import-multiaccount
{:passphrase (get-in db [:multiaccounts/key-storage :seed-phrase])
:password nil
:success-event ::import-multiaccount-success}})
(fx/defn delete-multiaccount-and-init-keycard-onboarding
{:events [::delete-multiaccount-and-init-keycard-onboarding]}
[{:keys [db] :as cofx}]
(fx/merge
{:dispatch [:bottom-sheet/hide]
:db (assoc-in db [:multiaccounts/key-storage :reset-db-checked?] true)}
(import-multiaccount)))
(fx/defn storage-selected
{:events [::storage-selected]}
[{:keys [db] :as cofx}]
@ -243,16 +231,13 @@ We don't need to take the exact steps, just set the required state and redirect
(assoc-in [:keycard :flow] :recovery)
(assoc-in [:keycard :from-key-storage-and-migration?] true)
(assoc-in [:keycard :converting-account?] (not (get-in db [:multiaccounts/key-storage :reset-db-checked?])))
(assoc-in [:keycard :delete-account?]
(true? (get-in db [:multiaccounts/key-storage :reset-db-checked?])))
(dissoc :multiaccounts/key-storage))}
(popover/hide-popover)
(common/listen-to-hardware-back-button)
(navigation/navigate-to-cofx :keycard-onboarding-intro nil)))
(fx/defn handle-delete-multiaccount-error
{:events [::delete-multiaccount-error]}
[cofx _]
(popover/show-popover cofx {:view :transfer-multiaccount-unknown-error}))
(fx/defn goto-multiaccounts-screen
{:events [::hide-popover-and-goto-multiaccounts-screen]}
[cofx _]