Official VerificaC19 SDK implementation for Node.js (official SDKs list).
Read this in other languages: Italian 🇮🇹.
- Node.js version >= 12.x
- MongoDB version >= 5.x (used to store CRL)
npm i verificac19-sdk
CRL data will be stored in a MongoDB database. This repository provides a simple
docker-compose.yml
file (dev instance) with a replica set. By default the
connection string is mongodb://root:example@localhost:27017/VC19?authSource=admin
,
if you want to change it, set VC19_MONGODB_URL
env variable.
You can download and cache rules, CRL data and DSCs using Service
module.
const {Service} = require('verificac19-sdk');
const main = async () => {
await Service.updateAll();
}
.cache
,
to change it, set VC19_CACHE_FOLDER
env variable.
👉🏻 See an example examples/syncdata.js.
You can load a DCC from an image or from a raw string using Certificate
module.
const {Certificate} = require('verificac19-sdk');
const main = async () => {
const myDCCfromImage = await Certificate.fromImage('./data/myDCC.png');
const myDCCfromRaw = await Certificate.fromRaw('HC1:6BF+70790T9WJWG.FKY*4GO0.O1CV2...etc..');
}
Loaded DCC has the following structure:
{
person: {
standardisedFamilyName: 'MUSTERMANN',
familyName: 'Mustermann',
standardisedGivenName: 'ERIKA',
givenName: 'Erika'
},
dateOfBirth: '1964-08-12',
kid: 'TH15154F4k3K1D=',
vaccinations: [ ... ], // Array of vaccinations (if any)
tests: [ ... ], // Array of tests (if any)
recoveryStatements: [ ... ], // Array of recovery statements (if any)
dcc: DCCObject // from dcc-utils https://github.com/ministero-salute/dcc-utils
}
👉🏻 fromImage
and fromRaw
methods may rise CertificateParsingError
.
You can verify a DCC using Validator
module.
const {Certificate, Validator} = require('verificac19-sdk');
const main = async () => {
const myDCC = await Certificate.fromImage('./data/myDCC.png');
const validationResult = await Validator.validate(myDCC);
}
Validator.validate
returns an object containing person
name,
date_of_birth
, code
and a message
alongside the result
{
person: 'Erika Mustermann',
date_of_birth: '1964-08-12',
code: 'NOT_VALID',
result: false,
message: 'Test Result is expired at : 2021-05-22T12:34:56.000Z'
}
you can compare the resulting code
with Validator.codes
values
Code | Description | Result | |
---|---|---|---|
✅ | VALID | Certificate is valid | true |
TEST_NEEDED | Test needed if verification mode is BOOSTER_DGP | false |
|
❌ | NOT_VALID | Certificate is not valid | false |
❌ | NOT_VALID_YET | Certificate is not valid yet | false |
❌ | REVOKED | Certificate is revoked | false |
❌ | NOT_EU_DCC | Certificate is not an EU DCC | false |
for example
const validationResult = await Validator.validate(dccTest);
console.log(validationResult.code === Validator.codes.NOT_VALID);
👉🏻 validate
method may rise CertificateVerificationError
(e.g. when cache is
not ready yet).
👉🏻 See an example examples/verifydccs.js.
If you want to change verification mode and verify whether a certificate is a
Super Green Pass or not, you need to pass Validator.mode.SUPER_DGP
to
Validator.validate
method.
const result = await Validator.validate(dcc, Validator.mode.SUPER_DGP);
Code | Description |
---|---|
NORMAL_DGP | Normal verification (default value) |
SUPER_DGP | Super Green Pass verification |
BOOSTER_DGP | Booster verification mode |
Details
-
SUPER_DGP Mode
: VerificaC19 SDK considers a green certificate valid only for people who have been vaccinated against or who have recovered from Covid19, and will prevent all the others from entering bars, restaurants, cinemas, gyms, theatres, discos and stadiums. -
BOOSTER_DGP Mode
: VerificaC19 SDK considers green certificates generated after a booster dose to be valid. Furthermore, green certificates generated after the first vaccination cycle or recovery with the simultaneous presentation of a digital document certifying the negative result of a SARS-CoV-2 test are considered valid.
To update rules and DSCs you can also use updateRules
,
updateSignaturesList
and updateSignatures
methods
const {Service} = require('verificac19-sdk');
const main = async () => {
await Service.setUp();
await Service.updateRules();
await Service.updateSignaturesList();
await Service.updateSignatures();
await Service.updateCRL();
await Service.tearDown();
}
To verify a DCC you can also use Validator.checkRules
and
Validator.checkSignature
methods.
const {Certificate, Validator} = require('verificac19-sdk');
const main = async () => {
const myDCC = await Certificate.fromImage('./data/myDCC.png');
const rulesOk = await Validator.checkRules(myDCC).result;
const signatureOk = await Validator.checkSignature(myDCC);
}
npm i
Run mongodb services using Docker
docker-compose up
Set VC19_CACHE_FOLDER
and run tests
npm run test
Copyright (c) 2021 - Andrea Stagi
Parts of the core code have been written by Area servizi ICT, Politecnico di Milano.
Here is a list of contributors. Thank you to everyone involved for improving this project, day by day.
VerificaC19-SDK for Node.js is available under the MIT license.