@veramo/cli 5.0.1-next.8 → 5.1.1-next.2
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.
- package/build/cli.d.ts +1 -13
- package/build/cli.d.ts.map +1 -1
- package/build/cli.js +3 -16
- package/build/cli.js.map +1 -1
- package/build/config.d.ts +3 -1
- package/build/config.d.ts.map +1 -1
- package/build/config.js +6 -4
- package/build/config.js.map +1 -1
- package/build/createCommand.d.ts +4 -0
- package/build/createCommand.d.ts.map +1 -0
- package/build/createCommand.js +31 -0
- package/build/createCommand.js.map +1 -0
- package/build/credential.d.ts +3 -1
- package/build/credential.d.ts.map +1 -1
- package/build/credential.js +12 -11
- package/build/credential.js.map +1 -1
- package/build/dev.d.ts +3 -1
- package/build/dev.d.ts.map +1 -1
- package/build/dev.js +12 -11
- package/build/dev.js.map +1 -1
- package/build/did.d.ts +3 -1
- package/build/did.d.ts.map +1 -1
- package/build/did.js +31 -25
- package/build/did.js.map +1 -1
- package/build/discover.d.ts +3 -1
- package/build/discover.d.ts.map +1 -1
- package/build/discover.js +6 -5
- package/build/discover.js.map +1 -1
- package/build/execute.d.ts +3 -1
- package/build/execute.d.ts.map +1 -1
- package/build/execute.js +14 -9
- package/build/execute.js.map +1 -1
- package/build/explore/index.d.ts +3 -1
- package/build/explore/index.d.ts.map +1 -1
- package/build/explore/index.js +4 -5
- package/build/explore/index.js.map +1 -1
- package/build/lib/agentCreator.d.ts +9 -0
- package/build/lib/agentCreator.d.ts.map +1 -1
- package/build/lib/agentCreator.js +10 -1
- package/build/lib/agentCreator.js.map +1 -1
- package/build/lib/objectCreator.d.ts +47 -1
- package/build/lib/objectCreator.d.ts.map +1 -1
- package/build/lib/objectCreator.js +48 -2
- package/build/lib/objectCreator.js.map +1 -1
- package/build/message.d.ts +3 -1
- package/build/message.d.ts.map +1 -1
- package/build/message.js +5 -4
- package/build/message.js.map +1 -1
- package/build/presentation.d.ts +3 -1
- package/build/presentation.d.ts.map +1 -1
- package/build/presentation.js +14 -13
- package/build/presentation.js.map +1 -1
- package/build/sdr.d.ts +3 -1
- package/build/sdr.d.ts.map +1 -1
- package/build/sdr.js +10 -8
- package/build/sdr.js.map +1 -1
- package/build/server.d.ts +3 -1
- package/build/server.d.ts.map +1 -1
- package/build/server.js +10 -7
- package/build/server.js.map +1 -1
- package/build/setup.d.ts +9 -1
- package/build/setup.d.ts.map +1 -1
- package/build/setup.js +22 -6
- package/build/setup.js.map +1 -1
- package/default/default.yml +21 -17
- package/package.json +45 -26
- package/src/__tests__/cli.test.ts +49 -0
- package/src/cli.ts +3 -17
- package/src/config.ts +9 -6
- package/src/createCommand.ts +34 -0
- package/src/credential.ts +13 -11
- package/src/dev.ts +15 -13
- package/src/did.ts +34 -27
- package/src/discover.ts +7 -5
- package/src/execute.ts +14 -9
- package/src/explore/index.ts +5 -5
- package/src/lib/agentCreator.ts +10 -1
- package/src/lib/objectCreator.ts +49 -3
- package/src/message.ts +6 -4
- package/src/presentation.ts +53 -48
- package/src/sdr.ts +11 -8
- package/src/server.ts +11 -7
- package/src/setup.ts +22 -6
- package/build/version.d.ts +0 -2
- package/build/version.d.ts.map +0 -1
- package/build/version.js +0 -7
- package/build/version.js.map +0 -1
- package/src/__tests__/default.test.ts +0 -6
- package/src/version.ts +0 -9
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 {
|
|
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
|
|
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) {
|
|
@@ -77,14 +77,14 @@ function getReference(response: string): OpenAPIV3.ReferenceObject | OpenAPIV3.S
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
if (['string', 'number', 'boolean', 'object', 'integer'].includes(response)) {
|
|
80
|
-
|
|
80
|
+
// @ts-ignore
|
|
81
81
|
return { type: response }
|
|
82
82
|
} else {
|
|
83
83
|
return { $ref: '#/components/schemas/' + response }
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
const dev =
|
|
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()
|
|
@@ -152,28 +152,28 @@ dev
|
|
|
152
152
|
const methodSignature = member as ApiMethodSignature
|
|
153
153
|
method.description = methodSignature.tsdocComment?.summarySection
|
|
154
154
|
?.getChildNodes()[0]
|
|
155
|
-
|
|
155
|
+
// @ts-ignore
|
|
156
156
|
?.getChildNodes()[0]?.text
|
|
157
157
|
|
|
158
158
|
method.description = method.description || ''
|
|
159
159
|
|
|
160
160
|
if (method.parameters) {
|
|
161
|
-
|
|
161
|
+
// @ts-ignore
|
|
162
162
|
api.components.schemas = {
|
|
163
|
-
|
|
163
|
+
// @ts-ignore
|
|
164
164
|
...api.components.schemas,
|
|
165
165
|
...createSchema(generator, method.parameters).components.schemas,
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
// @ts-ignore
|
|
170
170
|
api.components.schemas = {
|
|
171
|
-
|
|
171
|
+
// @ts-ignore
|
|
172
172
|
...api.components.schemas,
|
|
173
173
|
...createSchema(generator, method.response).components.schemas,
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
|
|
176
|
+
// @ts-ignore
|
|
177
177
|
api.components.methods[method.operationId] = {
|
|
178
178
|
description: method.description,
|
|
179
179
|
arguments: getReference(method.parameters),
|
|
@@ -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 {
|
|
4
|
+
import { Command } from 'commander'
|
|
5
5
|
import { printTable } from 'console-table-printer'
|
|
6
6
|
|
|
7
|
-
const did =
|
|
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(
|
|
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(
|
|
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) => ({
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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 {
|
|
2
|
+
import { Command } from 'commander'
|
|
3
3
|
import { printTable } from 'console-table-printer'
|
|
4
4
|
|
|
5
|
-
const discover =
|
|
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(
|
|
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:
|
|
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 {
|
|
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
|
-
|
|
9
|
-
.
|
|
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(
|
|
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
|
|
@@ -24,7 +23,7 @@ program
|
|
|
24
23
|
|
|
25
24
|
if (!method) {
|
|
26
25
|
const answers = await inquirer.prompt({
|
|
27
|
-
|
|
26
|
+
// @ts-ignore
|
|
28
27
|
type: 'autocomplete',
|
|
29
28
|
name: 'method',
|
|
30
29
|
pageSize: 15,
|
|
@@ -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 }
|
package/src/explore/index.ts
CHANGED
|
@@ -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
|
-
|
|
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(
|
|
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 }
|
package/src/lib/agentCreator.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
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' })
|
|
7
16
|
return agent
|
|
8
17
|
}
|
package/src/lib/objectCreator.ts
CHANGED
|
@@ -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
|
-
|
|
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 ?
|
|
100
|
+
const resolvedArgs = args !== undefined ? await resolveRefs(args) : []
|
|
55
101
|
try {
|
|
56
|
-
let required = member ? (await import(module))[member] :
|
|
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 {
|
|
2
|
+
import { Command } from 'commander'
|
|
3
3
|
import fs from 'fs'
|
|
4
4
|
|
|
5
|
-
const message =
|
|
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(
|
|
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 }
|
package/src/presentation.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { getAgent } from './setup.js'
|
|
2
|
-
import {
|
|
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
|
|
9
|
+
import { PartialIdentifier, UniqueVerifiablePresentation } from '@veramo/core-types'
|
|
10
10
|
|
|
11
|
-
const 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(
|
|
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 (
|
|
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 (
|
|
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(
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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(
|
|
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 }
|