PEX icon indicating copy to clipboard operation
PEX copied to clipboard

Handling of optional property in fields object fails

Open maycon-mello opened this issue 10 months ago • 3 comments

I'm submitting a ... [x] bug report [ ] feature request [ ] question about the decisions made in the repository [ ] question about how to use this project

Summary According to https://identity.foundation/presentation-exchange/#input-descriptor-object:

The fields object MAY contain an optional property. The value of this property MUST be a boolean, wherein true indicates the field is optional, and false or non-presence of the property indicates the field is required.

The library is not able to handle the optional property in the fields object. Filtering or presentation evalutation fails with an InvalidPresentation error.

Other information

Code snippet:

// PEX "version": "3.3.1"
const { PEX } = require("@sphereon/pex");

const pex = new PEX();
const presentationDefinition = {
  id: "test",
  input_descriptors: [
    {
      id: "Test1",
      name: "Testing the optional attribute in the fields object",
      purpose: "Testing purposes",
      constraints: {
        fields: [
          {
            path: ["$.credentialSubject.id"],
          },
          {
            path: ["$.expirationDate"],
            optional: true,
          },
        ],
      },
    },
  ],
};

const result = pex.selectFrom(presentationDefinition, [], []);

Output:


/Users/mzm/test-pex/node_modules/@sphereon/pex/dist/main/lib/types/SSITypesBuilder.js:35
            throw versionResult.error;
            ^
This is not a valid PresentationDefinition
(Use `node --trace-uncaught ...` to show where the exception was thrown)

Node.js v18.17.1

maycon-mello avatar Apr 08 '24 16:04 maycon-mello

Yeah good one. Probably what we will do is create a new release of the models/OpenAPI schema's, which means this error will not be present. But actually taking the optionality into account will have to wait a small bit. So will leave this ticket open

nklomp avatar Apr 10 '24 14:04 nklomp

Okay this has been added to https://github.com/Sphereon-Opensource/PEX/releases/tag/v3.3.2 Will leave this ticket open, as I only added support for the property. We do nothing with it at present

nklomp avatar Apr 24 '24 20:04 nklomp

@nklomp the optional field still produces an error when using definitionVersionDiscovery or evaluatePresentation, looks like its missing from resources/presentation_definition_v2.schema.json

cykoder avatar May 07 '24 22:05 cykoder