@sphereon/ssi-sdk.vc-status-list 0.34.1-feature.SSISDK.17.bitstring.sl.9 → 0.34.1-feature.merge.crypto.extensions.modules.33
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/dist/index.cjs +481 -188
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +151 -66
- package/dist/index.d.ts +151 -66
- package/dist/index.js +482 -189
- package/dist/index.js.map +1 -1
- package/package.json +9 -7
- package/src/functions.ts +125 -55
- package/src/impl/BitstringStatusListImplementation.ts +292 -97
- package/src/impl/IStatusList.ts +102 -9
- package/src/impl/OAuthStatusList.ts +118 -29
- package/src/impl/StatusList2021.ts +111 -31
- package/src/index.ts +1 -0
- package/src/types/index.ts +42 -65
- package/src/utils.ts +48 -19
package/src/types/index.ts
CHANGED
|
@@ -7,26 +7,20 @@ import {
|
|
|
7
7
|
type IVerifiableCredential,
|
|
8
8
|
type OrPromise,
|
|
9
9
|
type StatusListCredential,
|
|
10
|
-
StatusListCredentialIdMode,
|
|
11
10
|
StatusListDriverType,
|
|
12
11
|
type StatusListIndexingDirection,
|
|
13
12
|
StatusListType,
|
|
14
13
|
type StatusPurpose2021,
|
|
15
14
|
} from '@sphereon/ssi-types'
|
|
16
|
-
import type {
|
|
17
|
-
CredentialPayload,
|
|
18
|
-
IAgentContext,
|
|
19
|
-
ICredentialIssuer,
|
|
20
|
-
ICredentialPlugin,
|
|
21
|
-
ICredentialVerifier,
|
|
22
|
-
IKeyManager,
|
|
23
|
-
IPluginMethodMap,
|
|
24
|
-
} from '@veramo/core'
|
|
15
|
+
import type { CredentialPayload, IAgentContext, ICredentialIssuer, ICredentialVerifier, IKeyManager, IPluginMethodMap } from '@veramo/core'
|
|
25
16
|
import { DataSource } from 'typeorm'
|
|
26
17
|
import type { BitsPerStatus } from '@sd-jwt/jwt-status-list'
|
|
27
18
|
import type { SdJwtVcPayload } from '@sd-jwt/sd-jwt-vc'
|
|
28
19
|
import type { StatusListOpts } from '@sphereon/oid4vci-common'
|
|
29
20
|
import { BitstringStatusPurpose } from '@4sure-tech/vc-bitstring-status-lists'
|
|
21
|
+
import { IVcdmCredentialPlugin } from '@sphereon/ssi-sdk.credential-vcdm'
|
|
22
|
+
import { IExtractedCredentialDetails } from '../impl/IStatusList'
|
|
23
|
+
import { BitstringStatusListArgs, IStatusListEntity } from '@sphereon/ssi-sdk.data-store'
|
|
30
24
|
|
|
31
25
|
export enum StatusOAuth {
|
|
32
26
|
Valid = 0,
|
|
@@ -39,8 +33,6 @@ export enum Status2021 {
|
|
|
39
33
|
Invalid = 1,
|
|
40
34
|
}
|
|
41
35
|
|
|
42
|
-
export type BitstringStatus = number
|
|
43
|
-
|
|
44
36
|
export type StatusList2021Args = {
|
|
45
37
|
indexingDirection: StatusListIndexingDirection
|
|
46
38
|
statusPurpose?: StatusPurpose2021
|
|
@@ -48,18 +40,10 @@ export type StatusList2021Args = {
|
|
|
48
40
|
}
|
|
49
41
|
|
|
50
42
|
export type OAuthStatusListArgs = {
|
|
51
|
-
bitsPerStatus
|
|
43
|
+
bitsPerStatus: BitsPerStatus
|
|
52
44
|
expiresAt?: Date
|
|
53
45
|
}
|
|
54
46
|
|
|
55
|
-
export type BitstringStatusListArgs = {
|
|
56
|
-
statusPurpose: BitstringStatusPurpose
|
|
57
|
-
bitsPerStatus: number
|
|
58
|
-
ttl?: number
|
|
59
|
-
validFrom?: Date
|
|
60
|
-
validUntil?: Date
|
|
61
|
-
}
|
|
62
|
-
|
|
63
47
|
export type BaseCreateNewStatusListArgs = {
|
|
64
48
|
type: StatusListType
|
|
65
49
|
id: string
|
|
@@ -110,44 +94,36 @@ export interface UpdateStatusListFromStatusListCredentialArgs {
|
|
|
110
94
|
statusListCredential: StatusListCredential // | CompactJWT
|
|
111
95
|
keyRef?: string
|
|
112
96
|
statusListIndex: number | string
|
|
113
|
-
value: number | Status2021 | StatusOAuth
|
|
97
|
+
value: number | Status2021 | StatusOAuth
|
|
114
98
|
}
|
|
115
99
|
|
|
116
100
|
export interface StatusListResult {
|
|
101
|
+
id: string
|
|
117
102
|
encodedList: string
|
|
118
|
-
|
|
119
|
-
length: number
|
|
103
|
+
issuer: string | IIssuer
|
|
120
104
|
type: StatusListType
|
|
121
105
|
proofFormat: CredentialProofFormat
|
|
122
|
-
|
|
106
|
+
length: number
|
|
107
|
+
statusListCredential: StatusListCredential
|
|
123
108
|
statuslistContentType: string
|
|
124
|
-
issuer: string | IIssuer
|
|
125
|
-
statusList2021?: StatusList2021Details
|
|
126
|
-
oauthStatusList?: OAuthStatusDetails
|
|
127
|
-
bitstringStatusList?: BitstringStatusDetails
|
|
128
|
-
|
|
129
|
-
// These cannot be deduced from the VC, so they are present when callers pass in these values as params
|
|
130
109
|
correlationId?: string
|
|
131
110
|
driverType?: StatusListDriverType
|
|
132
|
-
credentialIdMode?: StatusListCredentialIdMode
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
interface StatusList2021Details {
|
|
136
|
-
indexingDirection: StatusListIndexingDirection
|
|
137
|
-
statusPurpose?: StatusPurpose2021
|
|
138
|
-
}
|
|
139
111
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
112
|
+
statusList2021?: {
|
|
113
|
+
indexingDirection: StatusListIndexingDirection
|
|
114
|
+
statusPurpose: StatusPurpose2021
|
|
115
|
+
}
|
|
116
|
+
oauthStatusList?: {
|
|
117
|
+
bitsPerStatus: number
|
|
118
|
+
expiresAt?: Date
|
|
119
|
+
}
|
|
120
|
+
bitstringStatusList?: {
|
|
121
|
+
statusPurpose: BitstringStatusPurpose | BitstringStatusPurpose[]
|
|
122
|
+
bitsPerStatus?: number
|
|
123
|
+
validFrom?: Date
|
|
124
|
+
validUntil?: Date
|
|
125
|
+
ttl?: number
|
|
126
|
+
}
|
|
151
127
|
}
|
|
152
128
|
|
|
153
129
|
export interface StatusList2021EntryCredentialStatus extends ICredentialStatus {
|
|
@@ -165,16 +141,6 @@ export interface StatusListOAuthEntryCredentialStatus extends ICredentialStatus
|
|
|
165
141
|
expiresAt?: Date
|
|
166
142
|
}
|
|
167
143
|
|
|
168
|
-
export interface BitstringStatusListEntryCredentialStatus extends ICredentialStatus {
|
|
169
|
-
type: 'BitstringStatusListEntry'
|
|
170
|
-
statusPurpose: BitstringStatusPurpose | BitstringStatusPurpose[]
|
|
171
|
-
statusListIndex: string
|
|
172
|
-
statusListCredential: string
|
|
173
|
-
bitsPerStatus?: number
|
|
174
|
-
statusMessage?: Array<BitstringStatus>
|
|
175
|
-
statusReference?: string | string[]
|
|
176
|
-
}
|
|
177
|
-
|
|
178
144
|
export interface StatusList2021ToVerifiableCredentialArgs {
|
|
179
145
|
issuer: string | IIssuer
|
|
180
146
|
id: string
|
|
@@ -200,7 +166,7 @@ export interface CreateStatusListArgs {
|
|
|
200
166
|
export interface UpdateStatusListIndexArgs {
|
|
201
167
|
statusListCredential: StatusListCredential // | CompactJWT
|
|
202
168
|
statusListIndex: number | string
|
|
203
|
-
value: number | Status2021 | StatusOAuth
|
|
169
|
+
value: number | Status2021 | StatusOAuth
|
|
204
170
|
bitsPerStatus?: number
|
|
205
171
|
keyRef?: string
|
|
206
172
|
expiresAt?: Date
|
|
@@ -212,11 +178,22 @@ export interface CheckStatusIndexArgs {
|
|
|
212
178
|
bitsPerStatus?: number
|
|
213
179
|
}
|
|
214
180
|
|
|
215
|
-
|
|
216
|
-
|
|
181
|
+
// For the CREATE and READ contexts
|
|
182
|
+
export interface IToDetailsFromCredentialArgs {
|
|
183
|
+
// The source credential we are converting
|
|
184
|
+
statusListCredential: StatusListCredential
|
|
185
|
+
|
|
186
|
+
// The required metadata that is NOT in the credential itself
|
|
187
|
+
statusListType: StatusListType
|
|
188
|
+
bitsPerStatus?: number
|
|
217
189
|
correlationId?: string
|
|
218
190
|
driverType?: StatusListDriverType
|
|
219
|
-
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// For the UPDATE context
|
|
194
|
+
export interface IMergeDetailsWithEntityArgs {
|
|
195
|
+
extractedDetails: IExtractedCredentialDetails
|
|
196
|
+
statusListEntity: IStatusListEntity
|
|
220
197
|
}
|
|
221
198
|
|
|
222
199
|
/**
|
|
@@ -304,5 +281,5 @@ export type SignedStatusListData = {
|
|
|
304
281
|
encodedList: string
|
|
305
282
|
}
|
|
306
283
|
|
|
307
|
-
export type IRequiredPlugins =
|
|
308
|
-
export type IRequiredContext = IAgentContext<ICredentialIssuer & ICredentialVerifier & IIdentifierResolution & IKeyManager &
|
|
284
|
+
export type IRequiredPlugins = IVcdmCredentialPlugin & IIdentifierResolution
|
|
285
|
+
export type IRequiredContext = IAgentContext<ICredentialIssuer & ICredentialVerifier & IIdentifierResolution & IKeyManager & IVcdmCredentialPlugin>
|
package/src/utils.ts
CHANGED
|
@@ -41,7 +41,7 @@ export function getAssertedProperty<T extends object>(propertyName: string, obj:
|
|
|
41
41
|
const ValidProofTypeMap = new Map<StatusListType, CredentialProofFormat[]>([
|
|
42
42
|
[StatusListType.StatusList2021, ['jwt', 'lds']],
|
|
43
43
|
[StatusListType.OAuthStatusList, ['jwt', 'cbor']],
|
|
44
|
-
[StatusListType.BitstringStatusList, ['lds']],
|
|
44
|
+
[StatusListType.BitstringStatusList, ['lds', 'vc+jwt']],
|
|
45
45
|
])
|
|
46
46
|
|
|
47
47
|
export function assertValidProofType(type: StatusListType, proofFormat: CredentialProofFormat) {
|
|
@@ -53,31 +53,60 @@ export function assertValidProofType(type: StatusListType, proofFormat: Credenti
|
|
|
53
53
|
|
|
54
54
|
export function determineStatusListType(credential: StatusListCredential): StatusListType {
|
|
55
55
|
const proofFormat = determineProofFormat(credential)
|
|
56
|
+
|
|
56
57
|
switch (proofFormat) {
|
|
57
58
|
case 'jwt':
|
|
58
|
-
|
|
59
|
-
const keys = Object.keys(payload)
|
|
60
|
-
if (keys.includes('status_list')) {
|
|
61
|
-
return StatusListType.OAuthStatusList
|
|
62
|
-
} else if (keys.includes('vc')) {
|
|
63
|
-
return StatusListType.StatusList2021
|
|
64
|
-
}
|
|
65
|
-
break
|
|
59
|
+
return determineJwtStatusListType(credential as string)
|
|
66
60
|
case 'lds':
|
|
67
|
-
|
|
68
|
-
const type = uniform.type.find((t) => {
|
|
69
|
-
return Object.values(StatusListType).some((statusType) => t.includes(statusType))
|
|
70
|
-
})
|
|
71
|
-
if (!type) {
|
|
72
|
-
throw new Error('Invalid status list credential type')
|
|
73
|
-
}
|
|
74
|
-
return type.replace('Credential', '') as StatusListType
|
|
75
|
-
|
|
61
|
+
return determineLdsStatusListType(credential)
|
|
76
62
|
case 'cbor':
|
|
77
63
|
return StatusListType.OAuthStatusList
|
|
64
|
+
default:
|
|
65
|
+
throw new Error('Cannot determine status list type from credential payload')
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function determineJwtStatusListType(credential: string): StatusListType {
|
|
70
|
+
const payload: any = jwtDecode(credential)
|
|
71
|
+
|
|
72
|
+
// OAuth status list format
|
|
73
|
+
if ('status_list' in payload) {
|
|
74
|
+
return StatusListType.OAuthStatusList
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Direct credential subject
|
|
78
|
+
if ('credentialSubject' in payload) {
|
|
79
|
+
return getStatusListTypeFromSubject(payload.credentialSubject)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Wrapped VC format
|
|
83
|
+
if ('vc' in payload && 'credentialSubject' in payload.vc) {
|
|
84
|
+
return getStatusListTypeFromSubject(payload.vc.credentialSubject)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
throw new Error('Invalid status list credential: credentialSubject not found')
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function determineLdsStatusListType(credential: StatusListCredential): StatusListType {
|
|
91
|
+
const uniform = CredentialMapper.toUniformCredential(credential)
|
|
92
|
+
const statusListType = uniform.type.find((type) => Object.values(StatusListType).some((statusType) => type.includes(statusType)))
|
|
93
|
+
|
|
94
|
+
if (!statusListType) {
|
|
95
|
+
throw new Error('Invalid status list credential type')
|
|
78
96
|
}
|
|
79
97
|
|
|
80
|
-
|
|
98
|
+
return statusListType.replace('Credential', '') as StatusListType
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function getStatusListTypeFromSubject(credentialSubject: any): StatusListType {
|
|
102
|
+
switch (credentialSubject.type) {
|
|
103
|
+
case 'StatusList2021':
|
|
104
|
+
return StatusListType.StatusList2021
|
|
105
|
+
case 'BitstringStatusList':
|
|
106
|
+
return StatusListType.BitstringStatusList
|
|
107
|
+
default:
|
|
108
|
+
throw new Error(`Unknown credential subject type: ${credentialSubject.type}`)
|
|
109
|
+
}
|
|
81
110
|
}
|
|
82
111
|
|
|
83
112
|
export function determineProofFormat(credential: StatusListCredential): CredentialProofFormat {
|