rainbowkit icon indicating copy to clipboard operation
rainbowkit copied to clipboard

[bug] Argent siwe signature validation error

Open MickaelNeves opened this issue 2 years ago • 7 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

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

MickaelNeves avatar Aug 02 '23 08:08 MickaelNeves

@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 avatar Aug 02 '23 19:08 DanielSinclair

Have released @rainbow-me/[email protected] to support more recent versions of next-auth. Let me know if that resolves your issue. Reference the Migration Guide

DanielSinclair avatar Aug 03 '23 06:08 DanielSinclair

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

  • @rainbow-me/rainbowkit: "^1.0.6"
  • siwe: "^2.1.4"
  • viem: "^1.3.0"
  • wagmi: "^1.3.9"

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 avatar Aug 03 '23 06:08 MickaelNeves

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

MickaelNeves avatar Aug 03 '23 07:08 MickaelNeves

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?

DanielSinclair avatar Aug 03 '23 07:08 DanielSinclair

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

MickaelNeves avatar Aug 03 '23 07:08 MickaelNeves

@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.

eliezerbasubi avatar Feb 15 '24 22:02 eliezerbasubi