diff --git a/CHANGELOG.md b/CHANGELOG.md index 50ccd2b456..06fcc18167 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed ### Changed +- Improved validation in account recovery. We now show a warning if any words are not from our mnemonic dictionary. ## [0.9.25 - Unreleased] ### Added diff --git a/src/status_im/translations/en.cljs b/src/status_im/translations/en.cljs index a7c4fe9d1d..addc0f18c1 100644 --- a/src/status_im/translations/en.cljs +++ b/src/status_im/translations/en.cljs @@ -32,6 +32,8 @@ :mailserver-connection-error "Could not connect to mailserver" :dont-allow "Don't Allow" :custom "Custom" + :required-field "Required field" + :are-you-sure? "Are you sure?" :camera-access-error "To grant the required camera permission, please go to your system settings and make sure that Status > Camera is selected." :photos-access-error "To grant the required photos permission, please go to your system settings and make sure that Status > Photos is selected." @@ -172,7 +174,6 @@ :enter-word "Enter word" :check-your-recovery-phrase "Check your recovery phrase" :wrong-word "Wrong word" - :are-you-sure? "Are you sure?" :are-you-sure-description "You will not be able to see the whole recovery phrase again" :you-are-all-set "You’re all set!" :you-are-all-set-description "Now if you lose your phone you can restore your account and wallet using the recovery phrase." @@ -393,6 +394,12 @@ :recover "Recover" :twelve-words-in-correct-order "12 words in correct order" :enter-12-words "Enter the 12 words of your recovery phrase, separated by single spaces" + :recover-password-too-short "Password is too short" + :recovery-phrase-invalid "Recovery phrase is invalid" + :recovery-phrase-unknown-words "Some words might be misspelled" + :recovery-typo-dialog-title "Is the phrase correct?" + :recovery-typo-dialog-description "If you enter the wrong words, you will create a new account instead of recovering an old one." + :recovery-confirm-phrase "Confirm phrase" ;;accounts :recover-access "Recover access" diff --git a/src/status_im/ui/screens/accounts/recover/events.cljs b/src/status_im/ui/screens/accounts/recover/events.cljs index e1fab1ce73..a99cd6c530 100644 --- a/src/status_im/ui/screens/accounts/recover/events.cljs +++ b/src/status_im/ui/screens/accounts/recover/events.cljs @@ -13,6 +13,26 @@ ;;;; Handlers +(handlers/register-handler-fx + :recover/set-phrase + (fn [cofx [_ recovery-phrase]] + (models/set-phrase recovery-phrase cofx))) + +(handlers/register-handler-fx + :recover/validate-phrase + (fn [cofx _] + (models/validate-phrase cofx))) + +(handlers/register-handler-fx + :recover/set-password + (fn [cofx [_ masked-password]] + (models/set-password masked-password cofx))) + +(handlers/register-handler-fx + :recover/validate-password + (fn [cofx _] + (models/validate-password cofx))) + (handlers/register-handler-fx :account-recovered (fn [cofx [_ result password]] @@ -25,5 +45,10 @@ (handlers/register-handler-fx :recover-account - (fn [cofx [_ masked-passphrase password]] - (models/recover-account masked-passphrase password cofx))) + (fn [cofx _] + (models/recover-account cofx))) + +(handlers/register-handler-fx + :recover-account-with-checks + (fn [cofx _] + (models/recover-account-with-checks cofx))) diff --git a/src/status_im/ui/screens/accounts/recover/models.cljs b/src/status_im/ui/screens/accounts/recover/models.cljs index 1941c40f0e..eb52f733d9 100644 --- a/src/status_im/ui/screens/accounts/recover/models.cljs +++ b/src/status_im/ui/screens/accounts/recover/models.cljs @@ -10,13 +10,31 @@ [status-im.utils.security :as security] [status-im.utils.signing-phrase.core :as signing-phrase] [status-im.utils.hex :as utils.hex] - [status-im.constants :as constants])) + [status-im.constants :as constants] + [cljs.spec.alpha :as spec] + [status-im.ui.screens.accounts.db :as db] + [status-im.utils.ethereum.mnemonic :as mnemonic] + [status-im.i18n :as i18n])) + +;;;; helpers + +(defn check-password-errors [password] + (cond (string/blank? password) :required-field + (not (db/valid-length? password)) :recover-password-too-short)) + +(defn check-phrase-errors [recovery-phrase] + (cond (string/blank? recovery-phrase) :required-field + (not (mnemonic/valid-phrase? recovery-phrase)) :recovery-phrase-invalid)) + +(defn check-phrase-warnings [recovery-phrase] + (when (not (mnemonic/status-generated-phrase? recovery-phrase)) + :recovery-phrase-unknown-words)) ;;;; FX (defn recover-account-fx! [masked-passphrase password] (status/recover-account - (security/unmask masked-passphrase) + (mnemonic/sanitize-passphrase (security/unmask masked-passphrase)) password (fn [result] ;; here we deserialize result, dissoc mnemonic and serialize the result again @@ -29,6 +47,27 @@ ;;;; Handlers +(defn set-phrase [recovery-phrase {:keys [db]}] + {:db (update db :accounts/recover assoc + :passphrase (string/lower-case recovery-phrase) + :passphrase-valid? (not (check-phrase-errors recovery-phrase)))}) + +(defn validate-phrase [{:keys [db]}] + (let [recovery-phrase (get-in db [:accounts/recover :passphrase])] + {:db (update db :accounts/recover assoc + :passphrase-error (check-phrase-errors recovery-phrase) + :passphrase-warning (check-phrase-warnings recovery-phrase))})) + +(defn set-password [masked-password {:keys [db]}] + (let [password (security/unmask masked-password)] + {:db (update db :accounts/recover assoc + :password password + :password-valid? (not (check-password-errors password)))})) + +(defn validate-password [{:keys [db]}] + (let [password (get-in db [:accounts/recover :password])] + {:db (assoc-in db [:accounts/recover :password-error] (check-password-errors password))})) + (defn on-account-recovered [result password {:keys [db]}] (let [data (types/json->clj result) public-key (:pubkey data) @@ -51,10 +90,20 @@ (assoc :dispatch-later [{:ms 2000 :dispatch [:account-recovered-navigate]}]))))) (defn account-recovered-navigate [{:keys [db]}] - {:db (assoc-in db [:accounts/recover :processing] false) + {:db (assoc-in db [:accounts/recover :processing?] false) :dispatch-n [[:navigate-to-clean :home] [:request-notifications]]}) -(defn recover-account [masked-passphrase password {:keys [db]}] - {:db (assoc-in db [:accounts/recover :processing] true) - :recover-account-fx [masked-passphrase password]}) +(defn recover-account [{:keys [db]}] + (let [{:keys [password passphrase]} (:accounts/recover db)] + {:db (assoc-in db [:accounts/recover :processing?] true) + :recover-account-fx [(security/mask-data passphrase) password]})) + +(defn recover-account-with-checks [{:keys [db] :as cofx}] + (let [{:keys [passphrase]} (:accounts/recover db)] + (if (mnemonic/status-generated-phrase? passphrase) + (recover-account cofx) + {:show-confirmation {:title (i18n/label :recovery-typo-dialog-title) + :content (i18n/label :recovery-typo-dialog-description) + :confirm-button-text (i18n/label :recovery-confirm-phrase) + :on-accept #(re-frame/dispatch [:recover-account])}}))) diff --git a/src/status_im/ui/screens/accounts/recover/navigation.cljs b/src/status_im/ui/screens/accounts/recover/navigation.cljs index b3ecb2acb4..3d09b7de21 100644 --- a/src/status_im/ui/screens/accounts/recover/navigation.cljs +++ b/src/status_im/ui/screens/accounts/recover/navigation.cljs @@ -3,4 +3,4 @@ (defmethod nav/preload-data! :recover [db] - (update db :accounts/recover dissoc :password :passphrase :processing)) \ No newline at end of file + (update db :accounts/recover dissoc :password :passphrase :processing?)) \ No newline at end of file diff --git a/src/status_im/ui/screens/accounts/recover/styles.cljs b/src/status_im/ui/screens/accounts/recover/styles.cljs index e449baa730..4c551aef1b 100644 --- a/src/status_im/ui/screens/accounts/recover/styles.cljs +++ b/src/status_im/ui/screens/accounts/recover/styles.cljs @@ -5,6 +5,12 @@ {:flex 1 :background-color colors/white}) +(def inputs-container + {:margin 16}) + +(def password-input + {:margin-top 10}) + (def bottom-button-container {:flex-direction :row :margin-horizontal 12 diff --git a/src/status_im/ui/screens/accounts/recover/views.cljs b/src/status_im/ui/screens/accounts/recover/views.cljs index 5ca80a0691..17498da90b 100644 --- a/src/status_im/ui/screens/accounts/recover/views.cljs +++ b/src/status_im/ui/screens/accounts/recover/views.cljs @@ -1,26 +1,22 @@ (ns status-im.ui.screens.accounts.recover.views (:require-macros [status-im.utils.views :refer [defview letsubs]]) - (:require [clojure.string :as string] - [re-frame.core :as re-frame] + (:require [re-frame.core :as re-frame] [reagent.core :as reagent] [status-im.ui.components.text-input.view :as text-input] [status-im.ui.components.react :as react] [status-im.ui.components.status-bar.view :as status-bar] - [status-im.ui.components.styles :as components.styles] [status-im.ui.components.toolbar.view :as toolbar] [status-im.i18n :as i18n] [status-im.ui.screens.accounts.recover.styles :as styles] - [status-im.ui.screens.accounts.db :as db] + [status-im.ui.components.styles :as components.styles] [status-im.utils.config :as config] - [status-im.utils.ethereum.core :as ethereum] + [status-im.utils.core :as utils.core] [status-im.react-native.js-dependencies :as js-dependencies] - [cljs.spec.alpha :as spec] [status-im.ui.components.common.common :as components.common] [status-im.utils.security :as security])) -(defview passphrase-input [passphrase] - (letsubs [error [:get-in [:accounts/recover :passphrase-error]] - input-ref (reagent/atom nil)] +(defview passphrase-input [passphrase error warning] + (letsubs [input-ref (reagent/atom nil)] {:component-did-mount (fn [_] (when config/testfairy-enabled? (.hideView js-dependencies/testfairy @input-ref)))} [text-input/text-input-with-label @@ -32,47 +28,47 @@ :multiline true :default-value passphrase :auto-correct false - :on-change-text #(re-frame/dispatch [:set-in [:accounts/recover :passphrase] (string/lower-case %)]) - :error error}])) + :on-change-text #(re-frame/dispatch [:recover/set-phrase %]) + :on-blur #(re-frame/dispatch [:recover/validate-phrase]) + :error (cond error (i18n/label error) + warning (i18n/label warning))}])) -(defview password-input [password] - (letsubs [error [:get-in [:accounts/recover :password-error]]] - [react/view {:style {:margin-top 10} - :important-for-accessibility :no-hide-descendants} - [text-input/text-input-with-label - {:label (i18n/label :t/password) - :placeholder (i18n/label :t/enter-password) - :default-value password - :auto-focus false - :on-change-text #(re-frame/dispatch [:set-in [:accounts/recover :password] %]) - :secure-text-entry true - :error error}]])) +(defview password-input [password error] + [react/view {:style styles/password-input + :important-for-accessibility :no-hide-descendants} + [text-input/text-input-with-label + {:label (i18n/label :t/password) + :placeholder (i18n/label :t/enter-password) + :default-value password + :auto-focus false + :on-change-text #(re-frame/dispatch [:recover/set-password (security/mask-data %)]) + :on-blur #(re-frame/dispatch [:recover/validate-password]) + :secure-text-entry true + :error (when error (i18n/label error))}]]) (defview recover [] - (letsubs [{:keys [passphrase password processing]} [:get :accounts/recover]] - (let [words (ethereum/passphrase->words passphrase) - valid-form? (and - (ethereum/valid-words? words) - (spec/valid? ::db/password password))] + (letsubs [{:keys [passphrase password processing passphrase-valid? password-valid? + password-error passphrase-error passphrase-warning processing?]} [:get-recover-account]] + (let [valid-form? (and password-valid? passphrase-valid?)] [react/keyboard-avoiding-view {:style styles/screen-container} [status-bar/status-bar] [toolbar/toolbar nil toolbar/default-nav-back [toolbar/content-title (i18n/label :t/sign-in-to-another)]] [components.common/separator] - [react/view {:margin 16} - [passphrase-input (or passphrase "")] - [password-input (or password "")]] - [react/view {:flex 1}] + [react/view styles/inputs-container + [passphrase-input (or passphrase "") passphrase-error passphrase-warning] + [password-input (or password "") password-error]] + [react/view components.styles/flex] (if processing [react/view styles/processing-view [react/activity-indicator {:animating true}] - [react/i18n-text {:style styles/sign-you-in :key :sign-you-in}]] + [react/i18n-text {:style styles/sign-you-in + :key :sign-you-in}]] [react/view {:style styles/bottom-button-container} - [react/view {:style {:flex 1}}] + [react/view {:style components.styles/flex}] [components.common/bottom-button {:forward? true :label (i18n/label :t/sign-in) - :disabled? (not valid-form?) - :on-press (fn [_] - (let [masked-passphrase (security/mask-data (ethereum/words->passphrase words))] - (re-frame/dispatch [:recover-account masked-passphrase password])))}]])]))) + :disabled? (or processing? (not valid-form?)) + :on-press (utils.core/wrap-call-once! + #(re-frame/dispatch [:recover-account-with-checks]))}]])]))) diff --git a/src/status_im/ui/screens/accounts/subs.cljs b/src/status_im/ui/screens/accounts/subs.cljs index b0fdf0fb36..54f681e5ef 100644 --- a/src/status_im/ui/screens/accounts/subs.cljs +++ b/src/status_im/ui/screens/accounts/subs.cljs @@ -1,31 +1,40 @@ (ns status-im.ui.screens.accounts.subs - (:require [re-frame.core :refer [reg-sub subscribe]] + (:require [re-frame.core :as re-frame] [clojure.string :as string] [status-im.ui.screens.accounts.db :as db] [status-im.utils.ethereum.core :as ethereum] [cljs.spec.alpha :as spec])) -(reg-sub :get-current-public-key - (fn [db] - (:current-public-key db))) +(re-frame/reg-sub + :get-current-public-key + (fn [db] + (:current-public-key db))) -(reg-sub :get-accounts - (fn [db] - (:accounts/accounts db))) +(re-frame/reg-sub + :get-accounts + (fn [db] + (:accounts/accounts db))) -(reg-sub :get-current-account - (fn [db] - (:account/account db))) +(re-frame/reg-sub + :get-current-account + (fn [db] + (:account/account db))) -(reg-sub :get-current-account-hex - :<- [:get-current-account] - (fn [{:keys [address]}] - (ethereum/normalized-address address))) +(re-frame/reg-sub + :get-current-account-hex + :<- [:get-current-account] + (fn [{:keys [address]}] + (ethereum/normalized-address address))) -(reg-sub +(re-frame/reg-sub :get-account-creation-next-enabled? (fn [{:accounts/keys [create]}] (let [{:keys [step password password-confirm name]} create] (or (and password (= :enter-password step) (spec/valid? ::db/password password)) (and password-confirm (= :confirm-password step) (spec/valid? ::db/password password-confirm)) (and name (= :enter-name step) (not (string/blank? name))))))) + +(re-frame/reg-sub + :get-recover-account + (fn [db] + (:accounts/recover db))) diff --git a/src/status_im/ui/screens/browser/subs.cljs b/src/status_im/ui/screens/browser/subs.cljs index 7781606f5a..6852c2cc36 100644 --- a/src/status_im/ui/screens/browser/subs.cljs +++ b/src/status_im/ui/screens/browser/subs.cljs @@ -1,7 +1,10 @@ (ns status-im.ui.screens.browser.subs (:require [re-frame.core :as re-frame])) -(re-frame/reg-sub :browsers :browser/browsers) +(re-frame/reg-sub + :browsers + (fn [db _] + (:browser/browsers db))) (re-frame/reg-sub :get-current-browser diff --git a/src/status_im/utils/ethereum/core.cljs b/src/status_im/utils/ethereum/core.cljs index 32565bd0d7..b44da489ff 100644 --- a/src/status_im/utils/ethereum/core.cljs +++ b/src/status_im/utils/ethereum/core.cljs @@ -25,28 +25,6 @@ (defn network-with-upstream-rpc? [network] (get-in network [:config :UpstreamConfig :Enabled])) -(defn passphrase->words [s] - (when s - (-> (string/trim s) - (string/replace-all #"\s+" " ") - (string/split #" ")))) - -(defn words->passphrase [v] - (string/join " " v)) - -(def valid-word-counts #{12 15 18 21 24}) - -(defn valid-word-counts? [v] - (boolean (valid-word-counts (count v)))) - -(defn- valid-word? [s] - (re-matches #"^[A-z]+$" s)) - -(defn valid-words? [v] - (and - (valid-word-counts? v) - (every? valid-word? v))) - (def hex-prefix "0x") (defn normalized-address [address] diff --git a/src/status_im/utils/ethereum/mnemonic.cljs b/src/status_im/utils/ethereum/mnemonic.cljs new file mode 100644 index 0000000000..93ff129e60 --- /dev/null +++ b/src/status_im/utils/ethereum/mnemonic.cljs @@ -0,0 +1,37 @@ +(ns status-im.utils.ethereum.mnemonic + (:require [clojure.string :as string])) + +(def dictionary + #{"abandon", "ability", "able", "about", "above", "absent", "absorb", "abstract", "absurd", "abuse", "access", "accident", "account", "accuse", "achieve", "acid", "acoustic", "acquire", "across", "act", "action", "actor", "actress", "actual", "adapt", "add", "addict", "address", "adjust", "admit", "adult", "advance", "advice", "aerobic", "affair", "afford", "afraid", "again", "age", "agent", "agree", "ahead", "aim", "air", "airport", "aisle", "alarm", "album", "alcohol", "alert", "alien", "all", "alley", "allow", "almost", "alone", "alpha", "already", "also", "alter", "always", "amateur", "amazing", "among", "amount", "amused", "analyst", "anchor", "ancient", "anger", "angle", "angry", "animal", "ankle", "announce", "annual", "another", "answer", "antenna", "antique", "anxiety", "any", "apart", "apology", "appear", "apple", "approve", "april", "arch", "arctic", "area", "arena", "argue", "arm", "armed", "armor", "army", "around", "arrange", "arrest", "arrive", "arrow", "art", "artefact", "artist", "artwork", "ask", "aspect", "assault", "asset", "assist", "assume", "asthma", "athlete", "atom", "attack", "attend", "attitude", "attract", "auction", "audit", "august", "aunt", "author", "auto", "autumn", "average", "avocado", "avoid", "awake", "aware", "away", "awesome", "awful", "awkward", "axis", "baby", "bachelor", "bacon", "badge", "bag", "balance", "balcony", "ball", "bamboo", "banana", "banner", "bar", "barely", "bargain", "barrel", "base", "basic", "basket", "battle", "beach", "bean", "beauty", "because", "become", "beef", "before", "begin", "behave", "behind", "believe", "below", "belt", "bench", "benefit", "best", "betray", "better", "between", "beyond", "bicycle", "bid", "bike", "bind", "biology", "bird", "birth", "bitter", "black", "blade", "blame", "blanket", "blast", "bleak", "bless", "blind", "blood", "blossom", "blouse", "blue", "blur", "blush", "board", "boat", "body", "boil", "bomb", "bone", "bonus", "book", "boost", "border", "boring", "borrow", "boss", "bottom", "bounce", "box", "boy", "bracket", "brain", "brand", "brass", "brave", "bread", "breeze", "brick", "bridge", "brief", "bright", "bring", "brisk", "broccoli", "broken", "bronze", "broom", "brother", "brown", "brush", "bubble", "buddy", "budget", "buffalo", "build", "bulb", "bulk", "bullet", "bundle", "bunker", "burden", "burger", "burst", "bus", "business", "busy", "butter", "buyer", "buzz", "cabbage", "cabin", "cable", "cactus", "cage", "cake", "call", "calm", "camera", "camp", "can", "canal", "cancel", "candy", "cannon", "canoe", "canvas", "canyon", "capable", "capital", "captain", "car", "carbon", "card", "cargo", "carpet", "carry", "cart", "case", "cash", "casino", "castle", "casual", "cat", "catalog", "catch", "category", "cattle", "caught", "cause", "caution", "cave", "ceiling", "celery", "cement", "census", "century", "cereal", "certain", "chair", "chalk", "champion", "change", "chaos", "chapter", "charge", "chase", "chat", "cheap", "check", "cheese", "chef", "cherry", "chest", "chicken", "chief", "child", "chimney", "choice", "choose", "chronic", "chuckle", "chunk", "churn", "cigar", "cinnamon", "circle", "citizen", "city", "civil", "claim", "clap", "clarify", "claw", "clay", "clean", "clerk", "clever", "click", "client", "cliff", "climb", "clinic", "clip", "clock", "clog", "close", "cloth", "cloud", "clown", "club", "clump", "cluster", "clutch", "coach", "coast", "coconut", "code", "coffee", "coil", "coin", "collect", "color", "column", "combine", "come", "comfort", "comic", "common", "company", "concert", "conduct", "confirm", "congress", "connect", "consider", "control", "convince", "cook", "cool", "copper", "copy", "coral", "core", "corn", "correct", "cost", "cotton", "couch", "country", "couple", "course", "cousin", "cover", "coyote", "crack", "cradle", "craft", "cram", "crane", "crash", "crater", "crawl", "crazy", "cream", "credit", "creek", "crew", "cricket", "crime", "crisp", "critic", "crop", "cross", "crouch", "crowd", "crucial", "cruel", "cruise", "crumble", "crunch", "crush", "cry", "crystal", "cube", "culture", "cup", "cupboard", "curious", "current", "curtain", "curve", "cushion", "custom", "cute", "cycle", "dad", "damage", "damp", "dance", "danger", "daring", "dash", "daughter", "dawn", "day", "deal", "debate", "debris", "decade", "december", "decide", "decline", "decorate", "decrease", "deer", "defense", "define", "defy", "degree", "delay", "deliver", "demand", "demise", "denial", "dentist", "deny", "depart", "depend", "deposit", "depth", "deputy", "derive", "describe", "desert", "design", "desk", "despair", "destroy", "detail", "detect", "develop", "device", "devote", "diagram", "dial", "diamond", "diary", "dice", "diesel", "diet", "differ", "digital", "dignity", "dilemma", "dinner", "dinosaur", "direct", "dirt", "disagree", "discover", "disease", "dish", "dismiss", "disorder", "display", "distance", "divert", "divide", "divorce", "dizzy", "doctor", "document", "dog", "doll", "dolphin", "domain", "donate", "donkey", "donor", "door", "dose", "double", "dove", "draft", "dragon", "drama", "drastic", "draw", "dream", "dress", "drift", "drill", "drink", "drip", "drive", "drop", "drum", "dry", "duck", "dumb", "dune", "during", "dust", "dutch", "duty", "dwarf", "dynamic", "eager", "eagle", "early", "earn", "earth", "easily", "east", "easy", "echo", "ecology", "economy", "edge", "edit", "educate", "effort", "egg", "eight", "either", "elbow", "elder", "electric", "elegant", "element", "elephant", "elevator", "elite", "else", "embark", "embody", "embrace", "emerge", "emotion", "employ", "empower", "empty", "enable", "enact", "end", "endless", "endorse", "enemy", "energy", "enforce", "engage", "engine", "enhance", "enjoy", "enlist", "enough", "enrich", "enroll", "ensure", "enter", "entire", "entry", "envelope", "episode", "equal", "equip", "era", "erase", "erode", "erosion", "error", "erupt", "escape", "essay", "essence", "estate", "eternal", "ethics", "evidence", "evil", "evoke", "evolve", "exact", "example", "excess", "exchange", "excite", "exclude", "excuse", "execute", "exercise", "exhaust", "exhibit", "exile", "exist", "exit", "exotic", "expand", "expect", "expire", "explain", "expose", "express", "extend", "extra", "eye", "eyebrow", "fabric", "face", "faculty", "fade", "faint", "faith", "fall", "false", "fame", "family", "famous", "fan", "fancy", "fantasy", "farm", "fashion", "fat", "fatal", "father", "fatigue", "fault", "favorite", "feature", "february", "federal", "fee", "feed", "feel", "female", "fence", "festival", "fetch", "fever", "few", "fiber", "fiction", "field", "figure", "file", "film", "filter", "final", "find", "fine", "finger", "finish", "fire", "firm", "first", "fiscal", "fish", "fit", "fitness", "fix", "flag", "flame", "flash", "flat", "flavor", "flee", "flight", "flip", "float", "flock", "floor", "flower", "fluid", "flush", "fly", "foam", "focus", "fog", "foil", "fold", "follow", "food", "foot", "force", "forest", "forget", "fork", "fortune", "forum", "forward", "fossil", "foster", "found", "fox", "fragile", "frame", "frequent", "fresh", "friend", "fringe", "frog", "front", "frost", "frown", "frozen", "fruit", "fuel", "fun", "funny", "furnace", "fury", "future", "gadget", "gain", "galaxy", "gallery", "game", "gap", "garage", "garbage", "garden", "garlic", "garment", "gas", "gasp", "gate", "gather", "gauge", "gaze", "general", "genius", "genre", "gentle", "genuine", "gesture", "ghost", "giant", "gift", "giggle", "ginger", "giraffe", "girl", "give", "glad", "glance", "glare", "glass", "glide", "glimpse", "globe", "gloom", "glory", "glove", "glow", "glue", "goat", "goddess", "gold", "good", "goose", "gorilla", "gospel", "gossip", "govern", "gown", "grab", "grace", "grain", "grant", "grape", "grass", "gravity", "great", "green", "grid", "grief", "grit", "grocery", "group", "grow", "grunt", "guard", "guess", "guide", "guilt", "guitar", "gun", "gym", "habit", "hair", "half", "hammer", "hamster", "hand", "happy", "harbor", "hard", "harsh", "harvest", "hat", "have", "hawk", "hazard", "head", "health", "heart", "heavy", "hedgehog", "height", "hello", "helmet", "help", "hen", "hero", "hidden", "high", "hill", "hint", "hip", "hire", "history", "hobby", "hockey", "hold", "hole", "holiday", "hollow", "home", "honey", "hood", "hope", "horn", "horror", "horse", "hospital", "host", "hotel", "hour", "hover", "hub", "huge", "human", "humble", "humor", "hundred", "hungry", "hunt", "hurdle", "hurry", "hurt", "husband", "hybrid", "ice", "icon", "idea", "identify", "idle", "ignore", "ill", "illegal", "illness", "image", "imitate", "immense", "immune", "impact", "impose", "improve", "impulse", "inch", "include", "income", "increase", "index", "indicate", "indoor", "industry", "infant", "inflict", "inform", "inhale", "inherit", "initial", "inject", "injury", "inmate", "inner", "innocent", "input", "inquiry", "insane", "insect", "inside", "inspire", "install", "intact", "interest", "into", "invest", "invite", "involve", "iron", "island", "isolate", "issue", "item", "ivory", "jacket", "jaguar", "jar", "jazz", "jealous", "jeans", "jelly", "jewel", "job", "join", "joke", "journey", "joy", "judge", "juice", "jump", "jungle", "junior", "junk", "just", "kangaroo", "keen", "keep", "ketchup", "key", "kick", "kid", "kidney", "kind", "kingdom", "kiss", "kit", "kitchen", "kite", "kitten", "kiwi", "knee", "knife", "knock", "know", "lab", "label", "labor", "ladder", "lady", "lake", "lamp", "language", "laptop", "large", "later", "latin", "laugh", "laundry", "lava", "law", "lawn", "lawsuit", "layer", "lazy", "leader", "leaf", "learn", "leave", "lecture", "left", "leg", "legal", "legend", "leisure", "lemon", "lend", "length", "lens", "leopard", "lesson", "letter", "level", "liar", "liberty", "library", "license", "life", "lift", "light", "like", "limb", "limit", "link", "lion", "liquid", "list", "little", "live", "lizard", "load", "loan", "lobster", "local", "lock", "logic", "lonely", "long", "loop", "lottery", "loud", "lounge", "love", "loyal", "lucky", "luggage", "lumber", "lunar", "lunch", "luxury", "lyrics", "machine", "mad", "magic", "magnet", "maid", "mail", "main", "major", "make", "mammal", "man", "manage", "mandate", "mango", "mansion", "manual", "maple", "marble", "march", "margin", "marine", "market", "marriage", "mask", "mass", "master", "match", "material", "math", "matrix", "matter", "maximum", "maze", "meadow", "mean", "measure", "meat", "mechanic", "medal", "media", "melody", "melt", "member", "memory", "mention", "menu", "mercy", "merge", "merit", "merry", "mesh", "message", "metal", "method", "middle", "midnight", "milk", "million", "mimic", "mind", "minimum", "minor", "minute", "miracle", "mirror", "misery", "miss", "mistake", "mix", "mixed", "mixture", "mobile", "model", "modify", "mom", "moment", "monitor", "monkey", "monster", "month", "moon", "moral", "more", "morning", "mosquito", "mother", "motion", "motor", "mountain", "mouse", "move", "movie", "much", "muffin", "mule", "multiply", "muscle", "museum", "mushroom", "music", "must", "mutual", "myself", "mystery", "myth", "naive", "name", "napkin", "narrow", "nasty", "nation", "nature", "near", "neck", "need", "negative", "neglect", "neither", "nephew", "nerve", "nest", "net", "network", "neutral", "never", "news", "next", "nice", "night", "noble", "noise", "nominee", "noodle", "normal", "north", "nose", "notable", "note", "nothing", "notice", "novel", "now", "nuclear", "number", "nurse", "nut", "oak", "obey", "object", "oblige", "obscure", "observe", "obtain", "obvious", "occur", "ocean", "october", "odor", "off", "offer", "office", "often", "oil", "okay", "old", "olive", "olympic", "omit", "once", "one", "onion", "online", "only", "open", "opera", "opinion", "oppose", "option", "orange", "orbit", "orchard", "order", "ordinary", "organ", "orient", "original", "orphan", "ostrich", "other", "outdoor", "outer", "output", "outside", "oval", "oven", "over", "own", "owner", "oxygen", "oyster", "ozone", "pact", "paddle", "page", "pair", "palace", "palm", "panda", "panel", "panic", "panther", "paper", "parade", "parent", "park", "parrot", "party", "pass", "patch", "path", "patient", "patrol", "pattern", "pause", "pave", "payment", "peace", "peanut", "pear", "peasant", "pelican", "pen", "penalty", "pencil", "people", "pepper", "perfect", "permit", "person", "pet", "phone", "photo", "phrase", "physical", "piano", "picnic", "picture", "piece", "pig", "pigeon", "pill", "pilot", "pink", "pioneer", "pipe", "pistol", "pitch", "pizza", "place", "planet", "plastic", "plate", "play", "please", "pledge", "pluck", "plug", "plunge", "poem", "poet", "point", "polar", "pole", "police", "pond", "pony", "pool", "popular", "portion", "position", "possible", "post", "potato", "pottery", "poverty", "powder", "power", "practice", "praise", "predict", "prefer", "prepare", "present", "pretty", "prevent", "price", "pride", "primary", "print", "priority", "prison", "private", "prize", "problem", "process", "produce", "profit", "program", "project", "promote", "proof", "property", "prosper", "protect", "proud", "provide", "public", "pudding", "pull", "pulp", "pulse", "pumpkin", "punch", "pupil", "puppy", "purchase", "purity", "purpose", "purse", "push", "put", "puzzle", "pyramid", "quality", "quantum", "quarter", "question", "quick", "quit", "quiz", "quote", "rabbit", "raccoon", "race", "rack", "radar", "radio", "rail", "rain", "raise", "rally", "ramp", "ranch", "random", "range", "rapid", "rare", "rate", "rather", "raven", "raw", "razor", "ready", "real", "reason", "rebel", "rebuild", "recall", "receive", "recipe", "record", "recycle", "reduce", "reflect", "reform", "refuse", "region", "regret", "regular", "reject", "relax", "release", "relief", "rely", "remain", "remember", "remind", "remove", "render", "renew", "rent", "reopen", "repair", "repeat", "replace", "report", "require", "rescue", "resemble", "resist", "resource", "response", "result", "retire", "retreat", "return", "reunion", "reveal", "review", "reward", "rhythm", "rib", "ribbon", "rice", "rich", "ride", "ridge", "rifle", "right", "rigid", "ring", "riot", "ripple", "risk", "ritual", "rival", "river", "road", "roast", "robot", "robust", "rocket", "romance", "roof", "rookie", "room", "rose", "rotate", "rough", "round", "route", "royal", "rubber", "rude", "rug", "rule", "run", "runway", "rural", "sad", "saddle", "sadness", "safe", "sail", "salad", "salmon", "salon", "salt", "salute", "same", "sample", "sand", "satisfy", "satoshi", "sauce", "sausage", "save", "say", "scale", "scan", "scare", "scatter", "scene", "scheme", "school", "science", "scissors", "scorpion", "scout", "scrap", "screen", "script", "scrub", "sea", "search", "season", "seat", "second", "secret", "section", "security", "seed", "seek", "segment", "select", "sell", "seminar", "senior", "sense", "sentence", "series", "service", "session", "settle", "setup", "seven", "shadow", "shaft", "shallow", "share", "shed", "shell", "sheriff", "shield", "shift", "shine", "ship", "shiver", "shock", "shoe", "shoot", "shop", "short", "shoulder", "shove", "shrimp", "shrug", "shuffle", "shy", "sibling", "sick", "side", "siege", "sight", "sign", "silent", "silk", "silly", "silver", "similar", "simple", "since", "sing", "siren", "sister", "situate", "six", "size", "skate", "sketch", "ski", "skill", "skin", "skirt", "skull", "slab", "slam", "sleep", "slender", "slice", "slide", "slight", "slim", "slogan", "slot", "slow", "slush", "small", "smart", "smile", "smoke", "smooth", "snack", "snake", "snap", "sniff", "snow", "soap", "soccer", "social", "sock", "soda", "soft", "solar", "soldier", "solid", "solution", "solve", "someone", "song", "soon", "sorry", "sort", "soul", "sound", "soup", "source", "south", "space", "spare", "spatial", "spawn", "speak", "special", "speed", "spell", "spend", "sphere", "spice", "spider", "spike", "spin", "spirit", "split", "spoil", "sponsor", "spoon", "sport", "spot", "spray", "spread", "spring", "spy", "square", "squeeze", "squirrel", "stable", "stadium", "staff", "stage", "stairs", "stamp", "stand", "start", "state", "stay", "steak", "steel", "stem", "step", "stereo", "stick", "still", "sting", "stock", "stomach", "stone", "stool", "story", "stove", "strategy", "street", "strike", "strong", "struggle", "student", "stuff", "stumble", "style", "subject", "submit", "subway", "success", "such", "sudden", "suffer", "sugar", "suggest", "suit", "summer", "sun", "sunny", "sunset", "super", "supply", "supreme", "sure", "surface", "surge", "surprise", "surround", "survey", "suspect", "sustain", "swallow", "swamp", "swap", "swarm", "swear", "sweet", "swift", "swim", "swing", "switch", "sword", "symbol", "symptom", "syrup", "system", "table", "tackle", "tag", "tail", "talent", "talk", "tank", "tape", "target", "task", "taste", "tattoo", "taxi", "teach", "team", "tell", "ten", "tenant", "tennis", "tent", "term", "test", "text", "thank", "that", "theme", "then", "theory", "there", "they", "thing", "this", "thought", "three", "thrive", "throw", "thumb", "thunder", "ticket", "tide", "tiger", "tilt", "timber", "time", "tiny", "tip", "tired", "tissue", "title", "toast", "tobacco", "today", "toddler", "toe", "together", "toilet", "token", "tomato", "tomorrow", "tone", "tongue", "tonight", "tool", "tooth", "top", "topic", "topple", "torch", "tornado", "tortoise", "toss", "total", "tourist", "toward", "tower", "town", "toy", "track", "trade", "traffic", "tragic", "train", "transfer", "trap", "trash", "travel", "tray", "treat", "tree", "trend", "trial", "tribe", "trick", "trigger", "trim", "trip", "trophy", "trouble", "truck", "true", "truly", "trumpet", "trust", "truth", "try", "tube", "tuition", "tumble", "tuna", "tunnel", "turkey", "turn", "turtle", "twelve", "twenty", "twice", "twin", "twist", "two", "type", "typical", "ugly", "umbrella", "unable", "unaware", "uncle", "uncover", "under", "undo", "unfair", "unfold", "unhappy", "uniform", "unique", "unit", "universe", "unknown", "unlock", "until", "unusual", "unveil", "update", "upgrade", "uphold", "upon", "upper", "upset", "urban", "urge", "usage", "use", "used", "useful", "useless", "usual", "utility", "vacant", "vacuum", "vague", "valid", "valley", "valve", "van", "vanish", "vapor", "various", "vast", "vault", "vehicle", "velvet", "vendor", "venture", "venue", "verb", "verify", "version", "very", "vessel", "veteran", "viable", "vibrant", "vicious", "victory", "video", "view", "village", "vintage", "violin", "virtual", "virus", "visa", "visit", "visual", "vital", "vivid", "vocal", "voice", "void", "volcano", "volume", "vote", "voyage", "wage", "wagon", "wait", "walk", "wall", "walnut", "want", "warfare", "warm", "warrior", "wash", "wasp", "waste", "water", "wave", "way", "wealth", "weapon", "wear", "weasel", "weather", "web", "wedding", "weekend", "weird", "welcome", "west", "wet", "whale", "what", "wheat", "wheel", "when", "where", "whip", "whisper", "wide", "width", "wife", "wild", "will", "win", "window", "wine", "wing", "wink", "winner", "winter", "wire", "wisdom", "wise", "wish", "witness", "wolf", "woman", "wonder", "wood", "wool", "word", "work", "world", "worry", "worth", "wrap", "wreck", "wrestle", "wrist", "write", "wrong", "yard", "year", "yellow", "you", "young", "youth", "zebra", "zero", "zone", "zoo"}) + +(defn sanitize-passphrase [s] + (-> (string/trim s) + (string/replace-all #"\s+" " "))) + +(defn passphrase->words [s] + (when s + (-> (sanitize-passphrase s) + (string/split #" ")))) + +(defn words->passphrase [v] + (string/join " " v)) + +(def valid-word-counts #{12 15 18 21 24}) + +(defn valid-word-counts? [v] + (boolean (valid-word-counts (count v)))) + +(defn- valid-word? [s] + (re-matches #"^[A-z]+$" s)) + +(defn valid-words? [v] + (and (valid-word-counts? v) + (every? valid-word? v))) + +(defn valid-phrase? [s] + (-> s + passphrase->words + valid-words?)) + +(defn status-generated-phrase? [s] + (every? dictionary (passphrase->words s))) \ No newline at end of file diff --git a/test/cljs/status_im/test/runner.cljs b/test/cljs/status_im/test/runner.cljs index 5b1a635535..e8bb9191aa 100644 --- a/test/cljs/status_im/test/runner.cljs +++ b/test/cljs/status_im/test/runner.cljs @@ -36,6 +36,7 @@ [status-im.test.utils.ethereum.eip681] [status-im.test.utils.ethereum.core] [status-im.test.utils.ethereum.ens] + [status-im.test.utils.ethereum.mnemonic] [status-im.test.utils.random] [status-im.test.utils.gfycat.core] [status-im.test.utils.signing-phrase.core] @@ -47,7 +48,8 @@ [status-im.test.utils.universal-links.core] [status-im.test.utils.http] [status-im.test.ui.screens.events] - [status-im.test.ui.screens.accounts.login.events] + [status-im.test.ui.screens.accounts.login.models] + [status-im.test.ui.screens.accounts.recover.models] [status-im.test.ui.screens.wallet.db])) (enable-console-print!) @@ -94,6 +96,7 @@ 'status-im.test.utils.clocks 'status-im.test.utils.ethereum.eip681 'status-im.test.utils.ethereum.core + 'status-im.test.utils.ethereum.mnemonic 'status-im.test.utils.ethereum.ens 'status-im.test.utils.random 'status-im.test.utils.gfycat.core @@ -105,6 +108,7 @@ 'status-im.test.utils.universal-links.core 'status-im.test.utils.http 'status-im.test.ui.screens.events - 'status-im.test.ui.screens.accounts.login.events + 'status-im.test.ui.screens.accounts.login.models + 'status-im.test.ui.screens.accounts.recover.models 'status-im.test.ui.screens.wallet.db 'status-im.test.browser.events) diff --git a/test/cljs/status_im/test/ui/screens/accounts/login/events.cljs b/test/cljs/status_im/test/ui/screens/accounts/login/models.cljs similarity index 99% rename from test/cljs/status_im/test/ui/screens/accounts/login/events.cljs rename to test/cljs/status_im/test/ui/screens/accounts/login/models.cljs index 121471f6d8..dd5c756b0c 100644 --- a/test/cljs/status_im/test/ui/screens/accounts/login/events.cljs +++ b/test/cljs/status_im/test/ui/screens/accounts/login/models.cljs @@ -1,4 +1,4 @@ -(ns status-im.test.ui.screens.accounts.login.events +(ns status-im.test.ui.screens.accounts.login.models (:require [cljs.test :refer-macros [deftest is testing]] [status-im.utils.config :as config] [status-im.ui.screens.accounts.login.models :as models])) diff --git a/test/cljs/status_im/test/ui/screens/accounts/recover/models.cljs b/test/cljs/status_im/test/ui/screens/accounts/recover/models.cljs new file mode 100644 index 0000000000..20dcfaa3c6 --- /dev/null +++ b/test/cljs/status_im/test/ui/screens/accounts/recover/models.cljs @@ -0,0 +1,125 @@ +(ns status-im.test.ui.screens.accounts.recover.models + (:require [cljs.test :refer-macros [deftest is testing]] + [status-im.ui.screens.accounts.recover.models :as models] + [clojure.string :as string] + [status-im.utils.security :as security] + [status-im.i18n :as i18n])) + +;;;; helpers + +(deftest check-password-errors + (is (= :required-field (models/check-password-errors nil))) + (is (= :required-field (models/check-password-errors " "))) + (is (= :required-field (models/check-password-errors " \t\n "))) + (is (= :recover-password-too-short) (models/check-password-errors "a")) + (is (= :recover-password-too-short) (models/check-password-errors "abc")) + (is (= :recover-password-too-short) (models/check-password-errors "12345")) + (is (nil? (models/check-password-errors "123456"))) + (is (nil? (models/check-password-errors "thisisapasswoord")))) + +(deftest check-phrase-errors + (is (= :required-field (models/check-phrase-errors nil))) + (is (= :required-field (models/check-phrase-errors " "))) + (is (= :required-field (models/check-phrase-errors " \t\n "))) + (is (= :recovery-phrase-invalid (models/check-phrase-errors "phrase with four words"))) + (is (= :recovery-phrase-invalid (models/check-phrase-errors "phrase with five cool words"))) + (is (nil? (models/check-phrase-errors "monkey monkey monkey monkey monkey monkey monkey monkey monkey monkey monkey monkey"))) + (is (nil? (models/check-phrase-errors (string/join " " (repeat 15 "monkey"))))) + (is (nil? (models/check-phrase-errors (string/join " " (repeat 18 "monkey"))))) + (is (nil? (models/check-phrase-errors (string/join " " (repeat 24 "monkey"))))) + (is (= :recovery-phrase-invalid (models/check-phrase-errors (string/join " " (repeat 14 "monkey"))))) + (is (= :recovery-phrase-invalid (models/check-phrase-errors (string/join " " (repeat 11 "monkey"))))) + (is (= :recovery-phrase-invalid (models/check-phrase-errors (string/join " " (repeat 19 "monkey"))))) + (is (= :recovery-phrase-invalid (models/check-phrase-errors "monkey monkey monkey 12345 monkey adf+123 monkey monkey monkey monkey monkey monkey"))) + ;;NOTE(goranjovic): the following check should be ok because we sanitize extra whitespace + (is (nil? (models/check-phrase-errors " monkey monkey monkey\t monkey monkey monkey monkey monkey monkey monkey monkey monkey \t ")))) + +(deftest check-phrase-warnings + (is (nil? (models/check-phrase-warnings "monkey monkey monkey monkey monkey monkey monkey monkey monkey monkey monkey monkey"))) + (is (nil? (models/check-phrase-warnings "game buzz method pretty olympic fat quit display velvet unveil marine crater"))) + (is (= :recovery-phrase-unknown-words (models/check-phrase-warnings "game buzz method pretty zeus fat quit display velvet unveil marine crater")))) + +;;;; handlers + +(deftest set-phrase + (is (= {:db {:accounts/recover {:passphrase "game buzz method pretty olympic fat quit display velvet unveil marine crater" + :passphrase-valid? true}}} + (models/set-phrase "game buzz method pretty olympic fat quit display velvet unveil marine crater" {:db {}}))) + (is (= {:db {:accounts/recover {:passphrase "game buzz method pretty olympic fat quit display velvet unveil marine crater" + :passphrase-valid? true}}} + (models/set-phrase "Game buzz method pretty Olympic fat quit DISPLAY velvet unveil marine crater" {:db {}}))) + (is (= {:db {:accounts/recover {:passphrase "game buzz method pretty zeus fat quit display velvet unveil marine crater" + :passphrase-valid? true}}} + (models/set-phrase "game buzz method pretty zeus fat quit display velvet unveil marine crater" {:db {}}))) + (is (= {:db {:accounts/recover {:passphrase " game\t buzz method pretty olympic fat quit\t display velvet unveil marine crater " + :passphrase-valid? true}}} + (models/set-phrase " game\t buzz method pretty olympic fat quit\t display velvet unveil marine crater " {:db {}}))) + (is (= {:db {:accounts/recover {:passphrase "game buzz method pretty 1234 fat quit display velvet unveil marine crater" + :passphrase-valid? false}}} + (models/set-phrase "game buzz method pretty 1234 fat quit display velvet unveil marine crater" {:db {}})))) + +(deftest validate-phrase + (is (= {:db {:accounts/recover {:passphrase-error nil + :passphrase-warning nil + :passphrase "game buzz method pretty olympic fat quit display velvet unveil marine crater"}}} + (models/validate-phrase {:db {:accounts/recover {:passphrase "game buzz method pretty olympic fat quit display velvet unveil marine crater"}}}))) + (is (= {:db {:accounts/recover {:passphrase-error nil + :passphrase-warning :recovery-phrase-unknown-words + :passphrase "game buzz method pretty zeus fat quit display velvet unveil marine crater"}}} + (models/validate-phrase {:db {:accounts/recover {:passphrase "game buzz method pretty zeus fat quit display velvet unveil marine crater"}}}))) + (is (= {:db {:accounts/recover {:passphrase-error :recovery-phrase-invalid + :passphrase-warning :recovery-phrase-unknown-words + :passphrase "game buzz method pretty 1234 fat quit display velvet unveil marine crater"}}} + (models/validate-phrase {:db {:accounts/recover {:passphrase "game buzz method pretty 1234 fat quit display velvet unveil marine crater"}}})))) + +(deftest set-password + (is (= {:db {:accounts/recover {:password " " + :password-valid? false}}} + (models/set-password (security/mask-data " ") {:db {}}))) + (is (= {:db {:accounts/recover {:password "abc" + :password-valid? false}}} + (models/set-password (security/mask-data "abc") {:db {}}))) + (is (= {:db {:accounts/recover {:password "thisisapaswoord" + :password-valid? true}}} + (models/set-password (security/mask-data "thisisapaswoord") {:db {}})))) + +(deftest validate-password + (is (= {:db {:accounts/recover {:password " " + :password-error :required-field}}} + (models/validate-password {:db {:accounts/recover {:password " "}}}))) + (is (= {:db {:accounts/recover {:password "abc" + :password-error :recover-password-too-short}}} + (models/validate-password {:db {:accounts/recover {:password "abc"}}}))) + (is (= {:db {:accounts/recover {:password "thisisapaswoord" + :password-error nil}}} + (models/validate-password {:db {:accounts/recover {:password "thisisapaswoord"}}})))) + +(deftest recover-account + (let [new-cofx (models/recover-account {:db {:accounts/recover + {:passphrase "game buzz method pretty zeus fat quit display velvet unveil marine crater" + :password "thisisapaswoord"}}})] + (is (= {:accounts/recover {:passphrase "game buzz method pretty zeus fat quit display velvet unveil marine crater" + :password "thisisapaswoord" + :processing? true}} + (:db new-cofx))) + (is (= security/MaskedData + (-> new-cofx :recover-account-fx first type))) + (is (= "thisisapaswoord" (-> new-cofx :recover-account-fx second))))) + +(deftest recover-account-with-checks + (let [new-cofx (models/recover-account-with-checks {:db {:accounts/recover + {:passphrase "game buzz method pretty olympic fat quit display velvet unveil marine crater" + :password "thisisapaswoord"}}})] + (is (= {:accounts/recover {:passphrase "game buzz method pretty olympic fat quit display velvet unveil marine crater" + :password "thisisapaswoord" + :processing? true}} + (:db new-cofx))) + (is (= security/MaskedData + (-> new-cofx :recover-account-fx first type))) + (is (= "thisisapaswoord" (-> new-cofx :recover-account-fx second)))) + (let [new-cofx (models/recover-account-with-checks {:db {:accounts/recover + {:passphrase "game buzz method pretty zeus fat quit display velvet unveil marine crater" + :password "thisisapaswoord"}}})] + (is (= (i18n/label :recovery-typo-dialog-title) (-> new-cofx :show-confirmation :title))) + (is (= (i18n/label :recovery-typo-dialog-description) (-> new-cofx :show-confirmation :content))) + (is (= (i18n/label :recovery-confirm-phrase) (-> new-cofx :show-confirmation :confirm-button-text))))) diff --git a/test/cljs/status_im/test/utils/ethereum/core.cljs b/test/cljs/status_im/test/utils/ethereum/core.cljs index 16b7024203..733ed8baeb 100644 --- a/test/cljs/status_im/test/utils/ethereum/core.cljs +++ b/test/cljs/status_im/test/utils/ethereum/core.cljs @@ -10,17 +10,6 @@ {:to "0x29b5f6efad2ad701952dfde9f29c960b5d6199c5" :data "0x70a08231000000000000000000000000a7cfd581060ec66414790691681732db249502bd"}))))) -(deftest valid-words? - (is (not (true? (ethereum/valid-words? ["rate" "rate"])))) - (is (not (true? (ethereum/valid-words? ["rate" "rate" "rate" "rate" "rate" "rate" "rate" "rate" "rate" "rate" "rate" "rate?"])))) - (is (true? (ethereum/valid-words? ["rate" "rate" "rate" "rate" "rate" "rate" "rate" "rate" "rate" "rate" "rate" "rate"])))) - -(deftest passphrase->words? - (is (= ["one" "two" "three" "for" "five" "six" "seven" "height" "nine" "ten" "eleven" "twelve"] - (ethereum/passphrase->words "one two three for five six seven height nine ten eleven twelve")) - (= ["one" "two" "three" "for" "five" "six" "seven" "height" "nine" "ten" "eleven" "twelve"] - (ethereum/passphrase->words " one two three for five six seven height nine ten eleven twelve ")))) - (deftest chain-id->chain-keyword (is (= (ethereum/chain-id->chain-keyword 1) :mainnet)) (is (= (ethereum/chain-id->chain-keyword 3) :testnet)) diff --git a/test/cljs/status_im/test/utils/ethereum/mnemonic.cljs b/test/cljs/status_im/test/utils/ethereum/mnemonic.cljs new file mode 100644 index 0000000000..90b0ee65b1 --- /dev/null +++ b/test/cljs/status_im/test/utils/ethereum/mnemonic.cljs @@ -0,0 +1,23 @@ +(ns status-im.test.utils.ethereum.mnemonic + (:require [cljs.test :refer-macros [deftest is testing]] + [status-im.utils.ethereum.mnemonic :as mnemonic])) + +(deftest valid-words? + (is (not (mnemonic/valid-words? ["rate" "rate"]))) + (is (not (mnemonic/valid-words? ["rate" "rate" "rate" "rate" "rate" "rate" "rate" "rate" "rate" "rate" "rate" "rate?"]))) + (is (mnemonic/valid-words? ["rate" "rate" "rate" "rate" "rate" "rate" "rate" "rate" "rate" "rate" "rate" "rate"]))) + +(deftest valid-phrase + (is (not (mnemonic/valid-phrase? "rate rate"))) + (is (not (mnemonic/valid-phrase? "rate rate rate rate rate rate rate rate rate rate rate rate?"))) + (is (mnemonic/valid-phrase? "rate rate rate rate rate rate rate rate rate rate rate rate"))) + +(deftest passphrase->words? + (is (= ["one" "two" "three" "for" "five" "six" "seven" "height" "nine" "ten" "eleven" "twelve"] + (mnemonic/passphrase->words "one two three for five six seven height nine ten eleven twelve")) + (= ["one" "two" "three" "for" "five" "six" "seven" "height" "nine" "ten" "eleven" "twelve"] + (mnemonic/passphrase->words " one two three for five six seven height nine ten eleven twelve ")))) + +(deftest status-generate-phrase? + (is (mnemonic/status-generated-phrase? "game buzz method pretty olympic fat quit display velvet unveil marine crater")) + (is (not (mnemonic/status-generated-phrase? "game buzz method pretty zeus fat quit display velvet unveil marine crater"))))