aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Finlay <flyswatter@users.noreply.github.com>2017-01-17 04:20:39 +0800
committerGitHub <noreply@github.com>2017-01-17 04:20:39 +0800
commitc05b783466c792789e321e5012e6e4fed6908abd (patch)
tree871c43750e3d3c2ebf8e096f2a5ecee0e65cfbd4
parentac6a2b4b61f34d3a60fc7cab926d390e172ed276 (diff)
parent053066b57ff73b4858cf9180748bf57495c47e62 (diff)
downloadtangerine-wallet-browser-c05b783466c792789e321e5012e6e4fed6908abd.tar
tangerine-wallet-browser-c05b783466c792789e321e5012e6e4fed6908abd.tar.gz
tangerine-wallet-browser-c05b783466c792789e321e5012e6e4fed6908abd.tar.bz2
tangerine-wallet-browser-c05b783466c792789e321e5012e6e4fed6908abd.tar.lz
tangerine-wallet-browser-c05b783466c792789e321e5012e6e4fed6908abd.tar.xz
tangerine-wallet-browser-c05b783466c792789e321e5012e6e4fed6908abd.tar.zst
tangerine-wallet-browser-c05b783466c792789e321e5012e6e4fed6908abd.zip
Merge pull request #1007 from MetaMask/simple-keystore-fix
keyring - simple - fix address generation
-rw-r--r--app/scripts/keyrings/simple.js9
-rw-r--r--test/unit/keyrings/simple-test.js9
2 files changed, 9 insertions, 9 deletions
diff --git a/app/scripts/keyrings/simple.js b/app/scripts/keyrings/simple.js
index 9717f1c45..6b16137ae 100644
--- a/app/scripts/keyrings/simple.js
+++ b/app/scripts/keyrings/simple.js
@@ -35,12 +35,12 @@ class SimpleKeyring extends EventEmitter {
newWallets.push(Wallet.generate())
}
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)
}
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.
@@ -54,6 +54,7 @@ class SimpleKeyring extends EventEmitter {
// For eth_sign, we need to sign transactions:
signMessage (withAccount, data) {
const wallet = this._getWalletForAccount(withAccount)
+
const message = ethUtil.removeHexPrefix(data)
var privKey = wallet.getPrivateKey()
var msgSig = ethUtil.ecsign(new Buffer(message, 'hex'), privKey)
@@ -70,7 +71,9 @@ class SimpleKeyring extends EventEmitter {
/* PRIVATE METHODS */
_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
}
}
diff --git a/test/unit/keyrings/simple-test.js b/test/unit/keyrings/simple-test.js
index 979abdb69..687318f99 100644
--- a/test/unit/keyrings/simple-test.js
+++ b/test/unit/keyrings/simple-test.js
@@ -1,5 +1,6 @@
const assert = require('assert')
const extend = require('xtend')
+const ethUtil = require('ethereumjs-util')
const SimpleKeyring = require('../../../app/scripts/keyrings/simple')
const TYPE_STR = 'Simple Key Pair'
@@ -72,14 +73,10 @@ describe('simple-keyring', function() {
it('calls getAddress on each wallet', function(done) {
// Push a mock wallet
- const desiredOutput = 'foo'
+ const desiredOutput = '0x18a3462427bcc9133bb46e88bcbe39cd7ef0e761'
keyring.wallets.push({
getAddress() {
- return {
- toString() {
- return desiredOutput
- }
- }
+ return ethUtil.toBuffer(desiredOutput)
}
})