Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
fix: Properly heck array length
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Aug 3, 2023
1 parent c0bb0db commit 21ca439
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
24 changes: 12 additions & 12 deletions src/authorization-response/PresentationExchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export class PresentationExchange {

/**
* Construct presentation submission from selected credentials
* @param presentationDefinition: payload object received by the OP from the RP
* @param presentationDefinition payload object received by the OP from the RP
* @param selectedCredentials
* @param presentationSignCallback
* @param options?
* @param options
*/
public async createVerifiablePresentation(
presentationDefinition: IPresentationDefinition,
Expand Down Expand Up @@ -83,7 +83,7 @@ export class PresentationExchange {
* if requestPayload doesn't contain any valid presentationDefinition throws an error
* if PEX library returns any error in the process, throws the error
* returns the SelectResults object if successful
* @param presentationDefinition: object received by the OP from the RP
* @param presentationDefinition object received by the OP from the RP
* @param opts
*/
public async selectVerifiableCredentialsForSubmission(
Expand Down Expand Up @@ -114,8 +114,8 @@ export class PresentationExchange {
/**
* validatePresentationAgainstDefinition function is called mainly by the RP
* after receiving the VP from the OP
* @param presentationDefinition: object containing PD
* @param verifiablePresentation:
* @param presentationDefinition object containing PD
* @param verifiablePresentation
* @param opts
*/
public static async validatePresentationAgainstDefinition(
Expand Down Expand Up @@ -157,7 +157,7 @@ export class PresentationExchange {
* throws exception if the PresentationDefinition is not valid
* returns null if no property named "presentation_definition" is found
* returns a PresentationDefinition if a valid instance found
* @param authorizationRequestPayload: object that can have a presentation_definition inside
* @param authorizationRequestPayload object that can have a presentation_definition inside
* @param version
*/
public static async findValidPresentationDefinitions(
Expand All @@ -170,22 +170,22 @@ export class PresentationExchange {
const vpTokens: PresentationDefinitionV1[] | PresentationDefinitionV2[] = extractDataFromPath(
authorizationRequestPayload,
'$..vp_token.presentation_definition'
);
).map((d) => d.value);
const vpTokenRefs = extractDataFromPath(authorizationRequestPayload, '$..vp_token.presentation_definition_uri');
if (vpTokens && vpTokens.length && vpTokenRefs && vpTokenRefs.length) {
throw new Error(SIOPErrors.REQUEST_CLAIMS_PRESENTATION_DEFINITION_BY_REF_AND_VALUE_NON_EXCLUSIVE);
}
if (vpTokens && vpTokens.length) {
vpTokens.forEach((vpToken) => {
vpTokens.forEach((vpToken: PresentationDefinitionV1 | PresentationDefinitionV2) => {
if (allDefinitions.find((value) => value.definition.id === vpToken.id)) {
console.log(
`Warning. We encountered presentation definition with id ${vpToken.id}, more then once whilst processing! Make sure your payload is valid!`
);
return;
}
PresentationExchange.assertValidPresentationDefinition(vpToken.value);
PresentationExchange.assertValidPresentationDefinition(vpToken);
allDefinitions.push({
definition: vpToken.value,
definition: vpToken,
location: PresentationDefinitionLocation.CLAIMS_VP_TOKEN,
version,
});
Expand Down Expand Up @@ -227,8 +227,8 @@ export class PresentationExchange {
const definitionsFromList = extractDataFromPath(authorizationRequestPayload, '$.presentation_definition[*]');
const definitionRefs = extractDataFromPath(authorizationRequestPayload, '$.presentation_definition_uri');
const definitionRefsFromList = extractDataFromPath(authorizationRequestPayload, '$.presentation_definition_uri[*]');
const hasPD = (definitions && definitions.length > 0) || (definitionsFromList && definitionsFromList > 0);
const hasPdRef = (definitionRefs && definitionRefs.length > 0) || (definitionRefsFromList && definitionsFromList > 0);
const hasPD = (definitions && definitions.length > 0) || (definitionsFromList && definitionsFromList.length > 0);
const hasPdRef = (definitionRefs && definitionRefs.length > 0) || (definitionRefsFromList && definitionsFromList.length > 0);
if (hasPD && hasPdRef) {
throw new Error(SIOPErrors.REQUEST_CLAIMS_PRESENTATION_DEFINITION_BY_REF_AND_VALUE_NON_EXCLUSIVE);
}
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/ObjectUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import jp from 'jsonpath';
import { JSONPath as jp } from '@astronautlabs/jsonpath';

export function extractDataFromPath(obj: unknown, path: string) {
export function extractDataFromPath(obj: unknown, path: string): { path: string[]; value: any }[] {

Check warning on line 3 in src/helpers/ObjectUtils.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type

Check warning on line 3 in src/helpers/ObjectUtils.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
return jp.nodes(obj, path);
}

Expand Down

0 comments on commit 21ca439

Please sign in to comment.