Created
May 20, 2021 14:52
-
-
Save marcan2020/8680dbc6023a1a6cec1d1c0c81a1e3fc to your computer and use it in GitHub Desktop.
shc_toNumericQr.js
This file contains 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
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