Crate bech32 [] [src]

Encoding and decoding Bech32 Bitcoin Segwit Addresses

Encoding and decoding for Bech32 strings and Bitcoin Segregated Witness addresses. 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 library contains bech32 utilities for generic encoding of Bech32 strings and wit_prog for converting witness programs to Bitcoin addresses and back.

Examples

use bech32::Bech32;

let b = Bech32 {
    hrp: "bech32".to_string(), 
    data: vec![0x00, 0x01, 0x02] 
};
let encoded = b.to_string().unwrap();
assert_eq!(encoded, "bech321qpz4nc4pe".to_string());
 
let c = Bech32::from_string(encoded);
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