Expand description
Bech32m decoding trait.
Import path:
use secure_gate::FromBech32mStr;
This trait provides secure, explicit decoding of Bech32m strings (BIP-350 checksum) to byte vectors, with HRP validation as the primary path. It is designed for handling untrusted input in cryptographic contexts, such as decoding encoded addresses or keys.
Requires the encoding-bech32m feature (distinct from classic Bech32).
§Security Notes
- Treat all input as untrusted: validate Bech32m strings upstream before wrapping in secrets. HRP validation prevents cross-protocol confusion attacks.
- HRP validation: use
try_from_bech32mas the default; usetry_from_bech32m_uncheckedonly when you intentionally need the decoded HRP. Test empty and invalid HRP inputs in security-critical code. - Heap allocation: Returns
Vec<u8>— wrap inFixedorDynamicto store as a secret. - BIP-350 checksum: Enhanced error detection over BIP-173 Bech32.
- Standard 90-byte payload limit (by design): decodes only spec-compliant
Bech32m strings intended for Bitcoin address formats. Strings produced by
the extended
ToBech32/Bech32Largevariant are a distinct format — decode those withFromBech32Str.
§Example
use secure_gate::FromBech32mStr;
// BIP-350 minimal valid Bech32m test vector
let bech32m = "A1LQFN3A";
let data = bech32m.try_from_bech32m("A").expect("HRP matches");
assert!(data.is_empty());
let (hrp, data) = bech32m.try_from_bech32m_unchecked().expect("valid bech32m");
assert_eq!(hrp.to_ascii_lowercase(), "a");
assert!(data.is_empty());
// Error on invalid input
assert!("not-bech32m".try_from_bech32m("a").is_err());Traits§
- From
Bech32m Str - Extension trait for decoding Bech32m (BIP-350) strings into byte vectors.