Skip to content

fix(isBtcAddress): accept testnet P2PKH addresses starting with n - #2958

Open
yxshee wants to merge 1 commit into
validatorjs:masterfrom
yxshee:fix/btc-testnet-n
Open

yxshee wants to merge 1 commit into
validatorjs:masterfrom
yxshee:fix/btc-testnet-n

Conversation

@yxshee

@yxshee yxshee commented Nov 8, 2026 •

Copy link
Copy Markdown

isBtcAddress accepts testnet base58 addresses that start with m and 2, but rejects testnet P2PKH addresses that start with n. Testnet P2PKH uses version byte 0x6f, which encodes to a leading m or n depending on the hash, so every testnet P2PKH address that happens to start with n is rejected.

// private key 12, compressed pubkey, same hash160 on both networks
validator.isBtcAddress('1M9sZKsStVRZyBZSSVe13XMGRtCHkNj7VD'); // true  (mainnet)
validator.isBtcAddress('n1fprNxRhWrpkJ34A4cNsSZbHsnzhob2KL'); // false (testnet), expected true

This adds n to the base58 prefix list next to m.

Reference: https://en.bitcoin.it/wiki/List_of_address_prefixes (testnet pubkey hash, decimal 111, leading symbol m or n).

Tested by adding the address above to the valid list. On master the test fails with validator.isBtcAddress("n1fprNxRhWrpkJ34A4cNsSZbHsnzhob2KL") failed but should have passed. With the change npm test (build, lint, 323 tests) passes.

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 Nov 8, 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 (26992f1).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2958   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       114           
  Lines         2599      2599           
  Branches       658       658           
=========================================
  Hits          2599      2599           

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

1 participant