Skip to content

Commit

Permalink
chore: fixed definitionVersionDiscovery handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderPostma committed Jan 23, 2025
1 parent 19382fa commit 44db119
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions packages/siop-oid4vp/lib/authorization-request/Payload.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PEX } from '@sphereon/pex'

import { getNonce, removeNullUndefined } from '../helpers'
import { getNonce, getWithUrl, removeNullUndefined } from '../helpers'
import { RequestObject } from '../request-object'
import { isTarget, isTargetOrNoTargets } from '../rp/Opts'
import { RPRegistrationMetadataPayloadSchema } from '../schemas'
Expand All @@ -11,13 +11,13 @@ import {
PassBy,
RPRegistrationMetadataPayload,
SIOPErrors,
SupportedVersion,
SupportedVersion
} from '../types'

import { createRequestRegistration } from './RequestRegistration'
import { ClaimPayloadOptsVID1, CreateAuthorizationRequestOpts, PropertyTarget } from './types'

export const createPresentationDefinitionClaimsProperties = (opts: ClaimPayloadOptsVID1): ClaimPayloadVID1 => {
export const createPresentationDefinitionClaimsProperties = async (opts: ClaimPayloadOptsVID1): Promise<ClaimPayloadVID1> => {
if (
!opts ||
!opts.vp_token ||
Expand All @@ -26,10 +26,14 @@ export const createPresentationDefinitionClaimsProperties = (opts: ClaimPayloadO
return undefined
}

if (opts.vp_token.presentation_definition) {
const discoveryResult = PEX.definitionVersionDiscovery(opts.vp_token.presentation_definition)
let presentationDef = opts.vp_token.presentation_definition
if (!presentationDef && opts.vp_token.presentation_definition_uri) {
presentationDef = await getWithUrl(opts.vp_token.presentation_definition_uri, false)
}
if (presentationDef) {
const discoveryResult = PEX.definitionVersionDiscovery(presentationDef)
if (discoveryResult.error) {
throw new Error(SIOPErrors.REQUEST_CLAIMS_PRESENTATION_DEFINITION_NOT_VALID)
return Promise.reject(new Error(SIOPErrors.REQUEST_CLAIMS_PRESENTATION_DEFINITION_NOT_VALID))
}
}

Expand All @@ -55,7 +59,7 @@ export const createAuthorizationRequestPayload = async (
// TODO: if opts['registration] throw Error to get rid of test code using that key
const clientMetadata = opts['registration'] ?? (opts.clientMetadata as ClientMetadataOpts)
const registration = await createRequestRegistration(clientMetadata, opts)
const claims = opts.version >= SupportedVersion.SIOPv2_ID1 ? opts.payload.claims : createPresentationDefinitionClaimsProperties(opts.payload.claims)
const claims = opts.version >= SupportedVersion.SIOPv2_ID1 ? opts.payload.claims : await createPresentationDefinitionClaimsProperties(opts.payload.claims)
const isRequestTarget = isTargetOrNoTargets(PropertyTarget.AUTHORIZATION_REQUEST, opts.requestObject.targets)
const isRequestByValue = opts.requestObject.passBy === PassBy.VALUE

Expand Down
2 changes: 1 addition & 1 deletion packages/siop-oid4vp/lib/request-object/Payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const createRequestObjectPayload = async (opts: CreateAuthorizationReques

const state = getState(payload.state)
const registration = await createRequestRegistration(opts.clientMetadata, opts)
const claims = createPresentationDefinitionClaimsProperties(payload.claims)
const claims = await createPresentationDefinitionClaimsProperties(payload.claims)

const metadataKey = opts.version >= SupportedVersion.SIOPv2_D11.valueOf() ? 'client_metadata' : 'registration'
const clientId = payload.client_id ?? registration.payload[metadataKey]?.client_id
Expand Down

0 comments on commit 44db119

Please sign in to comment.