#bech32 #base32

no-std bech32-no_std

Encodes and decodes the Bech32 format

1 unstable release

0.7.3 Oct 12, 2020

#10 in #bech32

Download history 1/week @ 2025-09-19 9/week @ 2025-09-26 344/week @ 2025-10-03 35/week @ 2025-10-10 2134/week @ 2025-10-17 300/week @ 2025-10-24 1/week @ 2025-11-07 698/week @ 2025-11-14 2229/week @ 2025-11-21 426/week @ 2025-11-28 31/week @ 2025-12-05 404/week @ 2025-12-12

404 downloads per month

MIT license

31KB
632 lines

Encoding and decoding of the Bech32 format

Bech32 is an encoding scheme that is easy to use for humans and efficient to encode in QR codes.

A Bech32 string consists of a human-readable part (HRP), a separator (the character '1'), and a data part. A checksum at the end of the string provides error detection to prevent mistakes when the string is written off or read out loud.

The original description in BIP-0173 has more details.

Examples

use bech32::{self, FromBase32, ToBase32};

let encoded = bech32::encode("bech32", vec![0x00, 0x01, 0x02].to_base32()).unwrap();
assert_eq!(encoded, "bech321qqqsyrhqy2a".to_string());

let (hrp, data) = bech32::decode(&encoded).unwrap();
assert_eq!(hrp, "bech32");
assert_eq!(Vec::<u8>::from_base32(&data).unwrap(), vec![0x00, 0x01, 0x02]);

Bech32 Rust

Docs.rs badge Build Status

Rust implementation of the Bech32 encoding format described in BIP-0173. You can find some usage examples in the documentation.

Bitcoin-specific address encoding is handled by the bitcoin-bech32 crate.

No runtime deps

Features