@sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-api 0.34.1-feature.SSISDK.45.135 → 0.34.1-feature.SSISDK.45.189
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 +20 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -7
- package/dist/index.d.ts +6 -7
- package/dist/index.js +20 -16
- package/dist/index.js.map +1 -1
- package/package.json +19 -21
- package/src/schemas/index.ts +8 -13
- package/src/siop-api-functions.ts +13 -20
- package/src/siopv2-rp-api-server.ts +2 -3
- package/src/types/types.ts +1 -2
- package/src/universal-oid4vp-api-functions.ts +61 -55
- package/src/webapp-api-functions.ts +183 -0
package/dist/index.cjs
CHANGED
|
@@ -74,9 +74,9 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
74
74
|
const path = opts?.path ?? "/siop/definitions/:definitionId/auth-responses/:correlationId";
|
|
75
75
|
router.post(path, (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
76
76
|
try {
|
|
77
|
-
const { correlationId, tenantId, version
|
|
78
|
-
if (!correlationId || !
|
|
79
|
-
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId},
|
|
77
|
+
const { correlationId, queryId, tenantId, version } = request.params;
|
|
78
|
+
if (!correlationId || !queryId) {
|
|
79
|
+
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, queryId: ${queryId}`);
|
|
80
80
|
return (0, import_ssi_express_support.sendErrorResponse)(response, 404, "No authorization request could be found");
|
|
81
81
|
}
|
|
82
82
|
console.log("Authorization Response (siop-sessions");
|
|
@@ -84,16 +84,16 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
84
84
|
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
85
85
|
filter: [
|
|
86
86
|
{
|
|
87
|
-
|
|
87
|
+
queryId,
|
|
88
88
|
tenantId,
|
|
89
89
|
version
|
|
90
90
|
}
|
|
91
91
|
]
|
|
92
92
|
});
|
|
93
93
|
if (definitionItems.length === 0) {
|
|
94
|
-
console.log(`Could not get definition ${
|
|
94
|
+
console.log(`Could not get definition ${queryId} from agent. Will return 404`);
|
|
95
95
|
response.statusCode = 404;
|
|
96
|
-
response.statusMessage = `No definition ${
|
|
96
|
+
response.statusMessage = `No definition ${queryId}`;
|
|
97
97
|
return response.send();
|
|
98
98
|
}
|
|
99
99
|
const authorizationResponse = parseAuthorizationResponse(request);
|
|
@@ -102,12 +102,12 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
102
102
|
const verifiedResponse = await context.agent.siopVerifyAuthResponse({
|
|
103
103
|
authorizationResponse,
|
|
104
104
|
correlationId,
|
|
105
|
-
queryId
|
|
106
|
-
|
|
105
|
+
queryId,
|
|
106
|
+
dcqlQuery: definitionItem.query
|
|
107
107
|
});
|
|
108
|
-
const
|
|
109
|
-
if (
|
|
110
|
-
console.log("
|
|
108
|
+
const presentation = verifiedResponse?.oid4vpSubmission?.presentation;
|
|
109
|
+
if (presentation && Object.keys(presentation).length > 0) {
|
|
110
|
+
console.log("PRESENTATIONS:" + JSON.stringify(verifiedResponse?.oid4vpSubmission?.presentation, null, 2));
|
|
111
111
|
response.statusCode = 200;
|
|
112
112
|
const authorizationChallengeValidationResponse = {
|
|
113
113
|
presentation_during_issuance_session: verifiedResponse.correlationId
|
|
@@ -118,7 +118,7 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
118
118
|
}
|
|
119
119
|
const responseRedirectURI = await context.agent.siopGetRedirectURI({
|
|
120
120
|
correlationId,
|
|
121
|
-
queryId
|
|
121
|
+
queryId,
|
|
122
122
|
state: verifiedResponse.state
|
|
123
123
|
});
|
|
124
124
|
if (responseRedirectURI) {
|
|
@@ -223,8 +223,8 @@ var validateData = /* @__PURE__ */ __name((schema) => {
|
|
|
223
223
|
}, "validateData");
|
|
224
224
|
|
|
225
225
|
// src/schemas/index.ts
|
|
226
|
-
var import_zod2 = require("zod");
|
|
227
226
|
var import_did_auth_siop = require("@sphereon/did-auth-siop");
|
|
227
|
+
var import_zod2 = require("zod");
|
|
228
228
|
var ResponseTypeSchema = import_zod2.z.enum([
|
|
229
229
|
import_did_auth_siop.ResponseType.VP_TOKEN
|
|
230
230
|
]);
|
|
@@ -232,7 +232,11 @@ var ResponseModeSchema = import_zod2.z.enum([
|
|
|
232
232
|
import_did_auth_siop.ResponseMode.DIRECT_POST,
|
|
233
233
|
import_did_auth_siop.ResponseMode.DIRECT_POST_JWT
|
|
234
234
|
]);
|
|
235
|
-
var
|
|
235
|
+
var requestUriMethods = [
|
|
236
|
+
"get",
|
|
237
|
+
"post"
|
|
238
|
+
];
|
|
239
|
+
var RequestUriMethodSchema = import_zod2.z.enum(requestUriMethods);
|
|
236
240
|
var QRCodeOptsSchema = import_zod2.z.object({
|
|
237
241
|
size: import_zod2.z.number().optional(),
|
|
238
242
|
color_dark: import_zod2.z.string().optional(),
|
|
@@ -277,7 +281,7 @@ function createAuthRequestUniversalOID4VPEndpoint(router, context, opts) {
|
|
|
277
281
|
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
278
282
|
filter: [
|
|
279
283
|
{
|
|
280
|
-
|
|
284
|
+
queryId
|
|
281
285
|
}
|
|
282
286
|
]
|
|
283
287
|
});
|
|
@@ -405,7 +409,7 @@ function authStatusUniversalOID4VPEndpoint(router, context, opts) {
|
|
|
405
409
|
query_id: overallState.queryId,
|
|
406
410
|
last_updated: overallState.lastUpdated,
|
|
407
411
|
...responseState?.status === import_did_auth_siop2.AuthorizationResponseStateStatus.VERIFIED && responseState.verifiedData !== void 0 && {
|
|
408
|
-
|
|
412
|
+
verified_data: responseState.verifiedData
|
|
409
413
|
},
|
|
410
414
|
...overallState.error && {
|
|
411
415
|
message: overallState.error.message
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/siop-api-functions.ts","../src/universal-oid4vp-api-functions.ts","../src/middleware/validationMiddleware.ts","../src/schemas/index.ts","../src/siopv2-rp-api-server.ts"],"sourcesContent":["/**\n * @public\n */\nexport * from './siop-api-functions'\nexport * from './universal-oid4vp-api-functions'\nexport * from './types'\nexport * from './siopv2-rp-api-server'\n","import { AuthorizationResponsePayload } from '@sphereon/did-auth-siop'\nimport { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'\nimport { AuthorizationChallengeValidationResponse } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'\nimport { CredentialMapper } from '@sphereon/ssi-types'\nimport { Request, Response, Router } from 'express'\nimport { IRequiredContext } from './types'\n\nconst parseAuthorizationResponse = (request: Request): AuthorizationResponsePayload => {\n const contentType = request.header('content-type')\n\n if (contentType === 'application/json') {\n const payload = typeof request.body === 'string' ? JSON.parse(request.body) : request.body\n return payload as AuthorizationResponsePayload\n }\n\n if (contentType === 'application/x-www-form-urlencoded') {\n const payload = request.body as AuthorizationResponsePayload\n\n // Parse presentation_submission if it's a string\n if (typeof payload.presentation_submission === 'string') {\n console.log(`Supplied presentation_submission was a string instead of JSON. Correcting, but external party should fix their implementation!`)\n payload.presentation_submission = JSON.parse(payload.presentation_submission)\n }\n\n // when using FORM_URL_ENCODED, vp_token comes back as string not matter whether the input was string, object or array. Handled below.\n if (typeof payload.vp_token === 'string') {\n const { vp_token } = payload\n\n // The only use case where vp_object is an object is JsonLdAsString atm. For arrays, any objects will be parsed along with the array\n // (Leaving the vp_token JsonLdAsString causes problems because the original credential will remain string and will be interpreted as JWT in some parts of the code)\n if ((vp_token.startsWith('[') && vp_token.endsWith(']')) || CredentialMapper.isJsonLdAsString(vp_token)) {\n payload.vp_token = JSON.parse(vp_token)\n }\n }\n\n return payload\n }\n\n throw new Error(\n `Unsupported content type: ${contentType}. Currently only application/x-www-form-urlencoded and application/json (for direct_post) are supported`,\n )\n}\n\nexport function verifyAuthResponseSIOPv2Endpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`verifyAuthResponse SIOP endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/siop/definitions/:definitionId/auth-responses/:correlationId'\n router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const { correlationId, tenantId, version, credentialQueryId } = request.params // TODO Can credentialQueryId be a request param\n if (!correlationId || !credentialQueryId) {\n console.log(\n `No authorization request could be found for the given url. correlationId: ${correlationId}, credentialQueryId: ${credentialQueryId}`,\n )\n return sendErrorResponse(response, 404, 'No authorization request could be found')\n }\n console.log('Authorization Response (siop-sessions')\n console.log(JSON.stringify(request.body, null, 2))\n const definitionItems = await context.agent.pdmGetDefinitions({ filter: [{ definitionId: credentialQueryId, tenantId, version }] })\n if (definitionItems.length === 0) {\n console.log(`Could not get definition ${credentialQueryId} from agent. Will return 404`)\n response.statusCode = 404\n response.statusMessage = `No definition ${credentialQueryId}`\n return response.send()\n }\n\n const authorizationResponse = parseAuthorizationResponse(request)\n console.log(`URI: ${JSON.stringify(authorizationResponse)}`)\n\n const definitionItem = definitionItems[0]\n const verifiedResponse = await context.agent.siopVerifyAuthResponse({\n authorizationResponse,\n correlationId,\n queryId: credentialQueryId,\n dcqlQueryPayload: definitionItem.dcqlPayload,\n })\n\n const wrappedPresentation = verifiedResponse?.oid4vpSubmission?.presentation[credentialQueryId]\n if (wrappedPresentation) {\n // const credentialSubject = wrappedPresentation.presentation.verifiableCredential[0]?.credential?.credentialSubject\n // console.log(JSON.stringify(credentialSubject, null, 2))\n console.log('PRESENTATION:' + JSON.stringify(wrappedPresentation.presentation, null, 2))\n response.statusCode = 200\n\n const authorizationChallengeValidationResponse: AuthorizationChallengeValidationResponse = {\n presentation_during_issuance_session: verifiedResponse.correlationId,\n }\n if (authorizationResponse.is_first_party) {\n response.setHeader('Content-Type', 'application/json')\n return response.send(JSON.stringify(authorizationChallengeValidationResponse))\n }\n\n const responseRedirectURI = await context.agent.siopGetRedirectURI({\n correlationId,\n queryId: credentialQueryId,\n state: verifiedResponse.state,\n })\n if (responseRedirectURI) {\n response.setHeader('Content-Type', 'application/json')\n return response.send(JSON.stringify({ redirect_uri: responseRedirectURI }))\n }\n // todo: delete session\n } else {\n console.log('Missing Presentation (Verifiable Credentials)')\n response.statusCode = 500\n response.statusMessage = 'Missing Presentation (Verifiable Credentials)'\n }\n return response.send()\n } catch (error) {\n console.error(error)\n return sendErrorResponse(response, 500, 'Could not verify auth status', error)\n }\n })\n}\n\nexport function getAuthRequestSIOPv2Endpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`getAuthRequest SIOP endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/siop/definitions/:definitionId/auth-requests/:correlationId'\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const correlationId = request.params.correlationId\n const definitionId = request.params.definitionId\n if (!correlationId || !definitionId) {\n console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`)\n return sendErrorResponse(response, 404, 'No authorization request could be found')\n }\n const requestState = await context.agent.siopGetAuthRequestState({\n correlationId,\n queryId: definitionId,\n errorOnNotFound: false,\n })\n if (!requestState) {\n console.log(\n `No authorization request could be found for the given url in the state manager. correlationId: ${correlationId}, definitionId: ${definitionId}`,\n )\n return sendErrorResponse(response, 404, `No authorization request could be found`)\n }\n const requestObject = await requestState.request?.requestObject?.toJwt()\n console.log('JWT Request object:')\n console.log(requestObject)\n\n let error: string | undefined\n try {\n response.statusCode = 200\n response.setHeader('Content-Type', 'application/jwt')\n return response.send(requestObject)\n } catch (e) {\n error = typeof e === 'string' ? e : e instanceof Error ? e.message : undefined\n return sendErrorResponse(response, 500, 'Could not get authorization request', e)\n } finally {\n await context.agent.siopUpdateAuthRequestState({\n correlationId,\n queryId: definitionId,\n state: 'authorization_request_created',\n error,\n })\n }\n } catch (error) {\n return sendErrorResponse(response, 500, 'Could not get authorization request', error)\n }\n })\n}\n","import { AuthorizationResponseStateStatus } from '@sphereon/did-auth-siop'\nimport { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'\nimport { uriWithBase } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'\nimport { Request, Response, Router } from 'express'\nimport uuid from 'short-uuid'\nimport { validateData } from './middleware/validationMiddleware'\nimport { CreateAuthorizationRequestBodySchema } from './schemas'\nimport {\n CreateAuthorizationRequest,\n CreateAuthorizationRequestResponse,\n CreateAuthorizationResponse,\n DeleteAuthorizationRequest,\n GetAuthorizationRequestStatus,\n AuthStatusResponse,\n ICreateAuthRequestWebappEndpointOpts,\n IRequiredContext\n} from './types'\n\nexport function createAuthRequestUniversalOID4VPEndpoint(router: Router, context: IRequiredContext, opts?: ICreateAuthRequestWebappEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`createAuthRequest universal OID4VP endpoint is disabled`)\n return\n }\n\n const path = opts?.path ?? '/backend/auth/requests'\n router.post(path, checkAuth(opts?.endpoint), validateData(CreateAuthorizationRequestBodySchema), async (request: CreateAuthorizationRequest, response: CreateAuthorizationResponse) => {\n try {\n const correlationId = request.body.correlation_id ?? uuid.uuid()\n const qrCodeOpts = request.body.qr_code ?? opts?.qrCodeOpts\n const queryId = request.body.query_id\n const directPostResponseRedirectUri = request.body.direct_post_response_redirect_uri // TODO Uri not URI\n const requestUriBase = request.body.request_uri_base\n const callback = request.body.callback\n\n const definitionItems = await context.agent.pdmGetDefinitions({ filter: [{ definitionId: queryId }] })\n if (definitionItems.length === 0) {\n console.log(`No query could be found for the given id. Query id: ${queryId}`)\n return sendErrorResponse(response, 404, { status: 404, message: 'No query could be found' })\n }\n\n const requestByReferenceURI = uriWithBase(`/siop/definitions/${queryId}/auth-requests/${correlationId}`, {\n baseURI: requestUriBase ?? opts?.siopBaseURI,\n })\n const responseURI = uriWithBase(`/siop/definitions/${queryId}/auth-responses/${correlationId}`, { baseURI: opts?.siopBaseURI })\n\n const authRequestURI = await context.agent.siopCreateAuthRequestURI({\n queryId,\n correlationId,\n nonce: uuid.uuid(),\n requestByReferenceURI,\n responseURIType: 'response_uri',\n responseURI,\n ...(directPostResponseRedirectUri && { responseRedirectURI: directPostResponseRedirectUri }),\n callback\n })\n\n let qrCodeDataUri: string | undefined\n if (qrCodeOpts) {\n const { AwesomeQR } = await import('awesome-qr')\n const qrCode = new AwesomeQR({ ...qrCodeOpts, text: authRequestURI })\n qrCodeDataUri = `data:image/png;base64,${(await qrCode.draw())!.toString('base64')}`\n }\n\n const authRequestBody = {\n query_id: queryId,\n correlation_id: correlationId,\n request_uri: authRequestURI,\n status_uri: `${uriWithBase(opts?.webappAuthStatusPath ?? `/backend/auth/status/${correlationId}`, { baseURI: opts?.webappBaseURI })}`,\n ...(qrCodeDataUri && { qr_uri: qrCodeDataUri }),\n } satisfies CreateAuthorizationRequestResponse\n console.log(`Auth Request URI data to send back: ${JSON.stringify(authRequestBody)}`)\n\n return response.status(201).json(authRequestBody)\n } catch (error) {\n return sendErrorResponse(response, 500, { status: 500, message: 'Could not create an authorization request URI' }, error)\n }\n })\n}\n\nexport function removeAuthRequestStateUniversalOID4VPEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`removeAuthStatus universal OID4VP endpoint is disabled`)\n return\n }\n\n const path = opts?.path ?? '/backend/auth/requests/:correlationId'\n router.delete(path, checkAuth(opts?.endpoint), async (request: DeleteAuthorizationRequest, response: Response) => {\n try {\n const correlationId: string = request.params.correlationId\n\n const authRequestState = await context.agent.siopGetAuthRequestState({\n correlationId,\n errorOnNotFound: false\n })\n if (!authRequestState) {\n console.log(`No authorization request could be found for the given correlationId. correlationId: ${correlationId}`)\n return sendErrorResponse(response, 404, { status: 404, message: 'No authorization request could be found' })\n }\n\n await context.agent.siopDeleteAuthState({ correlationId })\n\n return response.status(204).json()\n } catch (error) {\n return sendErrorResponse(response, 500, { status: 500, message: error.message }, error)\n }\n })\n}\n\nexport function authStatusUniversalOID4VPEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`authStatus universal OID4VP endpoint is disabled`)\n return\n }\n\n const path = opts?.path ?? '/backend/auth/status/:correlationId'\n router.get(path, checkAuth(opts?.endpoint), async (request: GetAuthorizationRequestStatus, response: Response) => {\n try {\n console.log('Received auth-status request...')\n const correlationId: string = request.params.correlationId\n\n const requestState = await context.agent.siopGetAuthRequestState({\n correlationId,\n errorOnNotFound: false\n })\n\n if (!requestState) {\n console.log(`No authorization request could be found for the given correlationId. correlationId: ${correlationId}`)\n return sendErrorResponse(response, 404, { status: 404, message: 'No authorization request could be found' })\n }\n\n let responseState\n if (requestState.status === 'authorization_request_created') {\n responseState = (await context.agent.siopGetAuthResponseState({ correlationId, errorOnNotFound: false }))\n }\n const overallState = responseState ?? requestState\n\n const statusBody = {\n status: overallState.status,\n correlation_id: overallState.correlationId,\n query_id: overallState.queryId,\n last_updated: overallState.lastUpdated,\n ...((responseState?.status === AuthorizationResponseStateStatus.VERIFIED && responseState.verifiedData !== undefined) && { verifiedData: responseState.verifiedData }),\n ...(overallState.error && { message: overallState.error.message })\n } satisfies AuthStatusResponse\n console.debug(`Will send auth status: ${JSON.stringify(statusBody)}`)\n\n if (overallState.status === 'error') {\n return response.status(500).json(statusBody)\n }\n return response.status(200).json(statusBody)\n } catch (error) {\n return sendErrorResponse(response, 500, { status: 500, message: error.message }, error)\n }\n })\n}\n\nexport function getDefinitionsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`getDefinitions universal OID4VP endpoint is disabled`)\n return\n }\n\n const path = opts?.path ?? '/backend/definitions'\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const definitions = await context.agent.pdmGetDefinitions()\n response.statusCode = 200\n return response.json(definitions)\n } catch (error) {\n return sendErrorResponse(response, 500, { status: 500, message: error.message }, error)\n }\n })\n}\n","import { Request, Response, NextFunction } from 'express';\nimport { z, ZodError } from 'zod';\n\nexport const validateData = (schema: z.ZodObject<any, any>) => {\n return (req: Request, res: Response, next: NextFunction) => {\n try {\n schema.parse(req.body);\n next();\n } catch (error) {\n if (error instanceof ZodError) {\n const errorMessages = error.issues.map((issue: any) => ({\n message: `${issue.path.join('.')} is ${issue.message}`,\n }))\n res.status(400).json({ status: 400, message: 'Invalid data', error_details: errorMessages[0].message });\n } else {\n res.status(500).json({ status: 500, message: 'Internal Server Error' });\n }\n }\n };\n}\n","import { z } from 'zod'\nimport {\n ResponseMode,\n ResponseType,\n RequestUriMethod,\n CallbackOptsSchema\n} from '@sphereon/did-auth-siop'\n\nexport const ResponseTypeSchema = z.enum([ResponseType.VP_TOKEN]);\n\nexport const ResponseModeSchema = z.enum([ResponseMode.DIRECT_POST, ResponseMode.DIRECT_POST_JWT]);\n\nexport const RequestUriMethodSchema = z.enum(Object.values(RequestUriMethod));\n\nexport const QRCodeOptsSchema = z.object({\n size: z.number().optional(),\n color_dark: z.string().optional(),\n color_light: z.string().optional(),\n});\n\nexport const CreateAuthorizationRequestBodySchema = z.object({\n query_id: z.string(),\n client_id: z.string().optional(),\n request_uri_base: z.string().optional(),\n correlation_id: z.string().optional(),\n request_uri_method: RequestUriMethodSchema.optional(),\n response_type: ResponseTypeSchema.optional(),\n response_mode: ResponseModeSchema.optional(),\n transaction_data: z.array(z.string()).optional(),\n qr_code: QRCodeOptsSchema.optional(),\n direct_post_response_redirect_uri: z.string().optional(),\n callback: CallbackOptsSchema.optional(),\n});\n\nexport const CreateAuthorizationResponseSchema = z.object({\n correlation_id: z.string(),\n query_id: z.string(),\n request_uri: z.string(),\n status_uri: z.string(),\n qr_uri: z.string().optional(),\n});\n","import { agentContext } from '@sphereon/ssi-sdk.core'\nimport { copyGlobalAuthToEndpoints, ExpressSupport } from '@sphereon/ssi-express-support'\nimport { IPresentationExchange } from '@sphereon/ssi-sdk.presentation-exchange'\nimport { ISIOPv2RP } from '@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth'\nimport { TAgent } from '@veramo/core'\nimport express, { Express, Request, Response, Router } from 'express'\nimport { getAuthRequestSIOPv2Endpoint, verifyAuthResponseSIOPv2Endpoint } from './siop-api-functions'\nimport { IRequiredPlugins, ISIOPv2RPRestAPIOpts } from './types'\nimport {\n authStatusUniversalOID4VPEndpoint,\n createAuthRequestUniversalOID4VPEndpoint,\n getDefinitionsEndpoint,\n removeAuthRequestStateUniversalOID4VPEndpoint,\n} from './universal-oid4vp-api-functions'\nimport swaggerUi from 'swagger-ui-express'\n\nexport class SIOPv2RPApiServer {\n private readonly _express: Express\n private readonly _router: Router\n private readonly _agent: TAgent<IPresentationExchange & ISIOPv2RP>\n private readonly _opts?: ISIOPv2RPRestAPIOpts\n private readonly _basePath: string\n\n private readonly OID4VP_SWAGGER_URL = 'https://api.swaggerhub.com/apis/SphereonInt/OID4VP/0.1.0'\n constructor(args: { agent: TAgent<IRequiredPlugins>; expressSupport: ExpressSupport; opts?: ISIOPv2RPRestAPIOpts }) {\n const { agent, opts } = args\n this._agent = agent\n copyGlobalAuthToEndpoints({ opts, keys: ['webappCreateAuthRequest', 'webappAuthStatus', 'webappDeleteAuthRequest'] })\n if (opts?.endpointOpts?.globalAuth?.secureSiopEndpoints) {\n copyGlobalAuthToEndpoints({ opts, keys: ['siopGetAuthRequest', 'siopVerifyAuthResponse'] })\n }\n\n this._opts = opts\n this._express = args.expressSupport.express\n this._router = express.Router()\n const context = agentContext(agent)\n\n const features = opts?.enableFeatures ?? ['rp-status', 'siop']\n console.log(`SIOPv2 API enabled, with features: ${JSON.stringify(features)}}`)\n\n // Webapp endpoints\n if (features.includes('rp-status')) {\n createAuthRequestUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappCreateAuthRequest)\n authStatusUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappAuthStatus)\n removeAuthRequestStateUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappDeleteAuthRequest)\n getDefinitionsEndpoint(this._router, context, opts?.endpointOpts?.webappGetDefinitions)\n }\n\n // SIOPv2 endpoints\n if (features.includes('siop')) {\n getAuthRequestSIOPv2Endpoint(this._router, context, opts?.endpointOpts?.siopGetAuthRequest)\n verifyAuthResponseSIOPv2Endpoint(this._router, context, opts?.endpointOpts?.siopVerifyAuthResponse)\n }\n this._basePath = opts?.endpointOpts?.basePath ?? ''\n this._express.use(this._basePath, this.router)\n this._express.set('trust proxy', opts?.endpointOpts?.trustProxy ?? true)\n this.setupSwaggerUi()\n }\n\n private setupSwaggerUi() {\n fetch(this.OID4VP_SWAGGER_URL)\n .then((res) => res.json())\n .then((swagger: any) => {\n const apiDocs = `${this._basePath}/api-docs`\n console.log(`[OID4P] API docs available at ${apiDocs}`)\n\n this._router.use(\n '/api-docs',\n (req: Request, res: Response, next: any) => {\n const regex = `${apiDocs.replace(/\\//, '\\/')}`.replace('/oid4vp', '').replace(/\\/api-docs.*/, '')\n swagger.servers = [{ url: `${req.protocol}://${req.get('host')}${regex}`, description: 'This server' }]\n // @ts-ignore\n req.swaggerDoc = swagger\n next()\n },\n swaggerUi.serveFiles(swagger, options),\n swaggerUi.setup(),\n )\n })\n .catch((err) => {\n console.log(`[OID4VP] Unable to fetch swagger document: ${err}. Will not host api-docs on this instance`)\n })\n const options = {\n // customCss: '.swagger-ui .topbar { display: none }',\n }\n }\n get express(): Express {\n return this._express\n }\n\n get router(): Router {\n return this._router\n }\n\n get agent(): TAgent<IPresentationExchange & ISIOPv2RP> {\n return this._agent\n }\n\n get opts(): ISIOPv2RPRestAPIOpts | undefined {\n return this._opts\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;ACCA,iCAAkE;AAElE,uBAAiC;AAIjC,IAAMA,6BAA6B,wBAACC,YAAAA;AAClC,QAAMC,cAAcD,QAAQE,OAAO,cAAA;AAEnC,MAAID,gBAAgB,oBAAoB;AAC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AA;YAASM,aAAa;UAAc;;AAErGR,YAAIS,aAAaX;AACjBG,aAAAA;MACF,GACAS,0BAAAA,QAAUC,WAAWb,SAASc,OAAAA,GAC9BF,0BAAAA,QAAUG,MAAK,CAAA;IAEnB,CAAA,EACCC,MAAM,CAACC,QAAAA;AACN5C,cAAQC,IAAI,8CAA8C2C,GAAAA,2CAA8C;IAC1G,CAAA;AACF,UAAMH,UAAU,CAEhB;EACF;EACA,IAAI/C,UAAmB;AACrB,WAAO,KAAKhB;EACd;EAEA,IAAIyC,SAAiB;AACnB,WAAO,KAAKxC;EACd;EAEA,IAAIO,QAAmD;AACrD,WAAO,KAAKN;EACd;EAEA,IAAIO,OAAyC;AAC3C,WAAO,KAAKN;EACd;AACF;","names":["parseAuthorizationResponse","request","contentType","header","payload","body","JSON","parse","presentation_submission","console","log","vp_token","startsWith","endsWith","CredentialMapper","isJsonLdAsString","Error","verifyAuthResponseSIOPv2Endpoint","router","context","opts","enabled","path","post","checkAuth","endpoint","response","correlationId","tenantId","version","credentialQueryId","params","sendErrorResponse","stringify","definitionItems","agent","pdmGetDefinitions","filter","definitionId","length","statusCode","statusMessage","send","authorizationResponse","definitionItem","verifiedResponse","siopVerifyAuthResponse","queryId","dcqlQueryPayload","dcqlPayload","wrappedPresentation","oid4vpSubmission","presentation","authorizationChallengeValidationResponse","presentation_during_issuance_session","is_first_party","setHeader","responseRedirectURI","siopGetRedirectURI","state","redirect_uri","error","getAuthRequestSIOPv2Endpoint","get","requestState","siopGetAuthRequestState","errorOnNotFound","requestObject","toJwt","e","message","undefined","siopUpdateAuthRequestState","import_did_auth_siop","import_ssi_express_support","validateData","schema","req","res","next","parse","body","error","ZodError","errorMessages","issues","map","issue","message","path","join","status","json","error_details","import_zod","ResponseTypeSchema","z","enum","ResponseType","VP_TOKEN","ResponseModeSchema","ResponseMode","DIRECT_POST","DIRECT_POST_JWT","RequestUriMethodSchema","Object","values","RequestUriMethod","QRCodeOptsSchema","object","size","number","optional","color_dark","string","color_light","CreateAuthorizationRequestBodySchema","query_id","client_id","request_uri_base","correlation_id","request_uri_method","response_type","response_mode","transaction_data","array","qr_code","direct_post_response_redirect_uri","callback","CallbackOptsSchema","CreateAuthorizationResponseSchema","request_uri","status_uri","qr_uri","createAuthRequestUniversalOID4VPEndpoint","router","context","opts","enabled","console","log","path","post","checkAuth","endpoint","validateData","CreateAuthorizationRequestBodySchema","request","response","correlationId","body","correlation_id","uuid","qrCodeOpts","qr_code","queryId","query_id","directPostResponseRedirectUri","direct_post_response_redirect_uri","requestUriBase","request_uri_base","callback","definitionItems","agent","pdmGetDefinitions","filter","definitionId","length","sendErrorResponse","status","message","requestByReferenceURI","uriWithBase","baseURI","siopBaseURI","responseURI","authRequestURI","siopCreateAuthRequestURI","nonce","responseURIType","responseRedirectURI","qrCodeDataUri","AwesomeQR","qrCode","text","draw","toString","authRequestBody","request_uri","status_uri","webappAuthStatusPath","webappBaseURI","qr_uri","JSON","stringify","json","error","removeAuthRequestStateUniversalOID4VPEndpoint","delete","params","authRequestState","siopGetAuthRequestState","errorOnNotFound","siopDeleteAuthState","authStatusUniversalOID4VPEndpoint","get","requestState","responseState","siopGetAuthResponseState","overallState","statusBody","last_updated","lastUpdated","AuthorizationResponseStateStatus","VERIFIED","verifiedData","undefined","debug","getDefinitionsEndpoint","definitions","statusCode","import_ssi_sdk","import_ssi_express_support","SIOPv2RPApiServer","_express","_router","_agent","_opts","_basePath","OID4VP_SWAGGER_URL","constructor","args","agent","opts","copyGlobalAuthToEndpoints","keys","endpointOpts","globalAuth","secureSiopEndpoints","expressSupport","express","Router","context","agentContext","features","enableFeatures","console","log","JSON","stringify","includes","createAuthRequestUniversalOID4VPEndpoint","webappCreateAuthRequest","authStatusUniversalOID4VPEndpoint","webappAuthStatus","removeAuthRequestStateUniversalOID4VPEndpoint","webappDeleteAuthRequest","getDefinitionsEndpoint","webappGetDefinitions","getAuthRequestSIOPv2Endpoint","siopGetAuthRequest","verifyAuthResponseSIOPv2Endpoint","siopVerifyAuthResponse","basePath","use","router","set","trustProxy","setupSwaggerUi","fetch","then","res","json","swagger","apiDocs","req","next","regex","replace","servers","url","protocol","get","description","swaggerDoc","swaggerUi","serveFiles","options","setup","catch","err"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/siop-api-functions.ts","../src/universal-oid4vp-api-functions.ts","../src/middleware/validationMiddleware.ts","../src/schemas/index.ts","../src/siopv2-rp-api-server.ts"],"sourcesContent":["/**\n * @public\n */\nexport * from './siop-api-functions'\nexport * from './universal-oid4vp-api-functions'\nexport * from './types'\nexport * from './siopv2-rp-api-server'\n","import { AuthorizationResponsePayload } from '@sphereon/did-auth-siop'\nimport { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'\nimport { AuthorizationChallengeValidationResponse } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'\nimport { CredentialMapper } from '@sphereon/ssi-types'\nimport { Request, Response, Router } from 'express'\nimport { IRequiredContext } from './types'\n\nconst parseAuthorizationResponse = (request: Request): AuthorizationResponsePayload => {\n const contentType = request.header('content-type')\n\n if (contentType === 'application/json') {\n const payload = typeof request.body === 'string' ? JSON.parse(request.body) : request.body\n return payload as AuthorizationResponsePayload\n }\n\n if (contentType === 'application/x-www-form-urlencoded') {\n const payload = request.body as AuthorizationResponsePayload\n\n // Parse presentation_submission if it's a string\n if (typeof payload.presentation_submission === 'string') {\n console.log(`Supplied presentation_submission was a string instead of JSON. Correcting, but external party should fix their implementation!`)\n payload.presentation_submission = JSON.parse(payload.presentation_submission)\n }\n\n // when using FORM_URL_ENCODED, vp_token comes back as string not matter whether the input was string, object or array. Handled below.\n if (typeof payload.vp_token === 'string') {\n const { vp_token } = payload\n\n // The only use case where vp_object is an object is JsonLdAsString atm. For arrays, any objects will be parsed along with the array\n // (Leaving the vp_token JsonLdAsString causes problems because the original credential will remain string and will be interpreted as JWT in some parts of the code)\n if ((vp_token.startsWith('[') && vp_token.endsWith(']')) || CredentialMapper.isJsonLdAsString(vp_token)) {\n payload.vp_token = JSON.parse(vp_token)\n }\n }\n\n return payload\n }\n\n throw new Error(\n `Unsupported content type: ${contentType}. Currently only application/x-www-form-urlencoded and application/json (for direct_post) are supported`,\n )\n}\n\nexport function verifyAuthResponseSIOPv2Endpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`verifyAuthResponse SIOP endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/siop/definitions/:definitionId/auth-responses/:correlationId'\n router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const { correlationId, queryId, tenantId, version } = request.params\n if (!correlationId || !queryId) {\n console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, queryId: ${queryId}`)\n return sendErrorResponse(response, 404, 'No authorization request could be found')\n }\n console.log('Authorization Response (siop-sessions')\n console.log(JSON.stringify(request.body, null, 2))\n const definitionItems = await context.agent.pdmGetDefinitions({ filter: [{ queryId, tenantId, version }] })\n if (definitionItems.length === 0) {\n console.log(`Could not get definition ${queryId} from agent. Will return 404`)\n response.statusCode = 404\n response.statusMessage = `No definition ${queryId}`\n return response.send()\n }\n\n const authorizationResponse = parseAuthorizationResponse(request)\n console.log(`URI: ${JSON.stringify(authorizationResponse)}`)\n\n const definitionItem = definitionItems[0]\n const verifiedResponse = await context.agent.siopVerifyAuthResponse({\n authorizationResponse,\n correlationId,\n queryId,\n dcqlQuery: definitionItem.query,\n })\n\n // FIXME SSISDK-55 add proper support for checking for DCQL presentations\n const presentation = verifiedResponse?.oid4vpSubmission?.presentation\n if (presentation && Object.keys(presentation).length > 0) {\n console.log('PRESENTATIONS:' + JSON.stringify(verifiedResponse?.oid4vpSubmission?.presentation, null, 2))\n response.statusCode = 200\n\n const authorizationChallengeValidationResponse: AuthorizationChallengeValidationResponse = {\n presentation_during_issuance_session: verifiedResponse.correlationId,\n }\n if (authorizationResponse.is_first_party) {\n response.setHeader('Content-Type', 'application/json')\n return response.send(JSON.stringify(authorizationChallengeValidationResponse))\n }\n\n const responseRedirectURI = await context.agent.siopGetRedirectURI({ correlationId, queryId: queryId, state: verifiedResponse.state })\n if (responseRedirectURI) {\n response.setHeader('Content-Type', 'application/json')\n return response.send(JSON.stringify({ redirect_uri: responseRedirectURI }))\n }\n // todo: delete session\n } else {\n console.log('Missing Presentation (Verifiable Credentials)')\n response.statusCode = 500\n response.statusMessage = 'Missing Presentation (Verifiable Credentials)'\n }\n return response.send()\n } catch (error) {\n console.error(error)\n return sendErrorResponse(response, 500, 'Could not verify auth status', error)\n }\n })\n}\n\nexport function getAuthRequestSIOPv2Endpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`getAuthRequest SIOP endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/siop/definitions/:definitionId/auth-requests/:correlationId'\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const correlationId = request.params.correlationId\n const definitionId = request.params.definitionId\n if (!correlationId || !definitionId) {\n console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`)\n return sendErrorResponse(response, 404, 'No authorization request could be found')\n }\n const requestState = await context.agent.siopGetAuthRequestState({\n correlationId,\n queryId: definitionId,\n errorOnNotFound: false,\n })\n if (!requestState) {\n console.log(\n `No authorization request could be found for the given url in the state manager. correlationId: ${correlationId}, definitionId: ${definitionId}`,\n )\n return sendErrorResponse(response, 404, `No authorization request could be found`)\n }\n const requestObject = await requestState.request?.requestObject?.toJwt()\n console.log('JWT Request object:')\n console.log(requestObject)\n\n let error: string | undefined\n try {\n response.statusCode = 200\n response.setHeader('Content-Type', 'application/jwt')\n return response.send(requestObject)\n } catch (e) {\n error = typeof e === 'string' ? e : e instanceof Error ? e.message : undefined\n return sendErrorResponse(response, 500, 'Could not get authorization request', e)\n } finally {\n await context.agent.siopUpdateAuthRequestState({\n correlationId,\n queryId: definitionId,\n state: 'authorization_request_created',\n error,\n })\n }\n } catch (error) {\n return sendErrorResponse(response, 500, 'Could not get authorization request', error)\n }\n })\n}\n","import { AuthorizationResponseStateStatus } from '@sphereon/did-auth-siop'\nimport { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'\nimport { uriWithBase } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'\nimport { Request, Response, Router } from 'express'\nimport uuid from 'short-uuid'\nimport { validateData } from './middleware/validationMiddleware'\nimport { CreateAuthorizationRequestBodySchema } from './schemas'\nimport {\n CreateAuthorizationRequest,\n CreateAuthorizationRequestResponse,\n CreateAuthorizationResponse,\n DeleteAuthorizationRequest,\n GetAuthorizationRequestStatus,\n AuthStatusResponse,\n ICreateAuthRequestWebappEndpointOpts,\n IRequiredContext,\n} from './types'\n\nexport function createAuthRequestUniversalOID4VPEndpoint(router: Router, context: IRequiredContext, opts?: ICreateAuthRequestWebappEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`createAuthRequest universal OID4VP endpoint is disabled`)\n return\n }\n\n const path = opts?.path ?? '/backend/auth/requests'\n router.post(\n path,\n checkAuth(opts?.endpoint),\n validateData(CreateAuthorizationRequestBodySchema),\n async (request: CreateAuthorizationRequest, response: CreateAuthorizationResponse) => {\n try {\n const correlationId = request.body.correlation_id ?? uuid.uuid()\n const qrCodeOpts = request.body.qr_code ?? opts?.qrCodeOpts\n const queryId = request.body.query_id\n const directPostResponseRedirectUri = request.body.direct_post_response_redirect_uri // TODO Uri not URI\n const requestUriBase = request.body.request_uri_base\n const callback = request.body.callback\n\n const definitionItems = await context.agent.pdmGetDefinitions({ filter: [{ queryId }] })\n if (definitionItems.length === 0) {\n console.log(`No query could be found for the given id. Query id: ${queryId}`)\n return sendErrorResponse(response, 404, { status: 404, message: 'No query could be found' })\n }\n\n const requestByReferenceURI = uriWithBase(`/siop/definitions/${queryId}/auth-requests/${correlationId}`, {\n baseURI: requestUriBase ?? opts?.siopBaseURI,\n })\n const responseURI = uriWithBase(`/siop/definitions/${queryId}/auth-responses/${correlationId}`, { baseURI: opts?.siopBaseURI })\n\n const authRequestURI = await context.agent.siopCreateAuthRequestURI({\n queryId,\n correlationId,\n nonce: uuid.uuid(),\n requestByReferenceURI,\n responseURIType: 'response_uri',\n responseURI,\n ...(directPostResponseRedirectUri && { responseRedirectURI: directPostResponseRedirectUri }),\n callback,\n })\n\n let qrCodeDataUri: string | undefined\n if (qrCodeOpts) {\n const { AwesomeQR } = await import('awesome-qr')\n const qrCode = new AwesomeQR({ ...qrCodeOpts, text: authRequestURI })\n qrCodeDataUri = `data:image/png;base64,${(await qrCode.draw())!.toString('base64')}`\n }\n\n const authRequestBody = {\n query_id: queryId,\n correlation_id: correlationId,\n request_uri: authRequestURI,\n status_uri: `${uriWithBase(opts?.webappAuthStatusPath ?? `/backend/auth/status/${correlationId}`, { baseURI: opts?.webappBaseURI })}`,\n ...(qrCodeDataUri && { qr_uri: qrCodeDataUri }),\n } satisfies CreateAuthorizationRequestResponse\n console.log(`Auth Request URI data to send back: ${JSON.stringify(authRequestBody)}`)\n\n return response.status(201).json(authRequestBody)\n } catch (error) {\n return sendErrorResponse(response, 500, { status: 500, message: 'Could not create an authorization request URI' }, error)\n }\n },\n )\n}\n\nexport function removeAuthRequestStateUniversalOID4VPEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`removeAuthStatus universal OID4VP endpoint is disabled`)\n return\n }\n\n const path = opts?.path ?? '/backend/auth/requests/:correlationId'\n router.delete(path, checkAuth(opts?.endpoint), async (request: DeleteAuthorizationRequest, response: Response) => {\n try {\n const correlationId: string = request.params.correlationId\n\n const authRequestState = await context.agent.siopGetAuthRequestState({\n correlationId,\n errorOnNotFound: false,\n })\n if (!authRequestState) {\n console.log(`No authorization request could be found for the given correlationId. correlationId: ${correlationId}`)\n return sendErrorResponse(response, 404, { status: 404, message: 'No authorization request could be found' })\n }\n\n await context.agent.siopDeleteAuthState({ correlationId })\n\n return response.status(204).json()\n } catch (error) {\n return sendErrorResponse(response, 500, { status: 500, message: error.message }, error)\n }\n })\n}\n\nexport function authStatusUniversalOID4VPEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`authStatus universal OID4VP endpoint is disabled`)\n return\n }\n\n const path = opts?.path ?? '/backend/auth/status/:correlationId'\n router.get(path, checkAuth(opts?.endpoint), async (request: GetAuthorizationRequestStatus, response: Response) => {\n try {\n console.log('Received auth-status request...')\n const correlationId: string = request.params.correlationId\n\n const requestState = await context.agent.siopGetAuthRequestState({\n correlationId,\n errorOnNotFound: false,\n })\n\n if (!requestState) {\n console.log(`No authorization request could be found for the given correlationId. correlationId: ${correlationId}`)\n return sendErrorResponse(response, 404, { status: 404, message: 'No authorization request could be found' })\n }\n\n let responseState\n if (requestState.status === 'authorization_request_created') {\n responseState = await context.agent.siopGetAuthResponseState({ correlationId, errorOnNotFound: false })\n }\n const overallState = responseState ?? requestState\n\n const statusBody = {\n status: overallState.status,\n correlation_id: overallState.correlationId,\n query_id: overallState.queryId,\n last_updated: overallState.lastUpdated,\n ...(responseState?.status === AuthorizationResponseStateStatus.VERIFIED &&\n responseState.verifiedData !== undefined && { verified_data: responseState.verifiedData }),\n ...(overallState.error && { message: overallState.error.message }),\n } satisfies AuthStatusResponse\n console.debug(`Will send auth status: ${JSON.stringify(statusBody)}`)\n\n if (overallState.status === 'error') {\n return response.status(500).json(statusBody)\n }\n return response.status(200).json(statusBody)\n } catch (error) {\n return sendErrorResponse(response, 500, { status: 500, message: error.message }, error)\n }\n })\n}\n\nexport function getDefinitionsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`getDefinitions universal OID4VP endpoint is disabled`)\n return\n }\n\n const path = opts?.path ?? '/backend/definitions'\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const definitions = await context.agent.pdmGetDefinitions()\n response.statusCode = 200\n return response.json(definitions)\n } catch (error) {\n return sendErrorResponse(response, 500, { status: 500, message: error.message }, error)\n }\n })\n}\n","import { Request, Response, NextFunction } from 'express';\nimport { z, ZodError } from 'zod';\n\nexport const validateData = (schema: z.ZodObject<any, any>) => {\n return (req: Request, res: Response, next: NextFunction) => {\n try {\n schema.parse(req.body);\n next();\n } catch (error) {\n if (error instanceof ZodError) {\n const errorMessages = error.issues.map((issue: any) => ({\n message: `${issue.path.join('.')} is ${issue.message}`,\n }))\n res.status(400).json({ status: 400, message: 'Invalid data', error_details: errorMessages[0].message });\n } else {\n res.status(500).json({ status: 500, message: 'Internal Server Error' });\n }\n }\n };\n}\n","import { CallbackOptsSchema, RequestUriMethod, ResponseMode, ResponseType } from '@sphereon/did-auth-siop'\nimport { z } from 'zod'\n\nexport const ResponseTypeSchema = z.enum([ResponseType.VP_TOKEN])\n\nexport const ResponseModeSchema = z.enum([ResponseMode.DIRECT_POST, ResponseMode.DIRECT_POST_JWT])\n\nconst requestUriMethods = ['get', 'post'] as const satisfies Array<RequestUriMethod>\nexport const RequestUriMethodSchema = z.enum(requestUriMethods)\nexport const QRCodeOptsSchema = z.object({\n size: z.number().optional(),\n color_dark: z.string().optional(),\n color_light: z.string().optional(),\n})\n\nexport const CreateAuthorizationRequestBodySchema = z.object({\n query_id: z.string(),\n client_id: z.string().optional(),\n request_uri_base: z.string().optional(),\n correlation_id: z.string().optional(),\n request_uri_method: RequestUriMethodSchema.optional(),\n response_type: ResponseTypeSchema.optional(),\n response_mode: ResponseModeSchema.optional(),\n transaction_data: z.array(z.string()).optional(),\n qr_code: QRCodeOptsSchema.optional(),\n direct_post_response_redirect_uri: z.string().optional(),\n callback: CallbackOptsSchema.optional(),\n})\n\nexport const CreateAuthorizationResponseSchema = z.object({\n correlation_id: z.string(),\n query_id: z.string(),\n request_uri: z.string(),\n status_uri: z.string(),\n qr_uri: z.string().optional(),\n})\n","import { agentContext } from '@sphereon/ssi-sdk.core'\nimport { copyGlobalAuthToEndpoints, ExpressSupport } from '@sphereon/ssi-express-support'\nimport { ISIOPv2RP } from '@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth'\nimport { TAgent } from '@veramo/core'\nimport express, { Express, Request, Response, Router } from 'express'\nimport { getAuthRequestSIOPv2Endpoint, verifyAuthResponseSIOPv2Endpoint } from './siop-api-functions'\nimport { IRequiredPlugins, ISIOPv2RPRestAPIOpts } from './types'\nimport {\n authStatusUniversalOID4VPEndpoint,\n createAuthRequestUniversalOID4VPEndpoint,\n getDefinitionsEndpoint,\n removeAuthRequestStateUniversalOID4VPEndpoint,\n} from './universal-oid4vp-api-functions'\nimport swaggerUi from 'swagger-ui-express'\n\nexport class SIOPv2RPApiServer {\n private readonly _express: Express\n private readonly _router: Router\n private readonly _agent: TAgent<ISIOPv2RP>\n private readonly _opts?: ISIOPv2RPRestAPIOpts\n private readonly _basePath: string\n\n private readonly OID4VP_SWAGGER_URL = 'https://api.swaggerhub.com/apis/SphereonInt/OID4VP/0.1.0'\n constructor(args: { agent: TAgent<IRequiredPlugins>; expressSupport: ExpressSupport; opts?: ISIOPv2RPRestAPIOpts }) {\n const { agent, opts } = args\n this._agent = agent\n copyGlobalAuthToEndpoints({ opts, keys: ['webappCreateAuthRequest', 'webappAuthStatus', 'webappDeleteAuthRequest'] })\n if (opts?.endpointOpts?.globalAuth?.secureSiopEndpoints) {\n copyGlobalAuthToEndpoints({ opts, keys: ['siopGetAuthRequest', 'siopVerifyAuthResponse'] })\n }\n\n this._opts = opts\n this._express = args.expressSupport.express\n this._router = express.Router()\n const context = agentContext(agent)\n\n const features = opts?.enableFeatures ?? ['rp-status', 'siop']\n console.log(`SIOPv2 API enabled, with features: ${JSON.stringify(features)}}`)\n\n // Webapp endpoints\n if (features.includes('rp-status')) {\n createAuthRequestUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappCreateAuthRequest)\n authStatusUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappAuthStatus)\n removeAuthRequestStateUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappDeleteAuthRequest)\n getDefinitionsEndpoint(this._router, context, opts?.endpointOpts?.webappGetDefinitions)\n }\n\n // SIOPv2 endpoints\n if (features.includes('siop')) {\n getAuthRequestSIOPv2Endpoint(this._router, context, opts?.endpointOpts?.siopGetAuthRequest)\n verifyAuthResponseSIOPv2Endpoint(this._router, context, opts?.endpointOpts?.siopVerifyAuthResponse)\n }\n this._basePath = opts?.endpointOpts?.basePath ?? ''\n this._express.use(this._basePath, this.router)\n this._express.set('trust proxy', opts?.endpointOpts?.trustProxy ?? true)\n this.setupSwaggerUi()\n }\n\n private setupSwaggerUi() {\n fetch(this.OID4VP_SWAGGER_URL)\n .then((res) => res.json())\n .then((swagger: any) => {\n const apiDocs = `${this._basePath}/api-docs`\n console.log(`[OID4P] API docs available at ${apiDocs}`)\n\n this._router.use(\n '/api-docs',\n (req: Request, res: Response, next: any) => {\n const regex = `${apiDocs.replace(/\\//, '\\/')}`.replace('/oid4vp', '').replace(/\\/api-docs.*/, '')\n swagger.servers = [{ url: `${req.protocol}://${req.get('host')}${regex}`, description: 'This server' }]\n // @ts-ignore\n req.swaggerDoc = swagger\n next()\n },\n swaggerUi.serveFiles(swagger, options),\n swaggerUi.setup(),\n )\n })\n .catch((err) => {\n console.log(`[OID4VP] Unable to fetch swagger document: ${err}. Will not host api-docs on this instance`)\n })\n const options = {\n // customCss: '.swagger-ui .topbar { display: none }',\n }\n }\n get express(): Express {\n return this._express\n }\n\n get router(): Router {\n return this._router\n }\n\n get agent(): TAgent<ISIOPv2RP> {\n return this._agent\n }\n\n get opts(): ISIOPv2RPRestAPIOpts | undefined {\n return this._opts\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;ACCA,iCAAkE;AAElE,uBAAiC;AAIjC,IAAMA,6BAA6B,wBAACC,YAAAA;AAClC,QAAMC,cAAcD,QAAQE,OAAO,cAAA;AAEnC,MAAID,gBAAgB,oBAAoB;AACt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AAc;;AAErGR,YAAIS,aAAaX;AACjBG,aAAAA;MACF,GACAS,0BAAAA,QAAUC,WAAWb,SAASc,OAAAA,GAC9BF,0BAAAA,QAAUG,MAAK,CAAA;IAEnB,CAAA,EACCC,MAAM,CAACC,QAAAA;AACN5C,cAAQC,IAAI,8CAA8C2C,GAAAA,2CAA8C;IAC1G,CAAA;AACF,UAAMH,UAAU,CAEhB;EACF;EACA,IAAI/C,UAAmB;AACrB,WAAO,KAAKf;EACd;EAEA,IAAIwC,SAAiB;AACnB,WAAO,KAAKvC;EACd;EAEA,IAAIM,QAA2B;AAC7B,WAAO,KAAKL;EACd;EAEA,IAAIM,OAAyC;AAC3C,WAAO,KAAKL;EACd;AACF;","names":["parseAuthorizationResponse","request","contentType","header","payload","body","JSON","parse","presentation_submission","console","log","vp_token","startsWith","endsWith","CredentialMapper","isJsonLdAsString","Error","verifyAuthResponseSIOPv2Endpoint","router","context","opts","enabled","path","post","checkAuth","endpoint","response","correlationId","queryId","tenantId","version","params","sendErrorResponse","stringify","definitionItems","agent","pdmGetDefinitions","filter","length","statusCode","statusMessage","send","authorizationResponse","definitionItem","verifiedResponse","siopVerifyAuthResponse","dcqlQuery","query","presentation","oid4vpSubmission","Object","keys","authorizationChallengeValidationResponse","presentation_during_issuance_session","is_first_party","setHeader","responseRedirectURI","siopGetRedirectURI","state","redirect_uri","error","getAuthRequestSIOPv2Endpoint","get","definitionId","requestState","siopGetAuthRequestState","errorOnNotFound","requestObject","toJwt","e","message","undefined","siopUpdateAuthRequestState","import_did_auth_siop","import_ssi_express_support","validateData","schema","req","res","next","parse","body","error","ZodError","errorMessages","issues","map","issue","message","path","join","status","json","error_details","import_zod","ResponseTypeSchema","z","enum","ResponseType","VP_TOKEN","ResponseModeSchema","ResponseMode","DIRECT_POST","DIRECT_POST_JWT","requestUriMethods","RequestUriMethodSchema","QRCodeOptsSchema","object","size","number","optional","color_dark","string","color_light","CreateAuthorizationRequestBodySchema","query_id","client_id","request_uri_base","correlation_id","request_uri_method","response_type","response_mode","transaction_data","array","qr_code","direct_post_response_redirect_uri","callback","CallbackOptsSchema","CreateAuthorizationResponseSchema","request_uri","status_uri","qr_uri","createAuthRequestUniversalOID4VPEndpoint","router","context","opts","enabled","console","log","path","post","checkAuth","endpoint","validateData","CreateAuthorizationRequestBodySchema","request","response","correlationId","body","correlation_id","uuid","qrCodeOpts","qr_code","queryId","query_id","directPostResponseRedirectUri","direct_post_response_redirect_uri","requestUriBase","request_uri_base","callback","definitionItems","agent","pdmGetDefinitions","filter","length","sendErrorResponse","status","message","requestByReferenceURI","uriWithBase","baseURI","siopBaseURI","responseURI","authRequestURI","siopCreateAuthRequestURI","nonce","responseURIType","responseRedirectURI","qrCodeDataUri","AwesomeQR","qrCode","text","draw","toString","authRequestBody","request_uri","status_uri","webappAuthStatusPath","webappBaseURI","qr_uri","JSON","stringify","json","error","removeAuthRequestStateUniversalOID4VPEndpoint","delete","params","authRequestState","siopGetAuthRequestState","errorOnNotFound","siopDeleteAuthState","authStatusUniversalOID4VPEndpoint","get","requestState","responseState","siopGetAuthResponseState","overallState","statusBody","last_updated","lastUpdated","AuthorizationResponseStateStatus","VERIFIED","verifiedData","undefined","verified_data","debug","getDefinitionsEndpoint","definitions","statusCode","import_ssi_sdk","import_ssi_express_support","SIOPv2RPApiServer","_express","_router","_agent","_opts","_basePath","OID4VP_SWAGGER_URL","args","agent","opts","copyGlobalAuthToEndpoints","keys","endpointOpts","globalAuth","secureSiopEndpoints","expressSupport","express","Router","context","agentContext","features","enableFeatures","console","log","JSON","stringify","includes","createAuthRequestUniversalOID4VPEndpoint","webappCreateAuthRequest","authStatusUniversalOID4VPEndpoint","webappAuthStatus","removeAuthRequestStateUniversalOID4VPEndpoint","webappDeleteAuthRequest","getDefinitionsEndpoint","webappGetDefinitions","getAuthRequestSIOPv2Endpoint","siopGetAuthRequest","verifyAuthResponseSIOPv2Endpoint","siopVerifyAuthResponse","basePath","use","router","set","trustProxy","setupSwaggerUi","fetch","then","res","json","swagger","apiDocs","req","next","regex","replace","servers","url","protocol","get","description","swaggerDoc","swaggerUi","serveFiles","options","setup","catch","err"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { ISingleEndpointOpts, GenericAuthArgs, ExpressSupport } from '@sphereon/ssi-express-support';
|
|
2
2
|
import { Request, Response, Router, Express } from 'express';
|
|
3
3
|
import { IAgentContext, ICredentialVerifier, TAgent } from '@veramo/core';
|
|
4
|
-
import { IPresentationExchange } from '@sphereon/ssi-sdk.presentation-exchange';
|
|
5
4
|
import { ISIOPv2RP } from '@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth';
|
|
6
5
|
import { IPDManager } from '@sphereon/ssi-sdk.pd-manager';
|
|
7
6
|
import { AdditionalClaims } from '@sphereon/ssi-types';
|
|
8
7
|
import { AuthorizationRequestStateStatus, AuthorizationResponseStateStatus } from '@sphereon/ssi-sdk.siopv2-oid4vp-common';
|
|
9
8
|
import { z } from 'zod';
|
|
10
9
|
import * as _sphereon_did_auth_siop from '@sphereon/did-auth-siop';
|
|
11
|
-
import {
|
|
10
|
+
import { ResponseType, ResponseMode } from '@sphereon/did-auth-siop';
|
|
12
11
|
|
|
13
12
|
declare const CreateAuthorizationRequestBodySchema: z.ZodObject<{
|
|
14
13
|
query_id: z.ZodString;
|
|
@@ -16,8 +15,8 @@ declare const CreateAuthorizationRequestBodySchema: z.ZodObject<{
|
|
|
16
15
|
request_uri_base: z.ZodOptional<z.ZodString>;
|
|
17
16
|
correlation_id: z.ZodOptional<z.ZodString>;
|
|
18
17
|
request_uri_method: z.ZodOptional<z.ZodEnum<{
|
|
19
|
-
get:
|
|
20
|
-
post:
|
|
18
|
+
get: "get";
|
|
19
|
+
post: "post";
|
|
21
20
|
}>>;
|
|
22
21
|
response_type: z.ZodOptional<z.ZodEnum<{
|
|
23
22
|
vp_token: ResponseType.VP_TOKEN;
|
|
@@ -35,7 +34,7 @@ declare const CreateAuthorizationRequestBodySchema: z.ZodObject<{
|
|
|
35
34
|
direct_post_response_redirect_uri: z.ZodOptional<z.ZodString>;
|
|
36
35
|
callback: z.ZodOptional<z.ZodObject<{
|
|
37
36
|
url: z.ZodString;
|
|
38
|
-
|
|
37
|
+
verifiedData: z.ZodOptional<z.ZodObject<{
|
|
39
38
|
modes: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
40
39
|
authorization_response: _sphereon_did_auth_siop.VerifiedDataMode.AUTHORIZATION_RESPONSE;
|
|
41
40
|
credential_claims_deserialized: _sphereon_did_auth_siop.VerifiedDataMode.CREDENTIAL_CLAIMS_DESERIALIZED;
|
|
@@ -286,7 +285,7 @@ interface ICreateAuthRequestWebappEndpointOpts extends ISingleEndpointOpts {
|
|
|
286
285
|
webappBaseURI?: string;
|
|
287
286
|
responseRedirectURI?: string;
|
|
288
287
|
}
|
|
289
|
-
type IRequiredPlugins = ICredentialVerifier & ISIOPv2RP &
|
|
288
|
+
type IRequiredPlugins = ICredentialVerifier & ISIOPv2RP & IPDManager;
|
|
290
289
|
type IRequiredContext = IAgentContext<IRequiredPlugins>;
|
|
291
290
|
type CreateAuthorizationRequest = Request<Record<string, never>, any, CreateAuthorizationRequestBody, Record<string, never>>;
|
|
292
291
|
type CreateAuthorizationRequestBody = z.infer<typeof CreateAuthorizationRequestBodySchema>;
|
|
@@ -352,7 +351,7 @@ declare class SIOPv2RPApiServer {
|
|
|
352
351
|
private setupSwaggerUi;
|
|
353
352
|
get express(): Express;
|
|
354
353
|
get router(): Router;
|
|
355
|
-
get agent(): TAgent<
|
|
354
|
+
get agent(): TAgent<ISIOPv2RP>;
|
|
356
355
|
get opts(): ISIOPv2RPRestAPIOpts | undefined;
|
|
357
356
|
}
|
|
358
357
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { ISingleEndpointOpts, GenericAuthArgs, ExpressSupport } from '@sphereon/ssi-express-support';
|
|
2
2
|
import { Request, Response, Router, Express } from 'express';
|
|
3
3
|
import { IAgentContext, ICredentialVerifier, TAgent } from '@veramo/core';
|
|
4
|
-
import { IPresentationExchange } from '@sphereon/ssi-sdk.presentation-exchange';
|
|
5
4
|
import { ISIOPv2RP } from '@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth';
|
|
6
5
|
import { IPDManager } from '@sphereon/ssi-sdk.pd-manager';
|
|
7
6
|
import { AdditionalClaims } from '@sphereon/ssi-types';
|
|
8
7
|
import { AuthorizationRequestStateStatus, AuthorizationResponseStateStatus } from '@sphereon/ssi-sdk.siopv2-oid4vp-common';
|
|
9
8
|
import { z } from 'zod';
|
|
10
9
|
import * as _sphereon_did_auth_siop from '@sphereon/did-auth-siop';
|
|
11
|
-
import {
|
|
10
|
+
import { ResponseType, ResponseMode } from '@sphereon/did-auth-siop';
|
|
12
11
|
|
|
13
12
|
declare const CreateAuthorizationRequestBodySchema: z.ZodObject<{
|
|
14
13
|
query_id: z.ZodString;
|
|
@@ -16,8 +15,8 @@ declare const CreateAuthorizationRequestBodySchema: z.ZodObject<{
|
|
|
16
15
|
request_uri_base: z.ZodOptional<z.ZodString>;
|
|
17
16
|
correlation_id: z.ZodOptional<z.ZodString>;
|
|
18
17
|
request_uri_method: z.ZodOptional<z.ZodEnum<{
|
|
19
|
-
get:
|
|
20
|
-
post:
|
|
18
|
+
get: "get";
|
|
19
|
+
post: "post";
|
|
21
20
|
}>>;
|
|
22
21
|
response_type: z.ZodOptional<z.ZodEnum<{
|
|
23
22
|
vp_token: ResponseType.VP_TOKEN;
|
|
@@ -35,7 +34,7 @@ declare const CreateAuthorizationRequestBodySchema: z.ZodObject<{
|
|
|
35
34
|
direct_post_response_redirect_uri: z.ZodOptional<z.ZodString>;
|
|
36
35
|
callback: z.ZodOptional<z.ZodObject<{
|
|
37
36
|
url: z.ZodString;
|
|
38
|
-
|
|
37
|
+
verifiedData: z.ZodOptional<z.ZodObject<{
|
|
39
38
|
modes: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
40
39
|
authorization_response: _sphereon_did_auth_siop.VerifiedDataMode.AUTHORIZATION_RESPONSE;
|
|
41
40
|
credential_claims_deserialized: _sphereon_did_auth_siop.VerifiedDataMode.CREDENTIAL_CLAIMS_DESERIALIZED;
|
|
@@ -286,7 +285,7 @@ interface ICreateAuthRequestWebappEndpointOpts extends ISingleEndpointOpts {
|
|
|
286
285
|
webappBaseURI?: string;
|
|
287
286
|
responseRedirectURI?: string;
|
|
288
287
|
}
|
|
289
|
-
type IRequiredPlugins = ICredentialVerifier & ISIOPv2RP &
|
|
288
|
+
type IRequiredPlugins = ICredentialVerifier & ISIOPv2RP & IPDManager;
|
|
290
289
|
type IRequiredContext = IAgentContext<IRequiredPlugins>;
|
|
291
290
|
type CreateAuthorizationRequest = Request<Record<string, never>, any, CreateAuthorizationRequestBody, Record<string, never>>;
|
|
292
291
|
type CreateAuthorizationRequestBody = z.infer<typeof CreateAuthorizationRequestBodySchema>;
|
|
@@ -352,7 +351,7 @@ declare class SIOPv2RPApiServer {
|
|
|
352
351
|
private setupSwaggerUi;
|
|
353
352
|
get express(): Express;
|
|
354
353
|
get router(): Router;
|
|
355
|
-
get agent(): TAgent<
|
|
354
|
+
get agent(): TAgent<ISIOPv2RP>;
|
|
356
355
|
get opts(): ISIOPv2RPRestAPIOpts | undefined;
|
|
357
356
|
}
|
|
358
357
|
|
package/dist/index.js
CHANGED
|
@@ -34,9 +34,9 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
34
34
|
const path = opts?.path ?? "/siop/definitions/:definitionId/auth-responses/:correlationId";
|
|
35
35
|
router.post(path, checkAuth(opts?.endpoint), async (request, response) => {
|
|
36
36
|
try {
|
|
37
|
-
const { correlationId, tenantId, version
|
|
38
|
-
if (!correlationId || !
|
|
39
|
-
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId},
|
|
37
|
+
const { correlationId, queryId, tenantId, version } = request.params;
|
|
38
|
+
if (!correlationId || !queryId) {
|
|
39
|
+
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, queryId: ${queryId}`);
|
|
40
40
|
return sendErrorResponse(response, 404, "No authorization request could be found");
|
|
41
41
|
}
|
|
42
42
|
console.log("Authorization Response (siop-sessions");
|
|
@@ -44,16 +44,16 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
44
44
|
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
45
45
|
filter: [
|
|
46
46
|
{
|
|
47
|
-
|
|
47
|
+
queryId,
|
|
48
48
|
tenantId,
|
|
49
49
|
version
|
|
50
50
|
}
|
|
51
51
|
]
|
|
52
52
|
});
|
|
53
53
|
if (definitionItems.length === 0) {
|
|
54
|
-
console.log(`Could not get definition ${
|
|
54
|
+
console.log(`Could not get definition ${queryId} from agent. Will return 404`);
|
|
55
55
|
response.statusCode = 404;
|
|
56
|
-
response.statusMessage = `No definition ${
|
|
56
|
+
response.statusMessage = `No definition ${queryId}`;
|
|
57
57
|
return response.send();
|
|
58
58
|
}
|
|
59
59
|
const authorizationResponse = parseAuthorizationResponse(request);
|
|
@@ -62,12 +62,12 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
62
62
|
const verifiedResponse = await context.agent.siopVerifyAuthResponse({
|
|
63
63
|
authorizationResponse,
|
|
64
64
|
correlationId,
|
|
65
|
-
queryId
|
|
66
|
-
|
|
65
|
+
queryId,
|
|
66
|
+
dcqlQuery: definitionItem.query
|
|
67
67
|
});
|
|
68
|
-
const
|
|
69
|
-
if (
|
|
70
|
-
console.log("
|
|
68
|
+
const presentation = verifiedResponse?.oid4vpSubmission?.presentation;
|
|
69
|
+
if (presentation && Object.keys(presentation).length > 0) {
|
|
70
|
+
console.log("PRESENTATIONS:" + JSON.stringify(verifiedResponse?.oid4vpSubmission?.presentation, null, 2));
|
|
71
71
|
response.statusCode = 200;
|
|
72
72
|
const authorizationChallengeValidationResponse = {
|
|
73
73
|
presentation_during_issuance_session: verifiedResponse.correlationId
|
|
@@ -78,7 +78,7 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
78
78
|
}
|
|
79
79
|
const responseRedirectURI = await context.agent.siopGetRedirectURI({
|
|
80
80
|
correlationId,
|
|
81
|
-
queryId
|
|
81
|
+
queryId,
|
|
82
82
|
state: verifiedResponse.state
|
|
83
83
|
});
|
|
84
84
|
if (responseRedirectURI) {
|
|
@@ -183,8 +183,8 @@ var validateData = /* @__PURE__ */ __name((schema) => {
|
|
|
183
183
|
}, "validateData");
|
|
184
184
|
|
|
185
185
|
// src/schemas/index.ts
|
|
186
|
+
import { CallbackOptsSchema, ResponseMode, ResponseType } from "@sphereon/did-auth-siop";
|
|
186
187
|
import { z } from "zod";
|
|
187
|
-
import { ResponseMode, ResponseType, RequestUriMethod, CallbackOptsSchema } from "@sphereon/did-auth-siop";
|
|
188
188
|
var ResponseTypeSchema = z.enum([
|
|
189
189
|
ResponseType.VP_TOKEN
|
|
190
190
|
]);
|
|
@@ -192,7 +192,11 @@ var ResponseModeSchema = z.enum([
|
|
|
192
192
|
ResponseMode.DIRECT_POST,
|
|
193
193
|
ResponseMode.DIRECT_POST_JWT
|
|
194
194
|
]);
|
|
195
|
-
var
|
|
195
|
+
var requestUriMethods = [
|
|
196
|
+
"get",
|
|
197
|
+
"post"
|
|
198
|
+
];
|
|
199
|
+
var RequestUriMethodSchema = z.enum(requestUriMethods);
|
|
196
200
|
var QRCodeOptsSchema = z.object({
|
|
197
201
|
size: z.number().optional(),
|
|
198
202
|
color_dark: z.string().optional(),
|
|
@@ -237,7 +241,7 @@ function createAuthRequestUniversalOID4VPEndpoint(router, context, opts) {
|
|
|
237
241
|
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
238
242
|
filter: [
|
|
239
243
|
{
|
|
240
|
-
|
|
244
|
+
queryId
|
|
241
245
|
}
|
|
242
246
|
]
|
|
243
247
|
});
|
|
@@ -365,7 +369,7 @@ function authStatusUniversalOID4VPEndpoint(router, context, opts) {
|
|
|
365
369
|
query_id: overallState.queryId,
|
|
366
370
|
last_updated: overallState.lastUpdated,
|
|
367
371
|
...responseState?.status === AuthorizationResponseStateStatus.VERIFIED && responseState.verifiedData !== void 0 && {
|
|
368
|
-
|
|
372
|
+
verified_data: responseState.verifiedData
|
|
369
373
|
},
|
|
370
374
|
...overallState.error && {
|
|
371
375
|
message: overallState.error.message
|