Skip to content

Commit 29e796e

Browse files
committed
Require mDL session transcript option when submitting an mDL.
1 parent f4373e5 commit 29e796e

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

lib/authorizationResponse.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ export async function send({
4242

4343
// if `authorizationRequest.response_mode` is `direct.jwt` generate a JWT
4444
if(authorizationRequest.response_mode === 'direct_post.jwt') {
45+
if(submitsFormat({presentationSubmission, format: 'mso_mdoc'}) &&
46+
!encryptionOptions?.mdl?.sessionTranscript) {
47+
throw createNamedError({
48+
message: '"encryptionOptions.mdl.sessionTranscript" is required ' +
49+
'when submitting an mDL presentation.',
50+
name: 'DataError'
51+
});
52+
}
53+
4554
const jwt = await _encrypt({
4655
vpToken, presentationSubmission, authorizationRequest,
4756
encryptionOptions
@@ -135,6 +144,22 @@ export function createPresentationSubmission({
135144
return {presentationSubmission};
136145
}
137146

147+
export function submitsFormat({presentationSubmission, format} = {}) {
148+
/* e.g. presentation submission submitting an mdoc:
149+
{
150+
"definition_id": "mDL-sample-req",
151+
"id": "mDL-sample-res",
152+
"descriptor_map": [{
153+
"id": "org.iso.18013.5.1.mDL",
154+
"format": "mso_mdoc",
155+
"path": "$"
156+
}]
157+
}
158+
*/
159+
return presentationSubmission?.descriptor_map?.some(
160+
e => e?.format === format);
161+
}
162+
138163
async function _encrypt({
139164
vpToken, presentationSubmission, authorizationRequest, encryptionOptions
140165
}) {
@@ -153,13 +178,13 @@ async function _encrypt({
153178

154179
// configure `keyManagementParameters` for `EncryptJWT` API
155180
const keyManagementParameters = {};
156-
if(encryptionOptions?.mdoc?.sessionTranscript) {
181+
if(encryptionOptions?.mdl?.sessionTranscript) {
157182
// ISO 18013-7: include specific session transcript params as apu + apv
158183
const {
159184
mdocGeneratedNonce,
160185
// default to using `authorizationRequest.nonce` for verifier nonce
161186
verifierGeneratedNonce = authorizationRequest.nonce
162-
} = encryptionOptions.mdoc.sessionTranscript;
187+
} = encryptionOptions.mdl.sessionTranscript;
163188
// note: `EncryptJWT` API requires `apu/apv` (`partyInfoU`/`partyInfoV`)
164189
// to be passed as Uint8Arrays; they will be encoded using `base64url` by
165190
// that API

0 commit comments

Comments
 (0)