Navigation Menu

Skip to content

Commit

Permalink
feat(cli): add DID discovery plugin to @veramo/cli (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Jul 6, 2021
1 parent 78321a9 commit a484f4c
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 3 deletions.
9 changes: 9 additions & 0 deletions packages/cli/default/default.yml
Expand Up @@ -28,6 +28,7 @@ constants:
- didManagerAddService
- didManagerRemoveService
- resolveDid
- discoverDid
- dataStoreGetMessage
- dataStoreSaveMessage
- dataStoreGetVerifiableCredential
Expand Down Expand Up @@ -266,6 +267,13 @@ didManager:
$args:
- defaultKms: local

didDiscovery:
$require: '@veramo/did-discovery#DIDDiscovery'
$args:
- providers:
- $require: '@veramo/did-manager#AliasDiscoveryProvider'
- $require: '@veramo/data-store#ProfileDiscoveryProvider'

# Agent
agent:
$require: '@veramo/core#Agent'
Expand All @@ -275,6 +283,7 @@ agent:
- $ref: /keyManager
- $ref: /didManager
- $ref: /didResolver
- $ref: /didDiscovery
- $ref: /messageHandler
- $require: '@veramo/did-comm#DIDComm'
- $require: '@veramo/credential-w3c#CredentialIssuer'
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/package.json
Expand Up @@ -10,8 +10,8 @@
"scripts": {
"build": "tsc",
"watch": "tsc -b --watch",
"update-veramo-next": "yarn add @veramo/core@next @veramo/remote-client@next @veramo/remote-server@next @veramo/did-provider-key@next @veramo/did-resolver@next @veramo/did-jwt@next @veramo/credential-w3c@next @veramo/did-provider-ethr@next @veramo/did-provider-web@next @veramo/did-comm@next @veramo/kms-local@next @veramo/selective-disclosure@next @veramo/data-store@next @veramo/key-manager@next @veramo/message-handler@next @veramo/did-manager@next @veramo/url-handler@next",
"update-veramo-latest": "yarn add @veramo/core@latest @veramo/remote-client@latest @veramo/remote-server@latest @veramo/did-provider-key@latest @veramo/did-resolver@latest @veramo/did-jwt@latest @veramo/credential-w3c@latest @veramo/did-provider-ethr@latest @veramo/did-provider-web@latest @veramo/did-comm@latest @veramo/kms-local@latest @veramo/selective-disclosure@latest @veramo/data-store@latest @veramo/key-manager@latest @veramo/message-handler@latest @veramo/did-manager@latest @veramo/url-handler@latest"
"update-veramo-next": "yarn add @veramo/core@next @veramo/discovery@next @veramo/remote-client@next @veramo/remote-server@next @veramo/did-provider-key@next @veramo/did-resolver@next @veramo/did-jwt@next @veramo/credential-w3c@next @veramo/did-provider-ethr@next @veramo/did-provider-web@next @veramo/did-comm@next @veramo/kms-local@next @veramo/selective-disclosure@next @veramo/data-store@next @veramo/key-manager@next @veramo/message-handler@next @veramo/did-manager@next @veramo/url-handler@next",
"update-veramo-latest": "yarn add @veramo/core@latest @veramo/discovery@latest @veramo/remote-client@latest @veramo/remote-server@latest @veramo/did-provider-key@latest @veramo/did-resolver@latest @veramo/did-jwt@latest @veramo/credential-w3c@latest @veramo/did-provider-ethr@latest @veramo/did-provider-web@latest @veramo/did-comm@latest @veramo/kms-local@latest @veramo/selective-disclosure@latest @veramo/data-store@latest @veramo/key-manager@latest @veramo/message-handler@latest @veramo/did-manager@latest @veramo/url-handler@latest"
},
"dependencies": {
"@microsoft/api-extractor": "7.17.1",
Expand All @@ -22,6 +22,7 @@
"@veramo/credential-w3c": "^1.2.0",
"@veramo/data-store": "^1.2.0",
"@veramo/did-comm": "^1.2.0",
"@veramo/did-discovery": "^1.2.0",
"@veramo/did-jwt": "^1.2.0",
"@veramo/did-manager": "^1.2.0",
"@veramo/did-provider-ethr": "^1.2.0",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/cli.ts
Expand Up @@ -9,6 +9,7 @@ import './presentation'
import './explore'
import './sdr'
import './message'
import './discover'
import './version'
import './execute'
import './server'
Expand Down
33 changes: 33 additions & 0 deletions packages/cli/src/discover.ts
@@ -0,0 +1,33 @@
import { getAgent } from './setup'
import program from 'commander'
import { printTable } from 'console-table-printer'

const discover = program.command('discover').description('Discovery')

discover
.command('did')
.description('did discovery')
.option('-q, --query <string>', 'Query string')

.action(async (cmd) => {
const agent = getAgent(program.opts().config)

const response = await agent.discoverDid({ query: cmd.query })
const list: any = []

response.results.forEach(r => {
r.matches.forEach(m => {
list.push({
provider: r.provider,
did: m.did
})
})
})

if (list.length > 0) {
printTable(list)
} else {
console.log('No dids discovered')
}
})

5 changes: 4 additions & 1 deletion packages/cli/src/setup.ts
Expand Up @@ -5,6 +5,8 @@ import { ICredentialIssuer } from '@veramo/credential-w3c'
import { ISelectiveDisclosure } from '@veramo/selective-disclosure'
import { IDIDComm } from '@veramo/did-comm'
import { IDataStoreORM } from '@veramo/data-store'
import { IDIDDiscovery } from '@veramo/did-discovery'

const fs = require('fs')
import { createAgentFromConfig } from './lib/agentCreator'

Expand Down Expand Up @@ -32,7 +34,8 @@ export type EnabledInterfaces = IDIDManager &
IMessageHandler &
IDIDComm &
ICredentialIssuer &
ISelectiveDisclosure
ISelectiveDisclosure &
IDIDDiscovery

export type ConfiguredAgent = TAgent<EnabledInterfaces>

Expand Down
1 change: 1 addition & 0 deletions packages/cli/tsconfig.json
Expand Up @@ -9,6 +9,7 @@
{ "path": "../credential-w3c" },
{ "path": "../data-store" },
{ "path": "../did-comm" },
{ "path": "../did-discovery" },
{ "path": "../did-jwt" },
{ "path": "../did-manager" },
{ "path": "../did-provider-ethr" },
Expand Down

0 comments on commit a484f4c

Please sign in to comment.