From 91b931c3b4592bd8d44f504a7d2c0db364d47b62 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 5 Dec 2019 08:02:31 +0200 Subject: [PATCH] Replace address with keyUid in accounts db Account's address was used as a primary key in accounts db and as a deterministic id of an account in some API calls. Also it was used as a part of the name of the account specific database. This revealed some extra information about the account and wasn't necessary. At first the hash of the address was planned to be used as a deterministic id, but we already have a keyUid which is calculated as sha256 hash of account's public key and has similar properties: - it is deterministic - doesn't reveal accounts public key or address in plain --- src/status_im/events.cljs | 6 +- src/status_im/hardwallet/core.cljs | 62 +++++++---------- src/status_im/init/core.cljs | 16 ++--- .../multiaccounts/biometric/core.cljs | 8 +-- src/status_im/multiaccounts/create/core.cljs | 21 +++--- src/status_im/multiaccounts/db.cljs | 5 +- src/status_im/multiaccounts/login/core.cljs | 52 +++++++------- src/status_im/multiaccounts/logout/core.cljs | 6 +- src/status_im/multiaccounts/model.cljs | 2 +- src/status_im/multiaccounts/recover/core.cljs | 27 +++----- src/status_im/native_module/core.cljs | 7 +- .../ui/screens/chat/toolbar_content.cljs | 2 - src/status_im/ui/screens/keycard/views.cljs | 8 +-- .../ui/screens/multiaccounts/views.cljs | 6 +- src/status_im/utils/keychain/core.cljs | 68 +++++++++---------- src/status_im/wallet/accounts/core.cljs | 2 +- status-go-version.json | 6 +- test/cljs/status_im/test/sign_in/flow.cljs | 4 +- 18 files changed, 148 insertions(+), 160 deletions(-) diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index 3c81eaeed0..e1b018dac7 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -154,13 +154,13 @@ ;; multiaccounts login module (handlers/register-handler-fx :multiaccounts.login.ui/multiaccount-selected - (fn [{:keys [db] :as cofx} [_ address]] + (fn [{:keys [db] :as cofx} [_ key-uid]] (let [{:keys [photo-path name public-key]} - (get-in db [:multiaccounts/multiaccounts address])] + (get-in db [:multiaccounts/multiaccounts key-uid])] (fx/merge cofx {:db (dissoc db :intro-wizard)} - (multiaccounts.login/open-login address photo-path name public-key))))) + (multiaccounts.login/open-login key-uid photo-path name public-key))))) ;; multiaccounts logout module diff --git a/src/status_im/hardwallet/core.cljs b/src/status_im/hardwallet/core.cljs index c70c9fecc8..39aebd9344 100644 --- a/src/status_im/hardwallet/core.cljs +++ b/src/status_im/hardwallet/core.cljs @@ -486,15 +486,6 @@ (proceed-with-generating-key))) (load-pair-screen cofx))))) -(fx/defn show-existing-multiaccount-alert - [{:keys [db] :as cofx}] - (fx/merge cofx - {:utils/show-confirmation {:title nil - :content (i18n/label :t/keycard-existing-multiaccount) - :cancel-button-text "" - :confirm-button-text :t/okay}} - (navigation/navigate-back))) - (fx/defn check-card-state {:events [:hardwallet/check-card-state]} [{:keys [db] :as cofx}] @@ -523,12 +514,11 @@ (load-pin-screen))))) (when (and (= card-state :multiaccount) (= flow :import)) - (let [{:keys [address]} (find-multiaccount-by-key-uid db key-uid)] - (if address - (recover/show-existing-multiaccount-alert address) - (if pairing - (load-recovery-pin-screen) - (load-pair-screen))))) + (if (find-multiaccount-by-key-uid db key-uid) + (recover/show-existing-multiaccount-alert key-uid) + (if pairing + (load-recovery-pin-screen) + (load-pair-screen)))) (when (= card-state :blank) (if (= flow :import) (navigation/navigate-to-cofx :keycard-recovery-no-key nil) @@ -631,13 +621,12 @@ (fx/defn get-keys-from-keycard [{:keys [db]}] - (let [multiaccount-address (get-in db [:multiaccounts/login :address]) - pairing (get-in db [:multiaccounts/multiaccounts multiaccount-address :keycard-pairing]) + (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 [:hardwallet :pin :login]))] (when (and pairing (seq pin)) - {:db (-> db - (assoc-in [:hardwallet :pin :status] :verifying)) + {:db (assoc-in db [:hardwallet :pin :status] :verifying) :hardwallet/get-keys {:pairing pairing :pin pin}}))) @@ -646,7 +635,7 @@ [{:keys [db] :as cofx}] (let [application-info (get-in db [:hardwallet :application-info]) key-uid (get-in db [:hardwallet :application-info :key-uid]) - multiaccount (get-in db [:multiaccounts/multiaccounts (get-in db [:multiaccounts/login :address])]) + 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)) @@ -947,12 +936,12 @@ (fx/defn on-remove-key-success [{:keys [db] :as cofx}] - (let [multiaccount-address (get-in db [:multiaccount :address]) + (let [key-uid (get-in db [:multiaccount :key-uid]) instance-uid (get-in db [:hardwallet :application-info :instance-uid]) pairings (get-in db [:hardwallet :pairings])] (fx/merge cofx {:db (-> db - (update :multiaccounts/multiaccounts dissoc multiaccount-address) + (update :multiaccounts/multiaccounts dissoc key-uid) (assoc-in [:hardwallet :secrets] nil) (update-in [:hardwallet :pairings] dissoc (keyword instance-uid)) (assoc-in [:hardwallet :whisper-public-key] nil) @@ -984,10 +973,10 @@ (fx/defn on-delete-success [{:keys [db] :as cofx}] - (let [multiaccount-address (get-in db [:multiaccount :address])] + (let [key-uid (get-in db [:multiaccount :key-uid])] (fx/merge cofx {:db (-> db - (update :multiaccounts/multiaccounts dissoc multiaccount-address) + (update :multiaccounts/multiaccounts dissoc key-uid) (assoc-in [:hardwallet :secrets] nil) (assoc-in [:hardwallet :application-info] nil) (assoc-in [:hardwallet :pin] {:status nil @@ -1817,11 +1806,12 @@ (fx/defn on-get-keys-success [{:keys [db] :as cofx} data] - (let [{:keys [address encryption-public-key whisper-private-key] :as account-data} (js->clj data :keywordize-keys true) - address (ethereum/normalized-hex address) - {:keys [photo-path name]} (get-in db [:multiaccounts/multiaccounts address]) + (let [{:keys [key-uid encryption-public-key whisper-private-key] :as account-data} (js->clj data :keywordize-keys true) + {:keys [photo-path name]} (get-in db [:multiaccounts/multiaccounts key-uid]) key-uid (get-in db [:hardwallet :application-info :key-uid]) - multiaccount-data (types/clj->json {:name name :address address :photo-path photo-path}) + multiaccount-data (types/clj->json {:name name + :key-uid key-uid + :photo-path photo-path}) save-keys? (get-in db [:multiaccounts/login :save-password?])] (fx/merge cofx @@ -1834,7 +1824,7 @@ (assoc-in [:hardwallet :flow] nil) (update :multiaccounts/login assoc :password encryption-public-key - :address address + :key-uid key-uid :photo-path photo-path :name name)) @@ -1843,22 +1833,22 @@ :password encryption-public-key :chat-key whisper-private-key}} (when save-keys? - (keychain/save-hardwallet-keys address encryption-public-key whisper-private-key)) + (keychain/save-hardwallet-keys key-uid encryption-public-key whisper-private-key)) (clear-on-card-connected) (clear-on-card-read)))) (fx/defn on-hardwallet-keychain-keys {:events [:multiaccounts.login.callback/get-hardwallet-keys-success]} - [{:keys [db] :as cofx} address [encryption-public-key whisper-private-key :as creds]] + [{:keys [db] :as cofx} key-uid [encryption-public-key whisper-private-key :as creds]] (if (nil? creds) (navigation/navigate-to-cofx cofx :keycard-login-pin nil) - (let [{:keys [photo-path name]} (get-in db [:multiaccounts/multiaccounts address]) + (let [{:keys [photo-path name]} (get-in db [:multiaccounts/multiaccounts key-uid]) multiaccount-data (types/clj->json {:name name - :address address + :key-uid key-uid :photo-path photo-path}) - account-data {:address address + account-data {:key-uid key-uid :encryption-public-key encryption-public-key - :whisper-private-key whisper-private-key}] + :whisper-private-key whisper-private-key}] {:db (-> db (assoc-in [:hardwallet :pin :status] nil) @@ -1868,7 +1858,7 @@ (assoc-in [:hardwallet :flow] nil) (update :multiaccounts/login assoc :password encryption-public-key - :address address + :key-uid key-uid :photo-path photo-path :name name :save-password? true)) diff --git a/src/status_im/init/core.cljs b/src/status_im/init/core.cljs index c15cfd807f..935e98bc89 100644 --- a/src/status_im/init/core.cljs +++ b/src/status_im/init/core.cljs @@ -35,18 +35,18 @@ (let [{{:multiaccounts/keys [multiaccounts] :as db} :db} cofx] (if (empty? multiaccounts) (navigation/navigate-to-cofx cofx :intro nil) - (let [{:keys [address public-key photo-path name]} (first (#(sort-by :last-sign-in > %) (vals multiaccounts)))] - (multiaccounts.login/open-login cofx address photo-path name public-key))))) + (let [{:keys [key-uid public-key photo-path name]} (first (#(sort-by :last-sign-in > %) (vals multiaccounts)))] + (multiaccounts.login/open-login cofx key-uid photo-path name public-key))))) (fx/defn initialize-multiaccounts {:events [::initialize-multiaccounts]} [{:keys [db] :as cofx} all-multiaccounts] - (let [multiaccounts (reduce (fn [acc {:keys [address key-uid keycard-pairing] :as multiaccount}] - (-> (assoc acc address multiaccount) - (assoc-in [address :key-uid] (when-not (string/blank? key-uid) - key-uid)) - (assoc-in [address :keycard-pairing] (when-not (string/blank? keycard-pairing) - keycard-pairing)))) + (let [multiaccounts (reduce (fn [acc {:keys [key-uid keycard-pairing] + :as multiaccount}] + (-> (assoc acc key-uid multiaccount) + (assoc-in [key-uid :keycard-pairing] + (when-not (string/blank? keycard-pairing) + keycard-pairing)))) {} all-multiaccounts)] (fx/merge cofx diff --git a/src/status_im/multiaccounts/biometric/core.cljs b/src/status_im/multiaccounts/biometric/core.cljs index edda3b5e5a..88083bb9a6 100644 --- a/src/status_im/multiaccounts/biometric/core.cljs +++ b/src/status_im/multiaccounts/biometric/core.cljs @@ -118,16 +118,16 @@ (authenticate-fx #(cb %) options))) (fx/defn update-biometric [{db :db :as cofx} biometric-auth?] - (let [address (or (get-in db [:multiaccount :address]) - (get-in db [:multiaccounts/login :address]))] + (let [key-uid (or (get-in db [:multiaccount :key-uid]) + (get-in db [:multiaccounts/login :key-uid]))] (fx/merge cofx (keychain/save-auth-method - address + key-uid (if biometric-auth? keychain/auth-method-biometric keychain/auth-method-none)) #(when-not biometric-auth? - {:keychain/clear-user-password address})))) + {:keychain/clear-user-password key-uid})))) (fx/defn biometric-auth-switched {:events [:multiaccounts.ui/biometric-auth-switched]} diff --git a/src/status_im/multiaccounts/create/core.cljs b/src/status_im/multiaccounts/create/core.cljs index 1c8fa9b0d3..1b69fa2181 100644 --- a/src/status_im/multiaccounts/create/core.cljs +++ b/src/status_im/multiaccounts/create/core.cljs @@ -50,9 +50,8 @@ (some #(when (= selected-id (:id %)) %) multiaccounts))) (fx/defn create-multiaccount - [{:keys [db] :as cofx}] - (let [{:keys [selected-id address key-code]} (:intro-wizard db) - {:keys [address]} (get-selected-multiaccount cofx) + [{:keys [db]}] + (let [{:keys [selected-id key-code]} (:intro-wizard db) hashed-password (ethereum/sha3 (security/safe-unmask-data key-code)) callback (fn [result] (let [derived-data (types/json->clj result) @@ -66,7 +65,7 @@ (merge derived-whisper {:name name :photo-path photo-path}))] (re-frame/dispatch [::store-multiaccount-success key-code derived-data-extended]))))))] - {::store-multiaccount [selected-id address hashed-password callback]})) + {::store-multiaccount [selected-id hashed-password callback]})) (fx/defn prepare-intro-wizard [{:keys [db] :as cofx} first-time-setup?] @@ -260,12 +259,12 @@ :keycard-pairing keycard-pairing :keycard-paired-on keycard-paired-on)) db (assoc db - :multiaccounts/login {:address address - :name name - :photo-path photo-path - :password password - :creating? true - :processing true} + :multiaccounts/login {:key-uid keyUid + :name name + :photo-path photo-path + :password password + :creating? true + :processing true} :multiaccount new-multiaccount :networks/current-network constants/default-network :networks/networks constants/default-networks)] @@ -365,7 +364,7 @@ (re-frame/reg-fx ::store-multiaccount - (fn [[id address hashed-password callback]] + (fn [[id hashed-password callback]] (status/multiaccount-store-derived id [constants/path-wallet-root diff --git a/src/status_im/multiaccounts/db.cljs b/src/status_im/multiaccounts/db.cljs index 768dd1fc5e..b24440a364 100644 --- a/src/status_im/multiaccounts/db.cljs +++ b/src/status_im/multiaccounts/db.cljs @@ -14,6 +14,7 @@ (spec/def :multiaccount/accounts (spec/nilable vector?)) (spec/def :multiaccount/address :global/address) +(spec/def :multiaccount/key-uid string?) (spec/def :multiaccount/name :global/not-empty-string) (spec/def :multiaccount/public-key :global/public-key) (spec/def :multiaccount/signed-up? (spec/nilable boolean?)) @@ -67,6 +68,6 @@ ;;used during logging (spec/def :multiaccounts/login (spec/nilable map?)) ;;before login -(spec/def :multiaccounts/multiaccount (spec/keys :req-un [:multiaccount/name :multiaccount/address] +(spec/def :multiaccounts/multiaccount (spec/keys :req-un [:multiaccount/name :multiaccount/key-uid] :opt-un [:multiaccount/timestamp])) -(spec/def :multiaccounts/multiaccounts (spec/nilable (spec/map-of :multiaccount/address :multiaccounts/multiaccount))) +(spec/def :multiaccounts/multiaccounts (spec/nilable (spec/map-of :multiaccount/key-uid :multiaccounts/multiaccount))) diff --git a/src/status_im/multiaccounts/login/core.cljs b/src/status_im/multiaccounts/login/core.cljs index bd1fbfb99f..17bbae580a 100644 --- a/src/status_im/multiaccounts/login/core.cljs +++ b/src/status_im/multiaccounts/login/core.cljs @@ -69,13 +69,15 @@ (fx/defn login {:events [:multiaccounts.login.ui/password-input-submitted]} - [{:keys [db] :as cofx}] - (let [{:keys [address password name photo-path]} (:multiaccounts/login db)] + [{:keys [db]}] + (let [{:keys [key-uid password name photo-path]} (:multiaccounts/login db)] {:db (-> db (assoc-in [:multiaccounts/login :processing] true) (dissoc :intro-wizard) (update :hardwallet dissoc :flow)) - ::login [(types/clj->json {:name name :address address :photo-path photo-path}) + ::login [(types/clj->json {:name name + :key-uid key-uid + :photo-path photo-path}) (ethereum/sha3 (security/safe-unmask-data password))]})) (fx/defn finish-keycard-setup @@ -185,7 +187,7 @@ keychain/auth-method-none))) (fx/defn login-only-events - [{:keys [db] :as cofx} address password save-password?] + [{:keys [db] :as cofx} key-uid password save-password?] (let [auth-method (:auth-method db) new-auth-method (get-new-auth-method auth-method save-password?)] (log/debug "[login] login-only-events" @@ -208,14 +210,14 @@ :params [["multiaccount" "current-network" "networks"]] :on-success #(re-frame/dispatch [::get-config-callback %])}]} (when save-password? - (keychain/save-user-password address password)) - (keychain/save-auth-method address (or new-auth-method auth-method)) + (keychain/save-user-password key-uid password)) + (keychain/save-auth-method key-uid (or new-auth-method auth-method)) (navigation/navigate-to-cofx :home nil) (when platform/desktop? (chat-model/update-dock-badge-label))))) (fx/defn create-only-events - [{:keys [db] :as cofx} address password] + [{:keys [db] :as cofx}] (let [{:keys [multiaccount :networks/networks :networks/current-network]} db] (fx/merge cofx {:db (assoc db @@ -254,7 +256,7 @@ (fx/defn multiaccount-login-success [{:keys [db] :as cofx}] - (let [{:keys [address password save-password? creating?]} (:multiaccounts/login db) + (let [{:keys [key-uid password save-password? creating?]} (:multiaccounts/login db) recovering? (get-in db [:intro-wizard :recovering?]) login-only? (not (or creating? recovering? @@ -278,8 +280,8 @@ (when nodes (fleet/set-nodes :eth.contract nodes)) (if login-only? - (login-only-events address password save-password?) - (create-only-events address password)) + (login-only-events key-uid password save-password?) + (create-only-events)) (when recovering? (navigation/navigate-to-cofx :home nil))))) @@ -296,26 +298,26 @@ (navigation/navigate-to-cofx :keycard-login-pin nil))))) (fx/defn open-login - [{:keys [db] :as cofx} address photo-path name public-key] + [{:keys [db] :as cofx} key-uid photo-path name public-key] (fx/merge cofx {:db (-> db (update :multiaccounts/login assoc :public-key public-key - :address address + :key-uid key-uid :photo-path photo-path :name name) (assoc :profile/photo-added? (= (identicon/identicon public-key) photo-path)) (update :multiaccounts/login dissoc :error :password))} - (keychain/get-auth-method address))) + (keychain/get-auth-method key-uid))) (fx/defn open-login-callback {:events [:multiaccounts.login.callback/get-user-password-success]} [{:keys [db] :as cofx} password] - (let [address (get-in db [:multiaccounts/login :address]) + (let [key-uid (get-in db [:multiaccounts/login :key-uid]) keycard-account? (boolean (get-in db [:multiaccounts/multiaccounts - address + key-uid :keycard-pairing]))] (if password (fx/merge @@ -334,20 +336,20 @@ nil))))) (fx/defn get-credentials - [{:keys [db] :as cofx} address] - (let [keycard-multiaccount? (boolean (get-in db [:multiaccounts/multiaccounts address :keycard-pairing]))] + [{:keys [db] :as cofx} key-uid] + (let [keycard-multiaccount? (boolean (get-in db [:multiaccounts/multiaccounts key-uid :keycard-pairing]))] (log/debug "[login] get-credentials" "keycard-multiacc?" keycard-multiaccount?) (if keycard-multiaccount? - (keychain/get-hardwallet-keys cofx address) - (keychain/get-user-password cofx address)))) + (keychain/get-hardwallet-keys cofx key-uid) + (keychain/get-user-password cofx key-uid)))) (fx/defn get-auth-method-success "Auth method: nil - not supported, \"none\" - not selected, \"password\", \"biometric\", \"biometric-prepare\"" {:events [:multiaccounts.login/get-auth-method-success]} [{:keys [db] :as cofx} auth-method] - (let [address (get-in db [:multiaccounts/login :address]) - keycard-multiaccount? (boolean (get-in db [:multiaccounts/multiaccounts address :keycard-pairing]))] + (let [key-uid (get-in db [:multiaccounts/login :key-uid]) + keycard-multiaccount? (boolean (get-in db [:multiaccounts/multiaccounts key-uid :keycard-pairing]))] (log/debug "[login] get-auth-method-success" "auth-method" auth-method "keycard-multiacc?" keycard-multiaccount?) @@ -357,7 +359,7 @@ keychain/auth-method-biometric (biometric/biometric-auth %) keychain/auth-method-password - (get-credentials % address) + (get-credentials % key-uid) ;;nil or "none" or "biometric-prepare" (if keycard-multiaccount? @@ -367,17 +369,17 @@ (fx/defn biometric-auth-done {:events [:biometric-auth-done]} [{:keys [db] :as cofx} {:keys [bioauth-success bioauth-message bioauth-code]}] - (let [address (get-in db [:multiaccounts/login :address])] + (let [key-uid (get-in db [:multiaccounts/login :key-uid])] (log/debug "[biometric] biometric-auth-done" "bioauth-success" bioauth-success "bioauth-message" bioauth-message "bioauth-code" bioauth-code) (if bioauth-success - (get-credentials cofx address) + (get-credentials cofx key-uid) (fx/merge cofx {:db (assoc-in db [:multiaccounts/login :save-password?] false)} (biometric/show-message bioauth-message bioauth-code) - (keychain/save-auth-method address keychain/auth-method-none) + (keychain/save-auth-method key-uid keychain/auth-method-none) (open-login-callback nil))))) (fx/defn save-password diff --git a/src/status_im/multiaccounts/logout/core.cljs b/src/status_im/multiaccounts/logout/core.cljs index e611e960d7..d56efb12eb 100644 --- a/src/status_im/multiaccounts/logout/core.cljs +++ b/src/status_im/multiaccounts/logout/core.cljs @@ -9,12 +9,12 @@ [status-im.utils.keychain.core :as keychain])) (fx/defn logout-method [{:keys [db] :as cofx} auth-method] - (let [address (get-in db [:multiaccount :address])] + (let [key-uid (get-in db [:multiaccount :key-uid])] (fx/merge cofx {::logout nil - :keychain/clear-user-password address + :keychain/clear-user-password key-uid ::init/open-multiaccounts #(re-frame/dispatch [::init/initialize-multiaccounts %])} - (keychain/save-auth-method address auth-method) + (keychain/save-auth-method key-uid auth-method) (transport/stop-whisper) (chaos-mode/stop-checking) (init/initialize-app-db)))) diff --git a/src/status_im/multiaccounts/model.cljs b/src/status_im/multiaccounts/model.cljs index 1ef1d38e0a..c91b1c01e3 100644 --- a/src/status_im/multiaccounts/model.cljs +++ b/src/status_im/multiaccounts/model.cljs @@ -5,7 +5,7 @@ (get-in cofx [:db :multiaccount]))) (defn credentials [cofx] - (select-keys (get-in cofx [:db :multiaccounts/login]) [:address :password :save-password?])) + (select-keys (get-in cofx [:db :multiaccounts/login]) [:key-uid :password :save-password?])) (defn current-public-key [cofx] diff --git a/src/status_im/multiaccounts/recover/core.cljs b/src/status_im/multiaccounts/recover/core.cljs index abf7af117f..45f71ca396 100644 --- a/src/status_im/multiaccounts/recover/core.cljs +++ b/src/status_im/multiaccounts/recover/core.cljs @@ -19,8 +19,7 @@ (defn existing-account? [root-key multiaccounts] - (contains? multiaccounts ((fnil clojure.string/lower-case "") - (:address root-key)))) + (contains? multiaccounts (:key-uid root-key))) (defn check-phrase-warnings [recovery-phrase] (cond (string/blank? recovery-phrase) :required-field @@ -49,11 +48,8 @@ :interceptors [(re-frame/inject-cofx :random-guid-generator) (re-frame/inject-cofx ::multiaccounts.create/get-signing-phrase)]} [{:keys [db] :as cofx} password] - (let [multiaccount (get-in db [:intro-wizard :root-key]) - multiaccount-address (-> (:address multiaccount) - (string/lower-case) - (string/replace-first "0x" "")) - keycard-multiaccount? (boolean (get-in db [:multiaccounts/multiaccounts multiaccount-address :keycard-pairing]))] + (let [{:keys [key-uid] :as multiaccount} (get-in db [:intro-wizard :root-key]) + keycard-multiaccount? (boolean (get-in db [:multiaccounts/multiaccounts key-uid :keycard-pairing]))] (if keycard-multiaccount? ;; trying to recover multiaccount created with keycard {:db (-> db @@ -70,14 +66,14 @@ (fx/defn store-multiaccount {:events [::recover-multiaccount-confirmed]} - [{:keys [db] :as cofx}] + [{:keys [db]}] (let [password (get-in db [:intro-wizard :key-code]) - {:keys [passphrase root-key]} (:intro-wizard db) - {:keys [id address]} root-key + {:keys [root-key]} (:intro-wizard db) + {:keys [id]} root-key callback #(re-frame/dispatch [::store-multiaccount-success password]) hashed-password (ethereum/sha3 (security/safe-unmask-data password))] {:db (assoc-in db [:intro-wizard :processing?] true) - ::multiaccounts.create/store-multiaccount [id address hashed-password callback]})) + ::multiaccounts.create/store-multiaccount [id hashed-password callback]})) (fx/defn recover-multiaccount-with-checks {:events [::sign-in-button-pressed]} @@ -118,19 +114,18 @@ root-data derived-data-extended])))))))))))) (fx/defn show-existing-multiaccount-alert - [_ address] + [_ key-uid] {:utils/show-confirmation {:title (i18n/label :t/multiaccount-exists-title) :content (i18n/label :t/multiaccount-exists-content) :confirm-button-text (i18n/label :t/unlock) :on-accept #(re-frame/dispatch - [:multiaccounts.login.ui/multiaccount-selected - (clojure.string/lower-case address)]) + [:multiaccounts.login.ui/multiaccount-selected key-uid]) :on-cancel #(re-frame/dispatch [:navigate-to :multiaccounts])}}) (fx/defn on-import-multiaccount-success {:events [::import-multiaccount-success]} - [{:keys [db] :as cofx} {:keys [address] :as root-data} derived-data] + [{:keys [db] :as cofx} {:keys [key-uid] :as root-data} derived-data] (let [multiaccounts (:multiaccounts/multiaccounts db)] (fx/merge cofx @@ -140,7 +135,7 @@ :step :recovery-success :forward-action :multiaccounts.recover/re-encrypt-pressed)} (when (existing-account? root-data multiaccounts) - (show-existing-multiaccount-alert address)) + (show-existing-multiaccount-alert key-uid)) (navigation/navigate-to-cofx :recover-multiaccount-success nil)))) (fx/defn enter-phrase-pressed diff --git a/src/status_im/native_module/core.cljs b/src/status_im/native_module/core.cljs index 7f1b212b25..806fa3685a 100644 --- a/src/status_im/native_module/core.cljs +++ b/src/status_im/native_module/core.cljs @@ -46,7 +46,8 @@ (defn save-account-and-login "NOTE: beware, the password has to be sha3 hashed" [multiaccount-data hashed-password config accounts-data] - (log/debug "[native-module] save-account-and-login") + (log/debug "[native-module] save-account-and-login" + "multiaccount-data" multiaccount-data) (clear-web-data) (.saveAccountAndLogin (status) multiaccount-data hashed-password config accounts-data)) @@ -125,12 +126,12 @@ (defn multiaccount-store-derived "NOTE: beware, the password has to be sha3 hashed" [account-id paths hashed-password callback] - (log/debug "[native-module] multiaccount-store-derived") + (log/debug "[native-module] multiaccount-store-derived" + "account-id" account-id) (.multiAccountStoreDerived (status) (types/clj->json {:accountID account-id :paths paths :password hashed-password}) - callback)) (defn multiaccount-generate-and-derive-addresses diff --git a/src/status_im/ui/screens/chat/toolbar_content.cljs b/src/status_im/ui/screens/chat/toolbar_content.cljs index 5e04634ed7..8a09c306aa 100644 --- a/src/status_im/ui/screens/chat/toolbar_content.cljs +++ b/src/status_im/ui/screens/chat/toolbar_content.cljs @@ -42,8 +42,6 @@ (defview toolbar-content-view [] (letsubs [{:keys [group-chat color online contacts chat-name contact public? chat-id] :as chat} [:chats/current-chat] - show-actions? [:chats/current-chat-ui-prop :show-actions?] - multiaccounts [:multiaccounts/multiaccounts] sync-state [:sync-state]] (let [has-subtitle? (or group-chat (not= :done sync-state))] [react/view {:style st/toolbar-container} diff --git a/src/status_im/ui/screens/keycard/views.cljs b/src/status_im/ui/screens/keycard/views.cljs index fea0bd492e..e334c693d1 100644 --- a/src/status_im/ui/screens/keycard/views.cljs +++ b/src/status_im/ui/screens/keycard/views.cljs @@ -366,7 +366,7 @@ status [:hardwallet/pin-status] error-label [:hardwallet/pin-error-label] multiple-multiaccounts? [:multiple-multiaccounts?] - {:keys [address name] :as account} [:multiaccounts/login] + {:keys [key-uid name] :as account} [:multiaccounts/login] small-screen? [:dimensions/small-screen?] retry-counter [:hardwallet/retry-counter]] [react/view styles/container @@ -428,7 +428,7 @@ :font-family "monospace"} :number-of-lines 1 :ellipsize-mode :middle} - (utils.core/truncate-str address 14 true)]]] + (utils.core/truncate-str key-uid 14 true)]]] [pin.views/pin-view {:pin pin :retry-counter retry-counter @@ -445,7 +445,7 @@ (defview login-connect-card [] (letsubs [status [:hardwallet/pin-status] - {:keys [address name] :as account} [:multiaccounts/login]] + {:keys [key-uid name] :as account} [:multiaccounts/login]] (let [in-progress? (= status :verifying)] [react/view styles/container [toolbar/toolbar @@ -506,7 +506,7 @@ :font-family "monospace"} :number-of-lines 1 :ellipsize-mode :middle} - (utils.core/truncate-str address 14 true)]]] + (utils.core/truncate-str key-uid 14 true)]]] [react/view {:margin-bottom 12 :flex 1 :align-items :center diff --git a/src/status_im/ui/screens/multiaccounts/views.cljs b/src/status_im/ui/screens/multiaccounts/views.cljs index f210f7fb5a..e34b1c891f 100644 --- a/src/status_im/ui/screens/multiaccounts/views.cljs +++ b/src/status_im/ui/screens/multiaccounts/views.cljs @@ -16,8 +16,10 @@ [status-im.react-native.resources :as resources])) (defn multiaccount-view - [{:keys [address photo-path name public-key keycard-pairing]}] - [react/touchable-highlight {:on-press #(re-frame/dispatch [:multiaccounts.login.ui/multiaccount-selected address])} + [{:keys [key-uid photo-path name keycard-pairing]}] + [react/touchable-highlight + {:on-press #(re-frame/dispatch + [:multiaccounts.login.ui/multiaccount-selected key-uid])} [react/view styles/multiaccount-view [photos/photo photo-path {:size styles/multiaccount-image-size}] [react/view styles/multiaccount-badge-text-view diff --git a/src/status_im/utils/keychain/core.cljs b/src/status_im/utils/keychain/core.cljs index 295e35ac30..cc19852d69 100644 --- a/src/status_im/utils/keychain/core.cljs +++ b/src/status_im/utils/keychain/core.cljs @@ -116,11 +116,11 @@ (re-frame/reg-fx :keychain/get-auth-method - (fn [[address callback]] + (fn [[key-uid callback]] (can-save-user-password? (fn [can-save?] (if can-save? - (get-credentials (str address "-auth") + (get-credentials (str key-uid "-auth") #(callback (if % (.-password %) auth-method-none))) @@ -128,18 +128,18 @@ (re-frame/reg-fx :keychain/get-user-password - (fn [[address callback]] - (get-credentials address #(if % (callback (security/mask-data (.-password %))) (callback nil))))) + (fn [[key-uid callback]] + (get-credentials key-uid #(if % (callback (security/mask-data (.-password %))) (callback nil))))) (re-frame/reg-fx :keychain/get-hardwallet-keys - (fn [[address callback]] + (fn [[key-uid callback]] (get-credentials - address + key-uid (fn [encryption-key-data] (if encryption-key-data (get-credentials - (whisper-key-name address) + (whisper-key-name key-uid) (fn [whisper-key-data] (if whisper-key-data (callback [(.-password encryption-key-data) @@ -149,10 +149,10 @@ (re-frame/reg-fx :keychain/save-user-password - (fn [[address password]] + (fn [[key-uid password]] (save-credentials - address - address + key-uid + key-uid (security/safe-unmask-data password) #(when-not % (log/error @@ -163,12 +163,12 @@ (re-frame/reg-fx :keychain/save-auth-method - (fn [[address method]] + (fn [[key-uid method]] (log/debug "[keychain] :keychain/save-auth-method" "method" method) (save-credentials - (str address "-auth") - address + (str key-uid "-auth") + key-uid method #(when-not % (log/error @@ -179,17 +179,17 @@ (re-frame/reg-fx :keychain/save-hardwallet-keys - (fn [[address encryption-public-key whisper-private-key]] + (fn [[key-uid encryption-public-key whisper-private-key]] (save-credentials - address - address + key-uid + key-uid encryption-public-key #(when-not % (log/error (str "Error while saving encryption-public-key")))) (save-credentials - (whisper-key-name address) - address + (whisper-key-name key-uid) + key-uid whisper-private-key #(when-not % (log/error @@ -197,40 +197,40 @@ (re-frame/reg-fx :keychain/clear-user-password - (fn [address] + (fn [key-uid] (when platform/mobile? - (-> (.resetInternetCredentials rn/keychain (string/lower-case address)) + (-> (.resetInternetCredentials rn/keychain (string/lower-case key-uid)) (.then #(when-not % (log/error (str "Error while clearing saved password.")))))))) (fx/defn get-auth-method - [_ address] + [_ key-uid] {:keychain/get-auth-method - [address #(re-frame/dispatch [:multiaccounts.login/get-auth-method-success % address])]}) + [key-uid #(re-frame/dispatch [:multiaccounts.login/get-auth-method-success % key-uid])]}) (fx/defn get-user-password - [_ address] + [_ key-uid] {:keychain/get-user-password - [address + [key-uid #(re-frame/dispatch - [:multiaccounts.login.callback/get-user-password-success % address])]}) + [:multiaccounts.login.callback/get-user-password-success % key-uid])]}) (fx/defn get-hardwallet-keys - [_ address] + [_ key-uid] {:keychain/get-hardwallet-keys - [address + [key-uid #(re-frame/dispatch - [:multiaccounts.login.callback/get-hardwallet-keys-success address %])]}) + [:multiaccounts.login.callback/get-hardwallet-keys-success key-uid %])]}) (fx/defn save-user-password - [_ address password] - {:keychain/save-user-password [address password]}) + [_ key-uid password] + {:keychain/save-user-password [key-uid password]}) (fx/defn save-hardwallet-keys - [_ address encryption-public-key whisper-private-key] - {:keychain/save-hardwallet-keys [address + [_ key-uid encryption-public-key whisper-private-key] + {:keychain/save-hardwallet-keys [key-uid encryption-public-key whisper-private-key]}) (fx/defn save-auth-method - [{:keys [db]} address method] + [{:keys [db]} key-uid method] {:db (assoc db :auth-method method) - :keychain/save-auth-method [address method]}) + :keychain/save-auth-method [key-uid method]}) diff --git a/src/status_im/wallet/accounts/core.cljs b/src/status_im/wallet/accounts/core.cljs index 709c2b362b..613b1afdcb 100644 --- a/src/status_im/wallet/accounts/core.cljs +++ b/src/status_im/wallet/accounts/core.cljs @@ -153,4 +153,4 @@ :path "" :type :watch :color (rand-nth colors/account-colors)})} - (navigation/navigate-to-cofx :account-added nil)))) \ No newline at end of file + (navigation/navigate-to-cofx :account-added nil)))) diff --git a/status-go-version.json b/status-go-version.json index 1677f669ee..d8bb737f3c 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -2,7 +2,7 @@ "_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh ' instead", "owner": "status-im", "repo": "status-go", - "version": "v0.36.1", - "commit-sha1": "fd49b0140ebafdcec35b4da84685bcd8559a7dd9", - "src-sha256": "1pqnvmldg93vbmmsvpr24pj87d2vx3cfm7rr9rgwdk469pd1hhhy" + "version": "v0.36.2", + "commit-sha1": "4c0d8dedea10b02bbad476170cc0eef61a92ecbf", + "src-sha256": "0a13rk9p13s3p1dz3n7wbb3s343dlqsidmphxz57xw6di2s40nzx" } diff --git a/test/cljs/status_im/test/sign_in/flow.cljs b/test/cljs/status_im/test/sign_in/flow.cljs index d401035e88..0f27cc6f60 100644 --- a/test/cljs/status_im/test/sign_in/flow.cljs +++ b/test/cljs/status_im/test/sign_in/flow.cljs @@ -11,14 +11,14 @@ (deftest on-password-input-submitted (testing "handling :multiaccounts.login.ui/password-input-submitted event" - (let [cofx {:db {:multiaccounts/login {:address "address" + (let [cofx {:db {:multiaccounts/login {:key-uid "key-uid" :password "password" :name "user" :photo-path "photo"}}} efx (login.core/login cofx)] (testing "Change multiaccount." (is (= (::login.core/login efx) - ["{\"name\":\"user\",\"address\":\"address\",\"photo-path\":\"photo\"}" (ethereum/sha3 "password")]))) + ["{\"name\":\"user\",\"key-uid\":\"key-uid\",\"photo-path\":\"photo\"}" (ethereum/sha3 "password")]))) (testing "start activity indicator" (is (= (get-in efx [:db :multiaccounts/login :processing]) true))))))