[#10277] [keycard] Fix tx signing for derived accounts

This commit is contained in:
Roman Volosovskyi 2020-04-17 15:01:19 +03:00
parent 4f120d99f7
commit c9308af4d8
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
3 changed files with 28 additions and 13 deletions

View File

@ -490,6 +490,7 @@ var TopLevel = {
"showActionSheetWithOptions" : function () {}, "showActionSheetWithOptions" : function () {},
"showPicker" : function () {}, "showPicker" : function () {},
"sign" : function () {}, "sign" : function () {},
"signWithPath" : function () {},
"signGroupMembership" : function () {}, "signGroupMembership" : function () {},
"signMessage" : function () {}, "signMessage" : function () {},
"signPinless" : function () {}, "signPinless" : function () {},

View File

@ -177,12 +177,17 @@
(catch on-failure)))) (catch on-failure))))
(defn sign (defn sign
[{:keys [pairing pin hash on-success on-failure]}] [{:keys [pairing pin path hash on-success on-failure]}]
(when (and pairing pin hash) (when (and pairing pin hash)
(.. status-keycard (if path
(sign pairing pin hash) (.. status-keycard
(then on-success) (signWithPath pairing pin path hash)
(catch on-failure)))) (then on-success)
(catch on-failure))
(.. status-keycard
(sign pairing pin hash)
(then on-success)
(catch on-failure)))))
(defn sign-typed-data (defn sign-typed-data
[{:keys [hash on-success on-failure]}] [{:keys [hash on-success on-failure]}]

View File

@ -13,13 +13,21 @@
(fx/defn sign (fx/defn sign
{:events [:hardwallet/sign]} {:events [:hardwallet/sign]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [card-connected? (get-in db [:hardwallet :card-connected?]) (log/debug "FOOOOO sign keke" (:signing/tx db))
pairing (common/get-pairing db) (let [card-connected? (get-in db [:hardwallet :card-connected?])
multiaccount-keycard-instance-uid (get-in db [:multiaccount :keycard-instance-uid]) pairing (common/get-pairing db)
instance-uid (get-in db [:hardwallet :application-info :instance-uid]) keycard-instance-uid (get-in db [:multiaccount :keycard-instance-uid])
keycard-match? (= multiaccount-keycard-instance-uid instance-uid) instance-uid (get-in db [:hardwallet :application-info :instance-uid])
hash (get-in db [:hardwallet :hash]) keycard-match? (= keycard-instance-uid instance-uid)
pin (common/vector->string (get-in db [:hardwallet :pin :sign]))] hash (get-in db [:hardwallet :hash])
pin (common/vector->string (get-in db [:hardwallet :pin :sign]))
from (get-in db [:signing/tx :from :address])
path (reduce
(fn [_ {:keys [address path]}]
(when (= from address)
(reduced path)))
nil
(:multiaccount/accounts db))]
(if (and card-connected? (if (and card-connected?
keycard-match?) keycard-match?)
{:db (-> db {:db (-> db
@ -27,7 +35,8 @@
(assoc-in [:hardwallet :pin :status] :verifying)) (assoc-in [:hardwallet :pin :status] :verifying))
:hardwallet/sign {:hash (ethereum/naked-address hash) :hardwallet/sign {:hash (ethereum/naked-address hash)
:pairing pairing :pairing pairing
:pin pin}} :pin pin
:path path}}
(fx/merge cofx (fx/merge cofx
{:db (assoc-in db [:signing/sign :keycard-step] :signing)} {:db (assoc-in db [:signing/sign :keycard-step] :signing)}
(common/set-on-card-connected :hardwallet/sign) (common/set-on-card-connected :hardwallet/sign)