@sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-api 0.32.1-next.13 → 0.32.1-next.145
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"siop-api-functions.d.ts","sourceRoot":"","sources":["../src/siop-api-functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,8BAA8B,EAAE,MAAM,yBAAyB,CAAA;AACtG,OAAO,EAAa,mBAAmB,EAAqB,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"siop-api-functions.d.ts","sourceRoot":"","sources":["../src/siop-api-functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,8BAA8B,EAAE,MAAM,yBAAyB,CAAA;AACtG,OAAO,EAAa,mBAAmB,EAAqB,MAAM,+BAA+B,CAAA;AAGjG,OAAO,EAAqB,MAAM,EAAE,MAAM,SAAS,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAsC1C,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,gBAAgB,EACzB,IAAI,CAAC,EAAE,mBAAmB,GAAG;IAAE,8BAA8B,CAAC,EAAE,8BAA8B,CAAA;CAAE,QAuEjG;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,mBAAmB,QAiDjH"}
|
|
@@ -13,6 +13,33 @@ exports.verifyAuthResponseSIOPv2Endpoint = verifyAuthResponseSIOPv2Endpoint;
|
|
|
13
13
|
exports.getAuthRequestSIOPv2Endpoint = getAuthRequestSIOPv2Endpoint;
|
|
14
14
|
const did_auth_siop_1 = require("@sphereon/did-auth-siop");
|
|
15
15
|
const ssi_express_support_1 = require("@sphereon/ssi-express-support");
|
|
16
|
+
const ssi_types_1 = require("@sphereon/ssi-types");
|
|
17
|
+
const parseAuthorizationResponse = (request) => {
|
|
18
|
+
const contentType = request.header('content-type');
|
|
19
|
+
if (contentType === 'application/json') {
|
|
20
|
+
const payload = typeof request.body === 'string' ? JSON.parse(request.body) : request.body;
|
|
21
|
+
return payload;
|
|
22
|
+
}
|
|
23
|
+
if (contentType === 'application/x-www-form-urlencoded') {
|
|
24
|
+
const payload = request.body;
|
|
25
|
+
// Parse presentation_submission if it's a string
|
|
26
|
+
if (typeof payload.presentation_submission === 'string') {
|
|
27
|
+
console.log(`Supplied presentation_submission was a string instead of JSON. Correcting, but external party should fix their implementation!`);
|
|
28
|
+
payload.presentation_submission = JSON.parse(payload.presentation_submission);
|
|
29
|
+
}
|
|
30
|
+
// when using FORM_URL_ENCODED, vp_token comes back as string not matter whether the input was string, object or array. Handled below.
|
|
31
|
+
if (typeof payload.vp_token === 'string') {
|
|
32
|
+
const { vp_token } = payload;
|
|
33
|
+
// The only use case where vp_object is an object is JsonLdAsString atm. For arrays, any objects will be parsed along with the array
|
|
34
|
+
// (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)
|
|
35
|
+
if ((vp_token.startsWith('[') && vp_token.endsWith(']')) || ssi_types_1.CredentialMapper.isJsonLdAsString(vp_token)) {
|
|
36
|
+
payload.vp_token = JSON.parse(vp_token);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return payload;
|
|
40
|
+
}
|
|
41
|
+
throw new Error(`Unsupported content type: ${contentType}. Currently only application/x-www-form-urlencoded and application/json (for direct_post) are supported`);
|
|
42
|
+
};
|
|
16
43
|
function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
17
44
|
var _a;
|
|
18
45
|
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
@@ -37,22 +64,9 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
37
64
|
response.statusMessage = `No definition ${definitionId}`;
|
|
38
65
|
return response.send();
|
|
39
66
|
}
|
|
40
|
-
const authorizationResponse =
|
|
41
|
-
if (typeof authorizationResponse.presentation_submission === 'string') {
|
|
42
|
-
console.log(`Supplied presentation_submission was a string instead of JSON. Correcting, but external party should fix their implementation!`);
|
|
43
|
-
authorizationResponse.presentation_submission = JSON.parse(authorizationResponse.presentation_submission);
|
|
44
|
-
}
|
|
45
|
-
if (typeof authorizationResponse.vp_token === 'string') {
|
|
46
|
-
// arrays pass as string when using FORM_URL_ENCODED
|
|
47
|
-
if (authorizationResponse.vp_token.startsWith('[') && authorizationResponse.vp_token.endsWith(']')) {
|
|
48
|
-
authorizationResponse.vp_token = JSON.parse(authorizationResponse.vp_token);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
authorizationResponse.vp_token = [authorizationResponse.vp_token];
|
|
52
|
-
}
|
|
53
|
-
}
|
|
67
|
+
const authorizationResponse = parseAuthorizationResponse(request);
|
|
54
68
|
console.log(`URI: ${JSON.stringify(authorizationResponse)}`);
|
|
55
|
-
const
|
|
69
|
+
const definitionItem = definitionItems[0];
|
|
56
70
|
const verifiedResponse = yield context.agent.siopVerifyAuthResponse({
|
|
57
71
|
authorizationResponse,
|
|
58
72
|
correlationId,
|
|
@@ -60,17 +74,23 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
60
74
|
presentationDefinitions: [
|
|
61
75
|
{
|
|
62
76
|
location: (_a = opts === null || opts === void 0 ? void 0 : opts.presentationDefinitionLocation) !== null && _a !== void 0 ? _a : did_auth_siop_1.PresentationDefinitionLocation.TOPLEVEL_PRESENTATION_DEF,
|
|
63
|
-
definition,
|
|
77
|
+
definition: definitionItem.definitionPayload,
|
|
64
78
|
},
|
|
65
79
|
],
|
|
80
|
+
dcqlQuery: definitionItem.dcqlPayload,
|
|
66
81
|
});
|
|
67
82
|
const wrappedPresentation = (_b = verifiedResponse === null || verifiedResponse === void 0 ? void 0 : verifiedResponse.oid4vpSubmission) === null || _b === void 0 ? void 0 : _b.presentations[0];
|
|
68
83
|
if (wrappedPresentation) {
|
|
69
84
|
// const credentialSubject = wrappedPresentation.presentation.verifiableCredential[0]?.credential?.credentialSubject
|
|
70
85
|
// console.log(JSON.stringify(credentialSubject, null, 2))
|
|
71
86
|
console.log('PRESENTATION:' + JSON.stringify(wrappedPresentation.presentation, null, 2));
|
|
72
|
-
const responseRedirectURI = yield context.agent.siopGetRedirectURI({ correlationId, definitionId, state: verifiedResponse.state });
|
|
73
87
|
response.statusCode = 200;
|
|
88
|
+
const authorizationChallengeValidationResponse = { presentation_during_issuance_session: verifiedResponse.correlationId };
|
|
89
|
+
if (authorizationResponse.is_first_party) {
|
|
90
|
+
response.setHeader('Content-Type', 'application/json');
|
|
91
|
+
return response.send(JSON.stringify(authorizationChallengeValidationResponse));
|
|
92
|
+
}
|
|
93
|
+
const responseRedirectURI = yield context.agent.siopGetRedirectURI({ correlationId, definitionId, state: verifiedResponse.state });
|
|
74
94
|
if (responseRedirectURI) {
|
|
75
95
|
response.setHeader('Content-Type', 'application/json');
|
|
76
96
|
return response.send(JSON.stringify({ redirect_uri: responseRedirectURI }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"siop-api-functions.js","sourceRoot":"","sources":["../src/siop-api-functions.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"siop-api-functions.js","sourceRoot":"","sources":["../src/siop-api-functions.ts"],"names":[],"mappings":";;;;;;;;;;;AA2CA,4EA0EC;AAED,oEAiDC;AAxKD,2DAAsG;AACtG,uEAAiG;AACjG,mDAAsD;AAKtD,MAAM,0BAA0B,GAAG,CAAC,OAAgB,EAAgC,EAAE;IACpF,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAA;IAElD,IAAI,WAAW,KAAK,kBAAkB,EAAE,CAAC;QACvC,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OA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,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAA;gBAC9E,OAAO,IAAA,uCAAiB,EAAC,QAAQ,EAAE,GAAG,EAAE,qCAAqC,EAAE,CAAC,CAAC,CAAA;YACnF,CAAC;oBAAS,CAAC;gBACT,MAAM,OAAO,CAAC,KAAK,CAAC,0BAA0B,CAAC;oBAC7C,aAAa;oBACb,YAAY;oBACZ,KAAK,EAAE,MAAM;oBACb,KAAK;iBACN,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,IAAA,uCAAiB,EAAC,QAAQ,EAAE,GAAG,EAAE,qCAAqC,EAAE,KAAK,CAAC,CAAA;QACvF,CAAC;IACH,CAAC,CAAA,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-api",
|
|
3
|
-
"version": "0.32.1-next.
|
|
3
|
+
"version": "0.32.1-next.145+1d1de14c",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,16 +11,16 @@
|
|
|
11
11
|
"start:dev": "ts-node __tests__/RestAPI.ts"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@sphereon/did-auth-siop": "0.16.1-next.
|
|
15
|
-
"@sphereon/ssi-express-support": "0.32.1-next.
|
|
16
|
-
"@sphereon/ssi-sdk.core": "0.32.1-next.
|
|
17
|
-
"@sphereon/ssi-sdk.credential-validation": "0.32.1-next.
|
|
18
|
-
"@sphereon/ssi-sdk.kv-store-temp": "0.32.1-next.
|
|
19
|
-
"@sphereon/ssi-sdk.pd-manager": "0.32.1-next.
|
|
20
|
-
"@sphereon/ssi-sdk.presentation-exchange": "0.32.1-next.
|
|
21
|
-
"@sphereon/ssi-sdk.siopv2-oid4vp-common": "0.32.1-next.
|
|
22
|
-
"@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth": "0.32.1-next.
|
|
23
|
-
"@sphereon/ssi-types": "0.32.1-next.
|
|
14
|
+
"@sphereon/did-auth-siop": "0.16.1-next.339",
|
|
15
|
+
"@sphereon/ssi-express-support": "0.32.1-next.145+1d1de14c",
|
|
16
|
+
"@sphereon/ssi-sdk.core": "0.32.1-next.145+1d1de14c",
|
|
17
|
+
"@sphereon/ssi-sdk.credential-validation": "0.32.1-next.145+1d1de14c",
|
|
18
|
+
"@sphereon/ssi-sdk.kv-store-temp": "0.32.1-next.145+1d1de14c",
|
|
19
|
+
"@sphereon/ssi-sdk.pd-manager": "0.32.1-next.145+1d1de14c",
|
|
20
|
+
"@sphereon/ssi-sdk.presentation-exchange": "0.32.1-next.145+1d1de14c",
|
|
21
|
+
"@sphereon/ssi-sdk.siopv2-oid4vp-common": "0.32.1-next.145+1d1de14c",
|
|
22
|
+
"@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth": "0.32.1-next.145+1d1de14c",
|
|
23
|
+
"@sphereon/ssi-types": "0.32.1-next.145+1d1de14c",
|
|
24
24
|
"@veramo/core": "4.2.0",
|
|
25
25
|
"@veramo/credential-w3c": "4.2.0",
|
|
26
26
|
"body-parser": "^1.20.2",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"@sphereon/pex": "5.0.0-unstable.28",
|
|
39
39
|
"@sphereon/pex-models": "^2.3.2",
|
|
40
40
|
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.27.0",
|
|
41
|
-
"@sphereon/ssi-sdk.data-store": "0.32.1-next.
|
|
42
|
-
"@sphereon/ssi-sdk.vc-handler-ld-local": "0.32.1-next.
|
|
41
|
+
"@sphereon/ssi-sdk.data-store": "0.32.1-next.145+1d1de14c",
|
|
42
|
+
"@sphereon/ssi-sdk.vc-handler-ld-local": "0.32.1-next.145+1d1de14c",
|
|
43
43
|
"@types/body-parser": "^1.19.5",
|
|
44
44
|
"@types/cookie-parser": "^1.4.7",
|
|
45
45
|
"@types/cors": "^2.8.17",
|
|
@@ -98,5 +98,5 @@
|
|
|
98
98
|
"Authenticator"
|
|
99
99
|
],
|
|
100
100
|
"nx": {},
|
|
101
|
-
"gitHead": "
|
|
101
|
+
"gitHead": "1d1de14cc4240fac80d3cc765026f719f3067357"
|
|
102
102
|
}
|
|
@@ -1,9 +1,46 @@
|
|
|
1
1
|
import { AuthorizationResponsePayload, PresentationDefinitionLocation } from '@sphereon/did-auth-siop'
|
|
2
2
|
import { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'
|
|
3
|
-
import {
|
|
3
|
+
import { CredentialMapper } from '@sphereon/ssi-types'
|
|
4
|
+
import { AuthorizationChallengeValidationResponse } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'
|
|
4
5
|
import { Request, Response, Router } from 'express'
|
|
5
6
|
import { IRequiredContext } from './types'
|
|
6
7
|
|
|
8
|
+
const parseAuthorizationResponse = (request: Request): AuthorizationResponsePayload => {
|
|
9
|
+
const contentType = request.header('content-type')
|
|
10
|
+
|
|
11
|
+
if (contentType === 'application/json') {
|
|
12
|
+
const payload = typeof request.body === 'string' ? JSON.parse(request.body) : request.body
|
|
13
|
+
return payload as AuthorizationResponsePayload
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (contentType === 'application/x-www-form-urlencoded') {
|
|
17
|
+
const payload = request.body as AuthorizationResponsePayload
|
|
18
|
+
|
|
19
|
+
// Parse presentation_submission if it's a string
|
|
20
|
+
if (typeof payload.presentation_submission === 'string') {
|
|
21
|
+
console.log(`Supplied presentation_submission was a string instead of JSON. Correcting, but external party should fix their implementation!`)
|
|
22
|
+
payload.presentation_submission = JSON.parse(payload.presentation_submission)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// when using FORM_URL_ENCODED, vp_token comes back as string not matter whether the input was string, object or array. Handled below.
|
|
26
|
+
if (typeof payload.vp_token === 'string') {
|
|
27
|
+
const { vp_token } = payload
|
|
28
|
+
|
|
29
|
+
// The only use case where vp_object is an object is JsonLdAsString atm. For arrays, any objects will be parsed along with the array
|
|
30
|
+
// (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)
|
|
31
|
+
if ((vp_token.startsWith('[') && vp_token.endsWith(']')) || CredentialMapper.isJsonLdAsString(vp_token)) {
|
|
32
|
+
payload.vp_token = JSON.parse(vp_token)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return payload
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
throw new Error(
|
|
40
|
+
`Unsupported content type: ${contentType}. Currently only application/x-www-form-urlencoded and application/json (for direct_post) are supported`,
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
7
44
|
export function verifyAuthResponseSIOPv2Endpoint(
|
|
8
45
|
router: Router,
|
|
9
46
|
context: IRequiredContext,
|
|
@@ -31,23 +68,10 @@ export function verifyAuthResponseSIOPv2Endpoint(
|
|
|
31
68
|
return response.send()
|
|
32
69
|
}
|
|
33
70
|
|
|
34
|
-
const authorizationResponse =
|
|
35
|
-
typeof request.body === 'string' ? (JSON.parse(request.body) as AuthorizationResponsePayload) : (request.body as AuthorizationResponsePayload)
|
|
36
|
-
if (typeof authorizationResponse.presentation_submission === 'string') {
|
|
37
|
-
console.log(`Supplied presentation_submission was a string instead of JSON. Correcting, but external party should fix their implementation!`)
|
|
38
|
-
authorizationResponse.presentation_submission = JSON.parse(authorizationResponse.presentation_submission) as PresentationSubmission
|
|
39
|
-
}
|
|
40
|
-
if (typeof authorizationResponse.vp_token === 'string') {
|
|
41
|
-
// arrays pass as string when using FORM_URL_ENCODED
|
|
42
|
-
if (authorizationResponse.vp_token.startsWith('[') && authorizationResponse.vp_token.endsWith(']')) {
|
|
43
|
-
authorizationResponse.vp_token = JSON.parse(authorizationResponse.vp_token)
|
|
44
|
-
} else {
|
|
45
|
-
authorizationResponse.vp_token = [authorizationResponse.vp_token]
|
|
46
|
-
}
|
|
47
|
-
}
|
|
71
|
+
const authorizationResponse = parseAuthorizationResponse(request)
|
|
48
72
|
console.log(`URI: ${JSON.stringify(authorizationResponse)}`)
|
|
49
73
|
|
|
50
|
-
const
|
|
74
|
+
const definitionItem = definitionItems[0]
|
|
51
75
|
const verifiedResponse = await context.agent.siopVerifyAuthResponse({
|
|
52
76
|
authorizationResponse,
|
|
53
77
|
correlationId,
|
|
@@ -55,9 +79,10 @@ export function verifyAuthResponseSIOPv2Endpoint(
|
|
|
55
79
|
presentationDefinitions: [
|
|
56
80
|
{
|
|
57
81
|
location: opts?.presentationDefinitionLocation ?? PresentationDefinitionLocation.TOPLEVEL_PRESENTATION_DEF,
|
|
58
|
-
definition,
|
|
82
|
+
definition: definitionItem.definitionPayload,
|
|
59
83
|
},
|
|
60
84
|
],
|
|
85
|
+
dcqlQuery: definitionItem.dcqlPayload,
|
|
61
86
|
})
|
|
62
87
|
|
|
63
88
|
const wrappedPresentation = verifiedResponse?.oid4vpSubmission?.presentations[0]
|
|
@@ -65,8 +90,15 @@ export function verifyAuthResponseSIOPv2Endpoint(
|
|
|
65
90
|
// const credentialSubject = wrappedPresentation.presentation.verifiableCredential[0]?.credential?.credentialSubject
|
|
66
91
|
// console.log(JSON.stringify(credentialSubject, null, 2))
|
|
67
92
|
console.log('PRESENTATION:' + JSON.stringify(wrappedPresentation.presentation, null, 2))
|
|
68
|
-
const responseRedirectURI = await context.agent.siopGetRedirectURI({ correlationId, definitionId, state: verifiedResponse.state })
|
|
69
93
|
response.statusCode = 200
|
|
94
|
+
|
|
95
|
+
const authorizationChallengeValidationResponse: AuthorizationChallengeValidationResponse = { presentation_during_issuance_session: verifiedResponse.correlationId }
|
|
96
|
+
if (authorizationResponse.is_first_party) {
|
|
97
|
+
response.setHeader('Content-Type', 'application/json')
|
|
98
|
+
return response.send(JSON.stringify(authorizationChallengeValidationResponse))
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const responseRedirectURI = await context.agent.siopGetRedirectURI({ correlationId, definitionId, state: verifiedResponse.state })
|
|
70
102
|
if (responseRedirectURI) {
|
|
71
103
|
response.setHeader('Content-Type', 'application/json')
|
|
72
104
|
return response.send(JSON.stringify({ redirect_uri: responseRedirectURI }))
|