Skip to content

Commit

Permalink
add request scheme
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra committed Oct 27, 2024
1 parent 3c2e24c commit f588af5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion agent/src/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ apiRouter.post('/offers/receive', async (request: Request, response: Response) =

const zCreatePresentationRequestBody = z.object({
presentationDefinition: z.record(z.string(), z.any()),
requestScheme: z.string(),
})

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)
console.log(authorizationRequest)

return response.json({
authorizationRequestUri: authorizationRequest,
authorizationRequestUri: authorizationRequest.replace('openid4vp://', createPresentationRequestBody.requestScheme),
verificationSessionId: verificationSession.id,
})
})
Expand Down
15 changes: 14 additions & 1 deletion app/components/VerifyBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Card } from './ui/card'
import { Label } from './ui/label'
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from './ui/select'
import { TypographyH3, TypographyH4 } from './ui/typography'
import { Input } from './ui/input'

export type CredentialType = 'mdoc' | 'sdjwt'
export type RequestType = 'name_age_over_21' | 'city' | 'age_birth_family_name'
Expand All @@ -22,9 +23,11 @@ type VerifyBlockProps = {
createRequest: ({
credentialType,
requestType,
requestScheme,
}: {
credentialType: CredentialType
requestType: RequestType
requestScheme: string
}) => Promise<{
verificationSessionId: string
authorizationRequestUri: string
Expand Down Expand Up @@ -53,6 +56,7 @@ export const VerifyBlock: React.FC<VerifyBlockProps> = ({ createRequest, flowNam
const isSuccess = requestStatus?.responseStatus === 'ResponseVerified'
const [credentialType, setCredentialType] = useState<CredentialType>('sdjwt')
const [requestType, setRequestType] = useState<RequestType>('name_age_over_21')
const [requestScheme, setRequestScheme] = useState<string>('openid4vp://')

useInterval({
callback: async () => {
Expand All @@ -73,7 +77,7 @@ export const VerifyBlock: React.FC<VerifyBlockProps> = ({ createRequest, flowNam
setVerificationSessionId(undefined)
setRequestStatus(undefined)

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

setVerificationSessionId(request.verificationSessionId)
setAuthorizationRequestUri(request.authorizationRequestUri)
Expand Down Expand Up @@ -141,6 +145,15 @@ export const VerifyBlock: React.FC<VerifyBlockProps> = ({ createRequest, flowNam
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label htmlFor="request-scheme">Scheme</Label>
<Input
name="request-scheme"
required
value={requestScheme}
onChange={({ target }) => setRequestScheme(target.value)}
/>
</div>
{!hasResponse && (
<div className="flex justify-center flex-col items-center bg-gray-200 min-h-64 w-full rounded-md">
{authorizationRequestUriHasBeenFetched ? (
Expand Down
2 changes: 2 additions & 0 deletions app/components/VerifyTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export function VerifyTab() {
const createRequestForVerification = async (options: {
credentialType: CredentialType
requestType: RequestType
requestScheme: string
}) => {
const issuer = (await getIssuer()).availableX509Certificates[0]
return await createRequest({
requestScheme: options.requestScheme,
presentationDefinition:
options.credentialType === 'sdjwt'
? getSdJwtPresentationDefinition(issuer, options.requestType)
Expand Down
3 changes: 3 additions & 0 deletions app/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ export async function receiveOffer(offerUri: string) {

export async function createRequest({
presentationDefinition,
requestScheme,
}: {
presentationDefinition: any
requestScheme: string
}) {
const response = await fetch(`${NEXT_PUBLIC_API_URL}/api/requests/create`, {
method: 'POST',
Expand All @@ -75,6 +77,7 @@ export async function createRequest({
},
body: JSON.stringify({
presentationDefinition,
requestScheme,
}),
})

Expand Down

0 comments on commit f588af5

Please sign in to comment.