Module segwit
Expand description
Segregated Witness API - enables typical usage for encoding and decoding segwit addresses.
BIP-173 and BIP-350 contain some complexity. This module aims to allow you to create modern
Bitcoin addresses correctly and easily without intimate knowledge of the BIPs. However, if you
do posses such knowledge and are doing unusual things you may prefer to use the primitives
submodules directly.
§Examples
use bech32::{hrp, segwit, Fe32, Hrp};
let witness_prog = [
0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4,
0x54, 0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23,
0xf1, 0x43, 0x3b, 0xd6,
];
// Encode a taproot address suitable for use on mainnet.
let _ = segwit::encode_v1(hrp::BC, &witness_prog);
// Encode a segwit v0 address suitable for use on testnet.
let _ = segwit::encode_v0(hrp::TB, &witness_prog);
// If you have the witness version already you can use:
let _ = segwit::encode(hrp::BC, witness_version, &witness_prog);
// Decode a Bitcoin bech32 segwit address.
let address = "bc1q2s3rjwvam9dt2ftt4sqxqjf3twav0gdx0k0q2etxflx38c3x8tnssdmnjq";
let (hrp, witness_version, witness_program) = segwit::decode(address).expect("failed to decode address");
Structs§
- An error while decoding a segwit address.
Enums§
- An error while constructing a
SegwitHrpstring
type.
Constants§
- The field element representing segwit version 0.
- The field element representing segwit version 1 (taproot).
Functions§
- Decodes a segwit address.
- Encodes a segwit address.
- Encodes a segwit address to a writer (
fmt::Write
) using lowercase characters. - Encodes a segwit address to a writer (
io::Write
) using lowercase characters. - Encodes a segwit address to a writer (
fmt::Write
) using lowercase characters. - Encodes a segwit address to a writer (
io::Write
) using lowercase characters. - Encodes a segwit address to a writer (
fmt::Write
) using uppercase characters. - Encodes a segwit address to a
io::Write
writer using uppercase characters. - Encodes a segwit version 0 address.
- Encodes a segwit version 1 address.
- Returns the length of the address after encoding HRP, witness version and program.