From 330deb2f14982b024c470840e8dd89492bdc060a Mon Sep 17 00:00:00 2001 From: alwx Date: Fri, 22 Nov 2024 18:29:14 +0100 Subject: [PATCH] Fixes --- src/status_im/common/signals/events.cljs | 6 ++++ .../standard_authentication/events.cljs | 1 + src/status_im/contexts/keycard/events.cljs | 1 + .../contexts/keycard/sign/events.cljs | 34 +++++++++++++++++++ src/status_im/contexts/wallet/effects.cljs | 3 +- src/status_im/contexts/wallet/rpc.cljs | 4 +-- 6 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 src/status_im/contexts/keycard/sign/events.cljs diff --git a/src/status_im/common/signals/events.cljs b/src/status_im/common/signals/events.cljs index c1090dd470..790f7d12c9 100644 --- a/src/status_im/common/signals/events.cljs +++ b/src/status_im/common/signals/events.cljs @@ -36,6 +36,12 @@ "wallet" {:fx [[:dispatch [:wallet/signal-received event-js]]]} + "wallet.sign.transactions" + {:fx [[:dispatch + [:standard-auth/authorize-with-keycard + {:on-complete #(rf/dispatch [:keycard/sign-hash % + (first (transforms/js->clj event-js))])}]]]} + "wallet.suggested.routes" {:fx [[:dispatch [:wallet/handle-suggested-routes (transforms/js->clj event-js)]]]} diff --git a/src/status_im/common/standard_authentication/events.cljs b/src/status_im/common/standard_authentication/events.cljs index 435ff8c46c..669ef3f525 100644 --- a/src/status_im/common/standard_authentication/events.cljs +++ b/src/status_im/common/standard_authentication/events.cljs @@ -116,6 +116,7 @@ :on-close #(rf/dispatch [:standard-auth/reset-login-password]) :content (fn [] [keycard.pin/auth {:on-complete on-complete}])}]]]}) + (rf/reg-event-fx :standard-auth/authorize-with-keycard authorize-with-keycard) (defn authorize-with-password diff --git a/src/status_im/contexts/keycard/events.cljs b/src/status_im/contexts/keycard/events.cljs index 70f249894a..60ee834124 100644 --- a/src/status_im/contexts/keycard/events.cljs +++ b/src/status_im/contexts/keycard/events.cljs @@ -6,6 +6,7 @@ status-im.contexts.keycard.nfc.events status-im.contexts.keycard.nfc.sheets.events status-im.contexts.keycard.pin.events + status-im.contexts.keycard.sign.events [status-im.contexts.keycard.utils :as keycard.utils] utils.datetime)) diff --git a/src/status_im/contexts/keycard/sign/events.cljs b/src/status_im/contexts/keycard/sign/events.cljs new file mode 100644 index 0000000000..4e4529e0ac --- /dev/null +++ b/src/status_im/contexts/keycard/sign/events.cljs @@ -0,0 +1,34 @@ +(ns status-im.contexts.keycard.sign.events + (:require [utils.address] + [utils.re-frame :as rf])) + +(defn get-signature-map + [tx-hash signature] + {tx-hash {:r (subs signature 0 64) + :s (subs signature 64 128) + :v (subs signature 128 130)}}) + +(rf/reg-event-fx :keycard/sign + (fn [_ [data]] + {:effects.keycard/sign data})) + +(rf/reg-event-fx :keycard/sign-hash + (fn [{:keys [db]} [pin-text tx-hash]] + (let [current-address (get-in db [:wallet :current-viewing-account-address]) + path (get-in db [:wallet :accounts current-address :path]) + key-uid (get-in db [:profile/profile :key-uid])] + {:fx [[:dispatch + [:keycard/connect + {:key-uid key-uid + :on-success + (fn [] + (rf/dispatch + [:keycard/sign + {:pin pin-text + :path path + :hash (utils.address/naked-address tx-hash) + :on-success (fn [signature] + (rf/dispatch [:keycard/disconnect]) + (rf/dispatch [:wallet/proceed-with-transactions-signatures + (get-signature-map tx-hash signature)])) + :on-failure #(rf/dispatch [:keycard/on-action-with-pin-error %])}]))}]]]}))) diff --git a/src/status_im/contexts/wallet/effects.cljs b/src/status_im/contexts/wallet/effects.cljs index c10c7a604b..a051700baa 100644 --- a/src/status_im/contexts/wallet/effects.cljs +++ b/src/status_im/contexts/wallet/effects.cljs @@ -109,7 +109,8 @@ [hashes address password] (-> (promesa/all (for [h hashes] - (wallet-rpc/sign-message h address password))) + {:message h + :signature (wallet-rpc/sign-message h address password)})) (promesa/catch (fn [err] (throw (ex-info "Failed to sign transaction hashes" {:error err diff --git a/src/status_im/contexts/wallet/rpc.cljs b/src/status_im/contexts/wallet/rpc.cljs index 9fe02c471c..731ee62ddb 100644 --- a/src/status_im/contexts/wallet/rpc.cljs +++ b/src/status_im/contexts/wallet/rpc.cljs @@ -56,6 +56,4 @@ message address password) - (promesa/then (fn [s] - {:message message - :signature (utils.hex/normalize-hex s)})))) + (promesa/then utils.hex/normalize-hex)))