-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
87 lines (67 loc) · 2.75 KB
/
Copy pathindex.js
File metadata and controls
87 lines (67 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Create a EUDGC Qr Code
// https://ec.europa.eu/health/sites/default/files/ehealth/docs/digital-green-certificates_dt-specifications_en.pdf
// Ref : https://blog.hqcodeshop.fi/archives/516-Decoding-EU-Digital-COVID-Certificate.html
// Developer : camillegroult.fr
const { pass2qr } = require("./lib/generator");
const { qr2pass } = require("./lib/extractor");
const IMG_PATH = process.argv[2];
if (!IMG_PATH) {
console.error('Usage: npm start <path_to_image>');
return process.exit(-1);
}
(async () => {
// Create a QR code (check function code)
await createOne();
// Try to parse an existing one
const ts = new Date();
console.log('Opening', IMG_PATH, '...');
const extrInfo = await qr2pass(IMG_PATH);
console.log('Decoded in', (new Date() - ts), 'ms:', extrInfo);
})();
async function createOne() {
// CBOR structure ES256 -7 ECDSA w/ SHA-256 [RFC-ietf-cose-rfc8152bis-algs-12]
const AGLO_SIGN = -7 // Protected Header Signature Algorithm (may-be public);
const SIGN_KEY_ID = Buffer.from(['0oCvyNKB210=', /* Here sample of EU getway... 8 bytes sequence for the used algorithm signature (may-be public) */]);
const HCERT_SIGN = Buffer.from(['',/* ... 64 bytes sequence health certificate signature */]);
const obj = {
v: [
{
// Unique certificate identifier
ci: 'URN:UVCI:01:FR:SXRQTBSXRQTBM9CDJGM9CDJG#7',
// Member State or third country in which the vaccine was administered
co: 'FI',
// Doses count
dn: 3,
// Date of vaccination
dt: '2021-12-20',
// Vaccine issuer
is: 'The Social Insurance Institution of Finland',
// Vaccine manufacturer, e.g., "ORG-100030215" (Biontech Manufacturing GmbH)
ma: 'ORG-100030215',
// Vaccine product, e.g., "EU/1/20/1528" (Comirnaty)
mp: 'EU/1/20/1525',
// Overall doses count
sd: 3,
// Targeted agent / disease
tg: '840539006',
// Type of vaccine used
vp: 'J07BX03'
}
],
// Date of birth
dob: '1969-01-06',
// Firstnames an lastnames, according to ICAO 9303 transliteration
nam: { fn: 'KIATURE', gn: 'RIJAH', fnt: 'KIATURE', gnt: 'RIJAH' },
// JSON schema / certificate semantic version
ver: '1.3.0'
};
const strQR = await pass2qr(
AGLO_SIGN, SIGN_KEY_ID, HCERT_SIGN,
'SIIF', // Vaccine issuer, french one here
1703703754 /* timestamp of vaccination */,
1640602800 /* timestamp for qrcode generation date */,
obj,
'./QR_CODE.png' // path to output
);
console.log('Generated!', strQR);
}