@veramo/cli 5.0.1-next.12 → 5.0.1-next.14

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 (89) 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 +47 -1
  42. package/build/lib/objectCreator.d.ts.map +1 -1
  43. package/build/lib/objectCreator.js +48 -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/build/setup.d.ts +9 -1
  62. package/build/setup.d.ts.map +1 -1
  63. package/build/setup.js +22 -6
  64. package/build/setup.js.map +1 -1
  65. package/default/default.yml +24 -20
  66. package/package.json +45 -26
  67. package/src/__tests__/cli.test.ts +49 -0
  68. package/src/cli.ts +3 -17
  69. package/src/config.ts +9 -6
  70. package/src/createCommand.ts +34 -0
  71. package/src/credential.ts +13 -11
  72. package/src/dev.ts +8 -6
  73. package/src/did.ts +34 -27
  74. package/src/discover.ts +7 -5
  75. package/src/execute.ts +13 -8
  76. package/src/explore/index.ts +5 -5
  77. package/src/lib/agentCreator.ts +9 -0
  78. package/src/lib/objectCreator.ts +49 -3
  79. package/src/message.ts +6 -4
  80. package/src/presentation.ts +53 -48
  81. package/src/sdr.ts +10 -7
  82. package/src/server.ts +11 -7
  83. package/src/setup.ts +22 -6
  84. package/build/version.d.ts +0 -2
  85. package/build/version.d.ts.map +0 -1
  86. package/build/version.js +0 -7
  87. package/build/version.js.map +0 -1
  88. package/src/__tests__/default.test.ts +0 -6
  89. package/src/version.ts +0 -9
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 - This API may change without a major version bump
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' })
@@ -2,7 +2,53 @@ import { set, get } from 'jsonpointer'
2
2
  import parse from 'url-parse'
3
3
  import { resolve } from 'path'
4
4
 
5
- export async function createObjects(config: object, pointers: Record<string, string>): Promise<any> {
5
+ /**
6
+ * Creates objects from a configuration object and a set of pointers.
7
+ *
8
+ * Example:
9
+ * ```ts
10
+ * const { url } = createObjects({ "rpcUrl": "http://localhost:8545", }, { url: '/rpcUrl' })
11
+ * ```
12
+ *
13
+ * The config can contain references (`$ref`) to other objects within using JSON pointers.
14
+ * Example:
15
+ * ```json
16
+ * {
17
+ * "rpcUrl": "http://localhost:8545",
18
+ * "endpoint": {
19
+ * "url": {
20
+ * "$ref": "/rpcUrl"
21
+ * }
22
+ * }
23
+ * }
24
+ * ```
25
+ *
26
+ * The config object can also contain references to NPM modules using the `$require` property.
27
+ * Example:
28
+ * ```json
29
+ * {
30
+ * "agent": {
31
+ * "$require": "@veramo/core#Agent",
32
+ * "$args": {
33
+ * "plugins": [
34
+ * { "$require": "@veramo/did-comm#DIDComm" },
35
+ * ]
36
+ * }
37
+ * }
38
+ * }
39
+ * ```
40
+ *
41
+ * Environment variables can also be specified using the `$env` property.
42
+ *
43
+ * @see Please see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for
44
+ * more information.
45
+ *
46
+ * @param config - The configuration object
47
+ * @param pointers - A map of JSON pointers to objects within that config that you wish to create
48
+ *
49
+ * @beta - This API may change without a major version bump
50
+ */
51
+ export async function createObjects(config: object, pointers: Record<string, string>): Promise<Record<string, any>> {
6
52
  const objects = {}
7
53
 
8
54
  async function resolveRefs(input: any): Promise<any> {
@@ -51,9 +97,9 @@ export async function createObjects(config: object, pointers: Record<string, str
51
97
  module = resolve(module)
52
98
  }
53
99
 
54
- const resolvedArgs = args !== undefined ? (await resolveRefs(args)) : []
100
+ const resolvedArgs = args !== undefined ? await resolveRefs(args) : []
55
101
  try {
56
- let required = member ? (await import(module))[member] : (await import(module))
102
+ let required = member ? (await import(module))[member] : await import(module)
57
103
  if (type === 'class') {
58
104
  object = new required(...resolvedArgs)
59
105
  } else if (type === 'function') {
package/src/message.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { getAgent } from './setup.js'
2
- import { program } from 'commander'
2
+ import { Command } from 'commander'
3
3
  import fs from 'fs'
4
4
 
5
- const message = program.command('message').description('Messages')
5
+ const message = new Command('message').description('Messages')
6
6
 
7
7
  message
8
8
  .command('handle', { isDefault: true })
@@ -11,8 +11,8 @@ message
11
11
  .option('-f, --file <string>', 'Path to a file containing raw message')
12
12
  .option('--save <boolean>', 'Save message', true)
13
13
 
14
- .action(async (options) => {
15
- const agent = await getAgent(program.opts().config)
14
+ .action(async (options: { file: string; raw: string; save: boolean }, cmd: Command) => {
15
+ const agent = await getAgent(cmd.optsWithGlobals().config)
16
16
  try {
17
17
  let raw
18
18
 
@@ -35,3 +35,5 @@ message
35
35
  console.error(e.message)
36
36
  }
37
37
  })
38
+
39
+ export { message }
@@ -1,22 +1,22 @@
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 { readStdin } from './util.js'
6
6
  import * as fs from 'fs'
7
7
  import * as json5 from 'json5'
8
8
  import { extractIssuer } from '@veramo/utils'
9
- import { PartialIdentifier, UniqueVerifiablePresentation } from "@veramo/core-types";
9
+ import { PartialIdentifier, UniqueVerifiablePresentation } from '@veramo/core-types'
10
10
 
11
- const presentation = program.command('presentation').description('W3C Verifiable Presentation')
11
+ const presentation = new Command('presentation').description('W3C Verifiable Presentation')
12
12
 
13
13
  presentation
14
14
  .command('create', { isDefault: true })
15
15
  .description('Create W3C Verifiable Presentation')
16
16
  .option('-s, --send', 'Send')
17
17
  .option('-q, --qrcode', 'Show qrcode')
18
- .action(async (cmd) => {
19
- const agent = await getAgent(program.opts().config)
18
+ .action(async (opts: { send: boolean; qrcode: boolean }, cmd: Command) => {
19
+ const agent = await getAgent(cmd.optsWithGlobals().config)
20
20
  const myIdentifiers = await agent.didManagerFind()
21
21
  if (myIdentifiers.length === 0) {
22
22
  console.error('No dids')
@@ -33,7 +33,7 @@ presentation
33
33
  ...ids.map((id: PartialIdentifier) => id.did),
34
34
  ]
35
35
 
36
- let aud:string[] = []
36
+ let aud: string[] = []
37
37
  const answers = await inquirer.prompt([
38
38
  {
39
39
  type: 'list',
@@ -72,8 +72,8 @@ presentation
72
72
  type: 'list',
73
73
  name: 'aud',
74
74
  message: 'Select Verifier or enter manually',
75
- choices: identifiers
76
- }
75
+ choices: identifiers,
76
+ },
77
77
  ])
78
78
  answer = audAnswer.aud
79
79
  if (answer === 'manual') {
@@ -144,8 +144,8 @@ presentation
144
144
  proofFormat: 'jwt',
145
145
  })
146
146
 
147
- if (cmd.send) {
148
- for(var verifier in aud) {
147
+ if (opts.send) {
148
+ for (var verifier in aud) {
149
149
  try {
150
150
  const message = await agent.sendMessageDIDCommAlpha1({
151
151
  save: true,
@@ -163,7 +163,7 @@ presentation
163
163
  }
164
164
  }
165
165
 
166
- if (cmd.qrcode) {
166
+ if (opts.qrcode) {
167
167
  qrcode.generate(verifiablePresentation.proof.jwt)
168
168
  } else {
169
169
  console.dir(verifiablePresentation, { depth: 10 })
@@ -178,54 +178,57 @@ presentation
178
178
  .option('-d, --domain <string>', 'Optional. Specify a domain that the presentation should match.')
179
179
  .option('-f, --filename <string>', 'Optional. Read the presentation from a file instead of stdin')
180
180
  .option('-r, --raw <string>', 'Optional. Presentation as a parameter string instead of a file or stdin.')
181
- .action(async (options) => {
182
- const agent = await getAgent(program.opts().config)
183
- let raw: string = ''
184
- if (options.raw) {
185
- raw = options.raw
186
- } else if (options.filename) {
187
- raw = await fs.promises.readFile(options.filename, 'utf-8')
188
- } else {
189
- raw = await readStdin()
190
- }
191
- let presentationAsJSON: any
192
- try {
193
- presentationAsJSON = json5.parse(raw)
194
- } catch (e: any) {
195
- presentationAsJSON = {
196
- proof: {
197
- type: 'JwtProof2020',
198
- jwt: raw,
199
- },
200
- } as any
201
- }
202
- const result = await agent.verifyPresentation({
203
- presentation: presentationAsJSON,
204
- challenge: options.challenge,
205
- domain: options.domain,
206
- })
207
- if (result.verified === true) {
208
- console.log('Presentation was verified successfully.')
209
- } else {
210
- console.error('Presentation could not be verified.')
211
- }
212
- })
181
+ .action(
182
+ async (options: { challenge: string; domain: string; filename: string; raw: string }, cmd: Command) => {
183
+ const agent = await getAgent(cmd.optsWithGlobals().config)
184
+ let raw: string = ''
185
+ if (options.raw) {
186
+ raw = options.raw
187
+ } else if (options.filename) {
188
+ raw = await fs.promises.readFile(options.filename, 'utf-8')
189
+ } else {
190
+ raw = await readStdin()
191
+ }
192
+ let presentationAsJSON: any
193
+ try {
194
+ presentationAsJSON = json5.parse(raw)
195
+ } catch (e: any) {
196
+ presentationAsJSON = {
197
+ proof: {
198
+ type: 'JwtProof2020',
199
+ jwt: raw,
200
+ },
201
+ } as any
202
+ }
203
+ const result = await agent.verifyPresentation({
204
+ presentation: presentationAsJSON,
205
+ challenge: options.challenge,
206
+ domain: options.domain,
207
+ })
208
+ if (result.verified === true) {
209
+ console.log('Presentation was verified successfully.')
210
+ } else {
211
+ console.error('Presentation could not be verified.')
212
+ }
213
+ },
214
+ )
213
215
 
214
216
  presentation
215
217
  .command('output')
216
218
  .description('Print W3C Verifiable Presentation to stdout')
217
219
  .option('-t, --tag <string>', 'Optional. Specify the tag for the presentation.')
218
- .action(async (options) => {
219
- const agent = await getAgent(program.opts().config)
220
+ .action(async (options: { tag: string }, cmd: Command) => {
221
+ const agent = await getAgent(cmd.optsWithGlobals().config)
220
222
 
221
- const presentations: UniqueVerifiablePresentation[] = await agent.dataStoreORMGetVerifiablePresentations({})
223
+ const presentations: UniqueVerifiablePresentation[] = await agent.dataStoreORMGetVerifiablePresentations(
224
+ {},
225
+ )
222
226
 
223
227
  if (presentations.length > 0) {
224
-
225
228
  let selected = null
226
229
  const list: any = []
227
230
  if (options.tag) {
228
- const matches = presentations.filter(pres => pres.verifiablePresentation.tag === options.tag)
231
+ const matches = presentations.filter((pres) => pres.verifiablePresentation.tag === options.tag)
229
232
  if (matches.length > 1) {
230
233
  console.log('Found multiple matching presentations. Only showing the first one.')
231
234
  }
@@ -263,3 +266,5 @@ presentation
263
266
  console.log('No presentations found.')
264
267
  }
265
268
  })
269
+
270
+ export { presentation }
package/src/sdr.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ICredentialRequestInput } from '@veramo/selective-disclosure'
2
2
  import { getAgent } from './setup.js'
3
- import { program } from 'commander'
3
+ import { Command } from 'commander'
4
4
  import inquirer from 'inquirer'
5
5
  import qrcode from 'qrcode-terminal'
6
6
  import { shortDate, shortDid } from './explore/utils.js'
@@ -9,13 +9,14 @@ import { asArray, extractIssuer } from '@veramo/utils'
9
9
 
10
10
  import fuzzy from 'fuzzy'
11
11
 
12
- const sdr = program.command('sdr').description('Selective Disclosure Request')
12
+ const sdr = new Command('sdr').description('Selective Disclosure Request')
13
13
 
14
14
  sdr
15
15
  .command('create', { isDefault: true })
16
16
  .description('create Selective Disclosure Request')
17
- .action(async (cmd) => {
18
- const agent = await getAgent(program.opts().config)
17
+ .option('-q, --qrcode', 'Show qrcode')
18
+ .action(async (opts: { qrcode: boolean }, cmd: Command) => {
19
+ const agent = await getAgent(cmd.optsWithGlobals().config)
19
20
  const identifiers = await agent.didManagerFind()
20
21
 
21
22
  const knownDids = await agent.dataStoreORMGetIdentifiers()
@@ -253,7 +254,7 @@ sdr
253
254
  console.log('Subject not specified')
254
255
  }
255
256
 
256
- if (cmd.qrcode) {
257
+ if (opts.qrcode) {
257
258
  qrcode.generate(jwt)
258
259
  } else {
259
260
  console.dir(data, { depth: 10 })
@@ -264,8 +265,8 @@ sdr
264
265
  sdr
265
266
  .command('respond')
266
267
  .description('respond to Selective Disclosure Request')
267
- .action(async (cmd) => {
268
- const agent = await getAgent(program.opts().config)
268
+ .action(async (opts: {}, cmd: Command) => {
269
+ const agent = await getAgent(cmd.optsWithGlobals().config)
269
270
  const sdrMessages = await agent.dataStoreORMGetMessages({
270
271
  where: [{ column: 'type', value: ['sdr'] }],
271
272
  order: [{ column: 'createdAt', direction: 'DESC' }],
@@ -354,3 +355,5 @@ sdr
354
355
 
355
356
  console.dir(verifiablePresentation, { depth: 10 })
356
357
  })
358
+
359
+ export { sdr }
package/src/server.ts CHANGED
@@ -1,30 +1,34 @@
1
1
  import express from 'express'
2
- import { program } from 'commander'
2
+ import { Command } from 'commander'
3
3
  import { getConfig } from './setup.js'
4
4
  import { createObjects } from './lib/objectCreator.js'
5
5
 
6
- program
7
- .command('server')
6
+ const server = new Command('server')
8
7
  .description('Launch OpenAPI server')
9
8
  .option('-p, --port <number>', 'Optionally set port to override config')
10
- .action(async (cmd) => {
9
+ .action(async (opts: { port: number }, cmd: Command) => {
11
10
  const app = express()
12
11
 
13
12
  let server: any
14
13
 
15
14
  try {
16
- const config = await createObjects(getConfig(program.opts().config), { server: '/server' })
15
+ const config = await createObjects(getConfig(cmd.optsWithGlobals().config), { server: '/server' })
17
16
  server = config.server
18
17
  } catch (e: any) {
19
- console.log(e.message)
18
+ console.error(e.message)
20
19
  process.exit(1)
21
20
  }
22
21
 
23
22
  for (let router of server.use) {
24
23
  app.use(...router)
24
+ if (typeof router[0] === 'string') {
25
+ console.log(`Listening to route: ${server.baseUrl}${router[0]}`)
26
+ }
25
27
  }
26
28
 
27
- app.listen(cmd.port || server.port, async () => {
29
+ app.listen(opts.port || server.port, async () => {
28
30
  console.log(`🚀 Cloud Agent ready at ${server.baseUrl}`)
29
31
  })
30
32
  })
33
+
34
+ export { server }
package/src/setup.ts CHANGED
@@ -16,17 +16,33 @@ import { createAgentFromConfig } from './lib/agentCreator.js'
16
16
 
17
17
  import fs from 'fs'
18
18
 
19
- export const getConfig = (fileName: string): any => {
20
- if (!fs.existsSync(fileName)) {
21
- console.log('Config file not found: ' + fileName)
19
+ /**
20
+ * Parses a yaml config file and returns a config object
21
+ * @param filePath
22
+ */
23
+ export const getConfig = async (filePath: fs.PathLike): Promise<{ version?: number; [x: string]: any }> => {
24
+ let fileContent: string
25
+
26
+ // read file async
27
+ try {
28
+ fileContent = await fs.promises.readFile(filePath, 'utf8')
29
+ } catch (e) {
30
+ console.log('Config file not found: ' + filePath)
22
31
  console.log('Use "veramo config create" to create one')
23
32
  process.exit(1)
24
33
  }
25
34
 
26
- const config = yaml.parse(fs.readFileSync(fileName).toString(), { prettyErrors: true })
35
+ let config
36
+
37
+ try {
38
+ config = yaml.parse(fileContent, { prettyErrors: true })
39
+ } catch (e) {
40
+ console.error(`Unable to parse config file: ${e.message} ${e.linePos}`)
41
+ process.exit(1)
42
+ }
27
43
 
28
44
  if (config?.version != 3) {
29
- console.log('Unsupported configuration file version:', config.version)
45
+ console.error('Unsupported configuration file version:', config.version)
30
46
  process.exit(1)
31
47
  }
32
48
  return config
@@ -47,7 +63,7 @@ export type ConfiguredAgent = TAgent<EnabledInterfaces>
47
63
 
48
64
  export async function getAgent(fileName: string): Promise<ConfiguredAgent> {
49
65
  try {
50
- return await createAgentFromConfig<EnabledInterfaces>(getConfig(fileName))
66
+ return await createAgentFromConfig<EnabledInterfaces>(await getConfig(fileName))
51
67
  } catch (e: any) {
52
68
  console.log('Unable to create agent from ' + fileName + '.', e.message)
53
69
  process.exit(1)
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=version.d.ts.map