Implement private key exporting.

feature/default_network_editable
Kevin Serrano 8 years ago
parent e0246975a7
commit 2afc06287d
No known key found for this signature in database
GPG Key ID: 7CC862A58D2889B4
  1. 9
      app/scripts/keyring-controller.js
  2. 16
      app/scripts/keyrings/hd.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) {

@ -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())
}

Loading…
Cancel
Save