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.Bech32

Description

The BIP0173 bech32 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

bech32-encoded bytestring

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

>>> let Just bech32 = encode "bc" "my string"
>>> bech32
"bc1d4ujqum5wf5kuecmu02w2"

decode Source #

Arguments

:: ByteString

bech23-encoded bytestring

-> Maybe (ByteString, ByteString)

(hrp, data less checksum)

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

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

Checksum

verify Source #

Arguments

:: ByteString

bech32-encoded bytestring

-> Bool 

Verify that a bech32 string has a valid checksum.

>>> verify "bc1d4ujqum5wf5kuecmu02w2"
True
>>> verify "bc1d4ujquw5wf5kuecmu02w2" -- s/m/w
False