Skip to content

Fix: CRC-16 checksum incorrect for non-ASCII characters#8

Open
BrookTV wants to merge 4 commits into
maythiwat:mainfrom
BrookTV:fix/crc16-non-ascii
Open

Fix: CRC-16 checksum incorrect for non-ASCII characters#8
BrookTV wants to merge 4 commits into
maythiwat:mainfrom
BrookTV:fix/crc16-non-ascii

Conversation

@BrookTV

@BrookTV BrookTV commented Jun 26, 2026

Copy link
Copy Markdown

Issue

From Issue

Fix

Fixes #7

Replace charCodeAt(0) with new TextEncoder().encode(data), which yields the actual UTF-8 byte sequence the EMVCo spec calls for. TextEncoder is a Web API available natively in Node.js 11+, all modern
browsers, Deno, and Bun — no polyfill needed.

tsconfig.json gains "DOM" in lib so TypeScript resolves the TextEncoder type.

Test

Added a test case that parses a PromptPay payload containing non-ascii characters in the merchant name field (tag 59) in strict mode (checksum validation on). The test was failing before this fix.


@maythiwat

Copy link
Copy Markdown
Owner

Thanks for the PR!

I have two concerns I'd like to get your thoughts on

  1. Do Thai banks actually use non-ASCII characters in the Merchant Name (Tag 59) in practice? The EMVCo spec usually limits this to ASCII (using Tag 64 for local languages). Have you encountered real QR payloads from Thai banks failing because of Thai characters in this field?

  2. Could replacing charCodeAt with new TextEncoder().encode break older browsers or specific in-app/embedded browsers that might lack native TextEncoder support?

I'll look into this soon. Thanks again for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CRC-16 checksum incorrect for non-ASCII characters (e.g. Thai merchant name)

2 participants