cometa-0.1.0.0: Idiomatic Haskell bindings to cardano-c
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cometa.AssetName

Description

Validated native-asset names, containing zero through 32 arbitrary bytes. Names identify assets by bytes; UTF-8 is an optional interpretation.

import qualified Cometa.AssetName as AssetName

roundTrip :: AssetName.AssetName -> Bool
roundTrip name = AssetName.fromBytes (AssetName.toBytes name) == Right name
Synopsis

Documentation

data AssetName Source #

Zero through 32 bytes. Equality and ordering compare exact bytes lexicographically. Show is diagnostic output.

Instances

Instances details
Show AssetName Source # 
Instance details

Defined in Cometa.AssetName

Eq AssetName Source # 
Instance details

Defined in Cometa.AssetName

Ord AssetName Source # 
Instance details

Defined in Cometa.AssetName

empty :: AssetName Source #

The empty native-asset name, distinct from the Ada asset.

fromBytes :: ByteString -> Either Error AssetName Source #

Import arbitrary bytes, including NUL and invalid UTF-8. More than 32 bytes returns InvalidAssetNameLength with the actual byte count.

toBytes :: AssetName -> ByteString Source #

Exact name bytes.

fromHex :: Text -> Either Error AssetName Source #

Import zero through 64 ASCII hexadecimal digits, accepting either case. Odd lengths, prefixes, whitespace and nonhexadecimal characters return InvalidHex; decoded names longer than 32 bytes return InvalidAssetNameLength.

toHex :: AssetName -> Text Source #

Lowercase hexadecimal without a prefix. The empty name renders as empty text.

fromText :: Text -> Either Error AssetName Source #

Encode text as UTF-8, then validate the 32-byte bound. The limit counts encoded bytes, not characters. No Unicode normalization is performed.

toText :: AssetName -> Maybe Text Source #

Interpret exact bytes as UTF-8. Invalid UTF-8 returns Nothing; no bytes are replaced or discarded. An empty name returns Just "".

encodeCbor :: AssetName -> ByteString Source #

Encode the exact name bytes as a shortest-length definite CBOR byte string.

decodeCbor :: ByteString -> Either Error AssetName Source #

Decode exactly one CBOR byte string containing 0 through 32 bytes. Nonminimal length encodings are accepted; invalid schemas, lengths or trailing bytes return InvalidAssetNameCbor. Fresh encoding is semantic and does not retain the original CBOR representation.