Skip to content
KSA-13

Previous invoice hash (PIH)

The base64 hash of the previous document from the same device, linking documents into a chain.

Each document carries the fingerprint of the one before it, so deleting or altering a document breaks the chain. BR-KSA-61 requires the field and BR-KSA-26 sets the method: remove the UBLExtensions block, the QR reference block and the cac:Signature block, canonicalize with C14N11, hash with SHA-256, encode in base64.

The first document of a device's chain has no predecessor and carries a fixed value from the standard: NWZlY2ViNjZmZmM4NmYzOGQ5NTI3ODZjNmQ2OTZjNzljMmRiYzIzOWRkNGU5MWI0NjcyOWQ3M2EyN2ZiNTdlOQ==, the base64 of the hexadecimal SHA-256 of the character "0".

Rejected documents stay in the chain: the technical guidelines say the platform records their hashes, so the next document must point to the rejected one, not to the one before it. There is no need to wait for clearance before issuing the next document, since ZATCA's stamp does not change the hash.

IdentifierKSA-13
Path in the document/Invoice/cac:AdditionalDocumentReference[cbc:ID='PIH']/cac:Attachment/cbc:EmbeddedDocumentBinaryObject
Cardinality0..1
Data typeBinary (base64)
Applies toStandard tax invoice and Simplified tax invoice

In JooDax

Built

Each unit keeps the hash of its last document and writes it into the next, starting from the standard's fixed value; the unit tests check that each document carries its predecessor's hash.

crates/jdx-einvoice-sa/src/unit.rs

Applies to

Tax invoiceDebit noteCredit noteSimplifiedSimplified debitSimplified credit
MandatoryMandatoryMandatoryMandatoryMandatoryMandatory

Rules that check it

  • BR-KSA-26 · The previous invoice hash must be a base64 SHA-256 computed the standard's way.
  • BR-KSA-61 · Every document must contain the previous invoice hash.

Related fields

Fields — E-invoicing in Saudi Arabia (FATOORA)

Sources

  1. Electronic Invoice XML Implementation Standard to the E-Invoicing resolution dated 2023-05-19 (v1.2) — ZATCA
  2. Electronic Invoice Data Dictionary to the E-Invoicing resolution dated 2023-05-19 (v1.2) — ZATCA
  3. Security Features Implementation Standards to the E-Invoicing resolution dated 2023-05-19 (v1.2) — ZATCA
  4. E-invoicing Detailed Technical Guidelines (vVersion 2) — ZATCA

Checked on: 4 November 2026. What concerns JooDax is taken from the programs’ own code.