Skip to content

Calling didManager does not raise a helpful error if registry is missing from agent config #1444

@emilaukner

Description

@emilaukner

Bug severity
Please rate severity from 1-5, 1 being very minor and 5 being critical
1

Describe the bug
A clear and concise description of what the bug is.
When attempting to add a key to a DID using agent.didManagerAddKey(args: IDIDManagerAddKeyArgs) an error was returned:

Error creating key: Error: could not decode result data (value="0x", info={ "method": "identityOwner", "signature": "identityOwner(address)" }, code=BAD_DATA, version=6.13.5)
    at makeError (/homeDir/userDir/my-repo/node_modules/ethers/lib.commonjs/utils/errors.js:129:21)
    at assert (/homeDir/userDir/my-repo/node_modules/ethers/lib.commonjs/utils/errors.js:149:15)
    at Interface.decodeFunctionResult (/homeDir/userDir/my-repo/node_modules/ethers/lib.commonjs/abi/interface.js:780:31)
    at staticCallResult (/homeDir/userDir/my-repo/node_modules/ethers/lib.commonjs/contract/contract.js:254:35)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async staticCall (/homeDir/userDir/my-repo/node_modules/ethers/lib.commonjs/contract/contract.js:219:24)
    at async Proxy.identityOwner (/homeDir/userDir/my-repo/node_modules/ethers/lib.commonjs/contract/contract.js:259:20)
    at async EthrDIDProvider.addKey (/homeDir/userDir/my-repo/node_modules/@veramo/did-provider-ethr/build/ethr-did-provider.js:210:28)
    at async DIDManager.didManagerAddKey (/homeDir/userDir/my-repo/node_modules/@veramo/did-manager/build/id-manager.js:154:24)
    at async Agent.execute (/homeDir/userDir/my-repo/node_modules/@veramo/core/build/agent.js:159:24) {
  code: 'BAD_DATA',
  value: '0x',
  info: { method: 'identityOwner', signature: 'identityOwner(address)' },
  shortMessage: 'could not decode result data'
}

To Reproduce
Steps to reproduce the behaviour:

  1. agent setup:
import {
  createAgent,
  IDIDManager,
  IResolver,
  IDataStore,
  IDataStoreORM,
  IKeyManager,
  ICredentialPlugin,
} from '@veramo/core';

import { DIDManager } from '@veramo/did-manager';
import { EthrDIDProvider } from '@veramo/did-provider-ethr';
import { KeyDIDProvider } from '@veramo/did-provider-key';
import { KeyManager } from '@veramo/key-manager';
import { KeyManagementSystem, SecretBox } from '@veramo/kms-local';
import { CredentialPlugin } from '@veramo/credential-w3c';
import { DIDResolverPlugin } from '@veramo/did-resolver';
import { Resolver } from 'did-resolver';
import { getResolver as ethrDidResolver } from 'ethr-did-resolver';
import { getResolver as keyDidResolver } from 'key-did-resolver';
import { getResolver as webDidResolver } from 'web-did-resolver';
import { Entities, KeyStore, DIDStore, PrivateKeyStore, migrations } from '@veramo/data-store';
import { DataSource } from 'typeorm';
import { DIDComm, IDIDComm } from '@veramo/did-comm';
import { CredentialIssuerLD, LdDefaultContexts, VeramoEd25519Signature2020 } from '@veramo/credential-ld';
import {
  VeramoEd25519Signature2018,
  VeramoEcdsaSecp256k1RecoverySignature2020,
  VeramoJsonWebSignature2020,
} from "@veramo/credential-ld";

const DATABASE_FILE = 'database.sqlite';
const INFURA_PROJECT_ID = process.env.INFURA_PROJECT_ID || 'Your_INFURA_PROJECT_ID';
const KMS_SECRET_KEY = process.env.KMS_SECRET_KEY || 'Create_A_Random_Key';

// Database setup
const dbConnection = new DataSource({
  type: 'sqlite',
  database: DATABASE_FILE,
  synchronize: false,
  migrations,
  migrationsRun: true,
  logging: ['error', 'info', 'warn'],
  entities: Entities,
}).initialize();

export const issuerAgent = createAgent<
  IDIDManager & IKeyManager & IDataStore & IDataStoreORM & IResolver & ICredentialPlugin & IDIDComm
>({
  plugins: [
    new KeyManager({
      store: new KeyStore(await dbConnection),
      kms: {
        local: new KeyManagementSystem(new PrivateKeyStore(await dbConnection, new SecretBox(KMS_SECRET_KEY))),
      },
    }),
    new DIDManager({
      store: new DIDStore(await dbConnection),
      defaultProvider: 'did:ethr:sepolia',
      providers: {
        'did:ethr:sepolia': new EthrDIDProvider({
          defaultKms: 'local',
          network: 'sepolia',
          rpcUrl: `https://sepolia.infura.io/v3/${INFURA_PROJECT_ID}`,
        }),
        'did:key': new KeyDIDProvider({ defaultKms: 'local' }),
      },
    }),
    new DIDResolverPlugin({
      resolver: new Resolver({
        ...ethrDidResolver({ infuraProjectId: INFURA_PROJECT_ID }),
        ...keyDidResolver(),
        ...webDidResolver(),
      }),
    }),
    new CredentialPlugin(),
    new DIDComm(),
  ],
});
  1. Code i tried to run to add key to default DID (DID must be managed by agent):

await agent.keyManagerCreate({ type: 'X25519', kms: 'local' }).then(async (key) => {
  console.log('Key created:', key)
  await agent.didManagerAddKey({ did: 'did:ethr:sepolia:0x123abc-mydid', key: key })
}).catch((error) => {
  console.error('Error creating key:', error)
})

Observed behaviour
The error was returned as described earlier, which was difficult to understand, even when trying to go down in the stack trace.

Expected behaviour
I expected an error message which informed me more about what the issue was. I asked for help on the Veramo Discord server in the support channel and was suggested to add registry: "addressForSepoliaEthereumDIDRegistry" which resolved the error. The expected behaviour would then be that the error alerted me of the missing registry or something similar.

Details
If applicable, add screenshots, error messages or stack traces to help explain your problem.
Stacktrace again:

Error creating key: Error: could not decode result data (value="0x", info={ "method": "identityOwner", "signature": "identityOwner(address)" }, code=BAD_DATA, version=6.13.5)
    at makeError (/homeDir/userDir/my-repo/node_modules/ethers/lib.commonjs/utils/errors.js:129:21)
    at assert (/homeDir/userDir/my-repo/node_modules/ethers/lib.commonjs/utils/errors.js:149:15)
    at Interface.decodeFunctionResult (/homeDir/userDir/my-repo/node_modules/ethers/lib.commonjs/abi/interface.js:780:31)
    at staticCallResult (/homeDir/userDir/my-repo/node_modules/ethers/lib.commonjs/contract/contract.js:254:35)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async staticCall (/homeDir/userDir/my-repo/node_modules/ethers/lib.commonjs/contract/contract.js:219:24)
    at async Proxy.identityOwner (/homeDir/userDir/my-repo/node_modules/ethers/lib.commonjs/contract/contract.js:259:20)
    at async EthrDIDProvider.addKey (/homeDir/userDir/my-repo/node_modules/@veramo/did-provider-ethr/build/ethr-did-provider.js:210:28)
    at async DIDManager.didManagerAddKey (/homeDir/userDir/my-repo/node_modules/@veramo/did-manager/build/id-manager.js:154:24)
    at async Agent.execute (/homeDir/userDir/my-repo/node_modules/@veramo/core/build/agent.js:159:24) {
  code: 'BAD_DATA',
  value: '0x',
  info: { method: 'identityOwner', signature: 'identityOwner(address)' },
  shortMessage: 'could not decode result data'
}

Additional context
Add any other context about the problem here.

Versions (please complete the following information):

  • Veramo: 6.0.0
  • Browser: Not in browser
  • Node Version: 20.18

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpinneddon't close this just for being stale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions