From c9308af4d8b93a9285e4771ecc2d43d719853b01 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Fri, 17 Apr 2020 15:01:19 +0300 Subject: [PATCH] [#10277] [keycard] Fix tx signing for derived accounts --- externs.js | 1 + src/status_im/hardwallet/real_keycard.cljs | 15 ++++++++----- src/status_im/hardwallet/sign.cljs | 25 +++++++++++++++------- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/externs.js b/externs.js index 8b7be452a0..91a0a15358 100644 --- a/externs.js +++ b/externs.js @@ -490,6 +490,7 @@ var TopLevel = { "showActionSheetWithOptions" : function () {}, "showPicker" : function () {}, "sign" : function () {}, + "signWithPath" : function () {}, "signGroupMembership" : function () {}, "signMessage" : function () {}, "signPinless" : function () {}, diff --git a/src/status_im/hardwallet/real_keycard.cljs b/src/status_im/hardwallet/real_keycard.cljs index 53f09ff09c..2024d19c58 100644 --- a/src/status_im/hardwallet/real_keycard.cljs +++ b/src/status_im/hardwallet/real_keycard.cljs @@ -177,12 +177,17 @@ (catch on-failure)))) (defn sign - [{:keys [pairing pin hash on-success on-failure]}] + [{:keys [pairing pin path hash on-success on-failure]}] (when (and pairing pin hash) - (.. status-keycard - (sign pairing pin hash) - (then on-success) - (catch on-failure)))) + (if path + (.. status-keycard + (signWithPath pairing pin path hash) + (then on-success) + (catch on-failure)) + (.. status-keycard + (sign pairing pin hash) + (then on-success) + (catch on-failure))))) (defn sign-typed-data [{:keys [hash on-success on-failure]}] diff --git a/src/status_im/hardwallet/sign.cljs b/src/status_im/hardwallet/sign.cljs index 6c7477de20..9f7c0fc20b 100644 --- a/src/status_im/hardwallet/sign.cljs +++ b/src/status_im/hardwallet/sign.cljs @@ -13,13 +13,21 @@ (fx/defn sign {:events [:hardwallet/sign]} [{:keys [db] :as cofx}] - (let [card-connected? (get-in db [:hardwallet :card-connected?]) - pairing (common/get-pairing db) - multiaccount-keycard-instance-uid (get-in db [:multiaccount :keycard-instance-uid]) - instance-uid (get-in db [:hardwallet :application-info :instance-uid]) - keycard-match? (= multiaccount-keycard-instance-uid instance-uid) - hash (get-in db [:hardwallet :hash]) - pin (common/vector->string (get-in db [:hardwallet :pin :sign]))] + (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]) + instance-uid (get-in db [:hardwallet :application-info :instance-uid]) + keycard-match? (= keycard-instance-uid instance-uid) + 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? keycard-match?) {:db (-> db @@ -27,7 +35,8 @@ (assoc-in [:hardwallet :pin :status] :verifying)) :hardwallet/sign {:hash (ethereum/naked-address hash) :pairing pairing - :pin pin}} + :pin pin + :path path}} (fx/merge cofx {:db (assoc-in db [:signing/sign :keycard-step] :signing)} (common/set-on-card-connected :hardwallet/sign)