@sphereon/ssi-sdk.vc-status-list-issuer-rest-api 0.32.1-next.54 → 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/dist/index.cjs +455 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +76 -0
- package/dist/index.d.ts +76 -7
- package/dist/index.js +422 -21
- package/dist/index.js.map +1 -1
- package/package.json +36 -24
- package/src/api-functions.ts +217 -71
- package/src/statuslist-management-api-server.ts +4 -2
- package/src/types.ts +18 -1
- package/dist/api-functions.d.ts +0 -7
- package/dist/api-functions.d.ts.map +0 -1
- package/dist/api-functions.js +0 -194
- package/dist/api-functions.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/statuslist-management-api-server.d.ts +0 -22
- package/dist/statuslist-management-api-server.d.ts.map +0 -1
- package/dist/statuslist-management-api-server.js +0 -67
- package/dist/statuslist-management-api-server.js.map +0 -1
- package/dist/types.d.ts +0 -38
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,41 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.vc-status-list-issuer-rest-api",
|
|
3
3
|
"description": "Sphereon SSI-SDK plugin for Status List management, like StatusList2021. Issuer drivers module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.33.1-feature.jose.vcdm.55+6f02f6f8",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
"react-native": "./dist/index.js",
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./dist/index.d.cts",
|
|
18
|
+
"require": "./dist/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
8
21
|
"scripts": {
|
|
9
|
-
"build": "
|
|
10
|
-
"build:clean": "tsc --build --clean && tsc --build",
|
|
22
|
+
"build": "tsup --config ../../tsup.config.ts --tsconfig ../../tsconfig.tsup.json",
|
|
11
23
|
"start:dev": "node --experimental-specifier-resolution=node --loader ts-node/esm __tests__/agent.ts",
|
|
12
24
|
"start:dev2": "node --experimental-specifier-resolution=node --loader ts-node/esm __tests__/agent.ts"
|
|
13
25
|
},
|
|
14
26
|
"dependencies": {
|
|
15
|
-
"@sphereon/ssi-express-support": "0.
|
|
16
|
-
"@sphereon/ssi-sdk-ext.did-utils": "0.
|
|
17
|
-
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.
|
|
18
|
-
"@sphereon/ssi-sdk.
|
|
19
|
-
"@sphereon/ssi-sdk.
|
|
20
|
-
"@sphereon/ssi-sdk.
|
|
21
|
-
"@sphereon/ssi-sdk.vc-status-list
|
|
22
|
-
"@sphereon/ssi-
|
|
27
|
+
"@sphereon/ssi-express-support": "0.33.1-feature.jose.vcdm.55+6f02f6f8",
|
|
28
|
+
"@sphereon/ssi-sdk-ext.did-utils": "0.28.1-feature.esm.cjs.18",
|
|
29
|
+
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.28.1-feature.esm.cjs.18",
|
|
30
|
+
"@sphereon/ssi-sdk-ext.jwt-service": "0.28.1-feature.esm.cjs.18",
|
|
31
|
+
"@sphereon/ssi-sdk.core": "0.33.1-feature.jose.vcdm.55+6f02f6f8",
|
|
32
|
+
"@sphereon/ssi-sdk.data-store": "0.33.1-feature.jose.vcdm.55+6f02f6f8",
|
|
33
|
+
"@sphereon/ssi-sdk.vc-status-list": "0.33.1-feature.jose.vcdm.55+6f02f6f8",
|
|
34
|
+
"@sphereon/ssi-sdk.vc-status-list-issuer-drivers": "0.33.1-feature.jose.vcdm.55+6f02f6f8",
|
|
35
|
+
"@sphereon/ssi-types": "0.33.1-feature.jose.vcdm.55+6f02f6f8",
|
|
23
36
|
"@sphereon/vc-status-list": "7.0.0-next.0",
|
|
24
37
|
"@veramo/core": "4.2.0",
|
|
25
38
|
"debug": "^4.3.5",
|
|
26
39
|
"express": "^4.19.2",
|
|
27
|
-
"reflect-metadata": "^0.
|
|
28
|
-
"typeorm": "
|
|
40
|
+
"reflect-metadata": "^0.2.2",
|
|
41
|
+
"typeorm": "0.3.20",
|
|
29
42
|
"uint8arrays": "^3.1.1",
|
|
30
43
|
"uuid": "^9.0.1"
|
|
31
44
|
},
|
|
32
45
|
"devDependencies": {
|
|
33
46
|
"@sphereon/did-uni-client": "^0.6.3",
|
|
34
|
-
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.
|
|
35
|
-
"@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.
|
|
36
|
-
"@sphereon/ssi-sdk.agent-config": "0.
|
|
47
|
+
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.28.1-feature.esm.cjs.18",
|
|
48
|
+
"@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.28.1-feature.esm.cjs.18",
|
|
49
|
+
"@sphereon/ssi-sdk.agent-config": "0.33.1-feature.jose.vcdm.55+6f02f6f8",
|
|
50
|
+
"@sphereon/ssi-sdk.credential-jsonld": "0.33.1-feature.jose.vcdm.55+6f02f6f8",
|
|
37
51
|
"@sphereon/ssi-sdk.data-store": "workspace:*",
|
|
38
|
-
"@sphereon/ssi-sdk.vc-handler-ld-local": "0.32.1-next.54+3b988a2b",
|
|
39
52
|
"@types/body-parser": "^1.19.5",
|
|
40
53
|
"@types/cookie-parser": "^1.4.7",
|
|
41
54
|
"@types/cors": "^2.8.17",
|
|
@@ -58,11 +71,11 @@
|
|
|
58
71
|
"@veramo/utils": "4.2.0",
|
|
59
72
|
"did-resolver": "^4.1.0",
|
|
60
73
|
"morgan": "^1.10.0",
|
|
61
|
-
"typescript": "5.
|
|
74
|
+
"typescript": "5.8.3"
|
|
62
75
|
},
|
|
63
76
|
"files": [
|
|
64
|
-
"dist
|
|
65
|
-
"src
|
|
77
|
+
"dist",
|
|
78
|
+
"src",
|
|
66
79
|
"README.md",
|
|
67
80
|
"LICENSE"
|
|
68
81
|
],
|
|
@@ -78,6 +91,5 @@
|
|
|
78
91
|
"SSI",
|
|
79
92
|
"StatusList2021"
|
|
80
93
|
],
|
|
81
|
-
"
|
|
82
|
-
"gitHead": "3b988a2bb62a7c4534a2670ea3a0985fd93d00f2"
|
|
94
|
+
"gitHead": "6f02f6f83679198268c6e1ea956be24cc1017234"
|
|
83
95
|
}
|
package/src/api-functions.ts
CHANGED
|
@@ -2,15 +2,55 @@ import { checkAuth, sendErrorResponse } from '@sphereon/ssi-express-support'
|
|
|
2
2
|
import {
|
|
3
3
|
checkStatusIndexFromStatusListCredential,
|
|
4
4
|
CreateNewStatusListFuncArgs,
|
|
5
|
+
StatusListResult,
|
|
5
6
|
updateStatusIndexFromStatusListCredential,
|
|
6
7
|
} from '@sphereon/ssi-sdk.vc-status-list'
|
|
7
8
|
import { getDriver } from '@sphereon/ssi-sdk.vc-status-list-issuer-drivers'
|
|
8
9
|
import Debug from 'debug'
|
|
9
10
|
import { Request, Response, Router } from 'express'
|
|
10
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
EntryIdType,
|
|
13
|
+
ICredentialStatusListEndpointOpts,
|
|
14
|
+
IRequiredContext,
|
|
15
|
+
IW3CredentialStatusEndpointOpts,
|
|
16
|
+
StatusListIdType,
|
|
17
|
+
UpdateIndexedCredentialStatusRequest,
|
|
18
|
+
UpdateW3cCredentialStatusRequest,
|
|
19
|
+
} from './types'
|
|
20
|
+
import { StatusListCredential, StatusListType } from '@sphereon/ssi-types'
|
|
21
|
+
import { IStatusListEntryEntity } from '@sphereon/ssi-sdk.data-store'
|
|
11
22
|
|
|
12
23
|
const debug = Debug('sphereon:ssi-sdk:status-list')
|
|
13
24
|
|
|
25
|
+
function sendStatuslistResponse(details: StatusListResult, statuslistPayload: StatusListCredential, response: Response) {
|
|
26
|
+
let payload: Buffer | StatusListCredential
|
|
27
|
+
|
|
28
|
+
switch (details.proofFormat) {
|
|
29
|
+
case 'jwt':
|
|
30
|
+
case 'cbor':
|
|
31
|
+
payload = Buffer.from(statuslistPayload as string, 'ascii')
|
|
32
|
+
break
|
|
33
|
+
default:
|
|
34
|
+
payload = statuslistPayload
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return response.status(200).setHeader('Content-Type', details.statuslistContentType).send(payload)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function buildStatusListId(request: Request): string {
|
|
41
|
+
const protocol = request.headers['x-forwarded-proto']?.toString() ?? request.protocol
|
|
42
|
+
let host = request.headers['x-forwarded-host']?.toString() ?? request.get('host')
|
|
43
|
+
const forwardedPort = request.headers['x-forwarded-port']?.toString()
|
|
44
|
+
|
|
45
|
+
if (forwardedPort && !(protocol === 'https' && forwardedPort === '443') && !(protocol === 'http' && forwardedPort === '80')) {
|
|
46
|
+
host += `:${forwardedPort}`
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const forwardedPrefix = request.headers['x-forwarded-prefix']?.toString() ?? ''
|
|
50
|
+
|
|
51
|
+
return `${protocol}://${host}${forwardedPrefix}${request.originalUrl.split('?')[0].replace(/\/status\/index\/.*/, '')}`
|
|
52
|
+
}
|
|
53
|
+
|
|
14
54
|
export function createNewStatusListEndpoint(router: Router, context: IRequiredContext, opts: ICredentialStatusListEndpointOpts) {
|
|
15
55
|
if (opts?.enabled === false) {
|
|
16
56
|
console.log(`Create new status list endpoint is disabled`)
|
|
@@ -24,26 +64,15 @@ export function createNewStatusListEndpoint(router: Router, context: IRequiredCo
|
|
|
24
64
|
if (!statusListArgs) {
|
|
25
65
|
return sendErrorResponse(response, 400, 'No statusList details supplied')
|
|
26
66
|
}
|
|
27
|
-
const
|
|
28
|
-
|
|
67
|
+
const details = await context.agent.slCreateStatusList(statusListArgs)
|
|
68
|
+
const statuslistPayload = details.statusListCredential
|
|
69
|
+
return sendStatuslistResponse(details, statuslistPayload, response)
|
|
29
70
|
} catch (e) {
|
|
30
|
-
return sendErrorResponse(response, 500, e
|
|
71
|
+
return sendErrorResponse(response, 500, (e as Error).message, e)
|
|
31
72
|
}
|
|
32
73
|
})
|
|
33
74
|
}
|
|
34
75
|
|
|
35
|
-
const buildStatusListId = (request: Request): string => {
|
|
36
|
-
const protocol = request.headers['x-forwarded-proto']?.toString() ?? request.protocol
|
|
37
|
-
let host = request.headers['x-forwarded-host']?.toString() ?? request.get('host')
|
|
38
|
-
const forwardedPort = request.headers['x-forwarded-port']?.toString()
|
|
39
|
-
|
|
40
|
-
if (forwardedPort && !(protocol === 'https' && forwardedPort === '443') && !(protocol === 'http' && forwardedPort === '80')) {
|
|
41
|
-
host += `:${forwardedPort}`
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return `${protocol}://${host}${request.originalUrl}`
|
|
45
|
-
}
|
|
46
|
-
|
|
47
76
|
export function getStatusListCredentialEndpoint(router: Router, context: IRequiredContext, opts: ICredentialStatusListEndpointOpts) {
|
|
48
77
|
if (opts?.enabled === false) {
|
|
49
78
|
console.log(`Get statusList credential endpoint is disabled`)
|
|
@@ -53,13 +82,17 @@ export function getStatusListCredentialEndpoint(router: Router, context: IRequir
|
|
|
53
82
|
router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
54
83
|
try {
|
|
55
84
|
//todo: Check index against correlationId first. Then match originalUrl against statusList id
|
|
56
|
-
const correlationId = request.query.correlationId?.toString() ?? request.params.index?.toString() ?? request.originalUrl
|
|
57
|
-
const
|
|
85
|
+
//const correlationId = request.query.correlationId?.toString() ?? request.params.index?.toString() ?? request.originalUrl TODO I so not get these
|
|
86
|
+
const correlationId = request.query.correlationId?.toString()
|
|
87
|
+
const driver = await getDriver({
|
|
88
|
+
...(correlationId ? { correlationId } : { id: buildStatusListId(request) }),
|
|
89
|
+
dbName: opts.dbName,
|
|
90
|
+
})
|
|
58
91
|
const details = await driver.getStatusList()
|
|
59
|
-
|
|
60
|
-
return
|
|
92
|
+
const statuslistPayload = details.statusListCredential
|
|
93
|
+
return sendStatuslistResponse(details, statuslistPayload, response)
|
|
61
94
|
} catch (e) {
|
|
62
|
-
return sendErrorResponse(response, 500, e
|
|
95
|
+
return sendErrorResponse(response, 500, (e as Error).message, e)
|
|
63
96
|
}
|
|
64
97
|
})
|
|
65
98
|
}
|
|
@@ -69,6 +102,84 @@ export function getStatusListCredentialIndexStatusEndpoint(router: Router, conte
|
|
|
69
102
|
console.log(`Get statusList credential index status endpoint is disabled`)
|
|
70
103
|
return
|
|
71
104
|
}
|
|
105
|
+
|
|
106
|
+
const path = opts?.path ?? '/status-lists/:statusListId/status/entry-by-id/:entryId'
|
|
107
|
+
router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
108
|
+
try {
|
|
109
|
+
const statusListIdType = (request.query.statusListIdType as StatusListIdType) ?? StatusListIdType.StatusListId
|
|
110
|
+
const entryIdType = (request.query.entryIdType as EntryIdType) ?? EntryIdType.StatusListIndex
|
|
111
|
+
|
|
112
|
+
let statusListIndex: number | undefined
|
|
113
|
+
let entityCorrelationId: string | undefined
|
|
114
|
+
let statusListId: string | undefined
|
|
115
|
+
let statusListCorrelationId: string | undefined
|
|
116
|
+
|
|
117
|
+
if (entryIdType === EntryIdType.StatusListIndex) {
|
|
118
|
+
try {
|
|
119
|
+
statusListIndex = Number.parseInt(request.params.entryId)
|
|
120
|
+
if (!statusListIndex || statusListIndex < 0) {
|
|
121
|
+
return sendErrorResponse(response, 400, `Please provide a proper statusListIndex`)
|
|
122
|
+
}
|
|
123
|
+
} catch (error) {
|
|
124
|
+
return sendErrorResponse(response, 400, `Please provide a proper statusListIndex`)
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
entityCorrelationId = request.params.entryId
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (statusListIdType === StatusListIdType.StatusListId) {
|
|
131
|
+
statusListId = request.params.statusListId
|
|
132
|
+
} else {
|
|
133
|
+
statusListCorrelationId = request.params.statusListId
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const driver = await getDriver({
|
|
137
|
+
...(statusListCorrelationId ? { correlationId: statusListCorrelationId } : { id: statusListId }),
|
|
138
|
+
dbName: opts.dbName,
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
const details = await driver.getStatusList()
|
|
142
|
+
if (statusListIndex && statusListIndex > details.length) {
|
|
143
|
+
return sendErrorResponse(response, 400, `Please provide a proper statusListIndex`)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
let entry = await driver.getStatusListEntryByIndex({
|
|
147
|
+
statusListId: details.id,
|
|
148
|
+
...(entityCorrelationId ? { correlationId: entityCorrelationId } : { statusListIndex }),
|
|
149
|
+
errorOnNotFound: false,
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
const type = details.type === StatusListType.StatusList2021 ? 'StatusList2021Entry' : details.type
|
|
153
|
+
const resultStatusIndex = entry?.statusListIndex ?? statusListIndex ?? 0
|
|
154
|
+
const status = await checkStatusIndexFromStatusListCredential({
|
|
155
|
+
statusListCredential: details.statusListCredential,
|
|
156
|
+
...(details.type === StatusListType.StatusList2021 ? { statusPurpose: details.statusList2021?.statusPurpose } : {}),
|
|
157
|
+
type,
|
|
158
|
+
id: details.id,
|
|
159
|
+
statusListIndex: resultStatusIndex,
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
if (!entry) {
|
|
163
|
+
entry = {
|
|
164
|
+
statusListId: details.id,
|
|
165
|
+
value: '0',
|
|
166
|
+
statusListIndex: resultStatusIndex,
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
response.statusCode = 200
|
|
171
|
+
return response.json({ ...entry, status })
|
|
172
|
+
} catch (e) {
|
|
173
|
+
return sendErrorResponse(response, 500, (e as Error).message, e)
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function getStatusListCredentialIndexStatusEndpointLegacy(router: Router, context: IRequiredContext, opts: ICredentialStatusListEndpointOpts) {
|
|
179
|
+
if (opts?.enabled === false) {
|
|
180
|
+
console.log(`Get statusList credential index status endpoint is disabled`)
|
|
181
|
+
return
|
|
182
|
+
}
|
|
72
183
|
const path = opts?.path ?? '/status-lists/:index/status/index/:statusListIndex'
|
|
73
184
|
router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
74
185
|
try {
|
|
@@ -83,10 +194,10 @@ export function getStatusListCredentialIndexStatusEndpoint(router: Router, conte
|
|
|
83
194
|
if (!statusListIndex || statusListIndex < 0) {
|
|
84
195
|
return sendErrorResponse(response, 400, `Please provide a proper statusListIndex`)
|
|
85
196
|
}
|
|
86
|
-
const correlationId = request.query.correlationId?.toString() ?? request.params.index?.toString() ?? request.originalUrl
|
|
197
|
+
//const correlationId = request.query.correlationId?.toString() ?? request.params.index?.toString() ?? request.originalUrl TODO I so not get these
|
|
198
|
+
const statusListCorrelationId = request.query.correlationId?.toString()
|
|
87
199
|
const driver = await getDriver({
|
|
88
|
-
|
|
89
|
-
correlationId,
|
|
200
|
+
...(statusListCorrelationId ? { correlationId: statusListCorrelationId } : { id: buildStatusListId(request) }),
|
|
90
201
|
dbName: opts.dbName,
|
|
91
202
|
})
|
|
92
203
|
const details = await driver.getStatusList()
|
|
@@ -94,29 +205,37 @@ export function getStatusListCredentialIndexStatusEndpoint(router: Router, conte
|
|
|
94
205
|
return sendErrorResponse(response, 400, `Please provide a proper statusListIndex`)
|
|
95
206
|
}
|
|
96
207
|
|
|
208
|
+
const entityCorrelationId = request.query.entityCorrelationId?.toString()
|
|
97
209
|
let entry = await driver.getStatusListEntryByIndex({
|
|
98
|
-
statusListIndex,
|
|
99
210
|
statusListId: details.id,
|
|
100
|
-
correlationId:
|
|
211
|
+
...(entityCorrelationId ? { correlationId: entityCorrelationId } : { statusListIndex: statusListIndex }),
|
|
101
212
|
errorOnNotFound: false,
|
|
102
213
|
})
|
|
103
|
-
const
|
|
214
|
+
const type = details.type === StatusListType.StatusList2021 ? 'StatusList2021Entry' : details.type
|
|
215
|
+
const status = await checkStatusIndexFromStatusListCredential({
|
|
216
|
+
statusListCredential: details.statusListCredential,
|
|
217
|
+
...(details.type === StatusListType.StatusList2021 ? { statusPurpose: details.statusList2021?.statusPurpose } : {}),
|
|
218
|
+
type,
|
|
219
|
+
id: details.id,
|
|
220
|
+
statusListIndex,
|
|
221
|
+
})
|
|
104
222
|
if (!entry) {
|
|
105
223
|
// The fact we have nothing on it means the status is okay
|
|
106
224
|
entry = {
|
|
107
|
-
|
|
225
|
+
statusListId: details.id,
|
|
108
226
|
value: '0',
|
|
109
227
|
statusListIndex,
|
|
110
228
|
}
|
|
111
229
|
}
|
|
112
230
|
response.statusCode = 200
|
|
113
|
-
return response.
|
|
231
|
+
return response.json({ ...entry, status })
|
|
114
232
|
} catch (e) {
|
|
115
|
-
return sendErrorResponse(response, 500, e
|
|
233
|
+
return sendErrorResponse(response, 500, (e as Error).message, e)
|
|
116
234
|
}
|
|
117
235
|
})
|
|
118
236
|
}
|
|
119
|
-
|
|
237
|
+
|
|
238
|
+
export function updateStatusEndpoint(router: Router, context: IRequiredContext, opts: IW3CredentialStatusEndpointOpts) {
|
|
120
239
|
if (opts?.enabled === false) {
|
|
121
240
|
console.log(`Update credential status endpoint is disabled`)
|
|
122
241
|
return
|
|
@@ -124,65 +243,92 @@ export function updateW3CStatusEndpoint(router: Router, context: IRequiredContex
|
|
|
124
243
|
router.post(opts?.path ?? '/credentials/status', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
125
244
|
try {
|
|
126
245
|
debug(JSON.stringify(request.body, null, 2))
|
|
127
|
-
const updateRequest = request.body as
|
|
128
|
-
const statusListId = updateRequest.statusListId ?? request.query.statusListId?.toString() ?? opts.statusListId
|
|
129
|
-
const statusListCorrelationId = updateRequest.statusListCorrelationId ?? request.query.
|
|
246
|
+
const updateRequest = request.body as UpdateW3cCredentialStatusRequest | UpdateIndexedCredentialStatusRequest
|
|
247
|
+
const statusListId = updateRequest.statusListId ?? request.query.statusListId?.toString() ?? opts.statusListId // TODO why query params when we have a JSON body ??
|
|
248
|
+
const statusListCorrelationId = updateRequest.statusListCorrelationId ?? request.query.statusListrelationId?.toString() ?? opts.correlationId
|
|
130
249
|
const entryCorrelationId = updateRequest.entryCorrelationId ?? request.query.entryCorrelationId?.toString()
|
|
131
|
-
const credentialId = updateRequest.credentialId
|
|
132
250
|
|
|
133
251
|
// TODO: Move mostly to driver
|
|
134
|
-
if (!
|
|
135
|
-
return sendErrorResponse(response, 400, 'No statusList
|
|
252
|
+
if (!statusListId && !statusListCorrelationId) {
|
|
253
|
+
return sendErrorResponse(response, 400, 'No statusList id or correlation Id provided or deduced for the API or in the request')
|
|
136
254
|
} else if (!updateRequest.credentialStatus || updateRequest.credentialStatus.length === 0) {
|
|
137
255
|
return sendErrorResponse(response, 400, 'No statusList updates supplied')
|
|
138
|
-
} else if (!statusListId && !statusListCorrelationId) {
|
|
139
|
-
return sendErrorResponse(response, 400, 'No statusList id or correlation Id provided or deduced for the API or in the request')
|
|
140
256
|
}
|
|
141
|
-
const driver = await getDriver({
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
statusListId,
|
|
145
|
-
statusListCorrelationId,
|
|
146
|
-
entryCorrelationId,
|
|
147
|
-
credentialId,
|
|
148
|
-
errorOnNotFound: true,
|
|
257
|
+
const driver = await getDriver({
|
|
258
|
+
...(statusListCorrelationId ? { correlationId: statusListCorrelationId } : { id: buildStatusListId(request) }),
|
|
259
|
+
dbName: opts.dbName,
|
|
149
260
|
})
|
|
261
|
+
let statusListResult: StatusListResult = await driver.getStatusList()
|
|
262
|
+
|
|
263
|
+
// Get status list entry based on request type
|
|
264
|
+
let statusListEntry: IStatusListEntryEntity | undefined
|
|
265
|
+
if ('credentialId' in updateRequest) {
|
|
266
|
+
if (!updateRequest.credentialId) {
|
|
267
|
+
return sendErrorResponse(response, 400, 'No credentialId supplied')
|
|
268
|
+
}
|
|
269
|
+
// unfortunately the W3C API works by credentialId. Which means you will have to map listIndices during issuance
|
|
270
|
+
statusListEntry = await driver.getStatusListEntryByCredentialId({
|
|
271
|
+
statusListId,
|
|
272
|
+
statusListCorrelationId,
|
|
273
|
+
entryCorrelationId,
|
|
274
|
+
credentialId: updateRequest.credentialId,
|
|
275
|
+
errorOnNotFound: true,
|
|
276
|
+
})
|
|
277
|
+
} else {
|
|
278
|
+
statusListEntry = await driver.getStatusListEntryByIndex({
|
|
279
|
+
...(statusListResult.id && { statusListId: statusListResult.id }),
|
|
280
|
+
...(statusListResult.correlationId && { statusListCorrelationId: statusListResult.correlationId }),
|
|
281
|
+
...(entryCorrelationId ? { entryCorrelationId } : { statusListIndex: updateRequest.statusListIndex }),
|
|
282
|
+
errorOnNotFound: true,
|
|
283
|
+
})
|
|
284
|
+
}
|
|
285
|
+
|
|
150
286
|
if (!statusListEntry) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
404,
|
|
154
|
-
`status list index for credential id ${credentialId} was never recorded for ${statusListId}. This means the status will be 0`,
|
|
155
|
-
)
|
|
287
|
+
const identifier = 'credentialId' in updateRequest ? updateRequest.credentialId : `index ${updateRequest.statusListIndex}`
|
|
288
|
+
return sendErrorResponse(response, 404, `Status list entry for ${identifier} not found for ${statusListId}`)
|
|
156
289
|
}
|
|
157
|
-
const statusListIndex = statusListEntry.statusListIndex
|
|
158
|
-
let details = await driver.getStatusList()
|
|
159
|
-
let statusListCredential = details.statusListCredential
|
|
160
290
|
|
|
291
|
+
let statusListCredential = statusListResult.statusListCredential
|
|
161
292
|
for (const updateItem of updateRequest.credentialStatus) {
|
|
162
|
-
if (updateItem.
|
|
163
|
-
return sendErrorResponse(response, 400, `
|
|
293
|
+
if (!updateItem.status) {
|
|
294
|
+
return sendErrorResponse(response, 400, `Required 'status' value was missing in the credentialStatus array`)
|
|
164
295
|
}
|
|
165
296
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
297
|
+
let value: string = '1'
|
|
298
|
+
if (updateItem.status === '0' || updateItem.status.toLowerCase() === 'false') {
|
|
299
|
+
value = '0'
|
|
300
|
+
} else if (updateItem.status !== '1' && updateItem.status.toLowerCase() !== 'true') {
|
|
301
|
+
if (updateItem.type === StatusListType.StatusList2021) {
|
|
302
|
+
// 2021 only allows 0 and 1
|
|
303
|
+
return sendErrorResponse(response, 400, `Invalid 'status' value in the credentialStatus array: ${updateItem.status}`)
|
|
304
|
+
} else if (parseInt(updateItem.status) < 0 || parseInt(updateItem.status) > 255) {
|
|
305
|
+
return sendErrorResponse(response, 400, `Invalid 'status' value in the credentialStatus array: ${updateItem.status}`)
|
|
306
|
+
}
|
|
307
|
+
value = `${parseInt(updateItem.status)}`
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const updStatusListId = statusListId ?? statusListEntry.statusList?.id // When input was statusListCorrelationId the statusList id should come from statusListEntry
|
|
311
|
+
if (!updStatusListId) {
|
|
312
|
+
return sendErrorResponse(response, 400, 'statuslist id could not be determined')
|
|
172
313
|
}
|
|
173
|
-
|
|
174
|
-
const statusList = statusListId ?? statusListEntry.statusList
|
|
175
|
-
await driver.updateStatusListEntry({ ...statusListEntry, statusListIndex, statusList, credentialId, value: value ? '1' : '0' })
|
|
314
|
+
await driver.updateStatusListEntry({ ...statusListEntry, statusListId: updStatusListId, value })
|
|
176
315
|
|
|
177
316
|
// todo: optimize. We are now creating a new VC for every item passed in. Probably wise to look at DB as well
|
|
178
|
-
|
|
179
|
-
|
|
317
|
+
statusListResult = await updateStatusIndexFromStatusListCredential(
|
|
318
|
+
{
|
|
319
|
+
statusListCredential: statusListCredential,
|
|
320
|
+
statusListIndex: statusListEntry.statusListIndex,
|
|
321
|
+
value: parseInt(value),
|
|
322
|
+
keyRef: opts.keyRef,
|
|
323
|
+
},
|
|
324
|
+
context,
|
|
325
|
+
)
|
|
326
|
+
statusListResult = await driver.updateStatusList({ statusListCredential: statusListResult.statusListCredential })
|
|
180
327
|
}
|
|
181
328
|
|
|
182
|
-
|
|
183
|
-
return response.send(details.statusListCredential)
|
|
329
|
+
return sendStatuslistResponse(statusListResult, statusListResult.statusListCredential, response)
|
|
184
330
|
} catch (e) {
|
|
185
|
-
return sendErrorResponse(response, 500, e
|
|
331
|
+
return sendErrorResponse(response, 500, (e as Error).message, e)
|
|
186
332
|
}
|
|
187
333
|
})
|
|
188
334
|
}
|
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
createNewStatusListEndpoint,
|
|
9
9
|
getStatusListCredentialEndpoint,
|
|
10
10
|
getStatusListCredentialIndexStatusEndpoint,
|
|
11
|
-
|
|
11
|
+
getStatusListCredentialIndexStatusEndpointLegacy,
|
|
12
|
+
updateStatusEndpoint,
|
|
12
13
|
} from './api-functions'
|
|
13
14
|
import { IStatusListOpts } from './types'
|
|
14
15
|
import { IRequiredPlugins } from '@sphereon/ssi-sdk.vc-status-list-issuer-drivers'
|
|
@@ -48,9 +49,10 @@ export class StatuslistManagementApiServer {
|
|
|
48
49
|
if (features.includes('status-list-hosting')) {
|
|
49
50
|
getStatusListCredentialEndpoint(this.router, context, opts.endpointOpts.getStatusList)
|
|
50
51
|
getStatusListCredentialIndexStatusEndpoint(this.router, context, opts.endpointOpts.getStatusList)
|
|
52
|
+
getStatusListCredentialIndexStatusEndpointLegacy(this.router, context, opts.endpointOpts.getStatusList)
|
|
51
53
|
}
|
|
52
54
|
if (features.includes('w3c-vc-api-credential-status')) {
|
|
53
|
-
|
|
55
|
+
updateStatusEndpoint(this.router, context, opts.endpointOpts.vcApiCredentialStatus)
|
|
54
56
|
}
|
|
55
57
|
this._express.use(opts?.endpointOpts?.basePath ?? '', this.router)
|
|
56
58
|
}
|
package/src/types.ts
CHANGED
|
@@ -31,8 +31,15 @@ export interface IW3CredentialStatusEndpointOpts extends ICredentialStatusListEn
|
|
|
31
31
|
keyRef?: string
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export interface UpdateCredentialStatusRequest {
|
|
34
|
+
export interface UpdateW3cCredentialStatusRequest extends UpdateCredentialStatusRequest {
|
|
35
35
|
credentialId: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface UpdateIndexedCredentialStatusRequest extends UpdateCredentialStatusRequest {
|
|
39
|
+
statusListIndex?: number
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface UpdateCredentialStatusRequest {
|
|
36
43
|
credentialStatus: UpdateCredentialStatusItem[]
|
|
37
44
|
statusListId?: string // Non spec compliant. Allows us to manage multiple status lists. The VC API endpoint also has this config option, allowing for a default
|
|
38
45
|
statusListCorrelationId?: string // Non spec compliant. Allows us to manage multiple status lists. The VC API endpoint also has this config option, allowing for a default
|
|
@@ -43,3 +50,13 @@ export interface UpdateCredentialStatusItem {
|
|
|
43
50
|
type?: StatusListType // makes very little sense, but listed in the spec. Would expect a purpose
|
|
44
51
|
status: string
|
|
45
52
|
}
|
|
53
|
+
|
|
54
|
+
export enum StatusListIdType {
|
|
55
|
+
StatusListId = 'StatusListId',
|
|
56
|
+
StatusListCorrelationId = 'StatusListCorrelationId',
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export enum EntryIdType {
|
|
60
|
+
StatusListIndex = 'StatusListIndex',
|
|
61
|
+
EntryCorrelationId = 'StatusListCorrelationId',
|
|
62
|
+
}
|
package/dist/api-functions.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Router } from 'express';
|
|
2
|
-
import { ICredentialStatusListEndpointOpts, IRequiredContext, IW3CredentialStatusEndpointOpts } from './types';
|
|
3
|
-
export declare function createNewStatusListEndpoint(router: Router, context: IRequiredContext, opts: ICredentialStatusListEndpointOpts): void;
|
|
4
|
-
export declare function getStatusListCredentialEndpoint(router: Router, context: IRequiredContext, opts: ICredentialStatusListEndpointOpts): void;
|
|
5
|
-
export declare function getStatusListCredentialIndexStatusEndpoint(router: Router, context: IRequiredContext, opts: ICredentialStatusListEndpointOpts): void;
|
|
6
|
-
export declare function updateW3CStatusEndpoint(router: Router, context: IRequiredContext, opts: IW3CredentialStatusEndpointOpts): void;
|
|
7
|
-
//# sourceMappingURL=api-functions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api-functions.d.ts","sourceRoot":"","sources":["../src/api-functions.ts"],"names":[],"mappings":"AAQA,OAAO,EAAqB,MAAM,EAAE,MAAM,SAAS,CAAA;AACnD,OAAO,EAAE,iCAAiC,EAAE,gBAAgB,EAAE,+BAA+B,EAAiC,MAAM,SAAS,CAAA;AAI7I,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,iCAAiC,QAmB7H;AAcD,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,iCAAiC,QAkBjI;AAED,wBAAgB,0CAA0C,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,iCAAiC,QAmD5I;AACD,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,+BAA+B,QAqEvH"}
|