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.
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:
- Remove the
Invoice / ext:UBLExtensionsblock - Remove the
Invoice / cac:AdditionalDocumentReferenceblock wherecbc:ID= QR - Remove the
Invoice / cac:Signatureblock - Canonicalize the invoice using the C14N11 standard
- Hash the result with SHA-256 to a binary object
- 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
- BR-KSA-03 – Invoice UUID (KSA-1) missing or invalid
- BR-KSA-08 – Seller identification (BT-29) missing or wrong scheme
- BR-KSA-27 – QR code (KSA-14) missing or not base64Binary
- BR-KSA-39 – Seller VAT number (BT-31) missing
- BR-KSA-40 – Seller VAT number (BT-31) is not 15 digits starting and ending with 3
- BR-KSA-04 – Invoice issue date (BT-2) is in the future or invalid
- BR-KSA-06 – Invoice transaction code (KSA-2) missing or invalid
- BR-KSA-17 – Credit or debit note missing the reason (KSA-10)
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.