When I sign a string using the following code I get back a different address to the one I signed with. The address returned is different for different strings.
const util = require('ethereumjs-util')
const msg = web3.sha3('hello!');
const sig = web3.eth.sign(web3.eth.accounts[0], msg);
const {v, r, s} = util.fromRpcSig(sig);
const pubKey = util.ecrecover(util.toBuffer(msg), v, r, s);
const addrBuf = util.pubToAddress(pubKey);
const addr = util.bufferToHex(addrBuf);
I took the code from the answer to a question I asked previously here Getting an address from ethereumjs-utils erecover.
I asked a question here: Secp256k1 bindings are not compiled. Pure JS implementation will be used about a possibly relevant error. The comments suggested that it should be harmless though.
npm list
). I think there were a bug in some of thetestrpc
dependencies.