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::wit_prog::WitnessProgram; let witness_program = WitnessProgram { version: 0, program: 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] }; let enc_result = witness_program.to_address("tb".to_string()); assert_eq!(enc_result.unwrap(), "tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy".to_string());
Modules
bech32 |
Encode and decode the Bech32 format, with checksums |
wit_prog |
Segregated Witness address encoding and decoding from and to a Witness Program. |
Enums
AddressError |
Error types while encoding and decoding SegWit addresses |
BitConversionError |
Error types during bit conversion |
CodingError |
Error types for Bech32 encoding / decoding |
ScriptPubKeyError |
Error types for validating scriptpubkeys |
WitnessProgramError |
Error types for witness programs |