13 unstable releases (6 breaking)

0.7.1 Jul 17, 2019
0.6.0 Jan 22, 2019
0.5.0 Jul 5, 2018
0.3.2 Mar 21, 2018
0.2.1 May 17, 2017

#59 in Encoding

Download history 1903/week @ 2019-07-12 2511/week @ 2019-07-19 3326/week @ 2019-07-26 2400/week @ 2019-08-02 2494/week @ 2019-08-09 1840/week @ 2019-08-16 1718/week @ 2019-08-23 2122/week @ 2019-08-30 2785/week @ 2019-09-06 4027/week @ 2019-09-13 5120/week @ 2019-09-20 4085/week @ 2019-09-27 4640/week @ 2019-10-04 5314/week @ 2019-10-11 5890/week @ 2019-10-18

7,223 downloads per month
Used in 76 crates (13 directly)

MIT license

29KB
584 lines

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.


lib.rs:

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::{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]);

No runtime deps