Skip to content

sen-ltd/address-decoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

address-decoder

Paste a Bitcoin or Ethereum address; see its byte-level breakdown — version byte, payload (hash160 / witness program), embedded checksum vs computed checksum. All decoders run locally: no network calls, no third-party crypto library.

What it covers

  • Bitcoin Base58Check — P2PKH (1…), P2SH (3…), testnet (m…/n…/2…). Verifies the trailing 4 bytes equal the first 4 of SHA256(SHA256(version || payload)).
  • Bitcoin Bech32 / Bech32m — SegWit native (bc1… / tb1…). Verifies the polymod-1024 checksum and the BIP-0350 split between bech32 (witness v0) and bech32m (v1+, Taproot).
  • Ethereum (EIP-55)0x… hex addresses. Recomputes the keccak-256 of the lowercase hex string and verifies that mixed-case input matches the canonical capitalisation. Lowercase / uppercase input is accepted as "no checksum present".

Why?

Three encodings, three completely different design philosophies:

  • Bitcoin Base58Check — defensive paranoia. SHA-256 squared, four bytes of checksum on every address. A typo of any single character is rejected with vanishingly small false-positive rate. The cost is that addresses are ugly (1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa) and you can't reason about them by eye.
  • Ethereum EIP-55 — bolted-on letter-case checksum, designed in 2016 after the fact. It piggybacks on the case insensitivity of hex digits (a and A both decode to nibble 0xa), using letter case to encode 4 extra bits per character about a keccak-256 hash of the address. An address that's all-lowercase has no checksum at all — the design is opt-in and doesn't break older non-EIP-55-aware tooling.
  • Bech32 / Bech32m — designed to be QR-friendly, easy to read out loud, and detect substitutions. Uses a 30-bit polynomial checksum modulo a known generator that catches all single-character errors and most pairs. Witness v0 used bech32; witness v1+ (Taproot) uses bech32m, which differs by exactly one constant — a defensive split prompted by an attack against the first one.

Run locally

npm run serve        # python3 -m http.server 8080
# open http://localhost:8080

No build step. Files: index.html, style.css, script.js, decoder.js, keccak256.js.

Tests

npm test

30 tests in tests/:

  • All 8 official EIP-55 reference vectors (mixed-case addresses) round-trip to themselves.
  • BIP-0173 P2WPKH and BIP-0350 Taproot reference vectors decode with the correct variant tagging.
  • Bitcoin Genesis address (1A1z…), P2SH (3J98…), and a testnet P2PKH decode and verify checksums.
  • Mutating a single character of a Bitcoin address triggers a checksum failure.
  • Mixed-case bech32 input is rejected (per spec).
  • Lowercase Ethereum addresses are accepted with a "no checksum" note.
  • Mixed-case Ethereum with a wrong capital letter is rejected as INVALID.

The Keccak-256 implementation (Ethereum's hash; not NIST SHA3-256) is verified via the EIP-55 vectors; eight independent address strings hashing to the right capitalisation pattern is strong evidence.

License

MIT

Links

About

Paste a BTC or ETH address; see byte-level Base58Check / Bech32m / EIP-55 breakdown. Hand-rolled Keccak-256, zero deps.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors