multibase-0.1.1: Self-identifying base encodings, implementation of <https://github.com/multiformats/multihash>

Copyright2019 Monadic GmbH
LicenseBSD3
Maintainerkim@monadic.xyz, alfredo@monadic.xyz, team@monadic.xyz
Stabilityprovisional
Portabilitynon-portable (GHC extensions)
Safe HaskellNone
LanguageHaskell2010

Data.ByteString.BaseN

Contents

Description

Type-safe kitchen sink base-N encoding and decoding of strict ByteStrings.

Synopsis

Documentation

data Base (a :: Symbol) where Source #

Supported bases.

Constructors

BaseIdentity :: Base "id" 
Base2 :: Base "2" 
Base16 :: Base "16" 
Base64 :: Base "64" 
Base16upper :: Base "16u"

hexadecimal, uppercase alphabet

Base32hex :: Base "32x"

RFC4648 no padding - highest char

Base32hexupper :: Base "32xu"

RFC4648 no padding - highest char, uppercase alphabet

Base32hexpad :: Base "32xp"

RFC4648 with padding

Base32hexpadupper :: Base "32xpu"

RFC4648 with padding, uppercase alphabet

Base32 :: Base "32"

RFC4648 no padding

Base32z :: Base "32z"

z-base-32 (used by Tahoe-LAFS)

Base32upper :: Base "32u"

RFC4648 no padding, uppercase alphabet

Base32pad :: Base "32p"

RFC4648 with padding

Base32padupper :: Base "32pu"

RFC4648 with padding, uppercase alphabet

Base58flickr :: Base "58flickr"

base58 flickr alphabet

Base58btc :: Base "58btc"

base58 bitcoint alphabet

Base64pad :: Base "64p"

RFC4648 with padding (MIME-encoding)

Base64url :: Base "64url"

RFC4648 no padding

Base64urlpad :: Base "64urlp"

RFC4648 with padding

data AtBase (b :: Symbol) Source #

A ByteString encoded at a specific base.

Instances
Eq (AtBase b) Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

(==) :: AtBase b -> AtBase b -> Bool #

(/=) :: AtBase b -> AtBase b -> Bool #

Ord (AtBase b) Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

compare :: AtBase b -> AtBase b -> Ordering #

(<) :: AtBase b -> AtBase b -> Bool #

(<=) :: AtBase b -> AtBase b -> Bool #

(>) :: AtBase b -> AtBase b -> Bool #

(>=) :: AtBase b -> AtBase b -> Bool #

max :: AtBase b -> AtBase b -> AtBase b #

min :: AtBase b -> AtBase b -> AtBase b #

KnownSymbol b => Show (AtBase b) Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

showsPrec :: Int -> AtBase b -> ShowS #

show :: AtBase b -> String #

showList :: [AtBase b] -> ShowS #

ValidBase b => IsString (AtBase b) Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

fromString :: String -> AtBase b #

Hashable (AtBase b) Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

hashWithSalt :: Int -> AtBase b -> Int #

hash :: AtBase b -> Int #

ToJSON (AtBase b) Source # 
Instance details

Defined in Data.ByteString.BaseN

ToJSONKey (AtBase b) Source # 
Instance details

Defined in Data.ByteString.BaseN

(ValidBase b, KnownSymbol b) => FromJSON (AtBase b) Source # 
Instance details

Defined in Data.ByteString.BaseN

(ValidBase b, KnownSymbol b) => FromJSONKey (AtBase b) Source # 
Instance details

Defined in Data.ByteString.BaseN

NFData (AtBase b) Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

rnf :: AtBase b -> () #

encodedBytes :: AtBase b -> ByteString Source #

Extract the base-n encoded bytes from an AtBase.

To recover the original ByteString (*not* base-n encoded), use decode.

type Base2 = AtBase "2" Source #

type Base16 = AtBase "16" Source #

type Base58 = AtBase "58" Source #

type Base64 = AtBase "64" Source #

type Base16upper = AtBase "16u" Source #

type Base32hex = AtBase "16x" Source #

type Base32hexpad = AtBase "16xp" Source #

type Base32 = AtBase "32" Source #

type Base32z = AtBase "32z" Source #

type Base32upper = AtBase "32u" Source #

type Base32pad = AtBase "32p" Source #

type Base58flickr = AtBase "58flickr" Source #

type Base58btc = AtBase "58btc" Source #

type Base64pad = AtBase "64p" Source #

type Base64url = AtBase "64url" Source #

type Base64urlpad = AtBase "16urlp" Source #

Compact Representation

data AtBaseCompact (b :: Symbol) Source #

A more memory-efficient representation of base-n encoded bytes.

Uses ShortByteString, recommendations and caveats described there apply.

Tagged

AtBase values tagged by the type they're representing.

type Base16Of a = Tagged a (AtBase "16") Source #

type Base58Of a = Tagged a (AtBase "58") Source #

type Base64Of a = Tagged a (AtBase "64") Source #

Re-exports

tagWith :: proxy s -> a -> Tagged s a #

Another way to convert a proxy to a tag.

unTagged :: Tagged s b -> b #

CBOR

Directly go from (presumed to be) base-n encoded ByteString to de-Serialise-able value.

Encoding

 

encodeBase58btc :: ByteString -> AtBase "58btc" Source #

>>> fromAtBase . encodeBase58btc $ "hello world"
"StV1DL6CwTryKyV"

encodeAtBase :: Base b -> ByteString -> AtBase b Source #

Encode at a base supplied at runtime.

Decoding Bytes

Decode (presumed to be) base-n encoded ByteStrings to their original (base-2) value.

class DecodeBase (b :: Symbol) Source #

Minimal complete definition

decodeAtBase, decodeAtBaseEither

Instances
DecodeBase "16" Source # 
Instance details

Defined in Data.ByteString.BaseN

DecodeBase "16u" Source # 
Instance details

Defined in Data.ByteString.BaseN

DecodeBase "2" Source # 
Instance details

Defined in Data.ByteString.BaseN

DecodeBase "32" Source # 
Instance details

Defined in Data.ByteString.BaseN

DecodeBase "32p" Source # 
Instance details

Defined in Data.ByteString.BaseN

DecodeBase "32pu" Source # 
Instance details

Defined in Data.ByteString.BaseN

DecodeBase "32u" Source # 
Instance details

Defined in Data.ByteString.BaseN

DecodeBase "32x" Source # 
Instance details

Defined in Data.ByteString.BaseN

DecodeBase "32xp" Source # 
Instance details

Defined in Data.ByteString.BaseN

DecodeBase "32xpu" Source # 
Instance details

Defined in Data.ByteString.BaseN

DecodeBase "32xu" Source # 
Instance details

Defined in Data.ByteString.BaseN

DecodeBase "32z" Source # 
Instance details

Defined in Data.ByteString.BaseN

DecodeBase "58btc" Source # 
Instance details

Defined in Data.ByteString.BaseN

DecodeBase "58flickr" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

decodeAtBase :: proxy "58flickr" -> ByteString -> Maybe ByteString Source #

decodeAtBaseEither :: proxy "58flickr" -> ByteString -> Either String ByteString Source #

DecodeBase "64" Source # 
Instance details

Defined in Data.ByteString.BaseN

DecodeBase "64p" Source # 
Instance details

Defined in Data.ByteString.BaseN

DecodeBase "64url" Source # 
Instance details

Defined in Data.ByteString.BaseN

DecodeBase "64urlpad" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

decodeAtBase :: proxy "64urlpad" -> ByteString -> Maybe ByteString Source #

decodeAtBaseEither :: proxy "64urlpad" -> ByteString -> Either String ByteString Source #

DecodeBase "id" Source # 
Instance details

Defined in Data.ByteString.BaseN

decodeBase58btc :: ByteString -> Either String ByteString Source #

\(Bytes bytes) -> decodeBase58btc (fromAtBase $ encodeBase58btc bytes) === Right bytes

Decoding

decode :: DecodeBase b => AtBase b -> ByteString Source #

Recover the original ByteString of a base-n encoded value.

Untrusted Input

Construct AtBases from raw ByteStrings. Note that this attempts to decode using the functions from $decoding, and throws away the result.

class KnownSymbol b => ValidBase (b :: Symbol) Source #

Minimal complete definition

validAtBase, validAtBaseEither

Instances
ValidBase "16" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

validAtBase :: proxy "16" -> ByteString -> Maybe (AtBase "16") Source #

validAtBaseEither :: proxy "16" -> ByteString -> Either String (AtBase "16") Source #

ValidBase "16u" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

validAtBase :: proxy "16u" -> ByteString -> Maybe (AtBase "16u") Source #

validAtBaseEither :: proxy "16u" -> ByteString -> Either String (AtBase "16u") Source #

ValidBase "2" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

validAtBase :: proxy "2" -> ByteString -> Maybe (AtBase "2") Source #

validAtBaseEither :: proxy "2" -> ByteString -> Either String (AtBase "2") Source #

ValidBase "32" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

validAtBase :: proxy "32" -> ByteString -> Maybe (AtBase "32") Source #

validAtBaseEither :: proxy "32" -> ByteString -> Either String (AtBase "32") Source #

ValidBase "32p" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

validAtBase :: proxy "32p" -> ByteString -> Maybe (AtBase "32p") Source #

validAtBaseEither :: proxy "32p" -> ByteString -> Either String (AtBase "32p") Source #

ValidBase "32pu" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

validAtBase :: proxy "32pu" -> ByteString -> Maybe (AtBase "32pu") Source #

validAtBaseEither :: proxy "32pu" -> ByteString -> Either String (AtBase "32pu") Source #

ValidBase "32u" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

validAtBase :: proxy "32u" -> ByteString -> Maybe (AtBase "32u") Source #

validAtBaseEither :: proxy "32u" -> ByteString -> Either String (AtBase "32u") Source #

ValidBase "32x" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

validAtBase :: proxy "32x" -> ByteString -> Maybe (AtBase "32x") Source #

validAtBaseEither :: proxy "32x" -> ByteString -> Either String (AtBase "32x") Source #

ValidBase "32xp" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

validAtBase :: proxy "32xp" -> ByteString -> Maybe (AtBase "32xp") Source #

validAtBaseEither :: proxy "32xp" -> ByteString -> Either String (AtBase "32xp") Source #

ValidBase "32xpu" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

validAtBase :: proxy "32xpu" -> ByteString -> Maybe (AtBase "32xpu") Source #

validAtBaseEither :: proxy "32xpu" -> ByteString -> Either String (AtBase "32xpu") Source #

ValidBase "32xu" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

validAtBase :: proxy "32xu" -> ByteString -> Maybe (AtBase "32xu") Source #

validAtBaseEither :: proxy "32xu" -> ByteString -> Either String (AtBase "32xu") Source #

ValidBase "32z" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

validAtBase :: proxy "32z" -> ByteString -> Maybe (AtBase "32z") Source #

validAtBaseEither :: proxy "32z" -> ByteString -> Either String (AtBase "32z") Source #

ValidBase "58btc" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

validAtBase :: proxy "58btc" -> ByteString -> Maybe (AtBase "58btc") Source #

validAtBaseEither :: proxy "58btc" -> ByteString -> Either String (AtBase "58btc") Source #

ValidBase "58flickr" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

validAtBase :: proxy "58flickr" -> ByteString -> Maybe (AtBase "58flickr") Source #

validAtBaseEither :: proxy "58flickr" -> ByteString -> Either String (AtBase "58flickr") Source #

ValidBase "64" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

validAtBase :: proxy "64" -> ByteString -> Maybe (AtBase "64") Source #

validAtBaseEither :: proxy "64" -> ByteString -> Either String (AtBase "64") Source #

ValidBase "64p" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

validAtBase :: proxy "64p" -> ByteString -> Maybe (AtBase "64p") Source #

validAtBaseEither :: proxy "64p" -> ByteString -> Either String (AtBase "64p") Source #

ValidBase "64url" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

validAtBase :: proxy "64url" -> ByteString -> Maybe (AtBase "64url") Source #

validAtBaseEither :: proxy "64url" -> ByteString -> Either String (AtBase "64url") Source #

ValidBase "64urlpad" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

validAtBase :: proxy "64urlpad" -> ByteString -> Maybe (AtBase "64urlpad") Source #

validAtBaseEither :: proxy "64urlpad" -> ByteString -> Either String (AtBase "64urlpad") Source #

ValidBase "id" Source # 
Instance details

Defined in Data.ByteString.BaseN

Methods

validAtBase :: proxy "id" -> ByteString -> Maybe (AtBase "id") Source #

validAtBaseEither :: proxy "id" -> ByteString -> Either String (AtBase "id") Source #

validAtBase :: ValidBase b => proxy b -> ByteString -> Maybe (AtBase b) Source #

validAndDecoded :: DecodeBase b => proxy b -> ByteString -> Maybe (AtBase b, ByteString) Source #

Like validAtBase, but also return the decoded ByteString.

validAndDecodedEither :: DecodeBase b => proxy b -> ByteString -> Either String (AtBase b, ByteString) Source #

Like validAtBaseEither, but also return the decoded ByteString.

Text

encodedTextAtBase :: Base b -> Text -> AtBase b Source #

Like encodeAtBase, but from a Text value.

encodedText :: AtBase b -> Text Source #

Like encodedBytes, but returns a Text value.

Formatting

format :: Format r (AtBase b -> r) Source #

Format a base-n encoded value.

formatAtBase :: Format r (AtBase b -> r) Source #

Format a base-n encoded value.