|
|
@ -71,41 +71,39 @@ describe('simple-keyring', function() { |
|
|
|
it('reliably can decode messages it signs', function (done) { |
|
|
|
it('reliably can decode messages it signs', function (done) { |
|
|
|
|
|
|
|
|
|
|
|
const message = 'hello there!' |
|
|
|
const message = 'hello there!' |
|
|
|
let address, msgHashHex |
|
|
|
const msgHashHex = web3.sha3(message) |
|
|
|
|
|
|
|
let address |
|
|
|
|
|
|
|
let addresses = [] |
|
|
|
|
|
|
|
|
|
|
|
keyring.deserialize([ privateKey ]) |
|
|
|
keyring.deserialize([ privateKey ]) |
|
|
|
|
|
|
|
.then(() => { |
|
|
|
|
|
|
|
keyring.addAccounts(9) |
|
|
|
|
|
|
|
}) |
|
|
|
.then(() => { |
|
|
|
.then(() => { |
|
|
|
return keyring.getAccounts() |
|
|
|
return keyring.getAccounts() |
|
|
|
}) |
|
|
|
}) |
|
|
|
.then((addresses) => { |
|
|
|
.then((addrs) => { |
|
|
|
address = addresses[0] |
|
|
|
addresses = addrs |
|
|
|
msgHashHex = web3.sha3(message) |
|
|
|
return Promise.all(addresses.map((address) => { |
|
|
|
return keyring.signMessage(address, msgHashHex) |
|
|
|
return keyring.signMessage(address, msgHashHex) |
|
|
|
|
|
|
|
})) |
|
|
|
}) |
|
|
|
}) |
|
|
|
.then((sgn) => { |
|
|
|
.then((signatures) => { |
|
|
|
var r = ethUtil.toBuffer(sgn.slice(0,66)) |
|
|
|
|
|
|
|
var s = ethUtil.toBuffer('0x' + sgn.slice(66,130)) |
|
|
|
signatures.forEach((sgn, index) => { |
|
|
|
var v = ethUtil.bufferToInt(ethUtil.toBuffer('0x' + sgn.slice(130,132))) |
|
|
|
const address = addresses[index] |
|
|
|
var m = ethUtil.toBuffer(msgHashHex) |
|
|
|
|
|
|
|
console.dir({ r, s, v, m }) |
|
|
|
var r = ethUtil.toBuffer(sgn.slice(0,66)) |
|
|
|
var pub = ethUtil.ecrecover(m, v, r, s) |
|
|
|
var s = ethUtil.toBuffer('0x' + sgn.slice(66,130)) |
|
|
|
var adr = '0x' + ethUtil.pubToAddress(pub).toString('hex') |
|
|
|
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 sgn = ethUtil.stripHexPrefix(signature) |
|
|
|
var adr = '0x' + ethUtil.pubToAddress(pub).toString('hex') |
|
|
|
var r = ethUtil.toBuffer(sgn.slice(0,64)) |
|
|
|
|
|
|
|
var s = ethUtil.toBuffer(sgn.slice(64,128)) |
|
|
|
assert.equal(adr, address, 'recovers address from signature correctly') |
|
|
|
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() |
|
|
|
done() |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch((reason) => { |
|
|
|
|
|
|
|
console.dir(reason) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|