aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-02-14 13:29:22 +0800
committerDan Finlay <dan@danfinlay.com>2017-02-14 13:29:22 +0800
commit97b8410b3001a45249244b5a236d31e1975154a2 (patch)
tree9f51e731afd1640409e977c1a2dc85e7375c54e3
parentf2486fbdd34246619f62ff67bb3ab6e77d202f26 (diff)
downloadtangerine-wallet-browser-97b8410b3001a45249244b5a236d31e1975154a2.tar
tangerine-wallet-browser-97b8410b3001a45249244b5a236d31e1975154a2.tar.gz
tangerine-wallet-browser-97b8410b3001a45249244b5a236d31e1975154a2.tar.bz2
tangerine-wallet-browser-97b8410b3001a45249244b5a236d31e1975154a2.tar.lz
tangerine-wallet-browser-97b8410b3001a45249244b5a236d31e1975154a2.tar.xz
tangerine-wallet-browser-97b8410b3001a45249244b5a236d31e1975154a2.tar.zst
tangerine-wallet-browser-97b8410b3001a45249244b5a236d31e1975154a2.zip
Verify messages in a loop
-rw-r--r--test/unit/keyrings/simple-test.js52
1 files changed, 25 insertions, 27 deletions
diff --git a/test/unit/keyrings/simple-test.js b/test/unit/keyrings/simple-test.js
index c09695b4c..ba7dd448a 100644
--- a/test/unit/keyrings/simple-test.js
+++ b/test/unit/keyrings/simple-test.js
@@ -71,41 +71,39 @@ describe('simple-keyring', function() {
it('reliably can decode messages it signs', function (done) {
const message = 'hello there!'
- let address, msgHashHex
+ const msgHashHex = web3.sha3(message)
+ let address
+ let addresses = []
keyring.deserialize([ privateKey ])
.then(() => {
+ keyring.addAccounts(9)
+ })
+ .then(() => {
return keyring.getAccounts()
})
- .then((addresses) => {
- address = addresses[0]
- msgHashHex = web3.sha3(message)
- return keyring.signMessage(address, msgHashHex)
+ .then((addrs) => {
+ addresses = addrs
+ return Promise.all(addresses.map((address) => {
+ return keyring.signMessage(address, msgHashHex)
+ }))
})
- .then((sgn) => {
- var r = ethUtil.toBuffer(sgn.slice(0,66))
- var s = ethUtil.toBuffer('0x' + sgn.slice(66,130))
- 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')
-
- /*
- 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')
+ .then((signatures) => {
+
+ signatures.forEach((sgn, index) => {
+ const address = addresses[index]
+
+ var r = ethUtil.toBuffer(sgn.slice(0,66))
+ var s = ethUtil.toBuffer('0x' + sgn.slice(66,130))
+ var v = ethUtil.bufferToInt(ethUtil.toBuffer('0x' + sgn.slice(130,132)))
+ var m = ethUtil.toBuffer(msgHashHex)
+ var pub = ethUtil.ecrecover(m, v, r, s)
+ var adr = '0x' + ethUtil.pubToAddress(pub).toString('hex')
+
+ assert.equal(adr, address, 'recovers address from signature correctly')
+ })
done()
})
- .catch((reason) => {
- console.dir(reason)
- })
})
})