diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index 57366f34b71f..b4f878c5746e 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -237,12 +237,17 @@ (def ^:const status-create-address "status_createaddress") -(def ^:const path-root "m/44'/60'/0'/0") -(def ^:const path-default-wallet "m/44'/60'/0'/0/0") -(def ^:const path-whisper "m/43'/60'/1581'/0'/0") +; The extended key from which any wallet can be derived +(def ^:const path-wallet-root "m/44'/60'/0'/0") +; The extended key from which any whisper key/encryption key can be derived +(def ^:const path-eip1581 "m/43'/60'/1581'") +(def ^:const path-default-wallet (str path-wallet-root "/0")) +(def ^:const path-whisper (str path-eip1581 "/0'/0")) (def ^:const path-default-wallet-keyword (keyword path-default-wallet)) (def ^:const path-whisper-keyword (keyword path-whisper)) +(def ^:const path-wallet-root-keyword (keyword path-wallet-root)) +(def ^:const path-eip1581-keyword (keyword path-eip1581)) ;; (ethereum/sha3 "Transfer(address,address,uint256)") (def ^:const event-transfer-hash "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") diff --git a/src/status_im/multiaccounts/create/core.cljs b/src/status_im/multiaccounts/create/core.cljs index 104774ca1555..afa8c63e9541 100644 --- a/src/status_im/multiaccounts/create/core.cljs +++ b/src/status_im/multiaccounts/create/core.cljs @@ -52,7 +52,7 @@ (let [{:keys [selected-id address key-code]} (:intro-wizard db) {:keys [address]} (get-selected-multiaccount cofx) hashed-password (ethereum/sha3 (security/safe-unmask-data key-code)) - callback #(re-frame/dispatch [::store-multiaccount-success key-code])] + callback #(re-frame/dispatch [::store-multiaccount-success key-code %])] {::store-multiaccount [selected-id address hashed-password callback]})) (fx/defn intro-wizard @@ -184,11 +184,16 @@ name (gfycat/generate-gfy publicKey) photo-path (identicon/identicon publicKey) multiaccount-data {:name name :address address :photo-path photo-path} - new-multiaccount (cond-> {:address address + new-multiaccount (cond-> {; address of the master key + :address address + ;; The address from which we derive any wallet + :wallet-root-address (get-in multiaccount [:derived constants/path-wallet-root-keyword :address]) + ;; The address from which we derive any chat account/encryption keys + :eip1581-address (get-in multiaccount [:derived constants/path-eip1581-keyword :address]) :name name :photo-path photo-path + ; public key of the chat account :public-key publicKey - :latest-derived-path 0 :accounts [wallet-account] :signing-phrase signing-phrase @@ -296,26 +301,26 @@ {:events [::store-multiaccount-success] :interceptors [(re-frame/inject-cofx :random-guid-generator) (re-frame/inject-cofx ::get-signing-phrase)]} - [cofx password] - (on-multiaccount-created cofx (get-selected-multiaccount cofx) password {:seed-backed-up? false})) + [cofx password derived] + (on-multiaccount-created cofx + (assoc + (get-selected-multiaccount cofx) + :derived + (types/json->clj derived)) + password + {:seed-backed-up? false})) (re-frame/reg-fx ::store-multiaccount (fn [[id address hashed-password callback]] - (status/multiaccount-store-account + (status/multiaccount-store-derived id + [constants/path-wallet-root + constants/path-eip1581 + constants/path-whisper + constants/path-default-wallet] hashed-password - (fn [] - (status/multiaccount-load-account - address - hashed-password - (fn [value] - (let [{:keys [id]} (types/json->clj value)] - (status/multiaccount-store-derived - id - [constants/path-whisper constants/path-default-wallet] - hashed-password - callback)))))))) + callback))) (re-frame/reg-fx ::save-account-and-login diff --git a/src/status_im/multiaccounts/recover/core.cljs b/src/status_im/multiaccounts/recover/core.cljs index 04520f8c998d..7ce0a24cbad3 100644 --- a/src/status_im/multiaccounts/recover/core.cljs +++ b/src/status_im/multiaccounts/recover/core.cljs @@ -127,7 +127,10 @@ (let [{:keys [id] :as root-data} (types/json->clj result)] (status-im.native-module.core/multiaccount-derive-addresses id - [constants/path-default-wallet constants/path-whisper] + [constants/path-wallet-root + constants/path-eip1581 + constants/path-whisper + constants/path-default-wallet] (fn [result] (let [derived-data (types/json->clj result)] (re-frame/dispatch [::import-multiaccount-success diff --git a/src/status_im/wallet/accounts/core.cljs b/src/status_im/wallet/accounts/core.cljs index fcb1bf56e9dd..9d029f426af2 100644 --- a/src/status_im/wallet/accounts/core.cljs +++ b/src/status_im/wallet/accounts/core.cljs @@ -29,7 +29,7 @@ (let [{:keys [id error]} (types/json->clj value)] (if error (re-frame/dispatch [::generate-new-account-error]) - (let [path (str constants/path-root "/" path-num)] + (let [path (str constants/path-wallet-root "/" path-num)] (status/multiaccount-derive-addresses id [path] @@ -58,7 +58,11 @@ [{:keys [db]} password] (when-not (get-in db [:generate-account :step]) {:db (assoc-in db [:generate-account :step] :generating) - ::generate-account {:address (get-in db [:multiaccount :address]) + ::generate-account {:address (or + ;; Use the walllet-root-address for stored on disk keys + (get-in db [:multiaccount :wallet-root-address]) + ;; Fallback on the master account for keycards + (get-in db [:multiaccount :address])) :path-num (inc (get-in db [:multiaccount :latest-derived-path])) :hashed-password (ethereum/sha3 password)}}))