mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Implement private key exporting.
This commit is contained in:
parent
e0246975a7
commit
2afc06287d
@ -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…
Reference in New Issue
Block a user