diff options
author | Dan Finlay <dan@danfinlay.com> | 2016-03-26 03:41:18 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2016-03-26 03:41:18 +0800 |
commit | 37fd45e5b70a66ff976cab0d1815374063e29d10 (patch) | |
tree | 563e18f391806e1c7ef956eabcdef101cc211ec4 /app | |
parent | da31f4daed76a3457df12f94bbf2974621b70a0c (diff) | |
download | tangerine-wallet-browser-37fd45e5b70a66ff976cab0d1815374063e29d10.tar tangerine-wallet-browser-37fd45e5b70a66ff976cab0d1815374063e29d10.tar.gz tangerine-wallet-browser-37fd45e5b70a66ff976cab0d1815374063e29d10.tar.bz2 tangerine-wallet-browser-37fd45e5b70a66ff976cab0d1815374063e29d10.tar.lz tangerine-wallet-browser-37fd45e5b70a66ff976cab0d1815374063e29d10.tar.xz tangerine-wallet-browser-37fd45e5b70a66ff976cab0d1815374063e29d10.tar.zst tangerine-wallet-browser-37fd45e5b70a66ff976cab0d1815374063e29d10.zip |
Convert to bip44 hdTrees
Added initial test just to verify we can recover the accounts we generate in this way.
Still need to add compliance test to make sure this interoperates with testrpc's new mnemonic flag.
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/lib/idStore.js | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js index c4547b07f..1a3e7e06f 100644 --- a/app/scripts/lib/idStore.js +++ b/app/scripts/lib/idStore.js @@ -1,6 +1,7 @@ const EventEmitter = require('events').EventEmitter const inherits = require('util').inherits const Transaction = require('ethereumjs-tx') +const Lightwallet = require('eth-lightwallet') const LightwalletKeyStore = require('eth-lightwallet').keystore const LightwalletSigner = require('eth-lightwallet').signing const async = require('async') @@ -14,23 +15,24 @@ module.exports = IdentityStore inherits(IdentityStore, EventEmitter) function IdentityStore(ethStore) { - const self = this - EventEmitter.call(self) + EventEmitter.call(this) // we just use the ethStore to auto-add accounts - self._ethStore = ethStore + this._ethStore = ethStore // lightwallet key store - self._keyStore = null + this._keyStore = null // lightwallet wrapper - self._idmgmt = null + this._idmgmt = null + + this.hdPathString = "m/44'/60'/0'/0" - self._currentState = { + this._currentState = { selectedAddress: null, identities: {}, unconfTxs: {}, } // not part of serilized metamask state - only kept in memory - self._unconfTxCbs = {} + this._unconfTxCbs = {} } // @@ -122,7 +124,6 @@ IdentityStore.prototype.addUnconfirmedTransaction = function(txParams, cb){ status: 'unconfirmed', } self._currentState.unconfTxs[txId] = txData - console.log('addUnconfirmedTransaction:', txData) // keep the cb around for after approval (requires user interaction) self._unconfTxCbs[txId] = cb @@ -201,7 +202,7 @@ IdentityStore.prototype._loadIdentities = function(){ const self = this if (!self._isUnlocked()) throw new Error('not unlocked') // get addresses and normalize address hexString - var addresses = self._keyStore.getAddresses().map(function(address){ return '0x'+address }) + var addresses = self._keyStore.getAddresses(this.hdPathString).map(function(address){ return '0x'+address }) addresses.forEach(function(address){ // // add to ethStore self._ethStore.addAccount(address) @@ -257,7 +258,7 @@ IdentityStore.prototype._createIdmgmt = function(password, seed, entropy, cb){ IdentityStore.prototype._restoreFromSeed = function(keyStore, seed, derivedKey) { keyStore = new LightwalletKeyStore(seed, derivedKey) - keyStore.generateNewAddress(derivedKey, 3) + keyStore.generateNewAddress(derivedKey, 3, hdPathString) window.localStorage['lightwallet'] = keyStore.serialize() console.log('restored from seed. saved to keystore localStorage') } @@ -268,19 +269,20 @@ IdentityStore.prototype._loadFromLocalStorage = function(serializedKeystore, der IdentityStore.prototype._createFirstWallet = function(entropy, derivedKey) { var secretSeed = LightwalletKeyStore.generateRandomSeed(entropy) - var keyStore = new LightwalletKeyStore(secretSeed, derivedKey) - keyStore.generateNewAddress(derivedKey, 3) + var keyStore = new LightwalletKeyStore(secretSeed, derivedKey, this.hdPathString) + keyStore.generateNewAddress(derivedKey, 3, this.hdPathString) window.localStorage['lightwallet'] = keyStore.serialize() console.log('saved to keystore localStorage') return keyStore } -function IdManagement( opts = { keyStore: null, derivedKey: null } ) { +function IdManagement( opts = { keyStore: null, derivedKey: null, hdPathString: null } ) { this.keyStore = opts.keyStore this.derivedKey = opts.derivedKey + this.hdPathString = opts.hdPathString this.getAddresses = function(){ - return keyStore.getAddresses().map(function(address){ return '0x'+address }) + return keyStore.getAddresses(this.hdPathString).map(function(address){ return '0x'+address }) } this.signTx = function(txParams){ |