Copyright | © 2017 Marko Bencun 2018-2019 IOHK |
---|---|
License | Apache-2.0 |
Safe Haskell | None |
Language | Haskell2010 |
Implementation of the Bech32 address format.
From an original implementation by Marko Bencun:
Synopsis
- encode :: HumanReadablePart -> DataPart -> Either EncodingError Text
- encodeLenient :: HumanReadablePart -> DataPart -> Text
- data EncodingError = EncodedStringTooLong
- decode :: Text -> Either DecodingError (HumanReadablePart, DataPart)
- decodeLenient :: Text -> Either DecodingError (HumanReadablePart, DataPart)
- data DecodingError
- data DataPart
- dataPartFromBytes :: ByteString -> DataPart
- dataPartFromText :: Text -> Maybe DataPart
- dataPartToBytes :: DataPart -> Maybe ByteString
- dataPartToText :: DataPart -> Text
- data HumanReadablePart
- data HumanReadablePartError
- humanReadablePartFromText :: Text -> Either HumanReadablePartError HumanReadablePart
- humanReadablePartToText :: HumanReadablePart -> Text
Encoding & Decoding
encode :: HumanReadablePart -> DataPart -> Either EncodingError Text Source #
Encode a human-readable string and data payload into a Bech32 string.
encodeLenient :: HumanReadablePart -> DataPart -> Text Source #
Like encode
but allows output to be longer than 90 characters. This isn't
ideal as the error detection becomes worse as string get longer but it's
still acceptable.
From BIP-0173:
Even though the chosen code performs reasonably well up to 1023 characters, other designs are preferable for lengths above 89 characters (excluding the separator).
data EncodingError Source #
Represents the set of error conditions that may occur while encoding a Bech32 string.
Instances
Eq EncodingError Source # | |
Defined in Codec.Binary.Bech32.Internal (==) :: EncodingError -> EncodingError -> Bool # (/=) :: EncodingError -> EncodingError -> Bool # | |
Show EncodingError Source # | |
Defined in Codec.Binary.Bech32.Internal showsPrec :: Int -> EncodingError -> ShowS # show :: EncodingError -> String # showList :: [EncodingError] -> ShowS # |
decode :: Text -> Either DecodingError (HumanReadablePart, DataPart) Source #
Decode a Bech32 string into a human-readable part and data part.
decodeLenient :: Text -> Either DecodingError (HumanReadablePart, DataPart) Source #
Like decode
but does not enforce a maximum length. See also
encodeLenient
for details.
data DecodingError Source #
Represents the set of errors that may occur while decoding a Bech32
string with the decode
function.
StringToDecodeTooLong | |
StringToDecodeTooShort | |
StringToDecodeHasMixedCase | |
StringToDecodeMissingSeparatorChar | |
StringToDecodeContainsInvalidChars [CharPosition] | In cases where it is possible to determine the exact locations of erroneous characters, this list will encode those locations. Clients can use this information to provide user feedback. In cases where it isn't possible to reliably determine the locations of erroneous characters, this list will be empty. |
Instances
Eq DecodingError Source # | |
Defined in Codec.Binary.Bech32.Internal (==) :: DecodingError -> DecodingError -> Bool # (/=) :: DecodingError -> DecodingError -> Bool # | |
Show DecodingError Source # | |
Defined in Codec.Binary.Bech32.Internal showsPrec :: Int -> DecodingError -> ShowS # show :: DecodingError -> String # showList :: [DecodingError] -> ShowS # |
Data Part
Represents the data part of a Bech32 string, as defined here: https://git.io/fj8FS
dataPartFromBytes :: ByteString -> DataPart Source #
Constructs a DataPart
from a ByteString
.
This function encodes a ByteString
in such a way that guarantees it can be
successfully decoded with the dataPartToBytes
function:
dataPartToBytes (dataPartFromBytes b) == Just b
dataPartFromText :: Text -> Maybe DataPart Source #
Constructs a DataPart
from textual input. All characters in the input
must be a member of dataCharList
, the set of characters permitted to
appear within the data part of a Bech32 string.
Returns Nothing
if any character in the input is not a member of
dataCharList
.
This function guarantees to satisfy the following property:
dataPartFromText (dataPartToText d) == Just d
dataPartToBytes :: DataPart -> Maybe ByteString Source #
Attempts to extract a ByteString
from a DataPart
.
This function guarantees to satisfy the following property:
dataPartToBytes (dataPartFromBytes b) == Just b
dataPartToText :: DataPart -> Text Source #
Human-Readable Part
data HumanReadablePart Source #
Represents the human-readable part of a Bech32 string, as defined here: https://git.io/fj8FS
Instances
Eq HumanReadablePart Source # | |
Defined in Codec.Binary.Bech32.Internal (==) :: HumanReadablePart -> HumanReadablePart -> Bool # (/=) :: HumanReadablePart -> HumanReadablePart -> Bool # | |
Show HumanReadablePart Source # | |
Defined in Codec.Binary.Bech32.Internal showsPrec :: Int -> HumanReadablePart -> ShowS # show :: HumanReadablePart -> String # showList :: [HumanReadablePart] -> ShowS # | |
Semigroup HumanReadablePart Source # | |
Defined in Codec.Binary.Bech32.Internal (<>) :: HumanReadablePart -> HumanReadablePart -> HumanReadablePart # sconcat :: NonEmpty HumanReadablePart -> HumanReadablePart # stimes :: Integral b => b -> HumanReadablePart -> HumanReadablePart # | |
Monoid HumanReadablePart Source # | |
Defined in Codec.Binary.Bech32.Internal |
data HumanReadablePartError Source #
Represents the set of error conditions that may occur while parsing the human-readable part of a Bech32 string.
HumanReadablePartTooShort | |
HumanReadablePartTooLong | |
HumanReadablePartContainsInvalidChars [CharPosition] |
Instances
Eq HumanReadablePartError Source # | |
Defined in Codec.Binary.Bech32.Internal | |
Show HumanReadablePartError Source # | |
Defined in Codec.Binary.Bech32.Internal showsPrec :: Int -> HumanReadablePartError -> ShowS # show :: HumanReadablePartError -> String # showList :: [HumanReadablePartError] -> ShowS # |
humanReadablePartFromText :: Text -> Either HumanReadablePartError HumanReadablePart Source #
Parses the human-readable part of a Bech32 string, as defined here: https://git.io/fj8FS
humanReadablePartToText :: HumanReadablePart -> Text Source #
Get the raw text of the human-readable part of a Bech32 string.