Encodings
Bech32
BIP173 bech32 with a prefix and 5-bit words and a BCH checksum. SegWit v0 and Lightning and Nostr
Encoding / Bech32
Bech32
A BCH checksum that catches four typos.
- Overhead
- +62% on random bytes
- Checksum
- checked on decode
- Standard
- BIP173
- Used by
- SegWit v0, Lightning, Nostr, Cosmos
family 2 / 20
Sample
- Out
- hi1dpjkcmr0ypmk7unvvsssgdwk9f
- Back
- "hello world!" · prefix hi
qpzry9x8gf2tvdw0s3jn54khce6mua7l
Options
Access
- Import
import { bech32 } from "@agntn/encodings/bech32" - CLI
encodings encode bech32 'hello world!' --prefix hi - Tryplayground with the sample above
- Kinbech32m
A human-readable prefix, a 1, then 5-bit words and six characters of checksum. The checksum is a BCH code that catches any four wrong characters. Base58 never came close.
encode("bech32", "gm", { prefix: "test" }); // "test1vaks69jerm"
decode("bech32", "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4");
// bytes: the 20-byte program, details: { prefix: "bc", witnessVersion: 0 }
A valid segwit v0 address comes back as its witness program. Anything else comes back as the bytes its words carry. A Nostr npub, say, or a Cosmos account. Mixed case is an error. Over 90 characters too, unless you raise limit. Lightning invoice? Raise it.
Checksums has the long version, segwit rules included.