cert-verifier-js
A library to parse and verify Blockcerts certificates.
Usage
Install
$ npm i cert-verifier-js
Import
Commonjs
Exposed by default:
var Certificate = ;var certificate = certificateDefinition;
ES module
;let certificate = certificateDefinition;
Script tag (iife)
Examples
You can find more examples in the test folder.
Parse a Blockcert certificate
var fs = ; fs;
Verify a Blockcert certificate
var fs = ; fs;
API
Certificate
new Certificate(certificateDefinition)
const certificate = certificateDefinition;
The constructor automatically parses a certificate.
Parameter
certificateDefinition
(String|Object
): the certificate definition. Can either be a string or a JSON object.
Returns
The certificate instance has the following properties:
certificateImage
:String
. Raw data of the certificate imagecertificateJson
:Object
. Certificate JSON objectchain
:Object
. Chain the certificate was issued ondescription
:String
. Description of the certificateexpires
:String
. Expiration dateid
:String
. Certificate's IDisFormatValid
:Boolean
. Indicates whether or not the certificate has a valid formatissuedOn
:String
. Datetime of issuance (ISO-8601)issuer
:Object
. Certificate issuermetadataJson
:Object
. Certificate metadata objectname
:String
. Name of the certificatepublicKey
:String
. Certificate's public keyreceipt
:String
. Certificate's receiptrecipientFullName
:String
. Full name of recipientrecordLink
:String
. Link to the certificate recordrevocationKey
:String|null
. Revocation key (if any)sealImage
:String
. Raw data of the seal's image;signature
:String
. Certificate's signaturesignatureImage
:String
. Raw data of the certificate's signature image;subtitle
:String
. Subtitle of the certificatetransactionId
:String
. Transaction IDrawTransactionLink
:String
. Raw transaction IDtransactionLink
:String
. Transaction linkverificationSteps
:VerificationStep[]
. The array of steps the certificate will have to go through during verificationversion
:CertificateVersion
. Version of the certificate
Note: verificationSteps
is generated according to the nature of the certificate. The full steps array is provided ahead of verification in order to give more flexibility to the consumer. For example, you might want to pre-render the verification steps for animation, or render a count of steps and/or sub-steps.
VerificationStep
has the following shape:
code: 'formatValidation' label: 'Format validation' labelPending: 'Validating format' subSteps: code: 'getTransactionId' label: 'Get transaction ID' labelPending: 'Getting transaction ID' parentStep: 'formatValidation' ...
verify(stepCallback)
This will run the verification of a certificate. The function is asynchronous.
const certificateVerification = await certificate);console;
Parameters
({code, label, status, errorMessage}) => {}
(Function
): callback function called whenever a substep status has changed. The callback parameter has 4 properties:code
: substep codelabel
: readable label of the substepstatus
: substep status (success
,failure
,starting
)errorMessage
: error message (optional)
Returns
The final verification status:
code status errorMessage
code
: code of the final step (final
)status
: final verification status (success
,failure
)errorMessage
: error message (optional)
Constants
Several constants are being exposed:
;
- [
BLOCKCHAINS
]https://github.com/blockchain-certificates/cert-verifier-js/blob/master/src/constants/blockchains.js: descriptive object of all blockchains supported by the library STEPS
: descriptive object of all verification steps (top level)SUB_STEPS
: descriptive object of all verification substepsCERTIFICATE_VERSIONS
: list of all certificate versionsVERIFICATION_STATUSES
Contribute
Run the tests
$ npm run test
Build
$ npm run build
The build files are in the dist
folder.
Verification process
If you want more details about the verification process, please check out the documentation.
Contact
Contact us at the Blockcerts community forum.