Skip to content

Commit

Permalink
validate mnemonic on restore
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTrunk committed Dec 22, 2023
1 parent f288628 commit ab9838b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/lib/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export function generateMnemonic(strength: 128 | 256 = 256): string {
return bip39.generateMnemonic(wordlist, strength);
}

export function validateMnemonic(mnemonic: string): boolean {
return bip39.validateMnemonic(mnemonic, wordlist);
}

// returns xpub of hardened derivation path for a particular coin
export function getMasterXpub(
mnemonic: string,
Expand Down
11 changes: 10 additions & 1 deletion src/screens/Restore/Restore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import { blockchains } from '@storage/blockchains';

const CryptoJS = require('crypto-js');

import { getMasterXpriv, getMasterXpub } from '../../lib/wallet';
import {
getMasterXpriv,
getMasterXpub,
validateMnemonic,
} from '../../lib/wallet';

import { setSeedPhrase, setSSPInitialState } from '../../store/ssp';
import { setXpubKeyIdentity, setXprivKeyIdentity } from '../../store';
Expand Down Expand Up @@ -113,6 +117,11 @@ function Restore({ navigation }: Props) {
displayMessage('error', t('cr:err_invalid_seed'));
return;
}
const isValid = validateMnemonic(newSeedPhrase);
if (!isValid) {
displayMessage('error', t('cr:err_invalid_seed'));
return;
}
if (password !== passwordConfirm) {
displayMessage('error', t('cr:err_pins_no_match'));
} else if (password.length < 4) {
Expand Down

0 comments on commit ab9838b

Please sign in to comment.