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

Cometa.AssetId

Description

Ada and native assets with validated policy and name components.

import qualified Cometa.AssetId as AssetId
import qualified Cometa.AssetName as AssetName
import qualified Cometa.PolicyId as PolicyId

unnamedToken :: PolicyId.PolicyId -> AssetId.AssetId
unnamedToken policy = AssetId.Native policy AssetName.empty
Synopsis

Documentation

data AssetId Source #

An asset's identity. Ordering places Ada first, then compares native policy bytes and name bytes lexicographically. Show is diagnostic output.

Constructors

Ada

Ada; its quantity is measured in lovelace (one millionth of an Ada).

Native !PolicyId !AssetName

A native asset, identified by policy and exact name bytes. An empty name under a policy is a native asset, distinct from Ada.

Instances

Instances details
Show AssetId Source # 
Instance details

Defined in Cometa.AssetId

Eq AssetId Source # 
Instance details

Defined in Cometa.AssetId

Methods

(==) :: AssetId -> AssetId -> Bool #

(/=) :: AssetId -> AssetId -> Bool #

Ord AssetId Source # 
Instance details

Defined in Cometa.AssetId

fromBytes :: ByteString -> Either Error AssetId Source #

Import a native asset as its 28-byte policy followed by zero through 32 exact name bytes. Other lengths, including empty input, return InvalidAssetIdLength. Ada has no encoding in this format.

toBytes :: AssetId -> Either Error ByteString Source #

Export the policy bytes followed by the exact name bytes. Ada returns UnsupportedOperation; an empty native name still exports 28 policy bytes.

fromHex :: Text -> Either Error AssetId Source #

Import 56 through 120 ASCII hexadecimal digits as a native asset. Either case is accepted, without a prefix or whitespace. Malformed hex returns InvalidHex; other decoded lengths return InvalidAssetIdLength. Empty text does not represent Ada.

toHex :: AssetId -> Either Error Text Source #

Export the native asset as lowercase hexadecimal policy and name bytes, without a separator. Ada returns UnsupportedOperation.

fingerprint :: AssetId -> IO (Either Error Text) Source #

Compute the CIP-14 user-facing native asset fingerprint: BLAKE2b-160 of the policy followed by the exact name bytes, encoded as Bech32 with the asset prefix. Ada returns UnsupportedOperation. Hashing failures return the corresponding NativeError.

The fingerprint is a display checksum. It cannot be decoded back to the policy and name, and does not replace the full asset identity or prove authenticity.