fix(isBtcAddress): accept 62-character bech32 P2WSH addresses#2775
Open
chatman-media wants to merge 1 commit into
Open
fix(isBtcAddress): accept 62-character bech32 P2WSH addresses#2775chatman-media wants to merge 1 commit into
chatman-media wants to merge 1 commit into
Conversation
The bech32 regex capped the data part after the bc1/tb1 prefix at 58 characters, but a witness-v0 32-byte program (P2WSH) squashes to 52 base32 chars, giving 1 (witness version) + 52 + 6 (checksum) = 59 data characters (62 total). As a result valid P2WSH addresses, including the official BIP-173 test vectors, were rejected. Bump the upper bound from 58 to 59 so v0 32-byte addresses match while the upper length limit is still enforced.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2775 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 114 114
Lines 2587 2587
Branches 656 656
=========================================
Hits 2587 2587 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
isBtcAddress rejects valid native SegWit P2WSH addresses (62 characters), including the official BIP-173 test vectors.
Problem
The bech32 pattern caps the data part after the
bc1/tb1prefix at 58 characters:A bech32 address is
HRP+1+ data, where the data part is1(witness version) + program (squashed to base32) +6(checksum). For a witness-v0 program:1 + prog + 6)ceil(20*8/5) = 32ceil(32*8/5) = 52P2WPKH sits exactly at the lower bound (39) and passes, but P2WSH needs 59 data characters and is cut off by the
{39,58}upper bound, so every 62-char v0 address fails. (P2TR/taproot is also 62 chars but only matched today by accident — its 4th charplets the regex backtrack into thebc1palternative.)Reproduction
Fix
Bump the upper bound from
58to59so a v0 32-byte (P2WSH) address matches. The upper limit is still enforced — a 60-data-char string is added to the invalid fixtures to guard against regression.Authoritative source
Tests
Added the two BIP-173 P2WSH vectors to
validand an over-length (60 data chars) string toinvalidintest/validators.test.js. The new valid cases fail before the fix and pass after; full suite (npm test) is green with coverage unchanged.