1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 03:36:18 +02:00

Implement private key exporting.

This commit is contained in:
Kevin Serrano 2016-11-03 15:40:23 -07:00
parent e0246975a7
commit 2afc06287d
No known key found for this signature in database
GPG Key ID: 7CC862A58D2889B4
2 changed files with 22 additions and 3 deletions

View File

@ -353,7 +353,6 @@ module.exports = class KeyringController extends EventEmitter {
gasMultiplier: configManager.getGasMultiplier() || 1, gasMultiplier: configManager.getGasMultiplier() || 1,
} }
console.log('addUnconfirmedTransaction:', txData)
// keep the onTxDoneCb around for after approval/denial (requires user interaction) // keep the onTxDoneCb around for after approval/denial (requires user interaction)
// This onTxDoneCb fires completion to the Dapp's write operation. // This onTxDoneCb fires completion to the Dapp's write operation.
@ -525,7 +524,13 @@ module.exports = class KeyringController extends EventEmitter {
} }
exportAccount(address, cb) { 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) { getNetwork(err) {

View File

@ -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) { addAccounts(n = 1) {
if (!this.root) { if (!this.root) {
this.initFromMnemonic(bip39.generateMnemonic()) this.initFromMnemonic(bip39.generateMnemonic())
@ -87,7 +92,16 @@ module.exports = class HdKeyring extends EventEmitter {
} }
getWalletForAccount(account) { 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())
} }