question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

_signTypedData result does not match address recovered from signature on the back-end side

See original GitHub issue

Describe the bug When using signer._signTypedData and MetaMask browser extension, the result of the function doesn’t match the recovered signature on the back-end.

Reproduction steps To reproduce this issue:

  • create a new provider const provider = new ethers.providers.Web3Provider(window.ethereum)
  • create a signer calling const signer = provider.current.getSigner()
  • create a signature:
    const signatureResult = await signer._signTypedData(
      domain,
      { types: types.Auth}, // exclude the EIP712Domain type
      message
    );
  • sign message via MetaMask;

After that, I make a request to the back-end server to verify the signed data and get JSON with data back, the error described above occurs as the result of this request.

Environment: Front-end:

  • ethers.js
  • useDapp
  • Next.js
  • TypeScript

Back-end:

Current solution Currently, I rewrote the code to use the external provider’s sendAsync method like this:

    provider.sendAsync(
      {
        method,
        params: [
          address,
          JSON.stringify({
            domain,
            message,
            primaryType,
            types,
          }),
        ],
      }, (err, result) => ... )

This solved the issue for now. Maybe you could look up to this and propose a possible fix, or provide a better solution to the problem. Thank you in advance.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
skylightxocommented, Jan 25, 2022

Embarrassing to realize, I completely messed up with types…

    const signatureResult = await signer._signTypedData(
      domain,
      { types: types.Auth}, // <-- the problem was here, 
      message
    );

fixed code

    const signatureResult = await signer._signTypedData(
      domain,
      { Auth: types.Auth}, // <-- works as a charm
      message
    );

@ricmoo thank you for your help, I’m closing the issue.

0reactions
skylightxocommented, Apr 30, 2022

Experiencing this same issue @skylightxo – do you mind explaining why the change from { types: types.Auth} to { Auth: types.Auth} solved this issue?

Hello, @taayyohh. Sure, the problem is that I was passing an argument for types as an object with a ‘types’ key, which is the cause of the issue. So, consider { types: types.Auth } as a variable.

let types = { types: types.Auth }; // <-- not appropriate
let types = { Auth: types.Auth }; // <-- works fine
Read more comments on GitHub >

github_iconTop Results From Across the Web

solidity cannot verify ethers.js signed data (signTypedData)
I am having a similar issue: using Metamask signTypedData_v4 to sign a message; I can recover address of signer in the browser but...
Read more >
recover_message gives different address from EIP-712 ...
I'm trying to sign some data using EIP-712 with their Web3 client (Using Metamask in my case), and then recover the address on...
Read more >
Signing and Verifying Ethereum Signatures
In this article, let's look at how you can perform off-chain computation using Ethereum signatures. Cryptographic signatures can be used to ...
Read more >
EIP712 is here: What to expect and how to use it
Figure 1: a signature request from a dApp that does not use EIP712 ... compare the result to your wallet address, and then...
Read more >
Documentation - Ethers.js
Performs a reverse lookup of the address in ENS using the Reverse Registrar. If the name does not exist, or the forward lookup...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found