@sphereon/ssi-sdk.credential-vcdm 0.33.1-feature.jose.vcdm.55

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/src/types.ts ADDED
@@ -0,0 +1,546 @@
1
+ import type {
2
+ CredentialPayload,
3
+ IAgentContext,
4
+ IDIDManager,
5
+ IKey,
6
+ IResolver,
7
+ IVerifyResult,
8
+ PresentationPayload,
9
+ VerifiableCredential,
10
+ VerifiablePresentation, VerificationPolicies,
11
+ } from '@veramo/core'
12
+
13
+ import type { VerifiableCredentialSP, VerifiablePresentationSP } from '@sphereon/ssi-sdk.core'
14
+ import type { ISphereonKeyManager } from '@sphereon/ssi-sdk-ext.key-manager'
15
+ import type { IIssueCredentialStatusOpts } from '@sphereon/ssi-sdk.vc-status-list'
16
+ import type { IPluginMethodMap } from '@veramo/core'
17
+ import { W3CVerifiableCredential, W3CVerifiablePresentation } from '@sphereon/ssi-types'
18
+
19
+ export type IVcdmCredentialPlugin = IVcdmCredentialIssuer & IVcdmCredentialVerifier
20
+
21
+
22
+ /**
23
+ * Encapsulates the parameters required to check if a credential type can be issued
24
+ *
25
+ * @public
26
+ */
27
+ export interface ICanIssueCredentialTypeArgs {
28
+ proofFormat: string
29
+ }
30
+
31
+ /**
32
+ * Encapsulates the parameters required to check if a document can be verified
33
+ *
34
+ * @public
35
+ */
36
+ export interface ICanVerifyDocumentTypeArgs {
37
+ /**
38
+ * The document to check against the verifier
39
+ */
40
+ document: W3CVerifiableCredential | W3CVerifiablePresentation
41
+ }
42
+
43
+
44
+ /**
45
+ * Encapsulates the parameters required to create a
46
+ * {@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation}
47
+ *
48
+ * @beta This API is likely to change without a BREAKING CHANGE notice
49
+ */
50
+ export interface ICreateVerifiablePresentationLDArgs {
51
+ /**
52
+ * The json payload of the Presentation according to the
53
+ * {@link https://www.w3.org/TR/vc-data-model/#presentations | canonical model}.
54
+ *
55
+ * The signer of the Presentation is chosen based on the `holderDID` property
56
+ * of the `presentation`
57
+ *
58
+ * '@context', 'type' and 'issuanceDate' will be added automatically if omitted
59
+ */
60
+ presentation: PresentationPayload
61
+
62
+ /**
63
+ * Optional (only JWT) string challenge parameter to add to the verifiable presentation.
64
+ */
65
+ challenge?: string
66
+
67
+ /**
68
+ * Optional string domain parameter to add to the verifiable presentation.
69
+ */
70
+ domain?: string
71
+
72
+ purpose?: IAuthenticationProofPurpose | IControllerProofPurpose | IAssertionProofPurpose | IProofPurpose
73
+
74
+ /**
75
+ * The desired format for the VerifiableCredential to be created.
76
+ */
77
+ proofFormat: string
78
+
79
+ /**
80
+ * Remove payload members during JWT-JSON transformation. Defaults to `true`.
81
+ * See https://www.w3.org/TR/vc-data-model/#jwt-encoding
82
+ */
83
+ removeOriginalFields?: boolean
84
+
85
+ /**
86
+ * [Optional] The ID of the key that should sign this presentation.
87
+ * If this is not specified, the first matching key will be used.
88
+ */
89
+ keyRef?: string
90
+
91
+ /**
92
+ * When dealing with JSON-LD you also MUST provide the proper contexts.
93
+ * Set this to `true` ONLY if you want the `@context` URLs to be fetched in case they are not preloaded.
94
+ * The context definitions SHOULD rather be provided at startup instead of being fetched.
95
+ *
96
+ * Defaults to `false`
97
+ */
98
+ fetchRemoteContexts?: boolean
99
+
100
+ /**
101
+ * Optional date to use for the `issuanceDate` or `validFrom` property depending on VCDM version being used.
102
+ * If not specified, the current date will be used.
103
+ *
104
+ */
105
+ now?: Date | number
106
+ }
107
+
108
+ /**
109
+ * Encapsulates the parameters required to create a
110
+ * {@link https://www.w3.org/TR/vc-data-model/#credentials | W3C Verifiable Credential}
111
+ *
112
+ * @beta This API is likely to change without a BREAKING CHANGE notice
113
+ */
114
+ export interface ICreateVerifiableCredentialLDArgs {
115
+ /**
116
+ * The JSON payload of the Credential according to the
117
+ * {@link https://www.w3.org/TR/vc-data-model/#credentials | canonical model}
118
+ *
119
+ * The signer of the Credential is chosen based on the `issuer.id` property
120
+ * of the `credential`
121
+ *
122
+ * `@context`, `type` and `issuanceDate` will be added automatically if omitted
123
+ */
124
+ credential: CredentialPayload
125
+
126
+ /**
127
+ * Optional date to use for the `issuanceDate` or `validFrom` property depending on VCDM version being used.
128
+ * If not specified, the current date will be used.
129
+ *
130
+ */
131
+ now?: Date | number
132
+
133
+ /**
134
+ * The desired format for the VerifiableCredential to be created.
135
+ */
136
+ proofFormat: string
137
+
138
+ /**
139
+ * Remove payload members during JWT-JSON transformation. Defaults to `true`.
140
+ * See https://www.w3.org/TR/vc-data-model/#jwt-encoding
141
+ */
142
+ removeOriginalFields?: boolean
143
+
144
+ /**
145
+ * [Optional] The ID of the key that should sign this credential.
146
+ * If this is not specified, the first matching key will be used.
147
+ */
148
+ keyRef?: string
149
+
150
+ /**
151
+ * When dealing with JSON-LD you also MUST provide the proper contexts.
152
+ * Set this to `true` ONLY if you want the `@context` URLs to be fetched in case they are not preloaded.
153
+ * The context definitions SHOULD rather be provided at startup instead of being fetched.
154
+ *
155
+ * Defaults to `false`
156
+ */
157
+ fetchRemoteContexts?: boolean
158
+
159
+ /**
160
+ * Use this purpose for the verification method in the DID when doing a check (defaults to CredentialIssuancePurpose)
161
+ */
162
+ purpose?: IAuthenticationProofPurpose | IControllerProofPurpose | IAssertionProofPurpose | IProofPurpose
163
+
164
+ credentialStatusOpts?: IIssueCredentialStatusOpts
165
+ }
166
+
167
+ /**
168
+ * Encapsulates the parameters required to verify a
169
+ * {@link https://www.w3.org/TR/vc-data-model/#credentials | W3C Verifiable Credential}
170
+ *
171
+ * @beta This API is likely to change without a BREAKING CHANGE notice
172
+ */
173
+ export interface IVerifyCredentialLDArgs {
174
+ /**
175
+ * The json payload of the Credential according to the
176
+ * {@link https://www.w3.org/TR/vc-data-model/#credentials | canonical model}
177
+ *
178
+ * The signer of the Credential is chosen based on the `issuer.id` property
179
+ * of the `credential`
180
+ *
181
+ */
182
+ credential: VerifiableCredential
183
+
184
+ /**
185
+ * Set this to true if you want the '@context' URLs to be fetched in case they are not pre-loaded.
186
+ *
187
+ * @default false
188
+ */
189
+ fetchRemoteContexts?: boolean
190
+
191
+ /**
192
+ * Overrides specific aspects of credential verification, where possible.
193
+ */
194
+ policies?: VerificationPolicies
195
+
196
+ /**
197
+ * Use this presentation purpose for the verification method in the DID when doing a check (defaults to CredentialIssuancePurpose)
198
+ */
199
+ purpose?: IAuthenticationProofPurpose | IControllerProofPurpose | IAssertionProofPurpose | IProofPurpose
200
+
201
+ /**
202
+ * Check status function, to check verifiableCredentials that have a credentialStatus property
203
+ */
204
+ checkStatus?: Function
205
+
206
+ /**
207
+ * Allows you to use the default integrated statusList 2021 support. If a checkStatus function is provided, this will be ignored
208
+ */
209
+ statusList?: StatusListCheck
210
+ }
211
+
212
+ export interface StatusListCheck {
213
+ /**
214
+ * If no checkStatus function is given we default to a StatusList2021 check in case the VC has a credentialStatus. This boolean allows to disable this fallback check
215
+ */
216
+ disableCheckStatusList2021?: boolean
217
+
218
+ mandatoryCredentialStatus: boolean
219
+ verifyStatusListCredential: boolean
220
+ verifyMatchingIssuers: boolean
221
+ errorUnknownListType?: boolean
222
+ }
223
+
224
+ /**
225
+ * Encapsulates the parameters required to verify a
226
+ * {@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation}
227
+ *
228
+ * @beta This API is likely to change without a BREAKING CHANGE notice
229
+ */
230
+ export interface IVerifyPresentationLDArgs {
231
+ /**
232
+ * The json payload of the Credential according to the
233
+ * {@link https://www.w3.org/TR/vc-data-model/#credentials | canonical model}
234
+ *
235
+ * The signer of the Credential is chosen based on the `issuer.id` property
236
+ * of the `credential`
237
+ *
238
+ */
239
+ presentation: VerifiablePresentation
240
+
241
+ /**
242
+ * Optional (only for JWT) string challenge parameter to verify the verifiable presentation against
243
+ */
244
+ challenge?: string
245
+
246
+ /**
247
+ * Optional (only for JWT) string domain parameter to verify the verifiable presentation against
248
+ */
249
+ domain?: string
250
+
251
+ /**
252
+ * Set this to true if you want the '@context' URLs to be fetched in case they are not pre-loaded.
253
+ *
254
+ * @default false
255
+ */
256
+ fetchRemoteContexts?: boolean
257
+
258
+ /**
259
+ * Overrides specific aspects of credential verification, where possible.
260
+ */
261
+ policies?: VerificationPolicies
262
+
263
+ /**
264
+ * Use this presentation purpose for the verification method in the DID when doing a check (defaualts to assertionMethod)
265
+ */
266
+ presentationPurpose?: IAuthenticationProofPurpose | IControllerProofPurpose | IAssertionProofPurpose | IProofPurpose
267
+
268
+ /**
269
+ * Check status function, to check verifiableCredentials that have a credentialStatus property
270
+ */
271
+ checkStatus?: Function
272
+
273
+ /**
274
+ * Allows you to use the default integrated statusList 2021 support. If a checkStatus function is provided, this will be ignored
275
+ */
276
+ statusList?: StatusListCheck
277
+ }
278
+
279
+ /**
280
+ * Represents the requirements that this plugin has.
281
+ * The agent that is using this plugin is expected to provide these methods.
282
+ *
283
+ * This interface can be used for static type checks, to make sure your application is properly initialized.
284
+ *
285
+ * @beta This API is likely to change without a BREAKING CHANGE notice
286
+ */
287
+ /*
288
+ export type IRequiredContext = IAgentContext<
289
+ IResolver & IDIDManager & Pick<ISphereonKeyManager, 'keyManagerGet' | 'keyManagerSign' | 'keyManagerVerify'>
290
+ >
291
+ */
292
+
293
+
294
+
295
+ /**
296
+ * Represents the requirements that this plugin has.
297
+ * The agent that is using this plugin is expected to provide these methods.
298
+ *
299
+ * This interface can be used for static type checks, to make sure your application is properly initialized.
300
+ *
301
+ * @beta
302
+ */
303
+ export type IVcdmIssuerAgentContext = IAgentContext<
304
+ IResolver &
305
+ IDIDManager &
306
+ Pick<ISphereonKeyManager, 'keyManagerGet' | 'keyManagerSign' | 'keyManagerVerify'>
307
+ >
308
+
309
+
310
+ export type ContextDoc = {
311
+ '@context': string | Record<string, any>
312
+ }
313
+
314
+ /*
315
+ @beta
316
+ */
317
+ export interface IProofPurpose {
318
+ term?: string
319
+ date?: string | Date | number
320
+ maxTimestampDelta?: number
321
+ }
322
+
323
+ /*
324
+ @beta
325
+ */
326
+ export interface IControllerProofPurpose extends IProofPurpose {
327
+ controller?: object
328
+ }
329
+
330
+ /*
331
+ @beta
332
+ */
333
+ export interface IAuthenticationProofPurpose extends IControllerProofPurpose {
334
+ challenge?: string
335
+ domain?: string
336
+ }
337
+
338
+ /*
339
+ @beta
340
+ */
341
+ export interface IAssertionProofPurpose extends IControllerProofPurpose {}
342
+
343
+ /**
344
+ * The interface definition for a plugin that can generate Verifiable Credentials and Presentations
345
+ *
346
+ * @see {@link @veramo/credential-w3c#CredentialPlugin} for an implementation.
347
+ * @remarks Please see {@link https://www.w3.org/TR/vc-data-model | W3C Verifiable Credentials data model}
348
+ *
349
+ * @public
350
+ */
351
+ export interface IVcdmCredentialProvider {
352
+ /**
353
+ * Creates a Verifiable Presentation.
354
+ * The payload, signer and format are chosen based on the `args` parameter.
355
+ *
356
+ * @param args - Arguments necessary to create the Presentation.
357
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
358
+ *
359
+ * @returns - a promise that resolves to the {@link @veramo/core#VerifiablePresentation} that was requested or
360
+ * rejects with an error if there was a problem with the input or while getting the key to sign
361
+ *
362
+ * @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#presentations | Verifiable Presentation data model
363
+ * }
364
+ */
365
+ createVerifiablePresentation(args: ICreateVerifiablePresentationLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiablePresentationSP>
366
+
367
+ /**
368
+ * Creates a Verifiable Presentation.
369
+ * The payload, signer and format are chosen based on the `args` parameter.
370
+ *
371
+ * @param args - Arguments necessary to create the Presentation.
372
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
373
+ *
374
+ * @returns - a promise that resolves to the {@link @veramo/core#VerifiablePresentation} that was requested or
375
+ * rejects with an error if there was a problem with the input or while getting the key to sign
376
+ *
377
+ * @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#presentations | Verifiable Presentation data model
378
+ * }
379
+ */
380
+ canIssueCredentialType(args: ICanIssueCredentialTypeArgs): boolean
381
+
382
+ /**
383
+ * Matches a key against the type of proof supported by this issuer
384
+ *
385
+ * @param key - The key to match against the proof type(s) supported by this issuer
386
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
387
+ *
388
+ * @returns - a promise that resolves to a boolean indicating if the key can be used to sign a credential with this issuer
389
+ */
390
+ matchKeyForType(key: IKey): boolean
391
+
392
+ /**
393
+ * Gets the proof type supported by this issuer
394
+ *
395
+ * @returns - a promise that resolves to a string of the proof format supported by this issuer
396
+ */
397
+ getTypeProofFormat(): string
398
+
399
+ /**
400
+ * Creates a Verifiable Credential.
401
+ * The payload, signer and format are chosen based on the `args` parameter.
402
+ *
403
+ * @param args - Arguments necessary to create the Presentation.
404
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
405
+ *
406
+ * @returns - a promise that resolves to the {@link @veramo/core#VerifiableCredential} that was requested or
407
+ * rejects with an error if there was a problem with the input or while getting the key to sign
408
+ *
409
+ * @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#credentials | Verifiable Credential data model}
410
+ */
411
+ createVerifiableCredential(args: ICreateVerifiableCredentialLDArgs, context: IVcdmIssuerAgentContext): Promise<VerifiableCredentialSP>
412
+
413
+ /**
414
+ * Verifies a Verifiable Credential
415
+ *
416
+ * @param args - Arguments necessary to verify a VerifiableCredential
417
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
418
+ *
419
+ * @returns - a promise that resolves to an object containing a `verified` boolean property and an optional `error`
420
+ * for details
421
+ *
422
+ * @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#credentials | Verifiable Credential data model}
423
+ */
424
+ verifyCredential(args: IVerifyCredentialLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult>
425
+
426
+ /**
427
+ *
428
+ * @param args - Arguments necessary to verify a document
429
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
430
+ *
431
+ * @returns a promise that resolves to a boolean indicating if the document can be verified
432
+ */
433
+ canVerifyDocumentType(args: ICanVerifyDocumentTypeArgs): boolean
434
+
435
+ /**
436
+ * Verifies a Verifiable Presentation JWT or LDS Format.
437
+ *
438
+ * @param args - Arguments necessary to verify a VerifiableCredential
439
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
440
+ *
441
+ * @returns - a promise that resolves to an object containing a `verified` boolean property and an optional `error`
442
+ * for details
443
+ *
444
+ * @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#presentations | Verifiable Credential data model}
445
+ */
446
+ verifyPresentation(args: IVerifyPresentationLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult>
447
+ }
448
+
449
+
450
+
451
+
452
+
453
+ /**
454
+ * The interface definition for a plugin that can generate Verifiable Credentials and Presentations
455
+ *
456
+ * @see {@link @veramo/credential-w3c#CredentialPlugin} for an implementation.
457
+ * @remarks Please see {@link https://www.w3.org/TR/vc-data-model | W3C Verifiable Credentials data model}
458
+ *
459
+ * @public
460
+ */
461
+ export interface IVcdmCredentialIssuer extends IPluginMethodMap {
462
+ /**
463
+ * Creates a Verifiable Presentation.
464
+ * The payload, signer and format are chosen based on the `args` parameter.
465
+ *
466
+ * @param args - Arguments necessary to create the Presentation.
467
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
468
+ *
469
+ * @returns - a promise that resolves to the {@link @veramo/core#VerifiablePresentation} that was requested or
470
+ * rejects with an error if there was a problem with the input or while getting the key to sign
471
+ *
472
+ * @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#presentations | Verifiable Presentation data model
473
+ * }
474
+ */
475
+ createVerifiablePresentation(
476
+ args: ICreateVerifiablePresentationLDArgs,
477
+ context: IVcdmIssuerAgentContext,
478
+ ): Promise<VerifiablePresentationSP>
479
+
480
+ /**
481
+ * Creates a Verifiable Credential.
482
+ * The payload, signer and format are chosen based on the `args` parameter.
483
+ *
484
+ * @param args - Arguments necessary to create the Presentation.
485
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
486
+ *
487
+ * @returns - a promise that resolves to the {@link @veramo/core#VerifiableCredential} that was requested or rejects
488
+ * with an error if there was a problem with the input or while getting the key to sign
489
+ *
490
+ * @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#credentials | Verifiable Credential data model}
491
+ */
492
+ createVerifiableCredential(
493
+ args: ICreateVerifiableCredentialLDArgs,
494
+ context: IVcdmIssuerAgentContext,
495
+ ): Promise<VerifiableCredentialSP>
496
+ }
497
+
498
+
499
+
500
+ /**
501
+ * The interface definition for a plugin that can generate Verifiable Credentials and Presentations
502
+ *
503
+ * @see {@link @veramo/credential-w3c#CredentialPlugin} for an implementation.
504
+ * @remarks Please see {@link https://www.w3.org/TR/vc-data-model | W3C Verifiable Credentials data model}
505
+ *
506
+ * @public
507
+ */
508
+ export interface IVcdmCredentialVerifier extends IPluginMethodMap {
509
+ /**
510
+ * Verifies a Verifiable Credential
511
+ *
512
+ * @param args - Arguments necessary to verify a VerifiableCredential
513
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
514
+ *
515
+ * @returns - a promise that resolves to an object containing a `verified` boolean property and an optional `error`
516
+ * for details
517
+ *
518
+ * @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#credentials | Verifiable Credential data model}
519
+ */
520
+ verifyCredential(args: IVerifyCredentialLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult>
521
+
522
+ /**
523
+ * Verifies a Verifiable Presentation JWT or LDS Format.
524
+ *
525
+ * @param args - Arguments necessary to verify a VerifiableCredential
526
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
527
+ *
528
+ * @returns - a promise that resolves to an object containing a `verified` boolean property and an optional `error`
529
+ * for details
530
+ *
531
+ * @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#presentations | Verifiable Credential data model}
532
+ */
533
+ verifyPresentation(args: IVerifyPresentationLDArgs, context: IVcdmVerifierAgentContext): Promise<IVerifyResult>
534
+ }
535
+
536
+ /**
537
+ * Represents the requirements that this plugin has.
538
+ * The agent that is using this plugin is expected to provide these methods.
539
+ *
540
+ * This interface can be used for static type checks, to make sure your application is properly initialized.
541
+ *
542
+ * @beta
543
+ */
544
+ export type IVcdmVerifierAgentContext = IAgentContext<
545
+ IResolver & Pick<IDIDManager, 'didManagerGet' | 'didManagerFind'>
546
+ >