From 4c87c67be9e087feef1539a514b16e32b6dc1bce Mon Sep 17 00:00:00 2001 From: Martin Auer Date: Tue, 19 Mar 2024 13:26:37 +0100 Subject: [PATCH] feat: allow ignoring revocation status when requesting credentials for request --- .../DifPresentationExchangeService.ts | 23 ++++++++++++++++--- .../DifPresentationExchangeProofFormat.ts | 5 ++-- ...fPresentationExchangeProofFormatService.ts | 23 +++++++++++++++---- .../router/credentialEndpoint.ts | 2 -- packages/openid4vc/tests/utils.ts | 2 -- 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/packages/core/src/modules/dif-presentation-exchange/DifPresentationExchangeService.ts b/packages/core/src/modules/dif-presentation-exchange/DifPresentationExchangeService.ts index f73b2b871b..c222580690 100644 --- a/packages/core/src/modules/dif-presentation-exchange/DifPresentationExchangeService.ts +++ b/packages/core/src/modules/dif-presentation-exchange/DifPresentationExchangeService.ts @@ -67,10 +67,27 @@ export class DifPresentationExchangeService { public async getCredentialsForRequest( agentContext: AgentContext, - presentationDefinition: DifPresentationExchangeDefinition + presentationDefinition: DifPresentationExchangeDefinition, + options?: { + filterByNonRevocationRequirements: boolean + } ): Promise { - const credentialRecords = await this.queryCredentialForPresentationDefinition(agentContext, presentationDefinition) - return getCredentialsForRequest(this.pex, presentationDefinition, credentialRecords) + let pd = presentationDefinition + + if (options?.filterByNonRevocationRequirements === false) { + pd = { + ...pd, + input_descriptors: (pd.input_descriptors = pd.input_descriptors.map((inputDescriptor) => { + return { + ...inputDescriptor, + constraints: { ...inputDescriptor.constraints, statuses: undefined }, + } + })), + } + } + + const credentialRecords = await this.queryCredentialForPresentationDefinition(agentContext, pd) + return getCredentialsForRequest(this.pex, pd, credentialRecords) } /** diff --git a/packages/core/src/modules/proofs/formats/dif-presentation-exchange/DifPresentationExchangeProofFormat.ts b/packages/core/src/modules/proofs/formats/dif-presentation-exchange/DifPresentationExchangeProofFormat.ts index 98c5df0d4d..c6844ed4ad 100644 --- a/packages/core/src/modules/proofs/formats/dif-presentation-exchange/DifPresentationExchangeProofFormat.ts +++ b/packages/core/src/modules/proofs/formats/dif-presentation-exchange/DifPresentationExchangeProofFormat.ts @@ -8,8 +8,9 @@ import type { ProofFormat } from '../ProofFormat' export type DifPresentationExchangeProposal = DifPresentationExchangeDefinitionV1 -// eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface DifPexGetCredentialsForProofRequestOptions {} +export interface DifPexGetCredentialsForProofRequestOptions { + filterByNonRevocationRequirements?: boolean +} export type DifPresentationExchangeRequest = { options?: { diff --git a/packages/core/src/modules/proofs/formats/dif-presentation-exchange/DifPresentationExchangeProofFormatService.ts b/packages/core/src/modules/proofs/formats/dif-presentation-exchange/DifPresentationExchangeProofFormatService.ts index befb69dca4..36afffa2d2 100644 --- a/packages/core/src/modules/proofs/formats/dif-presentation-exchange/DifPresentationExchangeProofFormatService.ts +++ b/packages/core/src/modules/proofs/formats/dif-presentation-exchange/DifPresentationExchangeProofFormatService.ts @@ -197,7 +197,9 @@ export class DifPresentationExchangeProofFormatService if (proofFormats?.presentationExchange?.credentials) { credentials = proofFormats.presentationExchange.credentials } else { - const credentialsForRequest = await ps.getCredentialsForRequest(agentContext, presentationDefinition) + const credentialsForRequest = await ps.getCredentialsForRequest(agentContext, presentationDefinition, { + filterByNonRevocationRequirements: true, + }) credentials = ps.selectCredentialsForRequest(credentialsForRequest) } @@ -354,7 +356,7 @@ export class DifPresentationExchangeProofFormatService public async getCredentialsForRequest( agentContext: AgentContext, - { requestAttachment }: ProofFormatGetCredentialsForRequestOptions + { requestAttachment, proofFormats }: ProofFormatGetCredentialsForRequestOptions ) { const ps = this.presentationExchangeService(agentContext) const { presentation_definition: presentationDefinition } = @@ -362,19 +364,30 @@ export class DifPresentationExchangeProofFormatService ps.validatePresentationDefinition(presentationDefinition) - const presentationSubmission = await ps.getCredentialsForRequest(agentContext, presentationDefinition) + // Set default values + const { filterByNonRevocationRequirements = true } = proofFormats?.presentationExchange ?? {} + const presentationSubmission = await ps.getCredentialsForRequest(agentContext, presentationDefinition, { + filterByNonRevocationRequirements, + }) return presentationSubmission } public async selectCredentialsForRequest( agentContext: AgentContext, - { requestAttachment }: ProofFormatSelectCredentialsForRequestOptions + { + requestAttachment, + proofFormats, + }: ProofFormatSelectCredentialsForRequestOptions ) { const ps = this.presentationExchangeService(agentContext) const { presentation_definition: presentationDefinition } = requestAttachment.getDataAsJson() - const credentialsForRequest = await ps.getCredentialsForRequest(agentContext, presentationDefinition) + // Set default values + const { filterByNonRevocationRequirements = true } = proofFormats?.presentationExchange ?? {} + const credentialsForRequest = await ps.getCredentialsForRequest(agentContext, presentationDefinition, { + filterByNonRevocationRequirements, + }) return { credentials: ps.selectCredentialsForRequest(credentialsForRequest) } } diff --git a/packages/openid4vc/src/openid4vc-issuer/router/credentialEndpoint.ts b/packages/openid4vc/src/openid4vc-issuer/router/credentialEndpoint.ts index 7c408ebcdc..ba61d8b780 100644 --- a/packages/openid4vc/src/openid4vc-issuer/router/credentialEndpoint.ts +++ b/packages/openid4vc/src/openid4vc-issuer/router/credentialEndpoint.ts @@ -3,8 +3,6 @@ import type { OpenId4VciCredentialRequest } from '../../shared' import type { OpenId4VciCredentialRequestToCredentialMapper } from '../OpenId4VcIssuerServiceOptions' import type { Router, Response } from 'express' -import { CredoError, JwsService, Jwt } from '@credo-ts/core' - import { getRequestContext, sendErrorResponse } from '../../shared/router' import { OpenId4VcIssuerService } from '../OpenId4VcIssuerService' import { getCNonceFromCredentialRequest } from '../util/credentialRequest' diff --git a/packages/openid4vc/tests/utils.ts b/packages/openid4vc/tests/utils.ts index 8a9ba68c94..18e707ad26 100644 --- a/packages/openid4vc/tests/utils.ts +++ b/packages/openid4vc/tests/utils.ts @@ -9,8 +9,6 @@ import type { TenantsModule } from '@credo-ts/tenants' import type { Observable } from 'rxjs' import { Agent, LogLevel, utils } from '@credo-ts/core' -import { tap, ReplaySubject, lastValueFrom, filter, timeout, catchError, take, map } from 'rxjs' -import { threadId } from 'worker_threads' import { TestLogger,