As explained by our Verifier ADR, the library is composed of verification methods, that are run over a document and provide fragments containing details about each verification. In this guide we will learn how to write custom verification method and how you can distribute your own verifier.
We will write a verification method having the following rules:
- it must run only on document having their version equal to
- it must return a valid fragment, if and only if the document data hold a name property with the value
Certificate of Completion
Document version must be equal to
This is where
test methods comes into play. We will use the
test method to return when the verification method run, and the
skip method to explain why it didn't run:
DOCUMENT_INTEGRITYtype because we check for the content of the document.
Document hold correct
Once we have decided
when the verification method run, it's time to write the logic of the verifier in the
verify. We will use getData utility to access the data of the document and return the appropriate fragment depending on the content:
verify function is built to run a list of verification method. Each verifier will produce a fragment that will help to determine if the document is valid. Open Attestation comes with its own set of verification methods available in
verificationBuilder function help you to create custom verification method. You can reuse the default one exported by the library.
Let's build a new verifier using our custom verification method:
The document that we created is not valid against our own verifier because the name property does not exist. Try again with the following document:
You are ready to distribute your own custom verifier
- opencerts-verify is an example of a custom verifier.
- Using Typescript ? The library exports a set of useful types to help you build verification method. Checkout the source code.
- Verification SDK implementation follow our Verifier ADR.
- Found a bug ? Having a question ? Want to share an idea ? Reach us out on the Github repository.`