first commit

This commit is contained in:
2021-09-23 15:38:13 +02:00
commit b2cd5d7c5c
15 changed files with 6389 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
// import crypto from 'crypto';
export class CertificateDownloader{
static instance: CertificateDownloader;
// private readonly baseUrl = 'https://get.dgc.gov.it';
private readonly keyStorage = 'cerificate_collection';
private readonly timeSpan = 86400000;
// private readonly timeSpan = 1000;
private cerficateCollection = {}
// eslint-disable-next-line @typescript-eslint/no-empty-function
private constructor(){}
public getCertificates(): unknown {
const savedData = JSON.parse(localStorage.getItem(this.keyStorage) || '{}');
if(savedData.lastupdateDate == null || Date.now() - savedData?.lastupdateDate > this.timeSpan){
this.getAllCertificate()
.then(() => { console.log('could not read the certificates from the local file'); return this.cerficateCollection })
.catch(console.error);
}
console.log('cerficates collection is valid loading from local source');
// console.log(dataRead.certificates);
this.cerficateCollection = savedData.certificates;
return this.cerficateCollection;
}
public static getCertificateDownloader():CertificateDownloader{
if(CertificateDownloader.instance == undefined){
CertificateDownloader.instance = new CertificateDownloader();
}
return CertificateDownloader.instance;
}
async getAllCertificate(): Promise<void> {
this.cerficateCollection = {};
const response = (await fetch('https://raw.githubusercontent.com/lovasoa/sanipasse/master/src/assets/Digital_Green_Certificate_Signing_Keys.json'));
if(response.ok){
this.cerficateCollection = await response.json();
console.log(response);
const lastupdateDate = Date.now();
localStorage.setItem(this.keyStorage, JSON.stringify({'certificates':this.cerficateCollection, lastupdateDate}))
// fs.writeFile('./cerificate_collection.json', JSON.stringify({'certificates':this.cerficateCollection, lastupdateDate}),'utf8',console.error);
}else{
throw new Error(response.statusText);
}
}
}

View File

@@ -0,0 +1,41 @@
export class RuleDownloader {
static instance: RuleDownloader;
private readonly baseUrl = 'https://get.dgc.gov.it';
private readonly timeSpan = 86400000;
private readonly keyStorage = 'rules'
// private readonly timeSpan = 1000;
public rules:unknown = {}
// eslint-disable-next-line @typescript-eslint/no-empty-function
private constructor(){
this.getRules();
}
public getRules(): unknown {
const savedData = JSON.parse(localStorage.getItem(this.keyStorage) || '{}');
if(savedData.lastupdateDate == null || Date.now() - savedData?.lastupdateDate > this.timeSpan){
this.getSettings()
.then(() => { console.log('could not read the certificates from the local file'); return this.rules })
.catch(console.error);
}
console.log('cerficates collection is valid loading from local source');
// console.log(dataRead.certificates);
this.rules = savedData.certificates;
return this.rules;
}
static getRuleDownloader(): RuleDownloader{
if(this.instance == undefined){
RuleDownloader.instance = new RuleDownloader();
}
return RuleDownloader.instance;
}
private async getSettings(): Promise<unknown>{
const response = await fetch(`${this.baseUrl}/v1/dgc/settings`);
const jsonData = await response.json();
// this.rules = Rule.fromJSON(jsonData,{valueSets, validationClock:new Date().toISOString(),})
this.rules = jsonData;
localStorage.setItem(this.keyStorage, JSON.stringify({rules:this.rules,lastupdateDate:Date.now()}));
return jsonData;
}
}

View File

@@ -0,0 +1,22 @@
import { CertificateDownloader } from './CertificateDownloader';
import { RuleDownloader } from './RuleDownloader';
import {DCC} from 'dcc-utils';
import fs from 'fs';
export default class Verifier {
static certDownloader: CertificateDownloader;
static ruleDownloader: RuleDownloader;
static certificateList: any;
static async setup():Promise<void> {
Verifier.certDownloader = CertificateDownloader.getCertificateDownloader();
Verifier.ruleDownloader = RuleDownloader.getRuleDownloader();
Verifier.certificateList = await Verifier.certDownloader.getCertificates()
}
static async checkCertificate(certificate:string): Promise<unknown>{
const dcc = await DCC.fromRaw(certificate);
const certCheck = await dcc.checkSignatureWithKeysList(Verifier.certificateList);
return certCheck;
}
}

View File

@@ -0,0 +1,389 @@
{
"country-2-codes": [
"AD",
"AE",
"AF",
"AG",
"AI",
"AL",
"AM",
"AO",
"AQ",
"AR",
"AS",
"AT",
"AU",
"AW",
"AX",
"AZ",
"BA",
"BB",
"BD",
"BE",
"BF",
"BG",
"BH",
"BI",
"BJ",
"BL",
"BM",
"BN",
"BO",
"BQ",
"BR",
"BS",
"BT",
"BV",
"BW",
"BY",
"BZ",
"CA",
"CC",
"CD",
"CF",
"CG",
"CH",
"CI",
"CK",
"CL",
"CM",
"CN",
"CO",
"CR",
"CU",
"CV",
"CW",
"CX",
"CY",
"CZ",
"DE",
"DJ",
"DK",
"DM",
"DO",
"DZ",
"EC",
"EE",
"EG",
"EH",
"ER",
"ES",
"ET",
"FI",
"FJ",
"FK",
"FM",
"FO",
"FR",
"GA",
"GB",
"GD",
"GE",
"GF",
"GG",
"GH",
"GI",
"GL",
"GM",
"GN",
"GP",
"GQ",
"GR",
"GS",
"GT",
"GU",
"GW",
"GY",
"HK",
"HM",
"HN",
"HR",
"HT",
"HU",
"ID",
"IE",
"IL",
"IM",
"IN",
"IO",
"IQ",
"IR",
"IS",
"IT",
"JE",
"JM",
"JO",
"JP",
"KE",
"KG",
"KH",
"KI",
"KM",
"KN",
"KP",
"KR",
"KW",
"KY",
"KZ",
"LA",
"LB",
"LC",
"LI",
"LK",
"LR",
"LS",
"LT",
"LU",
"LV",
"LY",
"MA",
"MC",
"MD",
"ME",
"MF",
"MG",
"MH",
"MK",
"ML",
"MM",
"MN",
"MO",
"MP",
"MQ",
"MR",
"MS",
"MT",
"MU",
"MV",
"MW",
"MX",
"MY",
"MZ",
"NA",
"NC",
"NE",
"NF",
"NG",
"NI",
"NL",
"NO",
"NP",
"NR",
"NU",
"NZ",
"OM",
"PA",
"PE",
"PF",
"PG",
"PH",
"PK",
"PL",
"PM",
"PN",
"PR",
"PS",
"PT",
"PW",
"PY",
"QA",
"RE",
"RO",
"RS",
"RU",
"RW",
"SA",
"SB",
"SC",
"SD",
"SE",
"SG",
"SH",
"SI",
"SJ",
"SK",
"SL",
"SM",
"SN",
"SO",
"SR",
"SS",
"ST",
"SV",
"SX",
"SY",
"SZ",
"TC",
"TD",
"TF",
"TG",
"TH",
"TJ",
"TK",
"TL",
"TM",
"TN",
"TO",
"TR",
"TT",
"TV",
"TW",
"TZ",
"UA",
"UG",
"UM",
"US",
"UY",
"UZ",
"VA",
"VC",
"VE",
"VG",
"VI",
"VN",
"VU",
"WF",
"WS",
"YE",
"YT",
"ZA",
"ZM",
"ZW"
],
"disease-agent-targeted": [
"840539006"
],
"covid-19-lab-test-manufacturer-and-name": [
"1065",
"1097",
"1114",
"1144",
"1162",
"1173",
"1180",
"1190",
"1199",
"1201",
"1215",
"1218",
"1223",
"1225",
"1232",
"1236",
"1242",
"1244",
"1253",
"1257",
"1263",
"1266",
"1267",
"1268",
"1271",
"1278",
"1295",
"1296",
"1304",
"1319",
"1331",
"1333",
"1341",
"1343",
"1360",
"1363",
"1365",
"1375",
"1392",
"1420",
"1437",
"1443",
"1456",
"1466",
"1468",
"1481",
"1484",
"1489",
"1490",
"1501",
"1574",
"1604",
"1606",
"1654",
"1736",
"1747",
"1763",
"1764",
"1767",
"1769",
"1815",
"1822",
"1833",
"1844",
"1870",
"1884",
"1906",
"1919",
"1934",
"2010",
"2017",
"2029",
"2074",
"2098",
"2101",
"2103",
"2104",
"2108",
"2109",
"2116",
"2128",
"2130",
"2139",
"2183",
"308",
"344",
"345",
"768"
],
"covid-19-lab-result": [
"260373001",
"260415000"
],
"covid-19-lab-test-type": [
"LP217198-3",
"LP6464-4"
],
"vaccines-covid-19-auth-holders": [
"Bharat-Biotech",
"Gamaleya-Research-Institute",
"ORG-100001417",
"ORG-100001699",
"ORG-100006270",
"ORG-100010771",
"ORG-100013793",
"ORG-100020693",
"ORG-100024420",
"ORG-100030215",
"ORG-100031184",
"ORG-100032020",
"Sinovac-Biotech",
"Vector-Institute"
],
"vaccines-covid-19-names": [
"BBIBP-CorV",
"CVnCoV",
"Convidecia",
"CoronaVac",
"Covaxin",
"EU/1/20/1507",
"EU/1/20/1525",
"EU/1/20/1528",
"EU/1/21/1529",
"EpiVacCorona",
"Inactivated-SARS-CoV-2-Vero-Cell",
"Sputnik-V"
],
"sct-vaccines-covid-19": [
"1119305005",
"1119349007",
"J07BX03"
]
}