Skip to content

Commit

Permalink
refactor: Checking whether PDs and DCQL are present
Browse files Browse the repository at this point in the history
  • Loading branch information
zoemaas committed Jan 8, 2025
1 parent d002379 commit 43420cf
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/siop-oid4vp/lib/rp/RP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,16 @@ export class RP {
}
}

const hasPD = (this._verifyResponseOptions.presentationDefinitions !== undefined && this._verifyResponseOptions.presentationDefinitions !== null || (Array.isArray(this._verifyResponseOptions.presentationDefinitions) && this._verifyResponseOptions.presentationDefinitions.length > 0)) ||
(opts.presentationDefinitions !== undefined && opts.presentationDefinitions !== null || (Array.isArray(opts.presentationDefinitions) && opts.presentationDefinitions.length > 0))
const hasDcql = (this._verifyResponseOptions.dcqlQuery !== undefined && this._verifyResponseOptions.dcqlQuery !== null) || (opts.dcqlQuery !== undefined && opts.dcqlQuery !== null)

if (hasPD && hasDcql) {
throw Error(`Only Presentation Definitions or DCQL is required`)
} else if (!hasPD && !hasDcql) {
throw Error(`Either a Presentation Definition or DCQL is required`)
}

return {
...this._verifyResponseOptions,
verifyJwtCallback: this._verifyResponseOptions.verifyJwtCallback,
Expand All @@ -424,12 +434,8 @@ export class RP {
state,
nonce,
verification: mergeVerificationOpts(this._verifyResponseOptions, opts),
...(opts?.presentationDefinitions && !opts?.dcqlQuery && {
presentationDefinitions: this._verifyResponseOptions.presentationDefinitions ?? opts?.presentationDefinitions
}),
...(opts?.dcqlQuery && !opts?.presentationDefinitions && {
dcqlQuery: this._verifyResponseOptions.dcqlQuery ?? opts?.dcqlQuery
})
presentationDefinitions: this._verifyResponseOptions.presentationDefinitions ?? opts?.presentationDefinitions,
dcqlQuery: this._verifyResponseOptions.dcqlQuery ?? opts?.dcqlQuery
}
}

Expand Down

0 comments on commit 43420cf

Please sign in to comment.