[#17410] migrate status-im.ethereum.core (#17422)

This commit is contained in:
flexsurfer 2023-09-27 11:57:51 +02:00 committed by GitHub
parent 4152b9318b
commit a847f508f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
72 changed files with 479 additions and 571 deletions

View File

@ -136,11 +136,6 @@ quo.animated/re-timing
quo.design-system.colors/white quo.design-system.colors/white
quo.design-system.colors/black quo.design-system.colors/black
status-im.transport.core-test/messages status-im.transport.core-test/messages
status-im.ethereum.core/sidechain?
status-im.ethereum.core/network-with-upstream-rpc?
status-im.ethereum.core/current-address
status-im.ethereum.core/network->network-name
status-im.ethereum.core/estimate-gas
quo.core/animated-header quo.core/animated-header
quo.core/safe-area-provider quo.core/safe-area-provider
quo.core/safe-area-consumer quo.core/safe-area-consumer

View File

@ -470,7 +470,8 @@
(defn sha3 (defn sha3
[s] [s]
(log/debug "[native-module] sha3") (log/debug "[native-module] sha3")
(.sha3 ^js (status) s)) (when s
(.sha3 ^js (status) (str s))))
(defn utf8-to-hex (defn utf8-to-hex
[s] [s]
@ -491,8 +492,9 @@
(defn address? (defn address?
[address] [address]
(log/debug "[native-module] address?") (log/debug "[native-module] address?")
(let [result (.isAddress ^js (status) address)] (when address
(types/json->clj result))) (let [result (.isAddress ^js (status) address)]
(types/json->clj result))))
(defn to-checksum-address (defn to-checksum-address
[address] [address]

View File

@ -9,7 +9,6 @@
[status-im.browser.permissions :as browser.permissions] [status-im.browser.permissions :as browser.permissions]
[status-im.browser.webview-ref :as webview-ref] [status-im.browser.webview-ref :as webview-ref]
[status-im2.constants :as constants] [status-im2.constants :as constants]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.ens :as ens] [status-im.ethereum.ens :as ens]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.multiaccounts.update.core :as multiaccounts.update]
@ -25,7 +24,9 @@
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[utils.debounce :as debounce] [utils.debounce :as debounce]
[utils.security.core :as security])) [utils.security.core :as security]
[utils.ethereum.chain :as chain]
[utils.address :as address]))
(rf/defn update-browser-option (rf/defn update-browser-option
[{:keys [db]} option-key option-value] [{:keys [db]} option-key option-value]
@ -91,7 +92,7 @@
host (url/url-host current-url)] host (url/url-host current-url)]
(if (and (not resolved-url) (ens/is-valid-eth-name? host)) (if (and (not resolved-url) (ens/is-valid-eth-name? host))
{:db (update db :browser/options assoc :resolving? true) {:db (update db :browser/options assoc :resolving? true)
:browser/resolve-ens-contenthash {:chain-id (ethereum/chain-id db) :browser/resolve-ens-contenthash {:chain-id (chain/chain-id db)
:ens-name host :ens-name host
:cb resolve-ens-contenthash-callback}} :cb resolve-ens-contenthash-callback}}
{:db (update db :browser/options assoc :url (or resolved-url current-url) :resolving? false)})))) {:db (update db :browser/options assoc :url (or resolved-url current-url) :resolving? false)}))))
@ -352,12 +353,19 @@
:id (int id) :id (int id)
:result result}}}) :result result}}})
(defn utf8-to-hex
[s]
(let [hex (native-module/utf8-to-hex (str s))]
(if (empty? hex)
nil
hex)))
(defn normalize-message (defn normalize-message
"NOTE (andrey) there is no spec for this, so this implementation just to be compatible with MM" "NOTE (andrey) there is no spec for this, so this implementation just to be compatible with MM"
[message] [message]
(if (string/starts-with? message "0x") (if (string/starts-with? message "0x")
message message
(ethereum/utf8-to-hex message))) (utf8-to-hex message)))
(defn normalize-sign-message-params (defn normalize-sign-message-params
"NOTE (andrey) we need this function, because params may be mixed up" "NOTE (andrey) we need this function, because params may be mixed up"
@ -365,9 +373,9 @@
(let [[first-param second-param] params] (let [[first-param second-param] params]
(when (and (string? first-param) (string? second-param)) (when (and (string? first-param) (string? second-param))
(cond (cond
(ethereum/address? first-param) (address/address? first-param)
[first-param (if typed? second-param (normalize-message second-param))] [first-param (if typed? second-param (normalize-message second-param))]
(ethereum/address? second-param) (address/address? second-param)
[second-param (if typed? first-param (normalize-message first-param))])))) [second-param (if typed? first-param (normalize-message first-param))]))))
(rf/defn send-to-bridge (rf/defn send-to-bridge

View File

@ -2,9 +2,9 @@
;(`wallet_switchEthereumChain`) ;(`wallet_switchEthereumChain`)
(ns status-im.browser.eip3326 (ns status-im.browser.eip3326
(:require [status-im2.constants :as constants] (:require [status-im2.constants :as constants]
[status-im.ethereum.core :as ethereum]
[status-im.ui.screens.browser.eip3326.sheet :as sheet] [status-im.ui.screens.browser.eip3326.sheet :as sheet]
[utils.re-frame :as rf])) [utils.re-frame :as rf]
[utils.ethereum.chain :as chain]))
(rf/defn deny-permission (rf/defn deny-permission
{:events [:eip3326.ui/dapp-permission-denied]} {:events [:eip3326.ui/dapp-permission-denied]}
@ -20,8 +20,8 @@
[{:keys [db] :as cofx} dapp-name id message-id {:keys [chainId] :as params}] [{:keys [db] :as cofx} dapp-name id message-id {:keys [chainId] :as params}]
(let [target-chain-id (js/parseInt chainId 16) (let [target-chain-id (js/parseInt chainId 16)
networks (vals (get-in db [:networks/networks])) networks (vals (get-in db [:networks/networks]))
exist-chain-ids (set (map ethereum/network->chain-id networks)) exist-chain-ids (set (map chain/network->chain-id networks))
current-chain-id (ethereum/chain-id db)] current-chain-id (chain/chain-id db)]
(if (exist-chain-ids target-chain-id) (if (exist-chain-ids target-chain-id)
(if (= current-chain-id target-chain-id) (if (= current-chain-id target-chain-id)
{:browser/send-to-bridge {:type constants/web3-send-async-callback {:browser/send-to-bridge {:type constants/web3-send-async-callback
@ -29,10 +29,10 @@
:result {:jsonrpc "2.0" :result {:jsonrpc "2.0"
:id (int id) :id (int id)
:result nil}}} :result nil}}}
(let [target-network (first (filter #(= (ethereum/network->chain-id %1) target-chain-id) (let [target-network (first (filter #(= (chain/network->chain-id %1) target-chain-id)
networks)) networks))
target-network-id (:id target-network) target-network-id (:id target-network)
current-network (ethereum/current-network db) current-network (chain/current-network db)
network-from (:name current-network) network-from (:name current-network)
network-to (:name target-network) network-to (:name target-network)
params (assoc params params (assoc params

View File

@ -1,7 +1,7 @@
(ns status-im.commands.core (ns status-im.commands.core
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum] [utils.re-frame :as rf]
[utils.re-frame :as rf])) [status-im.wallet.utils :as wallet.utils]))
(rf/defn handle-prepare-accept-request-address-for-transaction (rf/defn handle-prepare-accept-request-address-for-transaction
{:events [::prepare-accept-request-address-for-transaction]} {:events [::prepare-accept-request-address-for-transaction]}
@ -9,7 +9,8 @@
{:db (assoc db {:db (assoc db
:commands/select-account :commands/select-account
{:message message {:message message
:from (ethereum/get-default-account (:profile/wallet-accounts db))}) :from (wallet.utils/get-default-account (:profile/wallet-accounts
db))})
:show-select-acc-sheet nil}) :show-select-acc-sheet nil})
(rf/defn set-selected-account (rf/defn set-selected-account

View File

@ -2,8 +2,8 @@
(:require [clojure.set :as set] (:require [clojure.set :as set]
[clojure.string :as string] [clojure.string :as string]
[status-im2.constants :as constants] [status-im2.constants :as constants]
[status-im.ethereum.core :as ethereum] [status-im.utils.gfycat.core :as gfycat]
[status-im.utils.gfycat.core :as gfycat])) [utils.address :as address]))
(defn public-key->new-contact (defn public-key->new-contact
[public-key] [public-key]
@ -31,7 +31,7 @@
(defn- contact-by-address (defn- contact-by-address
[[addr contact] address] [[addr contact] address]
(when (ethereum/address= addr address) (when (address/address= addr address)
contact)) contact))
(defn find-contact-by-address (defn find-contact-by-address

View File

@ -1,6 +1,6 @@
(ns status-im.data-store.settings (ns status-im.data-store.settings
(:require [status-im.data-store.visibility-status-updates :as visibility-status-updates] (:require [status-im.data-store.visibility-status-updates :as visibility-status-updates]
[status-im.ethereum.eip55 :as eip55] [utils.ethereum.eip.eip55 :as eip55]
[status-im2.config :as config] [status-im2.config :as config]
[clojure.set :as set])) [clojure.set :as set]))

View File

@ -5,8 +5,7 @@
[clojure.string :as string] [clojure.string :as string]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.bottom-sheet.events :as bottom-sheet] [status-im.bottom-sheet.events :as bottom-sheet]
[status-im.ethereum.core :as ethereum] [utils.ethereum.eip.eip55 :as eip55]
[status-im.ethereum.eip55 :as eip55]
[status-im.ethereum.ens :as ens] [status-im.ethereum.ens :as ens]
[status-im.ethereum.stateofus :as stateofus] [status-im.ethereum.stateofus :as stateofus]
[status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.multiaccounts.update.core :as multiaccounts.update]
@ -15,7 +14,9 @@
[status-im.utils.random :as random] [status-im.utils.random :as random]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im2.constants :as constants] [status-im2.constants :as constants]
[taoensso.timbre :as log])) [taoensso.timbre :as log]
[utils.ethereum.chain :as chain]
[status-im.wallet.utils :as wallet.utils]))
(defn fullname (defn fullname
[custom-domain? username] [custom-domain? username]
@ -102,7 +103,7 @@
[{:keys [db] :as cofx} custom-domain? username redirect-to-summary? connected?] [{:keys [db] :as cofx} custom-domain? username redirect-to-summary? connected?]
(let [name (fullname custom-domain? username) (let [name (fullname custom-domain? username)
names (get-in db [:ens/names] []) names (get-in db [:ens/names] [])
chain-id (ethereum/chain-id db)] chain-id (chain/chain-id db)]
(rf/merge cofx (rf/merge cofx
(cond-> {:dispatch-n [[:ens/update-usernames [{:username name :chain-id chain-id}]]]} (cond-> {:dispatch-n [[:ens/update-usernames [{:username name :chain-id chain-id}]]]}
connected? (assoc :json-rpc/call connected? (assoc :json-rpc/call
@ -124,9 +125,9 @@
{:events [::set-pub-key]} {:events [::set-pub-key]}
[{:keys [db]}] [{:keys [db]}]
(let [{:keys [username address custom-domain?]} (:ens/registration db) (let [{:keys [username address custom-domain?]} (:ens/registration db)
address (or address (ethereum/default-address db)) address (or address (wallet.utils/default-address db))
{:keys [public-key]} (:profile/profile db) {:keys [public-key]} (:profile/profile db)
chain-id (ethereum/chain-id db) chain-id (chain/chain-id db)
username (fullname custom-domain? username)] username (fullname custom-domain? username)]
{:db (assoc-in db [:ens/registration :action] constants/ens-action-type-set-pub-key) {:db (assoc-in db [:ens/registration :action] constants/ens-action-type-set-pub-key)
:json-rpc/call [{:method "ens_setPubKeyPrepareTx" :json-rpc/call [{:method "ens_setPubKeyPrepareTx"
@ -192,7 +193,7 @@
(let [{:keys [username]} (let [{:keys [username]}
(:ens/registration db) (:ens/registration db)
{:keys [public-key]} (:profile/profile db) {:keys [public-key]} (:profile/profile db)
chain-id (ethereum/chain-id db)] chain-id (chain/chain-id db)]
{:db (assoc-in db [:ens/registration :action] constants/ens-action-type-register) {:db (assoc-in db [:ens/registration :action] constants/ens-action-type-register)
:json-rpc/call [{:method "ens_registerPrepareTx" :json-rpc/call [{:method "ens_registerPrepareTx"
:params [chain-id {:from address} username public-key] :params [chain-id {:from address} username public-key]
@ -225,6 +226,12 @@
:searching) :searching)
:else :invalid)) :else :invalid))
(defn addresses-without-watch
[db]
(into #{}
(remove #(= (:type %) :watch)
(map #(eip55/address->checksum (:address %)) (get db :profile/wallet-accounts)))))
;;NOTE we want to handle only last resolve ;;NOTE we want to handle only last resolve
(def resolve-last-id (atom nil)) (def resolve-last-id (atom nil))
@ -243,8 +250,8 @@
(when (= state :searching) (when (= state :searching)
(let [{:profile/keys [profile]} db (let [{:profile/keys [profile]} db
{:keys [public-key]} profile {:keys [public-key]} profile
addresses (ethereum/addresses-without-watch db) addresses (addresses-without-watch db)
chain-id (ethereum/chain-id db)] chain-id (chain/chain-id db)]
{::resolve-owner [chain-id {::resolve-owner [chain-id
(fullname custom-domain? username) (fullname custom-domain? username)
#(on-resolve-owner #(on-resolve-owner
@ -266,8 +273,8 @@
;; we reset navigation so that navigate back doesn't return ;; we reset navigation so that navigate back doesn't return
;; into the registration flow ;; into the registration flow
(navigation/navigate-back-to :my-profile) (navigation/navigate-back-to :my-profile)
(navigation/navigate-to :ens-main {}) (navigation/navigate-to :ens-main {})))
))
(rf/defn switch-domain-type (rf/defn switch-domain-type
{:events [::switch-domain-type]} {:events [::switch-domain-type]}
@ -320,7 +327,7 @@
(rf/defn navigate-to-name (rf/defn navigate-to-name
{:events [::navigate-to-name]} {:events [::navigate-to-name]}
[{:keys [db] :as cofx} username] [{:keys [db] :as cofx} username]
(let [chain-id (ethereum/chain-id db)] (let [chain-id (chain/chain-id db)]
(rf/merge cofx (rf/merge cofx
{::get-expiration-time {::get-expiration-time
[chain-id [chain-id

View File

@ -1,21 +0,0 @@
(ns status-im.ethereum.contracts
(:require [status-im.ethereum.core :as ethereum]))
(def contracts
{:status/snt
{:mainnet "0x744d70fdbe2ba4cf95131626614a1763df805b9e"
:goerli "0x3D6AFAA395C31FCd391fE3D562E75fe9E8ec7E6a"}
:status/stickers
{:mainnet "0x0577215622f43a39f4bc9640806dfea9b10d2a36"
:goerli "0x07f7CB0C0a4ab3e0999AfE8b3997Da34880f05d0"}
:status/sticker-market
{:mainnet "0x12824271339304d3a9f7e096e62a2a7e73b4a7e7"
:goerli "0xf1E149A7DF70D5Ff1E265daAa738d785D3274717"}
:status/sticker-pack
{:mainnet "0x110101156e8F0743948B2A61aFcf3994A8Fb172e"
:goerli "0x8D3fD2EA24bD53a8Bd2b1026727db8bbe9A8C8Af"}})
(defn get-address
[db contract]
(let [chain-keyword (ethereum/chain-keyword db)]
(get-in contracts [contract chain-keyword])))

View File

@ -1,202 +0,0 @@
(ns status-im.ethereum.core
(:require [clojure.string :as string]
[status-im.ethereum.eip55 :as eip55]
[native-module.core :as native-module]))
(defn sha3
[s]
(when s
(native-module/sha3 (str s))))
(defn utf8-to-hex
[s]
(let [hex (native-module/utf8-to-hex (str s))]
(if (empty? hex)
nil
hex)))
(defn hex-to-utf8
[s]
(let [utf8 (native-module/hex-to-utf8 s)]
(if (empty? utf8)
nil
utf8)))
(def BSC-mainnet-chain-id 56)
(def BSC-testnet-chain-id 97)
;; IDs standardized in https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md#list-of-chain-ids
(def chains
{:mainnet {:id 1 :name "Mainnet"}
:xdai {:id 100 :name "xDai"}
:goerli {:id 5 :name "Goerli"}
:bsc {:id BSC-mainnet-chain-id
:name "BSC"}
:bsc-testnet {:id BSC-testnet-chain-id
:name "BSC tetnet"}})
(defn chain-id->chain-keyword
[i]
(or (some #(when (= i (:id (val %))) (key %)) chains)
:custom))
(defn chain-id->chain-name
[i]
(or (some #(when (= i (:id (val %))) (:name (val %))) chains)
:custom))
(defn chain-keyword->chain-id
[k]
(get-in chains [k :id]))
(defn chain-keyword->snt-symbol
[k]
(case k
:mainnet :SNT
:STT))
(defn testnet?
[id]
(contains? #{(chain-keyword->chain-id :goerli)
(chain-keyword->chain-id :bsc-testnet)}
id))
(defn sidechain?
[id]
(contains? #{(chain-keyword->chain-id :xdai)
(chain-keyword->chain-id :bsc)}
id))
(defn network-with-upstream-rpc?
[network]
(get-in network [:config :UpstreamConfig :Enabled]))
(def hex-prefix "0x")
(defn normalized-hex
[hex]
(when hex
(if (string/starts-with? hex hex-prefix)
hex
(str hex-prefix hex))))
(defn current-address
[db]
(-> (get-in db [:profile/profile :address])
normalized-hex))
(defn get-default-account
[accounts]
(some #(when (:wallet %) %) accounts))
(defn default-address
[db]
(-> (get db :profile/wallet-accounts)
get-default-account
:address))
(defn addresses-without-watch
[db]
(into #{}
(remove #(= (:type %) :watch)
(map #(eip55/address->checksum (:address %)) (get db :profile/wallet-accounts)))))
(defn naked-address
[s]
(when s
(string/replace s hex-prefix "")))
(def public-key-length 128)
(defn coordinates
[public-key]
(when-let [hex (naked-address public-key)]
(when (= public-key-length (count (subs hex 2)))
{:x (normalized-hex (subs hex 2 66))
:y (normalized-hex (subs hex 66))})))
(defn address?
[s]
(when s
(native-module/address? s)))
(defn network->chain-id
[network]
(get-in network [:config :NetworkId]))
(defn network->chain-keyword
[network]
(chain-id->chain-keyword (network->chain-id network)))
(defn current-network
[db]
(let [networks (get db :networks/networks)
network-id (get db :networks/current-network)]
(get networks network-id)))
(defn binance-chain-id?
[chain-id]
(or (= BSC-mainnet-chain-id chain-id)
(= BSC-testnet-chain-id chain-id)))
(defn binance-chain?
[db]
(-> db
current-network
network->chain-id
binance-chain-id?))
(def custom-rpc-node-id-len 45)
(defn custom-rpc-node?
[{:keys [id]}]
(= custom-rpc-node-id-len (count id)))
(defn network->network-name
[network]
(chain-id->chain-name (network->chain-id network)))
(defn network->chain-name
[network]
(-> network
network->chain-keyword
name))
(defn get-current-network
[m]
(get (:networks/networks m) (:networks/current-network m)))
(defn chain-keyword
[db]
(network->chain-keyword (get-current-network db)))
(defn chain-id
[db]
(network->chain-id (get-current-network db)))
(defn snt-symbol
[db]
(chain-keyword->snt-symbol (chain-keyword db)))
(defn address=
[address1 address2]
(and address1
address2
(= (string/lower-case (normalized-hex address1))
(string/lower-case (normalized-hex address2)))))
(defn public-key->address
[public-key]
(let [length (count public-key)
normalized-key (case length
132 (str "0x" (subs public-key 4))
130 public-key
128 (str "0x" public-key)
nil)]
(when normalized-key
(subs (sha3 normalized-key) 26))))
(defn hex->text
"Converts a hexstring to UTF8 text."
[data]
(or (hex-to-utf8 data) data))

View File

@ -1,16 +0,0 @@
(ns status-im.ethereum.core-test
(:require [cljs.test :refer-macros [deftest is]]
[status-im.ethereum.core :as ethereum]))
(deftest chain-id->chain-keyword
(is (= (ethereum/chain-id->chain-keyword 1) :mainnet))
(is (= (ethereum/chain-id->chain-keyword 5) :goerli))
(is (= (ethereum/chain-id->chain-keyword 5777) :custom)))
(deftest coordinates
(is
(=
{:x "0x46fa4851f3cccd01e3b8d96c130c00bf812502354939eacf06a68fa519ebcbd1"
:y "0xeb08bebe7403856c0d9686210b9b2e324aa0179747bbba56d53f304a002f31c3"}
(ethereum/coordinates
"0x0446fa4851f3cccd01e3b8d96c130c00bf812502354939eacf06a68fa519ebcbd1eb08bebe7403856c0d9686210b9b2e324aa0179747bbba56d53f304a002f31c3"))))

View File

@ -5,10 +5,11 @@
e.g. ethereum:0x1234@1/transfer?to=0x5678&value=1e18&gas=5000" e.g. ethereum:0x1234@1/transfer?to=0x5678&value=1e18&gas=5000"
(:require [clojure.string :as string] (:require [clojure.string :as string]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.ens :as ens] [status-im.ethereum.ens :as ens]
[status-im.ethereum.tokens :as tokens] [status-im.ethereum.tokens :as tokens]
[utils.money :as money])) [utils.money :as money]
[utils.ethereum.chain :as chain]
[utils.address :as address]))
(def scheme "ethereum") (def scheme "ethereum")
(def scheme-separator ":") (def scheme-separator ":")
@ -64,16 +65,16 @@
Invalid URI will be parsed as `nil`." Invalid URI will be parsed as `nil`."
[s] [s]
(when (string? s) (when (string? s)
(if (ethereum/address? s) (if (address/address? s)
{:address s} {:address s}
(let [[_ authority-path query] (re-find uri-pattern s)] (let [[_ authority-path query] (re-find uri-pattern s)]
(when authority-path (when authority-path
(let [[_ raw-address chain-id function-name] (re-find authority-path-pattern authority-path)] (let [[_ raw-address chain-id function-name] (re-find authority-path-pattern authority-path)]
(when (or (or (ens/is-valid-eth-name? raw-address) (ethereum/address? raw-address)) (when (or (or (ens/is-valid-eth-name? raw-address) (address/address? raw-address))
(when (string/starts-with? raw-address "pay-") (when (string/starts-with? raw-address "pay-")
(let [pay-address (string/replace-first raw-address "pay-" "")] (let [pay-address (string/replace-first raw-address "pay-" "")]
(or (ens/is-valid-eth-name? pay-address) (or (ens/is-valid-eth-name? pay-address)
(ethereum/address? pay-address))))) (address/address? pay-address)))))
(let [address (if (string/starts-with? raw-address "pay-") (let [address (if (string/starts-with? raw-address "pay-")
(string/replace-first raw-address "pay-" "") (string/replace-first raw-address "pay-" "")
raw-address)] raw-address)]
@ -81,12 +82,12 @@
(let [contract-address (get-in arguments [:function-arguments :address])] (let [contract-address (get-in arguments [:function-arguments :address])]
(if-not (or (not contract-address) (if-not (or (not contract-address)
(or (ens/is-valid-eth-name? contract-address) (or (ens/is-valid-eth-name? contract-address)
(ethereum/address? contract-address))) (address/address? contract-address)))
nil nil
(merge {:address address (merge {:address address
:chain-id (if chain-id :chain-id (if chain-id
(js/parseInt chain-id) (js/parseInt chain-id)
(ethereum/chain-keyword->chain-id :mainnet))} (chain/chain-keyword->chain-id :mainnet))}
arguments)))))))))))) arguments))))))))))))
(defn parse-eth-value (defn parse-eth-value
@ -124,12 +125,12 @@
"Generate a EIP 681 URI based on `address` and a map (keywords / {bignumbers/strings} ) of extra properties. "Generate a EIP 681 URI based on `address` and a map (keywords / {bignumbers/strings} ) of extra properties.
No validation of address format is performed." No validation of address format is performed."
[address {:keys [chain-id function-name function-arguments] :as m}] [address {:keys [chain-id function-name function-arguments] :as m}]
(when (ethereum/address? address) (when (address/address? address)
(let [parameters (dissoc (into {} (filter second m)) :chain-id)] ;; filter nil values (let [parameters (dissoc (into {} (filter second m)) :chain-id)] ;; filter nil values
(str scheme (str scheme
scheme-separator scheme-separator
address address
(when (and chain-id (not= chain-id (ethereum/chain-keyword->chain-id :mainnet))) (when (and chain-id (not= chain-id (chain/chain-keyword->chain-id :mainnet)))
;; Add chain-id if specified and is not main-net ;; Add chain-id if specified and is not main-net
(str chain-id-separator chain-id)) (str chain-id-separator chain-id))
(when-not (empty? parameters) (when-not (empty? parameters)

View File

@ -1,5 +1,5 @@
(ns status-im.ethereum.eip681-test (ns status-im.ethereum.eip681-test
(:require [cljs.test :refer-macros [deftest is] :as test] (:require [cljs.test :refer-macros [deftest is]]
[status-im.ethereum.eip681 :as eip681] [status-im.ethereum.eip681 :as eip681]
[utils.money :as money])) [utils.money :as money]))

View File

@ -189,10 +189,6 @@
(-> (sanitize-passphrase s) (-> (sanitize-passphrase s)
(string/split #" ")))) (string/split #" "))))
(defn words->passphrase
[v]
(string/join " " v))
(def valid-word-counts #{12 15 18 21 24}) (def valid-word-counts #{12 15 18 21 24})
(defn valid-word-counts? (defn valid-word-counts?

View File

@ -1,6 +1,5 @@
(ns status-im.ethereum.stateofus (ns status-im.ethereum.stateofus
(:require [clojure.string :as string] (:require [clojure.string :as string]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.ens :as ens] [status-im.ethereum.ens :as ens]
[status-im2.config :as config])) [status-im2.config :as config]))
@ -33,23 +32,9 @@
(when config/test-stateofus? (when config/test-stateofus?
{:goerli "0xD1f7416F91E7Eb93dD96A61F12FC092aD6B67B11"}))) {:goerli "0xD1f7416F91E7Eb93dD96A61F12FC092aD6B67B11"})))
(def registrars-cache (atom {}))
(defn get-registrar
[chain callback]
(if-let [contract (get @registrars-cache chain)]
(callback contract)
(ens/owner
(ethereum/chain-keyword->chain-id chain)
domain
(fn [addr]
(let [addr (or addr (get old-registrars chain))]
(swap! registrars-cache assoc chain addr)
(callback addr))))))
(defn get-cached-registrar (defn get-cached-registrar
[chain] [chain]
(get @registrars-cache chain (get old-registrars chain))) (get old-registrars chain))
(defn lower-case? (defn lower-case?
[s] [s]

View File

@ -1,5 +1,5 @@
(ns status-im.ethereum.subscriptions (ns status-im.ethereum.subscriptions
(:require [status-im.ethereum.eip55 :as eip55] (:require [utils.ethereum.eip.eip55 :as eip55]
[status-im.ethereum.transactions.core :as transactions] [status-im.ethereum.transactions.core :as transactions]
[utils.re-frame :as rf] [utils.re-frame :as rf]
[status-im.wallet.core :as wallet.core] [status-im.wallet.core :as wallet.core]

View File

@ -1,6 +1,6 @@
(ns status-im.ethereum.tokens (ns status-im.ethereum.tokens
(:require [clojure.string :as string] (:require [clojure.string :as string]
[status-im.ethereum.core :as ethereum]) [utils.ethereum.chain :as chain])
(:require-macros [status-im.ethereum.macros :as ethereum.macros :refer [resolve-icons]])) (:require-macros [status-im.ethereum.macros :as ethereum.macros :refer [resolve-icons]]))
(def default-native-currency (def default-native-currency
@ -42,7 +42,7 @@
(defn native-currency (defn native-currency
[{sym :symbol :as current-network}] [{sym :symbol :as current-network}]
(let [chain (ethereum/network->chain-keyword current-network)] (let [chain (chain/network->chain-keyword current-network)]
(get all-native-currencies chain (default-native-currency sym)))) (get all-native-currencies chain (default-native-currency sym))))
(defn ethereum? (defn ethereum?

View File

@ -1,24 +1,24 @@
(ns status-im.ethereum.transactions.core (ns status-im.ethereum.transactions.core
(:require [cljs.spec.alpha :as spec] (:require [cljs.spec.alpha :as spec]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.decode :as decode] [status-im.ethereum.decode :as decode]
[status-im.ethereum.eip55 :as eip55] [utils.ethereum.eip.eip55 :as eip55]
[status-im.ethereum.encode :as encode] [status-im.ethereum.encode :as encode]
[utils.re-frame :as rf] [utils.re-frame :as rf]
[status-im.utils.mobile-sync :as utils.mobile-sync] [status-im.utils.mobile-sync :as utils.mobile-sync]
[status-im.wallet.core :as wallet] [status-im.wallet.core :as wallet]
[status-im2.common.json-rpc.events :as json-rpc] [status-im2.common.json-rpc.events :as json-rpc]
[taoensso.timbre :as log])) [taoensso.timbre :as log]
[utils.ethereum.chain :as chain]))
(def confirmations-count-threshold 12) (def confirmations-count-threshold 12)
(def etherscan-supported? (def etherscan-supported?
#{(ethereum/chain-keyword->chain-id :mainnet) #{(chain/chain-keyword->chain-id :mainnet)
(ethereum/chain-keyword->chain-id :goerli)}) (chain/chain-keyword->chain-id :goerli)})
(def binance-mainnet-chain-id (ethereum/chain-keyword->chain-id :bsc)) (def binance-mainnet-chain-id (chain/chain-keyword->chain-id :bsc))
(def binance-testnet-chain-id (ethereum/chain-keyword->chain-id :bsc-testnet)) (def binance-testnet-chain-id (chain/chain-keyword->chain-id :bsc-testnet))
(def network->subdomain {5 "goerli"}) (def network->subdomain {5 "goerli"})

View File

@ -3,7 +3,6 @@
[clojure.string :as string] [clojure.string :as string]
[day8.re-frame.test :as rf-test] [day8.re-frame.test :as rf-test]
[re-frame.core :as rf] [re-frame.core :as rf]
[status-im.ethereum.core :as ethereum]
status-im.events status-im.events
status-im2.events status-im2.events
[status-im.multiaccounts.logout.core :as logout] [status-im.multiaccounts.logout.core :as logout]
@ -12,7 +11,8 @@
status-im2.navigation.core status-im2.navigation.core
status-im2.subs.root ; so integration tests can run independently status-im2.subs.root ; so integration tests can run independently
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im2.constants :as constants])) [status-im2.constants :as constants]
[native-module.core :as native-module]))
(def password "testabc") (def password "testabc")
@ -52,7 +52,7 @@
[] []
(rf/dispatch-sync [:wallet.accounts/start-adding-new-account {:type :generate}]) (rf/dispatch-sync [:wallet.accounts/start-adding-new-account {:type :generate}])
(rf/dispatch-sync [:set-in [:add-account :account :name] account-name]) (rf/dispatch-sync [:set-in [:add-account :account :name] account-name])
(rf/dispatch [:wallet.accounts/add-new-account (ethereum/sha3 password)])) (rf/dispatch [:wallet.accounts/add-new-account (native-module/sha3 password)]))
(defn assert-new-account-created (defn assert-new-account-created
[] []

View File

@ -2,7 +2,6 @@
(:require [clojure.string :as string] (:require [clojure.string :as string]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.bottom-sheet.events :as bottom-sheet] [status-im.bottom-sheet.events :as bottom-sheet]
[status-im.ethereum.core :as ethereum]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[status-im.keycard.nfc :as nfc] [status-im.keycard.nfc :as nfc]
[status-im.popover.core :as popover] [status-im.popover.core :as popover]
@ -13,7 +12,8 @@
[react-native.platform :as platform] [react-native.platform :as platform]
[status-im.utils.deprecated-types :as types] [status-im.utils.deprecated-types :as types]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[taoensso.timbre :as log])) [taoensso.timbre :as log]
[utils.address :as address]))
(def default-pin "000000") (def default-pin "000000")
@ -78,7 +78,7 @@
(when key-uid (when key-uid
(->> (:profile/profiles-overview db) (->> (:profile/profiles-overview db)
vals vals
(filter #(= (ethereum/normalized-hex key-uid) (:key-uid %))) (filter #(= (address/normalized-hex key-uid) (:key-uid %)))
first))) first)))
(defn get-pairing (defn get-pairing
@ -354,7 +354,7 @@
:puk-retry-counter 5 :puk-retry-counter 5
:pin-retry-counter 3) :pin-retry-counter 3)
(assoc-in [:keycard :profile/profile] (assoc-in [:keycard :profile/profile]
(update account-data :whisper-public-key ethereum/normalized-hex)) (update account-data :whisper-public-key address/normalized-hex))
(assoc-in [:keycard :flow] nil) (assoc-in [:keycard :flow] nil)
(update :profile/login assoc (update :profile/login assoc
:password encryption-public-key :password encryption-public-key

View File

@ -1,6 +1,5 @@
(ns status-im.keycard.login (ns status-im.keycard.login
(:require [status-im.bottom-sheet.events :as bottom-sheet] (:require [status-im.bottom-sheet.events :as bottom-sheet]
[status-im.ethereum.core :as ethereum]
[status-im.keycard.common :as common] [status-im.keycard.common :as common]
status-im.keycard.fx status-im.keycard.fx
[status-im.keycard.onboarding :as onboarding] [status-im.keycard.onboarding :as onboarding]
@ -9,7 +8,8 @@
[utils.re-frame :as rf] [utils.re-frame :as rf]
[status-im.utils.deprecated-types :as types] [status-im.utils.deprecated-types :as types]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[taoensso.timbre :as log])) [taoensso.timbre :as log]
[utils.address :as address]))
(rf/defn login-got-it-pressed (rf/defn login-got-it-pressed
{:events [:keycard.login.pin.ui/got-it-pressed {:events [:keycard.login.pin.ui/got-it-pressed
@ -162,7 +162,7 @@
(assoc-in [:keycard :pin :status] nil) (assoc-in [:keycard :pin :status] nil)
(assoc-in [:keycard :pin :login] []) (assoc-in [:keycard :pin :login] [])
(assoc-in [:keycard :profile/profile] (assoc-in [:keycard :profile/profile]
(update account-data :whisper-public-key ethereum/normalized-hex)) (update account-data :whisper-public-key address/normalized-hex))
(assoc-in [:keycard :flow] nil) (assoc-in [:keycard :flow] nil)
(update :profile/login assoc (update :profile/login assoc
:password encryption-public-key :password encryption-public-key

View File

@ -2,12 +2,12 @@
(:require ["react-native" :as rn] (:require ["react-native" :as rn]
["react-native-status-keycard" :default status-keycard] ["react-native-status-keycard" :default status-keycard]
[clojure.string :as string] [clojure.string :as string]
[status-im.ethereum.core :as ethereum]
[status-im.keycard.keycard :as keycard] [status-im.keycard.keycard :as keycard]
[native-module.core :as native-module] [native-module.core :as native-module]
[react-native.platform :as platform] [react-native.platform :as platform]
[status-im.utils.deprecated-types :as types] [status-im.utils.deprecated-types :as types]
[taoensso.timbre :as log])) [taoensso.timbre :as log]
[utils.address :as address]))
(defonce event-emitter (defonce event-emitter
(if platform/ios? (if platform/ios?
@ -114,7 +114,7 @@
(then (fn [response] (then (fn [response]
(let [info (-> response (let [info (-> response
(js->clj :keywordize-keys true) (js->clj :keywordize-keys true)
(update :key-uid ethereum/normalized-hex))] (update :key-uid address/normalized-hex))]
(on-success info)))) (on-success info))))
(catch on-failure))) (catch on-failure)))
@ -125,7 +125,7 @@
(then (fn [response] (then (fn [response]
(let [info (-> response (let [info (-> response
(js->clj :keywordize-keys true) (js->clj :keywordize-keys true)
(update :key-uid ethereum/normalized-hex))] (update :key-uid address/normalized-hex))]
(on-success info)))) (on-success info))))
(catch on-failure))) (catch on-failure)))

View File

@ -3,8 +3,7 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.bottom-sheet.events :as bottom-sheet] [status-im.bottom-sheet.events :as bottom-sheet]
[status-im2.constants :as constants] [status-im2.constants :as constants]
[status-im.ethereum.core :as ethereum] [utils.ethereum.eip.eip55 :as eip55]
[status-im.ethereum.eip55 :as eip55]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[status-im.keycard.common :as common] [status-im.keycard.common :as common]
status-im.keycard.fx status-im.keycard.fx
@ -19,7 +18,8 @@
[status-im.utils.deprecated-types :as types] [status-im.utils.deprecated-types :as types]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[utils.security.core :as security])) [utils.security.core :as security]
[utils.address :as address]))
(rf/defn pair* (rf/defn pair*
[_ password] [_ password]
@ -203,7 +203,7 @@
:address address :address address
:public-key public-key :public-key public-key
:keycard-instance-uid instance-uid :keycard-instance-uid instance-uid
:key-uid (ethereum/normalized-hex key-uid) :key-uid (address/normalized-hex key-uid)
:keycard-pairing pairing :keycard-pairing pairing
:keycard-paired-on paired-on :keycard-paired-on paired-on
:chat-key whisper-private-key} :chat-key whisper-private-key}
@ -272,9 +272,9 @@
settings {:keycard-instance-uid instance-uid settings {:keycard-instance-uid instance-uid
:keycard-paired-on paired-on :keycard-paired-on paired-on
:keycard-pairing pairing} :keycard-pairing pairing}
password (ethereum/sha3 (security/safe-unmask-data (get-in db password (native-module/sha3 (security/safe-unmask-data (get-in db
[:keycard [:keycard
:migration-password]))) :migration-password])))
encryption-pass (get-in db [:keycard :profile/profile :encryption-public-key]) encryption-pass (get-in db [:keycard :profile/profile :encryption-public-key])
login-params {:key-uid key-uid login-params {:key-uid key-uid
:multiaccount-data (types/clj->json account) :multiaccount-data (types/clj->json account)
@ -316,20 +316,20 @@
(assoc-in (assoc-in
[:keycard :profile/profile] [:keycard :profile/profile]
(-> account-data (-> account-data
(update :address ethereum/normalized-hex) (update :address address/normalized-hex)
(update :whisper-address ethereum/normalized-hex) (update :whisper-address address/normalized-hex)
(update :wallet-address ethereum/normalized-hex) (update :wallet-address address/normalized-hex)
(update :wallet-root-address ethereum/normalized-hex) (update :wallet-root-address address/normalized-hex)
(update :public-key ethereum/normalized-hex) (update :public-key address/normalized-hex)
(update :whisper-public-key ethereum/normalized-hex) (update :whisper-public-key address/normalized-hex)
(update :wallet-public-key ethereum/normalized-hex) (update :wallet-public-key address/normalized-hex)
(update :wallet-root-public-key ethereum/normalized-hex) (update :wallet-root-public-key address/normalized-hex)
(update :instance-uid #(get-in db [:keycard :profile/profile :instance-uid] %)))) (update :instance-uid #(get-in db [:keycard :profile/profile :instance-uid] %))))
(assoc-in [:keycard :multiaccount-wallet-address] (:wallet-address account-data)) (assoc-in [:keycard :multiaccount-wallet-address] (:wallet-address account-data))
(assoc-in [:keycard :multiaccount-whisper-public-key] (:whisper-public-key account-data)) (assoc-in [:keycard :multiaccount-whisper-public-key] (:whisper-public-key account-data))
(assoc-in [:keycard :pin :status] nil) (assoc-in [:keycard :pin :status] nil)
(assoc-in [:keycard :application-info :key-uid] (assoc-in [:keycard :application-info :key-uid]
(ethereum/normalized-hex (:key-uid account-data))) (address/normalized-hex (:key-uid account-data)))
(update :keycard dissoc :recovery-phrase :creating-backup? :converting-account?) (update :keycard dissoc :recovery-phrase :creating-backup? :converting-account?)
(update-in [:keycard :secrets] dissoc :pin :puk :password :mnemonic) (update-in [:keycard :secrets] dissoc :pin :puk :password :mnemonic)
(assoc :multiaccounts/new-installation-id (random-guid-generator)))} (assoc :multiaccounts/new-installation-id (random-guid-generator)))}

View File

@ -1,12 +1,14 @@
(ns status-im.keycard.sign (ns status-im.keycard.sign
(:require [clojure.string :as string] (:require [clojure.string :as string]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum]
[status-im.keycard.common :as common] [status-im.keycard.common :as common]
[utils.re-frame :as rf] [utils.re-frame :as rf]
[utils.money :as money] [utils.money :as money]
[status-im.utils.deprecated-types :as types] [status-im.utils.deprecated-types :as types]
[taoensso.timbre :as log])) [taoensso.timbre :as log]
[utils.ethereum.chain :as chain]
[status-im.wallet.utils :as wallet.utils]
[utils.address :as address]))
(rf/defn sign (rf/defn sign
{:events [:keycard/sign]} {:events [:keycard/sign]}
@ -22,10 +24,10 @@
pin (common/vector->string (get-in db [:keycard :pin :sign])) pin (common/vector->string (get-in db [:keycard :pin :sign]))
from (or (get-in db [:signing/tx :from :address]) from (or (get-in db [:signing/tx :from :address])
(get-in db [:signing/tx :message :from]) (get-in db [:signing/tx :message :from])
(ethereum/default-address db)) (wallet.utils/default-address db))
path (reduce path (reduce
(fn [_ {:keys [address path]}] (fn [_ {:keys [address path]}]
(when (ethereum/address= from address) (when (address/address= from address)
(reduced path))) (reduced path)))
nil nil
(:profile/wallet-accounts db))] (:profile/wallet-accounts db))]
@ -43,7 +45,7 @@
{:db (-> db {:db (-> db
(assoc-in [:keycard :card-read-in-progress?] true) (assoc-in [:keycard :card-read-in-progress?] true)
(assoc-in [:keycard :pin :status] :verifying)) (assoc-in [:keycard :pin :status] :verifying))
:keycard/sign {:hash (ethereum/naked-address hash) :keycard/sign {:hash (address/naked-address hash)
:data data :data data
:typed? typed? ; this parameter is for e2e :typed? typed? ; this parameter is for e2e
:on-success on-success :on-success on-success
@ -55,7 +57,7 @@
(-> signature (-> signature
(string/replace-first #"00$" "1b") (string/replace-first #"00$" "1b")
(string/replace-first #"01$" "1c") (string/replace-first #"01$" "1c")
ethereum/normalized-hex)) address/normalized-hex))
(rf/defn sign-message (rf/defn sign-message
{:events [:keycard/sign-message]} {:events [:keycard/sign-message]}
@ -63,7 +65,7 @@
(let [{:keys [result error]} (types/json->clj result) (let [{:keys [result error]} (types/json->clj result)
on-success #(re-frame/dispatch [:keycard/on-sign-message-success params on-success #(re-frame/dispatch [:keycard/on-sign-message-success params
(normalize-signature %)]) (normalize-signature %)])
hash (ethereum/naked-address result)] hash (address/naked-address result)]
(sign cofx hash on-success))) (sign cofx hash on-success)))
(rf/defn on-sign-message-success (rf/defn on-sign-message-success
@ -92,7 +94,7 @@
{:db (-> db {:db (-> db
(assoc-in [:keycard :card-read-in-progress?] true) (assoc-in [:keycard :card-read-in-progress?] true)
(assoc-in [:signing/sign :keycard-step] :signing)) (assoc-in [:signing/sign :keycard-step] :signing))
:keycard/sign-typed-data {:hash (ethereum/naked-address hash)}} :keycard/sign-typed-data {:hash (address/naked-address hash)}}
(rf/merge cofx (rf/merge cofx
(common/set-on-card-connected :keycard/sign-typed-data) (common/set-on-card-connected :keycard/sign-typed-data)
{:db (assoc-in db [:signing/sign :keycard-step] :signing)})))) {:db (assoc-in db [:signing/sign :keycard-step] :signing)}))))
@ -116,7 +118,7 @@
currency-contract (:currency message)] currency-contract (:currency message)]
(when currency-contract (when currency-contract
{:json-rpc/call [{:method "wallet_discoverToken" {:json-rpc/call [{:method "wallet_discoverToken"
:params [(ethereum/chain-id db) currency-contract] :params [(chain/chain-id db) currency-contract]
:on-success #(re-frame/dispatch [:keycard/fetch-currency-token-on-success :on-success #(re-frame/dispatch [:keycard/fetch-currency-token-on-success
%])}]}) %])}]})
(rf/merge cofx (rf/merge cofx

View File

@ -3,7 +3,6 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[re-frame.db :as re-frame.db] [re-frame.db :as re-frame.db]
[status-im2.constants :as constants] [status-im2.constants :as constants]
[status-im.ethereum.core :as ethereum]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[status-im.keycard.keycard :as keycard] [status-im.keycard.keycard :as keycard]
[status-im.multiaccounts.create.core :as multiaccounts.create] [status-im.multiaccounts.create.core :as multiaccounts.create]
@ -11,12 +10,13 @@
[status-im.node.core :as node] [status-im.node.core :as node]
[status-im.utils.deprecated-types :as types] [status-im.utils.deprecated-types :as types]
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[taoensso.timbre :as log])) [taoensso.timbre :as log]
[utils.address :as address]))
(def kk1-password "000000") (def kk1-password "000000")
(def default-pin "111111") (def default-pin "111111")
(def default-puk "000000000000") (def default-puk "000000000000")
(def account-password (ethereum/sha3 "no password")) (def account-password (native-module/sha3 "no password"))
(def initial-state (def initial-state
{:card-connected? false {:card-connected? false
@ -476,7 +476,7 @@
(let [signature (-> res (let [signature (-> res
types/json->clj types/json->clj
:result :result
ethereum/normalized-hex)] address/normalized-hex)]
(on-success signature))))) (on-success signature)))))
(native-module/sign-typed-data (native-module/sign-typed-data
data data
@ -486,7 +486,7 @@
(let [signature (-> res (let [signature (-> res
types/json->clj types/json->clj
:result :result
ethereum/normalized-hex)] address/normalized-hex)]
(on-success signature)))))))) (on-success signature))))))))
(defn sign-typed-data (defn sign-typed-data

View File

@ -1,12 +1,12 @@
(ns status-im.keycard.wallet (ns status-im.keycard.wallet
(:require [status-im.bottom-sheet.events :as bottom-sheet] (:require [status-im.bottom-sheet.events :as bottom-sheet]
[status-im2.constants :as constants] [status-im2.constants :as constants]
[status-im.ethereum.core :as ethereum] [utils.ethereum.eip.eip55 :as eip55]
[status-im.ethereum.eip55 :as eip55]
[status-im.keycard.common :as common] [status-im.keycard.common :as common]
[status-im.ui.screens.wallet.add-new.views :as add-new.views] [status-im.ui.screens.wallet.add-new.views :as add-new.views]
[utils.re-frame :as rf] [utils.re-frame :as rf]
[status-im.utils.hex :as utils.hex])) [status-im.utils.hex :as utils.hex]
[native-module.core :as native-module]))
(rf/defn show-pin-sheet (rf/defn show-pin-sheet
{:events [:keycard/new-account-pin-sheet]} {:events [:keycard/new-account-pin-sheet]}
@ -31,6 +31,17 @@
[cofx] [cofx]
(bottom-sheet/hide-bottom-sheet-old cofx)) (bottom-sheet/hide-bottom-sheet-old cofx))
(defn public-key->address
[public-key]
(let [length (count public-key)
normalized-key (case length
132 (str "0x" (subs public-key 4))
130 public-key
128 (str "0x" public-key)
nil)]
(when normalized-key
(subs (native-module/sha3 normalized-key) 26))))
(rf/defn generate-new-keycard-account (rf/defn generate-new-keycard-account
{:events [:wallet.accounts/generate-new-keycard-account]} {:events [:wallet.accounts/generate-new-keycard-account]}
[{:keys [db]}] [{:keys [db]}]
@ -46,7 +57,7 @@
{;; Strip leading 04 prefix denoting uncompressed key format {;; Strip leading 04 prefix denoting uncompressed key format
:address (eip55/address->checksum :address (eip55/address->checksum
(str "0x" (str "0x"
(ethereum/public-key->address (public-key->address
(subs public-key 2)))) (subs public-key 2))))
:public-key (str "0x" public-key) :public-key (str "0x" public-key)
:path path}))) :path path})))

View File

@ -3,8 +3,7 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im2.constants :as constants] [status-im2.constants :as constants]
[status-im.data-store.settings :as data-store.settings] [status-im.data-store.settings :as data-store.settings]
[status-im.ethereum.core :as ethereum] [utils.ethereum.eip.eip55 :as eip55]
[status-im.ethereum.eip55 :as eip55]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[native-module.core :as native-module] [native-module.core :as native-module]
[status-im.node.core :as node] [status-im.node.core :as node]
@ -210,7 +209,7 @@
(save-account-and-login (save-account-and-login
key-uid key-uid
multiaccount-data multiaccount-data
(ethereum/sha3 (security/safe-unmask-data password)) (native-module/sha3 (security/safe-unmask-data password))
settings settings
(node/get-new-config db) (node/get-new-config db)
accounts-data))))) accounts-data)))))

View File

@ -1,7 +1,6 @@
(ns status-im.multiaccounts.login.core (ns status-im.multiaccounts.login.core
(:require (:require
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum]
[native-module.core :as native-module] [native-module.core :as native-module]
[status-im.ui.components.react :as react] [status-im.ui.components.react :as react]
[utils.re-frame :as rf] [utils.re-frame :as rf]
@ -26,7 +25,7 @@
{::export-db [key-uid {::export-db [key-uid
(types/clj->json {:name name (types/clj->json {:name name
:key-uid key-uid}) :key-uid key-uid})
(ethereum/sha3 (security/safe-unmask-data password)) (native-module/sha3 (security/safe-unmask-data password))
(fn [path] (fn [path]
(when platform/ios? (when platform/ios?
(let [uri (str "file://" path)] (let [uri (str "file://" path)]
@ -41,4 +40,4 @@
{::import-db [key-uid {::import-db [key-uid
(types/clj->json {:name name (types/clj->json {:name name
:key-uid key-uid}) :key-uid key-uid})
(ethereum/sha3 (security/safe-unmask-data password))]})) (native-module/sha3 (security/safe-unmask-data password))]}))

View File

@ -1,7 +1,6 @@
(ns status-im.multiaccounts.reset-password.core (ns status-im.multiaccounts.reset-password.core
(:require [clojure.string :as string] (:require [clojure.string :as string]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum]
[native-module.core :as native-module] [native-module.core :as native-module]
[status-im.popover.core :as popover] [status-im.popover.core :as popover]
[utils.re-frame :as rf] [utils.re-frame :as rf]
@ -54,8 +53,8 @@
(fn [[key-uid {:keys [current-password new-password]}]] (fn [[key-uid {:keys [current-password new-password]}]]
(native-module/reset-password (native-module/reset-password
key-uid key-uid
(ethereum/sha3 (security/safe-unmask-data current-password)) (native-module/sha3 (security/safe-unmask-data current-password))
(ethereum/sha3 (security/safe-unmask-data new-password)) (native-module/sha3 (security/safe-unmask-data new-password))
change-db-password-cb))) change-db-password-cb)))
(rf/defn handle-verification-success (rf/defn handle-verification-success
@ -80,7 +79,7 @@
(re-frame/reg-fx (re-frame/reg-fx
::validate-current-password-and-reset ::validate-current-password-and-reset
(fn [{:keys [address current-password] :as form-vals}] (fn [{:keys [address current-password] :as form-vals}]
(let [hashed-pass (ethereum/sha3 (security/safe-unmask-data current-password))] (let [hashed-pass (native-module/sha3 (security/safe-unmask-data current-password))]
(native-module/verify address (native-module/verify address
hashed-pass hashed-pass
(partial handle-verification form-vals))))) (partial handle-verification form-vals)))))

View File

@ -1,11 +1,11 @@
(ns status-im.network.core (ns status-im.network.core
(:require [clojure.string :as string] (:require [clojure.string :as string]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[status-im.node.core :as node] [status-im.node.core :as node]
[utils.re-frame :as rf] [utils.re-frame :as rf]
[status-im2.navigation.events :as navigation])) [status-im2.navigation.events :as navigation]
[utils.ethereum.chain :as chain]))
(def url-regex (def url-regex
#"https?://(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}(\.[a-z]{2,6})?\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)") #"https?://(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}(\.[a-z]{2,6})?\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)")
@ -136,7 +136,7 @@
[random-id network-name sym upstream-url chain-type chain-id] [random-id network-name sym upstream-url chain-type chain-id]
(let [data-dir (str "/ethereum/" (name chain-type) "_rpc") (let [data-dir (str "/ethereum/" (name chain-type) "_rpc")
config {:NetworkId (or (when chain-id (int chain-id)) config {:NetworkId (or (when chain-id (int chain-id))
(ethereum/chain-keyword->chain-id chain-type)) (chain/chain-keyword->chain-id chain-type))
:DataDir data-dir :DataDir data-dir
:UpstreamConfig {:Enabled true :UpstreamConfig {:Enabled true
:URL upstream-url}}] :URL upstream-url}}]

View File

@ -1,13 +1,13 @@
(ns status-im.qr-scanner.core (ns status-im.qr-scanner.core
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum]
[status-im.group-chats.core :as group-chats] [status-im.group-chats.core :as group-chats]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[status-im.router.core :as router] [status-im.router.core :as router]
[utils.re-frame :as rf] [utils.re-frame :as rf]
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[taoensso.timbre :as log])) [taoensso.timbre :as log]
[utils.ethereum.chain :as chain]))
(rf/defn scan-qr-code (rf/defn scan-qr-code
{:events [::scan-code]} {:events [::scan-code]}
@ -110,7 +110,7 @@
(rf/defn on-scan (rf/defn on-scan
{:events [::on-scan-success]} {:events [::on-scan-success]}
[{:keys [db]} uri] [{:keys [db]} uri]
{::router/handle-uri {:chain (ethereum/chain-keyword db) {::router/handle-uri {:chain (chain/chain-keyword db)
:chats (get db :chats) :chats (get db :chats)
:uri uri :uri uri
:cb #(re-frame/dispatch [::match-scanned-value %])}}) :cb #(re-frame/dispatch [::match-scanned-value %])}})

View File

@ -4,7 +4,6 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im2.contexts.chat.events :as chat.events] [status-im2.contexts.chat.events :as chat.events]
[status-im2.constants :as constants] [status-im2.constants :as constants]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.eip681 :as eip681] [status-im.ethereum.eip681 :as eip681]
[status-im.ethereum.ens :as ens] [status-im.ethereum.ens :as ens]
[status-im.utils.deprecated-types :as types] [status-im.utils.deprecated-types :as types]
@ -14,7 +13,9 @@
[utils.url :as url] [utils.url :as url]
[status-im.utils.wallet-connect :as wallet-connect] [status-im.utils.wallet-connect :as wallet-connect]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[utils.security.core :as security])) [utils.security.core :as security]
[utils.ethereum.chain :as chain]
[utils.address :as address]))
(def ethereum-scheme "ethereum:") (def ethereum-scheme "ethereum:")
@ -93,7 +94,7 @@
(string? user-id) (string? user-id)
(not (string/blank? user-id)) (not (string/blank? user-id))
(not= user-id "0x")) (not= user-id "0x"))
(let [chain-id (ethereum/chain-keyword->chain-id chain) (let [chain-id (chain/chain-keyword->chain-id chain)
ens-name (stateofus/ens-name-parse user-id) ens-name (stateofus/ens-name-parse user-id)
on-success #(match-contact-async chain {:user-id % :ens-name ens-name} callback)] on-success #(match-contact-async chain {:user-id % :ens-name ens-name} callback)]
(ens/pubkey chain-id ens-name on-success)) (ens/pubkey chain-id ens-name on-success))
@ -244,7 +245,7 @@
(= handler :wallet-account) (= handler :wallet-account)
(cb (match-wallet-account route-params)) (cb (match-wallet-account route-params))
(ethereum/address? uri) (address/address? uri)
(cb (address->eip681 uri)) (cb (address->eip681 uri))
(url/url? uri) (url/url? uri)

View File

@ -4,8 +4,7 @@
[clojure.string :as string] [clojure.string :as string]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im2.constants :as constants] [status-im2.constants :as constants]
[status-im.ethereum.core :as ethereum] [utils.ethereum.eip.eip55 :as eip55]
[status-im.ethereum.eip55 :as eip55]
[status-im.ethereum.tokens :as tokens] [status-im.ethereum.tokens :as tokens]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[status-im.keycard.card :as keycard.card] [status-im.keycard.card :as keycard.card]
@ -22,7 +21,10 @@
[status-im.wallet.prices :as prices] [status-im.wallet.prices :as prices]
[status-im2.common.json-rpc.events :as json-rpc] [status-im2.common.json-rpc.events :as json-rpc]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[utils.security.core :as security])) [utils.security.core :as security]
[utils.address :as address]
[status-im.wallet.utils :as wallet.utils]
[utils.ethereum.chain :as chain]))
(re-frame/reg-fx (re-frame/reg-fx
:signing/send-transaction-fx :signing/send-transaction-fx
@ -65,7 +67,7 @@
(let [to (utils.hex/normalize-hex to)] (let [to (utils.hex/normalize-hex to)]
(or (or
(get-in db [:contacts/contacts to]) (get-in db [:contacts/contacts to])
{:address (ethereum/normalized-hex to)}))) {:address (address/normalized-hex to)})))
(rf/defn change-password (rf/defn change-password
{:events [:signing.ui/password-is-changed]} {:events [:signing.ui/password-is-changed]}
@ -81,8 +83,9 @@
[{{:signing/keys [sign tx] :as db} :db}] [{{:signing/keys [sign tx] :as db} :db}]
(let [{{:keys [data typed? from v4]} :message} tx (let [{{:keys [data typed? from v4]} :message} tx
{:keys [in-progress? password]} sign {:keys [in-progress? password]} sign
from (or from (ethereum/default-address db)) from (or from (wallet.utils/default-address db))
hashed-password (ethereum/sha3 (security/safe-unmask-data password))] hashed-password (native-module/sha3 (security/safe-unmask-data
password))]
(when-not in-progress? (when-not in-progress?
(merge (merge
{:db (update db :signing/sign assoc :error nil :in-progress? true)} {:db (update db :signing/sign assoc :error nil :in-progress? true)}
@ -105,10 +108,11 @@
(let [{:keys [in-progress? password]} sign (let [{:keys [in-progress? password]} sign
{:keys [tx-obj gas gasPrice maxPriorityFeePerGas {:keys [tx-obj gas gasPrice maxPriorityFeePerGas
maxFeePerGas message nonce]} tx maxFeePerGas message nonce]} tx
hashed-password (ethereum/sha3 (security/safe-unmask-data password)) hashed-password (native-module/sha3 (security/safe-unmask-data
password))
{:keys [action username custom-domain?]} registration {:keys [action username custom-domain?]} registration
{:keys [public-key]} (:profile/profile db) {:keys [public-key]} (:profile/profile db)
chain-id (ethereum/chain-id db)] chain-id (chain/chain-id db)]
(if message (if message
(sign-message cofx) (sign-message cofx)
(let [tx-obj-to-send (merge tx-obj (let [tx-obj-to-send (merge tx-obj
@ -255,13 +259,13 @@
:value value :value value
:amount (str eth-amount) :amount (str eth-amount)
:token (tokens/asset-for (:wallet/all-tokens db) :token (tokens/asset-for (:wallet/all-tokens db)
(ethereum/get-current-network db) (chain/get-current-network db)
:ETH)} :ETH)}
(not (nil? token)) (not (nil? token))
token token
:else :else
{:to to {:to to
:contact {:address (ethereum/normalized-hex to)}}))))) :contact {:address (address/normalized-hex to)}})))))
(defn prepare-tx (defn prepare-tx
[db {{:keys [data gas gasPrice maxFeePerGas maxPriorityFeePerGas] :as tx-obj} :tx-obj :as tx}] [db {{:keys [data gas gasPrice maxFeePerGas maxPriorityFeePerGas] :as tx-obj} :tx-obj :as tx}]
@ -276,6 +280,18 @@
:maxPriorityFeePerGas (when maxPriorityFeePerGas :maxPriorityFeePerGas (when maxPriorityFeePerGas
(money/bignumber maxPriorityFeePerGas))})) (money/bignumber maxPriorityFeePerGas))}))
(defn hex-to-utf8
[s]
(let [utf8 (native-module/hex-to-utf8 s)]
(if (empty? utf8)
nil
utf8)))
(defn hex->text
"Converts a hexstring to UTF8 text."
[data]
(or (hex-to-utf8 data) data))
(rf/defn show-sign (rf/defn show-sign
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [{:signing/keys [queue]} db (let [{:signing/keys [queue]} db
@ -297,7 +313,7 @@
:formatted-data (if typed? :formatted-data (if typed?
(types/js->pretty-json (types/js->pretty-json
(types/json->js data)) (types/json->js data))
(ethereum/hex->text data)) (hex->text data))
:keycard-step (when pinless? :connect)}) :keycard-step (when pinless? :connect)})
:show-signing-sheet nil} :show-signing-sheet nil}
#(when-not wallet-set-up-passed? #(when-not wallet-set-up-passed?
@ -338,7 +354,7 @@
{:success-callback #(re-frame/dispatch {:success-callback #(re-frame/dispatch
[:wallet.send/update-gas-price-success :signing/tx % tx-obj]) [:wallet.send/update-gas-price-success :signing/tx % tx-obj])
:error-callback #(re-frame/dispatch [:signing/update-gas-price-error %]) :error-callback #(re-frame/dispatch [:signing/update-gas-price-error %])
:network-id (get-in (ethereum/current-network db) :network-id (get-in (chain/current-network db)
[:config :NetworkId])}}))))) [:config :NetworkId])}})))))
(rf/defn check-queue (rf/defn check-queue
@ -355,7 +371,7 @@
;; big-int ;; big-int
:params [chat-id (str value) contract transaction-hash :params [chat-id (str value) contract transaction-hash
(or (:result (types/json->clj signature)) (or (:result (types/json->clj signature))
(ethereum/normalized-hex signature))] (address/normalized-hex signature))]
:js-response true :js-response true
:on-success :on-success
#(re-frame/dispatch [:transport/message-sent %])}]}) #(re-frame/dispatch [:transport/message-sent %])}]})
@ -366,7 +382,7 @@
{:json-rpc/call [{:method "wakuext_acceptRequestTransaction" {:json-rpc/call [{:method "wakuext_acceptRequestTransaction"
:params [transaction-hash message-id :params [transaction-hash message-id
(or (:result (types/json->clj signature)) (or (:result (types/json->clj signature))
(ethereum/normalized-hex signature))] (address/normalized-hex signature))]
:js-response true :js-response true
:on-success :on-success
#(re-frame/dispatch [:transport/message-sent %])}]}) #(re-frame/dispatch [:transport/message-sent %])}]})
@ -496,7 +512,7 @@
(defn normalize-tx-obj (defn normalize-tx-obj
[db tx] [db tx]
(update-in tx [:tx-obj :from] #(eip55/address->checksum (or % (ethereum/default-address db))))) (update-in tx [:tx-obj :from] #(eip55/address->checksum (or % (wallet.utils/default-address db)))))
(rf/defn sign (rf/defn sign
"Signing transaction or message, shows signing sheet "Signing transaction or message, shows signing sheet
@ -516,7 +532,7 @@
[{:keys [db] :as cofx} {:keys [to amount from token]}] [{:keys [db] :as cofx} {:keys [to amount from token]}]
(let [{:keys [symbol address]} token (let [{:keys [symbol address]} token
amount-hex (str "0x" (native-module/number-to-hex amount)) amount-hex (str "0x" (native-module/number-to-hex amount))
to-norm (ethereum/normalized-hex (if (string? to) to (:address to))) to-norm (address/normalized-hex (if (string? to) to (:address to)))
from-address (:address from) from-address (:address from)
identity (:current-chat-id db) identity (:current-chat-id db)
db (dissoc db :wallet/prepare-transaction :signing/edit-fee)] db (dissoc db :wallet/prepare-transaction :signing/edit-fee)]
@ -530,7 +546,7 @@
:chat-id identity :chat-id identity
:command? true :command? true
:value amount-hex} :value amount-hex}
{:to (ethereum/normalized-hex address) {:to (address/normalized-hex address)
:from from-address :from from-address
:chat-id identity :chat-id identity
:command? true :command? true
@ -566,7 +582,7 @@
:chat-id chat-id :chat-id chat-id
:command? true :command? true
:value amount-hex} :value amount-hex}
{:to (ethereum/normalized-hex address) {:to (address/normalized-hex address)
:from from-address :from from-address
:command? true :command? true
:message-id (:id request-parameters) :message-id (:id request-parameters)
@ -578,7 +594,7 @@
[{:keys [db] :as cofx} {:keys [to amount from token gas gasPrice maxFeePerGas maxPriorityFeePerGas]}] [{:keys [db] :as cofx} {:keys [to amount from token gas gasPrice maxFeePerGas maxPriorityFeePerGas]}]
(let [{:keys [symbol address]} token (let [{:keys [symbol address]} token
amount-hex (str "0x" (native-module/number-to-hex amount)) amount-hex (str "0x" (native-module/number-to-hex amount))
to-norm (ethereum/normalized-hex (if (string? to) to (:address to))) to-norm (address/normalized-hex (if (string? to) to (:address to)))
from-address (:address from)] from-address (:address from)]
(rf/merge cofx (rf/merge cofx
{:db (dissoc db :wallet/prepare-transaction :signing/edit-fee)} {:db (dissoc db :wallet/prepare-transaction :signing/edit-fee)}
@ -596,7 +612,7 @@
(if (= symbol :ETH) (if (= symbol :ETH)
{:to to-norm {:to to-norm
:value amount-hex} :value amount-hex}
{:to (ethereum/normalized-hex address) {:to (address/normalized-hex address)
:data (native-module/encode-transfer to-norm amount-hex)}))})))) :data (native-module/encode-transfer to-norm amount-hex)}))}))))
(re-frame/reg-fx (re-frame/reg-fx

View File

@ -2,14 +2,14 @@
(:require [clojure.string :as string] (:require [clojure.string :as string]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.bottom-sheet.events :as bottom-sheet] [status-im.bottom-sheet.events :as bottom-sheet]
[status-im.ethereum.core :as ethereum]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[status-im.popover.core :as popover] [status-im.popover.core :as popover]
[status-im.signing.eip1559 :as eip1559] [status-im.signing.eip1559 :as eip1559]
[utils.re-frame :as rf] [utils.re-frame :as rf]
[utils.money :as money] [utils.money :as money]
[status-im2.common.json-rpc.events :as json-rpc] [status-im2.common.json-rpc.events :as json-rpc]
[taoensso.timbre :as log])) [taoensso.timbre :as log]
[utils.ethereum.chain :as chain]))
(def min-gas-price-wei ^js (money/bignumber 1)) (def min-gas-price-wei ^js (money/bignumber 1))
@ -409,7 +409,7 @@
(check-base-fee (check-base-fee
(assoc fee-history (assoc fee-history
:testnet? :testnet?
(ethereum/testnet? (chain/testnet?
(get-in networks [current-network :config :NetworkId]))))] (get-in networks [current-network :config :NetworkId]))))]
(merge {:max-priority-fee (merge {:max-priority-fee
(max-priority-fee-hex (money/bignumber %) current-base-fee)} (max-priority-fee-hex (money/bignumber %) current-base-fee)}

View File

@ -2,11 +2,12 @@
(:require [clojure.string :as string] (:require [clojure.string :as string]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im2.constants :as constants] [status-im2.constants :as constants]
[status-im.ethereum.core :as ethereum]
[status-im2.config :as config] [status-im2.config :as config]
[utils.re-frame :as rf] [utils.re-frame :as rf]
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[status-im2.navigation.events :as navigation])) [status-im2.navigation.events :as navigation]
[utils.ethereum.chain :as chain]
[status-im.wallet.utils :as wallet.utils]))
(re-frame/reg-fx (re-frame/reg-fx
:stickers/set-pending-timeout-fx :stickers/set-pending-timeout-fx
@ -21,14 +22,14 @@
cofx cofx
{:db (assoc-in db [:stickers/packs id :status] constants/sticker-pack-status-installed) {:db (assoc-in db [:stickers/packs id :status] constants/sticker-pack-status-installed)
:json-rpc/call [{:method "stickers_install" :json-rpc/call [{:method "stickers_install"
:params [(ethereum/chain-id db) id] :params [(chain/chain-id db) id]
:on-success #()}]})) :on-success #()}]}))
(rf/defn load-packs (rf/defn load-packs
{:events [:stickers/load-packs]} {:events [:stickers/load-packs]}
[{:keys [db]}] [{:keys [db]}]
{:json-rpc/call [{:method "stickers_market" {:json-rpc/call [{:method "stickers_market"
:params [(ethereum/chain-id db)] :params [(chain/chain-id db)]
:on-success #(re-frame/dispatch [:stickers/stickers-market-success %])} :on-success #(re-frame/dispatch [:stickers/stickers-market-success %])}
{:method "stickers_installed" {:method "stickers_installed"
:params [] :params []
@ -44,7 +45,7 @@
{:events [:stickers/buy-pack]} {:events [:stickers/buy-pack]}
[{db :db} pack-id] [{db :db} pack-id]
{:json-rpc/call [{:method "stickers_buyPrepareTx" {:json-rpc/call [{:method "stickers_buyPrepareTx"
:params [(ethereum/chain-id db) (ethereum/default-address db) (int pack-id)] :params [(chain/chain-id db) (wallet.utils/default-address db) (int pack-id)]
:on-success #(re-frame/dispatch [:signing.ui/sign :on-success #(re-frame/dispatch [:signing.ui/sign
{:tx-obj % {:tx-obj %
:on-result [:stickers/pending-pack pack-id]}])}]}) :on-result [:stickers/pending-pack pack-id]}])}]})
@ -58,7 +59,7 @@
(update :stickers/packs-pending conj id)) (update :stickers/packs-pending conj id))
:stickers/set-pending-timeout-fx nil :stickers/set-pending-timeout-fx nil
:json-rpc/call [{:method "stickers_addPending" :json-rpc/call [{:method "stickers_addPending"
:params [(ethereum/chain-id db) (int id)] :params [(chain/chain-id db) (int id)]
:on-success #()}]}) :on-success #()}]})
(rf/defn pending-timeout (rf/defn pending-timeout
@ -66,7 +67,7 @@
[{{:stickers/keys [packs-pending] :as db} :db}] [{{:stickers/keys [packs-pending] :as db} :db}]
(when (seq packs-pending) (when (seq packs-pending)
{:json-rpc/call [{:method "stickers_processPending" {:json-rpc/call [{:method "stickers_processPending"
:params [(ethereum/chain-id db)] :params [(chain/chain-id db)]
:on-success #(re-frame/dispatch [:stickers/stickers-process-pending-success :on-success #(re-frame/dispatch [:stickers/stickers-process-pending-success
%])}]})) %])}]}))

View File

@ -6,7 +6,6 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[reagent.core :as reagent] [reagent.core :as reagent]
[status-im.ens.core :as ens] [status-im.ens.core :as ens]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.ens :as ethereum.ens] [status-im.ethereum.ens :as ethereum.ens]
[status-im.ethereum.stateofus :as stateofus] [status-im.ethereum.stateofus :as stateofus]
[status-im.ethereum.tokens :as tokens] [status-im.ethereum.tokens :as tokens]
@ -23,7 +22,8 @@
[status-im.ui.screens.profile.components.views :as profile.components] [status-im.ui.screens.profile.components.views :as profile.components]
[status-im.ui.screens.wallet.send.sheets :as sheets] [status-im.ui.screens.wallet.send.sheets :as sheets]
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[utils.debounce :as debounce]) [utils.debounce :as debounce]
[utils.address :as address])
(:require-macros [status-im.utils.views :as views])) (:require-macros [status-im.utils.views :as views]))
(defn- link (defn- link
@ -547,7 +547,7 @@
(when-not pending? (when-not pending?
[section [section
{:title (i18n/label :t/wallet-address) {:title (i18n/label :t/wallet-address)
:content (ethereum/normalized-hex address)}]) :content (address/normalized-hex address)}])
(when-not pending? (when-not pending?
[react/view {:style {:margin-top 14}} [react/view {:style {:margin-top 14}}
[section [section

View File

@ -1,7 +1,6 @@
(ns status-im.ui.screens.privacy-and-security-settings.events (ns status-im.ui.screens.privacy-and-security-settings.events
(:require [clojure.string :as string] (:require [clojure.string :as string]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[native-module.core :as native-module] [native-module.core :as native-module]
[utils.re-frame :as rf] [utils.re-frame :as rf]
@ -20,7 +19,7 @@
(let [hashed-password (let [hashed-password
(-> masked-password (-> masked-password
security/safe-unmask-data security/safe-unmask-data
ethereum/sha3)] native-module/sha3)]
(native-module/verify (native-module/verify
address address
hashed-password hashed-password

View File

@ -8,7 +8,6 @@
[quo2.foundations.colors :as quo2.colors] [quo2.foundations.colors :as quo2.colors]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[reagent.core :as reagent] [reagent.core :as reagent]
[status-im.ethereum.core :as ethereum]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[status-im.ui.components.animation :as animation] [status-im.ui.components.animation :as animation]
[status-im.ui.components.icons.icons :as icons] [status-im.ui.components.icons.icons :as icons]
@ -22,7 +21,8 @@
[status-im.ui.screens.wallet.collectibles.views :as collectibles.views] [status-im.ui.screens.wallet.collectibles.views :as collectibles.views]
[status-im.ui.screens.wallet.transactions.views :as history] [status-im.ui.screens.wallet.transactions.views :as history]
[status-im2.config :as config] [status-im2.config :as config]
[utils.re-frame :as rf]) [utils.re-frame :as rf]
[utils.address :as address])
(:require-macros [status-im.utils.views :as views])) (:require-macros [status-im.utils.views :as views]))
(def state (reagent/atom {:tab :assets})) (def state (reagent/atom {:tab :assets}))
@ -61,7 +61,7 @@
:style {:width (/ window-width 3) :style {:width (/ window-width 3)
:line-height 22 :line-height 22
:color colors/white-transparent-70-persist}} :color colors/white-transparent-70-persist}}
(ethereum/normalized-hex address)]] (address/normalized-hex address)]]
[react/view {:position :absolute :top 12 :right 12} [react/view {:position :absolute :top 12 :right 12}
[react/touchable-highlight {:on-press #(re-frame/dispatch [:wallet/share-popover address])} [react/touchable-highlight {:on-press #(re-frame/dispatch [:wallet/share-popover address])}
[icons/icon :main-icons/share [icons/icon :main-icons/share

View File

@ -6,7 +6,6 @@
[quo.design-system.colors :as colors] [quo.design-system.colors :as colors]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[reagent.core :as reagent] [reagent.core :as reagent]
[status-im.ethereum.core :as ethereum]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[status-im.multiaccounts.db :as multiaccounts.db] [status-im.multiaccounts.db :as multiaccounts.db]
[status-im.ui.components.icons.icons :as icons] [status-im.ui.components.icons.icons :as icons]
@ -15,7 +14,8 @@
[status-im.ui.components.topbar :as topbar] [status-im.ui.components.topbar :as topbar]
[status-im.ui.screens.keycard.pin.views :as pin.views] [status-im.ui.screens.keycard.pin.views :as pin.views]
[status-im.ui.screens.wallet.account-settings.views :as account-settings] [status-im.ui.screens.wallet.account-settings.views :as account-settings]
[utils.security.core :as security])) [utils.security.core :as security]
[native-module.core :as native-module]))
(defn add-account-topbar (defn add-account-topbar
[type] [type]
@ -179,7 +179,7 @@
{:view {:content pin {:view {:content pin
:height 256}}]) :height 256}}])
#(re-frame/dispatch [:wallet.accounts/add-new-account #(re-frame/dispatch [:wallet.accounts/add-new-account
(ethereum/sha3 @entered-password)])) (native-module/sha3 @entered-password)]))
:disabled :disabled
(or add-account-disabled? (or add-account-disabled?
(and (and

View File

@ -4,7 +4,6 @@
[quo.design-system.colors :as colors] [quo.design-system.colors :as colors]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[reagent.core :as reagent] [reagent.core :as reagent]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.stateofus :as stateofus] [status-im.ethereum.stateofus :as stateofus]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[status-im.ui.components.chat-icon.screen :as chat-icon] [status-im.ui.components.chat-icon.screen :as chat-icon]
@ -17,7 +16,8 @@
[status-im.ui.screens.wallet.components.views :as components] [status-im.ui.screens.wallet.components.views :as components]
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[utils.debounce :as debounce] [utils.debounce :as debounce]
[utils.string :as utils.string]) [utils.string :as utils.string]
[utils.address :as address])
(:require-macros [status-im.utils.views :as views])) (:require-macros [status-im.utils.views :as views]))
(defn- recipient-topbar (defn- recipient-topbar
@ -317,7 +317,7 @@
:size :small :size :small
:align :center :align :center
:color :secondary} :color :secondary}
(when-not (ethereum/address? address) (when-not (address/address? address)
(str (stateofus/username-with-domain address) " • ")) (str (stateofus/username-with-domain address) " • "))
[quo/text [quo/text
{:monospace true {:monospace true

View File

@ -2,7 +2,7 @@
(:require [quo.core :as quo] (:require [quo.core :as quo]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[reagent.core :as reagent] [reagent.core :as reagent]
[status-im.ethereum.eip55 :as eip55] [utils.ethereum.eip.eip55 :as eip55]
[status-im.ethereum.eip681 :as eip681] [status-im.ethereum.eip681 :as eip681]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[status-im.ui.components.copyable-text :as copyable-text] [status-im.ui.components.copyable-text :as copyable-text]

View File

@ -5,7 +5,6 @@
[quo.design-system.colors :as colors] [quo.design-system.colors :as colors]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.commands.core :as commands] [status-im.commands.core :as commands]
[status-im.ethereum.core :as ethereum]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[status-im.multiaccounts.core :as multiaccounts] [status-im.multiaccounts.core :as multiaccounts]
[status-im.ui.components.bottom-panel.views :as bottom-panel] [status-im.ui.components.bottom-panel.views :as bottom-panel]
@ -20,7 +19,8 @@
[status-im.ui.screens.wallet.send.styles :as styles] [status-im.ui.screens.wallet.send.styles :as styles]
[utils.money :as money] [utils.money :as money]
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[status-im.wallet.utils :as wallet.utils])) [status-im.wallet.utils :as wallet.utils]
[utils.address :as address]))
(defn header (defn header
[{:keys [label small-screen?]}] [{:keys [label small-screen?]}]
@ -232,7 +232,7 @@
prices [:prices] prices [:prices]
wallet-currency [:wallet/currency] wallet-currency [:wallet/currency]
window-width [:dimensions/window-width]] window-width [:dimensions/window-width]]
(let [to-norm (ethereum/normalized-hex (if (string? to) to (:address to)))] (let [to-norm (address/normalized-hex (if (string? to) to (:address to)))]
[kb-presentation/keyboard-avoiding-view {:style {:flex 1}} [kb-presentation/keyboard-avoiding-view {:style {:flex 1}}
[:<> [:<>
[quo2/page-nav [quo2/page-nav

View File

@ -3,7 +3,6 @@
[goog.string :as gstring] [goog.string :as gstring]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im2.constants :as constants] [status-im2.constants :as constants]
[status-im.ethereum.core :as ethereum]
[status-im.group-chats.core :as group-chats] [status-im.group-chats.core :as group-chats]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[status-im.multiaccounts.model :as multiaccounts.model] [status-im.multiaccounts.model :as multiaccounts.model]
@ -13,7 +12,8 @@
[status-im.wallet.choose-recipient.core :as choose-recipient] [status-im.wallet.choose-recipient.core :as choose-recipient]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[native-module.core :as native-module])) [native-module.core :as native-module]
[utils.ethereum.chain :as chain]))
;; TODO(yenda) investigate why `handle-universal-link` event is ;; TODO(yenda) investigate why `handle-universal-link` event is
;; dispatched 7 times for the same link ;; dispatched 7 times for the same link
@ -161,7 +161,7 @@
(rf/defn route-url (rf/defn route-url
"Match a url against a list of routes and handle accordingly" "Match a url against a list of routes and handle accordingly"
[{:keys [db]} url] [{:keys [db]} url]
{::router/handle-uri {:chain (ethereum/chain-keyword db) {::router/handle-uri {:chain (chain/chain-keyword db)
:chats (:chats db) :chats (:chats db)
:uri url :uri url
:cb #(re-frame/dispatch [::match-value url %])}}) :cb #(re-frame/dispatch [::match-value url %])}})
@ -215,8 +215,8 @@
;;It can be called after the error "route ip+net: netlinkrib: permission denied" is fixed on status-go ;;It can be called after the error "route ip+net: netlinkrib: permission denied" is fixed on status-go
;;side ;;side
#_(native-module/start-searching-for-local-pairing-peers #_(native-module/start-searching-for-local-pairing-peers
#(log/info "[local-pairing] errors from local-pairing-preflight-outbound-check ->" %)) #(log/info "[local-pairing] errors from local-pairing-preflight-outbound-check ->" %)))
)
(defn finalize (defn finalize
"Remove event listener for url" "Remove event listener for url"

View File

@ -4,9 +4,9 @@
[clojure.string :as string] [clojure.string :as string]
[goog.string :as gstring] [goog.string :as gstring]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum] [utils.ethereum.eip.eip55 :as eip55]
[status-im.ethereum.eip55 :as eip55] [utils.i18n :as i18n]
[utils.i18n :as i18n])) [utils.address :as address]))
;;TODO (14/11/22 flexsurfer) .-Alert usage code has been moved to the status-im2 namespace, we keep this ;;TODO (14/11/22 flexsurfer) .-Alert usage code has been moved to the status-im2 namespace, we keep this
;;only for old (status 1.0) code, ;;only for old (status 1.0) code,
@ -106,7 +106,7 @@
(defn get-shortened-checksum-address (defn get-shortened-checksum-address
[address] [address]
(when address (when address
(get-shortened-address (eip55/address->checksum (ethereum/normalized-hex address))))) (get-shortened-address (eip55/address->checksum (address/normalized-hex address)))))
;;TODO (14/11/22 flexsurfer) haven't moved yet ;;TODO (14/11/22 flexsurfer) haven't moved yet
(defn format-decimals (defn format-decimals

View File

@ -5,8 +5,7 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im2.constants :as constants] [status-im2.constants :as constants]
[status-im.ens.core :as ens.core] [status-im.ens.core :as ens.core]
[status-im.ethereum.core :as ethereum] [utils.ethereum.eip.eip55 :as eip55]
[status-im.ethereum.eip55 :as eip55]
[status-im.ethereum.eip681 :as eip681] [status-im.ethereum.eip681 :as eip681]
[status-im.ethereum.mnemonic :as mnemonic] [status-im.ethereum.mnemonic :as mnemonic]
[status-im.ethereum.stateofus :as stateofus] [status-im.ethereum.stateofus :as stateofus]
@ -23,7 +22,9 @@
[status-im.wallet.prices :as prices] [status-im.wallet.prices :as prices]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[utils.security.core :as security])) [utils.security.core :as security]
[utils.ethereum.chain :as chain]
[utils.address :as address]))
(rf/defn start-adding-new-account (rf/defn start-adding-new-account
{:events [:wallet.accounts/start-adding-new-account]} {:events [:wallet.accounts/start-adding-new-account]}
@ -249,7 +250,7 @@
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [address (get-in db [:add-account :address])] (let [address (get-in db [:add-account :address])]
(account-generated cofx (account-generated cofx
{:address (eip55/address->checksum (ethereum/normalized-hex address)) {:address (eip55/address->checksum (address/normalized-hex address))
:type :watch}))) :type :watch})))
(rf/defn add-new-account-password-verifyied (rf/defn add-new-account-password-verifyied
@ -282,7 +283,7 @@
(cond-> {:db (assoc-in db [:add-account :address] account)} (cond-> {:db (assoc-in db [:add-account :address] account)}
name? name?
(assoc ::ens.core/resolve-address (assoc ::ens.core/resolve-address
[(ethereum/chain-id db) [(chain/chain-id db)
(stateofus/ens-name-parse account) (stateofus/ens-name-parse account)
#(re-frame/dispatch #(re-frame/dispatch
[:wallet.accounts/set-account-to-watch %])])))) [:wallet.accounts/set-account-to-watch %])]))))
@ -336,7 +337,7 @@
(re-frame/reg-fx (re-frame/reg-fx
:key-storage/delete-imported-key :key-storage/delete-imported-key
(fn [{:keys [key-uid address password on-success on-error]}] (fn [{:keys [key-uid address password on-success on-error]}]
(let [hashed-pass (ethereum/sha3 (security/safe-unmask-data password))] (let [hashed-pass (native-module/sha3 (security/safe-unmask-data password))]
(native-module/delete-imported-key (native-module/delete-imported-key
key-uid key-uid
(string/lower-case (subs address 2)) (string/lower-case (subs address 2))

View File

@ -2,7 +2,6 @@
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.bottom-sheet.events :as bottom-sheet] [status-im.bottom-sheet.events :as bottom-sheet]
[status-im.contact.db :as contact.db] [status-im.contact.db :as contact.db]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.eip681 :as eip681] [status-im.ethereum.eip681 :as eip681]
[status-im.ethereum.ens :as ens] [status-im.ethereum.ens :as ens]
[utils.i18n :as i18n] [utils.i18n :as i18n]
@ -13,7 +12,9 @@
[utils.money :as money] [utils.money :as money]
[status-im.utils.universal-links.utils :as links] [status-im.utils.universal-links.utils :as links]
[status-im.utils.wallet-connect :as wallet-connect] [status-im.utils.wallet-connect :as wallet-connect]
[status-im2.navigation.events :as navigation])) [status-im2.navigation.events :as navigation]
[utils.ethereum.chain :as chain]
[status-im.wallet.utils :as wallet.utils]))
;; FIXME(Ferossgp): Should be part of QR scanner not wallet ;; FIXME(Ferossgp): Should be part of QR scanner not wallet
(rf/defn toggle-flashlight (rf/defn toggle-flashlight
@ -66,7 +67,7 @@
:wallet/prepare-transaction :wallet/prepare-transaction
(cond-> {:to address (cond-> {:to address
:to-name (or name (find-address-name db address)) :to-name (or name (find-address-name db address))
:from (ethereum/get-default-account :from (wallet.utils/get-default-account
(get db :profile/wallet-accounts))} (get db :profile/wallet-accounts))}
gas (assoc :gas (money/bignumber gas)) gas (assoc :gas (money/bignumber gas))
gas-limit (assoc :gas (money/bignumber gas-limit)) gas-limit (assoc :gas (money/bignumber gas-limit))
@ -106,7 +107,7 @@
{:success-callback {:success-callback
#(re-frame/dispatch #(re-frame/dispatch
[:wallet.send/update-gas-price-success :wallet/prepare-transaction %]) [:wallet.send/update-gas-price-success :wallet/prepare-transaction %])
:network-id (get-in (ethereum/current-network db) :network-id (get-in (chain/current-network db)
[:config :NetworkId])}}) [:config :NetworkId])}})
(when (and chain-id (not= current-chain-id chain-id)) (when (and chain-id (not= current-chain-id chain-id))
{:ui/show-error (i18n/label :t/wallet-invalid-chain-id {:ui/show-error (i18n/label :t/wallet-invalid-chain-id
@ -129,7 +130,7 @@
;; if there are no ens-names, we dispatch request-uri-parsed immediately ;; if there are no ens-names, we dispatch request-uri-parsed immediately
(request-uri-parsed cofx message uri) (request-uri-parsed cofx message uri)
{::resolve-addresses {::resolve-addresses
{:chain-id (ethereum/chain-id db) {:chain-id (chain/chain-id db)
:ens-names ens-names :ens-names ens-names
:callback :callback
(fn [addresses] (fn [addresses]

View File

@ -6,8 +6,7 @@
[react-native.async-storage :as async-storage] [react-native.async-storage :as async-storage]
[status-im.bottom-sheet.events :as bottom-sheet] [status-im.bottom-sheet.events :as bottom-sheet]
[status-im.contact.db :as contact.db] [status-im.contact.db :as contact.db]
[status-im.ethereum.core :as ethereum] [utils.ethereum.eip.eip55 :as eip55]
[status-im.ethereum.eip55 :as eip55]
[status-im.ethereum.ens :as ens] [status-im.ethereum.ens :as ens]
[status-im.ethereum.stateofus :as stateofus] [status-im.ethereum.stateofus :as stateofus]
[status-im.ethereum.tokens :as tokens] [status-im.ethereum.tokens :as tokens]
@ -31,7 +30,8 @@
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.utils.mobile-sync :as utils.mobile-sync] [status-im.utils.mobile-sync :as utils.mobile-sync]
[native-module.core :as native-module])) [native-module.core :as native-module]
[utils.ethereum.chain :as chain]))
(defn get-balance (defn get-balance
[{:keys [address on-success on-error]}] [{:keys [address on-success on-error]}]
@ -158,8 +158,8 @@
(let [addresses (map (comp string/lower-case :address) (let [addresses (map (comp string/lower-case :address)
(get db :profile/wallet-accounts)) (get db :profile/wallet-accounts))
chain-id (-> db chain-id (-> db
ethereum/current-network chain/current-network
ethereum/network->chain-id)] chain/network->chain-id)]
(when (get-in db [:profile/profile :opensea-enabled?]) (when (get-in db [:profile/profile :opensea-enabled?])
{:json-rpc/call (map {:json-rpc/call (map
(fn [address] (fn [address]
@ -186,7 +186,7 @@
(rf/defn fetch-collectible-assets-by-owner-and-collection (rf/defn fetch-collectible-assets-by-owner-and-collection
{:events [::fetch-collectible-assets-by-owner-and-collection]} {:events [::fetch-collectible-assets-by-owner-and-collection]}
[{:keys [db]} address collectible-slug limit] [{:keys [db]} address collectible-slug limit]
(let [chain-id (ethereum/network->chain-id (ethereum/current-network db))] (let [chain-id (chain/network->chain-id (chain/current-network db))]
{:db (assoc-in db [:wallet/fetching-collection-assets collectible-slug] true) {:db (assoc-in db [:wallet/fetching-collection-assets collectible-slug] true)
:json-rpc/call [{:method "wallet_getOpenseaAssetsByOwnerAndCollection" :json-rpc/call [{:method "wallet_getOpenseaAssetsByOwnerAndCollection"
:params [chain-id address collectible-slug limit] :params [chain-id address collectible-slug limit]
@ -243,7 +243,7 @@
(let [addresses (or addresses (let [addresses (or addresses
(map (comp string/lower-case :address) wallet-accounts)) (map (comp string/lower-case :address) wallet-accounts))
{:keys [:wallet/visible-tokens]} profile {:keys [:wallet/visible-tokens]} profile
chain (ethereum/chain-keyword db) chain (chain/chain-keyword db)
assets (get visible-tokens chain) assets (get visible-tokens chain)
tokens (->> (vals all-tokens) tokens (->> (vals all-tokens)
(remove #(or (:hidden? %) (remove #(or (:hidden? %)
@ -310,7 +310,7 @@
(rf/defn update-toggle-in-settings (rf/defn update-toggle-in-settings
[{{:profile/keys [profile] :as db} :db :as cofx} symbol checked?] [{{:profile/keys [profile] :as db} :db :as cofx} symbol checked?]
(let [chain (ethereum/chain-keyword db) (let [chain (chain/chain-keyword db)
visible-tokens (get profile :wallet/visible-tokens)] visible-tokens (get profile :wallet/visible-tokens)]
(rf/merge cofx (rf/merge cofx
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
@ -355,7 +355,7 @@
(rf/defn configure-token-balance-and-visibility (rf/defn configure-token-balance-and-visibility
{:events [::tokens-found]} {:events [::tokens-found]}
[{:keys [db] :as cofx} balances] [{:keys [db] :as cofx} balances]
(let [chain (ethereum/chain-keyword db) (let [chain (chain/chain-keyword db)
visible-tokens (get-in db [:profile/profile :wallet/visible-tokens]) visible-tokens (get-in db [:profile/profile :wallet/visible-tokens])
chain-visible-tokens (into (or (config/default-visible-tokens chain) chain-visible-tokens (into (or (config/default-visible-tokens chain)
#{}) #{})
@ -459,11 +459,12 @@
{:keys [symbol decimals]} {:keys [symbol decimals]}
(if (seq contract) (if (seq contract)
(get all-tokens contract) (get all-tokens contract)
(tokens/native-currency (ethereum/get-current-network db))) (tokens/native-currency (chain/get-current-network db)))
amount-text (str (money/internal->formatted value symbol decimals))] amount-text (str (money/internal->formatted value symbol decimals))]
{:db (assoc db {:db (assoc db
:wallet/prepare-transaction :wallet/prepare-transaction
{:from (ethereum/get-default-account (:profile/wallet-accounts db)) {:from (wallet.utils/get-default-account (:profile/wallet-accounts
db))
:to (or (get-in db [:contacts/contacts identity]) :to (or (get-in db [:contacts/contacts identity])
(-> identity (-> identity
contact.db/public-key->new-contact contact.db/public-key->new-contact
@ -503,7 +504,7 @@
:signing/update-gas-price {:success-callback :signing/update-gas-price {:success-callback
#(re-frame/dispatch #(re-frame/dispatch
[:wallet.send/update-gas-price-success :wallet/prepare-transaction %]) [:wallet.send/update-gas-price-success :wallet/prepare-transaction %])
:network-id (get-in (ethereum/current-network db) :network-id (get-in (chain/current-network db)
[:config :NetworkId])}}) [:config :NetworkId])}})
(rf/defn prepare-transaction-from-chat (rf/defn prepare-transaction-from-chat
@ -517,7 +518,7 @@
contact.db/enrich-contact))] contact.db/enrich-contact))]
(cond-> {:db (assoc db (cond-> {:db (assoc db
:wallet/prepare-transaction :wallet/prepare-transaction
{:from (ethereum/get-default-account {:from (wallet.utils/get-default-account
(:profile/wallet-accounts db)) (:profile/wallet-accounts db))
:to contact :to contact
:symbol :ETH :symbol :ETH
@ -525,7 +526,7 @@
:dispatch [:open-modal :prepare-send-transaction]} :dispatch [:open-modal :prepare-send-transaction]}
ens-verified ens-verified
(assoc ::resolve-address (assoc ::resolve-address
{:chain-id (ethereum/chain-id db) {:chain-id (chain/chain-id db)
:ens-name (if (= (.indexOf ^js name ".") -1) :ens-name (if (= (.indexOf ^js name ".") -1)
(stateofus/subdomain name) (stateofus/subdomain name)
name) name)
@ -538,7 +539,7 @@
(let [identity (:current-chat-id db)] (let [identity (:current-chat-id db)]
{:db (assoc db {:db (assoc db
:wallet/prepare-transaction :wallet/prepare-transaction
{:from (ethereum/get-default-account (:profile/wallet-accounts db)) {:from (wallet.utils/get-default-account (:profile/wallet-accounts db))
:to (or (get-in db [:contacts/contacts identity]) :to (or (get-in db [:contacts/contacts identity])
(-> identity (-> identity
contact.db/public-key->new-contact contact.db/public-key->new-contact
@ -561,7 +562,7 @@
:signing/update-gas-price {:success-callback :signing/update-gas-price {:success-callback
#(re-frame/dispatch #(re-frame/dispatch
[:wallet.send/update-gas-price-success :wallet/prepare-transaction %]) [:wallet.send/update-gas-price-success :wallet/prepare-transaction %])
:network-id (get-in (ethereum/current-network db) :network-id (get-in (chain/current-network db)
[:config :NetworkId])}}) [:config :NetworkId])}})
(rf/defn cancel-transaction-command (rf/defn cancel-transaction-command
@ -671,13 +672,15 @@
nil nil
(get-in db [:wallet :accounts]))) (get-in db [:wallet :accounts])))
(defn custom-rpc-node? [{:keys [id]}] (= 45 (count id)))
(defn get-restart-interval (defn get-restart-interval
[db] [db]
(let [max-block (get-max-block-with-transfer db) (let [max-block (get-max-block-with-transfer db)
custom-interval (get db :wallet-service/custom-interval)] custom-interval (get db :wallet-service/custom-interval)]
(cond (cond
(ethereum/custom-rpc-node? (custom-rpc-node?
(ethereum/current-network db)) (chain/current-network db))
ms-2-min ms-2-min
(and max-block (and max-block
@ -690,8 +693,8 @@
(defn get-watching-interval (defn get-watching-interval
[db] [db]
(if (ethereum/custom-rpc-node? (if (custom-rpc-node?
(ethereum/current-network db)) (chain/current-network db))
ms-2-min ms-2-min
ms-10-min)) ms-10-min))
@ -734,7 +737,7 @@
:as params}] :as params}]
(when (:profile/profile db) (when (:profile/profile db)
(let [syncing-allowed? (utils.mobile-sync/syncing-allowed? cofx) (let [syncing-allowed? (utils.mobile-sync/syncing-allowed? cofx)
binance-chain? (ethereum/binance-chain? db)] binance-chain? (chain/binance-chain? db)]
(log/info "restart-wallet-service" (log/info "restart-wallet-service"
"force-restart?" force-restart? "force-restart?" force-restart?
"syncing-allowed?" syncing-allowed? "syncing-allowed?" syncing-allowed?
@ -778,7 +781,7 @@
(rf/defn transaction-included (rf/defn transaction-included
{:events [::transaction-included]} {:events [::transaction-included]}
[{:keys [db] :as cofx} address tx-hash] [{:keys [db] :as cofx} address tx-hash]
(if (ethereum/binance-chain? db) (if (chain/binance-chain? db)
(load-transaction-by-hash cofx address tx-hash) (load-transaction-by-hash cofx address tx-hash)
(restart cofx true))) (restart cofx true)))
@ -813,7 +816,7 @@
(rf/defn watch-tx (rf/defn watch-tx
{:events [:watch-tx]} {:events [:watch-tx]}
[{:keys [db] :as cofx} address tx-id] [{:keys [db] :as cofx} address tx-id]
(let [chain-id (ethereum/chain-id db)] (let [chain-id (chain/chain-id db)]
{::start-watching [[address tx-id chain-id]]})) {::start-watching [[address tx-id chain-id]]}))
(rf/defn clear-timeouts (rf/defn clear-timeouts
@ -889,8 +892,8 @@
(rf/defn stop-fetching-on-empty-tx-history (rf/defn stop-fetching-on-empty-tx-history
[{:keys [db now] :as cofx} transfers] [{:keys [db now] :as cofx} transfers]
(let [non-empty-history? (get db :wallet/non-empty-tx-history?) (let [non-empty-history? (get db :wallet/non-empty-tx-history?)
custom-node? (ethereum/custom-rpc-node? custom-node? (custom-rpc-node?
(ethereum/current-network db)) (chain/current-network db))
until-ms (get db :wallet/keep-watching-until-ms)] until-ms (get db :wallet/keep-watching-until-ms)]
(when-not (and until-ms (> until-ms now)) (when-not (and until-ms (> until-ms now))
(rf/merge (rf/merge
@ -1056,7 +1059,7 @@
[network-id tokens] [network-id tokens]
(mapv #(-> % (mapv #(-> %
(update :symbol keyword) (update :symbol keyword)
((partial tokens/update-icon (ethereum/chain-id->chain-keyword (int network-id))))) ((partial tokens/update-icon (chain/chain-id->chain-keyword (int network-id)))))
tokens)) tokens))
(re-frame/reg-fx (re-frame/reg-fx
@ -1166,7 +1169,8 @@
(fn [already-seen] (fn [already-seen]
(when (and (not already-seen) (when (and (not already-seen)
(boolean (get invalid-addrr (boolean (get invalid-addrr
(ethereum/sha3 (string/lower-case (ethereum/default-address db)))))) (native-module/sha3 (string/lower-case (wallet.utils/default-address
db))))))
(utils.utils/show-popup (utils.utils/show-popup
(i18n/label :t/warning) (i18n/label :t/warning)
(i18n/label :t/ens-username-invalid-name-warning) (i18n/label :t/ens-username-invalid-name-warning)
@ -1190,7 +1194,7 @@
;; NOTE: Local notifications should be enabled only after wallet was started ;; NOTE: Local notifications should be enabled only after wallet was started
::enable-local-notifications nil ::enable-local-notifications nil
:dispatch-n [(when (or (not (utils.mobile-sync/syncing-allowed? cofx)) :dispatch-n [(when (or (not (utils.mobile-sync/syncing-allowed? cofx))
(ethereum/binance-chain? db)) (chain/binance-chain? db))
[:transaction/get-fetched-transfers])]} [:transaction/get-fetched-transfers])]}
(check-invalid-ens) (check-invalid-ens)
(initialize-tokens tokens custom-tokens) (initialize-tokens tokens custom-tokens)
@ -1211,7 +1215,7 @@
(get-cached-balances scan-all-tokens?)) (get-cached-balances scan-all-tokens?))
(when-not (get db :wallet/new-account) (when-not (get db :wallet/new-account)
(restart-wallet-service nil)) (restart-wallet-service nil))
(when (ethereum/binance-chain? db) (when (chain/binance-chain? db)
(request-current-block-update)) (request-current-block-update))
(prices/update-prices))) (prices/update-prices)))

View File

@ -2,13 +2,14 @@
(:require [clojure.string :as string] (:require [clojure.string :as string]
[quo.design-system.colors :as colors] [quo.design-system.colors :as colors]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[status-im.ui.components.react :as react] [status-im.ui.components.react :as react]
[utils.re-frame :as rf] [utils.re-frame :as rf]
[status-im.wallet.core :as wallet] [status-im.wallet.core :as wallet]
[status-im.wallet.prices :as prices] [status-im.wallet.prices :as prices]
[status-im2.navigation.events :as navigation])) [status-im2.navigation.events :as navigation]
[utils.ethereum.chain :as chain]
[utils.address :as address]))
(re-frame/reg-fx (re-frame/reg-fx
:wallet.custom-token/contract-address-paste :wallet.custom-token/contract-address-paste
@ -28,7 +29,7 @@
(rf/defn contract-address-is-changed (rf/defn contract-address-is-changed
{:events [:wallet.custom-token/contract-address-is-pasted]} {:events [:wallet.custom-token/contract-address-is-pasted]}
[{:keys [db]} contract] [{:keys [db]} contract]
(if (ethereum/address? contract) (if (address/address? contract)
(if (token-in-list? db contract) (if (token-in-list? db contract)
{:db (assoc db {:db (assoc db
:wallet/custom-token-screen :wallet/custom-token-screen
@ -37,7 +38,7 @@
:wallet/custom-token-screen :wallet/custom-token-screen
{:contract contract :in-progress? true}) {:contract contract :in-progress? true})
:json-rpc/call [{:method "wallet_discoverToken" :json-rpc/call [{:method "wallet_discoverToken"
:params [(ethereum/chain-id db) contract] :params [(chain/chain-id db) contract]
:on-success #(re-frame/dispatch [:wallet.custom-token/token-discover-result %]) :on-success #(re-frame/dispatch [:wallet.custom-token/token-discover-result %])
:on-error #(re-frame/dispatch [:wallet.custom-token/not-supported])}]}) :on-error #(re-frame/dispatch [:wallet.custom-token/not-supported])}]})
{:db (assoc db {:db (assoc db

View File

@ -1,13 +1,13 @@
(ns status-im.wallet.prices (ns status-im.wallet.prices
(:require [clojure.set :as set] (:require [clojure.set :as set]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.tokens :as tokens] [status-im.ethereum.tokens :as tokens]
[status-im.utils.currency :as currency] [status-im.utils.currency :as currency]
[utils.re-frame :as rf] [utils.re-frame :as rf]
[status-im.utils.prices :as prices] [status-im.utils.prices :as prices]
[status-im.wallet.utils :as wallet.utils] [status-im.wallet.utils :as wallet.utils]
[taoensso.timbre :as log])) [taoensso.timbre :as log]
[utils.ethereum.chain :as chain]))
(defn assoc-error-message (defn assoc-error-message
[db error-type err] [db error-type err]
@ -54,7 +54,7 @@
:profile/profile :profile/profile
:as db} :as db}
:db}] :db}]
(let [chain (ethereum/chain-keyword db) (let [chain (chain/chain-keyword db)
mainnet? (= :mainnet chain) mainnet? (= :mainnet chain)
assets (get visible-tokens chain #{}) assets (get visible-tokens chain #{})
tokens (tokens-symbols assets all-tokens) tokens (tokens-symbols assets all-tokens)
@ -63,7 +63,7 @@
{:wallet/get-prices {:wallet/get-prices
{:from (if mainnet? {:from (if mainnet?
(conj tokens "ETH") (conj tokens "ETH")
[(-> (tokens/native-currency (ethereum/get-current-network db)) [(-> (tokens/native-currency (chain/get-current-network db))
(wallet.utils/exchange-symbol))]) (wallet.utils/exchange-symbol))])
:to [(:code currency)] :to [(:code currency)]
:mainnet? mainnet? :mainnet? mainnet?

View File

@ -1,8 +1,7 @@
(ns status-im.wallet.recipient.core (ns status-im.wallet.recipient.core
(:require [clojure.string :as string] (:require [clojure.string :as string]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum] [utils.ethereum.eip.eip55 :as eip55]
[status-im.ethereum.eip55 :as eip55]
[status-im.ethereum.ens :as ens] [status-im.ethereum.ens :as ens]
[status-im.ethereum.stateofus :as stateofus] [status-im.ethereum.stateofus :as stateofus]
[utils.i18n :as i18n] [utils.i18n :as i18n]
@ -12,7 +11,9 @@
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[status-im2.common.json-rpc.events :as json-rpc] [status-im2.common.json-rpc.events :as json-rpc]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[utils.string :as utils.string])) [utils.string :as utils.string]
[utils.ethereum.chain :as chain]
[utils.address :as address]))
;;NOTE we want to handle only last resolve ;;NOTE we want to handle only last resolve
(def resolve-last-id (atom nil)) (def resolve-last-id (atom nil))
@ -40,7 +41,7 @@
(reset! resolve-last-id nil) (reset! resolve-last-id nil)
(let [recipient (utils.string/safe-trim raw-recipient)] (let [recipient (utils.string/safe-trim raw-recipient)]
(cond (cond
(ethereum/address? recipient) (address/address? recipient)
(let [checksum (eip55/address->checksum recipient)] (let [checksum (eip55/address->checksum recipient)]
(if (eip55/valid-address-checksum? checksum) (if (eip55/valid-address-checksum? checksum)
(rf/merge cofx (rf/merge cofx
@ -67,7 +68,7 @@
(do (do
(reset! resolve-last-id (random/id)) (reset! resolve-last-id (random/id))
{::resolve-address {::resolve-address
{:chain-id (ethereum/chain-id db) {:chain-id (chain/chain-id db)
:ens-name ens-name :ens-name ens-name
:cb #(re-frame/dispatch [::recipient-address-resolved % @resolve-last-id])}}) :cb #(re-frame/dispatch [::recipient-address-resolved % @resolve-last-id])}})
{:db (assoc-in db [:wallet/recipient :searching] false)})) {:db (assoc-in db [:wallet/recipient :searching] false)}))

View File

@ -24,3 +24,13 @@
(name (or (:symbol-exchange m) (name (or (:symbol-exchange m)
(:symbol-display m) (:symbol-display m)
(:symbol m)))) (:symbol m))))
(defn get-default-account
[accounts]
(some #(when (:wallet %) %) accounts))
(defn default-address
[db]
(-> (get db :profile/wallet-accounts)
get-default-account
:address))

View File

@ -3,13 +3,13 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.browser.core :as browser] [status-im.browser.core :as browser]
[status-im2.constants :as constants] [status-im2.constants :as constants]
[status-im.ethereum.core :as ethereum]
[status-im.signing.core :as signing] [status-im.signing.core :as signing]
[status-im2.config :as config] [status-im2.config :as config]
[utils.re-frame :as rf] [utils.re-frame :as rf]
[status-im.utils.deprecated-types :as types] [status-im.utils.deprecated-types :as types]
[status-im.utils.wallet-connect :as wallet-connect] [status-im.utils.wallet-connect :as wallet-connect]
[taoensso.timbre :as log])) [taoensso.timbre :as log]
[utils.address :as address]))
(rf/defn proposal-handler (rf/defn proposal-handler
{:events [:wallet-connect/proposal]} {:events [:wallet-connect/proposal]}
@ -149,7 +149,7 @@
supported-chain-ids (filter (fn [chain-id] #(boolean (some #{chain-id} available-chain-ids))) supported-chain-ids (filter (fn [chain-id] #(boolean (some #{chain-id} available-chain-ids)))
proposal-chain-ids) proposal-chain-ids)
address (:address account) address (:address account)
accounts (map #(str "eip155:" % ":" (ethereum/normalized-hex address)) accounts (map #(str "eip155:" % ":" (address/normalized-hex address))
supported-chain-ids) supported-chain-ids)
;; TODO: Check for unsupported ;; TODO: Check for unsupported
metadata (get db :wallet-connect/proposal-metadata) metadata (get db :wallet-connect/proposal-metadata)
@ -179,7 +179,7 @@
available-chain-ids (map #(get-in % [:config :NetworkId]) (vals (get db :networks/networks))) available-chain-ids (map #(get-in % [:config :NetworkId]) (vals (get db :networks/networks)))
supported-chain-ids (filter (fn [chain-id] #(boolean (some #{chain-id} available-chain-ids))) supported-chain-ids (filter (fn [chain-id] #(boolean (some #{chain-id} available-chain-ids)))
proposal-chain-ids) proposal-chain-ids)
accounts (map #(str "eip155:" % ":" (ethereum/normalized-hex address)) accounts (map #(str "eip155:" % ":" (address/normalized-hex address))
supported-chain-ids)] supported-chain-ids)]
{:db (assoc db {:db (assoc db
:wallet-connect/showing-app-management-sheet? :wallet-connect/showing-app-management-sheet?

View File

@ -4,8 +4,8 @@
[utils.re-frame :as rf] [utils.re-frame :as rf]
[status-im.multiaccounts.core :as multiaccounts] [status-im.multiaccounts.core :as multiaccounts]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[status-im.ethereum.core :as ethereum] [reagent.core :as reagent]
[reagent.core :as reagent])) [native-module.core :as native-module]))
(defn view (defn view
[] []
@ -37,5 +37,5 @@
(i18n/label :t/oops-wrong-password)]) (i18n/label :t/oops-wrong-password)])
[quo/button [quo/button
{:container-style {:margin-bottom 12 :margin-top 40} {:container-style {:margin-bottom 12 :margin-top 40}
:on-press #((:on-press button) (ethereum/sha3 @entered-password))} :on-press #((:on-press button) (native-module/sha3 @entered-password))}
(:label button)]])))) (:label button)]]))))

View File

@ -1,8 +1,8 @@
(ns status-im2.config (ns status-im2.config
(:require [clojure.string :as string] (:require [clojure.string :as string]
[react-native.config :as react-native-config] [react-native.config :as react-native-config]
[status-im.ethereum.core :as ethereum] [status-im.ethereum.ens :as ens]
[status-im.ethereum.ens :as ens])) [utils.ethereum.chain :as chain]))
(def get-config react-native-config/get-config) (def get-config react-native-config/get-config)
@ -55,18 +55,18 @@
(def verify-transaction-chain-id (js/parseInt (get-config :VERIFY_TRANSACTION_CHAIN_ID "1"))) (def verify-transaction-chain-id (js/parseInt (get-config :VERIFY_TRANSACTION_CHAIN_ID "1")))
(def verify-transaction-url (def verify-transaction-url
(if (= :mainnet (ethereum/chain-id->chain-keyword verify-transaction-chain-id)) (if (= :mainnet (chain/chain-id->chain-keyword verify-transaction-chain-id))
mainnet-rpc-url mainnet-rpc-url
goerli-rpc-url)) goerli-rpc-url))
(def verify-ens-chain-id (js/parseInt (get-config :VERIFY_ENS_CHAIN_ID "1"))) (def verify-ens-chain-id (js/parseInt (get-config :VERIFY_ENS_CHAIN_ID "1")))
(def verify-ens-url (def verify-ens-url
(if (= :mainnet (ethereum/chain-id->chain-keyword verify-ens-chain-id)) (if (= :mainnet (chain/chain-id->chain-keyword verify-ens-chain-id))
mainnet-rpc-url mainnet-rpc-url
goerli-rpc-url)) goerli-rpc-url))
(def verify-ens-contract-address (def verify-ens-contract-address
(get-config :VERIFY_ENS_CONTRACT_ADDRESS (get-config :VERIFY_ENS_CONTRACT_ADDRESS
((ethereum/chain-id->chain-keyword verify-ens-chain-id) ens/ens-registries))) ((chain/chain-id->chain-keyword verify-ens-chain-id) ens/ens-registries)))
(def fast-create-community-enabled? (def fast-create-community-enabled?
(enabled? (get-config :FAST_CREATE_COMMUNITY_ENABLED "0"))) (enabled? (get-config :FAST_CREATE_COMMUNITY_ENABLED "0")))
@ -92,7 +92,7 @@
[{:id "mainnet_rpc" [{:id "mainnet_rpc"
:chain-explorer-link "https://etherscan.io/address/" :chain-explorer-link "https://etherscan.io/address/"
:name "Mainnet with upstream RPC" :name "Mainnet with upstream RPC"
:config {:NetworkId (ethereum/chain-keyword->chain-id :mainnet) :config {:NetworkId (chain/chain-keyword->chain-id :mainnet)
:DataDir "/ethereum/mainnet_rpc" :DataDir "/ethereum/mainnet_rpc"
:UpstreamConfig {:Enabled true :UpstreamConfig {:Enabled true
:URL mainnet-rpc-url}}}]) :URL mainnet-rpc-url}}}])
@ -101,14 +101,14 @@
[{:id "xdai_rpc" [{:id "xdai_rpc"
:name "xDai Chain" :name "xDai Chain"
:chain-explorer-link "https://blockscout.com/xdai/mainnet/address/" :chain-explorer-link "https://blockscout.com/xdai/mainnet/address/"
:config {:NetworkId (ethereum/chain-keyword->chain-id :xdai) :config {:NetworkId (chain/chain-keyword->chain-id :xdai)
:DataDir "/ethereum/xdai_rpc" :DataDir "/ethereum/xdai_rpc"
:UpstreamConfig {:Enabled true :UpstreamConfig {:Enabled true
:URL "https://gnosischain-rpc.gateway.pokt.network"}}} :URL "https://gnosischain-rpc.gateway.pokt.network"}}}
{:id "bsc_rpc" {:id "bsc_rpc"
:chain-explorer-link "https://bscscan.com/address/" :chain-explorer-link "https://bscscan.com/address/"
:name "BSC Network" :name "BSC Network"
:config {:NetworkId (ethereum/chain-keyword->chain-id :bsc) :config {:NetworkId (chain/chain-keyword->chain-id :bsc)
:DataDir "/ethereum/bsc_rpc" :DataDir "/ethereum/bsc_rpc"
:UpstreamConfig {:Enabled true :UpstreamConfig {:Enabled true
:URL "https://bsc-dataseed.binance.org"}}}]) :URL "https://bsc-dataseed.binance.org"}}}])
@ -117,14 +117,14 @@
[{:id "goerli_rpc" [{:id "goerli_rpc"
:chain-explorer-link "https://goerli.etherscan.io/address/" :chain-explorer-link "https://goerli.etherscan.io/address/"
:name "Goerli with upstream RPC" :name "Goerli with upstream RPC"
:config {:NetworkId (ethereum/chain-keyword->chain-id :goerli) :config {:NetworkId (chain/chain-keyword->chain-id :goerli)
:DataDir "/ethereum/goerli_rpc" :DataDir "/ethereum/goerli_rpc"
:UpstreamConfig {:Enabled true :UpstreamConfig {:Enabled true
:URL goerli-rpc-url}}} :URL goerli-rpc-url}}}
{:id "bsc_testnet_rpc" {:id "bsc_testnet_rpc"
:chain-explorer-link "https://testnet.bscscan.com/address/" :chain-explorer-link "https://testnet.bscscan.com/address/"
:name "BSC testnet" :name "BSC testnet"
:config {:NetworkId (ethereum/chain-keyword->chain-id :bsc-testnet) :config {:NetworkId (chain/chain-keyword->chain-id :bsc-testnet)
:DataDir "/ethereum/bsc_testnet_rpc" :DataDir "/ethereum/bsc_testnet_rpc"
:UpstreamConfig {:Enabled true :UpstreamConfig {:Enabled true
:URL "https://data-seed-prebsc-1-s1.binance.org:8545/"}}}]) :URL "https://data-seed-prebsc-1-s1.binance.org:8545/"}}}])

View File

@ -3,7 +3,6 @@
[utils.re-frame :as rf] [utils.re-frame :as rf]
[utils.transforms :as transforms] [utils.transforms :as transforms]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.ens :as ens] [status-im.ethereum.ens :as ens]
[status-im.ethereum.stateofus :as stateofus] [status-im.ethereum.stateofus :as stateofus]
[native-module.core :as native-module] [native-module.core :as native-module]
@ -11,7 +10,8 @@
[utils.validators :as validators] [utils.validators :as validators]
[status-im2.contexts.contacts.events :as data-store.contacts] [status-im2.contexts.contacts.events :as data-store.contacts]
[status-im2.constants :as constants] [status-im2.constants :as constants]
[utils.string :as utils.string])) [utils.string :as utils.string]
[utils.ethereum.chain :as chain]))
(defn init-contact (defn init-contact
"Create a new contact (persisted to app-db as [:contacts/new-identity]). "Create a new contact (persisted to app-db as [:contacts/new-identity]).
@ -115,7 +115,7 @@
(dispatcher :contacts/set-new-identity-error input)}} (dispatcher :contacts/set-new-identity-error input)}}
:resolve-ens {:db (assoc db :contacts/new-identity contact) :resolve-ens {:db (assoc db :contacts/new-identity contact)
:contacts/resolve-public-key-from-ens :contacts/resolve-public-key-from-ens
{:chain-id (ethereum/chain-id db) {:chain-id (chain/chain-id db)
:ens ens :ens ens
:on-success :on-success
(dispatcher :contacts/set-new-identity-success input) (dispatcher :contacts/set-new-identity-success input)

View File

@ -2,7 +2,6 @@
(:require [utils.re-frame :as rf] (:require [utils.re-frame :as rf]
[native-module.core :as native-module] [native-module.core :as native-module]
[status-im2.contexts.profile.config :as profile.config] [status-im2.contexts.profile.config :as profile.config]
[status-im.ethereum.core :as ethereum]
[utils.security.core :as security] [utils.security.core :as security]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im2.contexts.shell.jump-to.utils :as shell.utils] [status-im2.contexts.shell.jump-to.utils :as shell.utils]
@ -26,7 +25,7 @@
{::create-profile-and-login {::create-profile-and-login
(merge (profile.config/create) (merge (profile.config/create)
{:displayName display-name {:displayName display-name
:password (ethereum/sha3 (security/safe-unmask-data password)) :password (native-module/sha3 (security/safe-unmask-data password))
:imagePath (profile.config/strip-file-prefix image-path) :imagePath (profile.config/strip-file-prefix image-path)
:customizationColor color})}) :customizationColor color})})

View File

@ -1,7 +1,6 @@
(ns status-im2.contexts.profile.login.events (ns status-im2.contexts.profile.login.events
(:require (:require
[utils.re-frame :as rf] [utils.re-frame :as rf]
[status-im.ethereum.core :as ethereum]
[utils.security.core :as security] [utils.security.core :as security]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[native-module.core :as native-module] [native-module.core :as native-module]
@ -40,7 +39,7 @@
[{:keys [db]}] [{:keys [db]}]
(let [{:keys [key-uid password]} (:profile/login db)] (let [{:keys [key-uid password]} (:profile/login db)]
{:db (assoc-in db [:profile/login :processing] true) {:db (assoc-in db [:profile/login :processing] true)
::login [key-uid (ethereum/sha3 (security/safe-unmask-data password))]})) ::login [key-uid (native-module/sha3 (security/safe-unmask-data password))]}))
(rf/defn login-local-paired-user (rf/defn login-local-paired-user
{:events [:profile.login/local-paired-user]} {:events [:profile.login/local-paired-user]}

View File

@ -1,6 +1,5 @@
(ns status-im2.contexts.profile.recover.events (ns status-im2.contexts.profile.recover.events
(:require [utils.security.core :as security] (:require [utils.security.core :as security]
[status-im.ethereum.core :as ethereum]
[status-im2.contexts.profile.config :as profile.config] [status-im2.contexts.profile.config :as profile.config]
[utils.re-frame :as rf] [utils.re-frame :as rf]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
@ -22,6 +21,6 @@
(merge (profile.config/create) (merge (profile.config/create)
{:displayName display-name {:displayName display-name
:mnemonic (security/safe-unmask-data seed-phrase) :mnemonic (security/safe-unmask-data seed-phrase)
:password (ethereum/sha3 (security/safe-unmask-data password)) :password (native-module/sha3 (security/safe-unmask-data password))
:imagePath (profile.config/strip-file-prefix image-path) :imagePath (profile.config/strip-file-prefix image-path)
:customizationColor color})}) :customizationColor color})})

View File

@ -3,14 +3,14 @@
[quo2.theme :as theme] [quo2.theme :as theme]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.contact.db :as contact.db] [status-im.contact.db :as contact.db]
[status-im.ethereum.core :as ethereum]
[status-im.multiaccounts.core :as multiaccounts] [status-im.multiaccounts.core :as multiaccounts]
[status-im.ui.screens.profile.visibility-status.utils :as visibility-status-utils] [status-im.ui.screens.profile.visibility-status.utils :as visibility-status-utils]
[status-im.utils.gfycat.core :as gfycat] [status-im.utils.gfycat.core :as gfycat]
[status-im2.constants :as constants] [status-im2.constants :as constants]
[utils.collection] [utils.collection]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.image-server :as image-server])) [utils.image-server :as image-server]
[utils.address :as address]))
(re-frame/reg-sub (re-frame/reg-sub
::query-current-chat-contacts ::query-current-chat-contacts
@ -295,7 +295,7 @@
:<- [:contacts/contacts] :<- [:contacts/contacts]
:<- [:multiaccount/contact] :<- [:multiaccount/contact]
(fn [[contacts multiaccount] [_ address]] (fn [[contacts multiaccount] [_ address]]
(if (ethereum/address= address (:public-key multiaccount)) (if (address/address= address (:public-key multiaccount))
multiaccount multiaccount
(contact.db/find-contact-by-address contacts address)))) (contact.db/find-contact-by-address contacts address))))

View File

@ -2,8 +2,9 @@
(:require [clojure.string :as string] (:require [clojure.string :as string]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ens.core :as ens] [status-im.ens.core :as ens]
[status-im.ethereum.core :as ethereum] [utils.money :as money]
[utils.money :as money])) [utils.ethereum.chain :as chain]
[utils.address :as address]))
(re-frame/reg-sub (re-frame/reg-sub
:ens/preferred-name :ens/preferred-name
@ -37,7 +38,7 @@
:<- [:wallet] :<- [:wallet]
(fn [[{:keys [custom-domain? username address]} (fn [[{:keys [custom-domain? username address]}
chain default-account public-key chain-id wallet]] chain default-account public-key chain-id wallet]]
(let [address (or address (ethereum/normalized-hex (:address default-account))) (let [address (or address (address/normalized-hex (:address default-account)))
balance (get-in wallet [:accounts address :balance])] balance (get-in wallet [:accounts address :balance])]
{:address address {:address address
:username username :username username
@ -47,9 +48,9 @@
:amount-label (ens-amount-label chain-id) :amount-label (ens-amount-label chain-id)
:sufficient-funds? (money/sufficient-funds? :sufficient-funds? (money/sufficient-funds?
(money/formatted->internal (money/bignumber 10) (money/formatted->internal (money/bignumber 10)
(ethereum/chain-keyword->snt-symbol chain) (chain/chain-keyword->snt-symbol chain)
18) 18)
(get balance (ethereum/chain-keyword->snt-symbol chain)))}))) (get balance (chain/chain-keyword->snt-symbol chain)))})))
(re-frame/reg-sub (re-frame/reg-sub
:ens/confirmation-screen :ens/confirmation-screen

View File

@ -1,12 +1,12 @@
(ns status-im2.subs.general (ns status-im2.subs.general
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[clojure.string :as string] [clojure.string :as string]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.tokens :as tokens] [status-im.ethereum.tokens :as tokens]
[status-im.multiaccounts.model :as multiaccounts.model] [status-im.multiaccounts.model :as multiaccounts.model]
[status-im.utils.build :as build] [status-im.utils.build :as build]
[status-im.utils.mobile-sync :as mobile-network-utils] [status-im.utils.mobile-sync :as mobile-network-utils]
[status-im2.constants :as constants])) [status-im2.constants :as constants]
[utils.ethereum.chain :as chain]))
(re-frame/reg-sub (re-frame/reg-sub
:visibility-status-updates/visibility-status-update :visibility-status-updates/visibility-status-update
@ -50,26 +50,26 @@
(re-frame/reg-sub (re-frame/reg-sub
:custom-rpc-node :custom-rpc-node
:<- [:current-network] :<- [:current-network]
(fn [network] (fn [{:keys [id]}]
(ethereum/custom-rpc-node? network))) (= 45 (count id))))
(re-frame/reg-sub (re-frame/reg-sub
:chain-keyword :chain-keyword
:<- [:current-network] :<- [:current-network]
(fn [network] (fn [network]
(ethereum/network->chain-keyword network))) (chain/network->chain-keyword network)))
(re-frame/reg-sub (re-frame/reg-sub
:chain-name :chain-name
:<- [:current-network] :<- [:current-network]
(fn [network] (fn [network]
(ethereum/network->chain-name network))) (chain/network->chain-name network)))
(re-frame/reg-sub (re-frame/reg-sub
:chain-id :chain-id
:<- [:current-network] :<- [:current-network]
(fn [network] (fn [network]
(ethereum/network->chain-id network))) (chain/network->chain-id network)))
(re-frame/reg-sub (re-frame/reg-sub
:mainnet? :mainnet?
@ -220,7 +220,7 @@
:ethereum/chain-keyword :ethereum/chain-keyword
:<- [:current-network] :<- [:current-network]
(fn [network] (fn [network]
(ethereum/network->chain-keyword network))) (chain/network->chain-keyword network)))
(re-frame/reg-sub (re-frame/reg-sub
:ethereum/native-currency :ethereum/native-currency

View File

@ -1,9 +1,9 @@
(ns status-im2.subs.keycard (ns status-im2.subs.keycard
(:require [clojure.string :as string] (:require [clojure.string :as string]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum]
[status-im.keycard.common :as common] [status-im.keycard.common :as common]
[utils.datetime :as datetime])) [utils.datetime :as datetime]
[utils.address :as address]))
(re-frame/reg-sub (re-frame/reg-sub
:keycard/nfc-enabled? :keycard/nfc-enabled?
@ -116,7 +116,7 @@
(re-frame/reg-sub (re-frame/reg-sub
:keycard-multiaccount-whisper-public-key :keycard-multiaccount-whisper-public-key
(fn [db] (fn [db]
(ethereum/normalized-hex (get-in db [:keycard :multiaccount-whisper-public-key])))) (address/normalized-hex (get-in db [:keycard :multiaccount-whisper-public-key]))))
(re-frame/reg-sub (re-frame/reg-sub
:keycard-paired-on :keycard-paired-on

View File

@ -1,13 +1,13 @@
(ns status-im2.subs.networks (ns status-im2.subs.networks
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum] [status-im2.config :as config]
[status-im2.config :as config])) [utils.ethereum.chain :as chain]))
(defn- filter-networks (defn- filter-networks
[network-type] [network-type]
(fn [network] (fn [network]
(let [chain-id (ethereum/network->chain-id network) (let [chain-id (chain/network->chain-id network)
testnet? (ethereum/testnet? chain-id) testnet? (chain/testnet? chain-id)
custom? (:custom? network)] custom? (:custom? network)]
(case network-type (case network-type
:custom custom? :custom custom?

View File

@ -3,12 +3,13 @@
[clojure.string :as string] [clojure.string :as string]
[quo2.theme :as theme] [quo2.theme :as theme]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum]
[status-im.fleet.core :as fleet] [status-im.fleet.core :as fleet]
[status-im.multiaccounts.db :as multiaccounts.db] [status-im.multiaccounts.db :as multiaccounts.db]
[status-im2.constants :as constants] [status-im2.constants :as constants]
[utils.image-server :as image-server] [utils.image-server :as image-server]
[utils.security.core :as security])) [utils.security.core :as security]
[status-im.wallet.utils :as wallet.utils]
[utils.address :as address]))
(re-frame/reg-sub (re-frame/reg-sub
:profile/customization-color :profile/customization-color
@ -77,7 +78,7 @@
:multiaccount/default-account :multiaccount/default-account
:<- [:profile/wallet-accounts] :<- [:profile/wallet-accounts]
(fn [accounts] (fn [accounts]
(ethereum/get-default-account accounts))) (wallet.utils/get-default-account accounts)))
(re-frame/reg-sub (re-frame/reg-sub
:multiaccount/visible-accounts :multiaccount/visible-accounts
@ -208,7 +209,7 @@
:generate :generate
false false
:watch :watch
(or (not (ethereum/address? address)) (or (not (address/address? address))
(some #(when (= (:address %) address) %) accounts)) (some #(when (= (:address %) address) %) accounts))
:key :key
(string/blank? (security/safe-unmask-data private-key)) (string/blank? (security/safe-unmask-data private-key))

View File

@ -1,12 +1,12 @@
(ns status-im2.subs.wallet.signing (ns status-im2.subs.wallet.signing
(:require [clojure.string :as string] (:require [clojure.string :as string]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.tokens :as tokens] [status-im.ethereum.tokens :as tokens]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[status-im.signing.gas :as signing.gas] [status-im.signing.gas :as signing.gas]
[utils.money :as money] [utils.money :as money]
[status-im.wallet.db :as wallet.db])) [status-im.wallet.db :as wallet.db]
[utils.ethereum.chain :as chain]))
(re-frame/reg-sub (re-frame/reg-sub
::send-transaction ::send-transaction
@ -41,7 +41,7 @@
:wallet/binance-chain? :wallet/binance-chain?
:<- [:current-network] :<- [:current-network]
(fn [network] (fn [network]
(ethereum/binance-chain-id? (get-in network [:config :NetworkId])))) (chain/binance-chain-id? (get-in network [:config :NetworkId]))))
(re-frame/reg-sub (re-frame/reg-sub
:signing/fee :signing/fee

View File

@ -1,12 +1,12 @@
(ns status-im2.subs.wallet.wallet (ns status-im2.subs.wallet.wallet
(:require [clojure.string :as string] (:require [clojure.string :as string]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.tokens :as tokens] [status-im.ethereum.tokens :as tokens]
[status-im.utils.currency :as currency] [status-im.utils.currency :as currency]
[utils.money :as money] [utils.money :as money]
[status-im2.config :as config] [status-im2.config :as config]
[utils.i18n :as i18n])) [utils.i18n :as i18n]
[status-im.wallet.utils :as wallet.utils]))
(re-frame/reg-sub (re-frame/reg-sub
:balance :balance
@ -19,7 +19,7 @@
:<- [:wallet] :<- [:wallet]
:<- [:profile/wallet-accounts] :<- [:profile/wallet-accounts]
(fn [[wallet accounts]] (fn [[wallet accounts]]
(get-in wallet [:accounts (:address (ethereum/get-default-account accounts)) :balance]))) (get-in wallet [:accounts (:address (wallet.utils/get-default-account accounts)) :balance])))
(re-frame/reg-sub (re-frame/reg-sub
:balances :balances

View File

@ -1,7 +1,32 @@
(ns utils.address (ns utils.address
;; TODO move to status-im2 (:require [utils.ethereum.eip.eip55 :as eip55]
(:require [status-im.ethereum.core :as ethereum] [clojure.string :as string]
[status-im.ethereum.eip55 :as eip55])) [native-module.core :as native-module]))
(def hex-prefix "0x")
(defn normalized-hex
[hex]
(when hex
(if (string/starts-with? hex hex-prefix)
hex
(str hex-prefix hex))))
(defn naked-address
[s]
(when s
(string/replace s hex-prefix "")))
(defn address?
[address]
(native-module/address? address))
(defn address=
[address1 address2]
(and address1
address2
(= (string/lower-case (normalized-hex address1))
(string/lower-case (normalized-hex address2)))))
(defn get-shortened-key (defn get-shortened-key
"Takes first and last 4 digits from address including leading 0x "Takes first and last 4 digits from address including leading 0x
@ -13,7 +38,7 @@
(defn get-shortened-checksum-address (defn get-shortened-checksum-address
[address] [address]
(when address (when address
(get-shortened-key (eip55/address->checksum (ethereum/normalized-hex address))))) (get-shortened-key (eip55/address->checksum (normalized-hex address)))))
(defn get-abbreviated-profile-url (defn get-abbreviated-profile-url
"The goal here is to generate a string that begins with "The goal here is to generate a string that begins with

View File

@ -0,0 +1,84 @@
(ns utils.ethereum.chain)
(def BSC-mainnet-chain-id 56)
(def BSC-testnet-chain-id 97)
;; IDs standardized in https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md#list-of-chain-ids
(def chains
{:mainnet {:id 1 :name "Mainnet"}
:xdai {:id 100 :name "xDai"}
:goerli {:id 5 :name "Goerli"}
:bsc {:id BSC-mainnet-chain-id
:name "BSC"}
:bsc-testnet {:id BSC-testnet-chain-id
:name "BSC tetnet"}})
(defn chain-id->chain-keyword
[i]
(or (some #(when (= i (:id (val %))) (key %)) chains)
:custom))
(defn chain-id->chain-name
[i]
(or (some #(when (= i (:id (val %))) (:name (val %))) chains)
:custom))
(defn chain-keyword->chain-id
[k]
(get-in chains [k :id]))
(defn chain-keyword->snt-symbol
[k]
(case k
:mainnet :SNT
:STT))
(defn testnet?
[id]
(contains? #{(chain-keyword->chain-id :goerli)
(chain-keyword->chain-id :bsc-testnet)}
id))
(defn network->chain-id
[network]
(get-in network [:config :NetworkId]))
(defn network->chain-keyword
[network]
(chain-id->chain-keyword (network->chain-id network)))
(defn binance-chain-id?
[chain-id]
(or (= BSC-mainnet-chain-id chain-id)
(= BSC-testnet-chain-id chain-id)))
(defn current-network
[db]
(let [networks (get db :networks/networks)
network-id (get db :networks/current-network)]
(get networks network-id)))
(defn binance-chain?
[db]
(-> db
current-network
network->chain-id
binance-chain-id?))
(defn network->chain-name
[network]
(-> network
network->chain-keyword
name))
(defn get-current-network
[m]
(get (:networks/networks m) (:networks/current-network m)))
(defn chain-keyword
[db]
(network->chain-keyword (get-current-network db)))
(defn chain-id
[db]
(network->chain-id (get-current-network db)))

View File

@ -0,0 +1,8 @@
(ns utils.ethereum.chain-test
(:require [cljs.test :refer-macros [deftest is]]
[utils.ethereum.chain :as chain]))
(deftest chain-id->chain-keyword
(is (= (chain/chain-id->chain-keyword 1) :mainnet))
(is (= (chain/chain-id->chain-keyword 5) :goerli))
(is (= (chain/chain-id->chain-keyword 5777) :custom)))

View File

@ -1,4 +1,4 @@
(ns status-im.ethereum.eip55 (ns utils.ethereum.eip.eip55
"Utility function related to [EIP55](https://eips.ethereum.org/EIPS/eip-55) "Utility function related to [EIP55](https://eips.ethereum.org/EIPS/eip-55)
This EIP standardize how ethereum addresses should be printed as strings to validate checksum. This EIP standardize how ethereum addresses should be printed as strings to validate checksum.

View File

@ -1,6 +1,6 @@
(ns status-im.ethereum.eip55-test (ns utils.ethereum.eip.eip55-test
(:require [cljs.test :refer-macros [deftest is]] (:require [cljs.test :refer-macros [deftest is]]
[status-im.ethereum.eip55 :as eip55])) [utils.ethereum.eip.eip55 :as eip55]))
(deftest valid-address-checksum? (deftest valid-address-checksum?
(is (= true (eip55/valid-address-checksum? "0x52908400098527886E0F7030069857D2E4169EE7"))) (is (= true (eip55/valid-address-checksum? "0x52908400098527886E0F7030069857D2E4169EE7")))

View File

@ -1,9 +0,0 @@
(ns utils.requests
(:require [utils.datetime :as datetime]))
(def request-cooldown-ms (* 24 60 60 1000))
(defn can-request-access-again?
[requested-at]
(> (datetime/timestamp) (+ (* requested-at 1000) request-cooldown-ms)))