This commit is contained in:
alwx 2024-11-22 18:29:14 +01:00
parent 6f1605aea4
commit 330deb2f14
No known key found for this signature in database
GPG Key ID: D9E51F0C88DB4E2A
6 changed files with 45 additions and 4 deletions

View File

@ -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)]]]}

View File

@ -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

View File

@ -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))

View File

@ -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 %])}]))}]]]})))

View File

@ -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

View File

@ -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)))