1.2.1 • Published 2 years ago

verificac19-sdk v1.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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

CodiceDescrizioneRisultato
VALIDIl certificato è validotrue
⚠️TEST_NEEDEDIn modalità BOOSTER_DGP si necessita di testfalse
NOT_VALIDIl certificato non è validofalse
NOT_VALID_YETIl certificato non è ancora validofalse
REVOKEDIl certificato è stato revocatofalse
NOT_EU_DCCIl certificato non è un EU DCCfalse

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);
CodiceDescrizione
NORMAL_DGPVerifica normale (valore di default)
SUPER_DGPVerifica Super Green Pass
VISITORS_RSA_DGPRSA 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.

1.2.0

2 years ago

1.2.1

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

0.9.4

2 years ago

0.9.3

2 years ago

0.9.0

2 years ago

0.8.0

2 years ago

0.7.1

2 years ago

0.9.2

2 years ago

0.9.1

2 years ago

0.5.0

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.5.1

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

3 years ago