Added utility function to test addresses according to EIP55.

Added pop-up message when addres checksum fails in wallet/send/enter recipient address.

Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
This commit is contained in:
mestorlx 2019-02-02 14:49:24 +01:00 committed by Julien Eluard
parent 51f6a173df
commit 0471d5fd72
No known key found for this signature in database
GPG Key ID: 6FD7DB5437FCBEF6
7 changed files with 48 additions and 4 deletions

View File

@ -63,7 +63,7 @@
:chat-settings :offline :update-status :invited :chat-send-eth :address
:new-public-group-chat :datetime-hour :wallet-settings
:datetime-ago-format :close-app-button :block :camera-access-error
:wallet-invalid-address :address-explication :remove
:wallet-invalid-address :wallet-invalid-address-checksum :address-explication :remove
:transactions-delete-content :transactions-unsigned-empty
:transaction-moved-text :add-members :sign-later-title
:yes :dapps :popular-tags :network-settings :twelve-words-in-correct-order

View File

@ -4,6 +4,7 @@
[status-im.contact.db :as contact.db]
[status-im.i18n :as i18n]
[status-im.utils.ethereum.core :as ethereum]
[status-im.utils.ethereum.eip55 :as eip55]
[status-im.utils.ethereum.eip681 :as eip681]
[status-im.utils.ethereum.ens :as ens]
[status-im.utils.handlers :as handlers]
@ -81,8 +82,10 @@
:ens-name recipient
:cb #(re-frame/dispatch [:wallet.send/set-recipient %])}}
(if (ethereum/address? recipient)
{:db (assoc-in db [:wallet :send-transaction :to] recipient)
:dispatch [:navigate-back]}
(if (eip55/valid-address-checksum? recipient)
{:db (assoc-in db [:wallet :send-transaction :to] recipient)
:dispatch [:navigate-back]}
{:ui/show-error (i18n/label :t/wallet-invalid-address-checksum {:data recipient})})
{:ui/show-error (i18n/label :t/wallet-invalid-address {:data recipient})})))))
(handlers/register-handler-fx

View File

@ -0,0 +1,22 @@
(ns status-im.utils.ethereum.eip55
"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.
e.g. 0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"
(:require [clojure.string :as string]
[status-im.utils.ethereum.core :as ethereum]))
(defn valid-address-checksum? [address]
"verify address checksum according to EIP 55"
(let [adHash (ethereum/naked-address (ethereum/sha3
(string/lower-case (ethereum/naked-address address))))]
(every? true?
(map-indexed (fn [idx char]
(if (> (compare char "9") 0)
(if (>= (js/parseInt (nth adHash idx) 16) 8)
; If true should be upper case
(<= (compare char "Z") 0)
; If not should be lower case
(> (compare char "Z") 0))
true)) (ethereum/naked-address address)))))

View File

@ -3,7 +3,7 @@ basic_user['passphrase'] = "tree weekend ceiling awkward universe pyramid glimps
basic_user['username'] = "Little Weighty Iberianmole"
basic_user['public_key'] = "0x040d3400f0ba80b2f6017a9021a66e042abc33cf7051ddf98a24a815c93d6c052ce2b7873d799f096325" \
"9f41c5a1bf08133dd4f3fe63ea1cceaa1e86ebc4bc42c9"
basic_user['address'] = "f184747445c3b85ceb147dfb136067cb93d95f1d"
basic_user['address'] = "f184747445c3B85CEb147DfB136067CB93d95F1D"
wallet_users = dict()

View File

@ -37,6 +37,7 @@
[status-im.test.utils.utils]
[status-im.test.utils.money]
[status-im.test.utils.clocks]
[status-im.test.utils.ethereum.eip55]
[status-im.test.utils.ethereum.eip681]
[status-im.test.utils.ethereum.core]
[status-im.test.utils.ethereum.abi-spec]
@ -107,6 +108,7 @@
'status-im.test.utils.utils
'status-im.test.utils.money
'status-im.test.utils.clocks
'status-im.test.utils.ethereum.eip55
'status-im.test.utils.ethereum.eip681
'status-im.test.utils.ethereum.core
'status-im.test.utils.ethereum.mnemonic

View File

@ -0,0 +1,16 @@
(ns status-im.test.utils.ethereum.eip55
(:require [cljs.test :refer-macros [deftest is testing]]
[status-im.utils.ethereum.eip55 :as eip55]))
(deftest valid-address-checksum?
(is (= true (eip55/valid-address-checksum? "0x52908400098527886E0F7030069857D2E4169EE7")))
(is (= true (eip55/valid-address-checksum? "0x8617E340B3D01FA5F11F306F4090FD50E238070D")))
(is (= true (eip55/valid-address-checksum? "0xde709f2102306220921060314715629080e2fb77")))
(is (= true (eip55/valid-address-checksum? "0x27b1fdb04752bbc536007a920d24acb045561c26")))
(is (= true (eip55/valid-address-checksum? "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed")))
(is (= true (eip55/valid-address-checksum? "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359")))
(is (= true (eip55/valid-address-checksum? "0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB")))
(is (= true (eip55/valid-address-checksum? "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb")))
(is (= false (eip55/valid-address-checksum? "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9adB")))
(is (= false (eip55/valid-address-checksum? "0x8617e340b3d01fa5f11f306f4090fd50e238070d")))
(is (= false (eip55/valid-address-checksum? "0xDE709F2102306220921060314715629080E2fB77"))))

View File

@ -115,6 +115,7 @@
"empty-chat-description": "There are no messages \nin this chat yet",
"camera-access-error": "To grant the required camera permission, please go to your system settings and make sure that Status > Camera is selected.",
"wallet-invalid-address": "Invalid address: \n {{data}}",
"wallet-invalid-address-checksum": "Error in address: \n {{data}}",
"welcome-to-status": "Welcome to Status",
"cryptokitty-name": "CryptoKitty #{{id}}",
"address-explication": "Your public key is used to generate your address on Ethereum and is a series of numbers and letters. You can find it easily in your profile",