Using Keycard with the new Endpoints for Send/Bridge (#21705)
* fix: routes component annoying warning * feat: replaced keycard sign with sign-hashes * feat: using the keycard to sign transactions * fix: removed unused and weird imports * chore: removed debug logs * chore: linting * fix: removed clearing data on send error
This commit is contained in:
parent
874f07bd77
commit
53d5ac4ea2
|
@ -2,7 +2,9 @@
|
||||||
(:require
|
(:require
|
||||||
["react-native" :as rn]
|
["react-native" :as rn]
|
||||||
["react-native-status-keycard" :default status-keycard]
|
["react-native-status-keycard" :default status-keycard]
|
||||||
|
[oops.core :as oops]
|
||||||
[react-native.platform :as platform]
|
[react-native.platform :as platform]
|
||||||
|
[schema.core :as schema]
|
||||||
[taoensso.timbre :as log]))
|
[taoensso.timbre :as log]))
|
||||||
|
|
||||||
(defonce event-emitter
|
(defonce event-emitter
|
||||||
|
@ -254,17 +256,19 @@
|
||||||
(catch on-failure))))
|
(catch on-failure))))
|
||||||
|
|
||||||
(defn sign
|
(defn sign
|
||||||
[{pin :pin path :path card-hash :hash on-success :on-success on-failure :on-failure}]
|
[{:keys [pin path hash-data]}]
|
||||||
(when (and pin card-hash)
|
(if path
|
||||||
(if path
|
(oops/ocall status-keycard "signWithPath" pin path hash-data)
|
||||||
(.. status-keycard
|
(oops/ocall status-keycard "sign" pin hash-data)))
|
||||||
(signWithPath pin path card-hash)
|
|
||||||
(then on-success)
|
(schema/=> sign
|
||||||
(catch on-failure))
|
[:=>
|
||||||
(.. status-keycard
|
[:cat
|
||||||
(sign pin card-hash)
|
[:map
|
||||||
(then on-success)
|
[:pin :string]
|
||||||
(catch on-failure)))))
|
[:hash-data :string]
|
||||||
|
[:path {:optional true} [:maybe :string]]]]
|
||||||
|
:any])
|
||||||
|
|
||||||
(defn sign-typed-data
|
(defn sign-typed-data
|
||||||
[{card-hash :hash on-success :on-success on-failure :on-failure}]
|
[{card-hash :hash on-success :on-success on-failure :on-failure}]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
(ns status-im.common.log
|
(ns status-im.common.log
|
||||||
(:require
|
(:require
|
||||||
[clojure.pprint :as promesa]
|
[clojure.pprint :as pprint]
|
||||||
[clojure.string :as string]
|
[clojure.string :as string]
|
||||||
[native-module.core :as native-module]
|
[native-module.core :as native-module]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
|
@ -46,7 +46,7 @@
|
||||||
(update data
|
(update data
|
||||||
:vargs
|
:vargs
|
||||||
(partial mapv
|
(partial mapv
|
||||||
#(if (string? %) % (with-out-str (promesa/pprint %))))))]})
|
#(if (string? %) % (with-out-str (pprint/pprint %))))))]})
|
||||||
(native-module/init-status-go-logging logging-params)))))
|
(native-module/init-status-go-logging logging-params)))))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
|
|
|
@ -36,12 +36,6 @@
|
||||||
"wallet"
|
"wallet"
|
||||||
{:fx [[:dispatch [:wallet/signal-received event-js]]]}
|
{: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"
|
"wallet.suggested.routes"
|
||||||
{:fx [[:dispatch [:wallet/handle-suggested-routes (transforms/js->clj event-js)]]]}
|
{:fx [[:dispatch [:wallet/handle-suggested-routes (transforms/js->clj event-js)]]]}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
(ns status-im.contexts.keycard.effects
|
(ns status-im.contexts.keycard.effects
|
||||||
(:require [keycard.keycard :as keycard]
|
(:require [keycard.keycard :as keycard]
|
||||||
[native-module.core :as native-module]
|
[native-module.core :as native-module]
|
||||||
|
[promesa.core :as promesa]
|
||||||
[react-native.async-storage :as async-storage]
|
[react-native.async-storage :as async-storage]
|
||||||
[react-native.platform :as platform]
|
[react-native.platform :as platform]
|
||||||
status-im.contexts.keycard.nfc.effects
|
status-im.contexts.keycard.nfc.effects
|
||||||
[status-im.contexts.keycard.utils :as keycard.utils]
|
[status-im.contexts.keycard.utils :as keycard.utils]
|
||||||
[status-im.contexts.profile.config :as profile.config]
|
[status-im.contexts.profile.config :as profile.config]
|
||||||
|
[utils.hex :as hex]
|
||||||
[utils.re-frame :as rf]))
|
[utils.re-frame :as rf]))
|
||||||
|
|
||||||
(defonce ^:private active-listeners (atom []))
|
(defonce ^:private active-listeners (atom []))
|
||||||
|
@ -50,7 +52,22 @@
|
||||||
|
|
||||||
(rf/reg-fx :effects.keycard/sign
|
(rf/reg-fx :effects.keycard/sign
|
||||||
(fn [args]
|
(fn [args]
|
||||||
(keycard/sign (keycard.utils/wrap-handlers args))))
|
(-> (keycard/sign args)
|
||||||
|
(promesa/then (keycard.utils/get-on-success args))
|
||||||
|
(promesa/catch (keycard.utils/get-on-failure args)))))
|
||||||
|
|
||||||
|
(rf/reg-fx :effects.keycard/sign-hashes
|
||||||
|
(fn [{:keys [hashes pin path on-success] :as args}]
|
||||||
|
(-> (promesa/all
|
||||||
|
(for [hash-data hashes]
|
||||||
|
(-> (keycard/sign {:pin pin
|
||||||
|
:path path
|
||||||
|
:hash-data (hex/normalize-hex hash-data)})
|
||||||
|
(promesa/then (fn [signature]
|
||||||
|
{:signature signature
|
||||||
|
:message hash-data})))))
|
||||||
|
(promesa/then on-success)
|
||||||
|
(promesa/catch (keycard.utils/get-on-failure args)))))
|
||||||
|
|
||||||
(rf/reg-fx :keycard/init-card
|
(rf/reg-fx :keycard/init-card
|
||||||
(fn [args]
|
(fn [args]
|
||||||
|
|
|
@ -2,33 +2,24 @@
|
||||||
(:require [utils.address]
|
(:require [utils.address]
|
||||||
[utils.re-frame :as rf]))
|
[utils.re-frame :as rf]))
|
||||||
|
|
||||||
(defn get-signature-map
|
(rf/reg-event-fx :keycard/sign-hashes
|
||||||
[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]]
|
(fn [_ [data]]
|
||||||
{:effects.keycard/sign data}))
|
{:effects.keycard/sign-hashes data}))
|
||||||
|
|
||||||
(rf/reg-event-fx :keycard/sign-hash
|
(rf/reg-event-fx :keycard/connect-and-sign-hashes
|
||||||
(fn [{:keys [db]} [pin-text tx-hash]]
|
(fn [{:keys [db]} [{:keys [keycard-pin address hashes on-success on-failure]}]]
|
||||||
(let [current-address (get-in db [:wallet :current-viewing-account-address])
|
(let [{:keys [path key-uid]} (get-in db [:wallet :accounts address])]
|
||||||
path (get-in db [:wallet :accounts current-address :path])
|
|
||||||
key-uid (get-in db [:profile/profile :key-uid])]
|
|
||||||
{:fx [[:dispatch
|
{:fx [[:dispatch
|
||||||
[:keycard/connect
|
[:keycard/connect
|
||||||
{:key-uid key-uid
|
{:key-uid key-uid
|
||||||
:on-success
|
:on-success
|
||||||
(fn []
|
(fn []
|
||||||
(rf/dispatch
|
(rf/dispatch
|
||||||
[:keycard/sign
|
[:keycard/sign-hashes
|
||||||
{:pin pin-text
|
{:pin keycard-pin
|
||||||
:path path
|
:path path
|
||||||
:hash (utils.address/naked-address tx-hash)
|
:hashes hashes
|
||||||
:on-success (fn [signature]
|
:on-success (fn [signatures]
|
||||||
(rf/dispatch [:keycard/disconnect])
|
(rf/dispatch [:keycard/disconnect])
|
||||||
(rf/dispatch [:wallet/proceed-with-transactions-signatures
|
(when on-success (on-success signatures)))
|
||||||
(get-signature-map tx-hash signature)]))
|
:on-failure on-failure}]))}]]]})))
|
||||||
:on-failure #(rf/dispatch [:keycard/on-action-with-pin-error %])}]))}]]]})))
|
|
||||||
|
|
|
@ -57,9 +57,13 @@
|
||||||
data
|
data
|
||||||
(update data :key-uid address/normalized-hex)))
|
(update data :key-uid address/normalized-hex)))
|
||||||
|
|
||||||
|
(defn format-success-data
|
||||||
|
[data]
|
||||||
|
(normalize-key-uid (transforms/js->clj data)))
|
||||||
|
|
||||||
(defn get-on-success
|
(defn get-on-success
|
||||||
[{:keys [on-success]}]
|
[{:keys [on-success]}]
|
||||||
#(when on-success (on-success (normalize-key-uid (transforms/js->clj %)))))
|
#(when on-success (on-success (format-success-data %))))
|
||||||
|
|
||||||
(defn get-on-failure
|
(defn get-on-failure
|
||||||
[{:keys [on-failure]}]
|
[{:keys [on-failure]}]
|
||||||
|
|
|
@ -647,22 +647,38 @@
|
||||||
(rf/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:wallet/prepare-signatures-for-transactions
|
:wallet/prepare-signatures-for-transactions
|
||||||
(fn [{:keys [db]} [type sha3-pwd]]
|
(fn [{:keys [db]} [type sha3-pwd]]
|
||||||
(let [transaction-for-signing (get-in db [:wallet :ui type :transaction-for-signing])]
|
(let [{:keys [hashes address signOnKeycard]} (get-in db
|
||||||
{:fx [[:effects.wallet/sign-transaction-hashes
|
[:wallet :ui type :transaction-for-signing
|
||||||
{:hashes (get-in transaction-for-signing [:signingDetails :hashes])
|
:signingDetails])
|
||||||
:address (get-in transaction-for-signing [:signingDetails :address])
|
on-success (fn [signatures]
|
||||||
:password (security/safe-unmask-data sha3-pwd)
|
(rf/dispatch
|
||||||
:on-success (fn [signatures]
|
[:wallet/send-router-transactions-with-signatures type
|
||||||
(rf/dispatch [:wallet/send-router-transactions-with-signatures type
|
signatures]))
|
||||||
signatures]))
|
on-error (fn [error]
|
||||||
:on-error (fn [error]
|
(log/error
|
||||||
(log/error "failed to prepare signatures for transactions"
|
"failed to prepare signatures for transactions"
|
||||||
{:event :wallet/prepare-signatures-for-transactions
|
{:event :wallet/prepare-signatures-for-transactions
|
||||||
:error error})
|
:error error})
|
||||||
(rf/dispatch [:toasts/upsert
|
(rf/dispatch
|
||||||
{:id :prepare-signatures-for-transactions-error
|
[:toasts/upsert
|
||||||
:type :negative
|
{:id :prepare-signatures-for-transactions-error
|
||||||
:text (:message error)}]))}]]})))
|
:type :negative
|
||||||
|
:text (:message error)}]))]
|
||||||
|
(if signOnKeycard
|
||||||
|
{:fx [[:dispatch
|
||||||
|
[:standard-auth/authorize-with-keycard
|
||||||
|
{:on-complete #(rf/dispatch [:keycard/connect-and-sign-hashes
|
||||||
|
{:keycard-pin %
|
||||||
|
:address address
|
||||||
|
:hashes hashes
|
||||||
|
:on-success on-success
|
||||||
|
:on-failure on-error}])}]]]}
|
||||||
|
{:fx [[:effects.wallet/sign-transaction-hashes
|
||||||
|
{:hashes hashes
|
||||||
|
:address address
|
||||||
|
:password (security/safe-unmask-data sha3-pwd)
|
||||||
|
:on-success on-success
|
||||||
|
:on-error on-error}]]}))))
|
||||||
|
|
||||||
(rf/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:wallet/send-router-transactions-with-signatures
|
:wallet/send-router-transactions-with-signatures
|
||||||
|
@ -678,6 +694,7 @@
|
||||||
:params [{:uuid (get-in transaction-for-signing [:sendDetails :uuid])
|
:params [{:uuid (get-in transaction-for-signing [:sendDetails :uuid])
|
||||||
:signatures signatures-map}]
|
:signatures signatures-map}]
|
||||||
:on-success (fn []
|
:on-success (fn []
|
||||||
|
(rf/dispatch [:wallet/clean-send-data])
|
||||||
(rf/dispatch [:hide-bottom-sheet]))
|
(rf/dispatch [:hide-bottom-sheet]))
|
||||||
:on-error (fn [error]
|
:on-error (fn [error]
|
||||||
(log/error "failed to send router transactions with signatures"
|
(log/error "failed to send router transactions with signatures"
|
||||||
|
|
|
@ -84,39 +84,40 @@
|
||||||
[{:keys [network-values token-symbol on-press on-long-press receiver? loading-routes?
|
[{:keys [network-values token-symbol on-press on-long-press receiver? loading-routes?
|
||||||
token-not-supported-in-receiver-networks?]}]
|
token-not-supported-in-receiver-networks?]}]
|
||||||
[rn/view
|
[rn/view
|
||||||
(map-indexed (fn [index
|
(doall
|
||||||
{chain-id :chain-id
|
(map-indexed (fn [index
|
||||||
network-value-type :type
|
{chain-id :chain-id
|
||||||
total-amount :total-amount}]
|
network-value-type :type
|
||||||
(let [status (cond (and (= network-value-type :not-available)
|
total-amount :total-amount}]
|
||||||
loading-routes?
|
(let [status (cond (and (= network-value-type :not-available)
|
||||||
token-not-supported-in-receiver-networks?)
|
loading-routes?
|
||||||
:loading
|
token-not-supported-in-receiver-networks?)
|
||||||
(= network-value-type :not-available)
|
:loading
|
||||||
:disabled
|
(= network-value-type :not-available)
|
||||||
:else network-value-type)
|
:disabled
|
||||||
amount-formatted (-> (rf/sub [:wallet/send-amount-fixed total-amount])
|
:else network-value-type)
|
||||||
(str " " token-symbol))]
|
amount-formatted (-> (rf/sub [:wallet/send-amount-fixed total-amount])
|
||||||
[rn/view
|
(str " " token-symbol))]
|
||||||
{:key (str (if receiver? "to" "from") "-" chain-id)
|
[rn/view
|
||||||
:style {:margin-top (if (pos? index) 11 7.5)}}
|
{:key (str (if receiver? "to" "from") "-" chain-id)
|
||||||
[quo/network-bridge
|
:style {:margin-top (if (pos? index) 11 7.5)}}
|
||||||
{:amount (if (= network-value-type :not-available)
|
[quo/network-bridge
|
||||||
(i18n/label :t/not-available)
|
{:amount (if (= network-value-type :not-available)
|
||||||
amount-formatted)
|
(i18n/label :t/not-available)
|
||||||
:network (network-utils/id->network chain-id)
|
amount-formatted)
|
||||||
:status status
|
:network (network-utils/id->network chain-id)
|
||||||
:on-press #(when (not loading-routes?)
|
:status status
|
||||||
(cond
|
:on-press #(when (not loading-routes?)
|
||||||
(= network-value-type :edit)
|
(cond
|
||||||
(open-preferences)
|
(= network-value-type :edit)
|
||||||
on-press (on-press chain-id total-amount)))
|
(open-preferences)
|
||||||
:on-long-press #(when (and (not loading-routes?) (not= status :disabled))
|
on-press (on-press chain-id total-amount)))
|
||||||
(cond
|
:on-long-press #(when (and (not loading-routes?) (not= status :disabled))
|
||||||
(= network-value-type :add)
|
(cond
|
||||||
(open-preferences)
|
(= network-value-type :add)
|
||||||
on-long-press (on-long-press chain-id total-amount)))}]]))
|
(open-preferences)
|
||||||
network-values)])
|
on-long-press (on-long-press chain-id total-amount)))}]]))
|
||||||
|
network-values))])
|
||||||
|
|
||||||
(defn render-network-links
|
(defn render-network-links
|
||||||
[{:keys [network-links sender-network-values]}]
|
[{:keys [network-links sender-network-values]}]
|
||||||
|
|
|
@ -268,8 +268,7 @@
|
||||||
:transaction-type transaction-type}]
|
:transaction-type transaction-type}]
|
||||||
(when (and (not loading-suggested-routes?) route (seq route))
|
(when (and (not loading-suggested-routes?) route (seq route))
|
||||||
[standard-auth/slide-button
|
[standard-auth/slide-button
|
||||||
{:keycard-supported? (get-in transaction-for-signing
|
{:keycard-supported? true
|
||||||
[:signingDetails :signOnKeycard])
|
|
||||||
:size :size-48
|
:size :size-48
|
||||||
:track-text (if (= transaction-type :tx/bridge)
|
:track-text (if (= transaction-type :tx/bridge)
|
||||||
(i18n/label :t/slide-to-bridge)
|
(i18n/label :t/slide-to-bridge)
|
||||||
|
|
Loading…
Reference in New Issue