@sphereon/ssi-sdk.vc-status-list 0.32.1-next.54 → 0.33.0

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 (51) hide show
  1. package/dist/functions.d.ts +13 -13
  2. package/dist/functions.d.ts.map +1 -1
  3. package/dist/functions.js +53 -109
  4. package/dist/functions.js.map +1 -1
  5. package/dist/impl/IStatusList.d.ts +26 -0
  6. package/dist/impl/IStatusList.d.ts.map +1 -0
  7. package/dist/impl/IStatusList.js +3 -0
  8. package/dist/impl/IStatusList.js.map +1 -0
  9. package/dist/impl/OAuthStatusList.d.ts +21 -0
  10. package/dist/impl/OAuthStatusList.d.ts.map +1 -0
  11. package/dist/impl/OAuthStatusList.js +155 -0
  12. package/dist/impl/OAuthStatusList.js.map +1 -0
  13. package/dist/impl/StatusList2021.d.ts +16 -0
  14. package/dist/impl/StatusList2021.d.ts.map +1 -0
  15. package/dist/impl/StatusList2021.js +186 -0
  16. package/dist/impl/StatusList2021.js.map +1 -0
  17. package/dist/impl/StatusListFactory.d.ts +11 -0
  18. package/dist/impl/StatusListFactory.d.ts.map +1 -0
  19. package/dist/impl/StatusListFactory.js +32 -0
  20. package/dist/impl/StatusListFactory.js.map +1 -0
  21. package/dist/impl/encoding/cbor.d.ts +6 -0
  22. package/dist/impl/encoding/cbor.d.ts.map +1 -0
  23. package/dist/impl/encoding/cbor.js +140 -0
  24. package/dist/impl/encoding/cbor.js.map +1 -0
  25. package/dist/impl/encoding/common.d.ts +12 -0
  26. package/dist/impl/encoding/common.d.ts.map +1 -0
  27. package/dist/impl/encoding/common.js +17 -0
  28. package/dist/impl/encoding/common.js.map +1 -0
  29. package/dist/impl/encoding/jwt.d.ts +9 -0
  30. package/dist/impl/encoding/jwt.d.ts.map +1 -0
  31. package/dist/impl/encoding/jwt.js +74 -0
  32. package/dist/impl/encoding/jwt.js.map +1 -0
  33. package/dist/types/index.d.ts +131 -33
  34. package/dist/types/index.d.ts.map +1 -1
  35. package/dist/types/index.js +12 -0
  36. package/dist/types/index.js.map +1 -1
  37. package/dist/utils.d.ts +17 -0
  38. package/dist/utils.d.ts.map +1 -0
  39. package/dist/utils.js +88 -0
  40. package/dist/utils.js.map +1 -0
  41. package/package.json +17 -6
  42. package/src/functions.ts +73 -159
  43. package/src/impl/IStatusList.ts +42 -0
  44. package/src/impl/OAuthStatusList.ts +206 -0
  45. package/src/impl/StatusList2021.ts +241 -0
  46. package/src/impl/StatusListFactory.ts +34 -0
  47. package/src/impl/encoding/cbor.ts +171 -0
  48. package/src/impl/encoding/common.ts +20 -0
  49. package/src/impl/encoding/jwt.ts +80 -0
  50. package/src/types/index.ts +151 -37
  51. package/src/utils.ts +95 -0
@@ -4,8 +4,9 @@ import {
4
4
  ICredentialStatus,
5
5
  IIssuer,
6
6
  IVerifiableCredential,
7
- OriginalVerifiableCredential,
8
7
  OrPromise,
8
+ ProofFormat,
9
+ StatusListCredential,
9
10
  StatusListCredentialIdMode,
10
11
  StatusListDriverType,
11
12
  StatusListIndexingDirection,
@@ -18,58 +19,105 @@ import {
18
19
  ICredentialIssuer,
19
20
  ICredentialPlugin,
20
21
  ICredentialVerifier,
22
+ IKeyManager,
21
23
  IPluginMethodMap,
22
- ProofFormat,
23
24
  } from '@veramo/core'
24
25
  import { DataSource } from 'typeorm'
26
+ import { BitsPerStatus } from '@sd-jwt/jwt-status-list/dist'
27
+ import { SdJwtVcPayload } from '@sd-jwt/sd-jwt-vc'
28
+ import { StatusListOpts } from '@sphereon/oid4vci-common'
25
29
 
26
- export interface CreateNewStatusListFuncArgs extends Omit<StatusList2021ToVerifiableCredentialArgs, 'encodedList'> {
27
- correlationId: string
28
- length?: number
30
+ export enum StatusOAuth {
31
+ Valid = 0,
32
+ Invalid = 1,
33
+ Suspended = 2,
29
34
  }
30
35
 
31
- export interface UpdateStatusListFromEncodedListArgs extends StatusList2021ToVerifiableCredentialArgs {
32
- statusListIndex: number | string
33
- value: boolean
36
+ export enum Status2021 {
37
+ Valid = 0,
38
+ Invalid = 1,
34
39
  }
35
40
 
36
- export interface UpdateStatusListFromStatusListCredentialArgs {
37
- statusListCredential: OriginalVerifiableCredential
38
- keyRef?: string
39
- statusListIndex: number | string
40
- value: boolean
41
+ export type StatusList2021Args = {
42
+ indexingDirection: StatusListIndexingDirection
43
+ statusPurpose?: StatusPurpose2021
44
+ // todo: validFrom and validUntil
41
45
  }
42
46
 
43
- export interface StatusList2021ToVerifiableCredentialArgs {
44
- issuer: string | IIssuer
47
+ export type OAuthStatusListArgs = {
48
+ bitsPerStatus?: BitsPerStatus
49
+ expiresAt?: Date
50
+ }
51
+
52
+ export type BaseCreateNewStatusListArgs = {
53
+ type: StatusListType
45
54
  id: string
46
- type?: StatusListType
55
+ issuer: string | IIssuer
56
+ correlationId?: string
57
+ length?: number
58
+ proofFormat?: ProofFormat
59
+ keyRef?: string
60
+ statusList2021?: StatusList2021Args
61
+ oauthStatusList?: OAuthStatusListArgs
62
+ driverType?: StatusListDriverType
63
+ }
64
+
65
+ export type UpdateStatusList2021Args = {
47
66
  statusPurpose: StatusPurpose2021
48
- encodedList: string
67
+ }
68
+
69
+ export type UpdateOAuthStatusListArgs = {
70
+ bitsPerStatus: BitsPerStatus
71
+ expiresAt?: Date
72
+ }
73
+
74
+ export interface UpdateStatusListFromEncodedListArgs {
75
+ type?: StatusListType
76
+ statusListIndex: number | string
77
+ value: boolean
49
78
  proofFormat?: ProofFormat
50
79
  keyRef?: string
80
+ correlationId?: string
81
+ encodedList: string
82
+ issuer: string | IIssuer
83
+ id: string
84
+ statusList2021?: UpdateStatusList2021Args
85
+ oauthStatusList?: UpdateOAuthStatusListArgs
86
+ }
51
87
 
52
- // todo: validFrom and validUntil
88
+ export interface UpdateStatusListFromStatusListCredentialArgs {
89
+ statusListCredential: StatusListCredential // | CompactJWT
90
+ keyRef?: string
91
+ statusListIndex: number | string
92
+ value: number | Status2021 | StatusOAuth
53
93
  }
54
94
 
55
- export interface StatusListDetails {
95
+ export interface StatusListResult {
56
96
  encodedList: string
97
+ statusListCredential: StatusListCredential
57
98
  length: number
58
99
  type: StatusListType
59
100
  proofFormat: ProofFormat
60
- statusPurpose: StatusPurpose2021
61
101
  id: string
102
+ statuslistContentType: string
62
103
  issuer: string | IIssuer
63
- indexingDirection: StatusListIndexingDirection
64
- statusListCredential: OriginalVerifiableCredential
104
+ statusList2021?: StatusList2021Details
105
+ oauthStatusList?: OAuthStatusDetails
106
+
65
107
  // These cannot be deduced from the VC, so they are present when callers pass in these values as params
66
108
  correlationId?: string
67
109
  driverType?: StatusListDriverType
68
110
  credentialIdMode?: StatusListCredentialIdMode
69
111
  }
70
112
 
71
- export interface StatusListResult extends StatusListDetails {
72
- statusListCredential: OriginalVerifiableCredential
113
+ interface StatusList2021Details {
114
+ indexingDirection: StatusListIndexingDirection
115
+ statusPurpose?: StatusPurpose2021
116
+ }
117
+
118
+ interface OAuthStatusDetails {
119
+ bitsPerStatus?: BitsPerStatus
120
+ expiresAt?: Date
73
121
  }
74
122
 
75
123
  export interface StatusList2021EntryCredentialStatus extends ICredentialStatus {
@@ -79,6 +127,54 @@ export interface StatusList2021EntryCredentialStatus extends ICredentialStatus {
79
127
  statusListCredential: string
80
128
  }
81
129
 
130
+ export interface StatusListOAuthEntryCredentialStatus extends ICredentialStatus {
131
+ type: 'OAuthStatusListEntry'
132
+ bitsPerStatus: number
133
+ statusListIndex: string
134
+ statusListCredential: string
135
+ expiresAt?: Date
136
+ }
137
+
138
+ export interface StatusList2021ToVerifiableCredentialArgs {
139
+ issuer: string | IIssuer
140
+ id: string
141
+ type?: StatusListType
142
+ proofFormat?: ProofFormat
143
+ keyRef?: string
144
+ encodedList: string
145
+ statusPurpose: StatusPurpose2021
146
+ }
147
+
148
+ export interface CreateStatusListArgs {
149
+ issuer: string | IIssuer
150
+ id: string
151
+ proofFormat?: ProofFormat
152
+ keyRef?: string
153
+ correlationId?: string
154
+ length?: number
155
+ statusList2021?: StatusList2021Args
156
+ oauthStatusList?: OAuthStatusListArgs
157
+ }
158
+
159
+ export interface UpdateStatusListIndexArgs {
160
+ statusListCredential: StatusListCredential // | CompactJWT
161
+ statusListIndex: number | string
162
+ value: number | Status2021 | StatusOAuth
163
+ keyRef?: string
164
+ expiresAt?: Date
165
+ }
166
+
167
+ export interface CheckStatusIndexArgs {
168
+ statusListCredential: StatusListCredential // | CompactJWT
169
+ statusListIndex: string | number
170
+ }
171
+
172
+ export interface ToStatusListDetailsArgs {
173
+ statusListPayload: StatusListCredential
174
+ correlationId?: string
175
+ driverType?: StatusListDriverType
176
+ }
177
+
82
178
  /**
83
179
  * The interface definition for a plugin that can add statuslist info to a credential
84
180
  *
@@ -95,7 +191,7 @@ export interface IStatusListPlugin extends IPluginMethodMap {
95
191
  *
96
192
  * @returns - The details of the newly created status list
97
193
  */
98
- slCreateStatusList(args: CreateNewStatusListArgs, context: IRequiredContext): Promise<StatusListDetails>
194
+ slCreateStatusList(args: CreateNewStatusListArgs, context: IRequiredContext): Promise<StatusListResult>
99
195
 
100
196
  /**
101
197
  * Ensures status list info like index and list id is added to a credential
@@ -109,25 +205,44 @@ export interface IStatusListPlugin extends IPluginMethodMap {
109
205
  */
110
206
  slAddStatusToCredential(args: IAddStatusToCredentialArgs, context: IRequiredContext): Promise<CredentialWithStatusSupport>
111
207
 
208
+ slAddStatusToSdJwtCredential(args: IAddStatusToSdJwtCredentialArgs, context: IRequiredContext): Promise<SdJwtVcPayload>
209
+
112
210
  /**
113
211
  * Get the status list using the configured driver for the SL. Normally a correlationId or id should suffice. Optionally accepts a dbName/datasource
114
212
  * @param args
115
213
  * @param context
116
214
  */
117
- slGetStatusList(args: GetStatusListArgs, context: IRequiredContext): Promise<StatusListDetails>
215
+ slGetStatusList(args: GetStatusListArgs, context: IRequiredContext): Promise<StatusListResult>
216
+
217
+ /**
218
+ * Import status lists when noy yet present
219
+ *
220
+ * @param imports Array of status list information like type and size
221
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
222
+ */
223
+ slImportStatusLists(imports: Array<CreateNewStatusListArgs>, context: IRequiredContext): Promise<boolean>
224
+ }
225
+
226
+ export type CreateNewStatusListFuncArgs = BaseCreateNewStatusListArgs
227
+
228
+ export type CreateNewStatusListArgs = BaseCreateNewStatusListArgs & {
229
+ dbName?: string
230
+ dataSource?: OrPromise<DataSource>
231
+ isDefault?: boolean
118
232
  }
119
233
 
120
234
  export type IAddStatusToCredentialArgs = Omit<IIssueCredentialStatusOpts, 'dataSource'> & {
121
235
  credential: CredentialWithStatusSupport
122
236
  }
123
237
 
238
+ export type IAddStatusToSdJwtCredentialArgs = Omit<IIssueCredentialStatusOpts, 'dataSource'> & {
239
+ credential: SdJwtVcPayload
240
+ }
241
+
124
242
  export interface IIssueCredentialStatusOpts {
125
243
  dataSource?: DataSource
126
-
244
+ statusLists?: Array<StatusListOpts>
127
245
  credentialId?: string // An id to use for the credential. Normally should be set as the crdential.id value
128
- statusListId?: string // Explicit status list to use. Determines the id from the credentialStatus object in the VC itself or uses the default otherwise
129
- statusListIndex?: number | string
130
- statusEntryCorrelationId?: string // An id to use for correlation. Can be the credential id, but also a business identifier. Will only be used for lookups/management
131
246
  value?: string
132
247
  }
133
248
 
@@ -138,13 +253,12 @@ export type GetStatusListArgs = {
138
253
  dbName?: string
139
254
  }
140
255
 
141
- export type CreateNewStatusListArgs = CreateNewStatusListFuncArgs & {
142
- dataSource?: OrPromise<DataSource>
143
- dbName?: string
144
- isDefault?: boolean
145
- }
146
-
147
256
  export type CredentialWithStatusSupport = ICredential | CredentialPayload | IVerifiableCredential
148
257
 
258
+ export type SignedStatusListData = {
259
+ statusListCredential: StatusListCredential
260
+ encodedList: string
261
+ }
262
+
149
263
  export type IRequiredPlugins = ICredentialPlugin & IIdentifierResolution
150
- export type IRequiredContext = IAgentContext<ICredentialIssuer & ICredentialVerifier & IIdentifierResolution>
264
+ export type IRequiredContext = IAgentContext<ICredentialIssuer & ICredentialVerifier & IIdentifierResolution & IKeyManager & ICredentialPlugin>
package/src/utils.ts ADDED
@@ -0,0 +1,95 @@
1
+ import {
2
+ CredentialMapper,
3
+ IIssuer,
4
+ ProofFormat,
5
+ StatusListType,
6
+ StatusListType as StatusListTypeW3C,
7
+ StatusListCredential,
8
+ DocumentFormat,
9
+ } from '@sphereon/ssi-types'
10
+ import { jwtDecode } from 'jwt-decode'
11
+
12
+ export function getAssertedStatusListType(type?: StatusListType) {
13
+ const assertedType = type ?? StatusListType.StatusList2021
14
+ if (![StatusListType.StatusList2021, StatusListType.OAuthStatusList].includes(assertedType)) {
15
+ throw Error(`StatusList type ${assertedType} is not supported (yet)`)
16
+ }
17
+ return assertedType
18
+ }
19
+
20
+ export function getAssertedValue<T>(name: string, value: T): NonNullable<T> {
21
+ if (value === undefined || value === null) {
22
+ throw Error(`Missing required ${name} value`)
23
+ }
24
+ return value
25
+ }
26
+
27
+ export function getAssertedValues(args: { issuer: string | IIssuer; id: string; type?: StatusListTypeW3C | StatusListType }) {
28
+ const type = getAssertedStatusListType(args?.type)
29
+ const id = getAssertedValue('id', args.id)
30
+ const issuer = getAssertedValue('issuer', args.issuer)
31
+ return { id, issuer, type }
32
+ }
33
+
34
+ export function getAssertedProperty<T extends object>(propertyName: string, obj: T): NonNullable<any> {
35
+ if (!(propertyName in obj)) {
36
+ throw Error(`The input object does not contain required property: ${propertyName}`)
37
+ }
38
+ return getAssertedValue(propertyName, (obj as any)[propertyName])
39
+ }
40
+
41
+ const ValidProofTypeMap = new Map<StatusListType, ProofFormat[]>([
42
+ [StatusListType.StatusList2021, ['jwt', 'lds', 'EthereumEip712Signature2021']],
43
+ [StatusListType.OAuthStatusList, ['jwt', 'cbor']],
44
+ ])
45
+
46
+ export function assertValidProofType(type: StatusListType, proofFormat: ProofFormat) {
47
+ const validProofTypes = ValidProofTypeMap.get(type)
48
+ if (!validProofTypes?.includes(proofFormat)) {
49
+ throw Error(`Invalid proof format '${proofFormat}' for status list type ${type}`)
50
+ }
51
+ }
52
+
53
+ export function determineStatusListType(credential: StatusListCredential): StatusListType {
54
+ const proofFormat = determineProofFormat(credential)
55
+ switch (proofFormat) {
56
+ case 'jwt':
57
+ const payload: StatusListCredential = jwtDecode(credential as string)
58
+ const keys = Object.keys(payload)
59
+ if (keys.includes('status_list')) {
60
+ return StatusListType.OAuthStatusList
61
+ } else if (keys.includes('vc')) {
62
+ return StatusListType.StatusList2021
63
+ }
64
+ break
65
+ case 'lds':
66
+ const uniform = CredentialMapper.toUniformCredential(credential)
67
+ const type = uniform.type.find((t) => {
68
+ return Object.values(StatusListType).some((statusType) => t.includes(statusType))
69
+ })
70
+ if (!type) {
71
+ throw new Error('Invalid status list credential type')
72
+ }
73
+ return type.replace('Credential', '') as StatusListType
74
+
75
+ case 'cbor':
76
+ return StatusListType.OAuthStatusList
77
+ }
78
+
79
+ throw new Error('Cannot determine status list type from credential payload')
80
+ }
81
+
82
+ export function determineProofFormat(credential: StatusListCredential): ProofFormat {
83
+ const type: DocumentFormat = CredentialMapper.detectDocumentType(credential)
84
+ switch (type) {
85
+ case DocumentFormat.JWT:
86
+ return 'jwt'
87
+ case DocumentFormat.MSO_MDOC:
88
+ // Not really mdoc, just assume Cbor for now, I'd need to decode at least the header to what type of Cbor we have
89
+ return 'cbor'
90
+ case DocumentFormat.JSONLD:
91
+ return 'lds'
92
+ default:
93
+ throw Error('Cannot determine credential payload type')
94
+ }
95
+ }