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

Not able to resolve DID document after upgrading to version 1.2.0 #520

Closed
Muhammad-Altabba opened this issue May 16, 2021 · 8 comments
Closed
Assignees
Labels
bug Something isn't working triage

Comments

@Muhammad-Altabba
Copy link

Bug severity
5
(I am not sure what configuration I did wrongly)

Describe the bug
Not able to resolve a DID Document.

To Reproduce
Steps to reproduce the behaviour:

  1. Initialize WebDidDocRouter and add it to the routers of the app server:
import { WebDidDocRouter } from '@veramo/remote-server';
...
const didDocRouter = WebDidDocRouter();

export default function routes(app: Application): void {
  ...
  app.use(didDocRouter);
}

...

export default new Server().router(routes).listen(port, httpsPort);
  1. Try to resolve the DID
    const { username, identity } = await createIdentity();

    const didDoc: any = await agent.resolveDid({
      didUrl: `did:web:${username}`,
    });

Observed behaviour
The await, in the above code, never comes back with the DID Doc. It just waits forever.

Expected behaviour
Be able to resolve the DID Doc .

Versions (please complete the following information):

  • Veramo: 1.2.0
  • Node Version: 12.13.0
@Muhammad-Altabba Muhammad-Altabba added the bug Something isn't working label May 16, 2021
@Muhammad-Altabba
Copy link
Author

Also when requesting https://localhost/73650cd4-4750-49bc-ae90-fae346e53e58/did.json from the browser, the response never comes back.

@strumswell
Copy link
Contributor

Hey, I'm not a Veramo dev but did you import the WebDIDProvider and and added [1, 2] the resolver to your Veramo setup? And afaik the did.json is placed in the .well-known directory.

@jasheal
Copy link

jasheal commented May 17, 2021

Can you let us know if @strumswell solution works here @Muhammad-Altabba ?

@Muhammad-Altabba
Copy link
Author

Thanks all.
Yes, I am already importing and adding WebDIDProvider at setup. Actually, the same setup was working well before I upgraded to Veramo 1.2.0.

Here is the code that do the setup:

// Core interfaces
import {
  createAgent,
  IDIDManager,
  IResolver,
  IDataStore,
  IKeyManager,
} from '@veramo/core';

import { CredentialIssuer, W3cMessageHandler } from '@veramo/credential-w3c';

// Core identity manager plugin
import { DIDManager } from '@veramo/did-manager';

// DID Universal Resolver
import { UniversalResolver } from '@veramo/did-resolver';

// Core key manager plugin
import { KeyManager } from '@veramo/key-manager';

// Custom Web did identity provider.
//  And its custom key management system for RN
import {
  KeyManagementSystem,
  WebDIDProvider,
} from '@inter-ops/netid-kms-plugin';

// Custom resolvers
import { DIDResolverPlugin } from '@veramo/did-resolver';
import { Resolver } from 'did-resolver';
import { getResolver as webDidResolver } from 'web-did-resolver';

// Storage plugin using TypeOrm
import {
  Entities,
  KeyStore,
  DIDStore,
  IDataStoreORM,
  DataStore,
  DataStoreORM,
} from '@veramo/data-store';

import { MessageHandler } from '@veramo/message-handler';
import { DIDComm, DIDCommMessageHandler } from '@veramo/did-comm';
import { JwtMessageHandler } from '@veramo/did-jwt';
import {
  SdrMessageHandler,
  SelectiveDisclosure,
} from '@veramo/selective-disclosure';

// TypeORM is installed with daf-typeorm
import { createConnection } from 'typeorm';

import ormconfig from '../../ormconfig';

// TODO: Use the same dbConnection that is created at ../index.tx
const dbConnection = createConnection({
  ...ormconfig,
  entities: Entities,
} as any);

const uniResolver = new UniversalResolver({
  url: 'https://resolver.identity.foundation/1.0/identifiers/',
});

export const agent = createAgent<
  IDIDManager & IKeyManager & IDataStore & IDataStoreORM & IResolver
>({
  plugins: [
    new KeyManager({
      store: new KeyStore(dbConnection as any),
      kms: {
        local: new KeyManagementSystem(),
      },
    }),
    new DIDManager({
      store: new DIDStore(dbConnection as any),
      defaultProvider: 'did:web',
      providers: {
        'did:web': new WebDIDProvider({
          defaultKms: 'local',
        }),
      },
    }),
    new DIDResolverPlugin({
      resolver: new Resolver({
        web: webDidResolver().web as any,
        //resolve some other DID methods using the centralized `uniresolver.io` service
        key: uniResolver as any,
        elem: uniResolver as any,
      }),
    }),
    new CredentialIssuer(),
    new DataStore(dbConnection as any),
    new DataStoreORM(dbConnection as any),
    new MessageHandler({
      messageHandlers: [
        new DIDCommMessageHandler(),
        new JwtMessageHandler(),
        new W3cMessageHandler(),
        new SdrMessageHandler(),
      ],
    }),
    new DIDComm(),
    new SelectiveDisclosure(),
  ],
});

However, how to place the did.json in the .well-known directory? The URL used to be automatically served according to the configuration. Is there something I need to do regarding this?

Many thanks,

@jasheal
Copy link

jasheal commented May 17, 2021

Can you try matching your resolver config syntax to match our test cases? https://github.com/uport-project/veramo/blob/next/__tests__/localAgent.test.ts#L129

@mirceanis mirceanis self-assigned this May 17, 2021
@Muhammad-Altabba
Copy link
Author

Thanks @mirceanis,
However, I tried and updated the setup. But, I still face the same.
Below the new setup of Veramo:

// Core interfaces
import {
  createAgent,
  IDIDManager,
  IResolver,
  IDataStore,
  IKeyManager,
} from '@veramo/core';

import { CredentialIssuer, W3cMessageHandler } from '@veramo/credential-w3c';

// Core identity manager plugin
import { DIDManager } from '@veramo/did-manager';

// DID Universal Resolver
import { UniversalResolver } from '@veramo/did-resolver';

// Core key manager plugin
import { KeyManager } from '@veramo/key-manager';

// Custom Web did identity provider.
//  And its custom key management system for RN
import {
  KeyManagementSystem,
  WebDIDProvider,
} from '@inter-ops/netid-kms-plugin';

// Custom resolvers
import { DIDResolverPlugin } from '@veramo/did-resolver';
import { Resolver } from 'did-resolver';
import { getResolver as webDidResolver } from 'web-did-resolver';

// Storage plugin using TypeOrm
import {
  Entities,
  KeyStore,
  DIDStore,
  IDataStoreORM,
  DataStore,
  DataStoreORM,
} from '@veramo/data-store';

import { MessageHandler } from '@veramo/message-handler';
import { DIDComm, DIDCommMessageHandler } from '@veramo/did-comm';
import { JwtMessageHandler } from '@veramo/did-jwt';
import {
  SdrMessageHandler,
  SelectiveDisclosure,
} from '@veramo/selective-disclosure';

// TypeORM is installed with daf-typeorm
import { createConnection } from 'typeorm';

import ormconfig from '../../ormconfig';

// TODO: Use the same dbConnection that is created at ../index.tx
const dbConnection = createConnection({
  ...ormconfig,
  entities: Entities,
} as any);

const uniResolver = new UniversalResolver({
  url: 'https://resolver.identity.foundation/1.0/identifiers/',
});

export const agent = createAgent<
  IDIDManager & IKeyManager & IDataStore & IDataStoreORM & IResolver
>({
  plugins: [
    new KeyManager({
      store: new KeyStore(dbConnection as any),
      kms: {
        local: new KeyManagementSystem(),
      },
    }),
    new DIDManager({
      store: new DIDStore(dbConnection as any),
      defaultProvider: 'did:web',
      providers: {
        'did:web': new WebDIDProvider({
          defaultKms: 'local',
        }),
      },
    }),
    new DIDResolverPlugin({
      resolver: new Resolver({
        ...webDidResolver(),
      }),
    }),
    new CredentialIssuer(),
    new DataStore(dbConnection as any),
    new DataStoreORM(dbConnection as any),
    new MessageHandler({
      messageHandlers: [
        new DIDCommMessageHandler(),
        new JwtMessageHandler(),
        new W3cMessageHandler(),
        new SdrMessageHandler(),
      ],
    }),
    new DIDComm(),
    new SelectiveDisclosure(),
  ],
});

And below is my router setup.
(I notice that WebDidDocRouter does not take any argument in Veramo 1.2. Where in Veramo 1.1, it used to take the agent as a parameter. I am not sure how the agent is passed behind the scene in version 1.2)

import { Application } from 'express';
import { WebDidDocRouter } from '@veramo/remote-server';

const didDocRouter = WebDidDocRouter();

export default function routes(app: Application): void {
  app.use(didDocRouter);
}

@simonas-notcat
Copy link
Contributor

Hey @Muhammad-Altabba ,

Your express app needs to use RequestWithAgentRouter middleware, that adds the agent to the request object. You can see that it is being used in the default CLI config:

https://github.com/uport-project/veramo/blob/main/packages/cli/default/default.yml#L76

Your code should look like this:

import { Application } from 'express';
import { WebDidDocRouter, RequestWithAgentRouter } from '@veramo/remote-server';
import { agent } from './setup';

export default function routes(app: Application): void {
  app.use(RequestWithAgentRouter(agent));
  app.use(WebDidDocRouter());
}

@Muhammad-Altabba
Copy link
Author

This resolved the issue. Thanks,

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

No branches or pull requests

5 participants