Crate bech32 [] [src]

Encoding and decoding Bech32 format

Bech32 is a 5-bit (base-32) encoding scheme that produces strings that comprise a human-readable part, a separator, a data part, and a checksum. The encoding implements a BCH code that guarantees error detection of up to four characters with less than 1 in 1 billion chance of failing to detect more errors.

The Bech32 encoding was originally formulated in BIP-0173

Examples

use bech32::Bech32;

let b = Bech32::new("bech32".into(), vec![0x00, 0x01, 0x02]).unwrap();
let encoded = b.to_string();
assert_eq!(encoded, "bech321qpz4nc4pe".to_string());

let c = encoded.parse::<Bech32>();
assert_eq!(b, c.unwrap());

Structs

Bech32

Grouping structure for the human-readable part and the data part of decoded Bech32 string.

Enums

Error

Error types for Bech32 encoding / decoding

Functions

convert_bits

Convert between bit sizes