0

I want to verify my user before the server sends him information.

So I want the user to sign a message using his private key, then the server decrypt that signature to verify the user is indeed the owner of a wallet address.

So I used the following on the client side

web3.eth.personal.sign

I am not sure what I can use on the server side to decrypt that signature and verify the original message and sender address.

Thank you for advance.

1

1 Answer 1

2

Most answers for verification are outdated. Something like the following worked for me.

    var msg = Buffer.from(msgstr);
    const prefix = Buffer.from("\x19Ethereum Signed Message:\n");
    var prefixedMsg = Buffer.concat([prefix, 
    Buffer.from(String(msgstr.length)), msg]);
    
    prefixedMsg = Web3.utils.keccak256(prefixedMsg);
    prefixedMsg = prefixedMsg.substring(2);
    prefixedMsg = Uint8Array.from(Buffer.from(prefixedMsg, 'hex'));
    var pub = ethJsUtil.ecrecover(prefixedMsg , vrs.v, vrs.r, vrs.s);
    var addrBuf = ethJsUtil.pubToAddress(pub);
    var addr = ethJsUtil.bufferToHex(addrBuf);

Your Answer

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

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