diff options
author | Thomas Huang <tmashuang@users.noreply.github.com> | 2018-03-12 22:50:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-12 22:50:55 +0800 |
commit | b7c7083a112ea6908e8c5990886ab388200a51f4 (patch) | |
tree | bf7e0f880b5a3ce32cd0b0e680f62e0f5068df8d /app/scripts/lib | |
parent | 174f57b4646b3d320850c6286189a146cf0e23b0 (diff) | |
parent | ddc85354d3df508cbecc016fc0213a6560d885e1 (diff) | |
download | tangerine-wallet-browser-b7c7083a112ea6908e8c5990886ab388200a51f4.tar tangerine-wallet-browser-b7c7083a112ea6908e8c5990886ab388200a51f4.tar.gz tangerine-wallet-browser-b7c7083a112ea6908e8c5990886ab388200a51f4.tar.bz2 tangerine-wallet-browser-b7c7083a112ea6908e8c5990886ab388200a51f4.tar.lz tangerine-wallet-browser-b7c7083a112ea6908e8c5990886ab388200a51f4.tar.xz tangerine-wallet-browser-b7c7083a112ea6908e8c5990886ab388200a51f4.tar.zst tangerine-wallet-browser-b7c7083a112ea6908e8c5990886ab388200a51f4.zip |
Merge branch 'master' into i18n
Diffstat (limited to 'app/scripts/lib')
-rw-r--r-- | app/scripts/lib/seed-phrase-verifier.js | 48 | ||||
-rw-r--r-- | app/scripts/lib/tx-state-manager.js | 2 |
2 files changed, 49 insertions, 1 deletions
diff --git a/app/scripts/lib/seed-phrase-verifier.js b/app/scripts/lib/seed-phrase-verifier.js new file mode 100644 index 000000000..9cea22029 --- /dev/null +++ b/app/scripts/lib/seed-phrase-verifier.js @@ -0,0 +1,48 @@ +const KeyringController = require('eth-keyring-controller') + +const seedPhraseVerifier = { + + // Verifies if the seed words can restore the accounts. + // + // The seed words can recreate the primary keyring and the accounts belonging to it. + // The created accounts in the primary keyring are always the same. + // The keyring always creates the accounts in the same sequence. + verifyAccounts (createdAccounts, seedWords) { + + return new Promise((resolve, reject) => { + + if (!createdAccounts || createdAccounts.length < 1) { + return reject(new Error('No created accounts defined.')) + } + + const keyringController = new KeyringController({}) + const Keyring = keyringController.getKeyringClassForType('HD Key Tree') + const opts = { + mnemonic: seedWords, + numberOfAccounts: createdAccounts.length, + } + + const keyring = new Keyring(opts) + keyring.getAccounts() + .then((restoredAccounts) => { + + log.debug('Created accounts: ' + JSON.stringify(createdAccounts)) + log.debug('Restored accounts: ' + JSON.stringify(restoredAccounts)) + + if (restoredAccounts.length !== createdAccounts.length) { + // this should not happen... + return reject(new Error('Wrong number of accounts')) + } + + for (let i = 0; i < restoredAccounts.length; i++) { + if (restoredAccounts[i].toLowerCase() !== createdAccounts[i].toLowerCase()) { + return reject(new Error('Not identical accounts! Original: ' + createdAccounts[i] + ', Restored: ' + restoredAccounts[i])) + } + } + return resolve() + }) + }) + }, +} + +module.exports = seedPhraseVerifier diff --git a/app/scripts/lib/tx-state-manager.js b/app/scripts/lib/tx-state-manager.js index 051efd247..2eb006380 100644 --- a/app/scripts/lib/tx-state-manager.js +++ b/app/scripts/lib/tx-state-manager.js @@ -4,7 +4,7 @@ const ObservableStore = require('obs-store') const ethUtil = require('ethereumjs-util') const txStateHistoryHelper = require('./tx-state-history-helper') -module.exports = class TransactionStateManger extends EventEmitter { +module.exports = class TransactionStateManager extends EventEmitter { constructor ({ initState, txHistoryLimit, getNetwork }) { super() |