Signatures created in metamask with ledger is being rejected by ECDSA.recover

https://ethereum.stackexchange.com/questions/145045/signatures-created-in-metamask-with-ledger-is-being-rejected-by-ecdsa-recover

Some context.

  • The frontend right now is using wagmi under the hood, we are using the signMessageAsync method to generate a signature. Code is below
const { signMessageAsync } = useSignMessage()
const signature = await signMessageAsync({
  message: ethers.utils.arrayify(...),
})
  • We are 100% that we are passing the right parameters in the value that is passed to arrayify since hot wallets and wallet connect with ledger live is working. Only metamask with ledger is not working.

  • The recovery method on the smart contract is below.

require(ECDSA.recover(<eth signed hash>, sig) == msg.sender, "Invalid signature!");
  • We noticed that the last bits of the signature is 00 or 01. So we tried to adjust the v parameter with the function below to make sure it is of the right value.
function _adjustV(v: number): number {
  const chainId = <chain id of current network - we use public env vars for this>
  const baseV = chainId * 2 + 35
  if (v % 2 === 0) {
    return baseV
  } else {
    return baseV + 1
  }
}

It still doesn’t work. Is there a special workaround needed for metamask with ledger to work?