decentralized-identity / veramo

A JavaScript Framework for Verifiable Data
https://veramo.io
Apache License 2.0
431 stars 131 forks source link

Missing provider in hardhat network using did:ethr #1360

Closed MattiaDellOca closed 1 month ago

MattiaDellOca commented 6 months ago

Bug severity: 2

Describe the bug: I tried to create a local development environment for Veramo v5.1.2 using did:ethr. This was the configuration of my agent created following Veramo's guidelines:

this._agent = createAgent({
      plugins: [
...
    new DIDManager({
              store: new DIDStore(dbConnection),
              defaultProvider: "did:ethr:dev",
              providers: {
                "did:ethr:dev": new EthrDIDProvider({
                  defaultKms: "local",
                  ttl: 31104001,
                  networks: [
                    {
                      name: "dev",
                      registry: "0x5FbDB2315678afecb367f032d93F642f64180aa3",
                      chainId: 31337,
                      rpcUrl: process.env.RPC_URL,
                    },
                  ],
                }),
              },
            }),
            new DIDResolverPlugin({
              ...ethrDidResolver({
                networks: [
                  {
                    name: "dev",
                    registry: "0x5FbDB2315678afecb367f032d93F642f64180aa3",
                    chainId: 31337,
                    rpcUrl: process.env.RPC_URL,
                  },
                ],
              }),
            }),
...

At this phase I was able to create/resolve DIDs in my local network.

However, when I tried adding an X25519 key agreement (necessary for encrypting message when using did:ethr), I ran into the following error: Error: missing provider (operation="sendTransaction", code=UNSUPPORTED_OPERATION, version=abstract-signer/5.7.0).

To Reproduce Steps to reproduce the behaviour:

  1. Deploy the EthereumDIDRegistry in a Hardhat local network. You can find the necessary steps here
  2. Configure your Agent integrating my previous example for the DID provider and resolver
  3. Try adding an X25519 key agreement using this:
    await agent.didManagerAddKey(
    { 
    did: <your_did>, 
    key: await agent.keyManagerCreate({
      kms: "local",
      type: "X25519"
    })
    }
    )

Observed behaviour When trying to add an X25519 key agreement you will run into an error complaining about a missing provider: Error: missing provider (operation="sendTransaction", code=UNSUPPORTED_OPERATION, version=abstract-signer/5.7.0).

Expected behaviour I would expect the key to be added correctly, as the configuration seems correct

Additional context @mirceanis helped me solving this issue. He suggested me to remove the networks: [{<config>}] properties and move the <config> at the top level of the provider configuration. Here is my updated provider configuration:

new DIDManager({
          store: new DIDStore(dbConnection),
          defaultProvider: "did:ethr:dev",
          providers: {
            "did:ethr:dev": new EthrDIDProvider({
              defaultKms: "local",
              ttl: 31104001,
              network: "dev",
              name: "dev",
              registry: "0x5FbDB2315678afecb367f032d93F642f64180aa3",
              rpcUrl: process.env.RPC_URL,
            }),
          },
        }),

The key addition now works correctly. Note however that when configuring a provider, [networks](networks: [{<config>}]) should be used instead of using the <config> at the top level of the provider configuration, as described here: https://github.com/decentralized-identity/veramo/blob/ab16cbdad37266f0457251f34446624fbe2ed4c9/packages/did-provider-ethr/src/ethr-did-provider.ts#L56C1-L108C2.

Following @mirceanis suggestion, I've opened this issue for tracking.

Versions:

stale[bot] commented 4 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.