UNPKG

emvco-qr-sdk

Version:

A robust TypeScript SDK for decoding, validating, and processing EMVCo-compliant QR codes used in digital payment systems.

22 lines (21 loc) 966 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCrcInfo = getCrcInfo; const crc_1 = require("../../../domain/value-objects/crc"); const qr_constant_1 = require("../../constants/qr.constant"); /** * Extracts and validates the CRC (Cyclic Redundancy Check) from a list of TLV entities. * * @param rawString - The original QR string, required for computing expected CRC. * @param tlvs - The parsed list of TLV entities. * @returns An object containing the CRC value and its validation result. */ function getCrcInfo(rawString, tlvs) { var _a; const crcTlv = tlvs.find((t) => t.tag === qr_constant_1.TAG_CRC); const value = (_a = crcTlv === null || crcTlv === void 0 ? void 0 : crcTlv.value) !== null && _a !== void 0 ? _a : ''; const isValid = crc_1.CRC.isValidFormat(value) ? new crc_1.CRC(value).validate(rawString.slice(0, rawString.length - 4)) : false; return { value, isValid }; }