npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

verificac19-sdk

v1.2.1

Published

VerificaC19 SDK for Node.js

Downloads

90

Readme

VerificaC19 SDK per Node.js

Implementazione ufficiale per Node.js di VerificaC19 SDK (lista degli SDK ufficiali).

Requisiti

  • Node.js versione >= 12.x
  • MongoDB versione >= 5.x (usato per memorizzare la CRL)

Installazione

npm i verificac19-sdk

Utilizzo

Setup CRL environment

La CRL viene memorizzata su un database MongoDB. Questo repository fornisce un file docker-compose.yml (come istanza di sviluppo) con un replica set.

Di default la stringa di connessione è mongodb://root:example@localhost:27017/VC19?authSource=admin, ed è possibile modificarla utilizzando la libreria integrata dotenv, per fare ciò bisogna creare un file chiamato .env nella cartella di root e impostare il valore per la proprietà VC19_MONGODB_URL.

👉🏻 Vedi l'esempio examples/.env.

⚠️ Se non vuoi utilizzare MongoDB per gestire la CRL, leggi come scrivere il proprio sistema di gestione CRL.

Scarica e salva regole, CRL e DSC

Puoi scaricare e salvare regole e DSC utilizzando il modulo Service.

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

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

⚠️ Regole e DSC vengono salvati di default nella cartella .cache, per cambiare questa impostazione occorre settare il valore VC19_CACHE_FOLDER nel file .env.

⏱ Di default updateAll può scaricare i nuovi dati ogni 24 ore. Per cambiare questo valore, settare la variable VC19_UPDATE_HOURS nel file .env.

👉🏻 Vedi l'esempio examples/syncdata.js.

Verifica un DCC

Puoi caricare un DCC da un'immagine o da una stringa usando il modulo Certificate.

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

Il contenuto del DCC caricato sarà il seguente:

{
  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
}

👉🏻 I metodi fromImage e fromRaw potrebbero sollevare l'eccezione CertificateParsingError.

Puoi verificare un DCC utilizzando il modulo Validator.

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 torna un oggetto contenente il nome della persona person, date_of_birth, code e message insieme al risultato (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'
}

Puoi comparare code con i valori di Validator.codes riportati nella tabella

| | Codice | Descrizione | Risultato | |-| --------------- | --------------------------------------------- | --------- | |✅| VALID | Il certificato è valido | true | |⚠️| TEST_NEEDED | In modalità BOOSTER_DGP si necessita di test | false | |❌| NOT_VALID | Il certificato non è valido | false | |❌| NOT_VALID_YET | Il certificato non è ancora valido | false | |❌| REVOKED | Il certificato è stato revocato | false | |❌| NOT_EU_DCC | Il certificato non è un EU DCC | false |

per esempio

const validationResult = await Validator.validate(dccTest);
console.log(validationResult.code === Validator.codes.NOT_VALID);

👉🏻 validate potrebbe sollevare l'eccezione CertificateVerificationError (ad esempio quando la cache non è ancora pronta).

👉🏻 Vedi l'esempio examples/verifydccs.js.

Modalità di verifica

Se vuoi cambiare la modalità di verifica e verificare se il certificato è un Super Green Pass o meno, devi passare il valore Validator.mode.SUPER_DGP al metodo Validator.validate.

const result = await Validator.validate(dcc, Validator.mode.SUPER_DGP);

| Codice | Descrizione | | -------------- | ---------------------------------------- | | NORMAL_DGP | Verifica normale (valore di default) | | SUPER_DGP | Verifica Super Green Pass | | VISITORS_RSA_DGP | RSA Visitors (ex verifica BOOSTER_DGP) |

DECRETO-LEGGE 4 febbraio 2022, n. 5

Metodi alternativi

Per scaricare e salvare le regole e le DSC puoi anche usare i metodi updateRules, updateSignaturesList e updateSignatures.

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

Per validare un DCC puoi anche usare i metodi Validator.checkRules e Validator.checkSignature.

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

Installa le dipendenze con

npm i

Lancia i test

npm run test

Autori

Copyright (c) 2021 - Andrea Stagi

Parte del codice principale è stata scritta da Area servizi ICT, Politecnico di Milano.

Contributori

Licenza

VerificaC19-SDK per Node.js è disponibile sotto licenza MIT.