Skip to content

fix(ar/cbu): accept valid CBUs whose check digit is 0 - #167

Merged
koblas merged 1 commit into
koblas:mainfrom
nicolasfishman:fix/ar-cbu-check-digit-zero
Aug 1, 2026
Merged

fix(ar/cbu): accept valid CBUs whose check digit is 0#167
koblas merged 1 commit into
koblas:mainfrom
nicolasfishman:fix/ar-cbu-check-digit-zero

Conversation

@nicolasfishman

Copy link
Copy Markdown
Contributor

Problem

AR.cbu rejects valid CBUs whenever either of the two check digits is 0.

const { stdnum } = require('stdnum');

stdnum.AR.cbu.validate('0720429088000002339140');
// => { isValid: false, error: InvalidChecksum }   ❌ this CBU is valid

stdnum.AR.cbu.validate('0000000000000000000000');
// => { isValid: false, error: InvalidChecksum }   ❌ both check digits are 0

Root cause

In src/ar/cbu.ts the check digits are computed as:

const s1 = String(
  10 -
    weightedSum(front, { reverse: true, weights: [3, 1, 7, 9, 3, 1, 7], modulus: 10 }),
);

weightedSum(..., { modulus: 10 }) already returns a value in [0, 9], so 10 - that
is in [1, 10]. When weightedSum returns 0, 10 - 0 === 10 and String(10) is
"10", which can never equal the single-character check digit c1/c2 ("0"). Any CBU
whose bank block or account block has a check digit of 0 is therefore rejected.

Worked example for 0720429088000002339140:

  • front 0720429, c1 = "0", weightedSum(front) = 0s1 = "10" (should be "0")
  • back 8800000233914, c2 = "0", weightedSum(back) = 0s2 = "10" (should be "0")

Fix

Wrap the result modulo 10 — the same thing the sibling src/mx/clabe.ts validator
already does ((10 - weightedSum(...)) % 10), so this just brings ar/cbu in line with it.

Tests

Added three cases to src/ar/cbu.spec.ts:

  • 0720429088000002339140 — both check digits 0 → now valid
  • 0000000000000000000000 — both check digits 0 → now valid
  • 0720429088000002339141 — tampered → still InvalidChecksum

Full suite passes (npx jest), lint and prettier are clean.

`10 - weightedSum(...)` yields 10 (not 0) when the weighted sum is 0, and
`String(10)` is "10", which never equals a single-character check digit "0".
So any valid CBU whose bank block or account block has a check digit of 0 was
wrongly rejected with InvalidChecksum.

Wrap the result modulo 10, matching what the sibling mx/clabe validator already
does: `(10 - weightedSum(...)) % 10`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@koblas
koblas merged commit 8c5880b into koblas:main Aug 1, 2026
2 checks passed
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.

2 participants