@sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-api 0.34.1-feature.SSISDK.45.94 → 0.34.1-feature.SSISDK.46.40
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 +207 -119
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +80 -7
- package/dist/index.d.ts +80 -7
- package/dist/index.js +203 -115
- package/dist/index.js.map +1 -1
- package/package.json +22 -19
- package/src/index.ts +1 -1
- package/src/middleware/validationMiddleware.ts +20 -0
- package/src/schemas/index.ts +50 -0
- package/src/siop-api-functions.ts +19 -9
- package/src/siopv2-rp-api-server.ts +7 -7
- package/src/types/types.ts +42 -1
- package/src/universal-oid4vp-api-functions.ts +172 -0
- package/src/webapp-api-functions.ts +0 -183
package/dist/index.cjs
CHANGED
|
@@ -32,16 +32,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
32
32
|
var index_exports = {};
|
|
33
33
|
__export(index_exports, {
|
|
34
34
|
SIOPv2RPApiServer: () => SIOPv2RPApiServer,
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
authStatusUniversalOID4VPEndpoint: () => authStatusUniversalOID4VPEndpoint,
|
|
36
|
+
createAuthRequestUniversalOID4VPEndpoint: () => createAuthRequestUniversalOID4VPEndpoint,
|
|
37
37
|
getAuthRequestSIOPv2Endpoint: () => getAuthRequestSIOPv2Endpoint,
|
|
38
38
|
getDefinitionsEndpoint: () => getDefinitionsEndpoint,
|
|
39
|
-
|
|
39
|
+
removeAuthRequestStateUniversalOID4VPEndpoint: () => removeAuthRequestStateUniversalOID4VPEndpoint,
|
|
40
40
|
verifyAuthResponseSIOPv2Endpoint: () => verifyAuthResponseSIOPv2Endpoint
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(index_exports);
|
|
43
43
|
|
|
44
44
|
// src/siop-api-functions.ts
|
|
45
|
+
var import_did_auth_siop = require("@sphereon/did-auth-siop");
|
|
45
46
|
var import_ssi_express_support = require("@sphereon/ssi-express-support");
|
|
46
47
|
var import_ssi_types = require("@sphereon/ssi-types");
|
|
47
48
|
var parseAuthorizationResponse = /* @__PURE__ */ __name((request) => {
|
|
@@ -74,7 +75,7 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
74
75
|
const path = opts?.path ?? "/siop/definitions/:definitionId/auth-responses/:correlationId";
|
|
75
76
|
router.post(path, (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
76
77
|
try {
|
|
77
|
-
const { correlationId, definitionId, tenantId, version
|
|
78
|
+
const { correlationId, definitionId, tenantId, version } = request.params;
|
|
78
79
|
if (!correlationId || !definitionId) {
|
|
79
80
|
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`);
|
|
80
81
|
return (0, import_ssi_express_support.sendErrorResponse)(response, 404, "No authorization request could be found");
|
|
@@ -102,10 +103,16 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
102
103
|
const verifiedResponse = await context.agent.siopVerifyAuthResponse({
|
|
103
104
|
authorizationResponse,
|
|
104
105
|
correlationId,
|
|
105
|
-
definitionId,
|
|
106
|
+
queryId: definitionId,
|
|
107
|
+
presentationDefinitions: [
|
|
108
|
+
{
|
|
109
|
+
location: opts?.presentationDefinitionLocation ?? import_did_auth_siop.PresentationDefinitionLocation.TOPLEVEL_PRESENTATION_DEF,
|
|
110
|
+
definition: definitionItem.definitionPayload
|
|
111
|
+
}
|
|
112
|
+
],
|
|
106
113
|
dcqlQuery: definitionItem.dcqlPayload
|
|
107
114
|
});
|
|
108
|
-
const wrappedPresentation = verifiedResponse?.oid4vpSubmission?.
|
|
115
|
+
const wrappedPresentation = verifiedResponse?.oid4vpSubmission?.presentations[0];
|
|
109
116
|
if (wrappedPresentation) {
|
|
110
117
|
console.log("PRESENTATION:" + JSON.stringify(wrappedPresentation.presentation, null, 2));
|
|
111
118
|
response.statusCode = 200;
|
|
@@ -118,7 +125,7 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
118
125
|
}
|
|
119
126
|
const responseRedirectURI = await context.agent.siopGetRedirectURI({
|
|
120
127
|
correlationId,
|
|
121
|
-
definitionId,
|
|
128
|
+
queryId: definitionId,
|
|
122
129
|
state: verifiedResponse.state
|
|
123
130
|
});
|
|
124
131
|
if (responseRedirectURI) {
|
|
@@ -156,7 +163,7 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
156
163
|
}
|
|
157
164
|
const requestState = await context.agent.siopGetAuthRequestState({
|
|
158
165
|
correlationId,
|
|
159
|
-
definitionId,
|
|
166
|
+
queryId: definitionId,
|
|
160
167
|
errorOnNotFound: false
|
|
161
168
|
});
|
|
162
169
|
if (!requestState) {
|
|
@@ -177,8 +184,8 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
177
184
|
} finally {
|
|
178
185
|
await context.agent.siopUpdateAuthRequestState({
|
|
179
186
|
correlationId,
|
|
180
|
-
definitionId,
|
|
181
|
-
state: "
|
|
187
|
+
queryId: definitionId,
|
|
188
|
+
state: "authorization_request_created",
|
|
182
189
|
error
|
|
183
190
|
});
|
|
184
191
|
}
|
|
@@ -189,45 +196,128 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
189
196
|
}
|
|
190
197
|
__name(getAuthRequestSIOPv2Endpoint, "getAuthRequestSIOPv2Endpoint");
|
|
191
198
|
|
|
192
|
-
// src/
|
|
193
|
-
var
|
|
199
|
+
// src/universal-oid4vp-api-functions.ts
|
|
200
|
+
var import_did_auth_siop3 = require("@sphereon/did-auth-siop");
|
|
194
201
|
var import_ssi_express_support2 = require("@sphereon/ssi-express-support");
|
|
195
|
-
var
|
|
196
|
-
var import_ssi_sdk2 = require("@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth");
|
|
202
|
+
var import_ssi_sdk2 = require("@sphereon/ssi-sdk.siopv2-oid4vp-common");
|
|
197
203
|
var import_short_uuid = __toESM(require("short-uuid"), 1);
|
|
198
|
-
|
|
199
|
-
|
|
204
|
+
|
|
205
|
+
// src/middleware/validationMiddleware.ts
|
|
206
|
+
var import_zod = require("zod");
|
|
207
|
+
var validateData = /* @__PURE__ */ __name((schema) => {
|
|
208
|
+
return (req, res, next) => {
|
|
209
|
+
try {
|
|
210
|
+
schema.parse(req.body);
|
|
211
|
+
next();
|
|
212
|
+
} catch (error) {
|
|
213
|
+
if (error instanceof import_zod.ZodError) {
|
|
214
|
+
const errorMessages = error.issues.map((issue) => ({
|
|
215
|
+
message: `${issue.path.join(".")} is ${issue.message}`
|
|
216
|
+
}));
|
|
217
|
+
res.status(400).json({
|
|
218
|
+
status: 400,
|
|
219
|
+
message: "Invalid data",
|
|
220
|
+
error_details: errorMessages[0].message
|
|
221
|
+
});
|
|
222
|
+
} else {
|
|
223
|
+
res.status(500).json({
|
|
224
|
+
status: 500,
|
|
225
|
+
message: "Internal Server Error"
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
}, "validateData");
|
|
231
|
+
|
|
232
|
+
// src/schemas/index.ts
|
|
233
|
+
var import_zod2 = require("zod");
|
|
234
|
+
var import_ssi_sdk = require("@sphereon/ssi-sdk.siopv2-oid4vp-common");
|
|
235
|
+
var import_did_auth_siop2 = require("@sphereon/did-auth-siop");
|
|
236
|
+
var ResponseTypeSchema = import_zod2.z.enum([
|
|
237
|
+
import_did_auth_siop2.ResponseType.VP_TOKEN
|
|
238
|
+
]);
|
|
239
|
+
var ResponseModeSchema = import_zod2.z.enum([
|
|
240
|
+
import_did_auth_siop2.ResponseMode.DIRECT_POST,
|
|
241
|
+
import_did_auth_siop2.ResponseMode.DIRECT_POST_JWT
|
|
242
|
+
]);
|
|
243
|
+
var RequestUriMethodSchema = import_zod2.z.enum([
|
|
244
|
+
import_did_auth_siop2.RequestUriMethod.GET,
|
|
245
|
+
import_did_auth_siop2.RequestUriMethod.POST
|
|
246
|
+
]);
|
|
247
|
+
var AuthorizationStatusSchema = import_zod2.z.enum([
|
|
248
|
+
...import_ssi_sdk.authorizationRequestStatuses,
|
|
249
|
+
...import_ssi_sdk.authorizationResponseStatuses
|
|
250
|
+
]);
|
|
251
|
+
var CallbackOptsSchema = import_zod2.z.object({
|
|
252
|
+
url: import_zod2.z.string(),
|
|
253
|
+
status: import_zod2.z.array(AuthorizationStatusSchema).optional()
|
|
254
|
+
});
|
|
255
|
+
var QRCodeOptsSchema = import_zod2.z.object({
|
|
256
|
+
size: import_zod2.z.number().optional(),
|
|
257
|
+
color_dark: import_zod2.z.string().optional(),
|
|
258
|
+
color_light: import_zod2.z.string().optional()
|
|
259
|
+
});
|
|
260
|
+
var CreateAuthorizationRequestBodySchema = import_zod2.z.object({
|
|
261
|
+
query_id: import_zod2.z.string(),
|
|
262
|
+
client_id: import_zod2.z.string().optional(),
|
|
263
|
+
request_uri_base: import_zod2.z.string().optional(),
|
|
264
|
+
correlation_id: import_zod2.z.string().optional(),
|
|
265
|
+
request_uri_method: RequestUriMethodSchema.optional(),
|
|
266
|
+
response_type: ResponseTypeSchema.optional(),
|
|
267
|
+
response_mode: ResponseModeSchema.optional(),
|
|
268
|
+
transaction_data: import_zod2.z.array(import_zod2.z.string()).optional(),
|
|
269
|
+
qr_code: QRCodeOptsSchema.optional(),
|
|
270
|
+
direct_post_response_redirect_uri: import_zod2.z.string().optional(),
|
|
271
|
+
callback: CallbackOptsSchema.optional()
|
|
272
|
+
});
|
|
273
|
+
var CreateAuthorizationResponseSchema = import_zod2.z.object({
|
|
274
|
+
correlation_id: import_zod2.z.string(),
|
|
275
|
+
query_id: import_zod2.z.string(),
|
|
276
|
+
request_uri: import_zod2.z.string(),
|
|
277
|
+
status_uri: import_zod2.z.string(),
|
|
278
|
+
qr_uri: import_zod2.z.string().optional()
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
// src/universal-oid4vp-api-functions.ts
|
|
282
|
+
function createAuthRequestUniversalOID4VPEndpoint(router, context, opts) {
|
|
200
283
|
if (opts?.enabled === false) {
|
|
201
|
-
console.log(`createAuthRequest
|
|
284
|
+
console.log(`createAuthRequest universal OID4VP endpoint is disabled`);
|
|
202
285
|
return;
|
|
203
286
|
}
|
|
204
|
-
const path = opts?.path ?? "/
|
|
205
|
-
router.post(path, (0, import_ssi_express_support2.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
287
|
+
const path = opts?.path ?? "/backend/auth/requests";
|
|
288
|
+
router.post(path, (0, import_ssi_express_support2.checkAuth)(opts?.endpoint), validateData(CreateAuthorizationRequestBodySchema), async (request, response) => {
|
|
206
289
|
try {
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
290
|
+
const correlationId = request.body.correlation_id ?? import_short_uuid.default.uuid();
|
|
291
|
+
const qrCodeOpts = request.body.qr_code ?? opts?.qrCodeOpts;
|
|
292
|
+
const queryId = request.body.query_id;
|
|
293
|
+
const directPostResponseRedirectUri = request.body.direct_post_response_redirect_uri;
|
|
294
|
+
const requestUriBase = request.body.request_uri_base;
|
|
295
|
+
try {
|
|
296
|
+
await context.agent.pdmGetDefinition({
|
|
297
|
+
itemId: queryId
|
|
298
|
+
});
|
|
299
|
+
} catch (e) {
|
|
300
|
+
console.log(`No query could be found for the given id. Query id: ${queryId}`);
|
|
301
|
+
return (0, import_ssi_express_support2.sendErrorResponse)(response, 404, {
|
|
302
|
+
status: 404,
|
|
303
|
+
message: "No query could be found"
|
|
304
|
+
});
|
|
210
305
|
}
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
const qrCodeOpts = request.body.qrCodeOpts ?? opts?.qrCodeOpts;
|
|
214
|
-
const requestByReferenceURI = (0, import_ssi_sdk.uriWithBase)(`/siop/definitions/${definitionId}/auth-requests/${state}`, {
|
|
215
|
-
baseURI: opts?.siopBaseURI
|
|
306
|
+
const requestByReferenceURI = (0, import_ssi_sdk2.uriWithBase)(`/siop/definitions/${queryId}/auth-requests/${correlationId}`, {
|
|
307
|
+
baseURI: requestUriBase ?? opts?.siopBaseURI
|
|
216
308
|
});
|
|
217
|
-
const responseURI = (0,
|
|
309
|
+
const responseURI = (0, import_ssi_sdk2.uriWithBase)(`/siop/definitions/${queryId}/auth-responses/${correlationId}`, {
|
|
218
310
|
baseURI: opts?.siopBaseURI
|
|
219
311
|
});
|
|
220
|
-
const responseRedirectURI = ("response_redirect_uri" in request.body && request.body.response_redirect_uri) ?? ("responseRedirectURI" in request.body && request.body.responseRedirectURI);
|
|
221
312
|
const authRequestURI = await context.agent.siopCreateAuthRequestURI({
|
|
222
|
-
|
|
313
|
+
queryId,
|
|
223
314
|
correlationId,
|
|
224
|
-
state,
|
|
225
315
|
nonce: import_short_uuid.default.uuid(),
|
|
226
316
|
requestByReferenceURI,
|
|
227
317
|
responseURIType: "response_uri",
|
|
228
318
|
responseURI,
|
|
229
|
-
...
|
|
230
|
-
responseRedirectURI
|
|
319
|
+
...directPostResponseRedirectUri && {
|
|
320
|
+
responseRedirectURI: directPostResponseRedirectUri
|
|
231
321
|
}
|
|
232
322
|
});
|
|
233
323
|
let qrCodeDataUri;
|
|
@@ -240,140 +330,138 @@ function createAuthRequestWebappEndpoint(router, context, opts) {
|
|
|
240
330
|
qrCodeDataUri = `data:image/png;base64,${(await qrCode.draw()).toString("base64")}`;
|
|
241
331
|
}
|
|
242
332
|
const authRequestBody = {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
authStatusURI: `${(0, import_ssi_sdk.uriWithBase)(opts?.webappAuthStatusPath ?? "/webapp/auth-status", {
|
|
333
|
+
query_id: queryId,
|
|
334
|
+
correlation_id: correlationId,
|
|
335
|
+
request_uri: authRequestURI,
|
|
336
|
+
status_uri: `${(0, import_ssi_sdk2.uriWithBase)(opts?.webappAuthStatusPath ?? `/backend/auth/status/${correlationId}`, {
|
|
248
337
|
baseURI: opts?.webappBaseURI
|
|
249
338
|
})}`,
|
|
250
339
|
...qrCodeDataUri && {
|
|
251
|
-
qrCodeDataUri
|
|
340
|
+
qr_uri: qrCodeDataUri
|
|
252
341
|
}
|
|
253
342
|
};
|
|
254
343
|
console.log(`Auth Request URI data to send back: ${JSON.stringify(authRequestBody)}`);
|
|
255
|
-
return response.json(authRequestBody);
|
|
344
|
+
return response.status(201).json(authRequestBody);
|
|
256
345
|
} catch (error) {
|
|
257
|
-
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500,
|
|
346
|
+
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500, {
|
|
347
|
+
status: 500,
|
|
348
|
+
message: "Could not create an authorization request URI"
|
|
349
|
+
}, error);
|
|
258
350
|
}
|
|
259
351
|
});
|
|
260
352
|
}
|
|
261
|
-
__name(
|
|
262
|
-
function
|
|
353
|
+
__name(createAuthRequestUniversalOID4VPEndpoint, "createAuthRequestUniversalOID4VPEndpoint");
|
|
354
|
+
function removeAuthRequestStateUniversalOID4VPEndpoint(router, context, opts) {
|
|
263
355
|
if (opts?.enabled === false) {
|
|
264
|
-
console.log(`
|
|
356
|
+
console.log(`removeAuthStatus universal OID4VP endpoint is disabled`);
|
|
265
357
|
return;
|
|
266
358
|
}
|
|
267
|
-
const path = opts?.path ?? "/
|
|
268
|
-
router.
|
|
359
|
+
const path = opts?.path ?? "/backend/auth/requests/:correlationId";
|
|
360
|
+
router.delete(path, (0, import_ssi_express_support2.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
269
361
|
try {
|
|
270
|
-
|
|
271
|
-
const
|
|
272
|
-
const definitionId = request.body.definitionId;
|
|
273
|
-
const requestState = correlationId && definitionId ? await context.agent.siopGetAuthRequestState({
|
|
362
|
+
const correlationId = request.params.correlationId;
|
|
363
|
+
const authRequestState = await context.agent.siopGetAuthRequestState({
|
|
274
364
|
correlationId,
|
|
275
|
-
definitionId,
|
|
276
365
|
errorOnNotFound: false
|
|
277
|
-
})
|
|
278
|
-
if (!
|
|
279
|
-
console.log(`No
|
|
280
|
-
response
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
correlationId,
|
|
285
|
-
definitionId,
|
|
286
|
-
lastUpdated: requestState ? requestState.lastUpdated : Date.now()
|
|
287
|
-
};
|
|
288
|
-
return response.json(statusBody2);
|
|
366
|
+
});
|
|
367
|
+
if (!authRequestState) {
|
|
368
|
+
console.log(`No authorization request could be found for the given correlationId. correlationId: ${correlationId}`);
|
|
369
|
+
return (0, import_ssi_express_support2.sendErrorResponse)(response, 404, {
|
|
370
|
+
status: 404,
|
|
371
|
+
message: "No authorization request could be found"
|
|
372
|
+
});
|
|
289
373
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
374
|
+
await context.agent.siopDeleteAuthState({
|
|
375
|
+
correlationId
|
|
376
|
+
});
|
|
377
|
+
return response.status(204).json();
|
|
378
|
+
} catch (error) {
|
|
379
|
+
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500, {
|
|
380
|
+
status: 500,
|
|
381
|
+
message: error.message
|
|
382
|
+
}, error);
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
__name(removeAuthRequestStateUniversalOID4VPEndpoint, "removeAuthRequestStateUniversalOID4VPEndpoint");
|
|
387
|
+
function authStatusUniversalOID4VPEndpoint(router, context, opts) {
|
|
388
|
+
if (opts?.enabled === false) {
|
|
389
|
+
console.log(`authStatus universal OID4VP endpoint is disabled`);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
const path = opts?.path ?? "/backend/auth/status/:correlationId";
|
|
393
|
+
router.get(path, (0, import_ssi_express_support2.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
394
|
+
try {
|
|
395
|
+
console.log("Received auth-status request...");
|
|
396
|
+
const correlationId = request.params.correlationId;
|
|
397
|
+
const requestState = await context.agent.siopGetAuthRequestState({
|
|
398
|
+
correlationId,
|
|
399
|
+
errorOnNotFound: false
|
|
400
|
+
});
|
|
401
|
+
if (!requestState) {
|
|
402
|
+
console.log(`No authorization request could be found for the given correlationId. correlationId: ${correlationId}`);
|
|
403
|
+
return (0, import_ssi_express_support2.sendErrorResponse)(response, 404, {
|
|
404
|
+
status: 404,
|
|
405
|
+
message: "No authorization request could be found"
|
|
406
|
+
});
|
|
293
407
|
}
|
|
294
408
|
let responseState;
|
|
295
|
-
if (requestState.status === "
|
|
409
|
+
if (requestState.status === "authorization_request_created") {
|
|
296
410
|
responseState = await context.agent.siopGetAuthResponseState({
|
|
297
411
|
correlationId,
|
|
298
|
-
definitionId,
|
|
299
|
-
includeVerifiedData,
|
|
300
412
|
errorOnNotFound: false
|
|
301
413
|
});
|
|
302
414
|
}
|
|
303
415
|
const overallState = responseState ?? requestState;
|
|
304
416
|
const statusBody = {
|
|
305
417
|
status: overallState.status,
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
definitionId,
|
|
311
|
-
lastUpdated: overallState.lastUpdated,
|
|
312
|
-
...responseState && responseState.status === import_did_auth_siop.AuthorizationResponseStateStatus.VERIFIED ? {
|
|
313
|
-
payload: await responseState.response.mergedPayloads({
|
|
314
|
-
hasher: import_ssi_sdk3.shaHasher
|
|
315
|
-
}),
|
|
418
|
+
correlation_id: overallState.correlationId,
|
|
419
|
+
query_id: overallState.queryId,
|
|
420
|
+
last_updated: overallState.lastUpdated,
|
|
421
|
+
...responseState?.status === import_did_auth_siop3.AuthorizationResponseStateStatus.VERIFIED && responseState.verifiedData !== void 0 && {
|
|
316
422
|
verifiedData: responseState.verifiedData
|
|
317
|
-
}
|
|
423
|
+
},
|
|
424
|
+
...overallState.error && {
|
|
425
|
+
message: overallState.error.message
|
|
426
|
+
}
|
|
318
427
|
};
|
|
319
428
|
console.debug(`Will send auth status: ${JSON.stringify(statusBody)}`);
|
|
320
429
|
if (overallState.status === "error") {
|
|
321
|
-
response.
|
|
322
|
-
return response.json(statusBody);
|
|
430
|
+
return response.status(500).json(statusBody);
|
|
323
431
|
}
|
|
324
|
-
response.
|
|
325
|
-
return response.json(statusBody);
|
|
432
|
+
return response.status(200).json(statusBody);
|
|
326
433
|
} catch (error) {
|
|
327
|
-
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500,
|
|
434
|
+
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500, {
|
|
435
|
+
status: 500,
|
|
436
|
+
message: error.message
|
|
437
|
+
}, error);
|
|
328
438
|
}
|
|
329
439
|
});
|
|
330
440
|
}
|
|
331
|
-
__name(
|
|
332
|
-
function removeAuthRequestStateWebappEndpoint(router, context, opts) {
|
|
333
|
-
if (opts?.enabled === false) {
|
|
334
|
-
console.log(`removeAuthStatus Webapp endpoint is disabled`);
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
const path = opts?.path ?? "/webapp/definitions/:definitionId/auth-requests/:correlationId";
|
|
338
|
-
router.delete(path, (0, import_ssi_express_support2.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
339
|
-
try {
|
|
340
|
-
const correlationId = request.params.correlationId;
|
|
341
|
-
const definitionId = request.params.definitionId;
|
|
342
|
-
if (!correlationId || !definitionId) {
|
|
343
|
-
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`);
|
|
344
|
-
return (0, import_ssi_express_support2.sendErrorResponse)(response, 404, "No authorization request could be found");
|
|
345
|
-
}
|
|
346
|
-
response.statusCode = 200;
|
|
347
|
-
return response.json(await context.agent.siopDeleteAuthState({
|
|
348
|
-
definitionId,
|
|
349
|
-
correlationId
|
|
350
|
-
}));
|
|
351
|
-
} catch (error) {
|
|
352
|
-
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500, error.message, error);
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
__name(removeAuthRequestStateWebappEndpoint, "removeAuthRequestStateWebappEndpoint");
|
|
441
|
+
__name(authStatusUniversalOID4VPEndpoint, "authStatusUniversalOID4VPEndpoint");
|
|
357
442
|
function getDefinitionsEndpoint(router, context, opts) {
|
|
358
443
|
if (opts?.enabled === false) {
|
|
359
|
-
console.log(`getDefinitions
|
|
444
|
+
console.log(`getDefinitions universal OID4VP endpoint is disabled`);
|
|
360
445
|
return;
|
|
361
446
|
}
|
|
362
|
-
const path = opts?.path ?? "/
|
|
447
|
+
const path = opts?.path ?? "/backend/definitions";
|
|
363
448
|
router.get(path, (0, import_ssi_express_support2.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
364
449
|
try {
|
|
365
450
|
const definitions = await context.agent.pdmGetDefinitions();
|
|
366
451
|
response.statusCode = 200;
|
|
367
452
|
return response.json(definitions);
|
|
368
453
|
} catch (error) {
|
|
369
|
-
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500,
|
|
454
|
+
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500, {
|
|
455
|
+
status: 500,
|
|
456
|
+
message: error.message
|
|
457
|
+
}, error);
|
|
370
458
|
}
|
|
371
459
|
});
|
|
372
460
|
}
|
|
373
461
|
__name(getDefinitionsEndpoint, "getDefinitionsEndpoint");
|
|
374
462
|
|
|
375
463
|
// src/siopv2-rp-api-server.ts
|
|
376
|
-
var
|
|
464
|
+
var import_ssi_sdk3 = require("@sphereon/ssi-sdk.core");
|
|
377
465
|
var import_ssi_express_support3 = require("@sphereon/ssi-express-support");
|
|
378
466
|
var import_express = __toESM(require("express"), 1);
|
|
379
467
|
var import_swagger_ui_express = __toESM(require("swagger-ui-express"), 1);
|
|
@@ -410,16 +498,16 @@ var SIOPv2RPApiServer = class {
|
|
|
410
498
|
this._opts = opts;
|
|
411
499
|
this._express = args.expressSupport.express;
|
|
412
500
|
this._router = import_express.default.Router();
|
|
413
|
-
const context = (0,
|
|
501
|
+
const context = (0, import_ssi_sdk3.agentContext)(agent);
|
|
414
502
|
const features = opts?.enableFeatures ?? [
|
|
415
503
|
"rp-status",
|
|
416
504
|
"siop"
|
|
417
505
|
];
|
|
418
506
|
console.log(`SIOPv2 API enabled, with features: ${JSON.stringify(features)}}`);
|
|
419
507
|
if (features.includes("rp-status")) {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
508
|
+
createAuthRequestUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappCreateAuthRequest);
|
|
509
|
+
authStatusUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappAuthStatus);
|
|
510
|
+
removeAuthRequestStateUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappDeleteAuthRequest);
|
|
423
511
|
getDefinitionsEndpoint(this._router, context, opts?.endpointOpts?.webappGetDefinitions);
|
|
424
512
|
}
|
|
425
513
|
if (features.includes("siop")) {
|