Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mnemonic validation flexibility within Valora #6372

Merged
merged 14 commits into from
Jan 7, 2021

Conversation

tarikbellamine
Copy link
Contributor

@tarikbellamine tarikbellamine commented Jan 5, 2021

Description

This PR aims to do two things:

  • Allow the mnemonic to be entered in any language recognized by Valora (i.e., Valora does not need to be set to the language the mnemonic is)
  • Validate the mnemonic regardless of accented letters

Other changes

No

Tested

Yes

Related issues

Backwards compatibility

Yes

@jeanregisser
Copy link
Contributor

Allow the mnemonic to be entered in any language recognized by Valora (i.e., Valora does not need to be set to the language the mnemonic is)

Looks like #5825 already fixed this.

@tarikbellamine
Copy link
Contributor Author

tarikbellamine commented Jan 5, 2021

Allow the mnemonic to be entered in any language recognized by Valora (i.e., Valora does not need to be set to the language the mnemonic is)

Looks like #5825 already fixed this.

Not in all cases. This variable definition: const languages = defaultLanguage ? [defaultLanguage] : getAllLanguages().filter((lang) => lang !== defaultLanguage) has an edge case where it will break if the param defaultLanguage was specified but not the same as the mnemonic language.

Copy link
Contributor

@gastonponti gastonponti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bip39 from the saga is the only required thing to change.
The other are suggestions, but I strongly recommend to keep the ability of choosing the dictionary

packages/mobile/src/import/saga.ts Outdated Show resolved Hide resolved
packages/sdk/utils/src/account.ts Show resolved Hide resolved
packages/sdk/utils/src/account.ts Outdated Show resolved Hide resolved
@@ -54,21 +55,20 @@ export async function generateMnemonic(
return bip39ToUse.generateMnemonic(strength, undefined, getWordList(language))
}

export function validateMnemonic(
mnemonic: string,
defaultLanguage?: MnemonicLanguages,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entire sure of removing these. In a way, if you know the language, you will avoid to search in every dictionary.
I'm more into the idea of searching in the dictionary that the user said, or in all of them otherwise (nil/null).

Thinking more of a common utils side, and not our use case in Valora

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about my approach this way:

Good - eliminate the possibility of user error (i.e., if there is a mismatch between defaultLanguage and mnemonic language)

Bad - slightly less efficient as it defaults to checking all languages. However, there are not very many languages and bip39.validateMnemonic appears very optimized and will fail quickly on a language mismatch

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I agree. We could eventually have another function that requires an specific language if we see that we need to optimise that (which are not the actual cases due to we are only using these to create/update accounts, and won't be called too often)

@jeanregisser
Copy link
Contributor

jeanregisser commented Jan 6, 2021

Allow the mnemonic to be entered in any language recognized by Valora (i.e., Valora does not need to be set to the language the mnemonic is)

Looks like #5825 already fixed this.

Not in all cases. This variable definition: const languages = defaultLanguage ? [defaultLanguage] : getAllLanguages().filter((lang) => lang !== defaultLanguage) has an edge case where it will break if the param defaultLanguage was specified but not the same as the mnemonic language.

We were not passing a default language anymore with Gonza's fix:

if (!validateMnemonic(phrase, undefined, bip39)) {

Good that we're making this even more robust 👍

Copy link
Contributor

@gastonponti gastonponti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@tarikbellamine tarikbellamine added automerge Have PR merge automatically when checks pass and removed automerge Have PR merge automatically when checks pass labels Jan 6, 2021
Copy link
Contributor

@gastonponti gastonponti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I really like the mnemonic conversion approach.
I'm approving it, but remember to add the lowerCase

packages/sdk/utils/src/account.ts Outdated Show resolved Hide resolved
Co-authored-by: Gaston Ponti <pontigaston@gmail.com>
@tarikbellamine tarikbellamine added the automerge Have PR merge automatically when checks pass label Jan 7, 2021
@mergify mergify bot merged commit 4276a18 into master Jan 7, 2021
@mergify mergify bot deleted the tarikbellamine/mnemonic-accents branch January 7, 2021 19:35
@Lss-Ankit
Copy link

Hi @tarikbellamine I have verified this on latest Android Internal Build V1.8.0(1004294330) & Test Flight Build V1.8.0(40) & observed following:

  • User able to login when user paste English language Account key by selecting "Espanol(America Latina)" language while log in.
  • User able to login with English language account key by selecting "Portugues(Brasil)" language while log in.
  • Also I have verified by entering Account key in Espanol(America Latin) language and got error "Clave de cuenta Invalida" after tapping on Restore button.
    Attachment: Espanol(AmericaLatin)LanguageError.mp4
  • Also it is observed that by entering Account key in Portueguese(Brasil) language and user got error "Chave da cuenta Invalida" after tapping on Restore button.
    Attachment: Portuegues(Brasil)Language.mp4
  • Also it is observed that "Invalid Account Key" error message displayed when user enter account key in "Espanol(America Latin)" or "Portueguese(Brasil)" language.

Let me know if i need to test anything else Thanks!

@tarikbellamine
Copy link
Contributor Author

@Lss-Ankit could you please test one more thing: enter in the Spanish with the accents and without the accents. For example, if the Spanish account key has the a word like niño then it should also be able to be entered like nino (without the special ñ)

@Lss-Ankit
Copy link

Hi @tarikbellamine I have verified following scenarioes:

  • By entering Spanish account key with accents user able to login in application

Attachment: WithAccents.mp4

  • Also it is observed that by entering Spanish account key without accents user able to login in application.

Attachment: WithoutAccents.mp4

  • It is observed that account key shown in English language even user login in app by selecting Portuguese(Brasil) langauge & user not able to set Account key in Portuguese language. Is it expected?

Attachment: AccountKeyEnglishEvenLangaugePortueguese.jpg
Verified on devices: iPhone SE 2 (14.3), iPhone iphone 6+ (12.4.5), Samsung Galaxy A5(7.0)
Let me know anything else need to check.

@tarikbellamine
Copy link
Contributor Author

@jeanregisser is this expected or was adding the Portuguese support supposed to include the Account Key as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Have PR merge automatically when checks pass wallet
Projects
None yet
4 participants