Skip to content

fix: reject mixed-case bech32 addresses#4

Open
tolga-tom-nook wants to merge 2 commits into
BitgesellOfficial:betafrom
tolga-tom-nook:fix/reject-mixed-case-bech32
Open

fix: reject mixed-case bech32 addresses#4
tolga-tom-nook wants to merge 2 commits into
BitgesellOfficial:betafrom
tolga-tom-nook:fix/reject-mixed-case-bech32

Conversation

@tolga-tom-nook

Copy link
Copy Markdown

Summary

  • Reject mixed-case Bech32/SegWit addresses in isAddressValid() before checksum normalization.
  • Keep all-lowercase and all-uppercase Bech32 addresses valid, but reject mixed-case strings per BIP173.
  • Add regression coverage and update the distributed dist/functions/address.js entry point used by the package main.

RED proof

With the new regression added before the fix, npm test failed in Address functions: isAddressValid:

AssertionError: expected true to equal false
-true
+false

The failing address was a mixed-case BGL Bech32 address: Bgl1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7K0FY5A3.

GREEN proof

npm test

Result: 68 passing.

node - <<'NODE'
const assert = require('assert');
const jsbgl = require('./');
(async () => {
  await jsbgl.asyncInit(global);
  assert.strictEqual(isAddressValid('bgl1qw508d6qejxtdg4y5r3zarvary0c5xw7k0fy5a3'), true);
  assert.strictEqual(isAddressValid('BGL1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7K0FY5A3'), true);
  assert.strictEqual(isAddressValid('Bgl1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7K0FY5A3'), false);
  console.log('dist/package bech32 mixed-case regression ok');
})();
NODE

Result: dist/package bech32 mixed-case regression ok.

git diff --check

Result: clean.

Bounty context

This is submitted as a Bitgesell improvement/bugfix PR for the public bounty/improvement program:

@tolga-tom-nook

Copy link
Copy Markdown
Author

Pushed a small test-hardening follow-up (8074a86) to cover the same Bech32 mixed-case rule on testnet addresses too.

Validation rerun locally:

npm test
# 68 passing

node dist/package regression probe
# mainnet/testnet bech32 case regression ok

git diff --check
# clean

This keeps the implementation unchanged and adds explicit regression coverage that:

  • all-lowercase and all-uppercase mainnet/testnet Bech32 remain valid;
  • mixed-case mainnet/testnet Bech32 are rejected before checksum normalization.

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