yabase/bech32

Values

pub fn decode(
  input: String,
) -> Result(encoding.Bech32Decoded, encoding.CodecError)

Decode a Bech32 or Bech32m string, auto-detecting the variant. Per BIP 173: total length <= 90, HRP length 1..83.

pub fn encode(
  variant: encoding.Bech32Variant,
  hrp: String,
  data: BitArray,
) -> Result(String, encoding.CodecError)

Encode byte data with Bech32 or Bech32m. variant: Bech32 (BIP 173) or Bech32m (BIP 350). hrp: human-readable part (e.g. "bc" for Bitcoin mainnet). Must be all lowercase per BIP 173 — uppercase characters are rejected with Error(InvalidHrp("HRP must be lowercase")) rather than silently normalized, so the input is never quietly mutated. Lowercase the value at the call site if you started from a mixed-case identifier. data: raw bytes (8-to-5 bit conversion is done internally).

Search Document