Skip to content

fix(bitcoin): validate Base58Check and Bech32/Bech32m address checksums (#21) - #22

Closed
meridianmindx wants to merge 1 commit into
agntn:mainfrom
meridianmindx:fix/bitcoin-address-checksums
Closed

fix(bitcoin): validate Base58Check and Bech32/Bech32m address checksums (#21)#22
meridianmindx wants to merge 1 commit into
agntn:mainfrom
meridianmindx:fix/bitcoin-address-checksums

Conversation

@meridianmindx

Copy link
Copy Markdown

Closes #21

Summary of Changes

  • Base58Check Checksum Validation:
    • Implemented 4-byte checksum verification against double SHA-256 (createHash("sha256")) of the 21-byte version+payload slice for legacy (P2PKH 0x00 and P2SH 0x05) addresses.
    • Rejects single-character corruptions that alter the stored Base58 payload checksum (e.g. 14zMkTgaVXJcxdh4JdWi29MLRR44iUSG9W vs corrupted 14zMkTgaVXJcxdh4JdWi29MLRR44iUSG9X).
  • Bech32 & Bech32m Polymod Verification:
    • Implemented Bech32/Bech32m polymod checksum calculation over expanded bc HRP and 5-bit data values.
    • Validates BIP-173 constant (1) for SegWit v0 (bc1q...) addresses and BIP-350 constant (0x2bc830a3) for SegWit v1+ (Taproot bc1p...) addresses.
    • Rejects single-character corruptions that fail polymod verification (e.g. bc1qaxm5p35r3yl25rdh5ex0j6wx33peht9r735x90 vs corrupted bc1qaxm5p35r3yl25rdh5ex0j6wx33peht9r735x9q).
  • Automated Regression Tests:
    • Added unit test cases verifying rejection of corrupted Base58Check legacy addresses and corrupted Bech32 addresses.
    • Confirmed valid P2PKH, P2SH, Bech32 (v0 lowercase and uppercase), and Bech32m (v1 Taproot) addresses continue to pass cleanly.

Verification

  • vitest run → 122/122 unit tests passing (5/5 test files).
  • oxlint . → 0 errors, 0 warnings.
  • oxfmt --check . → clean formatting.
  • tsc --noEmit & tsc --noEmit -p tsconfig.extensions.json → clean typecheck.
  • obuild → clean build output across CLI, MCP, and library entries.

Base Payout Address: 0xcFDa9f32d292661740a6d0B4c00867E34c05c56D

@oritwoen oritwoen closed this Aug 27, 2026
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.

Validate Bitcoin address checksums

2 participants