diff options
author | Kevin Serrano <kevgagser@gmail.com> | 2016-11-04 06:40:23 +0800 |
---|---|---|
committer | Kevin Serrano <kevgagser@gmail.com> | 2016-11-04 06:40:23 +0800 |
commit | 2afc06287dfd1a87bd247234c9a04b92a8394cac (patch) | |
tree | 246d62342150415b391582486405bc728a7a0419 /app | |
parent | e0246975a7a40a72cc68fb3dbe5782c9c219fea2 (diff) | |
download | tangerine-wallet-browser-2afc06287dfd1a87bd247234c9a04b92a8394cac.tar tangerine-wallet-browser-2afc06287dfd1a87bd247234c9a04b92a8394cac.tar.gz tangerine-wallet-browser-2afc06287dfd1a87bd247234c9a04b92a8394cac.tar.bz2 tangerine-wallet-browser-2afc06287dfd1a87bd247234c9a04b92a8394cac.tar.lz tangerine-wallet-browser-2afc06287dfd1a87bd247234c9a04b92a8394cac.tar.xz tangerine-wallet-browser-2afc06287dfd1a87bd247234c9a04b92a8394cac.tar.zst tangerine-wallet-browser-2afc06287dfd1a87bd247234c9a04b92a8394cac.zip |
Implement private key exporting.
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/keyring-controller.js | 9 | ||||
-rw-r--r-- | app/scripts/keyrings/hd.js | 16 |
2 files changed, 22 insertions, 3 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js index 505414c88..aa303c43c 100644 --- a/app/scripts/keyring-controller.js +++ b/app/scripts/keyring-controller.js @@ -353,7 +353,6 @@ module.exports = class KeyringController extends EventEmitter { gasMultiplier: configManager.getGasMultiplier() || 1, } - console.log('addUnconfirmedTransaction:', txData) // keep the onTxDoneCb around for after approval/denial (requires user interaction) // This onTxDoneCb fires completion to the Dapp's write operation. @@ -525,7 +524,13 @@ module.exports = class KeyringController extends EventEmitter { } exportAccount(address, cb) { - cb(null, '0xPrivateKey') + try { + const keyring = this.getKeyringForAccount(address) + const privateKey = keyring.exportAccount(normalize(address)) + cb(null, privateKey) + } catch (e) { + cb(e) + } } getNetwork(err) { diff --git a/app/scripts/keyrings/hd.js b/app/scripts/keyrings/hd.js index d0ebee419..4bfc56c15 100644 --- a/app/scripts/keyrings/hd.js +++ b/app/scripts/keyrings/hd.js @@ -48,6 +48,11 @@ module.exports = class HdKeyring extends EventEmitter { } } + exportAccount(address) { + const wallet = this.getWalletForAccount(address) + return wallet.getPrivateKey().toString('hex') + } + addAccounts(n = 1) { if (!this.root) { this.initFromMnemonic(bip39.generateMnemonic()) @@ -87,7 +92,16 @@ module.exports = class HdKeyring extends EventEmitter { } getWalletForAccount(account) { - return this.wallets.find(w => w.getAddress().toString('hex') === account) + return this.wallets.find((w) => { + const address = w.getAddress().toString('hex') + return ((address === account) || (normalize(address) === account)) + }) } + + +} + +function normalize(address) { + return ethUtil.addHexPrefix(address.toLowerCase()) } |