Skip to content

Commit

Permalink
feat: allow setting purpose
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra committed Dec 7, 2024
1 parent 2c2089f commit e91406d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
18 changes: 14 additions & 4 deletions agent/src/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
getJwkFromKey,
} from '@credo-ts/core'
import { OpenId4VcVerificationSessionState } from '@credo-ts/openid4vc'
import express, { type NextFunction, type Request, type Response } from 'express'
import express, { query, type NextFunction, type Request, type Response } from 'express'
import z from 'zod'
import { agent } from './agent'
import { validateVerificationRequest, zValidateVerificationRequestSchema } from './ai'
Expand Down Expand Up @@ -248,10 +248,11 @@ const zCreatePresentationRequestBody = z.object({
presentationDefinitionId: z.string(),
requestScheme: z.string(),
responseMode: z.enum(['direct_post.jwt', 'direct_post']),
purpose: z.string().optional(),
})

apiRouter.post('/requests/create', async (request: Request, response: Response) => {
const { requestSignerType, presentationDefinitionId, requestScheme, responseMode } =
const { requestSignerType, presentationDefinitionId, requestScheme, responseMode, purpose } =
await zCreatePresentationRequestBody.parseAsync(request.body)

const x509Certificate = getX509Certificate()
Expand Down Expand Up @@ -293,13 +294,22 @@ apiRouter.post('/requests/create', async (request: Request, response: Response)
presentationExchange:
'input_descriptors' in definition
? {
definition,
definition: {
...definition,
purpose: purpose ?? definition.purpose,
},
}
: undefined,
dcql:
'credentials' in definition
? {
query: definition,
query: {
...definition,
credential_sets:
purpose && definition.credential_sets
? definition.credential_sets.map((set) => ({ ...set, purpose }))
: definition.credential_sets,
},
}
: undefined,
responseMode,
Expand Down
4 changes: 4 additions & 0 deletions agent/src/verifiers/turboKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ export const turboKeysVerifier = {
name: 'PID and MDL - Rent a Car (both either sd-jwt vc or mso_mdoc, prefer sd-jwt vc)',
credential_sets: [
{
purpose: 'To secure your car reservations and finalize the transaction, we require the following attributes',
options: [['pid_sd_jwt'], ['pid_mdoc']],
},
{
purpose: 'To secure your car reservations and finalize the transaction, we require the following attributes',
options: [['mdl_sd_jwt'], ['mdl_mdoc']],
},
],
Expand Down Expand Up @@ -176,9 +178,11 @@ export const turboKeysVerifier = {
name: 'PID and MDL - Rent a Car (both either sd-jwt vc or mso_mdoc, prefer mdoc)',
credential_sets: [
{
purpose: 'To secure your car reservations and finalize the transaction, we require the following attributes',
options: [['pid_mdoc'], ['pid_sd_jwt']],
},
{
purpose: 'To secure your car reservations and finalize the transaction, we require the following attributes',
options: [['mdl_mdoc'], ['mdl_sd_jwt']],
},
],
Expand Down
7 changes: 7 additions & 0 deletions app/components/VerifyBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const VerifyBlock: React.FC<VerifyBlockProps> = ({ createRequest, flowNam
const isSuccess = requestStatus?.responseStatus === 'ResponseVerified'
const [presentationDefinitionId, setPresentationDefinitionId] = useState<string>()
const [requestScheme, setRequestScheme] = useState<string>('openid4vp://')
const [purpose, setPurpose] = useState<string>()
const [requestSignerType, setRequestSignerType] = useState<RequestSignerType>('x5c')
const [useCase, setUseCase] = useState<string>('')
useEffect(() => {
Expand Down Expand Up @@ -94,6 +95,7 @@ export const VerifyBlock: React.FC<VerifyBlockProps> = ({ createRequest, flowNam
presentationDefinitionId: id,
requestScheme,
responseMode,
purpose: purpose && purpose !== '' ? purpose : undefined,
requestSignerType,
})
setRequestStatus(request)
Expand Down Expand Up @@ -194,6 +196,11 @@ export const VerifyBlock: React.FC<VerifyBlockProps> = ({ createRequest, flowNam
onChange={({ target }) => setRequestScheme(target.value)}
/>
</div>
<div className="space-y-2">
<Label htmlFor="request-purpose">Purpose</Label>
<span className="text-xs"> - Optional. Each request has an associated default purpose</span>
<Input name="request-purpose" required value={purpose} onChange={({ target }) => setPurpose(target.value)} />
</div>
<div className="space-y-2">
<Label htmlFor="response-mode">Response Mode</Label>
<Select
Expand Down
1 change: 1 addition & 0 deletions app/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export async function createRequest(data: {
presentationDefinitionId: string
requestScheme: string
responseMode: 'direct_post' | 'direct_post.jwt'
purpose?: string
}) {
const response = await fetch(`${NEXT_PUBLIC_API_URL}/api/requests/create`, {
method: 'POST',
Expand Down

0 comments on commit e91406d

Please sign in to comment.