[#13086] stateofus.eth ENS username is not connected with chat key after purchasing

Signed-off-by: andrey <motor4ik@gmail.com>
This commit is contained in:
andrey 2022-02-10 16:44:58 +01:00
parent c59089c7d3
commit aaf655abe4
No known key found for this signature in database
GPG Key ID: 89B67245FD2F0272
9 changed files with 86 additions and 104 deletions

View File

@ -2,18 +2,14 @@
(:refer-clojure :exclude [name]) (:refer-clojure :exclude [name])
(: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.abi-spec :as abi-spec]
[status-im.ethereum.contracts :as contracts]
[status-im.ethereum.core :as ethereum] [status-im.ethereum.core :as ethereum]
[status-im.ethereum.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]
[status-im.signing.core :as signing]
[status-im.navigation :as navigation] [status-im.navigation :as navigation]
[status-im.utils.datetime :as datetime] [status-im.utils.datetime :as datetime]
[status-im.utils.fx :as fx] [status-im.utils.fx :as fx]
[status-im.utils.money :as money]
[status-im.utils.random :as random] [status-im.utils.random :as random]
[status-im.bottom-sheet.core :as bottom-sheet])) [status-im.bottom-sheet.core :as bottom-sheet]))
@ -80,23 +76,6 @@
(assoc-in [:ens/registration :state] state) (assoc-in [:ens/registration :state] state)
(assoc-in [:ens/registration :address] address))})) (assoc-in [:ens/registration :address] address))}))
(fx/defn on-resolver-found
{:events [::resolver-found]}
[{:keys [db] :as cofx} resolver-contract address]
(let [{:keys [username custom-domain?]} (:ens/registration db)
{:keys [public-key]} (:multiaccount db)
{:keys [x y]} (ethereum/coordinates public-key)
namehash (ens/namehash (str username (when-not custom-domain?
".stateofus.eth")))]
(signing/eth-transaction-call
cofx
{:contract resolver-contract
:from address
:method "setPubkey(bytes32,bytes32,bytes32)"
:params [namehash x y]
:on-result [::save-username custom-domain? username true]
:on-error [::on-registration-failure]})))
(fx/defn save-username (fx/defn save-username
{:events [::save-username]} {:events [::save-username]}
[{:keys [db] :as cofx} custom-domain? username redirectToSummary] [{:keys [db] :as cofx} custom-domain? username redirectToSummary]
@ -112,19 +91,30 @@
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:preferred-name name {}))))) :preferred-name name {})))))
(fx/defn set-pub-key
{:events [::set-pub-key]}
[{:keys [db]}]
(let [{:keys [username address custom-domain?]} (:ens/registration db)
address (or address (ethereum/default-address db))
{:keys [public-key]} (:multiaccount db)
chain-id (ethereum/chain-id db)
username (fullname custom-domain? username)]
(ens/set-pub-key-prepare-tx
chain-id address username public-key
#(re-frame/dispatch [:signing.ui/sign
{:tx-obj %
:on-result [::save-username custom-domain? username true]
:on-error [::on-registration-failure]}]))))
(fx/defn on-input-submitted (fx/defn on-input-submitted
{:events [::input-submitted ::input-icon-pressed]} {:events [::input-submitted]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [{:keys [state username custom-domain? address]} (:ens/registration db) (let [{:keys [state username custom-domain?]} (:ens/registration db)]
registry-contract (get ens/ens-registries (ethereum/chain-keyword db))
ens-name (str username (when-not custom-domain?
".stateofus.eth"))]
(case state (case state
(:available :owned) (:available :owned)
(navigation/navigate-to-cofx cofx :ens-checkout {}) (navigation/navigate-to-cofx cofx :ens-checkout {})
:connected-with-different-key :connected-with-different-key
(ens/resolver registry-contract ens-name (re-frame/dispatch [::set-pub-key])
#(re-frame/dispatch [::resolver-found % address]))
:connected :connected
(save-username cofx custom-domain? username true) (save-username cofx custom-domain? username true)
;; for other states, we do nothing ;; for other states, we do nothing
@ -148,6 +138,8 @@
#(re-frame/dispatch [::name-resolved username #(re-frame/dispatch [::name-resolved username
(cond (cond
(not public-key) :owned (not public-key) :owned
(string/ends-with? % "0000000000000000000000000000000000000000000000000000000000000000")
:invalid
(= % public-key) :connected (= % public-key) :connected
:else :connected-with-different-key) :else :connected-with-different-key)
(eip55/address->checksum response)])) (eip55/address->checksum response)]))
@ -160,33 +152,19 @@
3 50 3 50
1 10)) 1 10))
;; (andrey) there is the method "register" in status-go, but im not sure how we could use it
;; because we still need to prepare tx and show it to user, and then have a condition to do not sign tx but
;; call register method instead, doesn't look like a good solution
(fx/defn register-name (fx/defn register-name
{:events [::register-name-pressed]} {:events [::register-name-pressed]}
[{:keys [db] :as cofx}] [{:keys [db]} address]
(let [{:keys [custom-domain? username address]} (let [{:keys [username]}
(:ens/registration db) (:ens/registration db)
{:keys [public-key]} (:multiaccount db) {:keys [public-key]} (:multiaccount db)
chain (ethereum/chain-keyword db) chain-id (ethereum/chain-id db)]
chain-id (ethereum/chain-id db) (ens/register-prepare-tx
amount (registration-cost chain-id) chain-id address username public-key
{:keys [x y]} (ethereum/coordinates public-key)] #(re-frame/dispatch [:signing.ui/sign
(stateofus/get-registrar {:tx-obj %
chain :on-result [:update-ens-tx-state-and-redirect :submitted username false]
(fn [contract] :on-error [::on-registration-failure]}]))))
(signing/eth-transaction-call
cofx
{:contract (contracts/get-address db :status/snt)
:method "approveAndCall(address,uint256,bytes)"
:from address
:params [contract
(money/unit->token amount 18)
(abi-spec/encode "register(bytes32,address,bytes32,bytes32)"
[(ethereum/sha3 username) address x y])]
:on-result [:update-ens-tx-state-and-redirect :submitted username custom-domain?]
:on-error [::on-registration-failure]})))))
(defn- valid-custom-domain? [username] (defn- valid-custom-domain? [username]
(and (ens/is-valid-eth-name? username) (and (ens/is-valid-eth-name? username)

View File

@ -1,12 +1,5 @@
(ns status-im.ethereum.ens (ns status-im.ethereum.ens
"
https://docs.ens.domains/en/latest/index.html
https://eips.ethereum.org/EIPS/eip-137
https://eips.ethereum.org/EIPS/eip-181
"
(:refer-clojure :exclude [name])
(:require [clojure.string :as string] (:require [clojure.string :as string]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.ethereum.abi-spec :as abi-spec])) [status-im.ethereum.abi-spec :as abi-spec]))
@ -16,36 +9,10 @@
:testnet "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e" :testnet "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"
:rinkeby "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"}) :rinkeby "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"})
(def default-namehash "0000000000000000000000000000000000000000000000000000000000000000")
(def default-address "0x0000000000000000000000000000000000000000") (def default-address "0x0000000000000000000000000000000000000000")
(def default-key "0x0400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") (def default-key "0x0400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
(def default-hash "0x0000000000000000000000000000000000000000000000000000000000000000") (def default-hash "0x0000000000000000000000000000000000000000000000000000000000000000")
(defn namehash
[s]
(ethereum/normalized-hex
(if (string/blank? s)
default-namehash
(let [[label remainder] (-> s
string/lower-case
(string/split #"\." 2))]
(if-not (seq label)
default-namehash
(ethereum/sha3 (str (namehash remainder)
(subs (ethereum/sha3 label) 2))))))))
(defn resolver
[registry ens-name cb]
(json-rpc/eth-call
{:contract registry
:method "resolver(bytes32)"
:params [(namehash ens-name)]
:outputs ["address"]
:on-error #(cb "0x")
:on-success
(fn [[address]]
(cb (when-not (= address default-address) address)))}))
(defn valid-eth-name-prefix? (defn valid-eth-name-prefix?
[prefix] [prefix]
(not (not
@ -72,8 +39,7 @@
{:pre [(is-valid-eth-name? ens-name)]} {:pre [(is-valid-eth-name? ens-name)]}
(json-rpc/call {:method "ens_publicKeyOf" (json-rpc/call {:method "ens_publicKeyOf"
:params [chain-id ens-name] :params [chain-id ens-name]
:on-success (fn [result] :on-success cb
(cb (str "0x04" (subs result 2))))
;;at some point infura started to return execution reverted error instead of "0x" result ;;at some point infura started to return execution reverted error instead of "0x" result
;;our code expects "0x" result ;;our code expects "0x" result
:on-error #(cb "0x")})) :on-error #(cb "0x")}))
@ -98,4 +64,16 @@
:params [chain-id ens-name] :params [chain-id ens-name]
:on-success :on-success
;;NOTE: returns a timestamp in s and we want ms ;;NOTE: returns a timestamp in s and we want ms
#(cb (* (js/Number (abi-spec/hex-to-number %)) 1000))})) #(cb (* (js/Number (abi-spec/hex-to-number %)) 1000))}))
(defn register-prepare-tx
[chain-id from ens-name pubkey cb]
(json-rpc/call {:method "ens_registerPrepareTx"
:params [chain-id {:from from} ens-name pubkey]
:on-success cb}))
(defn set-pub-key-prepare-tx
[chain-id from ens-name pubkey cb]
(json-rpc/call {:method "ens_setPubKeyPrepareTx"
:params [chain-id {:from from} ens-name pubkey]
:on-success cb}))

View File

@ -1,11 +0,0 @@
(ns status-im.ethereum.ens-test
(:require [cljs.test :refer-macros [deftest is]]
[status-im.ethereum.ens :as ens]))
(deftest namehash
(is (= (str "0x" ens/default-namehash) (ens/namehash nil)))
(is (= (str "0x" ens/default-namehash) (ens/namehash "")))
(is (= "0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae"
(ens/namehash "eth")))
(is (= "0xde9b09fd7c5f901e23a3f19fecc54828e9c848539801e86591bd9801b019f84f"
(ens/namehash "foo.eth"))))

View File

@ -35,6 +35,8 @@
"ens_ownerOf" {} "ens_ownerOf" {}
"ens_contentHash" {} "ens_contentHash" {}
"ens_resourceURL" {} "ens_resourceURL" {}
"ens_registerPrepareTx" {}
"ens_setPubKeyPrepareTx" {}
"net_version" {} "net_version" {}
"web3_clientVersion" {} "web3_clientVersion" {}
"shh_generateSymKeyFromPassword" {} "shh_generateSymKeyFromPassword" {}

View File

@ -41,7 +41,8 @@
[status-im.data-store.visibility-status-updates :as visibility-status-updates-store] [status-im.data-store.visibility-status-updates :as visibility-status-updates-store]
[status-im.ui.components.react :as react] [status-im.ui.components.react :as react]
[status-im.utils.platform :as platform] [status-im.utils.platform :as platform]
[status-im.ethereum.tokens :as tokens])) [status-im.ethereum.tokens :as tokens]
[clojure.string :as string]))
(re-frame/reg-fx (re-frame/reg-fx
::initialize-communities-enabled ::initialize-communities-enabled
@ -97,10 +98,37 @@
[] []
accounts)) accounts))
;;TODO remove this code after all invalid names will be fixed (ask chu or flexsurfer)
(def invalid-addrr
#{"0x9575cf381f71368a54e09b8138ebe046a1ef31ce93e6c37661513b21faaf741e"
"0x56fa5de8cd4f2a3cbc122e7c51ac8690c6fc739b7c3724add97d0c55cc783d45"
"0xf0e49d178fa34ac3ade4625e144f51e5f982434f0912bcbe23b6467343f48305"
"0x60d1bf67e9d0d34368a6422c55f034230cc0997b186dd921fd18e89b7f0df5f2"
"0x5fe69d562990616a02f4a5f934aa973b27bf02c4fc774f9ad82f105379f16789"
"0xf1cabf2d74576ef76dfcb1182fd59a734a26c95ea6e68fc8f91ca4bfa1ea0594"
"0x21d8ce6c0e32481506f98218920bee88f03d9c1b45dab3546948ccc34b1aadea"
"0xbf7a74b39090fb5b1366f61fb4ac3ecc4b7f99f0fd3cb326dc5c18c58d58d7b6"
"0xeeb570494d442795235589284100812e4176e9c29d151a81df43b6286ef66c49"
"0x86a12d91c813f69a53349ff640e32af97d5f5c1f8d42d54cf4c8aa8dea231955"
"0x0011a30f5b2023bc228f6dd5608b3e7149646fa83f33350926ceb1925af78f08"})
(fx/defn check-invalid-ens [{:keys [db]}]
(async-storage/get-item
:invalid-ens-name-seen
(fn [already-seen]
(when (and (not already-seen)
(boolean (get invalid-addrr (ethereum/sha3 (string/lower-case (ethereum/default-address db))))))
(utils/show-popup
(i18n/label :t/warning)
(i18n/label :t/ens-username-invalid-name-warning)
#(async-storage/set-item! :invalid-ens-name-seen true)))))
nil)
(fx/defn initialize-wallet (fx/defn initialize-wallet
{:events [::initialize-wallet]} {:events [::initialize-wallet]}
[{:keys [db] :as cofx} accounts tokens custom-tokens [{:keys [db] :as cofx} accounts tokens custom-tokens
favourites scan-all-tokens? new-account?] favourites scan-all-tokens? new-account?]
(check-invalid-ens cofx)
(fx/merge (fx/merge
cofx cofx
{:db (assoc db :multiaccount/accounts {:db (assoc db :multiaccount/accounts

View File

@ -439,6 +439,7 @@
:message {:address :data :typed? } - message data to sign :message {:address :data :typed? } - message data to sign
:on-result - re-frame event vector :on-result - re-frame event vector
:on-error - re-frame event vector}" :on-error - re-frame event vector}"
{:events [:signing.ui/sign]}
[{:keys [db] :as cofx} tx] [{:keys [db] :as cofx} tx]
(fx/merge cofx (fx/merge cofx
{:db (update db :signing/queue conj (normalize-tx-obj db tx))} {:db (update db :signing/queue conj (normalize-tx-obj db tx))}

View File

@ -106,7 +106,7 @@
(:available :connected :connected-with-different-key :owned) (:available :connected :connected-with-different-key :owned)
[react/touchable-highlight [react/touchable-highlight
{:on-press #(debounce/dispatch-and-chill [::ens/input-icon-pressed] 3000)} {:on-press #(debounce/dispatch-and-chill [::ens/input-submitted] 3000)}
[icon-wrapper colors/blue [icon-wrapper colors/blue
[icons/icon :main-icons/arrow-right {:color colors/white-persist}]]] [icons/icon :main-icons/arrow-right {:color colors/white-persist}]]]
@ -150,6 +150,10 @@
[help-message-text-element [help-message-text-element
:t/ens-username-owned :t/ens-username-owned
:t/ens-username-connected-with-different-key] :t/ens-username-connected-with-different-key]
:invalid
[help-message-text-element
:t/ens-username-owned
:t/ens-username-registration-invalid]
(if custom-domain? (if custom-domain?
(case state (case state
:too-short :too-short
@ -330,7 +334,7 @@
:right [react/view {:padding-horizontal 8} :right [react/view {:padding-horizontal 8}
[quo/button [quo/button
{:disabled (or (not @checked?) (not sufficient-funds?)) {:disabled (or (not @checked?) (not sufficient-funds?))
:on-press #(debounce/dispatch-and-chill [::ens/register-name-pressed] 2000)} :on-press #(debounce/dispatch-and-chill [::ens/register-name-pressed address] 2000)}
(if sufficient-funds? (if sufficient-funds?
(i18n/label :t/ens-register) (i18n/label :t/ens-register)
(i18n/label :t/not-enough-snt))]]}]])))) (i18n/label :t/not-enough-snt))]]}]]))))

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>", "_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im", "owner": "status-im",
"repo": "status-go", "repo": "status-go",
"version": "v0.94.4", "version": "v0.94.6",
"commit-sha1": "4cc53630d5cbe10ce28103154bd4cfe926176ccc", "commit-sha1": "3cc683587dabf16e17a987d1af7b2003faf09d60",
"src-sha256": "082wrqwjk27cijfd4vl7ma5qpd6vg01kh3k80va9l9693vn3ljdh" "src-sha256": "1d8f2x7na3scvsgarmfqay5f6nb5x9sh2m6af7lh8d295ia70ha8"
} }

View File

@ -530,6 +530,8 @@
"ens-username-owned-continue": "Continuing will connect this username with your chat key.", "ens-username-owned-continue": "Continuing will connect this username with your chat key.",
"ens-username-taken": "Username already taken :(", "ens-username-taken": "Username already taken :(",
"ens-name-not-found": "Cannot resolve ENS name", "ens-name-not-found": "Cannot resolve ENS name",
"ens-username-registration-invalid": "Warning! Registration process has finished in invalid state. DO NOT USE the name for wallet transactions and reach out to our support at support@status.im",
"ens-username-invalid-name-warning": "Registration process of one of your ens names has finished in invalid state. DO NOT USE the name for wallet transactions and reach out to our support at support@status.im",
"enter-12-words": "Enter the 12 words of your seed phrase, separated by single spaces", "enter-12-words": "Enter the 12 words of your seed phrase, separated by single spaces",
"enter-a-private-key": "Enter a private key", "enter-a-private-key": "Enter a private key",
"enter-a-seed-phrase": "Enter a seed phrase", "enter-a-seed-phrase": "Enter a seed phrase",