Skip to content

Commit

Permalink
feat: allow ignoring revocation status when requesting credentials fo…
Browse files Browse the repository at this point in the history
…r request
  • Loading branch information
auer-martin committed Mar 19, 2024
1 parent 5992c57 commit 4c87c67
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,27 @@ export class DifPresentationExchangeService {

public async getCredentialsForRequest(
agentContext: AgentContext,
presentationDefinition: DifPresentationExchangeDefinition
presentationDefinition: DifPresentationExchangeDefinition,
options?: {
filterByNonRevocationRequirements: boolean
}
): Promise<DifPexCredentialsForRequest> {
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)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -354,27 +356,38 @@ export class DifPresentationExchangeProofFormatService

public async getCredentialsForRequest(
agentContext: AgentContext,
{ requestAttachment }: ProofFormatGetCredentialsForRequestOptions<DifPresentationExchangeProofFormat>
{ requestAttachment, proofFormats }: ProofFormatGetCredentialsForRequestOptions<DifPresentationExchangeProofFormat>
) {
const ps = this.presentationExchangeService(agentContext)
const { presentation_definition: presentationDefinition } =
requestAttachment.getDataAsJson<DifPresentationExchangeRequest>()

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<DifPresentationExchangeProofFormat>
{
requestAttachment,
proofFormats,
}: ProofFormatSelectCredentialsForRequestOptions<DifPresentationExchangeProofFormat>
) {
const ps = this.presentationExchangeService(agentContext)
const { presentation_definition: presentationDefinition } =
requestAttachment.getDataAsJson<DifPresentationExchangeRequest>()

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) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 0 additions & 2 deletions packages/openid4vc/tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4c87c67

Please sign in to comment.