Practical Guide to PIH Hash Chains & Digital Signing in ZATCA Phase 2

Tax Compliance & ZATCA Published 2026-11-23 · 6 min read

What Actually Changed Between ZATCA Phase 1 and Phase 2?

Phase 1 (Generation) focused on structured invoicing with a basic 5-tag TLV QR code. Phase 2 (Integration) requires every invoice to be generated as a canonical UBL 2.1 XML document, cryptographically chained to the previous invoice, digitally signed, and transmitted to the Fatoora API.

Core Cryptographic Elements: ICV, PIH, and UUID

  • Invoice Counter Value (ICV): A strictly monotonic integer incremented by 1 for every invoice, credit note (381), or debit note (383) per signing unit with zero gaps.
  • Previous Invoice Hash (PIH): The Base64-encoded SHA-256 digest of the immediately preceding XML invoice (seeded with the standard hash of "0" for the first document).
  • Document UUID (v4): Globally unique document identifier preventing duplicate submissions across branches or POS shifts.
  • ECDSA (secp256k1) XAdES-BES Signature: Generated using the unit’s CSID certificate and embedded alongside TLV Tags 6, 7, 8, and 9 in the QR payload.

Clearance (B2B) vs Reporting (B2C) Flows

Standard B2B tax invoices follow the Clearance workflow: the XML is submitted to Fatoora and cleared before issuing the final signed invoice to the buyer. Simplified B2C retail/POS invoices are signed locally with your CSID, printed immediately, and reported within the 24-hour regulatory window.

4 Common Rejection Errors and How LAR ERP Prevents Them

  • Discount and TaxTotal rounding mismatch (BR-CO-13): Handled by deterministic line and document rounding before XML canonicalization.
  • Editing a posted invoice instead of issuing a Credit Note (381): Posted invoices are immutable; corrections flow exclusively through linked credit/debit notes.
  • Broken PIH sequence under concurrent billing: ICV increment and PIH chaining execute inside an atomic database transaction.
  • Exposing private signing keys: Private CSID keys are encrypted at rest with AES-256-GCM and never leave the server.
Practical Takeaway: Always validate your CSR, invoice templates, and credit notes in Sandbox and Simulation before switching to Production, keeping archived XML files linked directly to their GL entries.

Explore LAR ERP e-invoicing and accounting capabilities or start a free trial with your own workspace.