Skip to content

Instantly share code, notes, and snippets.

@marcan2020
marcan2020 / shc_decompress.py
Created May 20, 2021 14:59
shc_decompress.py
import zlib
# https://bugs.python.org/issue5784
shc_data = zlib.decompress(jws_parts[1], wbits=-15)
print("SHC Data:", shc_data)
# SHC Data: {"iss":"https://c19.cards/issuer","nbf":1591037940,"vc":{"type":["https://smarthealth.cards#covid19", ...
@marcan2020
marcan2020 / shc_jws.py
Created May 20, 2021 14:55
shc_jws.py
import base64
def decode(data):
missing_padding = len(data) % 4
if missing_padding:
data += b'='* (4 - missing_padding)
return base64.urlsafe_b64decode(data)
jws_parts = list(map(decode, jws.split(".")))
@marcan2020
marcan2020 / shc_fromNumeric.py
Last active November 16, 2021 21:29
shc_fromNumeric.py
import re
qr_data = "shc:/5676290952432060346029243740..."
parts = re.findall('..', qr_data[5:])
jws = ""
for p in parts:
jws += chr(int(p)+ 45)
print("jws:", jws)
@marcan2020
marcan2020 / shc_toNumericQr.js
Created May 20, 2021 14:52
shc_toNumericQr.js
const SMALLEST_B64_CHAR_CODE = 45; // "-".charCodeAt(0) === 45
const toNumericQr = (jws: string, chunkIndex: number, totalChunks: number): QRCodeSegment[] => [
{ data: 'shc:/' + ((totalChunks > 1) ? `${chunkIndex + 1}/${totalChunks}/` : ``), mode: 'byte' },
{
data: jws
.split('')
.map((c) => c.charCodeAt(0) - SMALLEST_B64_CHAR_CODE)
.flatMap((c) => [Math.floor(c / 10), c % 10])
.join(''),
mode: 'numeric',
async signJws(idTokenPayload: Record<string, unknown>, deflate = true): Promise<string> {
const bodyString = JSON.stringify(idTokenPayload);
const fields = deflate ? { zip: 'DEF' } : {};
const body = deflate ? pako.deflateRaw(bodyString) : bodyString;
const signed = await jose.JWS.createSign({ format: 'compact', fields }, this.signingKey)
.update(Buffer.from(body))
.final();
return (signed as unknown) as string;
}
@marcan2020
marcan2020 / notable.md
Last active December 29, 2021 05:01
Dockerized version of Notable with no network access
@marcan2020
marcan2020 / .notable.json
Created January 18, 2021 23:10
Notable config file
{
"monaco": {
"editorOptions": {
"minimap": {
"enabled": false
},
"lineNumbers": "off",
"scrollBeyondLastLine": false,
"wordWrap": "bounded"
}
#!/bin/bash
usage()
{
echo "usage: $0 [-d DOMAIN -D DICTIONARY -o OUTFILE [-x code] [-xL length] | -h]"
}
if [[ $# -eq 0 ]] ; then
usage
exit 0