5

How to verify MetaMask account holder is the real owner of the address?

I recently saw this post and tried it immediately, unfortunately, I am not getting the right result from the server. I think it has something to do with the hashing algorithm sha3, but I am not sure. Could anyone please update the solution? Thank you!

4 Answers 4

4

I think this is what you are asking for...

Using Web3.js 1.0 and Metamask:

Create a signature for a message:

var message = "Some string"
var hash = web3.utils.sha3(message)
var accounts = await web3.eth.getAccounts()
var signature = await web3.eth.personal.sign(hash, accounts[0])

Recover the address for a message + signature:

var hash = web3.utils.sha3(message)
var signing_address = await web3.eth.personal.ecRecover(hash, signature)

You should see that signing_address will match accounts[0] if you are using the same message and signature across the board.

0

metamask and web3 injected for recover an ethereum account by message and sign

var hashCodificado = web3.fromUtf8("Autentificacion en Plataforma")

        web3.personal.ecRecover(hashCodificado, "0x9b2d3a06ff7da90b629b18eaa56e150da522fa77d550d06be14049ee808ca3aa471af025c1aa40e5e11e3b42a0e033935da7b934059c1e6bebbc4f6h4486d7b51b", function (error, result) {
                if (error) alert("Necesitas identificarte para poder entrar al panel de usuario");
                if (result) {
                    alert("La cuenta que ha firmado la transaccion es: " + result)
                }
            });
0

Here's what works for me with MetaMask Version 7.1.1:

Signing a message:

var message = "Some string"
var hash = web3.sha3(message)
var account = web3.eth.accounts[0]

web3.personal.sign(hash, account, function(error, signature) {
    console.log(signature, error)
})

Getting the address of the signature:

var signature = "0x..."

var message_hash = web3.sha3(message)
web3.personal.ecRecover(message_hash, signature, function(error, signing_address) {
    console.log(signing_address, error);
})
1
  • How does this work on a server? web3.sha3 is 0.2, which is what MM injects, but your server should be running 1.2+ if using node. Commented Dec 21, 2019 at 6:51
0

I have been into a similar issue and none of answers worked out of the box for me.

I have come up with a solution that was tested to work with MetaMask and WalletConnect. I have published a detail answer here: How to verify MetaMask account holder is the real owner of the address?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.