diff options
author | frankiebee <frankie.diamond@gmail.com> | 2018-03-14 06:27:26 +0800 |
---|---|---|
committer | frankiebee <frankie.diamond@gmail.com> | 2018-03-14 06:27:26 +0800 |
commit | a2c14ad02b6f080efe18535d64efe4acdaa5f310 (patch) | |
tree | a4f10bab758b35c5344557907c7c95a396e4fbb9 /app/scripts/lib | |
parent | c465d510b100fdf9926413751df04cbd59de68eb (diff) | |
parent | c83a9ceb04a485149fe65fbb2b44f0adeda696b1 (diff) | |
download | tangerine-wallet-browser-a2c14ad02b6f080efe18535d64efe4acdaa5f310.tar tangerine-wallet-browser-a2c14ad02b6f080efe18535d64efe4acdaa5f310.tar.gz tangerine-wallet-browser-a2c14ad02b6f080efe18535d64efe4acdaa5f310.tar.bz2 tangerine-wallet-browser-a2c14ad02b6f080efe18535d64efe4acdaa5f310.tar.lz tangerine-wallet-browser-a2c14ad02b6f080efe18535d64efe4acdaa5f310.tar.xz tangerine-wallet-browser-a2c14ad02b6f080efe18535d64efe4acdaa5f310.tar.zst tangerine-wallet-browser-a2c14ad02b6f080efe18535d64efe4acdaa5f310.zip |
Merge remote-tracking branch 'origin/i#3509' into i#3509
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() |