php-ecrecover icon indicating copy to clipboard operation
php-ecrecover copied to clipboard

Why is the calculated address incorrect?

Open vtchg002 opened this issue 2 years ago • 1 comments

Why is the calculated address incorrect? 0xd3173e4f9de6bcc7dc5e4bfb68d4cc55019199a6350a384ad6a2e9a62c50ee26 0x0877b84f7fe8b38fef2569bb6e66ac7c031d99d6a12e65d55e5b7d30f76de5fa5ab6dd61511d88799c4d3d596f07f2162ae9e0e33fe159a7a672b485fc82f86d1b It comes out to be 0x9f135e9eb1e8186fafc34d498943c838eb8a1d6c It's actually 0x7ceE6241C5C1aE1c484D39031042e4c2cfe8a196

vtchg002 avatar Apr 16 '22 14:04 vtchg002

I was facing the same issue, it appeared to be an error in my code. When creating a signing message you you do it like this:

var web3 = new Web3(window.ethereum);
					
const accounts = await web3.eth.getAccounts();
		
const msgtext = "Hello world";
const message = web3.utils.fromUtf8(msgtext);
				
const signature = await web3.eth.personal.sign(message, accounts[0]);

I was using const message = web3.utils.sha3("Hello world"); which is wrong.

Your goal is to have the message visible in metamask window when signing, so no 0xhash there.

In PHP file simple do:

echo personal_ecRecover($message, $signature);

And it works. Took me a while to figure this out so I hope it helps someone with the same problem.

LubomirKurpel avatar Apr 28 '22 02:04 LubomirKurpel