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