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.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
  • Loading branch information
cammellos committed Oct 4, 2019
1 parent b3d04bb commit ba34af0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 36 deletions.
13 changes: 10 additions & 3 deletions src/status_im/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,19 @@

(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")
; BIP44 Wallet Root Key, the extended key from which any wallet can be derived
(def ^:const path-wallet-root "m/44'/60'/0'/0")
; EIP1581 Root Key, the extended key from which any whisper key/encryption key can be derived
(def ^:const path-eip1581 "m/43'/60'/1581'")
; BIP44-0 Wallet key, the default wallet key
(def ^:const path-default-wallet (str path-wallet-root "/0"))
; EIP1581 Chat Key 0, the default whisper key
(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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
39 changes: 24 additions & 15 deletions src/status_im/wallet/accounts/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@

(re-frame/reg-fx
::generate-account
(fn [{:keys [address hashed-password path-num]}]