2

I am trying to create a meteor dapp that can sign a piece of data and then recover the address it was signed with. When I run the dapp I get this error in the console:

Secp256k1 bindings are not compiled. Pure JS implementation will be used

I believe this is causing issues with web3.eth.sign as I cannot recover the address I signed with using ecrecover in either a contract or from ethereumjs-util.

From this answer https://ethereum.stackexchange.com/a/12684 it appears node version 5 or greater is required however meteor only supports node 4.

Is this error a problem or should I ignore it?

Joe
  • 1,173
  • 1
  • 11
  • 31
  • This is an innocent error that has no pronounced effect on web3, I have had the same for more than a year in Meteor and it has never hampered development. – Joël Mar 06 '17 at 13:42
  • @Joël do you have any idea why I cant get the correct address from ecrecover then? http://ethereum.stackexchange.com/questions/12621/getting-the-wrong-address-back-from-ecrecover?noredirect=1&lq=1 – Joe Mar 06 '17 at 14:05

1 Answers1

2

If you use web3 to sign a message and then try to verify that message in a contract, you need to prepend the following string to the message before running ecrecover in a contract: \x19Ethereum Signed Message:\n<length of message>

There are the two places where I found this.

https://github.com/ethereum/go-ethereum/issues/3731

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign

The Ethereum wiki page has a link after the Example in the eth_sign documentation, that links to an example of using solidity ecrecover to verify signature calculated with web3.eth.sign. Pasting it here for completeness.

https://gist.github.com/bas-vk/d46d83da2b2b4721efb0907aecdb7ebd

Ajoy Bhatia
  • 1,446
  • 15
  • 31
  • I have been using ecrecover from ethereumjs utils not from a contract. Do I still need to prepend the string? – Joe May 09 '17 at 08:41
  • AFAIK, you should not need to prepend the string when using ecrecover from ethereumjs utils. You might want to confirm this by looking at the ethereumjs utils source code. I mentioned the above because you also mentioned using ecrecover in a contract when you wrote " ... cannot recover the address I signed with using ecrecover in either a contract or from ethereumjs-util." – Ajoy Bhatia May 23 '17 at 17:06