@@ -3,6 +3,7 @@ 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'
6
7
import { Mdoc , MdocApi , MdocDeviceResponse , MdocOpenId4VpSessionTranscriptOptions , MdocRecord } from '../mdoc'
7
8
import { SdJwtVcApi , SdJwtVcRecord , SdJwtVcService } from '../sd-jwt-vc'
8
9
import { buildDisclosureFrameForPayload } from '../sd-jwt-vc/disclosureFrame'
@@ -17,6 +18,19 @@ import {
17
18
} from './models'
18
19
import { dcqlGetPresentationsToCreate as getDcqlVcPresentationsToCreate } from './utils'
19
20
21
+ interface HasToJson {
22
+ toJson ( ) : JsonValue
23
+ }
24
+
25
+ function isToJsonable ( value : unknown ) : value is HasToJson {
26
+ return (
27
+ value !== null &&
28
+ typeof value === 'object' &&
29
+ 'toJson' in value &&
30
+ typeof ( value as HasToJson ) . toJson === 'function'
31
+ )
32
+ }
33
+
20
34
/**
21
35
* @todo create a public api for using dif presentation exchange
22
36
*/
@@ -99,10 +113,23 @@ export class DcqlService {
99
113
100
114
const dcqlCredentials : DcqlCredential [ ] = credentialRecords . map ( ( record ) => {
101
115
if ( record . type === 'MdocRecord' ) {
116
+ const transformValue = ( value : unknown ) : unknown => {
117
+ if ( typeof value !== 'function' && typeof value !== 'object' ) return value
118
+ return isToJsonable ( value ) ? value . toJson ( ) : 'unknown json representation'
119
+ }
120
+
121
+ const mdoc = Mdoc . fromBase64Url ( record . base64Url )
122
+
123
+ const namespaces = Object . fromEntries (
124
+ Object . entries ( mdoc . issuerSignedNamespaces ) . map ( ( [ key , namespace ] ) => [
125
+ key ,
126
+ Object . fromEntries ( Object . entries ( namespace ) . map ( ( [ k , v ] ) => [ k , transformValue ( v ) ] ) ) ,
127
+ ] )
128
+ )
102
129
return {
103
130
credential_format : 'mso_mdoc' ,
104
131
doctype : record . getTags ( ) . docType ,
105
- namespaces : Mdoc . fromBase64Url ( record . base64Url ) . issuerSignedNamespaces ,
132
+ namespaces,
106
133
} satisfies DcqlMdocCredential
107
134
} else if ( record . type === 'SdJwtVcRecord' ) {
108
135
return {
@@ -123,9 +150,17 @@ export class DcqlService {
123
150
if ( result . success ) {
124
151
if ( result . output . credential_format === 'vc+sd-jwt' ) {
125
152
const sdJwtVcRecord = credentialRecords [ result . input_credential_index ] as SdJwtVcRecord
126
- agentContext . dependencyManager
153
+ const claims = agentContext . dependencyManager
127
154
. resolve ( SdJwtVcService )
128
155
. applyDisclosuresForPayload ( sdJwtVcRecord . compactSdJwtVc , result . output . claims )
156
+ return [
157
+ credential_query_id ,
158
+ {
159
+ ...result ,
160
+ output : { ...result . output , claims } ,
161
+ record : credentialRecords [ result . input_credential_index ] ,
162
+ } ,
163
+ ]
129
164
}
130
165
131
166
return [ credential_query_id , { ...result , record : credentialRecords [ result . input_credential_index ] } ]
0 commit comments