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

NIP-54 - Inline Resource Metadata #521

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
54 changes: 54 additions & 0 deletions 54.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
NIP-54
======

Inline Resource Metadata
------------------------

Inline resource metadata is additional information associated with urls in notes that clients can optionally use to enhance resource loading.

It uses [URI Fragment](https://en.wikipedia.org/wiki/URI_fragment) that agents (such as web browsers) never send to the server. Because of this, the url is fetched **without** the fragment parameters, unlike using query parameters.

The URI fragment follows [media fragments structure](https://www.w3.org/TR/media-frags/#general-structure). For example, one could use `t=number_of_seconds` to start playing a video at the specified position along with an extra [percent-encoded](https://www.ietf.org/rfc/rfc3986.txt) name-value pair separated by `&` char like `https://xyz.com/a-video.mp4#t=24&a%20name=a%20value`. **Notice the usage of `#` instead of `?`.**

The metadata can be appended to any url, like this [NIP-21](21.md) one: `nostr:nevent1qq...pm#a-metadata-name=a-metadata-value`.

## NIP-94 File Fragments

Besides available w3c and proprietary URI fragment usage, nostr uses existing [NIP-94](94.md) tags as file fragment name-value pairs. NIP-94 event `.content` is equivalent to `alt` fragment field. For example, one could join the following strings to form an image url with inline metadata:

- `https://nostr.build/i/863321bb1ae68830ebcf9a343ca0a5e0ce2323d0a55b7fbe86f7a886cf61db8d.jpg`
- `#`
- `m=image%2Fjpeg`
- `&`
- `dim=3024x4032`
- `&`
- `alt=A%20scenic%20photo%20overlooking%20the%20coast%20of%20Costa%20Rica`
- `&`
- `blurhash=eVF%24%5EOI%3A%24%7BM%7Bo%23*0-nNFxakD-%3FxVM%7DWEWB%25iNKxvR-oetmo%23R-aen%24`

Multiple array values use repeated names and are positioned in the same order of ocurrence in the tag array. For instance, `["aes-256-gcm", 'i-am-a-key', 'i-am-an-iv']` becomes `aes-256-gcm=i-am-a-key&aes-256-gcm=i-am-an-iv`.

## Usage

An url with added metadata can be used anywhere a normal url can, whether embedded in an event's `.content` field or as an event tag value.

### Example:

```js
{
"kind": 1,
"content": "What a great place! https://xyz.com/filename#m=image%2Fjpeg&dim=1920x1080`",
// ... other event fields
}
```

## Recommended client behavior

When uploading images during a new post, clients can collect metadata
after the image is uploaded and then include the url with inline metadata in the post.

When pasting urls during post composition, the client could download the image
and add some metadata before the post is sent.

Clients can use `alt` value to add accessible text for people who prefer not to
load images, visibility-impaired users, or text clients.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ They exist to document what may be implemented by [Nostr](https://github.com/nos
- [NIP-51: Lists](51.md)
- [NIP-52: Calendar Events](52.md)
- [NIP-53: Live Activities](53.md)
- [NIP-54: Inline Resource Metadata](54.md)
- [NIP-56: Reporting](56.md)
- [NIP-57: Lightning Zaps](57.md)
- [NIP-58: Badges](58.md)
Expand Down