Development
The PEX Library supports the following actions:
- Creating a presentation definition / request
- Validating a presentation definition / conforming to the specifications v1 and v2
- Creating a Presentation
- Creating a Verifiable Presentation using a callback function
- Validating a presentation (submission) when received
- Input evaluations: Verification of presentation submissions conforming to the presentation definition
- Utilities: to build and use different models compliant with the DIF Presentation Exchange v2.0.0 specification.
- Support for DIF Presentation Exchange v1.0.0 specification.
Stateful storage, signature support or credential management should be implemented in separate libraries/modules that make use of this library. By keeping these separate, the PEX library will stay platform-agnostic and lean with respect to dependencies.
For PEX Users
This project has been created using:
yarn
version 1.22.5node
version >= 16
Follow these steps to install and run @sphereon/pex on your operating system:
How to install: Install @sphereon/pex:
The core functionality of the DIF Presentation Exchange can be outlined as follows:
-
Verifiers/Agents:
-
Holders/Wallets:
Verifier: Create a Presentation Definition object:
Presentation Definitions are objects that
articulate what proofs a Verifier requires. These help the Verifier to decide how or whether to interact with a Holder.
Presentation Definitions are composed of inputs, which describe the forms and details of the proofs they require, and
optional sets of selection rules, to allow Holders flexibility in cases where different types of proofs may satisfy an
input requirement.
PEX library supports two versions of presentation_definition
object. The details of it can be found
in @spehereon/pex-models
below you can find some tips about querying via a presentation_definition object:
- Using the
constraint
field:- You can use the constraint field for creating your query:
- for special cases, like querying fields that start with
@
you can use the following syntax:- You can use the following syntax, PEX will change it to correct query itself:
For querying the arrays, right now we don’t support the json-schema fully, but we do support the following syntax:
- using
[*]
like:
- using
.*
like:
- using
type: array
andcontains
keyword. PEX currently doesn’t support this syntax fully, but if you don’t rely on ourversionDiscovery
functionality and call the specific version of PEX (PEXv1 or PEXv2) yourself, you can use this syntax as well.
Verifier: Input Evaluation
Input evaluation is the primary mechanism by which a verifier determines whether a Verifiable Presentation and Presentation Submission from a holder matches the requested presentation definition from the request. Obviously a holder/wallet could also use the method to verify whether its submission would be valid, before contacting the verifier.
Holder: Credential Query
A credential query allows holders to filter their set of credentials for matches to a given presentation definition. This filters out any non-matching Credentials that are passed in. Please note that multiple credentials could be satisfying the definition.
Holder: Presentation creation (non-verifiable)
To create a Presentation without Proof (for Proofs, see Verifiable Presentation below) you have to pass in the Presentation Definition, selected Verifiable Credentials and an optional holder (DID). The result will be a Verifiable Presentation, without proofs, so actually a Presentation. It also contains the presentation submission data that the verifier can use.
It is left up to you to sign the Presentation and adding the proof and make it a truly Verifiable Presentation. There are different libraries that allow you to do this. You can also use the callback integration mentioned in the next chapter for this.
Holder: Verifiable Presentation with callback
NOTE: PEX does not support the creation of signatures by itself. That has to do with the fact that we didn’t want to rely on all kinds of signature suites and libraries. PEX has minimal dependencies currently, so that it can be used in all kinds of scenarios.
How did we solve this? We have created a callback mechanism, allowing you to supply a callback function that gets all
input allowing you to use your library of choice to create the signature. The callback needs to accept
a PresentationSignCallBackParams
object.
NOTE:
The method verifiablePresentationFrom
accepts the presentation definition and selected Verifiable Credentials as the
first two arguments, just like the presentationFrom
method. Next it accepts the callback function as argument and
a VerifiablePresentationFromOpts
object as last argument. The sign callback params, allow you to control the signature
process. You will have access in the callback to these params as well.
Before calling your callback function a few things happen. First, just like the presentationFrom
method, it
will evaluate whether the supplied credentials conform to the supplied presentation definition. Then it creates a
presentation, just like presentationFrom
. This presentation is provided for your convenience and can be used in your
callback for simple use cases. In more elaborate cases, like for instance with more complex signature suites and/or
selective disclosure, you will probably not use the IPresentation directly and make use of other arguments passed into
the callback, like the EvaluationResults
, PresentationSubmission
and Partial<IProof>
.
The proofOptions
and signatureOptions
, allow you to populate proof values directly. in which case
the Partial<IProof>
will have all fields filled to just add it as a proof to the presentation in your callback. This
does mean you would have to create the IPresentation first and sign that, which means you probably have no use for the
callback. If you do not provide these values, the Partial<IProof>
, will still be populated without the proofValue and
jws, based upon your options.
Presentation Sign Options
The options accepted by the verifiablePresentationFrom
are:
These options are available in your callback function by accessing the options
field in
the PresentationSignCallBackParams
.
Callback params object
The callback params gets supplied as the single argument to your callback function. It contains the Presentation
, a
partial ‘Proof’ typically missing the proofValue/jws signature. It also contains the initially supplied Verifiable
Credentials and Presentation Definition as well as your supplied options.
If contains the Presentation Submission object, which is also found in the presentation. You can use this to create your own IPresentation object if you want. Lastly it contains the evaluation results, which includes the mappings and logs about the evaluation.
You can either choose to use the Presentation
and partial Proof
together with the options
, or in more elaborate
use cases opt to use the PresentationSubmission
, EvaluationResults
and the options
for instance.
Simple example of the callback function
A simple use case using your library of choice for non-selective disclosure using an ed25519 key and signature.
Utilities
In addition to the core functionality above, the underlying validation methods are exposed as low-level helper functions.
For PEX developers
This project has been created using:
yarn
version 1.22.5node
version >= 16
Install
Build
Test
The test command runs:
eslint
prettier
unit
You can also run only a single section of these tests, using for example yarn test:unit
.
Utility scripts
There are several other utility scripts that help with development.
yarn fix
- runseslint --fix
as well asprettier
to fix code styleyarn cov
- generates code coverage report