20
loading...
This website collects cookies to deliver better user experience
npm install base45 cbor jpeg-js jsqr pako
const base45 = require('base45');
const cbor = require('cbor');
const fs = require('fs')
const jpeg = require('jpeg-js');
const jsQR = require("jsqr");
const pako = require('pako');
greenpass.jpg
that I've downloaded directly from the Italian app IO
.const greenpassJpeg = fs.readFileSync(__ dirname + '/greenpass.jpg');
const greenpassImageData = jpeg.decode(greenpassJpeg, {useTArray: true});
useTArray
option passed to the decoder is used to make sure that the image is decoded as Uint8Arrayconst decodedGreenpass = jsQR(greenpassImageData.data, greenpassImageData.width, greenpassImageData.height);
HC1: 6BFOXM% TS3DHPVO13J /G-/2YKVA.R/K86PP2FC1J9M$DI9C3 [....] CS62GMVR + B1YM K5MJ1K: K: 2JZLT6KM + DTVKPDUG $ E7F06FA3O6I-VA126Y0
const greenpassBody = decodedGreenpass.data.substr(4);
zlib
:const decodedData = base45.decode(greenpassBody);
const output = pako.inflate(decodedData);
const results = cbor.decodeAllSync(output);
[headers1, headers2, cbor_data, signature] = results[0].value;
const greenpassData = cbor.decodeAllSync(cbor_data);
console.log (JSON.stringify(greenpassData[0].get(-260).get (1), null, 2));
{
"t": [
{
"sc": "2021-06- []",
"but": "1606",
"tt": "LP217198-3",
"co": "IT",
"tc": "Dr. [....]",
"there": "[....]",
"is": "Ministry of Health",
"tg": "840539006",
"tr": "26041 [....]"
}
],
"nam": {
"fnt": "MILLUCCI",
"fn": "MILLUCCI",
"gnt": "LORENZO",
"gn": "LORENZO"
},
"ver": "1.0.0",
"dob": "1992-08-10"
}
sc
indicates the date and time of the test
but it indicates "Marketing Authorization Holder" which simply indicates the body that put the test on the markettt
indicates the type of testtc
indicates the place where the test was performedci
the unique certificate number (Unique Certificate Identifier or UVCI)is
the entity that issued the certificatetg
is the type of agent against which the vaccine acts (at the moment the only allowed value is 840539006 and that is COVID-19)tr
is the test resultconst base45 = require('base45');
const cbor = require('cbor');
const fs = require('fs')
const jpeg = require('jpeg-js');
const jsQR = require("jsqr");
const pako = require('pako');
// Set the path to the green pass QR
const FILE_PATH = __dirname + '/greenpass.jpg';
// Read image file
const greenpassJpeg = fs.readFileSync(FILE_PATH);
const greenpassImageData = jpeg.decode(greenpassJpeg, {useTArray: true});
// Decode QR
const decodedGreenpass = jsQR(greenpassImageData.data, greenpassImageData.width, greenpassImageData.height);
// Remove `HC1:` from the string
const greenpassBody = decodedGreenpass.data.substr(4);
// Data is Base45 encoded
const decodedData = base45.decode(greenpassBody);
// And zipped
const output = pako.inflate(decodedData);
const results = cbor.decodeAllSync(output);
[headers1, headers2, cbor_data, signature] = results[0].value;
const greenpassData = cbor.decodeAllSync(cbor_data);
console.log(JSON.stringify(greenpassData[0].get(-260).get(1), null, 2));