emvco-qr-sdk
Version:
A robust TypeScript SDK for decoding, validating, and processing EMVCo-compliant QR codes used in digital payment systems.
55 lines (54 loc) • 1.98 kB
TypeScript
/**
* Represents a CRC (Cyclic Redundancy Check) value object used to verify data integrity.
*
* This class encapsulates the CRC value and provides utility methods for CRC calculation and validation.
* It implements the CRC-16/CCITT-FALSE algorithm, which is commonly used in EMVCo QR codes.
* The algorithm uses:
* - Initial value: 0xFFFF
* - Polynomial: 0x1021
* - No final XOR operation
*
* The calculated CRC is represented as a 4-character uppercase hexadecimal string.
*/
export declare class CRC {
private readonly _value;
/**
* Constructs a CRC value object.
*
* @param value - A 4-character hexadecimal string representing the CRC.
* @throws {Error} If the provided CRC does not match the required format.
*/
constructor(value: string);
/**
* Returns the CRC value as a string.
*
* @returns The CRC value.
*/
toString(): string;
/**
* Validates the format of a CRC string.
*
* @param value - The CRC string to validate.
* @returns True if the string is a valid 4-character hexadecimal, false otherwise.
*/
static isValidFormat(value: string): boolean;
/**
* Calculates the CRC-16/CCITT-FALSE for the given input string.
*
* This algorithm processes the input data byte by byte using the following parameters:
* - Initial value: 0xFFFF
* - Polynomial: 0x1021
* - No final XOR operation
*
* @param data - The input data (as a string) over which to calculate the CRC.
* @returns A 4-character uppercase hexadecimal string representing the calculated CRC.
*/
static calculate(data: string): string;
/**
* Validates that the CRC of the provided data matches the stored CRC value.
*
* @param data - The data (as a string) over which to compute the CRC.
* @returns True if the computed CRC matches the stored value; otherwise, false.
*/
validate(data: string): boolean;
}