Skip to content

Verified Rendering

SIDHARTH SINGH edited this page Dec 3, 2026 · 1 revision

Self-Auditing Rendering (renderVerified) & Tamper Evidence (verifyIntegrity)

Normally, HTML-to-PDF systems hand bytes back to the caller and hope pagination or rounding did not drop a zero or clip a tax column. Because ONEX both renders PDFs and extracts invoices in one engine, it closes the verification loop automatically.

What renderVerified() Does

  1. Renders your HTML document cleanly using toBuffer().
  2. Runs extractInvoiceData() and extractText() on the generated bytes right inside Node.
  3. Compares extracted totals, subtotals, tax totals, invoice numbers, PO numbers, Mod-36 GSTIN checksums, line-item sums, and required phrases against your expectations.
  4. If anything fails on pass one, retries once with forced bundled fonts and extra settlement wait time—then fails cleanly with ONEX_RENDER_VERIFICATION_FAILED if mismatches persist.
  5. Writes a canonical SHA-256 content manifest (optionally signed with hmacSecret) directly into the PDF's /Metadata XMP stream.

Usage & Long-Term Audit

const out = await engine.renderVerified(invoiceData, html, {
  format: 'A4',
  hmacSecret: process.env.ONEX_AUDIT_SECRET,
  expectations: {
    grandTotal: 11800,
    subtotal: 10000,
    invoiceNumber: 'INV-2026-8842',
    gstin: '27AADCB2230M1Z...',
    verifyLineItemSum: true,
  },
});

const audit = verifyIntegrity(out.bytes, { hmacSecret: process.env.ONEX_AUDIT_SECRET });

Months later, calling verifyIntegrity() checks both text/field consistency against the embedded manifest and timing-safe HMAC verification without launching Chromium.

Clone this wiki locally