Git Product home page Git Product logo

verificac19-sdk's Introduction

VerificaC19 SDK for Node.js

Official VerificaC19 SDK implementation for Node.js (official SDKs list).

Read this in other languages: Italian 🇮🇹.

Requirements

  • Node.js version >= 12.x
  • MongoDB version >= 5.x (used to store CRL)

⚠️ If you don't want to use MongoDB to store CRL, read how to write your own CRL management system.

Installation

npm i verificac19-sdk

Usage

Setup CRL environment

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.

⚠️ If you don't want to use MongoDB to store CRL, read how to write your own CRL management system.

Download and cache rules, CRL data and DSCs

You can download and cache rules, CRL data and DSCs using Service module.

const {Service} = require('verificac19-sdk');

const main = async () => {
  await Service.updateAll();
}

⚠️ By default rules and DSCs will be cached in a folder called .cache, to change it, set VC19_CACHE_FOLDER env variable.

👉🏻 See an example examples/syncdata.js.

Verify a DCC

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.

Verification mode

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.

Alternative methods

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);
}

Development

Install dependencies

npm i

Run tests

Run mongodb services using Docker

docker-compose up

Set VC19_CACHE_FOLDER and run tests

npm run test

Authors

Copyright (c) 2021 - Andrea Stagi

Parts of the core code have been written by Area servizi ICT, Politecnico di Milano.

Contributors

Here is a list of contributors. Thank you to everyone involved for improving this project, day by day.

License

VerificaC19-SDK for Node.js is available under the MIT license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.