@sphereon/ssi-sdk.vc-status-list 0.32.1-feature.VDX.341.57 → 0.32.1-feature.oid4vp.rest.api.improv.bootcamp.187
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/functions.d.ts +13 -13
- package/dist/functions.d.ts.map +1 -1
- package/dist/functions.js +53 -109
- package/dist/functions.js.map +1 -1
- package/dist/impl/IStatusList.d.ts +26 -0
- package/dist/impl/IStatusList.d.ts.map +1 -0
- package/dist/impl/IStatusList.js +3 -0
- package/dist/impl/IStatusList.js.map +1 -0
- package/dist/impl/OAuthStatusList.d.ts +21 -0
- package/dist/impl/OAuthStatusList.d.ts.map +1 -0
- package/dist/impl/OAuthStatusList.js +153 -0
- package/dist/impl/OAuthStatusList.js.map +1 -0
- package/dist/impl/StatusList2021.d.ts +16 -0
- package/dist/impl/StatusList2021.d.ts.map +1 -0
- package/dist/impl/StatusList2021.js +182 -0
- package/dist/impl/StatusList2021.js.map +1 -0
- package/dist/impl/StatusListFactory.d.ts +11 -0
- package/dist/impl/StatusListFactory.d.ts.map +1 -0
- package/dist/impl/StatusListFactory.js +32 -0
- package/dist/impl/StatusListFactory.js.map +1 -0
- package/dist/impl/encoding/cbor.d.ts +6 -0
- package/dist/impl/encoding/cbor.d.ts.map +1 -0
- package/dist/impl/encoding/cbor.js +140 -0
- package/dist/impl/encoding/cbor.js.map +1 -0
- package/dist/impl/encoding/common.d.ts +12 -0
- package/dist/impl/encoding/common.d.ts.map +1 -0
- package/dist/impl/encoding/common.js +26 -0
- package/dist/impl/encoding/common.js.map +1 -0
- package/dist/impl/encoding/jwt.d.ts +9 -0
- package/dist/impl/encoding/jwt.d.ts.map +1 -0
- package/dist/impl/encoding/jwt.js +74 -0
- package/dist/impl/encoding/jwt.js.map +1 -0
- package/dist/types/index.d.ts +123 -33
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +12 -0
- package/dist/types/index.js.map +1 -1
- package/dist/utils.d.ts +17 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +88 -0
- package/dist/utils.js.map +1 -0
- package/package.json +14 -3
- package/src/functions.ts +73 -159
- package/src/impl/IStatusList.ts +42 -0
- package/src/impl/OAuthStatusList.ts +204 -0
- package/src/impl/StatusList2021.ts +236 -0
- package/src/impl/StatusListFactory.ts +34 -0
- package/src/impl/encoding/cbor.ts +171 -0
- package/src/impl/encoding/common.ts +25 -0
- package/src/impl/encoding/jwt.ts +80 -0
- package/src/types/index.ts +142 -37
- package/src/utils.ts +95 -0
package/src/types/index.ts
CHANGED
|
@@ -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,104 @@ 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'
|
|
29
|
+
|
|
30
|
+
export enum StatusOAuth {
|
|
31
|
+
Valid = 0,
|
|
32
|
+
Invalid = 1,
|
|
33
|
+
Suspended = 2,
|
|
34
|
+
}
|
|
25
35
|
|
|
26
|
-
export
|
|
27
|
-
|
|
28
|
-
|
|
36
|
+
export enum Status2021 {
|
|
37
|
+
Valid = 0,
|
|
38
|
+
Invalid = 1,
|
|
29
39
|
}
|
|
30
40
|
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
export type StatusList2021Args = {
|
|
42
|
+
indexingDirection: StatusListIndexingDirection
|
|
43
|
+
statusPurpose?: StatusPurpose2021
|
|
44
|
+
// todo: validFrom and validUntil
|
|
34
45
|
}
|
|
35
46
|
|
|
36
|
-
export
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
statusListIndex: number | string
|
|
40
|
-
value: boolean
|
|
47
|
+
export type OAuthStatusListArgs = {
|
|
48
|
+
bitsPerStatus?: BitsPerStatus
|
|
49
|
+
expiresAt?: Date
|
|
41
50
|
}
|
|
42
51
|
|
|
43
|
-
export
|
|
44
|
-
|
|
52
|
+
export type BaseCreateNewStatusListArgs = {
|
|
53
|
+
type: StatusListType
|
|
45
54
|
id: string
|
|
46
|
-
|
|
55
|
+
issuer: string | IIssuer
|
|
56
|
+
correlationId?: string
|
|
57
|
+
length?: number
|
|
58
|
+
proofFormat?: ProofFormat
|
|
59
|
+
keyRef?: string
|
|
60
|
+
statusList2021?: StatusList2021Args
|
|
61
|
+
oauthStatusList?: OAuthStatusListArgs
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type UpdateStatusList2021Args = {
|
|
47
65
|
statusPurpose: StatusPurpose2021
|
|
48
|
-
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type UpdateOAuthStatusListArgs = {
|
|
69
|
+
bitsPerStatus: BitsPerStatus
|
|
70
|
+
expiresAt?: Date
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface UpdateStatusListFromEncodedListArgs {
|
|
74
|
+
type?: StatusListType
|
|
75
|
+
statusListIndex: number | string
|
|
76
|
+
value: boolean
|
|
49
77
|
proofFormat?: ProofFormat
|
|
50
78
|
keyRef?: string
|
|
79
|
+
correlationId?: string
|
|
80
|
+
encodedList: string
|
|
81
|
+
issuer: string | IIssuer
|
|
82
|
+
id: string
|
|
83
|
+
statusList2021?: UpdateStatusList2021Args
|
|
84
|
+
oauthStatusList?: UpdateOAuthStatusListArgs
|
|
85
|
+
}
|
|
51
86
|
|
|
52
|
-
|
|
87
|
+
export interface UpdateStatusListFromStatusListCredentialArgs {
|
|
88
|
+
statusListCredential: StatusListCredential // | CompactJWT
|
|
89
|
+
keyRef?: string
|
|
90
|
+
statusListIndex: number | string
|
|
91
|
+
value: number | Status2021 | StatusOAuth
|
|
53
92
|
}
|
|
54
93
|
|
|
55
|
-
export interface
|
|
94
|
+
export interface StatusListResult {
|
|
56
95
|
encodedList: string
|
|
96
|
+
statusListCredential: StatusListCredential
|
|
57
97
|
length: number
|
|
58
98
|
type: StatusListType
|
|
59
99
|
proofFormat: ProofFormat
|
|
60
|
-
statusPurpose: StatusPurpose2021
|
|
61
100
|
id: string
|
|
101
|
+
statuslistContentType: string
|
|
62
102
|
issuer: string | IIssuer
|
|
63
|
-
|
|
64
|
-
|
|
103
|
+
statusList2021?: StatusList2021Details
|
|
104
|
+
oauthStatusList?: OAuthStatusDetails
|
|
105
|
+
|
|
65
106
|
// These cannot be deduced from the VC, so they are present when callers pass in these values as params
|
|
66
107
|
correlationId?: string
|
|
67
108
|
driverType?: StatusListDriverType
|
|
68
109
|
credentialIdMode?: StatusListCredentialIdMode
|
|
69
110
|
}
|
|
70
111
|
|
|
71
|
-
|
|
72
|
-
|
|
112
|
+
interface StatusList2021Details {
|
|
113
|
+
indexingDirection: StatusListIndexingDirection
|
|
114
|
+
statusPurpose?: StatusPurpose2021
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
interface OAuthStatusDetails {
|
|
118
|
+
bitsPerStatus?: BitsPerStatus
|
|
119
|
+
expiresAt?: Date
|
|
73
120
|
}
|
|
74
121
|
|
|
75
122
|
export interface StatusList2021EntryCredentialStatus extends ICredentialStatus {
|
|
@@ -79,6 +126,54 @@ export interface StatusList2021EntryCredentialStatus extends ICredentialStatus {
|
|
|
79
126
|
statusListCredential: string
|
|
80
127
|
}
|
|
81
128
|
|
|
129
|
+
export interface StatusListOAuthEntryCredentialStatus extends ICredentialStatus {
|
|
130
|
+
type: 'OAuthStatusListEntry'
|
|
131
|
+
bitsPerStatus: number
|
|
132
|
+
statusListIndex: string
|
|
133
|
+
statusListCredential: string
|
|
134
|
+
expiresAt?: Date
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface StatusList2021ToVerifiableCredentialArgs {
|
|
138
|
+
issuer: string | IIssuer
|
|
139
|
+
id: string
|
|
140
|
+
type?: StatusListType
|
|
141
|
+
proofFormat?: ProofFormat
|
|
142
|
+
keyRef?: string
|
|
143
|
+
encodedList: string
|
|
144
|
+
statusPurpose: StatusPurpose2021
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface CreateStatusListArgs {
|
|
148
|
+
issuer: string | IIssuer
|
|
149
|
+
id: string
|
|
150
|
+
proofFormat?: ProofFormat
|
|
151
|
+
keyRef?: string
|
|
152
|
+
correlationId?: string
|
|
153
|
+
length?: number
|
|
154
|
+
statusList2021?: StatusList2021Args
|
|
155
|
+
oauthStatusList?: OAuthStatusListArgs
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export interface UpdateStatusListIndexArgs {
|
|
159
|
+
statusListCredential: StatusListCredential // | CompactJWT
|
|
160
|
+
statusListIndex: number | string
|
|
161
|
+
value: number | Status2021 | StatusOAuth
|
|
162
|
+
keyRef?: string
|
|
163
|
+
expiresAt?: Date
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface CheckStatusIndexArgs {
|
|
167
|
+
statusListCredential: StatusListCredential // | CompactJWT
|
|
168
|
+
statusListIndex: string | number
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface ToStatusListDetailsArgs {
|
|
172
|
+
statusListPayload: StatusListCredential
|
|
173
|
+
correlationId?: string
|
|
174
|
+
driverType?: StatusListDriverType
|
|
175
|
+
}
|
|
176
|
+
|
|
82
177
|
/**
|
|
83
178
|
* The interface definition for a plugin that can add statuslist info to a credential
|
|
84
179
|
*
|
|
@@ -95,7 +190,7 @@ export interface IStatusListPlugin extends IPluginMethodMap {
|
|
|
95
190
|
*
|
|
96
191
|
* @returns - The details of the newly created status list
|
|
97
192
|
*/
|
|
98
|
-
slCreateStatusList(args: CreateNewStatusListArgs, context: IRequiredContext): Promise<
|
|
193
|
+
slCreateStatusList(args: CreateNewStatusListArgs, context: IRequiredContext): Promise<StatusListResult>
|
|
99
194
|
|
|
100
195
|
/**
|
|
101
196
|
* Ensures status list info like index and list id is added to a credential
|
|
@@ -109,25 +204,36 @@ export interface IStatusListPlugin extends IPluginMethodMap {
|
|
|
109
204
|
*/
|
|
110
205
|
slAddStatusToCredential(args: IAddStatusToCredentialArgs, context: IRequiredContext): Promise<CredentialWithStatusSupport>
|
|
111
206
|
|
|
207
|
+
slAddStatusToSdJwtCredential(args: IAddStatusToSdJwtCredentialArgs, context: IRequiredContext): Promise<SdJwtVcPayload>
|
|
208
|
+
|
|
112
209
|
/**
|
|
113
210
|
* Get the status list using the configured driver for the SL. Normally a correlationId or id should suffice. Optionally accepts a dbName/datasource
|
|
114
211
|
* @param args
|
|
115
212
|
* @param context
|
|
116
213
|
*/
|
|
117
|
-
slGetStatusList(args: GetStatusListArgs, context: IRequiredContext): Promise<
|
|
214
|
+
slGetStatusList(args: GetStatusListArgs, context: IRequiredContext): Promise<StatusListResult>
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export type CreateNewStatusListFuncArgs = BaseCreateNewStatusListArgs
|
|
218
|
+
|
|
219
|
+
export type CreateNewStatusListArgs = BaseCreateNewStatusListArgs & {
|
|
220
|
+
dataSource?: OrPromise<DataSource>
|
|
221
|
+
dbName?: string
|
|
222
|
+
isDefault?: boolean
|
|
118
223
|
}
|
|
119
224
|
|
|
120
225
|
export type IAddStatusToCredentialArgs = Omit<IIssueCredentialStatusOpts, 'dataSource'> & {
|
|
121
226
|
credential: CredentialWithStatusSupport
|
|
122
227
|
}
|
|
123
228
|
|
|
229
|
+
export type IAddStatusToSdJwtCredentialArgs = Omit<IIssueCredentialStatusOpts, 'dataSource'> & {
|
|
230
|
+
credential: SdJwtVcPayload
|
|
231
|
+
}
|
|
232
|
+
|
|
124
233
|
export interface IIssueCredentialStatusOpts {
|
|
125
234
|
dataSource?: DataSource
|
|
126
|
-
|
|
235
|
+
statusListOpts?: Array<StatusListOpts>
|
|
127
236
|
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
237
|
value?: string
|
|
132
238
|
}
|
|
133
239
|
|
|
@@ -138,13 +244,12 @@ export type GetStatusListArgs = {
|
|
|
138
244
|
dbName?: string
|
|
139
245
|
}
|
|
140
246
|
|
|
141
|
-
export type CreateNewStatusListArgs = CreateNewStatusListFuncArgs & {
|
|
142
|
-
dataSource?: OrPromise<DataSource>
|
|
143
|
-
dbName?: string
|
|
144
|
-
isDefault?: boolean
|
|
145
|
-
}
|
|
146
|
-
|
|
147
247
|
export type CredentialWithStatusSupport = ICredential | CredentialPayload | IVerifiableCredential
|
|
148
248
|
|
|
249
|
+
export type SignedStatusListData = {
|
|
250
|
+
statusListCredential: StatusListCredential
|
|
251
|
+
encodedList: string
|
|
252
|
+
}
|
|
253
|
+
|
|
149
254
|
export type IRequiredPlugins = ICredentialPlugin & IIdentifierResolution
|
|
150
|
-
export type IRequiredContext = IAgentContext<ICredentialIssuer & ICredentialVerifier & IIdentifierResolution>
|
|
255
|
+
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
|
+
}
|