enforce lowercase for namehash

Signed-off-by: Eric Dvorsak <eric@dvorsak.fr>
This commit is contained in:
Eric Dvorsak 2018-08-11 05:14:54 +02:00
parent 1769bfb695
commit 3a982e5d6b
No known key found for this signature in database
GPG Key ID: 932AC1CE5F05DE0C
4 changed files with 12 additions and 6 deletions

View File

@ -17,7 +17,7 @@
:new-chat/set-new-identity
(fn [{{:keys [web3 network network-status] :as db} :db} [_ new-identity]]
(let [new-identity-error (db/validate-pub-key new-identity (:account/account db))]
(if (stateofus/is-stateofus-name? new-identity)
(if (stateofus/is-valid-name? new-identity)
(let [network (get-in db [:account/account :networks network])
chain (ethereum/network->chain-keyword network)]
{:resolve-whisper-identity {:web3 web3

View File

@ -97,7 +97,11 @@
(defn hex->bignumber [s]
(money/bignumber (if (= s hex-prefix) 0 s)))
(defn hex->address [s]
(defn hex->address
"When hex value is 66 char in length (2 for 0x, 64 for
the 32 bytes used by abi-spec for an address), only keep
the part that constitute the address and normalize it,"
[s]
(when (= 66 (count s))
(normalized-address (subs s 26))))

View File

@ -19,7 +19,9 @@
(defn namehash [s]
(ethereum/normalized-address (if (string/blank? s)
default-namehash
(let [[label remainder] (string/split s #"\." 2)]
(let [[label remainder] (-> s
string/lower-case
(string/split #"\." 2))]
(ethereum/sha3 (+ (namehash remainder)
(subs (ethereum/sha3 label) 2))
{:encoding "hex"})))))

View File

@ -4,11 +4,11 @@
[status-im.utils.ethereum.core :as ethereum]
[status-im.utils.ethereum.ens :as ens]))
(defn is-stateofus-name? [ens-name]
(defn is-valid-name? [ens-name]
(string/ends-with? ens-name ".stateofus.eth"))
(defn addr [web3 registry ens-name cb]
{:pre [(is-stateofus-name? ens-name)]}
{:pre [(is-valid-name? ens-name)]}
(ens/resolver web3
registry
ens-name
@ -19,7 +19,7 @@
TODO: https://solidity.readthedocs.io/en/develop/abi-spec.html needs to be implemented
to replace this by dynamic parameters"
[web3 registry ens-name cb]
{:pre [(is-stateofus-name? ens-name)]}
{:pre [(is-valid-name? ens-name)]}
(ens/resolver web3
registry
ens-name