Skip to content

Commit

Permalink
add response mode
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra committed Oct 30, 2024
1 parent 53a7d24 commit 06baa03
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion agent/src/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ apiRouter.post('/offers/receive', async (request: Request, response: Response) =
const zCreatePresentationRequestBody = z.object({
presentationDefinition: z.record(z.string(), z.any()),
requestScheme: z.string(),
responseMode: z.enum(['direct_post.jwt', 'direct_post']),
})

apiRouter.post('/requests/create', async (request: Request, response: Response) => {
Expand Down Expand Up @@ -166,7 +167,7 @@ apiRouter.post('/requests/create', async (request: Request, response: Response)
definition: definition as any,
},
additionalPayloadClaims,
responseMode: 'direct_post.jwt',
responseMode: createPresentationRequestBody.responseMode,
})

console.log(authorizationRequest)
Expand Down
29 changes: 28 additions & 1 deletion app/components/VerifyBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { TypographyH3, TypographyH4 } from './ui/typography'

export type CredentialType = 'mdoc' | 'sdjwt'
export type RequestType = 'name_age_over_21' | 'city' | 'age_birth_family_name'
export type ResponseMode = 'direct_post' | 'direct_post.jwt'

type VerifyBlockProps = {
flowName: string
Expand All @@ -24,10 +25,12 @@ type VerifyBlockProps = {
credentialType,
requestType,
requestScheme,
responseMode,
}: {
credentialType: CredentialType
requestType: RequestType
requestScheme: string
responseMode: ResponseMode
}) => Promise<{
verificationSessionId: string
authorizationRequestUri: string
Expand All @@ -45,6 +48,7 @@ export const VerifyBlock: React.FC<VerifyBlockProps> = ({ createRequest, flowNam
definition?: Record<string, unknown>
presentations?: Array<string | Record<string, unknown>>
}>()
const [responseMode, setResponseMode] = useState<ResponseMode>('direct_post.jwt')

const enabled =
verificationSessionId !== undefined &&
Expand Down Expand Up @@ -77,7 +81,7 @@ export const VerifyBlock: React.FC<VerifyBlockProps> = ({ createRequest, flowNam
setVerificationSessionId(undefined)
setRequestStatus(undefined)

const request = await createRequest({ credentialType, requestType, requestScheme })
const request = await createRequest({ credentialType, requestType, requestScheme, responseMode })

setVerificationSessionId(request.verificationSessionId)
setAuthorizationRequestUri(request.authorizationRequestUri)
Expand Down Expand Up @@ -154,6 +158,29 @@ export const VerifyBlock: React.FC<VerifyBlockProps> = ({ createRequest, flowNam
onChange={({ target }) => setRequestScheme(target.value)}
/>
</div>
<div className="space-y-2">
<Label htmlFor="response-mode">Response Mode</Label>
<Select
name="response-mode"
required
value={responseMode}
onValueChange={(value) => setResponseMode(value as ResponseMode)}
>
<SelectTrigger className="w-1/2">
<SelectValue placeholder="Select a credential type" />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem key="direct_post.jwt" value="direct_post.jwt">
<pre>direct_post.jwt - Response Encryption</pre>
</SelectItem>
<SelectItem key="direct_post" value="direct_post">
<pre>direct_post</pre>
</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
</div>
{!hasResponse && (
<div className="flex justify-center flex-col items-center bg-gray-200 min-h-64 w-full rounded-md">
{authorizationRequestUriHasBeenFetched ? (
Expand Down
4 changes: 3 additions & 1 deletion app/components/VerifyTab.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react'
import { createRequest, getIssuer, getX509Certificate } from '../lib/api'
import { type CredentialType, type RequestType, VerifyBlock } from './VerifyBlock'
import { type CredentialType, type RequestType, type ResponseMode, VerifyBlock } from './VerifyBlock'

const randomId = () => (Math.random() + 1).toString(36).substring(7)

Expand All @@ -11,6 +11,7 @@ export function VerifyTab() {
credentialType: CredentialType
requestType: RequestType
requestScheme: string
responseMode: ResponseMode
}) => {
const issuer = (await getIssuer()).availableX509Certificates[0]
return await createRequest({
Expand All @@ -19,6 +20,7 @@ export function VerifyTab() {
options.credentialType === 'sdjwt'
? getSdJwtPresentationDefinition(issuer, options.requestType)
: getMdocPresentationDefinition(options.requestType),
responseMode: options.responseMode,
})
}

Expand Down
3 changes: 3 additions & 0 deletions app/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ export async function receiveOffer(offerUri: string) {
export async function createRequest({
presentationDefinition,
requestScheme,
responseMode,
}: {
presentationDefinition: any
requestScheme: string
responseMode: 'direct_post' | 'direct_post.jwt'
}) {
const response = await fetch(`${NEXT_PUBLIC_API_URL}/api/requests/create`, {
method: 'POST',
Expand All @@ -78,6 +80,7 @@ export async function createRequest({
body: JSON.stringify({
presentationDefinition,
requestScheme,
responseMode,
}),
})

Expand Down

0 comments on commit 06baa03

Please sign in to comment.