diff --git a/src/backup/utils.test.ts b/src/backup/utils.test.ts index be7bd7433f6..2a6c57ebe18 100644 --- a/src/backup/utils.test.ts +++ b/src/backup/utils.test.ts @@ -1,4 +1,3 @@ -import * as bip39 from 'react-native-bip39' import { formatBackupPhraseOnEdit } from 'src/backup/utils' import { normalizeMnemonic, validateMnemonic } from 'src/utils/account' @@ -52,41 +51,41 @@ inner surprise invest` it('validates spanish successfully', () => { const mnemonic = normalizeMnemonic(SPANISH_MNEMONIC) - expect(validateMnemonic(mnemonic, bip39)).toBeTruthy() + expect(validateMnemonic(mnemonic)).toBeTruthy() }) it('validates spanish successfully without mnemonic accents', () => { const mnemonic = normalizeMnemonic(SPANISH_MNEMONIC_NO_ACCENTS) - expect(validateMnemonic(mnemonic, bip39)).toBeTruthy() + expect(validateMnemonic(mnemonic)).toBeTruthy() }) it('validates portuguese successfully', () => { const mnemonic = normalizeMnemonic(PORTUGUESE_MNEMONIC) - expect(validateMnemonic(mnemonic, bip39)).toBeTruthy() + expect(validateMnemonic(mnemonic)).toBeTruthy() }) it('validates english successfully', () => { const mnemonic = normalizeMnemonic(ENGLISH_MNEMONIC) - expect(validateMnemonic(mnemonic, bip39)).toBeTruthy() + expect(validateMnemonic(mnemonic)).toBeTruthy() }) it('validates english multiline successfully', () => { const mnemonic = normalizeMnemonic(MULTILINE_ENGLISH_MNEMONIC) - expect(validateMnemonic(mnemonic, bip39)).toBeTruthy() + expect(validateMnemonic(mnemonic)).toBeTruthy() }) it('does not validate bad english', () => { const mnemonic = normalizeMnemonic(BAD_ENGLISH_MNEMONIC) - expect(validateMnemonic(mnemonic, bip39)).toBeFalsy() + expect(validateMnemonic(mnemonic)).toBeFalsy() }) it('does not validate bad spanish', () => { const mnemonic = normalizeMnemonic(BAD_SPANISH_MNEMONIC) - expect(validateMnemonic(mnemonic, bip39)).toBeFalsy() + expect(validateMnemonic(mnemonic)).toBeFalsy() }) it('does not validate bad portuguese', () => { const mnemonic = normalizeMnemonic(BAD_PORTUGUESE_MNEMONIC) - expect(validateMnemonic(mnemonic, bip39)).toBeFalsy() + expect(validateMnemonic(mnemonic)).toBeFalsy() }) }) diff --git a/src/import/saga.ts b/src/import/saga.ts index c4a008b8ff7..daf01523817 100644 --- a/src/import/saga.ts +++ b/src/import/saga.ts @@ -1,6 +1,5 @@ import { privateKeyToAddress } from '@celo/utils/lib/address' import { Task } from '@redux-saga/types' -import * as bip39 from 'react-native-bip39' import { setBackupCompleted } from 'src/account/actions' import { initializeAccountSaga } from 'src/account/saga' import { recoveringFromStoreWipeSelector } from 'src/account/selectors' @@ -52,7 +51,7 @@ export function* importBackupPhraseSaga({ phrase, useEmptyWallet }: ImportBackup Logger.debug(TAG + '@importBackupPhraseSaga', 'Importing backup phrase') try { const normalizedPhrase = normalizeMnemonic(phrase) - const phraseIsValid = validateMnemonic(normalizedPhrase, bip39) + const phraseIsValid = validateMnemonic(normalizedPhrase) const invalidWords = phraseIsValid ? [] : invalidMnemonicWords(normalizedPhrase) if (!phraseIsValid) { diff --git a/src/web3/saga.test.ts b/src/web3/saga.test.ts index 80ee235e4c6..96e65eae734 100644 --- a/src/web3/saga.test.ts +++ b/src/web3/saga.test.ts @@ -1,5 +1,4 @@ import { isValidChecksumAddress } from '@celo/utils/lib/address' -import * as bip39 from 'react-native-bip39' import { expectSaga } from 'redux-saga-test-plan' import * as matchers from 'redux-saga-test-plan/matchers' import { call, select } from 'redux-saga/effects' @@ -8,15 +7,15 @@ import { ErrorMessages } from 'src/app/ErrorMessages' import { storeMnemonic } from 'src/backup/utils' import { currentLanguageSelector } from 'src/i18n/selectors' import { getPasswordSaga, retrieveSignedMessage } from 'src/pincode/authentication' -import { generateMnemonic, MnemonicLanguages, MnemonicStrength } from 'src/utils/account' +import { MnemonicLanguages, MnemonicStrength, generateMnemonic } from 'src/utils/account' import { setAccount, setDataEncryptionKey } from 'src/web3/actions' import { + UnlockResult, getConnectedAccount, getConnectedUnlockedAccount, getOrCreateAccount, getWalletAddress, unlockAccount, - UnlockResult, } from 'src/web3/saga' import { currentAccountSelector, walletAddressSelector } from 'src/web3/selectors' import { createMockStore } from 'test/utils' @@ -101,8 +100,7 @@ describe(getOrCreateAccount, () => { .call( generateMnemonic, MnemonicStrength.s128_12words, - MnemonicLanguages[expectedMnemonicLang] as unknown as MnemonicLanguages, - bip39 + MnemonicLanguages[expectedMnemonicLang] as unknown as MnemonicLanguages ) .run() diff --git a/src/web3/saga.ts b/src/web3/saga.ts index 35f56556087..ac38ca9d397 100644 --- a/src/web3/saga.ts +++ b/src/web3/saga.ts @@ -1,21 +1,20 @@ import { privateKeyToAddress } from '@celo/utils/lib/address' import { UnlockableWallet } from '@celo/wallet-base' import { RpcWalletErrors } from '@celo/wallet-rpc/lib/rpc-wallet' -import * as bip39 from 'react-native-bip39' import { setAccountCreationTime } from 'src/account/actions' import { generateSignedMessage } from 'src/account/saga' import { ErrorMessages } from 'src/app/ErrorMessages' import { generateKeysFromMnemonic, storeMnemonic } from 'src/backup/utils' +import { clearPasswordCaches } from 'src/pincode/PasswordCache' import { CANCELLED_PIN_INPUT, getPasswordSaga, retrieveSignedMessage, } from 'src/pincode/authentication' -import { clearPasswordCaches } from 'src/pincode/PasswordCache' -import { generateMnemonic, MnemonicLanguages, MnemonicStrength } from 'src/utils/account' -import { ensureError } from 'src/utils/ensureError' import Logger from 'src/utils/Logger' -import { Actions, setAccount, SetAccountAction } from 'src/web3/actions' +import { MnemonicLanguages, MnemonicStrength, generateMnemonic } from 'src/utils/account' +import { ensureError } from 'src/utils/ensureError' +import { Actions, SetAccountAction, setAccount } from 'src/web3/actions' import { UNLOCK_DURATION } from 'src/web3/consts' import { getWallet, initContractKit } from 'src/web3/contracts' import { createAccountDek } from 'src/web3/dataEncryptionKey' @@ -45,7 +44,7 @@ export function* getOrCreateAccount() { const mnemonicBitLength = MnemonicStrength.s128_12words const mnemonicLanguage = MnemonicLanguages.english - let mnemonic: string = yield* call(generateMnemonic, mnemonicBitLength, mnemonicLanguage, bip39) + let mnemonic: string = yield* call(generateMnemonic, mnemonicBitLength, mnemonicLanguage) // Ensure no duplicates in mnemonic const checkDuplicate = (someString: string) => { @@ -54,7 +53,7 @@ export function* getOrCreateAccount() { let duplicateInMnemonic = checkDuplicate(mnemonic) while (duplicateInMnemonic) { Logger.debug(TAG + '@getOrCreateAccount', 'Regenerating mnemonic to avoid duplicates') - mnemonic = yield* call(generateMnemonic, mnemonicBitLength, mnemonicLanguage, bip39) + mnemonic = yield* call(generateMnemonic, mnemonicBitLength, mnemonicLanguage) duplicateInMnemonic = checkDuplicate(mnemonic) }