Validate a ZATCA XML file for free · ZATCA error codes

ZATCA BR-KSA-26: previous invoice hash (PIH) format

BR-KSA-26 · Warning

[BR-KSA-26]-If the invoice contains the previous invoice hash (KSA-13), this hash must be base64 encoded SHA256. The hash shall be computed using the following method as described in the ds:transforms block in the XML Invoice Specifications: 1. Remove the block 2. Remove the block where = QR 3. Remove the block 4. Canonicalize the Invoice using the C14N11 standard 5. Hash the resulting string using SHA256 to a binary object 6. Base64 encode the binary object to generate the digest value For the first invoice, the previous invoice hash is "NWZlY2ViNjZmZmM4NmYzOGQ5NTI3ODZjNmQ2OTZjNzljMmRiYzIzOWRkNGU5MWI0NjcyOWQ3M2EyN2ZiNTdlOQ==", the equivalent for base64 encoded SHA256 of "0" (zero) character.

Official rule text: ZATCA e-invoice validation rules (official SDK XSL, 20210819).

The official rule: if the invoice contains the previous invoice hash (KSA-13), this hash must be base64-encoded SHA-256, computed with the method described in the ds:transforms block of the XML invoice specifications:

  1. Remove the Invoice / ext:UBLExtensions block
  2. Remove the Invoice / cac:AdditionalDocumentReference block where cbc:ID = QR
  3. Remove the Invoice / cac:Signature block
  4. Canonicalize the invoice using the C14N11 standard
  5. Hash the result with SHA-256 to a binary object
  6. Base64-encode that binary object

For the first invoice, the official initial previous-invoice hash is NWZlY2ViNjZmZmM4NmYzOGQ5NTI3ODZjNmQ2OTZjNzljMmRiYzIzOWRkNGU5MWI0NjcyOWQ3M2EyN2ZiNTdlOQ==, the base64-encoded SHA-256 of the character 0 (zero).

In UBL the PIH is typically an AdditionalDocumentReference with cbc:ID = PIH and a cbc:EmbeddedDocumentBinaryObject whose mimeCode is text/plain. Your EGS maintains the hash chain; Valifakt drafts are not part of a live Fatoora chain. This page is not tax advice.

What if PIH is omitted?

The official wording is conditional: if the invoice contains the previous invoice hash, it must be a base64 SHA-256 value. Phase 2 documents are expected to carry a PIH; a missing or malformed value is what this rule addresses when the element is present.

Can I invent a hash?

No. The official method and the documented first-invoice value must be used. A random string that is not that digest will fail.

Does Valifakt stamp the chain?

No. Valifakt is not a ZATCA-onboarded EGS and does not maintain a production PIH chain.

Related ZATCA rules

Validate a ZATCA XML file for free Pricing

Not tax advice. Valifakt is not a ZATCA-onboarded e-invoicing solution (EGS). Official rule text is quoted from the ZATCA SDK validation-rules XSL.