-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Implementation of the Bech32 cryptocurrency address format (BIP 0173). -- -- Implementation of the Bech32 cryptocurrency address format documented -- in the BIP (Bitcoin Improvement Proposal) 0173. @package bech32 @version 1.0.2 -- | Implementation of the Bech32 address format. -- -- From an original implementation by Marko Bencun: -- -- sipa/bech32 module Codec.Binary.Bech32.Internal -- | Encode a Bech32 string from a human-readable prefix and data payload. -- --

Example

-- --
--   >>> import Prelude
--   
--   >>> import Codec.Binary.Bech32
--   
--   >>> import Data.Text.Encoding
--   
-- -- First, prepare a human-readable prefix: -- --
--   >>> Right prefix = humanReadablePartFromText "example"
--   
-- -- Next, prepare a data payload: -- --
--   >>> messageToEncode = "Lorem ipsum dolor sit amet!"
--   
--   >>> dataPart = dataPartFromBytes $ encodeUtf8 messageToEncode
--   
-- -- Finally, produce a Bech32 string: -- --
--   >>> encode prefix dataPart
--   Right "example1f3hhyetdyp5hqum4d5sxgmmvdaezqumfwssxzmt9wsss9un3cx"
--   
encode :: HumanReadablePart -> DataPart -> Either EncodingError Text -- | Like encode but allows output to be longer than 90 characters. -- -- This isn't ideal, as Bech32 error detection becomes worse as strings -- get longer, but it may be useful in certain circumstances. -- -- 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)." encodeLenient :: HumanReadablePart -> DataPart -> Text -- | Represents the set of error conditions that may occur while encoding a -- Bech32 string. data EncodingError -- | The resultant encoded string would be longer than -- encodedStringMaxLength. EncodedStringTooLong :: EncodingError -- | Decode a Bech32 string into a human-readable prefix and data payload. -- --

Example

-- --
--   >>> import Prelude
--   
--   >>> import Codec.Binary.Bech32
--   
--   >>> import Data.Text.Encoding
--   
-- -- First, decode the input: -- --
--   >>> input = "example1f3hhyetdyp5hqum4d5sxgmmvdaezqumfwssxzmt9wsss9un3cx"
--   
--   >>> Right (prefix, dataPart) = decode input
--   
-- -- Next, examine the decoded human-readable prefix: -- --
--   >>> humanReadablePartToText prefix
--   "example"
--   
-- -- Finally, examine the decoded data payload: -- --
--   >>> decodeUtf8 <$> dataPartToBytes dataPart
--   Just "Lorem ipsum dolor sit amet!"
--   
decode :: Text -> Either DecodingError (HumanReadablePart, DataPart) -- | Like decode but does not enforce a maximum length. -- -- See also encodeLenient for details. decodeLenient :: Text -> Either DecodingError (HumanReadablePart, DataPart) -- | Represents the set of errors that may occur while decoding a Bech32 -- string with the decode function. data DecodingError -- | The string to decode is longer than -- encodedStringMaxLength. StringToDecodeTooLong :: DecodingError -- | The string to decode is shorter than -- encodedStringMinLength. StringToDecodeTooShort :: DecodingError -- | The string to decode contains both upper case and lower -- case characters. StringToDecodeHasMixedCase :: DecodingError -- | The string to decode is missing the separator character, -- specified by separatorChar. StringToDecodeMissingSeparatorChar :: DecodingError -- | The string to decode contains one or more invalid characters. -- -- 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. StringToDecodeContainsInvalidChars :: [CharPosition] -> DecodingError -- | The length of the checksum portion of an encoded string, in bytes. checksumLength :: Int -- | The maximum length of an encoded string, in bytes. -- -- This length includes the human-readable part, the separator character, -- the encoded data portion, and the checksum. encodedStringMaxLength :: Int -- | The minimum length of an encoded string, in bytes. -- -- This length includes the human-readable part, the separator character, -- the encoded data portion, and the checksum. encodedStringMinLength :: Int -- | The separator character. -- -- This character appears immediately after the human-readable part and -- before the data part in an encoded string. separatorChar :: Char -- | The length of the separator portion of an encoded string, in bytes. separatorLength :: Int -- | Represents the data part of a Bech32 string, as defined here: -- https://git.io/fj8FS data DataPart -- | Returns true iff. the specified DataPart is valid. dataPartIsValid :: DataPart -> Bool -- | 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
--   
dataPartFromBytes :: ByteString -> DataPart -- | 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
--   
dataPartFromText :: Text -> Maybe DataPart -- | Construct a DataPart directly from a list of words. -- -- This function guarantees to satisfy the following properties: -- --
--   dataPartFromWords (dataPartToWords d) == d
--   dataPartToWords (dataPartFromWords w) == w
--   
dataPartFromWords :: [Word5] -> DataPart -- | Attempts to extract a ByteString from a DataPart. -- -- This function guarantees to satisfy the following property: -- --
--   dataPartToBytes (dataPartFromBytes b) == Just b
--   
dataPartToBytes :: DataPart -> Maybe ByteString -- | Converts a DataPart to Text, using the Bech32 character -- set to render the data. -- -- This function guarantees to satisfy the following property: -- --
--   dataPartFromText (dataPartToText d) == Just d
--   
dataPartToText :: DataPart -> Text -- | Unpack a DataPart into a list of its constituent words. -- -- This function guarantees to satisfy the following properties: -- --
--   dataPartFromWords (dataPartToWords d) == d
--   dataPartToWords (dataPartFromWords w) == w
--   
dataPartToWords :: DataPart -> [Word5] -- | If the specified character is permitted to appear within the data part -- of a Bech32 string, this function returns that character's -- corresponding Word5 value. If the specified character is not -- permitted, or if the specified character is upper-case, returns -- Nothing. dataCharToWord :: Char -> Maybe Word5 -- | Maps the specified Word5 onto a character that is permitted to -- appear within the data part of a Bech32 string. dataCharFromWord :: Word5 -> Char -- | A list of all characters that are permitted to appear within the data -- part of a Bech32 string. -- -- See here for more details: https://git.io/fj8FS dataCharList :: String -- | Represents the human-readable part of a Bech32 string, as defined -- here: https://git.io/fj8FS data HumanReadablePart -- | Represents the set of error conditions that may occur while parsing -- the human-readable part of a Bech32 string. data HumanReadablePartError -- | The human-readable part is shorter than -- humanReadablePartMinLength. HumanReadablePartTooShort :: HumanReadablePartError -- | The human-readable part is longer than -- humanReadablePartMaxLength. HumanReadablePartTooLong :: HumanReadablePartError -- | The human-readable part contains one or more characters whose values -- are less than humanReadableCharMinBound or greater -- than humanReadableCharMaxBound. HumanReadablePartContainsInvalidChars :: [CharPosition] -> HumanReadablePartError -- | Parses the human-readable part of a Bech32 string, as defined here: -- https://git.io/fj8FS humanReadablePartFromText :: Text -> Either HumanReadablePartError HumanReadablePart -- | Get the raw text of the human-readable part of a Bech32 string. humanReadablePartToText :: HumanReadablePart -> Text -- | Convert the specified human-readable part to a list of words. humanReadablePartToWords :: HumanReadablePart -> [Word5] -- | The shortest length permitted for the human-readable part of a Bech32 -- string. humanReadablePartMinLength :: Int -- | The longest length permitted for the human-readable part of a Bech32 -- string. humanReadablePartMaxLength :: Int -- | Returns true iff. the specified character is permitted to appear -- within the human-readable part of a Bech32 string. humanReadableCharIsValid :: Char -> Bool -- | The lower bound of the set of characters permitted to appear within -- the human-readable part of a Bech32 string. humanReadableCharMinBound :: Char -- | The upper bound of the set of characters permitted to appear within -- the human-readable part of a Bech32 string. humanReadableCharMaxBound :: Char -- | Big-endian conversion of a word string from base '2^frombits' to base -- '2^tobits'. The frombits and twobits parameters must -- be positive, while '2^frombits' and '2^tobits' must be smaller than -- the size of Word. Every value in dat must be strictly -- smaller than '2^frombits'. convertBits :: Functor f => [Word] -> Int -> Int -> Pad f -> f [Word] -- | Represents a data word of 5 bits in width. -- -- Each character in the data portion of a Bech32 string encodes exactly -- 5 bits of data. -- --

Construction and Deconstruction

-- -- Use the toEnum and fromEnum functions to construct and -- deconstruct Word5 values. -- --

Packing Words into Data Payloads

-- -- Use the dataPartFromWords and dataPartToWords functions -- to pack and unpack Word5 values into and out of data payloads. data Word5 word5 :: Integral a => a -> Word5 getWord5 :: Word5 -> Word8 toBase256 :: [Word5] -> Maybe [Word8] toBase32 :: [Word8] -> [Word5] noPadding :: Pad Maybe yesPadding :: Pad Identity -- | The zero-based position of a character in a string, counting from the -- left. -- -- Values of this type are typically used to reflect the positions of -- errors. -- -- See DecodingError. newtype CharPosition CharPosition :: Int -> CharPosition instance GHC.Show.Show Codec.Binary.Bech32.Internal.Word5 instance GHC.Classes.Ord Codec.Binary.Bech32.Internal.Word5 instance GHC.Classes.Eq Codec.Binary.Bech32.Internal.Word5 instance GHC.Show.Show Codec.Binary.Bech32.Internal.HumanReadablePartError instance GHC.Classes.Eq Codec.Binary.Bech32.Internal.HumanReadablePartError instance GHC.Show.Show Codec.Binary.Bech32.Internal.DecodingError instance GHC.Classes.Eq Codec.Binary.Bech32.Internal.DecodingError instance GHC.Show.Show Codec.Binary.Bech32.Internal.CharPosition instance GHC.Classes.Ord Codec.Binary.Bech32.Internal.CharPosition instance GHC.Classes.Eq Codec.Binary.Bech32.Internal.CharPosition instance GHC.Show.Show Codec.Binary.Bech32.Internal.EncodingError instance GHC.Classes.Eq Codec.Binary.Bech32.Internal.EncodingError instance GHC.Show.Show Codec.Binary.Bech32.Internal.HumanReadablePart instance GHC.Base.Semigroup Codec.Binary.Bech32.Internal.HumanReadablePart instance GHC.Base.Monoid Codec.Binary.Bech32.Internal.HumanReadablePart instance GHC.Classes.Eq Codec.Binary.Bech32.Internal.HumanReadablePart instance GHC.Show.Show Codec.Binary.Bech32.Internal.DataPart instance GHC.Base.Semigroup Codec.Binary.Bech32.Internal.DataPart instance GHC.Base.Monoid Codec.Binary.Bech32.Internal.DataPart instance GHC.Classes.Eq Codec.Binary.Bech32.Internal.DataPart instance GHC.Enum.Bounded Codec.Binary.Bech32.Internal.Word5 instance GHC.Enum.Enum Codec.Binary.Bech32.Internal.Word5 instance GHC.Arr.Ix Codec.Binary.Bech32.Internal.Word5 instance GHC.Exception.Type.Exception Codec.Binary.Bech32.Internal.HumanReadablePartError -- | Implementation of the Bech32 address format. -- -- Based on an original implementation by Marko Bencun. module Codec.Binary.Bech32 -- | Encode a Bech32 string from a human-readable prefix and data payload. -- --

Example

-- --
--   >>> import Prelude
--   
--   >>> import Codec.Binary.Bech32
--   
--   >>> import Data.Text.Encoding
--   
-- -- First, prepare a human-readable prefix: -- --
--   >>> Right prefix = humanReadablePartFromText "example"
--   
-- -- Next, prepare a data payload: -- --
--   >>> messageToEncode = "Lorem ipsum dolor sit amet!"
--   
--   >>> dataPart = dataPartFromBytes $ encodeUtf8 messageToEncode
--   
-- -- Finally, produce a Bech32 string: -- --
--   >>> encode prefix dataPart
--   Right "example1f3hhyetdyp5hqum4d5sxgmmvdaezqumfwssxzmt9wsss9un3cx"
--   
encode :: HumanReadablePart -> DataPart -> Either EncodingError Text -- | Decode a Bech32 string into a human-readable prefix and data payload. -- --

Example

-- --
--   >>> import Prelude
--   
--   >>> import Codec.Binary.Bech32
--   
--   >>> import Data.Text.Encoding
--   
-- -- First, decode the input: -- --
--   >>> input = "example1f3hhyetdyp5hqum4d5sxgmmvdaezqumfwssxzmt9wsss9un3cx"
--   
--   >>> Right (prefix, dataPart) = decode input
--   
-- -- Next, examine the decoded human-readable prefix: -- --
--   >>> humanReadablePartToText prefix
--   "example"
--   
-- -- Finally, examine the decoded data payload: -- --
--   >>> decodeUtf8 <$> dataPartToBytes dataPart
--   Just "Lorem ipsum dolor sit amet!"
--   
decode :: Text -> Either DecodingError (HumanReadablePart, DataPart) -- | Represents the set of error conditions that may occur while encoding a -- Bech32 string. data EncodingError -- | The resultant encoded string would be longer than -- encodedStringMaxLength. EncodedStringTooLong :: EncodingError -- | Represents the set of errors that may occur while decoding a Bech32 -- string with the decode function. data DecodingError -- | The string to decode is longer than -- encodedStringMaxLength. StringToDecodeTooLong :: DecodingError -- | The string to decode is shorter than -- encodedStringMinLength. StringToDecodeTooShort :: DecodingError -- | The string to decode contains both upper case and lower -- case characters. StringToDecodeHasMixedCase :: DecodingError -- | The string to decode is missing the separator character, -- specified by separatorChar. StringToDecodeMissingSeparatorChar :: DecodingError -- | The string to decode contains one or more invalid characters. -- -- 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. StringToDecodeContainsInvalidChars :: [CharPosition] -> DecodingError -- | Represents the data part of a Bech32 string, as defined here: -- https://git.io/fj8FS data DataPart -- | Construct a DataPart directly from a list of words. -- -- This function guarantees to satisfy the following properties: -- --
--   dataPartFromWords (dataPartToWords d) == d
--   dataPartToWords (dataPartFromWords w) == w
--   
dataPartFromWords :: [Word5] -> DataPart -- | Unpack a DataPart into a list of its constituent words. -- -- This function guarantees to satisfy the following properties: -- --
--   dataPartFromWords (dataPartToWords d) == d
--   dataPartToWords (dataPartFromWords w) == w
--   
dataPartToWords :: DataPart -> [Word5] -- | 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
--   
dataPartFromBytes :: ByteString -> DataPart -- | Attempts to extract a ByteString from a DataPart. -- -- This function guarantees to satisfy the following property: -- --
--   dataPartToBytes (dataPartFromBytes b) == Just b
--   
dataPartToBytes :: DataPart -> Maybe ByteString -- | 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
--   
dataPartFromText :: Text -> Maybe DataPart -- | Converts a DataPart to Text, using the Bech32 character -- set to render the data. -- -- This function guarantees to satisfy the following property: -- --
--   dataPartFromText (dataPartToText d) == Just d
--   
dataPartToText :: DataPart -> Text -- | Represents the human-readable part of a Bech32 string, as defined -- here: https://git.io/fj8FS data HumanReadablePart -- | Parses the human-readable part of a Bech32 string, as defined here: -- https://git.io/fj8FS humanReadablePartFromText :: Text -> Either HumanReadablePartError HumanReadablePart -- | Get the raw text of the human-readable part of a Bech32 string. humanReadablePartToText :: HumanReadablePart -> Text -- | Represents the set of error conditions that may occur while parsing -- the human-readable part of a Bech32 string. data HumanReadablePartError -- | The human-readable part is shorter than -- humanReadablePartMinLength. HumanReadablePartTooShort :: HumanReadablePartError -- | The human-readable part is longer than -- humanReadablePartMaxLength. HumanReadablePartTooLong :: HumanReadablePartError -- | The human-readable part contains one or more characters whose values -- are less than humanReadableCharMinBound or greater -- than humanReadableCharMaxBound. HumanReadablePartContainsInvalidChars :: [CharPosition] -> HumanReadablePartError -- | The zero-based position of a character in a string, counting from the -- left. -- -- Values of this type are typically used to reflect the positions of -- errors. -- -- See DecodingError. newtype CharPosition CharPosition :: Int -> CharPosition -- | Represents a data word of 5 bits in width. -- -- Each character in the data portion of a Bech32 string encodes exactly -- 5 bits of data. -- --

Construction and Deconstruction

-- -- Use the toEnum and fromEnum functions to construct and -- deconstruct Word5 values. -- --

Packing Words into Data Payloads

-- -- Use the dataPartFromWords and dataPartToWords functions -- to pack and unpack Word5 values into and out of data payloads. data Word5 -- | Like encode but allows output to be longer than 90 characters. -- -- This isn't ideal, as Bech32 error detection becomes worse as strings -- get longer, but it may be useful in certain circumstances. -- -- 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)." encodeLenient :: HumanReadablePart -> DataPart -> Text -- | Like decode but does not enforce a maximum length. -- -- See also encodeLenient for details. decodeLenient :: Text -> Either DecodingError (HumanReadablePart, DataPart) -- | A list of all characters that are permitted to appear within the data -- part of a Bech32 string. -- -- See here for more details: https://git.io/fj8FS dataCharList :: String -- | The shortest length permitted for the human-readable part of a Bech32 -- string. humanReadablePartMinLength :: Int -- | The longest length permitted for the human-readable part of a Bech32 -- string. humanReadablePartMaxLength :: Int -- | The lower bound of the set of characters permitted to appear within -- the human-readable part of a Bech32 string. humanReadableCharMinBound :: Char -- | The upper bound of the set of characters permitted to appear within -- the human-readable part of a Bech32 string. humanReadableCharMaxBound :: Char -- | The maximum length of an encoded string, in bytes. -- -- This length includes the human-readable part, the separator character, -- the encoded data portion, and the checksum. encodedStringMaxLength :: Int -- | The minimum length of an encoded string, in bytes. -- -- This length includes the human-readable part, the separator character, -- the encoded data portion, and the checksum. encodedStringMinLength :: Int -- | The separator character. -- -- This character appears immediately after the human-readable part and -- before the data part in an encoded string. separatorChar :: Char