xmtp / xmtp-js

XMTP client SDKs, content types, and other packages written in TypeScript
https://xmtp.org/docs
211 stars 40 forks source link

Invalid Signature: r must be 0 < r < n in React Native+Expo #281

Closed VIVEK-SUTHAR closed 1 year ago

VIVEK-SUTHAR commented 1 year ago

Describe the bug

I am integrating XMTP DM's in my React-Native+Expo app. When I try to create a Client via Client.create, it prompts me to enable identity in my wallet and after signing message in my wallet, it throws the below error

Invalid Signature: r must be 0 < r < n

I am using Wallet-Connect's react-native-dapp for wallet connection.

Below is the code I am using

const connector = useWalletConnect();

const enableDM = async () => {

    const WCProvider = new WalletConnectProvider({
      infuraId:MY_KEY,
      connector: connector,
    });
    await WCProvider.enable();
    const provider = new ethers.providers.Web3Provider(WCProvider);
    const signer = provider.getSigner();
    try {
      const client = await Client.create(signer);
      console.log(client);
    } catch (error) {
      if (error instanceof Error) {
        console.log(error);
      }
    }
  };

Expected behavior

No response

Steps to reproduce the bug

No response

nplasterer commented 1 year ago

Thanks for the report. @dmccartney is working on a lot of improvements to the react native flow so hopefully he will have a better diagnosis of this for you. Have you tried the React Native Example app? https://github.com/xmtp/example-chat-react-native this might have some helpful bits to get you unblocked in the meantime.

VIVEK-SUTHAR commented 1 year ago

@nplasterer Thanks for your support, I have also tried the code described in the react-native-example-app, but still, after signing the message in the wallet it throws the same error - Invalid Signature: r must be 0 < r < n

grabbou commented 1 year ago

Let me know as soon as there are some updates to test this flow, the getting started experience is pretty rough atm, would love to help!

neekolas commented 1 year ago

I'm curious what version of xmtp-js you are using in your app? We made some improvements to the way we handle signatures recently that improve compatibility with some wallets.

VIVEK-SUTHAR commented 1 year ago

Hey @neekolas , I just upgraded the xmtp-js to the latest version and still, it throws the same error. I am using Wallet Connect Web3 Provider(Infura) and Rainbow wallet for signing the message.

neekolas commented 1 year ago

Thanks for confirming. Looking at the noble crypto code, my suspicion is that this issue has to do with BigInt polyfills.

What version of React Native are you using? Are you using Hermes? And are you using any BigInt polyfills in your application?

We recommend using Hermes, which has native BigInt support.

jazzz commented 1 year ago

Closing this issue as it's been awhile with no response. If the problem still exists feel free to reopen the issue.