Error: urilib.resolve is not a function

Hello,

I am trying to use signed typed data. But when I am doing the signature I am getting the following error:

Error: urilib.resolve is not a function
    at getJsonRpcError (errors.js:176:1)
    at Object.internal (errors.js:42:1)
    at provider.sendAsync (openloginJrpc.esm.js:686:22)
    at async provider.request (openloginJrpc.esm.js:708:1)

I am using the following code:

const originalMessage = {
        types: {
          EIP712Domain: [
            {
              name: "name",
              type: "string",
            },
            {
              name: "version",
              type: "string",
            },
            {
              name: "verifyingContract",
              type: "address",
            },
          ],
          Greeting: [
            {
              name: "contents",
              type: "string",
            },
          ],
        },
        primaryType: "Greeting",
        domain: {
          name: "web3auth",
          version: "1",
          verifyingContract: "0xE0cef4417a772512E6C95cEf366403839b0D6D6D",
        },
        message: {
          contents: "Hello, from Web3Auth!",
        },
      };
      const params = [maker, originalMessage];
      const method = "eth_signTypedData_v4";
      const sigBytes = await signer.provider.send(method, params);

Do you have an idea where it could come from ? Maybe I missed something.

Thanks in advance.

@guillaume Thanks for reaching out.

Your issue has been forwarded to our Dev team and we will get back with further updates once more information becomes available.

Thank you.

To provide you with more details. I tried many differents approches and this one is happening with ethers v5. Even in your exemple bundle there is the exact same error with ethers v5.

Waiting for your dev team answer.

Regards.

@guillaume Sorry for the inconvenience. Could you please help with the example with this issue?

If you git clone your w3a-modal-evm-vue example repository.

And set "ethers": "^5.6.5" in your package.json

The following signing code would reproduce the error:

async signMessage() {
    try {
      // For ethers v5
      const ethersProvider = new ethers.providers.Web3Provider(this.provider);
      // const ethersProvider = new ethers.BrowserProvider(this.provider);

      const signer = await ethersProvider.getSigner();


      // Get user's Ethereum public address
      const fromAddress = await signer.getAddress();

      const originalMessage = {
        types: {
          EIP712Domain: [
            {
              name: "name",
              type: "string",
            },
            {
              name: "version",
              type: "string",
            },
            {
              name: "verifyingContract",
              type: "address",
            },
          ],
          Greeting: [
            {
              name: "contents",
              type: "string",
            },
          ],
        },
        primaryType: "Greeting",
        domain: {
          name: "web3auth",
          version: "1",
          verifyingContract: "0xE0cef4417a772512E6C95cEf366403839b0D6D6D",
        },
        message: {
          contents: "Hello, from Web3Auth!",
        },
      };
      const params = [fromAddress, originalMessage];
      const method = "eth_signTypedData_v4";
      
      const signedMessage = await signer.provider.send(method, params);      

      return signedMessage;
    } catch (error) {
      console.log(error)
      return error as string;
    }
  }

And this code is coming from your docs

This is a runtime error. The compilation is ok.

Best regards.

Hi @guillaume, I tried out the given signMessage method with the vue-evm-modal example and I faced no issue whatsoever. I am curious did you run npm install after changing the ethers version? Or do you use yarn?

@maharshi Yes I run npm install and I still face the same issue.

I am using npm versoin 8.19.2

Do you know where it could come from ? Did you change the sign message method with v4 ? Because v1 signature is working for me but not v4.

@guillaume Have you tried removing the node_modules folder and the package-lock.json and running a fresh npm install ? Let me know if this resolves the issue for you. I am puzzled because I am not able to re-create this error on my side with the said example and replacing the signMessage code with the one you’ve mentioned.

@maharshi Ok it is weird I tried all of this and I still have the same error. This is really a bottleneck for us because I am missing only this function to go live…

Did you think to change the import in Home.vue L103 with ethers RPC ?

import RPC from "./web3RPC";

Should become:

import RPC from “./ethersRPC”;

And the repo is not working with v6 compilation fails… Though I am really stuck.

@guillaume Is the v6 ethers working for you or that also is throwing some errors?

@maharshi v6 is not working. I opened an other ticket for that.

The example is working for you with v6 ?

You really need to change the import in Home.vue as said before so that you can reproduce the error.

Okay @guillaume. I got the error. Thanks a lot for pointing it out and keeping our examples up to date. I have resolved it. I have resolved the errors with the ethers v6. It is advisable to be on the latest version of ethers to prevent the exposure to vulnerabilities.
I will be raising a PR for it and will let you know.

Here’s the PR I have raised. You can take pull from the branch if you’re able to otherwise, I am working to get this merged ASAP.

Thanks @maharshi for your reactivity !

Could be great as well to have it working with v5 to allow all projects to have it working… I am planning to move to v6 but I’d like to have it up and running with v5 as well…

Do you plan to fix it as well ?

@maharshi It is working but know I have the same error with the v6 version:

[
{
"code": "UNKNOWN_ERROR",
"error": {
"code": -32603,
"message": "urilib.resolve is not a function"
},
"payload": {
"method": "eth_signTypedData_v4",
"params": [
"0x7759A924c4d19253C75511D9d4905B2bA443B5BA",
{
"types": {
"EIP712Domain": [
{
"name": "name",
"type": "string"
},
{
"name": "version",
"type": "string"
},
{
"name": "verifyingContract",
"type": "address"
}
],
"Greeting": [
{
"name": "contents",
"type": "string"
}
]
},
"primaryType": "Greeting",
"domain": {
"name": "web3auth",
"version": "1",
"verifyingContract": "0xE0cef4417a772512E6C95cEf366403839b0D6D6D"
},
"message": {
"contents": "Hello, from Web3Auth!"
}
}
],
"id": 4,
"jsonrpc": "2.0"
}
}
]

Could you try to resolve it ?

1 Like

@guillaume I understand that this error is seen with the signMessage method pasted by you. But I am starting to believe that this is an issue with the method signer.provider.send(method, params) and nothing on the web3auth side. Advising you to refer their documentation for the methods that are used to sign a message or you could try using the way we have used in our examples. Let me know if this works for you.

@maharshi this is the way you provide in your docs as you can see: SignedTypedV4

I just change in the exemple to paste the signature from your docs.

Can you try on your side ?

1 Like

Hi @guillaume, I have pushed another commit to the PR. All it needed was a polyfill for url. This fix will work for v5 as well.

Hi @maharshi,

Looks nice, I’ll have a look, thanks for your reactivity !

Regards.

1 Like

Will mark this thread as resolved.