web3modal icon indicating copy to clipboard operation
web3modal copied to clipboard

personal_ecRecover AND eth_signTypedData_v4

Open MetallianFR68 opened this issue 4 years ago • 1 comments

Hi,

provider.request({method: 'eth_signTypedData_v4', params: [pubkey,JSON.stringify(payload)]}) .then((signature) => { provider.request({method: 'personal_ecRecover',params: [JSON.stringify(payload), signature]}) .then((pubkey) => { console.log(pubkey); }) })

If I sign a message with "personal_sign", I can immediately extract the public key from the signature with "personal_ecRecover". This allows me to authenticate the sender

Howewer I read everywhere that we have to use "eth_signTypedData_v4" instead of "personal_sign" for security reasons. (EIP-712) But If I use "personal_ecRecover" on a signature generated by "eth_signTypedData_v4", it doesn't work. The extracted key returned by the function is not the good one.

Any idea why ? Is there another way to extract the public key ? I'm searching for an easy solution in vanilla javascript

Thanks in advance

Best regards

MetallianFR68 avatar Apr 26 '21 04:04 MetallianFR68

@MetallianFR68 here's an example of how you can do this using @metamask/eth-sig-util

https://github.com/MetaMask/eth-sig-util/blob/cde38f7aa3f8e8d0a7ee75730f363325b8e1924c/src/sign-typed-data.test.ts#L6421

0x7An avatar Jun 30 '22 13:06 0x7An

With stable version 2.0.0 of Web3Modal now released, we are officially dropping support for version 1.x Due to this this issue/pr was marked for closing. It is highly recommended to upgrade as 2.x will be receiving further updates that will enable functionality for some of our newer sdks like auth and push as well as support for WalletConnect v2 (See this post about WalletConnect v1 being deprecated https://medium.com/walletconnect/walletconnect-v1-0-sunset-notice-and-migration-schedule-8af9d3720d2e)

If you need to continue using Web3Modal 1.x and require this feature/fix implemented, we suggest adding it via forking V1 branch.

xzilja avatar Jan 21 '23 14:01 xzilja