UNPKG

@li0ard/tsemrtd

Version:

simple library for eMRTD. supports browsers, node, bun and more!

28 lines (27 loc) 957 B
import { TLV } from "@li0ard/tinytlv"; import { TAGS, ISO7816Tags } from "./consts/enums.js"; import { validateDataGroupTag } from "./utils.js"; /** * Class for working with DG5 (Displayed image) */ export class DG5 { /** * Get displayed image * @param data Data of EF.DG5 file */ static load(data) { const tlv = TLV.parse(data); validateDataGroupTag(tlv, TAGS.DG5); const bict = tlv.childs[0]; if (parseInt(bict.tag, 16) != ISO7816Tags.BIOMETRIC_INFO_COUNT) throw new Error(`Invalid object tag "0x${bict.tag}", expected 0x02`); const results = []; for (let i = 0; i < parseInt(bict.value, 16); i++) { const record = tlv.childs[i + 1]; if (parseInt(record.tag, 16) != 0x5f40) throw new Error(`Invalid object tag "0x${tlv.tag}", expected 0x5f40`); results.push(record.byteValue); } return results; } }