#bech32 #base32 #codec

no-std bech32-no_std

Encodes and decodes the Bech32 format

1 unstable release

0.7.3 Oct 12, 2020

#1714 in Encoding

MIT license

31KB
632 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 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]);

No runtime deps

Features