Skip to content

fix(isBtcAddress): verify address checksums - #2983

Open
sanketpatel32 wants to merge 4 commits into
validatorjs:masterfrom
sanketpatel32:devin/1796278831-btc-address-checksum
Open

sanketpatel32 wants to merge 4 commits into
validatorjs:masterfrom
sanketpatel32:devin/1796278831-btc-address-checksum

Conversation

@sanketpatel32

Copy link
Copy Markdown

isBtcAddress now verifies Bitcoin address checksums instead of relying only on address shape:

  • Verifies bech32 checksums for witness version 0 and bech32m checksums for witness versions 1-16, covering bc1p/tb1p taproot addresses.
  • Verifies base58check checksums for the legacy and testnet address versions already accepted by the validator, using a small dependency-free SHA-256 implementation.
  • Adds regression fixtures for one-character bech32, bech32m, and base58check checksum typos.

Two pre-existing valid fixtures were replaced because they only passed while checksums were ignored. 14qViLJfdGaP4EeHnDyJbEGQysnCpwk3gd had an incorrect checksum, so it was replaced with the corrected checksum encoding of the same payload (14qViLJfdGaP4EeHnDyJbEGQysnCpwn1gZ). 17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhemt decoded to 26 bytes rather than a 25-byte base58check payload, so it was replaced with the valid genesis address 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa.

The README now documents checksum validation. No runtime dependencies were added, and no generated distribution files are committed.

Fixes #2982

References:

Validation performed:

  • npm run lint
  • 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)

@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9ff3424) to head (30234c3).

Additional details and impacted files
@@            Coverage Diff             @@
##            master     #2983    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          114       115     +1     
  Lines         2599      2725   +126     
  Branches       658       664     +6     
==========================================
+ Hits          2599      2725   +126     

☔ 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.

@sanketpatel32

Copy link
Copy Markdown
Author

Added fixtures covering the missing invalid witness-version and base58check length/version branches in 30234c3. npm run lint and npm test pass locally, and coverage is green. Thanks!

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)

1 participant