UNPKG

@li0ard/tsemrtd

Version:

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

28 lines (27 loc) 954 B
import { TLV } from "@li0ard/tinytlv"; import { TAGS, ISO7816Tags } from "./consts/enums.js"; import { validateDataGroupTag } from "./utils.js"; /** * Class for working with DG7 (Signature) */ export class DG7 { /** * Get image of signature * @param data Data of EF.DG7 file */ static load(data) { const tlv = TLV.parse(data); validateDataGroupTag(tlv, TAGS.DG7); 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) != 0x5f43) throw new Error(`Invalid object tag "0x${tlv.tag}", expected 0x5f43`); results.push(record.byteValue); } return results; } }