diff options
author | Dan Finlay <dan@danfinlay.com> | 2017-02-14 13:25:02 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2017-02-14 13:25:02 +0800 |
commit | f2486fbdd34246619f62ff67bb3ab6e77d202f26 (patch) | |
tree | 291c60ebc060f921d3b399f02257d0d046cc8479 | |
parent | b862d942097b645abe31fa2af87226e544ecd627 (diff) | |
download | tangerine-wallet-browser-f2486fbdd34246619f62ff67bb3ab6e77d202f26.tar tangerine-wallet-browser-f2486fbdd34246619f62ff67bb3ab6e77d202f26.tar.gz tangerine-wallet-browser-f2486fbdd34246619f62ff67bb3ab6e77d202f26.tar.bz2 tangerine-wallet-browser-f2486fbdd34246619f62ff67bb3ab6e77d202f26.tar.lz tangerine-wallet-browser-f2486fbdd34246619f62ff67bb3ab6e77d202f26.tar.xz tangerine-wallet-browser-f2486fbdd34246619f62ff67bb3ab6e77d202f26.tar.zst tangerine-wallet-browser-f2486fbdd34246619f62ff67bb3ab6e77d202f26.zip |
got hash test passing
-rw-r--r-- | app/scripts/keyrings/hd.js | 4 | ||||
-rw-r--r-- | app/scripts/keyrings/simple.js | 3 | ||||
-rw-r--r-- | test/unit/keyrings/simple-test.js | 37 |
3 files changed, 28 insertions, 16 deletions
diff --git a/app/scripts/keyrings/hd.js b/app/scripts/keyrings/hd.js index 7b10f925a..3a66f7868 100644 --- a/app/scripts/keyrings/hd.js +++ b/app/scripts/keyrings/hd.js @@ -112,9 +112,11 @@ class HdKeyring extends EventEmitter { _getWalletForAccount (account) { + const targetAddress = sigUtil.normalize(account) return this.wallets.find((w) => { const address = w.getAddress().toString('hex') - return ((address === account) || (sigUtil.normalize(address) === account)) + return ((address === targetAddress) || + (sigUtil.normalize(address) === targetAddress)) }) } } diff --git a/app/scripts/keyrings/simple.js b/app/scripts/keyrings/simple.js index b6ffc606e..82881aa2d 100644 --- a/app/scripts/keyrings/simple.js +++ b/app/scripts/keyrings/simple.js @@ -88,7 +88,8 @@ class SimpleKeyring extends EventEmitter { /* PRIVATE METHODS */ _getWalletForAccount (account) { - let wallet = this.wallets.find(w => ethUtil.bufferToHex(w.getAddress()) === account) + const address = sigUtil.normalize(account) + let wallet = this.wallets.find(w => ethUtil.bufferToHex(w.getAddress()) === address) 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 60b762cb8..c09695b4c 100644 --- a/test/unit/keyrings/simple-test.js +++ b/test/unit/keyrings/simple-test.js @@ -71,31 +71,40 @@ describe('simple-keyring', function() { it('reliably can decode messages it signs', function (done) { const message = 'hello there!' - let address, msgHex + let address, msgHashHex - keyring.addAccounts(10) + keyring.deserialize([ privateKey ]) + .then(() => { + return keyring.getAccounts() + }) .then((addresses) => { address = addresses[0] - msgHex = web3.sha3(message) - return keyring.signMessage(address, msgHex) + msgHashHex = web3.sha3(message) + return keyring.signMessage(address, msgHashHex) }) - .then((signature) => { - var sgn = signature + .then((sgn) => { var r = ethUtil.toBuffer(sgn.slice(0,66)) var s = ethUtil.toBuffer('0x' + sgn.slice(66,130)) - var v = parseInt(sgn.slice(130,132)) + 27 - var msgBuffer = ethUtil.toBuffer(msgHex) - var msgHash = ethUtil.hashPersonalMessage(msgBuffer) - var pub = ethUtil.ecrecover(msgHash, v, r, s) + var v = ethUtil.bufferToInt(ethUtil.toBuffer('0x' + sgn.slice(130,132))) + var m = ethUtil.toBuffer(msgHashHex) + console.dir({ r, s, v, m }) + var pub = ethUtil.ecrecover(m, v, r, s) var adr = '0x' + ethUtil.pubToAddress(pub).toString('hex') - assert.equal(adr, address) + + /* + var sgn = ethUtil.stripHexPrefix(signature) + var r = ethUtil.toBuffer(sgn.slice(0,64)) + var s = ethUtil.toBuffer(sgn.slice(64,128)) + var v = parseInt(sgn.slice(128,130)) + 27 + var msgHashBuffer = ethUtil.toBuffer(msgHashHex) + var pub = ethUtil.ecrecover(msgHashBuffer, v, r, s) + var adr = '0x' + ethUtil.pubToAddress(pub).toString('hex') + */ + assert.equal(adr, address, 'recovers address from signature correctly') done() }) .catch((reason) => { - console.log('failed for reason:') console.dir(reason) - assert.equal(true, false, reason) - done() }) }) }) |