Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug](snap): Error during credential query, error message unhelpful #632

Open
c4bade6fdec3d9cb86a281668cbab42b opened this issue Apr 21, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@c4bade6fdec3d9cb86a281668cbab42b
Copy link

Describe the bug

I am trying to query for credentials using JSON-RPC API, here's my code:

import { createStore } from 'mipd'

const snapId = 'npm:@blockchain-lab-um/masca';
const store = createStore()
const provider = store.getProviders()[0].provider
const accounts = await provider.request({
  method: 'eth_requestAccounts',
});
const address = accounts[0];
console.log('Address: ' + address);
const snap = await provider.request({
  method: 'wallet_requestSnaps',
  params:
      {
        [snapId]: { }
      },
});
console.log('Snap: ' + JSON.stringify(snap));

const vcs = await provider.request({
    method: 'wallet_invokeSnap',
    params: {
        snapId: snapId,
        request: {
            method: 'queryCredentials',
            params: { },
        },
    },
});

console.log(vcs);

And the output of the logs are:

Address: 0xd9c9e2f655e23a379c1033ffd656723e66431a7f
App.js:20 Snap: {"npm:@blockchain-lab-um/masca":{"blocked":false,"enabled":true,"id":"npm:@blockchain-lab-um/masca","initialPermissions":{"endowment:ethereum-provider":{},"endowment:network-access":{},"endowment:rpc":{"dapps":true,"snaps":true},"endowment:webassembly":{},"snap_dialog":{},"snap_getEntropy":{},"snap_manageState":{}},"version":"1.2.2"}}
App.js:33 {success: false, error: '[object Object]'}error: "[object Object]"success: false[[Prototype]]: Object

So the snap is enabled and the provider is valid, while trying to fetch the credentials I get '[object Object]' error, which doesn't tell me much.

I've tried using Masca connector as well, same thing happens.

Have I run into a real bug or am I just not doing something correctly? If it's the latter, I apologize.

Versions:

├── @blockchain-lab-um/masca-connector@1.3.2 // not used in this code snippt, but same issue
├── @blockchain-lab-um/masca@1.2.2
├── mipd@0.0.7

To Reproduce

No response

Expected behavior

No response

@c4bade6fdec3d9cb86a281668cbab42b c4bade6fdec3d9cb86a281668cbab42b added the bug Something isn't working label Apr 21, 2024
@martines3000
Copy link
Member

martines3000 commented Apr 22, 2024

Hi @c4bade6fdec3d9cb86a281668cbab42b , thanks for reporting the issue.

Before you can use Masca RPC methods, you need to set your current account inside Masca, as switching MetaMask accounts does not change Masca accounts. This can be done like this:

// After your code here
console.log('Snap: ' + JSON.stringify(snap));

// Call this
const response = await ethereum.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: snapId,
    request: {
      method: 'setCurrentAccount',
      params: {
        currentAccount: address
      },
    },
  },
});

I am not sure if this is the main issue, as I couldn't replicate your error. The error I was getting with your code was:

{
    "success": false,
    "error": "Error: No current account set. Please call the `setCurrentAccount` RPC method first."
}

If I understand correctly you are developing your own dapp, right ? So you are probably testing things on localhost. May I ask which version of MetaMask you are using and which browser you are testing it with ?

Things to note that could help resolve your issue:

  1. MetaMask had a bug on version 11.13.X (resolved in latest version 11.14.0) that broke our Snap.
  2. We normally test things using Chrome, Brave browser and Chromium, so we recommend you use one of those browsers if possible. We are also aware of some issue of Firefox that we are trying to resolve, so it could be related to this.

Please report your findings after you try again, and I can try to help you further if the issue persists.

@c4bade6fdec3d9cb86a281668cbab42b
Copy link
Author

Hey, my Metamask was indeed version 11.13.1!

But, after updating it to 11.14.0 I get a different error: 'Session has expired', so it still doesn't work.

However, I tried it using Masca connector instead of using JSON-RPC and that does work.

My code for JSON-RPC was the identical to the one in the initial comment, except I updated the code to call the set account function before calling query credentials function.

Just a note for the account switching: in your example and your documentation it says the property is currentAccount, however it is actually account

The type that gets passed as argument is SetCurrentAccountRequestParams, which looks like this

interface SetCurrentAccountRequestParams {
    account: string;
}

So, I guess this may be closed, I'll just use the Masca connector library instead of JSON-RPC, not going to hunt down what's going on (for now at least).

Thank you.

@martines3000
Copy link
Member

Thanks for pointing out the mistake in the documentation, we will fix 👍. I am also happy we resolved your issue.

Regarding the expired session, this is related to Ceramic (I forgot to mention this in my example, sorry). We handle this inside our Masca Connector and without it you would need to handle it through separate JSON RPC calls. It is easier using Masca Connector.

If you are interested in the details, this are the steps we do inside the Connector SDK:

  1. Install Masca
  2. JSON-RPC call for setCurrentAccount
  3. JSON-RPC call for validateStoredCeramicSession
  4. If Ceramic session is expired or missing we prompt the user to sign a SIWE message which is used for the Ceramic session creation.
  5. JSON-RPC call for setCeramicSession with the session created in step 4

Steps 2 to 5 need to be repeated each time the user changes his MetaMask account.

May I ask what you are building with Masca ? 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants