Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Disallow upper case letters in passphrase
Browse files Browse the repository at this point in the history
  • Loading branch information
slaweet committed Dec 19, 2017
1 parent 475707b commit 5a72a6b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions i18n/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
"What's New...": "What's New...",
"When you have the signature, you only need the publicKey of the signer in order to verify that the message came from the right private/publicKey pair. Be aware, everybody knowing the signature and the publicKey can verify the message. If ever there is a dispute, everybody can take the publicKey and signature to a judge and prove that the message is coming from the specific private/publicKey pair.": "When you have the signature, you only need the publicKey of the signer in order to verify that the message came from the right private/publicKey pair. Be aware, everybody knowing the signature and the publicKey can verify the message. If ever there is a dispute, everybody can take the publicKey and signature to a judge and prove that the message is coming from the specific private/publicKey pair.",
"Window": "Window",
"Word \"{{invalidWord}}\" contains upper case letters. All words must be lower case": "Word \"{{invalidWord}}\" contains upper case letters. All words must be lower case",
"Word \"{{invalidWord}}\" is not on the passphrase Word List.": "Word \"{{invalidWord}}\" is not on the passphrase Word List.",
"Word \"{{invalidWord}}\" is not on the passphrase Word List. Most similar word on the list is \"{{similarWord}}\"": "Word \"{{invalidWord}}\" is not on the passphrase Word List. Most similar word on the list is \"{{similarWord}}\"",
"Yes! It's safe": "Yes! It's safe",
Expand Down
6 changes: 4 additions & 2 deletions src/components/passphraseInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ class PassphraseInput extends React.Component {
return this.props.t('Passphrase should have 12 words, entered passphrase has {{length}}', { length: mnemonic.length });
}

const invalidWord = mnemonic.find(word => !inDictionary(word.toLowerCase()));
const invalidWord = mnemonic.find(word => !inDictionary(word));
if (invalidWord) {
if (invalidWord.length >= 2 && invalidWord.length <= 8) {
const validWord = findSimilarWord(invalidWord);
if (validWord) {
if (invalidWord.toLowerCase() !== invalidWord) {
return this.props.t('Word "{{invalidWord}}" contains upper case letters. All words must be lower case', { invalidWord });
} else if (validWord) {
return this.props.t('Word "{{invalidWord}}" is not on the passphrase Word List. Most similar word on the list is "{{similarWord}}"', { invalidWord, similarWord: findSimilarWord(invalidWord) });
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/components/passphraseInput/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ describe('PassphraseInput', () => {
expect(wrapper.props().onChange).to.have.been.calledWith(passphrase, SIMILAR_WORD_ERROR);
});

const UPPER_CASE_ERROR = 'Word "WAGON" contains upper case letters. All words must be lower case';
it(`should call props.onChange with error='${UPPER_CASE_ERROR}' if an passphrase with a typo is entered`, () => {
const passphrase = 'WAGON stock borrow episode laundry kitten salute link globe zero feed marble';
wrapper.find('input').simulate('change', { target: { value: passphrase } });
expect(wrapper.props().onChange).to.have.been.calledWith(passphrase, UPPER_CASE_ERROR);
});

const NOT_VALID_ERROR = 'Passphrase is not valid';
it(`should call props.onChange with error="${NOT_VALID_ERROR}" if an otherwise invalid passphrase is entered`, () => {
const passphrase = 'stock wagon borrow episode laundry kitten salute link globe zero feed marble';
Expand Down
2 changes: 1 addition & 1 deletion src/utils/passphrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const generatePassphrase = ({ seed }) => (new mnemonic(new Buffer(seed.jo
* @returns {bool} isValidPassphrase
*/
export const isValidPassphrase = (passphrase) => {
const normalizedValue = passphrase.replace(/ +/g, ' ').trim().toLowerCase();
const normalizedValue = passphrase.replace(/ +/g, ' ').trim();
let isValid;
try {
isValid = normalizedValue.split(' ').length >= 12 && mnemonic.isValid(normalizedValue);
Expand Down

0 comments on commit 5a72a6b

Please sign in to comment.