diff options
author | Csaba Solya <csaba.solya@gmail.com> | 2018-03-03 07:32:57 +0800 |
---|---|---|
committer | Csaba Solya <csaba.solya@gmail.com> | 2018-03-03 07:32:57 +0800 |
commit | 92453f8715b78c0e6e2cdb9b2e1cfe48c0b013ad (patch) | |
tree | d430911e722a580ffa7d282c59a8a94554a2feb1 /app/scripts/lib | |
parent | f22dfd4ae8031e3f7b4972a1cc8f119b99007717 (diff) | |
download | tangerine-wallet-browser-92453f8715b78c0e6e2cdb9b2e1cfe48c0b013ad.tar tangerine-wallet-browser-92453f8715b78c0e6e2cdb9b2e1cfe48c0b013ad.tar.gz tangerine-wallet-browser-92453f8715b78c0e6e2cdb9b2e1cfe48c0b013ad.tar.bz2 tangerine-wallet-browser-92453f8715b78c0e6e2cdb9b2e1cfe48c0b013ad.tar.lz tangerine-wallet-browser-92453f8715b78c0e6e2cdb9b2e1cfe48c0b013ad.tar.xz tangerine-wallet-browser-92453f8715b78c0e6e2cdb9b2e1cfe48c0b013ad.tar.zst tangerine-wallet-browser-92453f8715b78c0e6e2cdb9b2e1cfe48c0b013ad.zip |
seed phrase verifier
Diffstat (limited to 'app/scripts/lib')
-rw-r--r-- | app/scripts/lib/seed-phrase-verifier.js | 43 |
1 files changed, 43 insertions, 0 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..9bea2910e --- /dev/null +++ b/app/scripts/lib/seed-phrase-verifier.js @@ -0,0 +1,43 @@ +const KeyringController = require('eth-keyring-controller') + +const seedPhraseVerifier = { + + verifyAccounts(createdAccounts, seedWords) { + + return new Promise((resolve, reject) => { + + if (!createdAccounts || createdAccounts.length < 1) { + return reject(new Error('No created accounts defined.')) + } + + let keyringController = new KeyringController({}) + let Keyring = keyringController.getKeyringClassForType('HD Key Tree') + let opts = { + mnemonic: seedWords, + numberOfAccounts: createdAccounts.length, + } + + let 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] !== createdAccounts[i]) { + return reject(new Error('Not identical accounts! Original: ' + createdAccounts[i] + ', Restored: ' + restoredAccounts[i])) + } + } + return resolve() + }) + }) + } +} + +module.exports = seedPhraseVerifier
\ No newline at end of file |