-
Notifications
You must be signed in to change notification settings - Fork 29
/
color.html
267 lines (225 loc) · 12.6 KB
/
color.html
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!doctype html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/style.v2.css">
<link rel="stylesheet" href="css/topnav.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="https://www.pathcheck.org/hubfs/Favicon.png">
<title>Massachusetts's Color Vaccine Record to Verifiable QR</title>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DTDMHW3NV6"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-DTDMHW3NV6');
</script>
</head>
<body>
<div class="topnav">
<div class="topnavContainer">
<a class="active" href="index.html">Signers</a>
<a href="verify.html"><span class="xs-hidden">Universal </span>Verifier</a>
<a class="xs-hidden" href="debug.html">QR Debugger</a>
<a class="xs-hidden" href="https://github.com/Path-Check/paper-cred-demo">Source Code</a>
<a href="https://github.com/Path-Check/paper-cred"><span class="xs-hidden"> QR </span>Specs</a>
<a href="http://vaccine-docs.pathcheck.org"><span class="xs-hidden">Vaccine </span>Docs</a>
<a class="xs-hidden" href="http://pathcheck.org">About PathCheck</a>
</div>
</div>
<div class="subnav">
<div class="subnavContainer">
<a href="index.v5.html">PCF<span class="xs-hidden">'s 4 QRs</span></a>
<a href="eu.dgc.html">EU<span class="xs-hidden"> Covid Pass</span></a>
<a class="active" href="color.html"><span class="xs-hidden">Color</a>
<a href="icao.html">ICAO<span class="xs-hidden"> Seals</span></a>
<a href="cowin.html">DIVOC<span class="xs-hidden">/India</span></a>
<a href="liberty.html">IBM/NY<span class="xs-hidden"> Excelsior</span></a>
<a class="xs-hidden" href="opencerta.html"><span class="xs-hidden">Open</span>Certa</a>
<a href="vial.html">Vial<span class="xs-hidden"> Label</span></a>
<a href="us.ma.id.html"><span class="xs-hidden">Mass </span>ID</a>
<a href="banknote.html">Cash<span class="xs-hidden"> Bills</span></a>
</div>
</div>
<div class="center">
<h1>Massachusetts's Color Vaccine Record to Verifiable QR</h1>
<div class="full-div">
<div class="four-quarter-left">
<br><br>
<h4>Insert your Vaccination history URL (you received it as an SMS)</h4>
<br>
<table>
<tr><td><input id="qr-color-url" type="text" placeholder="https://www.color.com/vaccine/vaccinations/XXXXXXXXXXX?claim_token=YYYYYYYYYYYYYYY"/></td></tr>
</table>
<br><br>
</div>
<div class="quarter" style="display: none;">
<h4>CRED Credentials</h4>
<label for="privkey">Private Key</label><br/>
<textarea id="privkey" rows="7" style="width: 100%;">-----BEGIN EC PARAMETERS-----
BgUrgQQACg==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIPWKbSezZMY1gCpvN42yaVv76Lo47FvSsVZpQl0a5lWRoAcGBSuBBAAK
oUQDQgAE6DeIun4EgMBLUmbtjQw7DilMJ82YIvOR2jz/IK0R/F7/zXY1z+gqvFXf
DcJqR5clbAYlO9lHmvb4lsPLZHjugQ==
-----END EC PRIVATE KEY-----</textarea>
<label for="pubkey">Public KeyID</label><br/>
<textarea id="qr-link" rows="1" cols="30">1A9.PCF.PW</textarea>
</div>
</div>
<div class="full-div"></div>
<div class="four-quarter">
<br>
<button class="qr-btn" onclick="generateQRCodes()">Generate Credentials</button>
<br><br>
</div>
<div class="full-div">
<div class="third">
<h4>First Dose</h4>
<canvas id="qr-cred-first-code"></canvas><br/>
<pre id="qr-cred-first-result"></pre>
<pre id="qr-cred-first-bytes" class="xs-hidden"></pre>
</div>
<div class="third">
<h4>Second Dose</h4>
<canvas id="qr-cred-second-code"></canvas><br/>
<pre id="qr-cred-second-result"></pre>
<pre id="qr-cred-second-bytes" class="xs-hidden"></pre>
</div>
<div class="third">
<h4>Status</h4>
<canvas id="qr-cred-status-code"></canvas><br/>
<pre id="qr-cred-status-result"></pre>
<pre id="qr-cred-status-bytes" class="xs-hidden"></pre>
</div>
</div>
</div>
<div class="footer">
<div class="footerContainer">
<img src="https://www.pathcheck.org/hubfs/pathcheck-foundation-logo-white.svg" alt="pathcheck-foundation-logo-white" width="264" style="width: 264px; max-width: 264px; margin: 0px 0px 5px;">
<span style="font-size: 14px;">
<br>©2021. PathCheck Foundation – a 501(c)(3) nonprofit.
<br>Content is distributed under the Creative Commons CC-BY License unless otherwise stated. PathCheck is a trademark of PathCheck Foundation.
</span>
</div>
</div>
<script src="js/qrcode.min.js"></script>
<script src="js/libbcmath.js" type="text/javascript"></script>
<script src="js/bcmath.js" type="text/javascript"></script>
<script src="js/pdf417.js" type="text/javascript"></script>
<script src="js/pcf-utils.js"></script>
<script src="js/ui-utils.js"></script>
<script src="js/cred-sdk.min.js"></script>
<script>
function e(elem) { return document.getElementById(elem); }
function signAndDisplayQR(elemPref, _type, _version, priKeyPEM, pubKeyId, payloadValueArray) {
const uri = CRED.signAndPack(_type, _version, priKeyPEM, pubKeyId, payloadValueArray).then(uri => {
PCFUtils.debugURI(uri).then( debugInfo => {
UIUtils.renderQR(elemPref, uri);
// Updates screen elements.
e(elemPref+"-result").innerHTML= debugInfo;
CRED.unpackAndVerify(uri).then(result => {
UIUtils.drawVerifiedSymbol(elemPref+'-code',result);
});
});
});
}
function downloadColorRecord(userid, token) {
console.log("https://home.color.com/api/v1/vaccination_appointments/"+userid+"?claim_token="+token);
let client = new XMLHttpRequest();
client.open('GET', "https://pathcheck-cors-proxy.herokuapp.com/home.color.com/api/v1/vaccination_appointments/"+userid+"?claim_token="+token, false);
client.send();
return JSON.parse(client.response);
}
function convertPreviousApptToBadgeArray(data) {
if (data.previous_appointment && data.previous_appointment.vaccination_record) {
let firstDate = new Date(data.previous_appointment.vaccination_record.vaccination_date);
let secondDate = new Date(data.vaccination_record.vaccination_date);
const diffTime = Math.abs(secondDate - firstDate);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
return [
data.previous_appointment.vaccination_record.vaccination_date, //date
data.previous_appointment.vaccination_record.manufacturer, // manuf
data.vaccination_record.type.replaceAll(data.vaccination_record.manufacturer + " ", ""), // product
data.previous_appointment.vaccination_record.substance_lot_number, // type
diffDays.toString(), //doses
, //vaccinee
, //route
data.previous_appointment.vaccination_record.administration_site, //site
(data.previous_appointment.vaccination_record.administered_amount_in_ml*1000).toString(), //dose
data.first_name + " " + data.last_name, //name
data.birthday //dob
];
} else {
return undefined;
}
}
function convertColorToBadgeArray(data) {
if (data && data.vaccination_record) {
let diffDays = "";
if (data.next_appointment) {
let firstDate = new Date(data.previous_appointment.vaccination_record.vaccination_date);
let secondDate = new Date(data.next_appointment);
const diffTime = Math.abs(secondDate - firstDate);
diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
}
return [
data.vaccination_record.vaccination_date,
data.vaccination_record.manufacturer,
data.vaccination_record.type.replaceAll(data.vaccination_record.manufacturer + " ", ""), // product
data.vaccination_record.substance_lot_number,
diffDays,
, //vaccinee
, //route
data.vaccination_record.administration_site, //site
(data.vaccination_record.administered_amount_in_ml*1000).toString(), //dose
data.first_name + " " + data.last_name, //name
data.birthday //dob
];
} else {
return undefined;
}
}
function getInitialsAndYear(fullName, dob) {
var names = fullName.split(' '),
initials = names[0].substring(0, 1).toUpperCase();
if (names.length > 1) {
initials += names[names.length - 1].substring(0, 1).toUpperCase();
}
return initials + dob.substring(2,4);
}
function getDoses(badgeArrayCurr, badgeArrayPrevious) {
if (!badgeArrayCurr) return "0";
if (badgeArrayCurr.next_appointment) return "1";
return "2";
}
function generateQRCodes() {
gtag('event', 'generateQR');
// Where to Download the public key
const pubKeyLink = e("qr-link").value.trim().replace("http://","");
// PEM code of the private key
const priKeyPEM = e('privkey').value;
let urlMain = e('qr-color-url').value.split("?")[0];
let queryString = e('qr-color-url').value.split("?")[1];
let userid = urlMain.substring(urlMain.lastIndexOf('/')+1);
let token = new URLSearchParams(queryString).get('claim_token')
colorRecord = downloadColorRecord(userid, token);
// Badge QR
const badgeArrayCurr = convertColorToBadgeArray(colorRecord);
// Badge QR
const badgeArrayPrevious = convertPreviousApptToBadgeArray(colorRecord);
if (badgeArrayPrevious && badgeArrayCurr) {
signAndDisplayQR("qr-cred-first", "badge","2", priKeyPEM, pubKeyLink, badgeArrayPrevious);
signAndDisplayQR("qr-cred-second", "badge","2", priKeyPEM, pubKeyLink, badgeArrayCurr);
} else if (!badgeArrayPrevious && badgeArrayCurr) {
signAndDisplayQR("qr-cred-first", "badge","2", priKeyPEM, pubKeyLink, badgeArrayCurr);
} else {
}
const initals = getInitialsAndYear(badgeArrayCurr[9], badgeArrayCurr[10]);
const statusArray = [getDoses(badgeArrayCurr,badgeArrayPrevious),,initals];
signAndDisplayQR("qr-cred-status", "status","2", priKeyPEM, pubKeyLink, statusArray);
}
</script>
</body>
</html>