@@ -3,9 +3,9 @@ import type { AgentContext } from '../../agent'
3
3
import { DcqlCredential , DcqlMdocCredential , DcqlQuery , DcqlSdJwtVcCredential } from 'dcql'
4
4
import { injectable } from 'tsyringe'
5
5
6
- import { JsonValue } from '../../types'
7
6
import { Mdoc , MdocApi , MdocDeviceResponse , MdocOpenId4VpSessionTranscriptOptions , MdocRecord } from '../mdoc'
8
- import { IPresentationFrame , SdJwtVcApi , SdJwtVcRecord } from '../sd-jwt-vc'
7
+ import { SdJwtVcApi , SdJwtVcRecord , SdJwtVcService } from '../sd-jwt-vc'
8
+ import { buildDisclosureFrameForPayload } from '../sd-jwt-vc/disclosureFrame'
9
9
import { ClaimFormat , W3cCredentialRecord , W3cCredentialRepository } from '../vc'
10
10
11
11
import { DcqlError } from './DcqlError'
@@ -100,13 +100,13 @@ export class DcqlService {
100
100
const dcqlCredentials : DcqlCredential [ ] = credentialRecords . map ( ( record ) => {
101
101
if ( record . type === 'MdocRecord' ) {
102
102
return {
103
- credentialFormat : 'mso_mdoc' ,
103
+ credential_format : 'mso_mdoc' ,
104
104
doctype : record . getTags ( ) . docType ,
105
105
namespaces : Mdoc . fromBase64Url ( record . base64Url ) . issuerSignedNamespaces ,
106
106
} satisfies DcqlMdocCredential
107
107
} else if ( record . type === 'SdJwtVcRecord' ) {
108
108
return {
109
- credentialFormat : 'vc+sd-jwt' ,
109
+ credential_format : 'vc+sd-jwt' ,
110
110
vct : record . getTags ( ) . vct ,
111
111
claims : this . getSdJwtVcApi ( agentContext ) . fromCompact ( record . compactSdJwtVc )
112
112
. prettyClaims as DcqlSdJwtVcCredential . Claims ,
@@ -120,7 +120,18 @@ export class DcqlService {
120
120
const queryResult = DcqlQuery . query ( DcqlQuery . parse ( dcqlQuery ) , dcqlCredentials )
121
121
const matchesWithRecord = Object . fromEntries (
122
122
Object . entries ( queryResult . credential_matches ) . map ( ( [ credential_query_id , result ] ) => {
123
- return [ credential_query_id , { ...result , record : credentialRecords [ result . credential_index ] } ]
123
+ if ( result . success ) {
124
+ if ( result . output . credential_format === 'vc+sd-jwt' ) {
125
+ const sdJwtVcRecord = credentialRecords [ result . input_credential_index ] as SdJwtVcRecord
126
+ agentContext . dependencyManager
127
+ . resolve ( SdJwtVcService )
128
+ . applyDisclosuresForPayload ( sdJwtVcRecord . compactSdJwtVc , result . output . claims )
129
+ }
130
+
131
+ return [ credential_query_id , { ...result , record : credentialRecords [ result . input_credential_index ] } ]
132
+ } else {
133
+ return [ credential_query_id , result ]
134
+ }
124
135
} )
125
136
)
126
137
@@ -207,21 +218,6 @@ export class DcqlService {
207
218
return DcqlQuery . parse ( dcqlQuery )
208
219
}
209
220
210
- // TODO: this IS WRONG
211
- private createPresentationFrame ( obj : Record < string , JsonValue > ) : IPresentationFrame {
212
- const frame : IPresentationFrame = { }
213
-
214
- for ( const [ key , value ] of Object . entries ( obj ) ) {
215
- if ( typeof value === 'object' && value !== null ) {
216
- frame [ key ] = true
217
- } else {
218
- frame [ key ] = ! ! value
219
- }
220
- }
221
-
222
- return frame
223
- }
224
-
225
221
public async createPresentation (
226
222
agentContext : AgentContext ,
227
223
options : {
@@ -268,7 +264,7 @@ export class DcqlService {
268
264
269
265
dcqlPresentation [ credentialQueryId ] = MdocDeviceResponse . fromBase64Url ( deviceResponseBase64Url )
270
266
} else if ( presentationToCreate . claimFormat === ClaimFormat . SdJwtVc ) {
271
- const presentationFrame = this . createPresentationFrame ( presentationToCreate . disclosedPayload )
267
+ const presentationFrame = buildDisclosureFrameForPayload ( presentationToCreate . disclosedPayload )
272
268
273
269
if ( ! domain ) {
274
270
throw new DcqlError ( 'Missing domain property for creating SdJwtVc presentation.' )
0 commit comments