mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
Merge pull request #1007 from MetaMask/simple-keystore-fix
keyring - simple - fix address generation
This commit is contained in:
commit
c05b783466
@ -35,12 +35,12 @@ class SimpleKeyring extends EventEmitter {
|
|||||||
newWallets.push(Wallet.generate())
|
newWallets.push(Wallet.generate())
|
||||||
}
|
}
|
||||||
this.wallets = this.wallets.concat(newWallets)
|
this.wallets = this.wallets.concat(newWallets)
|
||||||
const hexWallets = newWallets.map(w => w.getAddress().toString('hex'))
|
const hexWallets = newWallets.map(w => ethUtil.bufferToHex(w.getAddress()))
|
||||||
return Promise.resolve(hexWallets)
|
return Promise.resolve(hexWallets)
|
||||||
}
|
}
|
||||||
|
|
||||||
getAccounts () {
|
getAccounts () {
|
||||||
return Promise.resolve(this.wallets.map(w => w.getAddress().toString('hex')))
|
return Promise.resolve(this.wallets.map(w => ethUtil.bufferToHex(w.getAddress())))
|
||||||
}
|
}
|
||||||
|
|
||||||
// tx is an instance of the ethereumjs-transaction class.
|
// tx is an instance of the ethereumjs-transaction class.
|
||||||
@ -54,6 +54,7 @@ class SimpleKeyring extends EventEmitter {
|
|||||||
// For eth_sign, we need to sign transactions:
|
// For eth_sign, we need to sign transactions:
|
||||||
signMessage (withAccount, data) {
|
signMessage (withAccount, data) {
|
||||||
const wallet = this._getWalletForAccount(withAccount)
|
const wallet = this._getWalletForAccount(withAccount)
|
||||||
|
|
||||||
const message = ethUtil.removeHexPrefix(data)
|
const message = ethUtil.removeHexPrefix(data)
|
||||||
var privKey = wallet.getPrivateKey()
|
var privKey = wallet.getPrivateKey()
|
||||||
var msgSig = ethUtil.ecsign(new Buffer(message, 'hex'), privKey)
|
var msgSig = ethUtil.ecsign(new Buffer(message, 'hex'), privKey)
|
||||||
@ -70,7 +71,9 @@ class SimpleKeyring extends EventEmitter {
|
|||||||
/* PRIVATE METHODS */
|
/* PRIVATE METHODS */
|
||||||
|
|
||||||
_getWalletForAccount (account) {
|
_getWalletForAccount (account) {
|
||||||
return this.wallets.find(w => w.getAddress().toString('hex') === account)
|
let wallet = this.wallets.find(w => ethUtil.bufferToHex(w.getAddress()) === account)
|
||||||
|
if (!wallet) throw new Error('Simple Keyring - Unable to find matching address.')
|
||||||
|
return wallet
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const extend = require('xtend')
|
const extend = require('xtend')
|
||||||
|
const ethUtil = require('ethereumjs-util')
|
||||||
const SimpleKeyring = require('../../../app/scripts/keyrings/simple')
|
const SimpleKeyring = require('../../../app/scripts/keyrings/simple')
|
||||||
const TYPE_STR = 'Simple Key Pair'
|
const TYPE_STR = 'Simple Key Pair'
|
||||||
|
|
||||||
@ -72,14 +73,10 @@ describe('simple-keyring', function() {
|
|||||||
it('calls getAddress on each wallet', function(done) {
|
it('calls getAddress on each wallet', function(done) {
|
||||||
|
|
||||||
// Push a mock wallet
|
// Push a mock wallet
|
||||||
const desiredOutput = 'foo'
|
const desiredOutput = '0x18a3462427bcc9133bb46e88bcbe39cd7ef0e761'
|
||||||
keyring.wallets.push({
|
keyring.wallets.push({
|
||||||
getAddress() {
|
getAddress() {
|
||||||
return {
|
return ethUtil.toBuffer(desiredOutput)
|
||||||
toString() {
|
|
||||||
return desiredOutput
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user