Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dcql alpha #2098

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions packages/core/src/modules/dcql/DcqlService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { AgentContext } from '../../agent'
import { DcqlCredential, DcqlMdocCredential, DcqlQuery, DcqlSdJwtVcCredential } from 'dcql'
import { injectable } from 'tsyringe'

import { JsonValue } from '../../types'
import { Mdoc, MdocApi, MdocDeviceResponse, MdocOpenId4VpSessionTranscriptOptions, MdocRecord } from '../mdoc'
import { SdJwtVcApi, SdJwtVcRecord, SdJwtVcService } from '../sd-jwt-vc'
import { buildDisclosureFrameForPayload } from '../sd-jwt-vc/disclosureFrame'
Expand All @@ -17,6 +18,19 @@ import {
} from './models'
import { dcqlGetPresentationsToCreate as getDcqlVcPresentationsToCreate } from './utils'

interface HasToJson {
toJson(): JsonValue
}

function isToJsonable(value: unknown): value is HasToJson {
return (
value !== null &&
typeof value === 'object' &&
'toJson' in value &&
typeof (value as HasToJson).toJson === 'function'
)
}

/**
* @todo create a public api for using dif presentation exchange
*/
Expand Down Expand Up @@ -99,10 +113,23 @@ export class DcqlService {

const dcqlCredentials: DcqlCredential[] = credentialRecords.map((record) => {
if (record.type === 'MdocRecord') {
const transformValue = (value: unknown): unknown => {
if (typeof value !== 'function' && typeof value !== 'object') return value
return isToJsonable(value) ? value.toJson() : 'unknown json representation'
}

const mdoc = Mdoc.fromBase64Url(record.base64Url)

const namespaces = Object.fromEntries(
Object.entries(mdoc.issuerSignedNamespaces).map(([key, namespace]) => [
key,
Object.fromEntries(Object.entries(namespace).map(([k, v]) => [k, transformValue(v)])),
])
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you still convert to json? shouldn't this be handled by dcql?

return {
credential_format: 'mso_mdoc',
doctype: record.getTags().docType,
namespaces: Mdoc.fromBase64Url(record.base64Url).issuerSignedNamespaces,
namespaces,
} satisfies DcqlMdocCredential
} else if (record.type === 'SdJwtVcRecord') {
return {
Expand All @@ -123,9 +150,17 @@ export class DcqlService {
if (result.success) {
if (result.output.credential_format === 'vc+sd-jwt') {
const sdJwtVcRecord = credentialRecords[result.input_credential_index] as SdJwtVcRecord
agentContext.dependencyManager
const claims = agentContext.dependencyManager
.resolve(SdJwtVcService)
.applyDisclosuresForPayload(sdJwtVcRecord.compactSdJwtVc, result.output.claims)
return [
credential_query_id,
{
...result,
output: { ...result.output, claims },
record: credentialRecords[result.input_credential_index],
},
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns the whole sd jwt vc. not the claims.

So should do claims.prettyClaims

}

return [credential_query_id, { ...result, record: credentialRecords[result.input_credential_index] }]
Expand Down
Loading