Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIP-0025: Added version 2 and cddl #267

Merged
merged 7 commits into from
Jun 28, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 86 additions & 7 deletions CIP-0025/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ This is the registered `transaction_metadatum_label` value
| --------------------------- | ------------ |
| 721 | NFT Metadata |

### Structure
### General structure

The structure allows for multiple token mints, also with different policies, in a single transaction.

Expand All @@ -50,7 +50,7 @@ The structure allows for multiple token mints, also with different policies, in
"name": <string>,

"image": <uri | array>,
"mediaType": "image/<mime_sub_type>",
"mediaType": image/<mime_sub_type>,

"description": <string | array>,

Expand All @@ -64,27 +64,90 @@ The structure allows for multiple token mints, also with different policies, in
<other properties>
}
},
"version": "1.0"
"version": <version_id>
}
}
```

The **`asset_name`** must be `UTF-8` encoded for the key in the metadata map and the actual NFT. This is true for version `1.0`, future versions will use the `hex` encoding for **`asset_name`**.
### CDDL

#### Version 1

```cddl

policy_id = text
asset_name = text ; utf-8

files_details =
{
name: text,
mediaType: text,
src: text / [* text]
}

metadata_details =
{
name : text,
image : text,
? mediaType: text,
? description: text / [* text]
? files: [* files_details]
}

label_metadata = { * policy_id => { * asset_name => metadata_details } }

metadata = { 721 : uint => label_metadata }
```

#### Version 2

```cddl

policy_id = bytes ; no longer in text
asset_name = bytes ; no longer in text and utf-8

files_details =
{
name : text,
mediaType : text,
src : text / [* text]
}

metadata_details =
{
name : text,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to be a little careful with this definition since text here isn't the standard "text" in cbor. Instead, Cardano metadata enforces that all text or byte array has a maximum length. We should probably either define these as a special type that matches the same max length or explicitly allow people to use an array to combine chunks together

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I just fixed it. name should definitely stay below 64 characters. The ones that can exceed 64 characters have the type string / [* string].

image : text,
? mediaType : text,
? description : text / [* text]
? files : [* files_details]
}

label_metadata = { * policy_id => { * asset_name => metadata_details }, version: 2 } ; version 2

metadata = { 721 : uint => label_metadata }
```

In version `1` the **`asset_name`** must be `utf-8` encoded and in text format for the key in the metadata map. In version `2` the the raw bytes of the **`asset_name`** are used.

In version `1` the **`policy_id`** is used in text format for the key in the metadata map. In version `2` the the raw bytes of the **`policy_id`** are used.


The **`image`** and **`name`** property are marked as required. **`image`** should be an URI pointing to a resource with mime type `image/*` used as thumbnail or as actual link if the NFT is an image (ideally <= 1MB).

The **`description`** property is optional.

The **`mediaType`** and **`files`** properties are optional.<br /> **`mediaType`** is however required inside **`files`**. The **`src`** property inside **`files`** is an URI pointing to a resource of this mime type. If the mime type is `image/*`, **`mediaType`** points to the same image, like the on in the **`image`** property, but in an higher resolution.

The **`version`** property is also optional. If not specified the version is `1.0`. It will become mandatory in future versions if needed.
The **`version`** property is also optional. If not specified the version is `1`. It will become mandatory in future versions if needed.

This structure really just defines the basis. New properties and standards can be defined later on for varies uses cases. That's why there is an "other properties" tag.

The retrieval of the metadata should be the same for all however.

Optional fields allow to save space in the blockchain. Consequently the minimal structure for a single token is:

#### Version 1

```
{
"721": {
Expand All @@ -98,6 +161,22 @@ Optional fields allow to save space in the blockchain. Consequently the minimal
}
```

#### Version 2

```
{
"721": {
"<policy_id>": {
"<asset_name>": {
"name": <string>,
"image": <uri | array>
}
},
"version": 2
}
}
```

### Retrieve valid metadata for a specific token

As mentioned above this metadata structure allows to have either one token or multiple tokens with also different policies in a single mint transaction. A third party tool can then fetch the token metadata seamlessly. It doesn't matter if the metadata includes just one token or multiple. The proceedure for the third party is always the same:
Expand All @@ -114,8 +193,8 @@ Using the latest mint transaction with the label 721 as valid metadata for a tok

## Backward Compatibility

To keep NFT metadata compatible with changes coming up in the future, we use the **`version`** property. Version `1.0` is used in the current metadata structure of this CIP.
Version `2.0` will introduce [schema.org](https://schema.org).
To keep NFT metadata compatible with changes coming up in the future, we use the **`version`** property.
A future version will introduce [schema.org](https://schema.org).

## References

Expand Down