#bitcoin #base32 #bech32 #encoding

bitcoin-bech32

Encodes and decodes Bitcoin Segregated Witness addresses in Bech32

14 releases (9 breaking)

0.10.0 Jul 10, 2019
0.9.0 Feb 14, 2019
0.8.1 Sep 20, 2018
0.8.0 Jul 25, 2018
0.2.0 May 20, 2017

#86 in Encoding

Download history 466/week @ 2019-03-27 451/week @ 2019-04-03 474/week @ 2019-04-10 420/week @ 2019-04-17 465/week @ 2019-04-24 457/week @ 2019-05-01 437/week @ 2019-05-08 592/week @ 2019-05-15 484/week @ 2019-05-22 366/week @ 2019-05-29 414/week @ 2019-06-05 435/week @ 2019-06-12 320/week @ 2019-06-19 360/week @ 2019-06-26 312/week @ 2019-07-03

1,812 downloads per month
Used in 30 crates (4 directly)

MIT license

21KB
330 lines

Bitcoin Bech32

Encodes and decodes Bitcoin Segregated Witness addresses in the Bech32 format described in BIP-0173.

Example

use bitcoin_bech32::{WitnessProgram, u5};
use bitcoin_bech32::constants::Network;

let witness_program = WitnessProgram::new(
    u5::try_from_u8(0).unwrap(),
    vec![
        0x00, 0x00, 0x00, 0xc4, 0xa5, 0xca, 0xd4, 0x62,
        0x21, 0xb2, 0xa1, 0x87, 0x90, 0x5e, 0x52, 0x66,
        0x36, 0x2b, 0x99, 0xd5, 0xe9, 0x1c, 0x6c, 0xe2,
        0x4d, 0x16, 0x5d, 0xab, 0x93, 0xe8, 0x64, 0x33],
    Network::Testnet,
).unwrap();

let address = witness_program.to_address();
assert_eq!(address,
           "tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy".to_string());

let decoded = WitnessProgram::from_address(&address).unwrap();
assert_eq!(decoded, witness_program);

lib.rs:

Encoding and decoding Bech32 Bitcoin Segwit Addresses

Encoding and decoding for Bitcoin Segregated Witness addresses. Bech32 is an encoding scheme described in BIP-0173, and segregated witness addresses encoded by Bech32 simply combine a coin-specific human-readable part with the data of the witness program as the Bech32 data payload.

Examples

use bitcoin_bech32::{WitnessProgram, u5};
use bitcoin_bech32::constants::Network;

let witness_program = WitnessProgram::new(
    u5::try_from_u8(0).unwrap(),
    vec![
        0x00, 0x00, 0x00, 0xc4, 0xa5, 0xca, 0xd4, 0x62,
        0x21, 0xb2, 0xa1, 0x87, 0x90, 0x5e, 0x52, 0x66,
        0x36, 0x2b, 0x99, 0xd5, 0xe9, 0x1c, 0x6c, 0xe2,
        0x4d, 0x16, 0x5d, 0xab, 0x93, 0xe8, 0x64, 0x33],
    Network::Testnet
).unwrap();

let address = witness_program.to_address();
assert_eq!(address,
    "tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy".to_string());

let decoded = WitnessProgram::from_address(&address).unwrap();
assert_eq!(decoded, witness_program);

Dependencies

~29KB