Unable to recover signer from hash and signature using viem but works for ethers.js #1685
-
I'm trying to recover the address which signed a hash by using viem's recoverAddress method, but the value it is giving is not the correct value which i'm expecting. But when i use ethers library, it is giving me correct results. Viem Version is "^1.20.3" Example ValuesHash: 0x2a87193349a393ba9a914af959b532120dfb2a2bc7aeabd7de344dd711bb92fc Expected Signer Address: 0xC6dAB8652E5E9749523bA948F42d5944584E4e73 Code with ethers
Code with viem
Usage
Console OutputRecovered address from Viem: 0xefCb4A92Df00e54987CDC9D9e1B98E07A466D608 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Looks like the hash uses a EIP-191 prefix. So you would need to use await recoverMessageAddress({
message: { raw: '0x2a87193349a393ba9a914af959b532120dfb2a2bc7aeabd7de344dd711bb92fc' },
signature: '0x5ae4e70321e29afe793c5d00711c72716febced4e7944233c7788dacb242325e4c6bc072a509d52aebaee8baab7294017ee3cdb94b37da545b29cb678cd0b5a91b',
}) |
Beta Was this translation helpful? Give feedback.
Looks like the hash uses a EIP-191 prefix. So you would need to use
recoverMessageAddress
(recoverAddress
is the raw version of this, andrecoverMessageAddress
uses it internally but also adds on the prefix).