aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-02-14 12:13:11 +0800
committerDan Finlay <dan@danfinlay.com>2017-02-14 12:13:11 +0800
commitb862d942097b645abe31fa2af87226e544ecd627 (patch)
treeb7742845cba5269fb89e9252e5f74a0fde64f26b /test/unit
parent07422ae8350c08a68ecf17b8ca2ec08f9ea1805f (diff)
downloadtangerine-wallet-browser-b862d942097b645abe31fa2af87226e544ecd627.tar
tangerine-wallet-browser-b862d942097b645abe31fa2af87226e544ecd627.tar.gz
tangerine-wallet-browser-b862d942097b645abe31fa2af87226e544ecd627.tar.bz2
tangerine-wallet-browser-b862d942097b645abe31fa2af87226e544ecd627.tar.lz
tangerine-wallet-browser-b862d942097b645abe31fa2af87226e544ecd627.tar.xz
tangerine-wallet-browser-b862d942097b645abe31fa2af87226e544ecd627.tar.zst
tangerine-wallet-browser-b862d942097b645abe31fa2af87226e544ecd627.zip
Add failing test for signature recovery
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/keyrings/simple-test.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/unit/keyrings/simple-test.js b/test/unit/keyrings/simple-test.js
index 77eeb834c..60b762cb8 100644
--- a/test/unit/keyrings/simple-test.js
+++ b/test/unit/keyrings/simple-test.js
@@ -1,5 +1,7 @@
const assert = require('assert')
const extend = require('xtend')
+const Web3 = require('web3')
+const web3 = new Web3()
const ethUtil = require('ethereumjs-util')
const SimpleKeyring = require('../../../app/scripts/keyrings/simple')
const TYPE_STR = 'Simple Key Pair'
@@ -65,6 +67,37 @@ describe('simple-keyring', function() {
done()
})
})
+
+ it('reliably can decode messages it signs', function (done) {
+
+ const message = 'hello there!'
+ let address, msgHex
+
+ keyring.addAccounts(10)
+ .then((addresses) => {
+ address = addresses[0]
+ msgHex = web3.sha3(message)
+ return keyring.signMessage(address, msgHex)
+ })
+ .then((signature) => {
+ var sgn = signature
+ 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 adr = '0x' + ethUtil.pubToAddress(pub).toString('hex')
+ assert.equal(adr, address)
+ done()
+ })
+ .catch((reason) => {
+ console.log('failed for reason:')
+ console.dir(reason)
+ assert.equal(true, false, reason)
+ done()
+ })
+ })
})
describe('#addAccounts', function() {