Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 15 additions & 3 deletions src/controllers/openid4vc/holder/holder.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,14 @@ export class HolderService {
public async resolveProofRequest(agentReq: Req, body: ResolveProofRequest) {
return (await agentReq.agent.modules.openid4vc.holder.resolveOpenId4VpAuthorizationRequest(
body.proofRequestUri,
body.options,
)) as any
}

public async acceptPresentationRequest(agentReq: Req, body: ResolveProofRequest) {
const resolved = await agentReq.agent.modules.openid4vc.holder.resolveOpenId4VpAuthorizationRequest(
body.proofRequestUri,
body.options,
)
// const presentationExchangeService = agent.dependencyManager.resolve(DifPresentationExchangeService)

Expand All @@ -224,10 +226,20 @@ export class HolderService {
dcql: {
credentials: dcqlCredentials as DcqlCredentialsForRequest,
},
origin: body.options?.origin,
})
const result: any = submissionResult.serverResponse
result['authorizationResponsePayload'] = submissionResult.authorizationResponsePayload
return result
if (submissionResult.serverResponse) {
const { serverResponse, ...rest } = submissionResult

return {
...serverResponse,
body: rest,
} as any
}
return {
status: 200,
body: submissionResult,
} as any
}

public async deleteCredential(agentReq: Req, { credentialId, credentialType }: DeleteCredentialBody) {
Expand Down
3 changes: 3 additions & 0 deletions src/controllers/openid4vc/types/holder.types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { ResolveOpenId4VpAuthorizationRequestOptions } from '@credo-ts/openid4vc'

export interface ResolveCredentialOfferBody {
credentialOfferUri: string
}
Expand All @@ -17,6 +19,7 @@ export interface AuthorizeRequestCredentialOffer {

export interface ResolveProofRequest {
proofRequestUri: string
options?: ResolveOpenId4VpAuthorizationRequestOptions
}

export interface AcceptProofRequest {
Expand Down
8 changes: 7 additions & 1 deletion src/controllers/openid4vc/types/verifier.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/explicit-member-accessibility */
import type { DifPresentationExchangeDefinitionV2 } from '@credo-ts/core'
import type { SubmissionRequirement, Format, Issuance, InputDescriptorV2 } from '@sphereon/pex-models'
import type { Format, Issuance, InputDescriptorV2 } from '@sphereon/pex-models'

export enum ResponseModeEnum {
DIRECT_POST = 'direct_post',
Expand Down Expand Up @@ -109,3 +109,9 @@ export class OpenId4VcSiopCreateVerifierOptions {
export class OpenId4VcUpdateVerifierRecordOptions {
clientMetadata?: OpenId4VcSiopVerifierClientMetadata
}

export interface OpenId4VCDCQLVerificationSessionRecord {
verificationSessionId: string
authorizationResponse: Record<string, unknown>
origin?: string
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Agent } from '@credo-ts/core'
import { OpenId4VcVerificationSessionState } from '@credo-ts/openid4vc'
import { Request as Req } from 'express'
import { Controller, Get, Path, Query, Route, Request, Security, Tags, Post, Body } from 'tsoa'
import { injectable } from 'tsyringe'

import { SCOPES } from '../../../enums'
import ErrorHandlingService from '../../../errorHandlingService'
import { CreateAuthorizationRequest } from '../types/verifier.types'
import { CreateAuthorizationRequest, OpenId4VCDCQLVerificationSessionRecord } from '../types/verifier.types'

import { VerificationSessionsService } from './verification-sessions.service'

Expand Down Expand Up @@ -87,4 +86,19 @@ export class VerificationSessionsController extends Controller {
throw ErrorHandlingService.handle(error)
}
}

/**
* Verify authorization response for a DCAPI proof request
*/
@Post('/verify-authorization-response')
public async verifyDcqlProofRequest(
@Request() request: Req,
@Body() verifydcqlProofRquest: OpenId4VCDCQLVerificationSessionRecord,
) {
try {
return await this.verificationSessionService.verifyAuthorizationResponse(request, verifydcqlProofRquest)
} catch (error) {
throw ErrorHandlingService.handle(error)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import {
ClientIdPrefix,
CreateAuthorizationRequest,
OpenId4VcIssuerX5cOptions,
OpenId4VCDCQLVerificationSessionRecord,
OpenId4VcIssuerX5c,
ClientIdPrefix,
OpenId4VcIssuerX5cOptions,
ResponseModeEnum,
} from '../types/verifier.types'

Expand Down Expand Up @@ -200,4 +204,16 @@ export class VerificationSessionsService {
: undefined,
} as any
}

public async verifyAuthorizationResponse(
agentReq: Req,
verifydcqlProofRquest: OpenId4VCDCQLVerificationSessionRecord,
) {
const verifier = agentReq.agent.modules.openid4vc.verifier
if (!verifier) {
throw new Error('OID4VC verifier module not initialized')
}
const result = (await verifier.verifyAuthorizationResponse({ ...verifydcqlProofRquest })) as any
return result
}
}