ppad-bech32-0.2.2: bech32 and bech32m encoding/decoding, per BIPs 173 & 350.
Copyright(c) 2024 Jared Tobin
LicenseMIT
MaintainerJared Tobin <jared@ppad.tech>
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.ByteString.Bech32m

Description

The BIP350 bech32m checksummed base32 encoding, with decoding and checksum verification.

Synopsis

Encoding and Decoding

encode Source #

Arguments

:: ByteString

base256-encoded human-readable part

-> ByteString

base256-encoded data part

-> Maybe ByteString

bech32m-encoded bytestring

Encode a base256 human-readable part and input as bech32m.

>>> let Just bech32m = encode "bc" "my string"
>>> bech32m
"bc1d4ujqum5wf5kuecwqlxtg"

decode Source #

Arguments

:: ByteString

bech23-encoded bytestring

-> Maybe (ByteString, ByteString)

(hrp, data less checksum)

Decode a bech32m-encoded ByteString into its human-readable and data parts.

>>> decode "hi1df6x7cnfdcs8wctnyp5x2un9m9ac4f"
Just ("hi","jtobin was here")
>>> decode "hey1df6x7cnfdcs8wctnyp5x2un9m9ac4f" -- s/hi/hey
Nothing

Checksum

verify Source #

Arguments

:: ByteString

bech32m-encoded bytestring

-> Bool 

Verify that a bech32m string has a valid checksum.

>>> verify "bc1d4ujqum5wf5kuecwqlxtg"
True
>>> verify "bc1d4ujquw5wf5kuecwqlxtg" -- s/m/w
False