CIP-0067 support.
CIP-0067 describes a standard format for assets so that their purpose can be deduced solely by their token names. So far, the primary application of this standard is to easily distinguish between CIP-0068 assets and their reference counterparts.
Phantom type for CIP-0067 asset names with the label prefix removed.
Validate and separate the label of a CIP-0067 asset name.
Given a valid CIP-0067 token name [Bytes], this function separates the label as an [Int], and returns the asset name without the label bytes.
Extract the label if it is valid. Return Nothing otherwise.
CBOR decoder for [Cip67].
Convert an Int label into its CIP-0067 hex string.
CBOR encoder.
Datatype for modeling CIP-0067.
This standard offers a label number preceding the actual token name, which can be from
0
to65535
(i.e. 2 bytes, and left-padded with00
for numbers smaller than 2 bytes). This label should be formatted as such:-- openning bracket closing bracket -- ┌──┐ ┌──┐ -- [ 0000 | 16 bits label_num | 8 bits checksum | 0000 ] -- └───────────────┘ └───────┬─────┘ -- fixed 2 bytes for the label │ -- │ -- label's checksum found by applying the CRC-8 algorithm to its 2 bytes
The polynomial representation of the CRC-8 is
0x07
(0b00000111
).As an example, a label of
222
turn into:0x000de140
222
is0xde
0x00
to the left and get0x00de
0x14
)0x000de140
Finally, a complete CIP-0067 example:
spacebudz2921 : Maybe Cip67 spacebudz2921 = Maybe.andThen Cip67.fromBytes <| Bytes.fromHex "000de14042756432393231" -- Just { assetName = Bytes "42756432393231", label = 222 }