Regular multiacc as a backend for simulated keycard

This commit is contained in:
Roman Volosovskyi 2020-04-24 10:45:54 +03:00
parent 35dd4b015b
commit 7ebd9dc899
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
13 changed files with 143 additions and 61 deletions

View File

@ -21,3 +21,4 @@ PARTITIONED_TOPIC=0
CONTRACT_NODES=1
MOBILE_UI_FOR_DESKTOP=1
STATUS_GO_ENABLE_NIMBUS=0
KEYCARD_TEST_MENU=0

View File

@ -440,3 +440,9 @@
(re-frame/dispatch
[:hardwallet.callback/on-sign-error
(error-object->map response)]))}))
(defn save-multiaccount-and-login [args]
(keycard/save-multiaccount-and-login card args))
(defn login [args]
(keycard/login card args))

View File

@ -96,7 +96,7 @@
(re-frame/reg-fx
:hardwallet/login-with-keycard
status/login-with-keycard)
card/login)
(re-frame/reg-fx
:send-transaction-with-signature
@ -143,3 +143,7 @@
(fn [whisper-name photo-path]
(re-frame/dispatch
[on-success whisper-name photo-path])))))
(re-frame/reg-fx
:hardwallet/save-multiaccount-and-login
card/save-multiaccount-and-login)

View File

@ -27,4 +27,6 @@
(export-key [this args])
(unpair-and-delete [this args])
(get-keys [this args])
(sign [this args]))
(sign [this args])
(save-multiaccount-and-login [this args])
(login [this args]))

View File

@ -27,4 +27,6 @@
(unpair-and-delete [this args])
(get-keys [this args])
(sign [this args])
(sign-typed-data [this args]))
(sign-typed-data [this args])
(save-multiaccount-and-login [this args])
(login [this args]))

View File

@ -252,19 +252,28 @@
(fx/defn generate-and-load-key
{:events [:hardwallet/generate-and-load-key]}
[{:keys [db] :as cofx}]
(let [{:keys [mnemonic pairing pin]} (get-in db [:hardwallet :secrets])
{:keys [selected-id multiaccounts]} (:intro-wizard db)
user-selected-mnemonic (->> multiaccounts
(let [{:keys [pairing pin]}
(get-in db [:hardwallet :secrets])
{:keys [selected-id multiaccounts]}
(:intro-wizard db)
multiaccount (or (->> multiaccounts
(filter #(= (:id %) selected-id))
first
:mnemonic)
first)
(assoc (get-in db [:intro-wizard :root-key])
:derived
(get-in db [:intro-wizard :derived])))
recovery-mnemonic (get-in db [:intro-wizard :passphrase])
mnemonic' (or user-selected-mnemonic mnemonic recovery-mnemonic)
mnemonic (or (:mnemonic multiaccount)
recovery-mnemonic)
pin' (or pin (common/vector->string (get-in db [:hardwallet :pin :current])))]
(fx/merge cofx
{:hardwallet/generate-and-load-key {:mnemonic mnemonic'
{:hardwallet/generate-and-load-key
{:mnemonic mnemonic
:pairing pairing
:pin pin'}})))
:pin pin'
:multiaccount multiaccount}})))
(fx/defn begin-setup-pressed
{:events [:keycard.onboarding.intro.ui/begin-setup-pressed]}

View File

@ -1,6 +1,8 @@
(ns status-im.hardwallet.real-keycard
(:require [status-im.react-native.js-dependencies :as js-dependencies]
[status-im.hardwallet.keycard :as keycard]))
[status-im.hardwallet.keycard :as keycard]
[status-im.native-module.core :as status]
[status-im.utils.types :as types]))
(defonce status-keycard (.-default js-dependencies/status-keycard))
(defonce event-emitter (.-DeviceEventEmitter js-dependencies/react-native))
@ -189,6 +191,19 @@
(then on-success)
(catch on-failure))))
(defn save-multiaccount-and-login
[{:keys [multiaccount-data password settings node-config accounts-data chat-key]}]
(status/save-multiaccount-and-login-with-keycard
(types/clj->json multiaccount-data)
password
(types/clj->json settings)
node-config
(types/clj->json accounts-data)
chat-key))
(defn login [args]
(status/login-with-keycard args))
(defrecord RealKeycard []
keycard/Keycard
(keycard/check-nfc-support [this args]
@ -244,4 +259,8 @@
(keycard/sign [this args]
(sign args))
(keycard/sign-typed-data [this args]
(sign-typed-data args)))
(sign-typed-data args))
(keycard/save-multiaccount-and-login [this args]
(save-multiaccount-and-login args))
(keycard/login [this args]
(login args)))

View File

@ -13,7 +13,6 @@
(fx/defn sign
{:events [:hardwallet/sign]}
[{:keys [db] :as cofx}]
(log/debug "FOOOOO sign keke" (:signing/tx db))
(let [card-connected? (get-in db [:hardwallet :card-connected?])
pairing (common/get-pairing db)
keycard-instance-uid (get-in db [:multiaccount :keycard-instance-uid])

View File

@ -1,6 +1,12 @@
(ns status-im.hardwallet.simulated-keycard
(:require [status-im.hardwallet.keycard :as keycard]
[status-im.utils.utils :as utils]))
[status-im.utils.utils :as utils]
[status-im.constants :as constants]
[taoensso.timbre :as log]
[status-im.ethereum.core :as ethereum]
[status-im.native-module.core :as status]
[status-im.utils.types :as types]
[re-frame.db :as re-frame.db]))
(def initial-state
{:card-connected? false
@ -13,6 +19,18 @@
(doseq [callback (vals (get @state :on-card-connected))]
(callback)))
(defn connect-selected-card []
(swap! state assoc :application-info
{:free-pairing-slots 5
:app-version "2.2"
:secure-channel-pub-key "04c3071768912a515c00aeab7ceb8a5bfda91d036f4a4e60b7944cee3ca7fb67b6d118e8df1e2480b87fd636c6615253245bbbc93a6a407f155f2c58f76c96ef0e",
:instance-uid "9c3f27ee5dfc39c2b14f4d6d3379cd68"
:paired? true
:has-master-key? true
:initialized? true
:key-uid (get-in @re-frame.db/app-db [:multiaccounts/login :key-uid])})
(connect-card))
(defn disconnect-card []
(swap! state assoc :card-connected? false)
(doseq [callback (vals (get @state :on-card-disconnected))]
@ -86,23 +104,35 @@
(when (= password kk1-password)
(later #(on-success kk1-pair))))
(defn generate-and-load-key [{:keys [pin pairing on-success]}]
(defn generate-and-load-key
[{:keys [pin pairing on-success multiaccount]}]
(when (and (= pin (get @state :pin))
(= pairing kk1-pair))
(later
(let [{:keys [id address public-key derived key-uid]}
multiaccount
whisper (get derived constants/path-whisper-keyword)
wallet (get derived constants/path-default-wallet-keyword)
password (ethereum/sha3 pin)]
(status/multiaccount-store-derived
id
[constants/path-wallet-root
constants/path-eip1581
constants/path-whisper
constants/path-default-wallet]
password
#(on-success
{:key-uid "08f1e42f076b956715dac6b93ad1282e435be877a90c9353f6c6dfe455474047"
:encryption-public-key "04a15b33d5c76ff72c3b3863fe2cb2b45c25f87c6accc96fa95457845e3f69ba5fc2d835351d17b5031e1723513824612003facb98f508af2866382ed996125b4d"
:address "f75457177cd2b7bdc407a6c4881eb490f66ca3c2"
:whisper-public-key "04d25f563a8a2897a7025a1f022eee78ba7c0e182aae04ab640bc9e118698734257647e18cb6c95f825e6d03d8e3550178b13a30dceba722be7c8fcd0adecc0fa9"
{:key-uid key-uid
:encryption-public-key (ethereum/sha3 pin)
:address address
:whisper-public-key (:public-key whisper)
:instance-uid "1b360b10a9a68b7d494e8f059059f118"
:wallet-root-public-key "0463187f5c917eef481e04af704c14e57a9e8596516f0ec10a4556561ad49b5aa249976ec545d37d04f4d4c7d1c0d9a2141dc61e458b09631d25fa7858c6323ea3"
:wallet-root-address "e034a084d2282e265f83e3fdfa48b42c3d53312a"
:whisper-address "87f1c9bbe1c907143413cf018caad355dde16b3c"
:public-key "04035d4efe4e96f8fa0e49a94433c972e510f0c8698348b4e1acd3b4d3083c61283b932ec54dd9512566931b26627a5d3122a916577459b7926fce6a278055f899"
:whisper-address (:address whisper)
:public-key public-key
:whisper-private-key "34bc7d0c258c4f2ac1dac4fd6c55c9478bac1f4a9d8b9f1152c8551ab7187b43"
:wallet-address "c8435ef92bbb76bc1861833713e202e18ebd4601"
:wallet-public-key "044887a5a2599d722aa1af8cda800a17415d3a071c4706e111ad05465c3bf10fcb6f92c8d74df994160e0ba4aeff71f7a6d256cf36ce8cff3d313b8a0709404886"}))))
:wallet-address (:address wallet)
:wallet-public-key (:public-key wallet)})))))
(defn unblock-pin [args])
@ -118,10 +148,28 @@
(defn remove-key-with-unpair [args])
(defn export-key [args])
(defn unpair-and-delete [args])
(defn get-keys [args])
(defn get-keys [{:keys [on-success pin]}]
;;TODO(rasom): verify password before callback
(later
#(on-success
{:key-uid (get-in @state [:application-info :key-uid])
:encryption-public-key (ethereum/sha3 pin)})))
(defn sign [args])
(defn sign-typed-data [args])
(defn save-multiaccount-and-login
[{:keys [multiaccount-data password settings node-config accounts-data]}]
(status/save-account-and-login
(types/clj->json multiaccount-data)
password
(types/clj->json settings)
node-config
(types/clj->json accounts-data)))
(defn login [{:keys [multiaccount-data password]}]
(status/login multiaccount-data password))
(defrecord SimulatedKeycard []
keycard/Keycard
(keycard/check-nfc-support [this args]
@ -173,4 +221,8 @@
(keycard/get-keys [this args]
(get-keys args))
(keycard/sign [this args]
(sign args)))
(sign args))
(keycard/save-multiaccount-and-login [this args]
(save-multiaccount-and-login args))
(keycard/login [this args]
(login args)))

View File

@ -22,6 +22,7 @@
:justify-content :center
:align-items :center}}
[button "conn" :connect-card simulated-keycard/connect-card]
[button "conn sell" :connect-selected-card simulated-keycard/connect-selected-card]
[button "disc" :disconnect-card simulated-keycard/disconnect-card]
[button "res" :keycard-reset-state simulated-keycard/reset-state]])

View File

@ -224,14 +224,9 @@
:path constants/path-whisper
:chat true})])
(fx/defn save-account-and-login-with-keycard
[_ multiaccount-data password settings node-config accounts-data chat-key]
{::save-account-and-login-with-keycard [(types/clj->json multiaccount-data)
password
(types/clj->json settings)
node-config
(types/clj->json accounts-data)
chat-key]})
(fx/defn save-multiaccount-and-login-with-keycard
[_ args]
{:hardwallet/save-multiaccount-and-login args})
(fx/defn save-account-and-login
[_ multiaccount-data password settings node-config accounts-data]
@ -306,12 +301,13 @@
(fx/merge cofx
{:db db}
(if keycard-multiaccount?
(save-account-and-login-with-keycard multiaccount-data
password
settings
(node/get-new-config db)
accounts-data
chat-key)
(save-multiaccount-and-login-with-keycard
{:multiaccount-data multiaccount-data
:password password
:settings settings
:node-config (node/get-new-config db)
:accounts-data accounts-data
:chat-key chat-key})
(save-account-and-login multiaccount-data
(ethereum/sha3 (security/safe-unmask-data password))
settings
@ -420,12 +416,3 @@
settings
config
accounts-data)))
(re-frame/reg-fx
::save-account-and-login-with-keycard
(fn [[multiaccount-data password settings config accounts-data chat-key]]
(status/save-account-and-login-with-keycard multiaccount-data
(security/safe-unmask-data password)
settings
config
accounts-data
chat-key)))

View File

@ -52,7 +52,7 @@
(.saveAccountAndLogin
(status) multiaccount-data hashed-password settings config accounts-data))
(defn save-account-and-login-with-keycard
(defn save-multiaccount-and-login-with-keycard
"NOTE: chat-key is a whisper private key sent from keycard"
[multiaccount-data password settings config accounts-data chat-key]
(log/debug "[native-module] save-account-and-login-with-keycard")