/** Numeric packing: BCD = 2 digits/byte, ASCII = 1 char/byte. */ declare enum NumericEncoding { ASCII = "ascii", BCD = "bcd" } /** Bitmap wire encoding: raw bytes (default) or ASCII hex (16 chars per 8-byte segment). */ declare enum BitmapEncoding { Binary = "binary", HexAscii = "hex-ascii" } /** Encoding of the LL/LLL length prefix. BCD LL=1 byte/LLL=2 bytes; ASCII LL=2 bytes/LLL=3 bytes. */ declare enum VarLenHeaderEncoding { ASCII = "ascii", BCD = "bcd" } /** Encoding of a variable field's value bytes. */ declare enum VarPayloadEncoding { ASCII = "ascii", BINARY = "binary", BCD_DIGITS = "bcd-digits" } /** Whether a length header counts digits or bytes. `DIGITS` is valid only on numeric (`*n`) fields. */ declare enum VarLenCountMode { BYTES = "bytes", DIGITS = "digits" } /** Internal field-type tag carried on every format object. Use the helpers below, not this directly. */ declare enum Kind { Alpha = "a", AlphaNumeric = "an", AlphaNumericSpecial = "ans", Binary = "b", Bitmap = "bitmap", LLVAR = "LLVAR", LLVARn = "LLVARn", LLVARan = "LLVARan", LLVARans = "LLVARans", LLVARb = "LLVARb", LLLVAR = "LLLVAR", LLLVARn = "LLLVARn", LLLVARan = "LLLVARan", LLLVARans = "LLLVARans", LLLVARb = "LLLVARb", Numeric = "n" } type HeaderSpec = { encode: (messageBytes: Buffer) => Buffer; decode: (buf: Buffer) => { headerLength: number; }; }; type AFormat = { kind: Kind.Alpha; length: number; }; type ANFormat = { kind: Kind.AlphaNumeric; length: number; }; type ANSFormat = { kind: Kind.AlphaNumericSpecial; length: number; }; type BFormat = { kind: Kind.Binary; length: number; }; type NFormat = { kind: Kind.Numeric; length: number; encoding?: NumericEncoding; }; type BitmapFormat = { kind: Kind.Bitmap; length: 8 | 16; encoding?: BitmapEncoding; }; type FormatObject = NFormat | AFormat | ANFormat | ANSFormat | BFormat | BitmapFormat | LLVARFormat | LLLVARFormat; /** Options shared by every LL/LLL helper. */ type VarBase = { /** Max logical length: digits for numeric (`*n`) fields, bytes otherwise. */ length: number; /** Value encoding. Defaults: `BCD_DIGITS` for `*n`, `BINARY` for `*b`, otherwise `ASCII`. */ payload?: VarPayloadEncoding; /** Length-prefix encoding. Default: `BCD`. */ lenHeader?: VarLenHeaderEncoding; /** Whether the length counts digits or bytes. Defaults: `DIGITS` for `*n`, otherwise `BYTES`. */ lenCountMode?: VarLenCountMode; }; type LLVARFormat = { kind: Kind.LLVAR | Kind.LLVARn | Kind.LLVARan | Kind.LLVARans | Kind.LLVARb; } & VarBase; type LLLVARFormat = { kind: Kind.LLLVAR | Kind.LLLVARn | Kind.LLLVARan | Kind.LLLVARans | Kind.LLLVARb; } & VarBase; /** Fixed-length numeric field (n). BCD-encoded by default; pass `{ encoding: NumericEncoding.ASCII }` for ASCII. */ declare const N: (length: number, opts?: { encoding?: NumericEncoding; }) => NFormat; /** Fixed-length alphabetic field (a), space-padded. */ declare const A: (length: number) => AFormat; /** Fixed-length alphanumeric field (an), space-padded. */ declare const AN: (length: number) => ANFormat; /** Fixed-length alphanumeric + printable-special field (ans), space-padded. */ declare const ANS: (length: number) => ANSFormat; /** Fixed-length binary field (b) of `lengthBytes`. Pack with a `Buffer` or hex string. */ declare const B: (lengthBytes: number) => BFormat; /** Bitmap field for DE 1. `8` ⇒ 64-bit (DE 1–64), `16` ⇒ 128-bit (allows DE 65–128). Pass `{ encoding: BitmapEncoding.HexAscii }` for ASCII hex wire format. */ declare const bitmap: (lengthBytes: 8 | 16, opts?: { encoding?: BitmapEncoding; }) => BitmapFormat; /** Variable field with a 2-digit length header (max length 99); choose `payload` explicitly. */ declare const LLVAR: (opts: VarBase) => LLVARFormat; /** * Numeric variable field, 2-digit length header (max length 99). * Defaults to BCD payload counted in digits. * @example * // PAN: BCD digits, BCD length header counting digits, up to 19 digits * LLVARn({ length: 19, lenHeader: VarLenHeaderEncoding.BCD, * payload: VarPayloadEncoding.BCD_DIGITS, lenCountMode: VarLenCountMode.DIGITS }) */ declare const LLVARn: (opts: VarBase) => LLVARFormat; /** Alphanumeric variable field, 2-digit length header (max length 99). */ declare const LLVARan: (opts: VarBase) => LLVARFormat; /** Alphanumeric + special variable field, 2-digit length header (max length 99). */ declare const LLVARans: (opts: VarBase) => LLVARFormat; /** Binary variable field, 2-digit length header (max length 99). Defaults to `BINARY` payload counted in bytes. Pack with a `Buffer` or even-length hex string. */ declare const LLVARb: (opts: VarBase) => LLVARFormat; /** Variable field with a 3-digit length header (max length 999); choose `payload` explicitly. */ declare const LLLVAR: (opts: VarBase) => LLLVARFormat; /** Numeric variable field, 3-digit length header (max length 999). Defaults to BCD payload counted in digits. */ declare const LLLVARn: (opts: VarBase) => LLLVARFormat; /** Alphanumeric variable field, 3-digit length header (max length 999). */ declare const LLLVARan: (opts: VarBase) => LLLVARFormat; /** Alphanumeric + special variable field, 3-digit length header (max length 999). */ declare const LLLVARans: (opts: VarBase) => LLLVARFormat; /** Binary variable field, 3-digit length header (max length 999). Defaults to `BINARY` payload counted in bytes. Pack with a `Buffer` or even-length hex string. */ declare const LLLVARb: (opts: VarBase) => LLLVARFormat; type EncoderOptions = { /** Optional message header wrapped on pack and skipped on unpack (e.g. an acquirer prefix). */ header?: HeaderSpec; }; /** How `explain()` redacts a field: `'pan'` keeps first 6 / last 4 digits, `'redact'` hides it entirely. */ type MaskMode = 'pan' | 'redact'; /** Spec for a single data element. `mask` opts the field into redaction in `explain()`. */ type FieldSpec = { name: string; format: FormatObject; mask?: MaskMode; }; /** Message spec keyed by DE number. DE 0 sets MTI encoding, DE 1 sets bitmap size; both optional. */ type MessageSpec = Record; type PackedMessage = { mti: string; bytes: Buffer; }; type UnpackedMessage = { mti: string; fields: Record; bytesRead: number; }; /** * Encodes and decodes ISO 8583 messages against a {@link MessageSpec}. * @example * const iso = new Iso8583(spec) * const { bytes } = iso.pack('0200', { 3: '000000', 4: '000000001000' }) * const { mti, fields } = iso.unpack(bytes) // mti === '0200' */ declare class Iso8583 { private spec; private mtiEncoding; private bitmapConstraint; private bitmapEncoding; private header?; constructor(spec: MessageSpec, opts?: EncoderOptions); /** * Encodes an MTI and a `{ [DE]: value }` map into the message bytes. Only DE 2–128 are * emitted; the bitmap (and a secondary bitmap when any DE > 64) is computed automatically. * Throws if a field has no spec or a value violates its format. */ pack(mti: string, fields: Record): PackedMessage; /** * Decodes message bytes into `{ mti, fields, bytesRead }`. Field values are returned as * `string` (numeric/alpha) or `Buffer` (binary). Throws on underruns or unknown DEs. */ unpack(buf: Buffer): UnpackedMessage; /** * Renders a readable, line-per-field dump. Fields whose spec sets `mask` are redacted by * default; pass `{ unmask: true }` for raw values (local debugging only — never log it). * @example * iso.explain(bytes) * // MTI: 0200 * // 002 PAN (LLVARn, len=19): 476173******0119 */ explain(buf: Buffer, opts?: { unmask?: boolean; }): string; encodeField(de: number, spec: FieldSpec, value: Buffer | string | number): Buffer; decodeField(de: number, spec: FieldSpec, buf: Buffer, offset: number): { value: Buffer | string; read: number; }; } export { A, AN, ANS, B, BitmapEncoding, type FieldSpec, Iso8583, Kind, LLLVAR, LLLVARan, LLLVARans, LLLVARb, LLLVARn, LLVAR, LLVARan, LLVARans, LLVARb, LLVARn, type MaskMode, type MessageSpec, N, NumericEncoding, VarLenCountMode, VarLenHeaderEncoding, VarPayloadEncoding, bitmap };