#bech32 #bitcoin #base32 #encoding

no-std bitcoin-bech32

Encodes and decodes Bitcoin Segregated Witness addresses in Bech32

18 releases (breaking)

Uses old Rust 2015

0.13.0 Apr 5, 2023
0.12.1 Feb 23, 2021
0.11.0 Aug 8, 2019
0.10.0 Jul 10, 2019
0.2.0 May 20, 2017

#2406 in Magic Beans

Download history 1472/week @ 2024-03-14 1381/week @ 2024-03-21 1758/week @ 2024-03-28 1125/week @ 2024-04-04 1594/week @ 2024-04-11 1893/week @ 2024-04-18 1731/week @ 2024-04-25 1255/week @ 2024-05-02 1092/week @ 2024-05-09 967/week @ 2024-05-16 903/week @ 2024-05-23 1132/week @ 2024-05-30 1221/week @ 2024-06-06 1506/week @ 2024-06-13 1293/week @ 2024-06-20 686/week @ 2024-06-27

4,902 downloads per month
Used in 27 crates (9 directly)

MIT license

27KB
462 lines

Bitcoin Bech32

Docs.rs badge Continuous Integration

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

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);

Dependencies

~180KB