fix: issues after endpoints update

This commit is contained in:
Cristian Lungu 2024-12-10 16:02:58 +02:00
parent 5d9c6e6215
commit 1c42fa6039
No known key found for this signature in database
GPG Key ID: FBF86D630661E2CE
8 changed files with 34 additions and 222 deletions

View File

@ -259,15 +259,19 @@
(defn hash-typed-data
"used for keycard"
[data callback]
(log/debug "[native-module] hash-typed-data")
(.hashTypedData ^js (encryption) data callback))
([data]
(native-utils/promisify-native-module-call hash-typed-data data))
([data callback]
(log/debug "[native-module] hash-typed-data")
(.hashTypedData ^js (encryption) data callback)))
(defn hash-typed-data-v4
"used for keycard"
[data callback]
(log/debug "[native-module] hash-typed-data-v4")
(.hashTypedDataV4 ^js (encryption) data callback))
([data]
(native-utils/promisify-native-module-call hash-typed-data-v4 data))
([data callback]
(log/debug "[native-module] hash-typed-data-v4")
(.hashTypedDataV4 ^js (encryption) data callback)))
(defn send-transaction-with-signature
"used for keycard"

View File

@ -128,6 +128,5 @@
:effects.wallet/sign-message
(fn [{:keys [message address password on-success on-error]}]
(-> (wallet-rpc/sign-message message address (security/safe-unmask-data password))
(promesa/then :signature)
(promesa/then on-success)
(promesa/catch on-error))))

View File

@ -25,14 +25,6 @@
[message]
(rpc-events/call-async "wallet_hashMessageEIP191" true message))
(defn hash-typed-message-eip-712
[message chain-id legacy?]
(rpc-events/call-async "wallet_hashTypedData"
true
message
chain-id
legacy?))
(defn safe-sign-typed-data
[data address password chain-id legacy?]
(rpc-events/call-async "wallet_safeSignTypedDataForDApps"

View File

@ -1,17 +1,16 @@
(ns status-im.contexts.wallet.wallet-connect.events.effects
(:require
[native-module.core :as native-module]
[promesa.core :as promesa]
[react-native.wallet-connect :as wallet-connect]
[status-im.config :as config]
[status-im.constants :as constants]
[status-im.contexts.wallet.rpc :as wallet-rpc]
[status-im.contexts.wallet.wallet-connect.utils.sessions :as sessions]
[status-im.contexts.wallet.wallet-connect.utils.signing :as signing]
[status-im.contexts.wallet.wallet-connect.utils.transactions :as transactions]
[status-im.contexts.wallet.wallet-connect.utils.typed-data :as typed-data]
[utils.i18n :as i18n]
[utils.re-frame :as rf]
[utils.security.core :as security]))
[utils.transforms :as transforms]))
(rf/reg-fx
:effects.wallet-connect/init
@ -69,27 +68,14 @@
(rf/reg-fx
:effects.wallet-connect/hash-typed-data
(fn [{:keys [message chain-id legacy? on-success on-fail]}]
(-> (wallet-rpc/hash-typed-message-eip-712 message chain-id legacy?)
(fn [{:keys [message legacy? on-success on-fail]}]
(-> (if legacy?
(native-module/hash-typed-data message)
(native-module/hash-typed-data-v4 message))
(promesa/then (fn [response] (-> response transforms/json->clj :result)))
(promesa/then (partial rf/call-continuation on-success))
(promesa/catch (partial rf/call-continuation on-fail)))))
(rf/reg-fx
:effects.wallet-connect/sign-message
(fn [{:keys [password address data rpc-method on-success on-error]}]
(let [password (security/safe-unmask-data password)]
(-> (condp =
rpc-method
:personal-sign
(signing/personal-sign password address data)
:eth-sign
(signing/eth-sign password address data)
(signing/personal-sign password address data))
(promesa/then (partial rf/call-continuation on-success))
(promesa/catch (partial rf/call-continuation on-error))))))
(rf/reg-fx
:effects.wallet-connect/prepare-transaction
(fn [{:keys [tx chain-id on-success on-error]}]
@ -99,17 +85,6 @@
(promesa/then on-success)
(promesa/catch on-error))))
(rf/reg-fx
:effects.wallet-connect/sign-transaction
(fn [{:keys [password address chain-id tx-hash tx-args on-success on-error]}]
(-> (transactions/sign-transaction (security/safe-unmask-data password)
address
tx-hash
tx-args
chain-id)
(promesa/then (partial rf/call-continuation on-success))
(promesa/catch (partial rf/call-continuation on-error)))))
(rf/reg-fx
:effects.wallet-connect/send-transaction
(fn [{:keys [chain-id signature tx-args on-success on-error]}]
@ -119,17 +94,6 @@
(promesa/then (partial rf/call-continuation on-success))
(promesa/catch (partial rf/call-continuation on-error)))))
(rf/reg-fx
:effects.wallet-connect/sign-typed-data
(fn [{:keys [password address data version chain-id on-success on-error]}]
(-> (typed-data/sign (security/safe-unmask-data password)
address
data
chain-id
version)
(promesa/then (partial rf/call-continuation on-success))
(promesa/catch (partial rf/call-continuation on-error)))))
(rf/reg-fx
:effects.wallet-connect/respond-session-request
(fn [{:keys [web3-wallet topic id result error on-success on-error]}]

View File

@ -57,11 +57,11 @@
[:dispatch [:wallet-connect/process-personal-sign]])]}))))
(rf/reg-event-fx
:wallet-connect/store-sign-hash
(fn [{:keys [db]} [sign-hash]]
:wallet-connect/store-prepared-hash
(fn [{:keys [db]} [prepared-hash]]
{:db (assoc-in db
[:wallet-connect/current-request :sign-hash]
sign-hash)}))
[:wallet-connect/current-request :prepared-hash]
prepared-hash)}))
(rf/reg-event-fx
:wallet-connect/process-personal-sign
@ -72,30 +72,10 @@
[:wallet-connect/current-request]
assoc
:address (string/lower-case address)
;; TODO: DELETE
:raw-data raw-data
:display-data (or parsed-data raw-data))
:fx [[:effects.wallet-connect/hash-message
{:message raw-data
:on-success #(rf/dispatch [:wallet-connect/store-sign-hash %])
:on-fail #(rf/dispatch [:wallet-connect/on-processing-error %])}]
[:dispatch [:wallet-connect/show-request-modal]]]})))
;; DEPRECATE IF NOT WORKING ?!
(rf/reg-event-fx
:wallet-connect/process-eth-sign
(fn [{:keys [db]}]
(let [[address raw-data] (data-store/get-db-current-request-params db)
parsed-data (native-module/hex-to-utf8 raw-data)]
{:db (update-in db
[:wallet-connect/current-request]
assoc
:address (string/lower-case address)
:raw-data raw-data
:display-data (or parsed-data raw-data))
:fx [[:effects.wallet-connect/hash-message
{:message raw-data
:on-success #(rf/dispatch [:wallet-connect/store-sign-hash %])
:on-success #(rf/dispatch [:wallet-connect/store-prepared-hash %])
:on-fail #(rf/dispatch [:wallet-connect/on-processing-error %])}]
[:dispatch [:wallet-connect/show-request-modal]]]})))
@ -114,7 +94,7 @@
:transaction tx
:chain-id chain-id
:display-data display-data)
:fx [[:dispatch [:wallet-connect/store-sign-hash tx-hash]]]})))
:fx [[:dispatch [:wallet-connect/store-prepared-hash tx-hash]]]})))
(rf/reg-event-fx
:wallet-connect/process-eth-send-transaction
@ -177,10 +157,9 @@
:raw-data raw-data)
:fx [[:effects.wallet-connect/hash-typed-data
{:message raw-data
:chain-id session-chain-id
:legacy? (not= constants/wallet-connect-eth-sign-typed-v4-method
method)
:on-success #(rf/dispatch [:wallet-connect/store-sign-hash %])
:on-success #(rf/dispatch [:wallet-connect/store-prepared-hash %])
:on-fail #(rf/dispatch [:wallet-connect/on-processing-error %])}]
[:dispatch [:wallet-connect/show-request-modal]]]}))
(catch js/Error err

View File

@ -22,26 +22,10 @@
(contains? address))))))
(vals keypairs)))
(rf/reg-event-fx
:wallet-connect/sign-message-with-keycard
(fn [{:keys [db]} [{:keys [keycard-pin sign-data on-success on-fail]}]]
(let [address (get-in db [:wallet-connect/current-request :address])
{:keys [path key-uid]} (get-in db [:wallet :accounts address])]
;; NOTE: give time to the keycard-pin sheet to hide before showing the next one
{:fx [[:dispatch-later
{:ms 300
:dispatch [:keycard/sign-hash
{:key-uid key-uid
:pin keycard-pin
:path path
:hash (hex/normalize-hex sign-data)
:on-success on-success
:on-failure on-fail}]}]]})))
(rf/reg-event-fx
:wallet-connect/authorized-signing
(fn [{:keys [db]} [password]]
(let [sign-data (get-in db [:wallet-connect/current-request :sign-hash])
(let [prepared-hash (get-in db [:wallet-connect/current-request :prepared-hash])
address (get-in db [:wallet-connect/current-request :address])
keycard-sign? (-> (get-in db [:wallet :keypairs])
(keycard-account? address))
@ -51,18 +35,20 @@
{:fx [[:dispatch
[:standard-auth/authorize-with-keycard
{:on-complete (fn [pin]
(rf/dispatch [:hide-bottom-sheet])
(rf/dispatch [:wallet-connect/sign-message-with-keycard
(rf/dispatch [:keycard/connect-and-sign-hashes
{:keycard-pin pin
:sign-data sign-data
:on-success on-success
:on-fail on-fail}]))}]]]}
:address address
:hashes [prepared-hash]
:on-success (fn [signatures]
(rf/dispatch [:hide-bottom-sheet])
(-> signatures first :signature on-success))
:on-failure on-fail}]))}]]]}
{:fx [[:effects.wallet/sign-message
{:message sign-data
{:message prepared-hash
:address address
:password password
:on-success on-success
:on-fail on-fail}]]}))))
:on-error on-fail}]]}))))
(rf/reg-event-fx
:wallet-connect/respond
@ -88,64 +74,6 @@
#{constants/wallet-connect-eth-send-transaction-method}
[:dispatch [:wallet-connect/respond-send-transaction-data signature]])]}))))
(rf/reg-event-fx
:wallet-connect/respond-current-session
(fn [{:keys [db]} [signature]]
(let [event (get-in db [:wallet-connect/current-request :event])
method (data-store/get-request-method event)
screen (data-store/method-to-screen method)
expiry (get-in event [:params :request :expiryTimestamp])]
(if (uri/timestamp-expired? expiry)
{:fx [[:dispatch
[:toasts/upsert
{:type :negative
:text (i18n/label :t/wallet-connect-request-expired)}]]
[:dispatch [:dismiss-modal screen]]]}
{:fx [(condp = method
constants/wallet-connect-personal-sign-method
[:dispatch [:wallet-connect/respond-sign-message signature :personal-sign]]
constants/wallet-connect-eth-sign-method
[:dispatch [:wallet-connect/respond-sign-message signature :eth-sign]]
constants/wallet-connect-eth-send-transaction-method
[:dispatch [:wallet-connect/respond-send-transaction-data signature]]
constants/wallet-connect-eth-sign-transaction-method
[:dispatch [:wallet-connect/respond-sign-transaction-data signature]]
constants/wallet-connect-eth-sign-typed-method
[:dispatch [:wallet-connect/respond-sign-typed-data signature :v1]]
constants/wallet-connect-eth-sign-typed-v4-method
[:dispatch [:wallet-connect/respond-sign-typed-data signature :v4]])]}))))
(rf/reg-event-fx
:wallet-connect/respond-sign-message
(fn [{:keys [db]} [password rpc-method]]
(let [{:keys [address raw-data]} (get db :wallet-connect/current-request)]
{:fx [[:effects.wallet-connect/sign-message
{:password password
:address address
:data raw-data
:rpc-method rpc-method
:on-error [:wallet-connect/on-sign-error]
:on-success [:wallet-connect/finish-session-request]}]]})))
(rf/reg-event-fx
:wallet-connect/respond-sign-typed-data
(fn [{:keys [db]} [password typed-data-version]]
(let [{:keys [address raw-data event]} (get db :wallet-connect/current-request)
chain-id (get-in event [:params :chainId])]
{:fx [[:effects.wallet-connect/sign-typed-data
{:password password
:address address
:data raw-data
:chain-id chain-id
:version typed-data-version
:on-error [:wallet-connect/on-sign-error]
:on-success [:wallet-connect/finish-session-request]}]]})))
(rf/reg-event-fx
:wallet-connect/respond-send-transaction-data
(fn [{:keys [db]} [signature]]
@ -158,20 +86,6 @@
:on-error [:wallet-connect/on-sign-error]
:on-success [:wallet-connect/finish-session-request]}]]})))
(rf/reg-event-fx
:wallet-connect/respond-sign-transaction-data
(fn [{:keys [db]} [password]]
(let [{:keys [chain-id raw-data address]} (get db :wallet-connect/current-request)
{:keys [tx-hash tx-args]} raw-data]
{:fx [[:effects.wallet-connect/sign-transaction
{:password password
:address address
:chain-id chain-id
:tx-hash tx-hash
:tx-params tx-args
:on-error [:wallet-connect/on-sign-error]
:on-success [:wallet-connect/finish-session-request]}]]})))
(rf/reg-event-fx
:wallet-connect/on-sign-error
(fn [{:keys [db]} [error]]

View File

@ -1,24 +0,0 @@
(ns status-im.contexts.wallet.wallet-connect.utils.signing
(:require
[native-module.core :as native-module]
[promesa.core :as promesa]
[status-im.contexts.wallet.rpc :as wallet-rpc]
[status-im.contexts.wallet.wallet-connect.utils.data-store :as
data-store]
[utils.hex :as hex]
[utils.transforms :as transforms]))
(defn eth-sign
[password address data]
(-> {:data data
:account address
:password password}
transforms/clj->json
native-module/sign-message
(promesa/then data-store/extract-native-call-signature)))
(defn personal-sign
[password address data]
(-> (wallet-rpc/hash-message-eip-191 data)
(promesa/then #(wallet-rpc/sign-message % address password))
(promesa/then hex/prefix-hex)))

View File

@ -136,22 +136,6 @@
:suggested-fees suggested-fees
:estimated-time estimated-time}))
(defn sign-transaction
[password address tx-hash tx-args chain-id]
(promesa/let
[signature (wallet-rpc/sign-message tx-hash address password)
raw-tx (wallet-rpc/build-raw-transaction chain-id tx-args signature)]
raw-tx))
(defn send-transaction
[password address tx-hash tx-args chain-id]
(promesa/let
[signature (wallet-rpc/sign-message tx-hash address password)
tx (wallet-rpc/send-transaction-with-signature chain-id
tx-args
signature)]
tx))
(defn transactions->display-array
[data]
(remove (fn [[k v]]