BR-KSA-26: Previous invoice hash (PIH) attachment must be filled, text/plain
Runs on the cac:Attachment of the cac:AdditionalDocumentReference whose cbc:ID is 'PIH' (KSA-13): it must contain a non-empty cbc:EmbeddedDocumentBinaryObject with mimeCode='text/plain'. The official text describes how the SHA-256 hash is computed, but this check does not recompute or verify the hash value itself.
How to fix it
Put the base64 SHA-256 hash of the previous invoice in <cbc:EmbeddedDocumentBinaryObject mimeCode="text/plain">…</cbc:EmbeddedDocumentBinaryObject> inside the PIH attachment. For the first invoice, the official text gives the value NWZlY2ViNjZmZmM4NmYzOGQ5NTI3ODZjNmQ2OTZjNzljMmRiYzIzOWRkNGU5MWI0NjcyOWQ3M2EyN2ZiNTdlOQ==.
ZATCA's official text
[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 <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 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.
Source: ZATCA SDK 3.4.8 · ZATCA KSA rules
Fails when (the condition ZATCA's SDK runs)
not(exists(cbc:EmbeddedDocumentBinaryObject) and (cbc:EmbeddedDocumentBinaryObject) != '' and (cbc:EmbeddedDocumentBinaryObject[normalize-space(@mimeCode) = 'text/plain']))
Related rules
- BR-KSA-61 · Every invoice needs the previous invoice hash (PIH, KSA-13)
- BR-KSA-23 · VAT-exempt (E) breakdown needs an exemption reason code (BT-121)
- BR-KSA-24 · Not-subject-to-VAT (O) breakdown needs a reason code (BT-121)
- BR-KSA-25 · Simplified invoice with EDU/HEA exemption needs the buyer name
- BR-KSA-27 · Simplified invoices must carry a QR code (KSA-14)
- BR-KSA-28 · Signature information ID must be ...ubl:signature:1
Validate your invoice against ZATCA's rules
Paste the XML and see every error and warning. It runs in your browser; the invoice goes nowhere.
Validate an invoice or try Matheel