XML canonicalization (C14N 1.1) before hashing
Turning XML text into one standard form before hashing, so the same document gives the same fingerprint on every system.
One document can be written as many texts: attribute order, quote style, namespace declarations, empty elements. Canonicalization (Canonical XML 1.1) maps all of them to one text, and the hash is taken over it.
ZATCA fixes it in the signature block: three XPath transforms removing UBLExtensions, cac:Signature and the QR reference, then the transform http://www.w3.org/2006/12/xml-c14n11. The same method computes the previous invoice hash.
Practical effects for Arabic invoices: text is UTF-8, quotes inside text are not escaped while &, < and > are, and the line whitespace around removed blocks stays in the text.
In JooDax
BuiltThe programs carry no canonicalizer. Instead they write the document in canonical form from the start (decision D-01: escape &, < and > only and leave quotes, unlike version 1.0), so the written text is the canonical text and the hash is taken from it directly. This relies on every character in the writer staying fixed; 400 golden cases hold it to version 1.0.
crates/jdx-einvoice-sa/src/xml.rs
Related pages
- KSA-13 Previous invoice hash (PIH)
- KSA-15 Cryptographic stamp
- BR-KSA-26 · The previous invoice hash must be a base64 SHA-256 computed the standard's way.
Related concepts
- The invoice hash: how it is computedA SHA-256 fingerprint of the document after removing the stamp and QR blocks and canonicalizing it, written in base64; the stamp and the chain rest on it.
- The cryptographic stamp (digital signature)An ECDSA signature in XAdES form over the document hash and signing properties, made with a registered device key and a ZATCA-issued certificate.
E-invoicing in Saudi Arabia (FATOORA)
Sources
- Security Features Implementation Standards to the E-Invoicing resolution dated 2023-05-19 (v1.2) — ZATCA
- Electronic Invoice XML Implementation Standard to the E-Invoicing resolution dated 2023-05-19 (v1.2) — ZATCA
- E-invoicing Detailed Technical Guidelines (vVersion 2) — ZATCA
Checked on: 4 November 2026. What concerns JooDax is taken from the programs’ own code.