add to wallet working now - working on photos portion

This commit is contained in:
Billy Lo 2021-09-29 21:39:11 -04:00
parent 66e450a2ed
commit 0fe177dffa
5 changed files with 196 additions and 163 deletions

View File

@ -122,11 +122,13 @@ function Form(): JSX.Element {
setFileLoading(false);
setFile(file);
if (Object.keys(payload.receipts).length === 1) {
setSelectedDose(parseInt(Object.keys(payload.receipts)[0]));
}else{
setShowDoseOption(true);
}
if (payload.rawData.length == 0) {
if (Object.keys(payload.receipts).length === 1) {
setSelectedDose(parseInt(Object.keys(payload.receipts)[0]));
} else {
setShowDoseOption(true);
}
}
} catch (e) {
setFile(file);
setFileLoading(false);

View File

@ -2,7 +2,7 @@
const jsQR = require("jsqr");
const zlib = require("zlib");
import {Receipt} from "./payload";
import {Receipt, HashTable} from "./payload";
export function getQRFromImage(imageData) {
return jsQR(
@ -17,7 +17,7 @@ export function getQRFromImage(imageData) {
// http://mchp-appserv.cpe.umanitoba.ca/viewConcept.php?printer=Y&conceptID=1514
export function decodedStringToReceipt(shcResources: object[]) : Receipt[] {
export function decodedStringToReceipt(shcResources: object[]) : HashTable<Receipt> {
const codeToVaccineName = {
'28581000087106': 'Pfizer-BioNTech',
@ -28,7 +28,7 @@ export function decodedStringToReceipt(shcResources: object[]) : Receipt[] {
let name = '';
let dateOfBirth;
let receipts : Receipt[] = [];
let receipts : HashTable<Receipt> = {};
const numResources = shcResources.length;
for (let i = 0; i < numResources; i++) {
@ -63,10 +63,10 @@ export function decodedStringToReceipt(shcResources: object[]) : Receipt[] {
organizationName = performer.actor.display;
}
vaccinationDate = resource.occurrenceDateTime;
const receiptNumber = receipts.length + 1;
const receiptNumber = shcResources[i]['fullUrl'].split(':')[1];
const receipt = new Receipt(name, vaccinationDate, vaccineName, dateOfBirth, receiptNumber, organizationName);
console.log(receipt);
receipts.push(receipt);
receipts[receiptNumber] = receipt;
}
}
return receipts;

View File

@ -85,13 +85,16 @@ export class PassData {
// Create Payload
try {
console.log(JSON.stringify(payloadBody, null, 2), numDose);
const payload: Payload = new Payload(payloadBody, numDose);
payload.serialNumber = uuid4();
// register record
const clonedReceipt = Object.assign({}, payload.receipts[0]);
const clonedReceipt = Object.assign({}, payloadBody.receipts[numDose]);
delete clonedReceipt.name;
delete clonedReceipt.dateOfBirth;
clonedReceipt["serialNumber"] = payload.serialNumber;
@ -105,7 +108,7 @@ export class PassData {
body: JSON.stringify(clonedReceipt) // body data type must match "Content-Type" header
}
// console.log('registering ' + JSON.stringify(clonedReceipt, null, 2));
console.log('registering ' + JSON.stringify(clonedReceipt, null, 2));
const configResponse = await fetch('/api/config');
const configResponseJson = await configResponse.json();
@ -130,18 +133,18 @@ export class PassData {
return Promise.reject();
}
const encodedUri = `serialNumber=${encodeURIComponent(payload.serialNumber)}&vaccineName=${encodeURIComponent(payload.receipt.vaccineName)}&vaccinationDate=${encodeURIComponent(payload.receipt.vaccinationDate)}&organization=${encodeURIComponent(payload.receipt.organization)}&dose=${encodeURIComponent(payload.receipt.numDoses)}`;
const encodedUri = `serialNumber=${encodeURIComponent(payload.serialNumber)}&vaccineName=${encodeURIComponent(payloadBody.receipts[numDose].vaccineName)}&vaccinationDate=${encodeURIComponent(payloadBody.receipts[numDose].vaccinationDate)}&organization=${encodeURIComponent(payloadBody.receipts[numDose].organization)}&dose=${encodeURIComponent(payloadBody.receipts[numDose].numDoses)}`;
const qrCodeUrl = `${verifierHost}/verify?${encodedUri}`;
// console.log(qrCodeUrl);
let qrCodeMessage = payloadBody.rawData.startsWith('shc:/')
? payloadBody.rawData
: `${verifierHost}/verify?serialNumber=${payload.serialNumber}&vaccineName=${payload.receipts[0].vaccineName}&vaccinationDate=${payload.receipts[0].vaccinationDate}&organization=${payload.receipts[0].organization}&dose=${payload.receipts[0].numDoses}`;
: qrCodeUrl;
// Create QR Code Object
const qrCode: QrCode = {
message: qrCodeUrl,
message: qrCodeMessage,
format: QrFormat.PKBarcodeFormatQR,
messageEncoding: Encoding.iso88591,
// altText : payload.rawData

View File

@ -1,5 +1,6 @@
import {Constants} from "./constants";
import {COLORS} from "./colors";
import { TEXT_ALIGN } from "html2canvas/dist/types/css/property-descriptors/text-align";
export class Receipt {
constructor(public name: string, public vaccinationDate: string, public vaccineName: string, public dateOfBirth: string, public numDoses: number, public organization: string) {};
@ -48,11 +49,54 @@ export class Payload {
constructor(body: PayloadBody, numDose: number) {
let receipt = body.receipts[0];
// Get name and date of birth information
const name = body.receipts[numDose].name;
const dateOfBirth = body.receipts[numDose].dateOfBirth;
const vaccineName = body.receipts[numDose].vaccineName;
let generic: PassDictionary = {
headerFields: [
],
primaryFields: [],
secondaryFields: [],
auxiliaryFields: [],
backFields: [
//TODO: add url link back to grassroots site
]
}
this.backgroundColor = COLORS.YELLOW;
this.labelColor = COLORS.WHITE
this.foregroundColor = COLORS.WHITE
this.img1x = Constants.img1xWhite
this.img2x = Constants.img2xWhite
let fullyVaccinated = false;
var keys = Object.keys(body.receipts).reverse();
if (body.rawData.length > 0) { // SHC contains multiple receipts
for (let k of keys) {
fullyVaccinated = processReceipt(body.receipts[k], generic);
if (fullyVaccinated) {
this.backgroundColor = COLORS.GREEN;
}
}
} else {
fullyVaccinated = processReceipt(body.receipts[numDose], generic);
if (fullyVaccinated) {
this.backgroundColor = COLORS.GREEN;
}
}
this.rawData = body.rawData;
this.generic = generic;
}
}
function processReceipt(receipt: Receipt, generic: PassDictionary) : boolean {
console.log('processing receipt #' + receipt.numDoses);
const name = receipt['name'];
const dateOfBirth = receipt.dateOfBirth;
const numDoses = receipt.numDoses;
const vaccineName = receipt.vaccineName.toLocaleUpperCase();
let vaccineNameProper = vaccineName.charAt(0) + vaccineName.substr(1).toLowerCase();
if (vaccineName.includes('PFIZER'))
@ -60,47 +104,62 @@ export class Payload {
if (vaccineName.includes('MODERNA'))
vaccineNameProper = 'Moderna (SpikeVax)'
// vaccineNameProper = 'Pfizer (Comirnaty)'
if (vaccineName.includes('ASTRAZENECA'))
if (vaccineName.includes('ASTRAZENECA') || vaccineName.includes('Covishield'))
vaccineNameProper = 'AstraZeneca (Vaxzevria)'
let doseVaccine = "#" + String(body.receipts[numDose].numDoses) + ": " + vaccineNameProper;
if (name == undefined) {
throw new Error('nameMissing');
}
if (dateOfBirth == undefined) {
throw new Error('dobMissing');
let doseVaccine = "#" + String(receipt.numDoses) + ": " + vaccineNameProper;
let fullyVaccinated = false;
if (receipt.numDoses > 1 ||
vaccineName.toLowerCase().includes('janssen') ||
vaccineName.toLowerCase().includes('johnson') ||
vaccineName.toLowerCase().includes('j&j')) {
fullyVaccinated = true;
}
const generic: PassDictionary = {
headerFields: [
],
primaryFields: [
if (generic.primaryFields.length == 0) {
generic.primaryFields.push(
{
key: "vaccine",
label: "Vaccine",
value: doseVaccine,
key: "vaccine",
label: "Vaccine",
value: doseVaccine
}
)
}
],
secondaryFields: [
{
let fieldToPush = generic.secondaryFields;
if (fieldToPush.length > 0) {
fieldToPush = generic.backFields;
generic.headerFields.push({
key: "extra",
label: "More",
value: "(i)",
"textAlignment" : "PKTextAlignmentCenter"
});
generic.backFields.push({
key: "vaccine" + numDoses,
label: `Vaccine (Dose ${numDoses})`,
value: receipt.vaccineName
})
}
fieldToPush.push(
{
key: "issuer",
label: "Authorized Organization",
value: body.receipts[numDose].organization
},
value: receipt.organization
},
{
key: "dov",
label: "Date",
value: body.receipts[numDose].vaccinationDate,
// textAlignment: TextAlignment.right
value: receipt.vaccinationDate,
}
],
auxiliaryFields: [
{
);
if (generic.auxiliaryFields.length == 0) {
generic.auxiliaryFields.push(
{
key: "name",
label: "Name",
value: name
@ -109,33 +168,7 @@ export class Payload {
key: "dob",
label: "Date of Birth",
value: dateOfBirth
}
],
backFields: [
//TODO: add url link back to grassroots site
]
});
}
// Set Values
// this.receipt = body.receipts[numDose];
this.rawData = body.rawData;
if (body.receipts[numDose].numDoses > 1 || body.receipts[numDose].vaccineName.toLowerCase().includes('janssen') || body.receipts[numDose].vaccineName.toLowerCase().includes('johnson') || body.receipts[numDose].vaccineName.toLowerCase().includes('j&j')) {
this.backgroundColor = COLORS.GREEN;
} else {
this.backgroundColor = COLORS.YELLOW;
}
this.labelColor = COLORS.WHITE
this.foregroundColor = COLORS.WHITE
this.img1x = Constants.img1xWhite
this.img2x = Constants.img2xWhite
this.generic = generic;
return fullyVaccinated;
}
}

View File

@ -20,16 +20,23 @@ export async function getPayloadBodyFromFile(file: File): Promise<PayloadBody> {
// Read file
const fileBuffer = await file.arrayBuffer();
let receipts: HashTable<Receipt>;
let rawData = ''; // unused at the moment, the original use was to store the QR code from issuer
switch (file.type) {
case 'application/pdf':
const receiptType = await detectReceiptType(fileBuffer);
receipts = await loadPDF(fileBuffer, receiptType) // receipt type is needed to decide if digital signature checking is needed
console.log(receiptType);
if (receiptType == 'ON') {
receipts = await loadPDF(fileBuffer) // receipt type is needed to decide if digital signature checking is needed
} else {
const shcData = await processSHC(fileBuffer);
receipts = shcData.receipts;
rawData = shcData.rawData;
}
break
default:
throw Error('invalidFileType')
}
const rawData = ''; // unused at the moment, the original use was to store the QR code from issuer
return {
receipts: receipts,
@ -56,102 +63,92 @@ async function detectReceiptType(fileBuffer : ArrayBuffer): Promise<string> {
let item = content.items[i] as TextItem;
const value = item.str;
console.log(value);
if (value.includes('BC Vaccine Card')) {
console.log('detected bc');
return Promise.resolve('BC');
}
if (value.includes('COVID-19 vaccination receipt')) {
console.log('detected on');
return Promise.resolve('ON');
}
}
return Promise.resolve('SHC');
}
async function loadPDF(fileBuffer : ArrayBuffer, receiptType : string): Promise<HashTable<Receipt>> {
async function loadPDF(fileBuffer : ArrayBuffer): Promise<HashTable<Receipt>> {
try {
if (receiptType == 'ON') {
const certs = getCertificatesInfoFromPDF(fileBuffer);
const certs = getCertificatesInfoFromPDF(fileBuffer);
const result = certs[0];
const refcert = '-----BEGIN CERTIFICATE-----\r\n'+
'MIIHNTCCBh2gAwIBAgIQanhJa+fBXT8GQ8QG/t9p4TANBgkqhkiG9w0BAQsFADCB\r\n'+
'ujELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUVudHJ1c3QsIEluYy4x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8uvPUFXGj6MjdQysx6YG+K3mae0GEVpODEl4MiceEFZ7v4CPA6pFNadijRF\r\n'+
'6tdXky2psuo7VXfnE2WIlahKr56x+8R6To5pcWglKTywTqvCbnKRRVZhXXYo3Awd\r\n'+
'8h9+TbL3ACHDqA4fi5sAbZ7nMXp8RK4o5A==\r\n'+
'-----END CERTIFICATE-----';
const pdfCert = result.pemCertificate.trim();
const pdfOrg = result.issuedBy.organizationName;
const issuedpemCertificate = (pdfCert == refcert.trim());
const pdfCert = result.pemCertificate.trim();
const pdfOrg = result.issuedBy.organizationName;
const issuedpemCertificate = (pdfCert == refcert.trim());
//console.log(`pdf is signed by this cert ${result.pemCertificate.trim()}`);
//console.log(issuedpemCertificate);
//console.log(`PDF is signed by ${result.issuedBy.organizationName}, issued to ${result.issuedTo.commonName}`);
//console.log(`pdf is signed by this cert ${result.pemCertificate.trim()}`);
//console.log(issuedpemCertificate);
//console.log(`PDF is signed by ${result.issuedBy.organizationName}, issued to ${result.issuedTo.commonName}`);
// const bypass = window.location.href.includes('grassroots2');
// const bypass = window.location.href.includes('grassroots2');
if (( issuedpemCertificate )) {
//console.log('getting receipt details inside PDF');
const receipt = await getPdfDetails(fileBuffer);
// console.log(JSON.stringify(receipt, null, 2));
return Promise.resolve(receipt);
} else {
// According to the Sentry docs, this can be up to 8KB in size
// https://develop.sentry.dev/sdk/data-handling/#variable-size
Sentry.setContext("certificate", {
pdfCert: pdfCert,
pdfOrg: pdfOrg,
});
Sentry.captureMessage('Certificate validation failed');
console.error('invalid certificate');
return Promise.reject(`invalid certificate + ${JSON.stringify(result)}`);
}
} else if (receiptType == 'BC') {
processBC(fileBuffer);
if (( issuedpemCertificate )) {
//console.log('getting receipt details inside PDF');
const receipt = await getPdfDetails(fileBuffer);
// console.log(JSON.stringify(receipt, null, 2));
return Promise.resolve(receipt);
} else {
// According to the Sentry docs, this can be up to 8KB in size
// https://develop.sentry.dev/sdk/data-handling/#variable-size
Sentry.setContext("certificate", {
pdfCert: pdfCert,
pdfOrg: pdfOrg,
});
Sentry.captureMessage('Certificate validation failed');
console.error('invalid certificate');
return Promise.reject(`invalid certificate + ${JSON.stringify(result)}`);
}
} catch (e) {
@ -206,6 +203,7 @@ async function getPdfDetails(fileBuffer: ArrayBuffer): Promise<HashTable<Receipt
numDoses = Number(value.split(' ')[3]);
}
receiptObj[numDoses] = new Receipt(name, vaccinationDate, vaccineName, dateOfBirth, numDoses, organization);
console.log(receiptObj[numDoses]);
}
return Promise.resolve(receiptObj);
@ -241,7 +239,9 @@ async function getImageDataFromPdf(pdfPage: PDFPageProxy): Promise<ImageData> {
}
async function processBC(fileBuffer : ArrayBuffer) {
async function processSHC(fileBuffer : ArrayBuffer) : Promise<any> {
console.log('processSHC');
try {
const typedArray = new Uint8Array(fileBuffer);
@ -257,26 +257,21 @@ async function processBC(fileBuffer : ArrayBuffer) {
let decoded = await decodeJWS(jws);
console.log(JSON.stringify(decoded, null, 2));
console.log(decoded);
const verified = verifyJWS(jws, decoded.iss);
if (verified) {
let receipts = Decode.decodedStringToReceipt(decoded.vc.credentialSubject.fhirBundle.entry);
console.log(receipts);
return Promise.resolve({receipts: receipts, rawData: rawData});
} else {
return Promise.reject(`Issuer ${decoded.iss} cannot be verified.`);
}
} catch (e) {
Promise.reject(e);
}
}