| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
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
Documentation
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. |
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.