rainbow-me / rainbowkit

The best way to connect a wallet 🌈 🧰
https://rainbowkit.com
MIT License
2.4k stars 638 forks source link

[bug] Argent siwe signature validation error #1443

Open MickaelNeves opened 1 year ago

MickaelNeves commented 1 year ago

Is there an existing issue for this?

RainbowKit Version

^1.0.6

wagmi Version

^1.3.9

Current Behavior

I can't verify my account. I'm using WalletConnect + Argent Wallet and when the signature modal pops up to send a message, I accept it in Argent wallet, but in the modal I get the message "Error verifying signature, please retry!". After debugging using breakpoints (cause the try/catch error is not handled btw) I found that im getting the error "No matching key. keychain"

Expected Behavior

Excepted to sign the message and connect my wallet

Steps To Reproduce

1 - visit www.botto.com 2 - connect wallet 3 - choose walletconnect or argent wallet 4 - follow the steps until reaching the sign modal

Link to Minimal Reproducible Example (CodeSandbox, StackBlitz, etc.)

No response

Anything else?

Screenshot 2023-08-02 at 11 04 31

DanielSinclair commented 1 year ago

@MickaelNeves I believe this caused by the version of next-auth that you have adopted. Please use 4.20.1 or earlier. A bug/API change was introduced in later versions, and we will have a package upgrade soon to support those versions. This will be described in release notes. Let me know if that resolves your issue.

DanielSinclair commented 1 year ago

Have released @rainbow-me/rainbowkit-siwe-next-auth@0.3.0 to support more recent versions of next-auth. Let me know if that resolves your issue. Reference the Migration Guide

MickaelNeves commented 1 year ago

I'm not using next-auth @DanielSinclair , these are the ones:

and this is my adapter

`const authenticationAdapter = createAuthenticationAdapter({ getNonce: async () => { const url = URL_FOR_NONCE const response = await request({ url })

  return response.nonce
},

createMessage: ({ nonce, address, chainId }) => {
  return new SiweMessage({
    domain: window.location.host,
    address,
    statement: `You are about to sign this message.\nThe signature is: ${nonce}`,
    uri: window.location.origin,
    version: '1',
    chainId,
    nonce,
  })
},

getMessageBody: ({ message }) => {
  return message.prepareMessage()
},

verify: async ({ message, signature }) => {
  verifyingRef.current = true

  try {
    // request to fetch JWT
    const response = await request({......})

    if (!response.jwt) {
      setAuthStatus('unauthenticated')
      return false
    }

    const user = {
      account: response.data.address,
      token: response.jwt,
    } as User
    const updatedAccounts = addOrReplaceAccount(userAccounts, user)

    setCookie(LOCALSTORAGE_ITEMS.AuthToken, response.jwt)
    setUserAccounts(updatedAccounts)
    setCurrentAccount(user.account)
    setAuthStatus('authenticated')
    Sentry.setUser({ id: user.account })
    handleOnboarding(user.account)

    return true
  } catch (error) {
    setAuthStatus('unauthenticated')

    return false
  } finally {
    verifyingRef.current = false
  }
},

signOut: async () => {
  setAuthStatus('unauthenticated')
  deleteCookie(LOCALSTORAGE_ITEMS.AuthToken)
  Sentry.setUser(null)
},

})`

MickaelNeves commented 1 year ago

other wallets work fine,for example WalletConnect + MetaMask, but WalletConnect + Argent or just the Argent adapter does not seem to work

DanielSinclair commented 1 year ago

I see. The No matching key. keychain error is actually a WalletConnect error that (unfortunately) still fires from their libraries. But this sounds like an Argent specific problem. I was able to replicate. Are you using Argent Vault by chance?

MickaelNeves commented 1 year ago

I think so. I dont use this wallet, this error was reported from users that interact with our website, so what I did was just installing Argent on my phone, top up ETH account to activate and scan the WalletConnect QR

eliezerbasubi commented 7 months ago

@MickaelNeves, have you considered adding the 0x prefix to the signature before verifying it?

Upon reviewing the signature in the images of your console, it's evident that the signature lacks the 0x prefix. Some wallets may be overlooking the necessity of adding this prefix to the signature, leading to errors in the verify method.

I encountered a similar problem with Trust Wallet, where both siwe and eth typed data signatures failed to work due to the absence of the 0x prefix.