Fixing Arabic UTF-8 Length Bugs in ZATCA Phase-1 TLV QR Codes with TypeScript
A developer explains how Saudi ZATCA Phase-1 e-invoices need a Base64-encoded TLV QR code containing five fields: seller name, 15-digit VAT number, ISO 8601 timestamp, total with VAT, and VAT total. The article points out that using JavaScript's string.length for the length byte breaks Arabic text, because ZATCA's scanner validates UTF-8 byte counts rather than UTF-16 code units. To solve this, the author shares a browser-native TypeScript implementation that uses TextEncoder to compute exact byte lengths before assembling and Base64-encoding the frame. The post also promotes the author's BillCraft invoicing tool and a self-hostable source kit as ways to test and deploy the approach.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in