Skip to content

Commit

Permalink
[Fixes #9088] Store eip1581 path and wallet root path, don't store
Browse files Browse the repository at this point in the history
master key

When creating the account we store as well the path specified in eip1581
https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1581.md ,
`m / 43' / 60' / 1581'`.

The reason for doing so is that eventually we might want to derive an
encryption key from it, which would require the user to re-enter their
seed phrase if we would not store this.

This commit changes the behavior not to store the master key, and
instead store `m /44'/60' /0'/0`, from which wallets are now derived.
  • Loading branch information
cammellos committed Oct 3, 2019
1 parent 78c57a3 commit 68354f0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
11 changes: 8 additions & 3 deletions src/status_im/constants.cljs
Expand Up @@ -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")
Expand Down
39 changes: 22 additions & 17 deletions src/status_im/multiaccounts/create/core.cljs
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/status_im/multiaccounts/recover/core.cljs
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/status_im/wallet/accounts/core.cljs
Expand Up @@ -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]
Expand Down Expand Up @@ -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)}}))

Expand Down

0 comments on commit 68354f0

Please sign in to comment.