@veramo/credential-ld 6.0.1-next.9 → 6.0.1

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 (55) hide show
  1. package/build/action-handler.d.ts +461 -0
  2. package/build/action-handler.d.ts.map +1 -0
  3. package/build/{CredentialProviderLD.js → action-handler.js} +25 -38
  4. package/build/action-handler.js.map +1 -0
  5. package/build/index.d.ts +4 -3
  6. package/build/index.d.ts.map +1 -1
  7. package/build/index.js +4 -3
  8. package/build/index.js.map +1 -1
  9. package/build/ld-credential-module.d.ts +4 -4
  10. package/build/ld-credential-module.d.ts.map +1 -1
  11. package/build/ld-credential-module.js.map +1 -1
  12. package/build/ld-default-contexts.d.ts +1 -1
  13. package/build/ld-default-contexts.js +1 -1
  14. package/build/ld-suites.d.ts +0 -1
  15. package/build/ld-suites.d.ts.map +1 -1
  16. package/build/ld-suites.js.map +1 -1
  17. package/build/plugin.schema.d.ts +430 -0
  18. package/build/plugin.schema.d.ts.map +1 -0
  19. package/build/plugin.schema.js +477 -0
  20. package/build/plugin.schema.js.map +1 -0
  21. package/build/suites/EcdsaSecp256k1RecoverySignature2020.d.ts +0 -1
  22. package/build/suites/EcdsaSecp256k1RecoverySignature2020.d.ts.map +1 -1
  23. package/build/suites/EcdsaSecp256k1RecoverySignature2020.js +0 -3
  24. package/build/suites/EcdsaSecp256k1RecoverySignature2020.js.map +1 -1
  25. package/build/suites/Ed25519Signature2018.d.ts +0 -1
  26. package/build/suites/Ed25519Signature2018.d.ts.map +1 -1
  27. package/build/suites/Ed25519Signature2018.js +0 -3
  28. package/build/suites/Ed25519Signature2018.js.map +1 -1
  29. package/build/suites/Ed25519Signature2020.d.ts +0 -1
  30. package/build/suites/Ed25519Signature2020.d.ts.map +1 -1
  31. package/build/suites/Ed25519Signature2020.js +0 -3
  32. package/build/suites/Ed25519Signature2020.js.map +1 -1
  33. package/build/suites/JsonWebSignature2020.d.ts +0 -1
  34. package/build/suites/JsonWebSignature2020.d.ts.map +1 -1
  35. package/build/suites/JsonWebSignature2020.js +0 -3
  36. package/build/suites/JsonWebSignature2020.js.map +1 -1
  37. package/build/types.d.ts +220 -0
  38. package/build/types.d.ts.map +1 -1
  39. package/package.json +10 -6
  40. package/src/__tests__/issue-verify-ed25519-2020.test.ts +122 -122
  41. package/src/__tests__/{issue-verify-flow-ld.test.ts → issue-verify-flow.test.ts} +6 -7
  42. package/src/{CredentialProviderLD.ts → action-handler.ts} +40 -61
  43. package/src/index.ts +4 -3
  44. package/src/ld-credential-module.ts +3 -4
  45. package/src/ld-default-contexts.ts +1 -1
  46. package/src/ld-suites.ts +0 -2
  47. package/src/plugin.schema.ts +476 -0
  48. package/src/suites/EcdsaSecp256k1RecoverySignature2020.ts +1 -6
  49. package/src/suites/Ed25519Signature2018.ts +0 -5
  50. package/src/suites/Ed25519Signature2020.ts +1 -5
  51. package/src/suites/JsonWebSignature2020.ts +1 -5
  52. package/src/types.ts +265 -0
  53. package/build/CredentialProviderLD.d.ts +0 -42
  54. package/build/CredentialProviderLD.d.ts.map +0 -1
  55. package/build/CredentialProviderLD.js.map +0 -1
@@ -2,23 +2,15 @@ import {
2
2
  CredentialPayload,
3
3
  IAgentContext,
4
4
  IAgentPlugin,
5
- ICanIssueCredentialTypeArgs,
6
- ICreateVerifiableCredentialArgs,
7
- ICreateVerifiablePresentationArgs,
8
5
  IIdentifier,
9
6
  IKey,
10
7
  IResolver,
11
- IssuerAgentContext,
12
- IVerifyCredentialArgs,
13
- IVerifyPresentationArgs,
14
- IVerifyResult,
15
8
  PresentationPayload,
16
9
  VerifiableCredential,
17
10
  VerifiablePresentation,
18
- VerifierAgentContext,
19
- ICanVerifyDocumentTypeArgs,
20
11
  } from '@veramo/core-types'
21
12
  import { VeramoLdSignature } from './index.js'
13
+ import { schema } from './plugin.schema.js'
22
14
  import Debug from 'debug'
23
15
  import { LdContextLoader } from './ld-context-loader.js'
24
16
  import {
@@ -38,19 +30,25 @@ import { LdCredentialModule } from './ld-credential-module.js'
38
30
  import { LdSuiteLoader } from './ld-suite-loader.js'
39
31
  import {
40
32
  ContextDoc,
33
+ ICreateVerifiableCredentialLDArgs,
34
+ ICreateVerifiablePresentationLDArgs,
35
+ ICredentialIssuerLD,
36
+ IRequiredContext,
37
+ IVerifyCredentialLDArgs,
38
+ IVerifyPresentationLDArgs,
41
39
  } from './types.js'
42
40
  import { DIDResolutionOptions } from 'did-resolver'
43
41
 
44
- import { AbstractCredentialProvider } from '@veramo/credential-w3c'
45
-
46
42
  const debug = Debug('veramo:credential-ld:action-handler')
47
43
 
48
44
  /**
49
- * A handler that implements the {@link AbstractCredentialProvider} methods.
45
+ * A Veramo plugin that implements the {@link ICredentialIssuerLD} methods.
50
46
  *
51
47
  * @public
52
48
  */
53
- export class CredentialProviderLD implements AbstractCredentialProvider {
49
+ export class CredentialIssuerLD implements IAgentPlugin {
50
+ readonly methods: ICredentialIssuerLD
51
+ readonly schema = schema.ICredentialIssuerLD
54
52
 
55
53
  private ldCredentialModule: LdCredentialModule
56
54
 
@@ -59,40 +57,20 @@ export class CredentialProviderLD implements AbstractCredentialProvider {
59
57
  ldContextLoader: new LdContextLoader({ contextsPaths: options.contextMaps }),
60
58
  ldSuiteLoader: new LdSuiteLoader({ veramoLdSignatures: options.suites }),
61
59
  })
62
- }
63
-
64
- /** {@inheritdoc @veramo/credential-w3c#AbstractCredentialProvider.matchKeyForType} */
65
- matchKeyForType(key: IKey): boolean {
66
- return this.matchKeyForLDSuite(key)
67
- }
68
-
69
- /** {@inheritdoc @veramo/credential-w3c#AbstractCredentialProvider.getTypeProofFormat} */
70
- getTypeProofFormat(): string {
71
- return 'lds'
72
- }
73
-
74
- /** {@inheritdoc @veramo/credential-w3c#AbstractCredentialProvider.canIssueCredentialType} */
75
- canIssueCredentialType(args: ICanIssueCredentialTypeArgs): boolean {
76
- return (args.proofFormat === 'lds')
77
- }
78
60
 
79
- /** {@inheritdoc @veramo/credential-w3c#AbstractCredentialProvider.canVerifyDocumentType */
80
- canVerifyDocumentType(args: ICanVerifyDocumentTypeArgs): boolean {
81
- const { document } = args
82
-
83
- for (const suite of this.ldCredentialModule.ldSuiteLoader.getAllSignatureSuites()) {
84
- if (suite.getSupportedProofType() === (<VerifiableCredential>document)?.proof?.type || '') {
85
- return true
86
- }
61
+ this.methods = {
62
+ createVerifiablePresentationLD: this.createVerifiablePresentationLD.bind(this),
63
+ createVerifiableCredentialLD: this.createVerifiableCredentialLD.bind(this),
64
+ verifyCredentialLD: this.verifyCredentialLD.bind(this),
65
+ verifyPresentationLD: this.verifyPresentationLD.bind(this),
66
+ matchKeyForLDSuite: this.matchKeyForLDSuite.bind(this),
87
67
  }
88
-
89
- return false
90
68
  }
91
69
 
92
- /** {@inheritdoc ICredentialIssuer.createVerifiablePresentationLD} */
93
- async createVerifiablePresentation(
94
- args: ICreateVerifiablePresentationArgs,
95
- context: IssuerAgentContext,
70
+ /** {@inheritdoc ICredentialIssuerLD.createVerifiablePresentationLD} */
71
+ public async createVerifiablePresentationLD(
72
+ args: ICreateVerifiablePresentationLDArgs,
73
+ context: IRequiredContext,
96
74
  ): Promise<VerifiablePresentation> {
97
75
  const presentationContext = processEntryToArray(
98
76
  args?.presentation?.['@context'],
@@ -161,10 +139,10 @@ export class CredentialProviderLD implements AbstractCredentialProvider {
161
139
  }
162
140
  }
163
141
 
164
- /** {@inheritdoc ICredentialIssuer.createVerifiableCredentialLD} */
165
- async createVerifiableCredential(
166
- args: ICreateVerifiableCredentialArgs,
167
- context: IssuerAgentContext,
142
+ /** {@inheritdoc ICredentialIssuerLD.createVerifiableCredentialLD} */
143
+ public async createVerifiableCredentialLD(
144
+ args: ICreateVerifiableCredentialLDArgs,
145
+ context: IRequiredContext,
168
146
  ): Promise<VerifiableCredential> {
169
147
  const credentialContext = processEntryToArray(
170
148
  args?.credential?.['@context'],
@@ -215,26 +193,27 @@ export class CredentialProviderLD implements AbstractCredentialProvider {
215
193
  }
216
194
  }
217
195
 
218
- /** {@inheritdoc ICredentialIssuer.verifyCredentialLD} */
219
- async verifyCredential(args: IVerifyCredentialArgs, context: VerifierAgentContext): Promise<IVerifyResult> {
220
- args.credential = args.credential as VerifiableCredential
196
+ /** {@inheritdoc ICredentialIssuerLD.verifyCredentialLD} */
197
+ public async verifyCredentialLD(
198
+ args: IVerifyCredentialLDArgs,
199
+ context: IRequiredContext,
200
+ ): Promise<boolean> {
221
201
  const credential = args.credential
222
202
 
223
- let now = new Date()
224
-
225
- if (args.policies?.now && typeof args.policies?.now === 'number') {
226
- now = new Date(args.policies?.now * 1000)
203
+ let { now } = args
204
+ if (typeof now === 'number') {
205
+ now = new Date(now * 1000)
227
206
  }
228
207
 
229
208
  return this.ldCredentialModule.verifyCredential(credential, { ...args, now }, context)
230
209
  }
231
210
 
232
- /** {@inheritdoc ICredentialVerifier.verifyPresentation} */
233
- async verifyPresentation(
234
- args: IVerifyPresentationArgs,
235
- context: VerifierAgentContext,
236
- ): Promise<IVerifyResult> {
237
- const presentation = args.presentation as VerifiablePresentation
211
+ /** {@inheritdoc ICredentialIssuerLD.verifyPresentationLD} */
212
+ public async verifyPresentationLD(
213
+ args: IVerifyPresentationLDArgs,
214
+ context: IRequiredContext,
215
+ ): Promise<boolean> {
216
+ const presentation = args.presentation
238
217
  let { now } = args
239
218
  if (typeof now === 'number') {
240
219
  now = new Date(now * 1000)
@@ -292,7 +271,7 @@ export class CredentialProviderLD implements AbstractCredentialProvider {
292
271
  *
293
272
  * @internal
294
273
  */
295
- matchKeyForLDSuite(k: IKey): boolean {
274
+ async matchKeyForLDSuite(k: IKey): Promise<boolean> {
296
275
  // prefilter based on key algorithms
297
276
  switch (k.type) {
298
277
  case 'Ed25519':
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Provides a {@link @veramo/credential-ld#CredentialProviderLD | handler} for the {@link @veramo/credential-w3c#CredentialPlugin} that
2
+ * Provides a {@link @veramo/credential-ld#CredentialIssuerLD | plugin} for the {@link @veramo/core#Agent} that
3
3
  * implements
4
- * {@link @veramo/core-types#AbstractCredentialProvider} interface.
4
+ * {@link @veramo/credential-ld#ICredentialIssuerLD} interface.
5
5
  *
6
6
  * This plugin adds support for working with JSON-LD credentials.
7
7
  * When installed, this plugin will be automatically used by
@@ -10,7 +10,7 @@
10
10
  *
11
11
  * @packageDocumentation
12
12
  */
13
- export { CredentialProviderLD } from './CredentialProviderLD.js'
13
+ export { CredentialIssuerLD } from './action-handler.js'
14
14
  export * from './types.js'
15
15
  export { LdDefaultContexts } from './ld-default-contexts.js'
16
16
  export { VeramoLdSignature } from './ld-suites.js'
@@ -18,3 +18,4 @@ export * from './suites/EcdsaSecp256k1RecoverySignature2020.js'
18
18
  export * from './suites/Ed25519Signature2018.js'
19
19
  export * from './suites/Ed25519Signature2020.js'
20
20
  export * from './suites/JsonWebSignature2020.js'
21
+ export { schema } from './plugin.schema.js'
@@ -3,7 +3,6 @@ import {
3
3
  IAgentContext,
4
4
  IKey,
5
5
  IResolver,
6
- IVerifyResult,
7
6
  PresentationPayload,
8
7
  UsingResolutionOptions,
9
8
  VerifiableCredential,
@@ -23,7 +22,7 @@ const debug = Debug('veramo:w3c:ld-credential-module')
23
22
 
24
23
  type ForwardedOptions = UsingResolutionOptions & {
25
24
  fetchRemoteContexts?: boolean // defaults to false
26
- now?: Date // defaults to Date.now()
25
+ now?: number // defaults to Date.now()
27
26
  }
28
27
 
29
28
  export class LdCredentialModule {
@@ -171,7 +170,7 @@ export class LdCredentialModule {
171
170
  credential: VerifiableCredential,
172
171
  options: ForwardedOptions,
173
172
  context: IAgentContext<IResolver>,
174
- ): Promise<IVerifyResult> {
173
+ ): Promise<boolean> {
175
174
  const fetchRemoteContexts = options.fetchRemoteContexts ?? false
176
175
  const result = await vc.verifyCredential({
177
176
  ...options,
@@ -196,7 +195,7 @@ export class LdCredentialModule {
196
195
  domain: string | undefined,
197
196
  options: ForwardedOptions,
198
197
  context: IAgentContext<IResolver>,
199
- ): Promise<IVerifyResult> {
198
+ ): Promise<boolean> {
200
199
  const fetchRemoteContexts = options.fetchRemoteContexts ?? false
201
200
  const result = await vc.verify({
202
201
  ...options,
@@ -20,7 +20,7 @@ import schema_org from './contexts/schema.org.json' assert { type: 'json' }
20
20
  * Provides a hardcoded map of common Linked Data `@context` definitions.
21
21
  *
22
22
  * You can use this to bootstrap the `@context` definitions used by
23
- * {@link @veramo/credential-ld#CredentialProviderLD | CredentialProviderLD} with these common context definitions.
23
+ * {@link @veramo/credential-ld#CredentialIssuerLD | CredentialIssuerLD} with these common context definitions.
24
24
  *
25
25
  * @beta This API may change without a BREAKING CHANGE notice.
26
26
  */
package/src/ld-suites.ts CHANGED
@@ -25,8 +25,6 @@ export abstract class VeramoLdSignature {
25
25
 
26
26
  abstract getSupportedVerificationType(): string | string[]
27
27
 
28
- abstract getSupportedProofType(): string
29
-
30
28
  abstract getSupportedVeramoKeyType(): TKeyType
31
29
 
32
30
  abstract getSuiteForSigning(