Skip to content

Instantly share code, notes, and snippets.

@marcan2020
Created May 20, 2021 14:52
Show Gist options
  • Save marcan2020/8680dbc6023a1a6cec1d1c0c81a1e3fc to your computer and use it in GitHub Desktop.
Save marcan2020/8680dbc6023a1a6cec1d1c0c81a1e3fc to your computer and use it in GitHub Desktop.
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',
},
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment