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

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

Open
emilaukner opened this issue Feb 4, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@emilaukner
Copy link

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
@emilaukner emilaukner added the bug Something isn't working label Feb 4, 2025
@emilaukner emilaukner changed the title Calling didManager does not raise a helpful error if registry is missing from config Calling didManager does not raise a helpful error if registry is missing from agent config Feb 4, 2025
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

1 participant