Skip to content

fix(isBtcAddress): verify base58check and bech32 checksums - #2984

Open
adembilge wants to merge 1 commit into
validatorjs:masterfrom
adembilge:fix/btc-address-checksum
Open

adembilge wants to merge 1 commit into
validatorjs:masterfrom
adembilge:fix/btc-address-checksum

Conversation

@adembilge

Copy link
Copy Markdown

Fixes #2982

isBtcAddress only checked the address alphabet, so a one-character typo still returned true. It now verifies the checksum: double SHA-256 for base58check, BIP-173 bech32 for witness version 0, and BIP-350 bech32m for witness versions 1-16.

Two addresses that were listed as valid fail that check and are now rejected:

  • 14qViLJfdGaP4EeHnDyJbEGQysnCpwk3gd
  • 17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhemt (extra trailing t; 17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem stays valid)

References:

npm test: 323 passing.

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)
  • References provided in PR (where applicable)

Reject addresses whose alphabet matches but whose checksum does not, so a single-character typo is no longer accepted.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI balanced review requested due to automatic review settings December 3, 2026 21:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@codecov

codecov Bot commented Dec 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.61702% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.67%. Comparing base (9ff3424) to head (f675e77).

Files with missing lines Patch % Lines
src/lib/isBtcAddress.js 93.61% 5 Missing and 4 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##            master    #2984      +/-   ##
===========================================
- Coverage   100.00%   99.67%   -0.33%     
===========================================
  Files          114      114              
  Lines         2599     2739     +140     
  Branches       658      669      +11     
===========================================
+ Hits          2599     2730     +131     
- Misses           0        5       +5     
- Partials         0        4       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

isBtcAddress accepts Bitcoin addresses with broken checksums (single-character typos pass validation)

2 participants