-
-
Save minchaminder/382189bf726b4628dc26fb356e2facd5 to your computer and use it in GitHub Desktop.
Extract JSON object from https://smarthealth.cards QR code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Extract JSON payload from SHC QR code (without any kind of private/public key verification) | |
// Credits + inspiration | |
// https://github.com/dvci/health-cards-walkthrough/blob/main/SMART%20Health%20Cards.ipynb | |
// Usage | |
// $ node shc.js "shc:/01234569…" | |
const zlib = require("zlib"); | |
// Extract the QR data from arguments | |
const data = process.argv[2]; | |
// Convert the data to a JWT and extract its base64-encode payload | |
const payload = data | |
.split("/")[1] | |
.match(/(..?)/g) | |
.map((number) => String.fromCharCode(parseInt(number, 10) + 45)) | |
.join("") | |
.split(".")[1]; | |
// Decode the payload | |
const buffer = Buffer.from(payload, "base64"); | |
// Uncompress the payload and print the result | |
zlib.inflateRaw(buffer, (err, result) => { | |
console.log(result.toString("utf8")); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment