wevm/wagmi

Mismatch between processing of typed data when signing and verifying

Closed this issue · 3 comments

Describe the bug

The verification fails because of additional processing of typed data struct fields that is different between signTypedData and verifyTypedData

Link to Minimal Reproducible Example

No response

Steps To Reproduce

POC. The address should contain both uppercase and lowercase characters (according to standard formatting).

const signature = await signTypedData(rainbowkitConfig, {
  types,
  domain,
  primaryType: 'WalletData',
  message: {
    address,
  },
})

const verificationResult = await verifyTypedData(rainbowkitConfig, {
  address,
  types,
  signature,
  domain,
  primaryType: 'WalletData',
  message: {
    address,
  },
})

Running the above code, the signTypedData will pass, but the verification will fail.

However, if the address is modified only in the verifyTypedData call, it now passess. This implies some additional processing happening before signTypedData is called in viem.

What Wagmi package(s) are you using?

@wagmi/core

Wagmi Version

^2.5.20

Viem Version

^2.9.25

TypeScript Version

^5.3.3

Check existing issues

Anything else?

Likely a Viem issue, due to the following code in viem/actions/wallet/signTypedData.ts:

const typedData = stringify(
  { domain: domain ?? {}, message, primaryType, types },
  (_, value) => (isHex(value) ? value.toLowerCase() : value),
)
tmm commented

Better to track upstream on Viem

This issue has been locked since it has been closed for more than 14 days.

If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Wagmi version. If you have any questions or comments you can create a new discussion thread.