@veramo/cli 3.0.1-next.8 → 3.1.1-next.10

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 (58) hide show
  1. package/build/cli.js +3 -3
  2. package/build/cli.js.map +1 -1
  3. package/build/config.js +42 -9
  4. package/build/config.js.map +1 -1
  5. package/build/credential.js +94 -8
  6. package/build/credential.js.map +1 -1
  7. package/build/dev.js +7 -9
  8. package/build/dev.js.map +1 -1
  9. package/build/did.js +13 -13
  10. package/build/did.js.map +1 -1
  11. package/build/discover.js +3 -6
  12. package/build/discover.js.map +1 -1
  13. package/build/execute.js +3 -3
  14. package/build/execute.js.map +1 -1
  15. package/build/explore/credentials.d.ts.map +1 -1
  16. package/build/explore/credentials.js +3 -2
  17. package/build/explore/credentials.js.map +1 -1
  18. package/build/explore/index.js +3 -6
  19. package/build/explore/index.js.map +1 -1
  20. package/build/explore/presentations.d.ts.map +1 -1
  21. package/build/explore/presentations.js +3 -2
  22. package/build/explore/presentations.js.map +1 -1
  23. package/build/message.js +3 -6
  24. package/build/message.js.map +1 -1
  25. package/build/presentation.js +70 -4
  26. package/build/presentation.js.map +1 -1
  27. package/build/sdr.js +8 -7
  28. package/build/sdr.js.map +1 -1
  29. package/build/server.js +3 -3
  30. package/build/server.js.map +1 -1
  31. package/build/setup.js +1 -1
  32. package/build/setup.js.map +1 -1
  33. package/build/util.d.ts +2 -0
  34. package/build/util.d.ts.map +1 -0
  35. package/build/util.js +36 -0
  36. package/build/util.js.map +1 -0
  37. package/build/version.js +2 -5
  38. package/build/version.js.map +1 -1
  39. package/default/client.yml +3 -1
  40. package/default/default.yml +26 -9
  41. package/package.json +35 -34
  42. package/src/cli.ts +1 -1
  43. package/src/config.ts +44 -4
  44. package/src/credential.ts +69 -8
  45. package/src/dev.ts +8 -12
  46. package/src/did.ts +1 -1
  47. package/src/discover.ts +1 -1
  48. package/src/execute.ts +1 -3
  49. package/src/explore/credentials.ts +3 -2
  50. package/src/explore/index.ts +1 -1
  51. package/src/explore/presentations.ts +3 -3
  52. package/src/message.ts +1 -1
  53. package/src/presentation.ts +46 -3
  54. package/src/sdr.ts +6 -4
  55. package/src/server.ts +1 -1
  56. package/src/setup.ts +1 -1
  57. package/src/util.ts +23 -0
  58. package/src/version.ts +1 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@veramo/cli",
3
3
  "description": "Veramo command line application.",
4
- "version": "3.0.1-next.8+0ca9b448",
4
+ "version": "3.1.1-next.10+ef7797d4",
5
5
  "main": "build/cli.js",
6
6
  "types": "build/cli.d.ts",
7
7
  "bin": {
@@ -14,68 +14,69 @@
14
14
  "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"
15
15
  },
16
16
  "dependencies": {
17
- "@microsoft/api-extractor": "7.18.11",
18
- "@microsoft/api-extractor-model": "7.13.9",
17
+ "@microsoft/api-extractor": "7.18.19",
18
+ "@microsoft/api-extractor-model": "7.13.16",
19
19
  "@types/blessed": "^0.1.17",
20
20
  "@types/swagger-ui-express": "^4.1.2",
21
- "@veramo/core": "^3.0.1-next.8+0ca9b448",
22
- "@veramo/credential-w3c": "^3.0.1-next.8+0ca9b448",
23
- "@veramo/data-store": "^3.0.1-next.8+0ca9b448",
24
- "@veramo/did-comm": "^3.0.1-next.8+0ca9b448",
25
- "@veramo/did-discovery": "^3.0.1-next.8+0ca9b448",
26
- "@veramo/did-jwt": "^3.0.1-next.8+0ca9b448",
27
- "@veramo/did-manager": "^3.0.1-next.8+0ca9b448",
28
- "@veramo/did-provider-ethr": "^3.0.1-next.8+0ca9b448",
29
- "@veramo/did-provider-key": "^3.0.1-next.8+0ca9b448",
30
- "@veramo/did-provider-web": "^3.0.1-next.8+0ca9b448",
31
- "@veramo/did-resolver": "^3.0.1-next.8+0ca9b448",
32
- "@veramo/key-manager": "^3.0.1-next.8+0ca9b448",
33
- "@veramo/kms-local": "^3.0.1-next.8+0ca9b448",
34
- "@veramo/message-handler": "^3.0.1-next.8+0ca9b448",
35
- "@veramo/remote-client": "^3.0.1-next.8+0ca9b448",
36
- "@veramo/remote-server": "^3.0.1-next.8+0ca9b448",
37
- "@veramo/selective-disclosure": "^3.0.1-next.8+0ca9b448",
38
- "@veramo/url-handler": "^3.0.1-next.8+0ca9b448",
21
+ "@veramo/core": "^3.1.1-next.10+ef7797d4",
22
+ "@veramo/credential-w3c": "^3.1.1-next.10+ef7797d4",
23
+ "@veramo/data-store": "^3.1.1-next.10+ef7797d4",
24
+ "@veramo/did-comm": "^3.1.1-next.10+ef7797d4",
25
+ "@veramo/did-discovery": "^3.1.1-next.10+ef7797d4",
26
+ "@veramo/did-jwt": "^3.1.1-next.10+ef7797d4",
27
+ "@veramo/did-manager": "^3.1.1-next.10+ef7797d4",
28
+ "@veramo/did-provider-ethr": "^3.1.1-next.10+ef7797d4",
29
+ "@veramo/did-provider-key": "^3.1.1-next.10+ef7797d4",
30
+ "@veramo/did-provider-web": "^3.1.1-next.10+ef7797d4",
31
+ "@veramo/did-resolver": "^3.1.1-next.10+ef7797d4",
32
+ "@veramo/key-manager": "^3.1.1-next.10+ef7797d4",
33
+ "@veramo/kms-local": "^3.1.1-next.10+ef7797d4",
34
+ "@veramo/message-handler": "^3.1.1-next.10+ef7797d4",
35
+ "@veramo/remote-client": "^3.1.1-next.10+ef7797d4",
36
+ "@veramo/remote-server": "^3.1.1-next.10+ef7797d4",
37
+ "@veramo/selective-disclosure": "^3.1.1-next.10+ef7797d4",
38
+ "@veramo/url-handler": "^3.1.1-next.10+ef7797d4",
39
39
  "blessed": "^0.1.81",
40
- "commander": "^7.0.0",
40
+ "commander": "^8.0.0",
41
41
  "console-table-printer": "^2.8.2",
42
42
  "cors": "^2.8.5",
43
43
  "cross-fetch": "^3.1.4",
44
44
  "date-fns": "^2.16.1",
45
45
  "debug": "^4.1.1",
46
- "did-resolver": "3.1.0",
46
+ "did-resolver": "3.1.3",
47
47
  "dotenv": "^10.0.0",
48
- "ethr-did-resolver": "4.3.4",
48
+ "ethr-did-resolver": "5.0.2",
49
49
  "express": "^4.17.1",
50
- "express-handlebars": "^5.2.0",
50
+ "express-handlebars": "^6.0.0",
51
51
  "fuzzy": "^0.1.3",
52
52
  "handlebars": "^4.7.6",
53
53
  "inquirer": "^8.0.0",
54
54
  "inquirer-autocomplete-prompt": "^1.2.0",
55
- "json-schema": "^0.3.0",
56
- "jsonpointer": "^4.1.0",
55
+ "json-schema": "^0.4.0",
56
+ "json5": "^2.2.0",
57
+ "jsonpointer": "^5.0.0",
57
58
  "oas-resolver": "^2.5.3",
58
- "openapi-types": "^9.0.0",
59
+ "openapi-types": "9.3.1",
59
60
  "passport": "^0.5.0",
60
61
  "passport-http-bearer": "^1.0.1",
61
62
  "pg": "^8.6.0",
62
63
  "qrcode-terminal": "^0.12.0",
63
64
  "sqlite3": "^5.0.0",
64
65
  "swagger-ui-express": "^4.1.5",
65
- "ts-json-schema-generator": "^0.95.0",
66
- "typeorm": "0.2.37",
66
+ "ts-json-schema-generator": "^0.97.0",
67
+ "typeorm": "0.2.41",
67
68
  "url-parse": "^1.5.1",
68
- "web-did-resolver": "2.0.4",
69
+ "web-did-resolver": "2.0.8",
69
70
  "ws": "^8.0.0",
70
71
  "yaml": "^1.10.0"
71
72
  },
72
73
  "devDependencies": {
73
74
  "@types/debug": "4.1.7",
74
- "@types/inquirer": "8.1.2",
75
+ "@types/inquirer": "8.1.3",
75
76
  "@types/node-fetch": "3.0.2",
76
77
  "@types/passport-http-bearer": "1.0.37",
77
78
  "@types/ws": "8.2.0",
78
- "typescript": "4.4.3"
79
+ "typescript": "4.5.2"
79
80
  },
80
81
  "files": [
81
82
  "bin/**/*",
@@ -99,5 +100,5 @@
99
100
  ],
100
101
  "license": "Apache-2.0",
101
102
  "keywords": [],
102
- "gitHead": "0ca9b448db8b467630a14bc64343082af29bc725"
103
+ "gitHead": "ef7797d4c5f20b22e4e39a5ad60a851fa1c4f2ed"
103
104
  }
package/src/cli.ts CHANGED
@@ -1,4 +1,4 @@
1
- import program from 'commander'
1
+ import { program } from 'commander'
2
2
  import inquirer from 'inquirer'
3
3
 
4
4
  inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt'))
package/src/config.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import 'cross-fetch/polyfill'
2
- import program from 'commander'
2
+ import { program } from 'commander'
3
3
  import { SecretBox } from '@veramo/kms-local'
4
+ import { getAgent, getConfig } from './setup'
4
5
  const fs = require('fs')
5
6
  const { dirname } = require('path')
6
7
 
@@ -38,12 +39,51 @@ config
38
39
 
39
40
  config
40
41
  .command('create-secret-key')
42
+ .alias('gen-key')
43
+ .alias('key-gen')
41
44
  .description('generate secret key')
42
- .action(async (raw) => {
45
+ .option('-q, --quiet', 'Only print the raw key, no instructions', false)
46
+ .action(async (options) => {
43
47
  try {
44
- const secretKey = await SecretBox.createSecretKey()
45
- console.log(secretKey)
48
+ const dbEncryptionKey = await SecretBox.createSecretKey()
49
+ if (options.quiet === true) {
50
+ console.log(dbEncryptionKey)
51
+ } else {
52
+ console.log(`
53
+ X25519 raw private key (hex encoded):
54
+
55
+ ${dbEncryptionKey}
56
+
57
+ You can use this key with @veramo/kms-local#SecretBox
58
+ or replace the default agent.yml 'dbEncryptionKey' constant
59
+ `)
60
+ }
46
61
  } catch (e: any) {
47
62
  console.error(e.message)
48
63
  }
49
64
  })
65
+
66
+ config
67
+ .command('check')
68
+ .alias('verify')
69
+ .description('Verify an agent config file syntax')
70
+ .option('-f, --filename <string>', 'Config file name', './agent.yml')
71
+ .option('-m, --method <string>', 'Check that a specific method is exposed by the agent.', 'execute')
72
+ .action(async (options) => {
73
+ const agent = getAgent(options.filename)
74
+ if (!agent) {
75
+ console.error(
76
+ 'unknown error while creating the agent from your config. Consider running `veramo config create` to generate a new configuration file, or to manually compare differences.',
77
+ )
78
+ } else {
79
+ if (typeof agent[options.method] !== 'function') {
80
+ console.error(
81
+ `The agent was created using the config, but the 'agent.${options.method}()' method is not available. Make sure the plugin that implements that method is installed.`,
82
+ )
83
+ } else {
84
+ console.log(
85
+ `Your Veramo configuration seems fine. An agent can be created and the 'agent.${options.method}()' method can be called on it.`,
86
+ )
87
+ }
88
+ }
89
+ })
package/src/credential.ts CHANGED
@@ -1,8 +1,11 @@
1
- import { W3CCredential } from '@veramo/core'
2
1
  import { getAgent } from './setup'
3
- import program from 'commander'
2
+ import { program } from 'commander'
4
3
  import inquirer from 'inquirer'
5
4
  import qrcode from 'qrcode-terminal'
5
+ import * as fs from 'fs'
6
+ import * as json5 from 'json5'
7
+ import { readStdin } from './util'
8
+ import { CredentialPayload } from '@veramo/core'
6
9
 
7
10
  const credential = program.command('credential').description('W3C Verifiable Credential')
8
11
 
@@ -10,6 +13,7 @@ credential
10
13
  .command('create', { isDefault: true })
11
14
  .description('Create W3C Verifiable Credential')
12
15
  .option('-s, --send', 'Send')
16
+ .option('-j, --json', 'Output in JSON')
13
17
  .option('-q, --qrcode', 'Show qrcode')
14
18
  .action(async (cmd) => {
15
19
  const agent = getAgent(program.opts().config)
@@ -19,6 +23,12 @@ credential
19
23
  process.exit()
20
24
  }
21
25
  const answers = await inquirer.prompt([
26
+ {
27
+ type: 'list',
28
+ name: 'proofFormat',
29
+ choices: ['jwt', 'lds'],
30
+ message: 'Credential proofFormat',
31
+ },
22
32
  {
23
33
  type: 'list',
24
34
  name: 'iss',
@@ -68,9 +78,9 @@ credential
68
78
  const type: string = answers.claimType
69
79
  credentialSubject[type] = answers.claimValue
70
80
 
71
- const credential: W3CCredential = {
81
+ const credential: CredentialPayload = {
72
82
  issuer: { id: answers.iss },
73
- '@context': ['https://www.w3.org/2018/credentials/v1'],
83
+ '@context': ['https://www.w3.org/2018/credentials/v1', 'https://veramo.io/contexts/profile/v1'],
74
84
  type: answers.type.split(','),
75
85
  issuanceDate: new Date().toISOString(),
76
86
  credentialSubject,
@@ -101,18 +111,27 @@ credential
101
111
  const verifiableCredential = await agent.createVerifiableCredential({
102
112
  save: true,
103
113
  credential,
104
- proofFormat: 'jwt',
114
+ proofFormat: answers.proofFormat,
105
115
  })
106
116
 
107
117
  if (cmd.send) {
118
+ let body
119
+ let type
120
+ if (answers.proofFormat == 'jwt') {
121
+ body = verifiableCredential.proof.jwt
122
+ type = 'jwt'
123
+ } else {
124
+ body = verifiableCredential
125
+ type = 'w3c.vc'
126
+ }
108
127
  try {
109
128
  const message = await agent.sendMessageDIDCommAlpha1({
110
129
  save: true,
111
130
  data: {
112
131
  from: answers.iss,
113
132
  to: answers.sub,
114
- type: 'jwt',
115
- body: verifiableCredential.proof.jwt,
133
+ type,
134
+ body,
116
135
  },
117
136
  })
118
137
  console.dir(message, { depth: 10 })
@@ -124,6 +143,48 @@ credential
124
143
  if (cmd.qrcode) {
125
144
  qrcode.generate(verifiableCredential.proof.jwt)
126
145
  } else {
127
- console.dir(verifiableCredential, { depth: 10 })
146
+ if (cmd.json) {
147
+ console.log(JSON.stringify(verifiableCredential, null, 2))
148
+ } else {
149
+ console.dir(verifiableCredential, { depth: 10 })
150
+ }
151
+ }
152
+ })
153
+
154
+ credential
155
+ .command('verify')
156
+ .description('Verify a W3C Verifiable Credential provided as raw string, file or stdin')
157
+ .option('-f, --filename <string>', 'Optional. Read the credential from a file instead of stdin')
158
+ .option('-r, --raw <string>', 'Optional. Specify the credential as a parameter instead of file or stdin')
159
+ .action(async (options) => {
160
+ const agent = getAgent(program.opts().config)
161
+ let raw: string = ''
162
+ if (options.raw) {
163
+ raw = options.raw
164
+ } else if (options.filename) {
165
+ raw = await fs.promises.readFile(options.filename, 'utf-8')
166
+ } else {
167
+ raw = await readStdin()
168
+ }
169
+ let credentialAsJSON: any
170
+ try {
171
+ credentialAsJSON = json5.parse(raw)
172
+ } catch (e: any) {
173
+ credentialAsJSON = {
174
+ proof: {
175
+ type: 'JwtProof2020',
176
+ jwt: raw,
177
+ },
178
+ } as any
179
+ }
180
+ try {
181
+ const result = await agent.verifyCredential({ credential: credentialAsJSON })
182
+ if (result === true) {
183
+ console.log('Credential was verified successfully.')
184
+ } else {
185
+ console.error('Credential could not be verified.')
186
+ }
187
+ } catch (e) {
188
+ console.error(e.message)
128
189
  }
129
190
  })
package/src/dev.ts CHANGED
@@ -1,21 +1,16 @@
1
- import { getAgent } from './setup'
2
- import program from 'commander'
3
- const fs = require('fs')
4
- import { resolve, dirname } from 'path'
5
- import { writeFileSync, readFileSync } from 'fs'
6
- import * as TJS from 'ts-json-schema-generator'
7
- import { JSONSchema7 } from 'json-schema'
8
- import { OpenAPIV3 } from 'openapi-types'
9
1
  import { Extractor, ExtractorConfig, ExtractorResult } from '@microsoft/api-extractor'
10
2
  import {
3
+ ApiMethodSignature,
11
4
  ApiModel,
12
- ApiPackage,
13
5
  ApiParameterListMixin,
14
- ApiDocumentedItem,
15
6
  ApiReturnTypeMixin,
16
- ApiMethodSignature,
17
7
  } from '@microsoft/api-extractor-model'
18
- import { IIdentifier } from '@veramo/core'
8
+ import { program } from 'commander'
9
+ import { writeFileSync } from 'fs'
10
+ import { OpenAPIV3 } from 'openapi-types'
11
+ import { resolve } from 'path'
12
+ import * as TJS from 'ts-json-schema-generator'
13
+ const fs = require('fs')
19
14
 
20
15
  interface Method {
21
16
  packageName: string
@@ -50,6 +45,7 @@ function createSchema(generator: TJS.SchemaGenerator, symbol: string) {
50
45
  schemaStr = schemaStr.replace(/Where\<(.*)\>/gm, 'Where-$1')
51
46
  schemaStr = schemaStr.replace(/Order\<(.*)\>/gm, 'Order-$1')
52
47
  schemaStr = schemaStr.replace(/FindArgs\<(.*)\>/gm, 'FindArgs-$1')
48
+ schemaStr = schemaStr.replace(/https \:\/\//gm, 'https://')
53
49
  return JSON.parse(schemaStr)
54
50
  }
55
51
 
package/src/did.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { IDIDManagerCreateArgs } from '@veramo/core'
2
2
  import { getAgent } from './setup'
3
3
  import inquirer from 'inquirer'
4
- import program from 'commander'
4
+ import { program } from 'commander'
5
5
  import { printTable } from 'console-table-printer'
6
6
 
7
7
  const did = program.command('did').description('Decentralized identifiers')
package/src/discover.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { getAgent } from './setup'
2
- import program from 'commander'
2
+ import { program } from 'commander'
3
3
  import { printTable } from 'console-table-printer'
4
4
 
5
5
  const discover = program.command('discover').description('Discovery')
package/src/execute.ts CHANGED
@@ -1,7 +1,5 @@
1
- import { input } from 'blessed'
2
- import program from 'commander'
1
+ import { program } from 'commander'
3
2
  import inquirer from 'inquirer'
4
- import jsonpointer from 'jsonpointer'
5
3
  import { getAgent } from './setup'
6
4
  const fs = require('fs')
7
5
  const OasResolver = require('oas-resolver')
@@ -3,6 +3,7 @@ import { UniqueVerifiableCredential } from '@veramo/data-store'
3
3
  import { shortDate, shortDid } from './utils'
4
4
  import { ConfiguredAgent } from '../setup'
5
5
  import { styles } from './styles'
6
+ import { asArray, extractIssuer } from '@veramo/utils'
6
7
 
7
8
  export const getCredentialsTable = async (agent: ConfiguredAgent, screen: Widgets.Screen) => {
8
9
  screen.title = 'Credentials'
@@ -25,8 +26,8 @@ export const getCredentialsTable = async (agent: ConfiguredAgent, screen: Widget
25
26
  [['Created', 'Type', 'From', 'To']].concat(
26
27
  credentials.map(({ verifiableCredential: m }) => [
27
28
  shortDate(m.issuanceDate),
28
- m.type.join(','),
29
- shortDid(m.issuer.id),
29
+ asArray(m.type || []).join(','),
30
+ shortDid(extractIssuer(m)),
30
31
  shortDid(m.credentialSubject.id),
31
32
  ]),
32
33
  ),
@@ -1,5 +1,5 @@
1
1
  import { getAgent } from '../setup'
2
- import program from 'commander'
2
+ import { program } from 'commander'
3
3
  import { renderMainScreen } from './main'
4
4
 
5
5
  program
@@ -1,9 +1,9 @@
1
1
  import blessed, { Widgets } from 'blessed'
2
- import { VerifiablePresentation } from '@veramo/core'
3
2
  import { UniqueVerifiablePresentation } from '@veramo/data-store'
4
3
  import { shortDate, shortDid } from './utils'
5
4
  import { ConfiguredAgent } from '../setup'
6
5
  import { styles } from './styles'
6
+ import { asArray } from '@veramo/utils'
7
7
 
8
8
  export const getPresentationsTable = async (agent: ConfiguredAgent, screen: Widgets.Screen) => {
9
9
  screen.title = 'Presentations'
@@ -26,9 +26,9 @@ export const getPresentationsTable = async (agent: ConfiguredAgent, screen: Widg
26
26
  [['Created', 'Type', 'Holder', 'Verifier']].concat(
27
27
  presentations.map(({ verifiablePresentation: m }) => [
28
28
  shortDate(m.issuanceDate),
29
- m.type.join(','),
29
+ asArray(m.type || []).join(','),
30
30
  shortDid(m.holder),
31
- shortDid(m.verifier.join(',')),
31
+ shortDid(asArray(m.verifier || []).join(',')),
32
32
  ]),
33
33
  ),
34
34
  )
package/src/message.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { getAgent } from './setup'
2
- import program from 'commander'
2
+ import { program } from 'commander'
3
3
  const fs = require('fs')
4
4
 
5
5
  const message = program.command('message').description('Messages')
@@ -1,8 +1,11 @@
1
- import { W3CCredential } from '@veramo/core'
2
1
  import { getAgent } from './setup'
3
- import program from 'commander'
2
+ import { program } from 'commander'
4
3
  import inquirer from 'inquirer'
5
4
  import qrcode from 'qrcode-terminal'
5
+ import { readStdin } from './util'
6
+ import * as fs from 'fs'
7
+ import * as json5 from 'json5'
8
+ import { extractIssuer } from '@veramo/utils'
6
9
 
7
10
  const presentation = program.command('presentation').description('W3C Verifiable Presentation')
8
11
 
@@ -85,7 +88,7 @@ presentation
85
88
  name:
86
89
  JSON.stringify(credential.verifiableCredential.credentialSubject) +
87
90
  ' | Issuer: ' +
88
- credential.verifiableCredential.issuer.id,
91
+ extractIssuer(credential.verifiableCredential),
89
92
  value: credential.verifiableCredential,
90
93
  })
91
94
  }
@@ -153,3 +156,43 @@ presentation
153
156
  }
154
157
  }
155
158
  })
159
+
160
+ presentation
161
+ .command('verify')
162
+ .description('Verify a W3C Verifiable Presentation provided as a string param or a file or from stdin')
163
+ .option('-c, --challenge <string>', 'Optional. Specify a challenge that the presentation should match.')
164
+ .option('-d, --domain <string>', 'Optional. Specify a domain that the presentation should match.')
165
+ .option('-f, --filename <string>', 'Optional. Read the presentation from a file instead of stdin')
166
+ .option('-r, --raw <string>', 'Optional. Presentation as a parameter string instead of a file or stdin.')
167
+ .action(async (options) => {
168
+ const agent = getAgent(program.opts().config)
169
+ let raw: string = ''
170
+ if (options.raw) {
171
+ raw = options.raw
172
+ } else if (options.filename) {
173
+ raw = await fs.promises.readFile(options.filename, 'utf-8')
174
+ } else {
175
+ raw = await readStdin()
176
+ }
177
+ let presentationAsJSON: any
178
+ try {
179
+ presentationAsJSON = json5.parse(raw)
180
+ } catch (e: any) {
181
+ presentationAsJSON = {
182
+ proof: {
183
+ type: 'JwtProof2020',
184
+ jwt: raw,
185
+ },
186
+ } as any
187
+ }
188
+ const result = await agent.verifyPresentation({
189
+ presentation: presentationAsJSON,
190
+ challenge: options.challenge,
191
+ domain: options.domain,
192
+ })
193
+ if (result === true) {
194
+ console.log('Presentation was verified successfully.')
195
+ } else {
196
+ console.error('Presentation could not be verified.')
197
+ }
198
+ })
package/src/sdr.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  import { ICredentialRequestInput } from '@veramo/selective-disclosure'
2
2
  import { getAgent } from './setup'
3
- import program from 'commander'
3
+ import { program } from 'commander'
4
4
  import inquirer from 'inquirer'
5
5
  import qrcode from 'qrcode-terminal'
6
6
  import { shortDate, shortDid } from './explore/utils'
7
7
  import { VerifiableCredential } from '@veramo/core'
8
+ import { asArray, extractIssuer } from '@veramo/utils'
9
+
8
10
  const fuzzy = require('fuzzy')
9
11
 
10
12
  const sdr = program.command('sdr').description('Selective Disclosure Request')
@@ -173,7 +175,7 @@ sdr
173
175
  name:
174
176
  JSON.stringify(credential.verifiableCredential.credentialSubject) +
175
177
  ' | Issuer: ' +
176
- credential.verifiableCredential.issuer.id,
178
+ extractIssuer(credential.verifiableCredential),
177
179
  value: credential.verifiableCredential.proof.jwt,
178
180
  })
179
181
  }
@@ -305,9 +307,9 @@ sdr
305
307
  name:
306
308
  c.verifiableCredential.credentialSubject[item.claimType] +
307
309
  ' (' +
308
- c.verifiableCredential.type.join(',') +
310
+ asArray(c.verifiableCredential.type || []).join(',') +
309
311
  ') issued by: ' +
310
- c.verifiableCredential.issuer.id +
312
+ extractIssuer(c.verifiableCredential) +
311
313
  ' ' +
312
314
  shortDate(c.verifiableCredential.issuanceDate) +
313
315
  ' ago',
package/src/server.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import express from 'express'
2
- import program from 'commander'
2
+ import { program } from 'commander'
3
3
  import { getConfig } from './setup'
4
4
  import { createObjects } from './lib/objectCreator'
5
5
 
package/src/setup.ts CHANGED
@@ -17,7 +17,7 @@ export const getConfig = (fileName: string): any => {
17
17
  process.exit(1)
18
18
  }
19
19
 
20
- const config = yaml.parse(fs.readFileSync(fileName).toString())
20
+ const config = yaml.parse(fs.readFileSync(fileName).toString(), { prettyErrors: true })
21
21
 
22
22
  if (config?.version != 3) {
23
23
  console.log('Unsupported configuration file version:', config.version)
package/src/util.ts ADDED
@@ -0,0 +1,23 @@
1
+ export async function readStdin(): Promise<string> {
2
+ return new Promise((resolve, reject) => {
3
+ let data = ''
4
+ process.stdin.setEncoding('utf-8')
5
+
6
+ process.stdin.on('readable', () => {
7
+ let chunk: string
8
+ while ((chunk = process.stdin.read())) {
9
+ data += chunk
10
+ }
11
+ })
12
+
13
+ process.stdin.on('end', () => {
14
+ // There will be a trailing \n from the user hitting enter. Get rid of it.
15
+ data = data.replace(/\n$/, '')
16
+ resolve(data)
17
+ })
18
+
19
+ process.stdin.on('error', (error) => {
20
+ reject(error)
21
+ })
22
+ })
23
+ }
package/src/version.ts CHANGED
@@ -1,4 +1,4 @@
1
- import program from 'commander'
1
+ import { program } from 'commander'
2
2
 
3
3
  const { version } = require('../package.json')
4
4