Skip to content

Bech32m

Utility functions for BIP-350 bech32m encoding and decoding.

Examples

Below are some examples demonstrating common usages of the Bech32m module:

Encoding

import { Bech32m } from 'ox'
 
const encoded = Bech32m.encode('tempo', new Uint8Array(20))

Decoding

import { Bech32m } from 'ox'
 
const { hrp, data } = Bech32m.decode('tempo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq7w9gdx')

Functions

NameDescription
Bech32m.decodeDecodes a bech32m string (BIP-350) into a human-readable part and data bytes.
Bech32m.encodeEncodes data bytes with a human-readable part (HRP) into a bech32m string (BIP-350).

Errors

NameDescription
Bech32m.ExceedsLengthErrorThrown when the encoded string exceeds the length limit.
Bech32m.InvalidCharacterErrorThrown when a bech32m string contains an invalid character.
Bech32m.InvalidChecksumErrorThrown when a bech32m string has an invalid checksum.
Bech32m.InvalidHrpErrorThrown when the HRP is invalid (empty or contains non-ASCII characters).
Bech32m.InvalidPaddingErrorThrown when the padding bits are invalid during base32 conversion.
Bech32m.MixedCaseErrorThrown when a bech32m string contains mixed case.
Bech32m.NoSeparatorErrorThrown when a bech32m string has no separator.