# EBTS / ANSI-NIST Packaging

Conceptual plan and implementation approach for producing ANSI/NIST transaction files and the TransactionBuilder abstraction.

## What We Produce

We need to produce an ANSI/NIST file (per ITL 1-2011 or applicable) containing:

- Type-1 — Transaction info: TOT, ORI, TCN, CNT, DAT, etc.
- Type-2 — Demographics: NAM, DOB, SEX, and other ORI-required fields.
- Type-14 — Fingerprint records: WSQ 500 ppi 8-bit, one per finger and/or slap as required.
- Type-10 — Facial/photo, only if the ORI config requires it.

## TransactionBuilder Abstraction

Because vendor/FDLE specs can be proprietary, the design uses an abstraction: a TransactionBuilder interface that:

- Accepts session metadata, demographics, and fingerprint records (WSQ + position).
- Optionally accepts a photo image when the ORI requires Type-10.
- Outputs a binary ANSI/NIST payload and a validation result (findings, valid/invalid).

Node (session-service) orchestrates: it gathers data from the DB and artifacts, calls the builder, then passes the binary to the vendor adapter. It does not store the binary long-term.

## Builder Interface (gRPC)

The builder is exposed as a gRPC service (same pattern as the Agent):

    service TransactionBuilderService {
      rpc BuildTransaction(BuildTransactionRequest) returns (BuildTransactionResponse);
      rpc ValidateTransaction(ValidateTransactionRequest) returns (ValidateTransactionResponse);
    }

    // BuildTransactionRequest: session_id, ori, purpose, tcn, demographics, fingerprints (WSQ + position), optional photo_image
    // BuildTransactionResponse: ansi_nist_payload (bytes), findings, valid

Validation findings include record type (e.g. Type-1, Type-2), code, message, and severity (error/warning).

## Implementation Approach

- Orchestrator: Node (session-service) — finalize step validates session, loads best captures from DB/artifacts, builds TCN, and either calls the builder or uses a stub.
- Builder: Native service (C#/.NET) — ANSI/NIST record layout and WSQ handling are complex; .NET has mature WSQ/NBIS options. Node has no robust ANSI-NIST assembler.
- Current status: Session-service uses a stub that returns a placeholder binary (no real Type-1/2/14 records). A C# Builder service can be added later; session-service will call it via gRPC and replace the stub payload with the real ANSI-NIST bytes.

## Reference

Full design: `docs/CAPTURE_SESSION_PIPELINE_DESIGN.md` — Section 4 (EBTS/ANSI-NIST Packaging Plan), Section 4.2 (Builder Interface), Section 4.3 (Implementation Approach).