@veramo/cli 5.0.1-next.11 → 5.0.1-next.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/build/cli.d.ts +1 -13
  2. package/build/cli.d.ts.map +1 -1
  3. package/build/cli.js +3 -16
  4. package/build/cli.js.map +1 -1
  5. package/build/config.d.ts +3 -1
  6. package/build/config.d.ts.map +1 -1
  7. package/build/config.js +6 -4
  8. package/build/config.js.map +1 -1
  9. package/build/createCommand.d.ts +4 -0
  10. package/build/createCommand.d.ts.map +1 -0
  11. package/build/createCommand.js +31 -0
  12. package/build/createCommand.js.map +1 -0
  13. package/build/credential.d.ts +3 -1
  14. package/build/credential.d.ts.map +1 -1
  15. package/build/credential.js +12 -11
  16. package/build/credential.js.map +1 -1
  17. package/build/dev.d.ts +3 -1
  18. package/build/dev.d.ts.map +1 -1
  19. package/build/dev.js +5 -4
  20. package/build/dev.js.map +1 -1
  21. package/build/did.d.ts +3 -1
  22. package/build/did.d.ts.map +1 -1
  23. package/build/did.js +31 -25
  24. package/build/did.js.map +1 -1
  25. package/build/discover.d.ts +3 -1
  26. package/build/discover.d.ts.map +1 -1
  27. package/build/discover.js +6 -5
  28. package/build/discover.js.map +1 -1
  29. package/build/execute.d.ts +3 -1
  30. package/build/execute.d.ts.map +1 -1
  31. package/build/execute.js +13 -8
  32. package/build/execute.js.map +1 -1
  33. package/build/explore/index.d.ts +3 -1
  34. package/build/explore/index.d.ts.map +1 -1
  35. package/build/explore/index.js +4 -5
  36. package/build/explore/index.js.map +1 -1
  37. package/build/lib/agentCreator.d.ts +9 -0
  38. package/build/lib/agentCreator.d.ts.map +1 -1
  39. package/build/lib/agentCreator.js +9 -0
  40. package/build/lib/agentCreator.js.map +1 -1
  41. package/build/lib/objectCreator.d.ts +44 -0
  42. package/build/lib/objectCreator.d.ts.map +1 -1
  43. package/build/lib/objectCreator.js +46 -2
  44. package/build/lib/objectCreator.js.map +1 -1
  45. package/build/message.d.ts +3 -1
  46. package/build/message.d.ts.map +1 -1
  47. package/build/message.js +5 -4
  48. package/build/message.js.map +1 -1
  49. package/build/presentation.d.ts +3 -1
  50. package/build/presentation.d.ts.map +1 -1
  51. package/build/presentation.js +14 -13
  52. package/build/presentation.js.map +1 -1
  53. package/build/sdr.d.ts +3 -1
  54. package/build/sdr.d.ts.map +1 -1
  55. package/build/sdr.js +9 -7
  56. package/build/sdr.js.map +1 -1
  57. package/build/server.d.ts +3 -1
  58. package/build/server.d.ts.map +1 -1
  59. package/build/server.js +10 -7
  60. package/build/server.js.map +1 -1
  61. package/package.json +44 -26
  62. package/src/__tests__/cli.test.ts +42 -0
  63. package/src/cli.ts +3 -17
  64. package/src/config.ts +9 -6
  65. package/src/createCommand.ts +34 -0
  66. package/src/credential.ts +13 -11
  67. package/src/dev.ts +8 -6
  68. package/src/did.ts +34 -27
  69. package/src/discover.ts +7 -5
  70. package/src/execute.ts +13 -8
  71. package/src/explore/index.ts +5 -5
  72. package/src/lib/agentCreator.ts +9 -0
  73. package/src/lib/objectCreator.ts +46 -2
  74. package/src/message.ts +6 -4
  75. package/src/presentation.ts +53 -48
  76. package/src/sdr.ts +10 -7
  77. package/src/server.ts +11 -7
  78. package/build/version.d.ts +0 -2
  79. package/build/version.d.ts.map +0 -1
  80. package/build/version.js +0 -7
  81. package/build/version.js.map +0 -1
  82. package/src/__tests__/default.test.ts +0 -6
  83. package/src/version.ts +0 -9
package/package.json CHANGED
@@ -1,9 +1,27 @@
1
1
  {
2
2
  "name": "@veramo/cli",
3
3
  "description": "Veramo command line application.",
4
- "version": "5.0.1-next.11+672f92b1",
4
+ "version": "5.0.1-next.13+9c73d98f",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./build/cli.d.ts",
8
+ "import": "./build/cli.js"
9
+ },
10
+ "./build/setup": {
11
+ "types": "./build/setup.d.ts",
12
+ "import": "./build/setup.js"
13
+ },
14
+ "./build/lib/objectCreator": {
15
+ "types": "./build/lib/objectCreator.d.ts",
16
+ "import": "./build/lib/objectCreator.js"
17
+ },
18
+ "./build/lib/agentCreator": {
19
+ "types": "./build/lib/agentCreator.d.ts",
20
+ "import": "./build/lib/agentCreator.js"
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
5
24
  "main": "build/cli.js",
6
- "exports": "./build/cli.js",
7
25
  "types": "build/cli.d.ts",
8
26
  "bin": {
9
27
  "veramo": "bin/veramo.js"
@@ -22,30 +40,30 @@
22
40
  "@transmute/credentials-context": "^0.7.0-unstable.79",
23
41
  "@types/blessed": "^0.1.19",
24
42
  "@types/swagger-ui-express": "^4.1.3",
25
- "@veramo/core": "^5.0.1-next.11+672f92b1",
26
- "@veramo/core-types": "^5.0.1-next.11+672f92b1",
27
- "@veramo/credential-eip712": "^5.0.1-next.11+672f92b1",
28
- "@veramo/credential-ld": "^5.0.1-next.11+672f92b1",
29
- "@veramo/credential-w3c": "^5.0.1-next.11+672f92b1",
30
- "@veramo/data-store": "^5.0.1-next.11+672f92b1",
31
- "@veramo/did-comm": "^5.0.1-next.11+672f92b1",
32
- "@veramo/did-discovery": "^5.0.1-next.11+672f92b1",
33
- "@veramo/did-jwt": "^5.0.1-next.11+672f92b1",
34
- "@veramo/did-manager": "^5.0.1-next.11+672f92b1",
35
- "@veramo/did-provider-ethr": "^5.0.1-next.11+672f92b1",
36
- "@veramo/did-provider-key": "^5.0.1-next.11+672f92b1",
37
- "@veramo/did-provider-web": "^5.0.1-next.11+672f92b1",
38
- "@veramo/did-resolver": "^5.0.1-next.11+672f92b1",
39
- "@veramo/key-manager": "^5.0.1-next.11+672f92b1",
40
- "@veramo/kms-local": "^5.0.1-next.11+672f92b1",
41
- "@veramo/message-handler": "^5.0.1-next.11+672f92b1",
42
- "@veramo/remote-client": "^5.0.1-next.11+672f92b1",
43
- "@veramo/remote-server": "^5.0.1-next.11+672f92b1",
44
- "@veramo/selective-disclosure": "^5.0.1-next.11+672f92b1",
45
- "@veramo/url-handler": "^5.0.1-next.11+672f92b1",
46
- "@veramo/utils": "^5.0.1-next.11+672f92b1",
43
+ "@veramo/core": "^5.0.1-next.13+9c73d98f",
44
+ "@veramo/core-types": "^5.0.1-next.13+9c73d98f",
45
+ "@veramo/credential-eip712": "^5.0.1-next.13+9c73d98f",
46
+ "@veramo/credential-ld": "^5.0.1-next.13+9c73d98f",
47
+ "@veramo/credential-w3c": "^5.0.1-next.13+9c73d98f",
48
+ "@veramo/data-store": "^5.0.1-next.13+9c73d98f",
49
+ "@veramo/did-comm": "^5.0.1-next.13+9c73d98f",
50
+ "@veramo/did-discovery": "^5.0.1-next.13+9c73d98f",
51
+ "@veramo/did-jwt": "^5.0.1-next.13+9c73d98f",
52
+ "@veramo/did-manager": "^5.0.1-next.13+9c73d98f",
53
+ "@veramo/did-provider-ethr": "^5.0.1-next.13+9c73d98f",
54
+ "@veramo/did-provider-key": "^5.0.1-next.13+9c73d98f",
55
+ "@veramo/did-provider-web": "^5.0.1-next.13+9c73d98f",
56
+ "@veramo/did-resolver": "^5.0.1-next.13+9c73d98f",
57
+ "@veramo/key-manager": "^5.0.1-next.13+9c73d98f",
58
+ "@veramo/kms-local": "^5.0.1-next.13+9c73d98f",
59
+ "@veramo/message-handler": "^5.0.1-next.13+9c73d98f",
60
+ "@veramo/remote-client": "^5.0.1-next.13+9c73d98f",
61
+ "@veramo/remote-server": "^5.0.1-next.13+9c73d98f",
62
+ "@veramo/selective-disclosure": "^5.0.1-next.13+9c73d98f",
63
+ "@veramo/url-handler": "^5.0.1-next.13+9c73d98f",
64
+ "@veramo/utils": "^5.0.1-next.13+9c73d98f",
47
65
  "blessed": "^0.1.81",
48
- "commander": "^9.0.0",
66
+ "commander": "^10.0.0",
49
67
  "console-table-printer": "^2.10.0",
50
68
  "cors": "^2.8.5",
51
69
  "cross-fetch": "^3.1.4",
@@ -115,5 +133,5 @@
115
133
  "node_modules",
116
134
  "src"
117
135
  ],
118
- "gitHead": "672f92b1bd3850c369cbef646c8ece8a58fafc16"
136
+ "gitHead": "9c73d98fd217ed9a612767f49a235cdbf43619cb"
119
137
  }
@@ -0,0 +1,42 @@
1
+ import { veramo } from '../createCommand.js'
2
+ import { jest } from '@jest/globals'
3
+ import { createObjects } from '../lib/objectCreator'
4
+ import { getConfig } from '../setup'
5
+
6
+ jest.useFakeTimers()
7
+
8
+ describe('cli version', () => {
9
+ const writeMock = jest.fn()
10
+
11
+ beforeAll(() => {
12
+ // veramo
13
+ // .exitOverride()
14
+ // .configureOutput({ writeOut: writeMock })
15
+ })
16
+
17
+ afterAll(() => {
18
+ jest.clearAllMocks()
19
+ })
20
+
21
+ it.skip('should list version number', async () => {
22
+ expect(() => {
23
+ // veramo.parse(['--version'], { from: 'user' })
24
+ }).toThrow()
25
+ expect(writeMock).toHaveBeenCalledWith(expect.stringMatching(/^\d\.\d\.\d\n?$/))
26
+ })
27
+
28
+ it.skip('should load the dbConnection', async () => {
29
+ // this seems to fail because of some timing issues or an incompatibility with the `chalk` transitive dependency
30
+ // all other tests that need to load the dbConnection fail similarly
31
+ const res = await createObjects(getConfig('./packages/cli/default/default.yml'), {
32
+ my: '/dbConnection',
33
+ })
34
+ })
35
+
36
+ it.skip('should check the default config', async () => {
37
+ expect(() => {
38
+ // veramo.parse(['config', 'check', '-f', './packages/cli/default/default.yml'], { from: 'user' })
39
+ }).toThrow(/hello/)
40
+ expect(writeMock).toHaveBeenCalledWith(expect.stringMatching(/^\d\.\d\.\d\n?$/))
41
+ })
42
+ })
package/src/cli.ts CHANGED
@@ -1,25 +1,11 @@
1
- import { program } from 'commander'
2
1
  import inquirer from 'inquirer'
3
2
  import inquirerAutoPrompt from 'inquirer-autocomplete-prompt'
4
3
 
5
4
  inquirer.registerPrompt('autocomplete', inquirerAutoPrompt)
6
-
7
- import './did.js'
8
- import './credential.js'
9
- import './presentation.js'
10
- import './explore/index.js'
11
- import './sdr.js'
12
- import './message.js'
13
- import './discover.js'
14
- import './version.js'
15
- import './execute.js'
16
- import './server.js'
17
- import './setup.js'
18
- import './config.js'
19
- import './dev.js'
5
+ import { veramo } from './createCommand.js'
20
6
 
21
7
  if (!process.argv.slice(2).length) {
22
- program.outputHelp()
8
+ veramo.outputHelp()
23
9
  } else {
24
- program.parse(process.argv)
10
+ veramo.parse(process.argv)
25
11
  }
package/src/config.ts CHANGED
@@ -1,15 +1,14 @@
1
- import { program } from 'commander'
1
+ import { Command } from 'commander'
2
2
  import { SecretBox } from '@veramo/kms-local'
3
3
  import { getAgent } from './setup.js'
4
- import fs from "fs"
4
+ import fs from 'fs'
5
5
  import { dirname } from 'path'
6
6
 
7
- import * as url from 'url';
8
- const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
7
+ import * as url from 'url'
9
8
 
10
- program.option('--config <path>', 'Configuration file', './agent.yml')
9
+ const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
11
10
 
12
- const config = program.command('config').description('Agent configuration')
11
+ const config = new Command('config').description('Agent configuration')
13
12
 
14
13
  config
15
14
  .command('create', { isDefault: true })
@@ -43,6 +42,8 @@ config
43
42
  .command('create-secret-key')
44
43
  .alias('gen-key')
45
44
  .alias('key-gen')
45
+ .alias('keygen')
46
+ .alias('genkey')
46
47
  .description('generate secret key')
47
48
  .option('-q, --quiet', 'Only print the raw key, no instructions', false)
48
49
  .action(async (options) => {
@@ -89,3 +90,5 @@ config
89
90
  }
90
91
  }
91
92
  })
93
+
94
+ export { config }
@@ -0,0 +1,34 @@
1
+ import { Command } from 'commander'
2
+ import module from 'module'
3
+
4
+ import { config } from './config.js'
5
+ import { credential } from './credential.js'
6
+ import { dev } from './dev.js'
7
+ import { did } from './did.js'
8
+ import { discover } from './discover.js'
9
+ import { execute } from './execute.js'
10
+ import { message } from './message.js'
11
+ import { presentation } from './presentation.js'
12
+ import { explore } from './explore/index.js'
13
+ import { sdr } from './sdr.js'
14
+ import { server } from './server.js'
15
+
16
+ const requireCjs = module.createRequire(import.meta.url)
17
+ const { version } = requireCjs('../package.json')
18
+
19
+ const veramo = new Command('veramo')
20
+ .version(version, '-v, --version')
21
+ .option('--config <string>', 'Configuration file', './agent.yml')
22
+ .addCommand(config)
23
+ .addCommand(credential)
24
+ .addCommand(dev)
25
+ .addCommand(did)
26
+ .addCommand(discover)
27
+ .addCommand(execute)
28
+ .addCommand(explore)
29
+ .addCommand(message)
30
+ .addCommand(presentation)
31
+ .addCommand(sdr)
32
+ .addCommand(server)
33
+
34
+ export { veramo }
package/src/credential.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { getAgent } from './setup.js'
2
- import { program } from 'commander'
2
+ import { Command } from 'commander'
3
3
  import inquirer from 'inquirer'
4
4
  import qrcode from 'qrcode-terminal'
5
5
  import * as fs from 'fs'
@@ -9,7 +9,7 @@ import { CredentialPayload } from '@veramo/core-types'
9
9
 
10
10
  import fuzzy from 'fuzzy'
11
11
 
12
- const credential = program.command('credential').description('W3C Verifiable Credential')
12
+ const credential = new Command('credential').description('W3C Verifiable Credential')
13
13
 
14
14
  credential
15
15
  .command('create', { isDefault: true })
@@ -17,8 +17,8 @@ credential
17
17
  .option('-s, --send', 'Send')
18
18
  .option('-j, --json', 'Output in JSON')
19
19
  .option('-q, --qrcode', 'Show qrcode')
20
- .action(async (cmd) => {
21
- const agent = await getAgent(program.opts().config)
20
+ .action(async (opts: { send: boolean; qrcode: boolean; json: boolean }, cmd: Command) => {
21
+ const agent = await getAgent(cmd.optsWithGlobals().config)
22
22
  const identifiers = await agent.didManagerFind()
23
23
 
24
24
  const knownDids = await agent.dataStoreORMGetIdentifiers()
@@ -127,7 +127,7 @@ credential
127
127
  proofFormat: answers.proofFormat,
128
128
  })
129
129
 
130
- if (cmd.send) {
130
+ if (opts.send) {
131
131
  let body
132
132
  let type
133
133
  if (answers.proofFormat == 'jwt') {
@@ -153,10 +153,10 @@ credential
153
153
  }
154
154
  }
155
155
 
156
- if (cmd.qrcode) {
156
+ if (opts.qrcode) {
157
157
  qrcode.generate(verifiableCredential.proof.jwt)
158
158
  } else {
159
- if (cmd.json) {
159
+ if (opts.json) {
160
160
  console.log(JSON.stringify(verifiableCredential, null, 2))
161
161
  } else {
162
162
  console.dir(verifiableCredential, { depth: 10 })
@@ -169,8 +169,8 @@ credential
169
169
  .description('Verify a W3C Verifiable Credential provided as raw string, file or stdin')
170
170
  .option('-f, --filename <string>', 'Optional. Read the credential from a file instead of stdin')
171
171
  .option('-r, --raw <string>', 'Optional. Specify the credential as a parameter instead of file or stdin')
172
- .action(async (options) => {
173
- const agent = await getAgent(program.opts().config)
172
+ .action(async (options: { raw: string; filename: string }, cmd: Command) => {
173
+ const agent = await getAgent(cmd.optsWithGlobals().config)
174
174
  let raw: string = ''
175
175
  if (options.raw) {
176
176
  raw = options.raw
@@ -205,8 +205,8 @@ credential
205
205
  credential
206
206
  .command('output')
207
207
  .description('Print W3C Verifiable Credential to stdout')
208
- .action(async (cmd) => {
209
- const agent = await getAgent(program.opts().config)
208
+ .action(async (opts: {}, cmd: Command) => {
209
+ const agent = await getAgent(cmd.optsWithGlobals().config)
210
210
 
211
211
  const credentials = await agent.dataStoreORMGetVerifiableCredentials()
212
212
 
@@ -236,3 +236,5 @@ credential
236
236
  console.log('No credentials found.')
237
237
  }
238
238
  })
239
+
240
+ export { credential }
package/src/dev.ts CHANGED
@@ -5,16 +5,15 @@ import {
5
5
  ApiParameterListMixin,
6
6
  ApiReturnTypeMixin,
7
7
  } from '@microsoft/api-extractor-model'
8
- import { program } from 'commander'
8
+ import { Command } from 'commander'
9
9
  import { writeFileSync } from 'fs'
10
10
  import { OpenAPIV3 } from 'openapi-types'
11
11
  import { resolve } from 'path'
12
12
  import * as TJS from 'ts-json-schema-generator'
13
- import fs from 'fs'
14
13
 
15
- import module from "module"
16
- const requireCjs = module.createRequire(import.meta.url);
14
+ import module from 'module'
17
15
 
16
+ const requireCjs = module.createRequire(import.meta.url)
18
17
 
19
18
  interface Method {
20
19
  packageName: string
@@ -24,6 +23,7 @@ interface Method {
24
23
  parameters?: string
25
24
  response: string
26
25
  }
26
+
27
27
  const genericTypes = ['boolean', 'string', 'number', 'any', 'Array<string>']
28
28
 
29
29
  function createSchema(generator: TJS.SchemaGenerator, symbol: string) {
@@ -84,7 +84,7 @@ function getReference(response: string): OpenAPIV3.ReferenceObject | OpenAPIV3.S
84
84
  }
85
85
  }
86
86
 
87
- const dev = program.command('dev').description('Plugin developer tools')
87
+ const dev = new Command('dev').description('Plugin developer tools')
88
88
 
89
89
  dev
90
90
  .command('generate-plugin-schema')
@@ -129,7 +129,7 @@ dev
129
129
  path: resolve(entryFile),
130
130
  encodeRefs: false,
131
131
  additionalProperties: true,
132
- skipTypeCheck: true
132
+ skipTypeCheck: true,
133
133
  })
134
134
 
135
135
  const apiModel: ApiModel = new ApiModel()
@@ -208,3 +208,5 @@ dev
208
208
  process.exitCode = 1
209
209
  }
210
210
  })
211
+
212
+ export { dev }
package/src/did.ts CHANGED
@@ -1,19 +1,19 @@
1
- import { IDIDManagerCreateArgs } from '@veramo/core-types'
1
+ import { IDIDManagerCreateArgs, IIdentifier } from '@veramo/core-types'
2
2
  import { getAgent } from './setup.js'
3
3
  import inquirer from 'inquirer'
4
- import { program } from 'commander'
4
+ import { Command } from 'commander'
5
5
  import { printTable } from 'console-table-printer'
6
6
 
7
- const did = program.command('did').description('Decentralized identifiers')
7
+ const did = new Command('did').description('Decentralized identifiers')
8
8
 
9
9
  did
10
10
  .command('providers')
11
11
  .description('list available identifier providers')
12
- .action(async (cmd) => {
13
- const agent = await getAgent(program.opts().config)
12
+ .action(async (opts: {}, cmd: Command) => {
13
+ const agent = await getAgent(cmd.optsWithGlobals().config)
14
14
 
15
15
  const providers = await agent.didManagerGetProviders()
16
- const list = providers.map((provider) => ({ provider }))
16
+ const list = providers.map((provider: string) => ({ provider }))
17
17
 
18
18
  if (list.length > 0) {
19
19
  printTable(list)
@@ -25,13 +25,17 @@ did
25
25
  did
26
26
  .command('list', { isDefault: true })
27
27
  .description('list managed identifiers')
28
- .action(async (cmd) => {
29
- const agent = await getAgent(program.opts().config)
28
+ .action(async (opts: {}, cmd: Command) => {
29
+ const agent = await getAgent(cmd.optsWithGlobals().config)
30
30
 
31
31
  const list = await agent.didManagerFind()
32
32
 
33
33
  if (list.length > 0) {
34
- const dids = list.map((item) => ({ provider: item.provider, alias: item.alias, did: item.did }))
34
+ const dids = list.map((item: IIdentifier) => ({
35
+ provider: item.provider,
36
+ alias: item.alias,
37
+ did: item.did,
38
+ }))
35
39
  printTable(dids)
36
40
  } else {
37
41
  console.log('No dids')
@@ -41,8 +45,9 @@ did
41
45
  did
42
46
  .command('create')
43
47
  .description('create an identifier')
44
- .action(async (cmd) => {
45
- const agent = await getAgent(program.opts().config)
48
+ .action(async (opts: {}, cmd: Command) => {
49
+ // FIXME: CLI add arguments for provider, kms, alias
50
+ const agent = await getAgent(cmd.optsWithGlobals().config)
46
51
 
47
52
  try {
48
53
  const providers = await agent.didManagerGetProviders()
@@ -79,8 +84,8 @@ did
79
84
  did
80
85
  .command('delete')
81
86
  .description('delete an identifier')
82
- .action(async (cmd) => {
83
- const agent = await getAgent(program.opts().config)
87
+ .action(async (opts: {}, cmd: Command) => {
88
+ const agent = await getAgent(cmd.optsWithGlobals().config)
84
89
 
85
90
  try {
86
91
  const identifiers = await agent.didManagerFind()
@@ -106,8 +111,8 @@ did
106
111
  did
107
112
  .command('add-service')
108
113
  .description('add a service endpoint to did document')
109
- .action(async (cmd) => {
110
- const agent = await getAgent(program.opts().config)
114
+ .action(async (opts: {}, cmd: Command) => {
115
+ const agent = await getAgent(cmd.optsWithGlobals().config)
111
116
 
112
117
  try {
113
118
  const identifiers = await agent.didManagerFind()
@@ -154,8 +159,8 @@ did
154
159
  did
155
160
  .command('remove-service')
156
161
  .description('remove a service endpoint from did document')
157
- .action(async (cmd) => {
158
- const agent = await getAgent(program.opts().config)
162
+ .action(async (opts: {}, cmd: Command) => {
163
+ const agent = await getAgent(cmd.optsWithGlobals().config)
159
164
 
160
165
  try {
161
166
  const identifiers = await agent.didManagerFind()
@@ -187,8 +192,8 @@ did
187
192
  did
188
193
  .command('add-key')
189
194
  .description('create and add a public key to did document')
190
- .action(async (cmd) => {
191
- const agent = await getAgent(program.opts().config)
195
+ .action(async (opts: {}, cmd: Command) => {
196
+ const agent = await getAgent(cmd.optsWithGlobals().config)
192
197
 
193
198
  try {
194
199
  const identifiers = await agent.didManagerFind()
@@ -233,8 +238,8 @@ did
233
238
  did
234
239
  .command('remove-key')
235
240
  .description('remove a key from did document')
236
- .action(async (cmd) => {
237
- const agent = await getAgent(program.opts().config)
241
+ .action(async (opts: {}, cmd: Command) => {
242
+ const agent = await getAgent(cmd.optsWithGlobals().config)
238
243
 
239
244
  try {
240
245
  const identifiers = await agent.didManagerFind()
@@ -266,8 +271,8 @@ did
266
271
  did
267
272
  .command('export')
268
273
  .description('export an identifier')
269
- .action(async (cmd) => {
270
- const agent = await getAgent(program.opts().config)
274
+ .action(async (opts: {}, cmd: Command) => {
275
+ const agent = await getAgent(cmd.optsWithGlobals().config)
271
276
 
272
277
  try {
273
278
  const identifiers = await agent.didManagerFind()
@@ -294,8 +299,8 @@ did
294
299
  did
295
300
  .command('import')
296
301
  .description('import an identifier')
297
- .action(async (cmd) => {
298
- const agent = await getAgent(program.opts().config)
302
+ .action(async (opts: {}, cmd: Command) => {
303
+ const agent = await getAgent(cmd.optsWithGlobals().config)
299
304
 
300
305
  try {
301
306
  const answers = await inquirer.prompt([
@@ -316,8 +321,8 @@ did
316
321
  did
317
322
  .command('resolve <didUrl>')
318
323
  .description('Resolve DID Document')
319
- .action(async (didUrl) => {
320
- const agent = await getAgent(program.opts().config)
324
+ .action(async (didUrl: string, opts: {}, cmd: Command) => {
325
+ const agent = await getAgent(cmd.optsWithGlobals().config)
321
326
  try {
322
327
  const ddo = await agent.resolveDid({ didUrl })
323
328
  console.log(JSON.stringify(ddo, null, 2))
@@ -325,3 +330,5 @@ did
325
330
  console.error(e.message)
326
331
  }
327
332
  })
333
+
334
+ export { did }
package/src/discover.ts CHANGED
@@ -1,18 +1,18 @@
1
1
  import { getAgent } from './setup.js'
2
- import { program } from 'commander'
2
+ import { Command } from 'commander'
3
3
  import { printTable } from 'console-table-printer'
4
4
 
5
- const discover = program.command('discover').description('Discovery')
5
+ const discover = new Command('discover').description('Discovery')
6
6
 
7
7
  discover
8
8
  .command('did')
9
9
  .description('did discovery')
10
10
  .option('-q, --query <string>', 'Query string')
11
11
 
12
- .action(async (cmd) => {
13
- const agent = await getAgent(program.opts().config)
12
+ .action(async (opts: { query: string }, cmd: Command) => {
13
+ const agent = await getAgent(cmd.optsWithGlobals().config)
14
14
 
15
- const response = await agent.discoverDid({ query: cmd.query })
15
+ const response = await agent.discoverDid({ query: opts.query })
16
16
  const list: any = []
17
17
 
18
18
  response.results.forEach((r: any) => {
@@ -30,3 +30,5 @@ discover
30
30
  console.log('No dids discovered')
31
31
  }
32
32
  })
33
+
34
+ export { discover }
package/src/execute.ts CHANGED
@@ -1,18 +1,17 @@
1
- import { program } from 'commander'
1
+ import { Command } from 'commander'
2
2
  import inquirer from 'inquirer'
3
3
  import { getAgent } from './setup.js'
4
4
  import fs from 'fs'
5
5
  import OasResolver from 'oas-resolver'
6
6
  import fuzzy from 'fuzzy'
7
7
 
8
- program
9
- .command('execute')
10
- .description('Executes agent method')
8
+ const execute = new Command('execute')
9
+ .description('Execute agent method')
11
10
  .option('-m, --method <string>', 'Method name')
12
11
  .option('-a, --argsJSON <string>', 'Method arguments')
13
12
  .option('-f, --argsFile <string>', 'Path to a file containing method arguments in a JSON string')
14
- .action(async (options) => {
15
- const agent = await getAgent(program.opts().config)
13
+ .action(async (options: { method: string; argsJSON?: string; argsFile?: string }, cmd: Command) => {
14
+ const agent = await getAgent(cmd.optsWithGlobals().config)
16
15
 
17
16
  try {
18
17
  let method = options.method
@@ -92,9 +91,13 @@ program
92
91
  } else {
93
92
  if (argsFile) {
94
93
  console.log({ argsFile })
95
- argsString = fs.readFileSync(argsFile)
94
+ argsString = fs.readFileSync(argsFile).toString('utf-8')
95
+ }
96
+ try {
97
+ argsObj = JSON.parse(argsString!)
98
+ } catch (e: any) {
99
+ console.error('could not parse arguments JSON')
96
100
  }
97
- argsObj = JSON.parse(argsString)
98
101
  }
99
102
 
100
103
  console.log('\nMethod: ', method)
@@ -111,3 +114,5 @@ program
111
114
  console.error(e.message)
112
115
  }
113
116
  })
117
+
118
+ export { execute }
@@ -1,12 +1,12 @@
1
1
  import { getAgent } from '../setup.js'
2
2
  import { Command } from 'commander'
3
- const program = new Command();
4
3
  import { renderMainScreen } from './main.js'
5
4
 
6
- program
7
- .command('explore')
5
+ const explore = new Command('explore')
8
6
  .description('launch Verifiable Data explorer')
9
- .action(async (cmd) => {
10
- const agent = await getAgent(program.opts().config)
7
+ .action(async (opts: {}, cmd: Command) => {
8
+ const agent = await getAgent(cmd.optsWithGlobals().config)
11
9
  await renderMainScreen(agent)
12
10
  })
11
+
12
+ export { explore }
@@ -1,6 +1,15 @@
1
1
  import { TAgent, IPluginMethodMap } from '@veramo/core-types'
2
2
  import { createObjects } from './objectCreator.js'
3
3
 
4
+ /**
5
+ * Creates a Veramo agent from a config object containing an `/agent` pointer.
6
+ * @param config - The configuration object
7
+ *
8
+ * @see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for details on
9
+ * the configuration options.
10
+ *
11
+ * @beta
12
+ */
4
13
  export async function createAgentFromConfig<T extends IPluginMethodMap>(config: object): Promise<TAgent<T>> {
5
14
  // @ts-ignore
6
15
  const { agent } = await createObjects(config, { agent: '/agent' })