mirror of
https://github.com/nostr-protocol/nips.git
synced 2025-12-09 08:38:50 +00:00
Compare commits
22 Commits
zap-sender
...
cleanup-52
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae73a8dbf7 | ||
|
|
0946eb8d34 | ||
|
|
bd248bab20 | ||
|
|
884ea3d8b8 | ||
|
|
56610771b6 | ||
|
|
b90ddd2dae | ||
|
|
4d32f3a1db | ||
|
|
b0e6c01321 | ||
|
|
e489ed468b | ||
|
|
a309c96205 | ||
|
|
0cd480dd84 | ||
|
|
cfc8dfce89 | ||
|
|
ad40fbdab3 | ||
|
|
13c9202ba3 | ||
|
|
b3c0c4f64a | ||
|
|
74a586d6ae | ||
|
|
2409f821a4 | ||
|
|
3e05545952 | ||
|
|
8bfcbebae4 | ||
|
|
402c330ce9 | ||
|
|
3d8652ea14 | ||
|
|
27fef638e2 |
2
01.md
2
01.md
@@ -116,7 +116,7 @@ Clients can send 3 types of messages, which must be JSON arrays, according to th
|
||||
* `["REQ", <subscription_id>, <filters1>, <filters2>, ...]`, used to request events and subscribe to new updates.
|
||||
* `["CLOSE", <subscription_id>]`, used to stop previous subscriptions.
|
||||
|
||||
`<subscription_id>` is an arbitrary, non-empty string of max length 64 chars. It represents a subscription per connection. Relays MUST manage `<subscription_id>`s independently for each WebSocket connection. `<subscription_id>`s are not guarantueed to be globally unique.
|
||||
`<subscription_id>` is an arbitrary, non-empty string of max length 64 chars. It represents a subscription per connection. Relays MUST manage `<subscription_id>`s independently for each WebSocket connection. `<subscription_id>`s are not guaranteed to be globally unique.
|
||||
|
||||
`<filtersX>` is a JSON object that determines what events will be sent in that subscription, it can have the following attributes:
|
||||
|
||||
|
||||
2
02.md
2
02.md
@@ -27,6 +27,8 @@ For example:
|
||||
|
||||
Every new following list that gets published overwrites the past ones, so it should contain all entries. Relays and clients SHOULD delete past following lists as soon as they receive a new one.
|
||||
|
||||
Whenever new follows are added to an existing list, clients SHOULD append them to the end of the list, so they are stored in chronological order.
|
||||
|
||||
## Uses
|
||||
|
||||
### Follow list backup
|
||||
|
||||
78
15.md
78
15.md
@@ -149,7 +149,6 @@ The `merchant` and the `customer` can exchange JSON messages that represent diff
|
||||
| 1 | Merchant | Payment Request |
|
||||
| 2 | Merchant | Order Status Update |
|
||||
|
||||
|
||||
### Step 1: `customer` order (event)
|
||||
The below json goes in content of [NIP04](https://github.com/nostr-protocol/nips/blob/master/04.md).
|
||||
|
||||
@@ -229,7 +228,9 @@ The below json goes in `content` of [NIP04](https://github.com/nostr-protocol/ni
|
||||
"shipped": <bool: has been shipped>,
|
||||
}
|
||||
```
|
||||
|
||||
## Customize Marketplace
|
||||
|
||||
Create a customized user experience using the `naddr` from [NIP-19](https://github.com/nostr-protocol/nips/blob/master/19.md#shareable-identifiers-with-extra-metadata). The use of `naddr` enables easy sharing of marketplace events while incorporating a rich set of metadata. This metadata can include relays, merchant profiles, and more. Subsequently, it allows merchants to be grouped into a market, empowering the market creator to configure the marketplace's user interface and user experience, and share that marketplace. This customization can encompass elements such as market name, description, logo, banner, themes, and even color schemes, offering a tailored and unique marketplace experience.
|
||||
|
||||
### Event `30019`: Create or update marketplace UI/UX
|
||||
@@ -253,6 +254,81 @@ Create a customized user experience using the `naddr` from [NIP-19](https://gith
|
||||
|
||||
This event leverages naddr to enable comprehensive customization and sharing of marketplace configurations, fostering a unique and engaging marketplace environment.
|
||||
|
||||
## Auctions
|
||||
|
||||
### Event `30020`: Create or update a product sold as an auction
|
||||
|
||||
**Event Content**:
|
||||
```json
|
||||
{
|
||||
"id": <String, UUID generated by the merchant. Sequential IDs (`0`, `1`, `2`...) are discouraged>,
|
||||
"stall_id": <String, UUID of the stall to which this product belong to>,
|
||||
"name": <String, product name>,
|
||||
"description": <String (optional), product description>,
|
||||
"images": <[String], array of image URLs, optional>,
|
||||
"starting_bid": <int>,
|
||||
"start_date": <int (optional) UNIX timestamp, date the auction started / will start>,
|
||||
"duration": <int, number of seconds the auction will run for, excluding eventual time extensions that might happen>,
|
||||
"specs": [
|
||||
[<String, spec key>, <String, spec value>]
|
||||
],
|
||||
"shipping": [
|
||||
{
|
||||
"id": <String, UUID of the shipping zone. Must match one of the zones defined for the stall>,
|
||||
"cost": <float, extra cost for shipping. The currency is defined at the stall level>,
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> Items sold as an auction are very similar in structure to fixed-price items, with some important differences worth noting.
|
||||
|
||||
* The `start_date` can be set to a date in the future if the auction is scheduled to start on that date, or can be omitted if the start date is unknown/hidden. If the start date is not specified, the auction will have to be edited later to set an actual date.
|
||||
|
||||
* The auction runs for an initial number of seconds after the `start_date`, specified by `duration`.
|
||||
|
||||
### Event `1021`: Bid
|
||||
|
||||
```json
|
||||
{
|
||||
"content": <int, amount of sats>,
|
||||
"tags": [["e", <event ID of the auction to bid on>]],
|
||||
}
|
||||
```
|
||||
|
||||
Bids are simply events of kind `1021` with a `content` field specifying the amount, in the currency of the auction. Bids must reference an auction.
|
||||
|
||||
> [!NOTE]
|
||||
> Auctions can be edited as many times as desired (they are "parameterized replaceable events") by the author - even after the start_date, but they cannot be edited after they have received the first bid! This is enforced by the fact that bids reference the event ID of the auction (rather than the product UUID), which changes with every new version of the auctioned product. So a bid is always attached to one "version". Editing the auction after a bid would result in the new product losing the bid!
|
||||
|
||||
### Event `1022`: Bid confirmation
|
||||
|
||||
**Event Content**:
|
||||
|
||||
```json
|
||||
{
|
||||
"status": <String, "accepted" | "rejected" | "pending" | "winner">,
|
||||
"message": <String (optional)>,
|
||||
"duration_extended": <int (optional), number of seconds>,
|
||||
}
|
||||
```
|
||||
|
||||
**Event Tags**:
|
||||
```json
|
||||
"tags": [["e" <event ID of the bid being confirmed>], ["e", <event ID of the auction>]],
|
||||
```
|
||||
|
||||
Bids should be confirmed by the merchant before being considered as valid by other clients. So clients should subscribe to *bid confirmation* events (kind `1022`) for every auction that they follow, in addition to the actual bids and should check that the pubkey of the bid confirmation matches the pubkey of the merchant (in addition to checking the signature).
|
||||
|
||||
The `content` field is a JSON which includes *at least* a `status`. `winner` is how the *winning bid* is replied to after the auction ends and the winning bid is picked by the merchant.
|
||||
|
||||
The reasons for which a bid can be marked as `rejected` or `pending` are up to the merchant's implementation and configuration - they could be anything from basic validation errors (amount too low) to the bidder being blacklisted or to the bidder lacking sufficient *trust*, which could lead to the bid being marked as `pending` until sufficient verification is performed. The difference between the two is that `pending` bids *might* get approved after additional steps are taken by the bidder, whereas `rejected` bids can not be later approved.
|
||||
|
||||
An additional `message` field can appear in the `content` JSON to give further context as of why a bid is `rejected` or `pending`.
|
||||
|
||||
Another thing that can happen is - if bids happen very close to the end date of the auction - for the merchant to decide to extend the auction duration for a few more minutes. This is done by passing a `duration_extended` field as part of a bid confirmation, which would contain a number of seconds by which the initial duration is extended. So the actual end date of an auction is always `start_date + duration + (SUM(c.duration_extended) FOR c in all confirmations`.
|
||||
|
||||
## Customer support events
|
||||
|
||||
Customer support is handled over whatever communication method was specified. If communicating via nostr, NIP-04 is used https://github.com/nostr-protocol/nips/blob/master/04.md.
|
||||
|
||||
4
44.md
4
44.md
@@ -161,7 +161,7 @@ validation rules, refer to BIP-340.
|
||||
### Implementation pseudocode
|
||||
|
||||
The following is a collection of python-like pseudocode functions which implement the above primitives,
|
||||
intended to guide impelmenters. A collection of implementations in different languages is available at https://github.com/paulmillr/nip44.
|
||||
intended to guide implementers. A collection of implementations in different languages is available at https://github.com/paulmillr/nip44.
|
||||
|
||||
```py
|
||||
# Calculates length of the padded byte array.
|
||||
@@ -286,7 +286,7 @@ Example of a test vector from the file:
|
||||
The file also contains intermediate values. A quick guidance with regards to its usage:
|
||||
|
||||
- `valid.get_conversation_key`: calculate conversation_key from secret key sec1 and public key pub2
|
||||
- `valid.get_message_keys`: calculate chacha_key, chacha_nocne, hmac_key from conversation_key and nonce
|
||||
- `valid.get_message_keys`: calculate chacha_key, chacha_nonce, hmac_key from conversation_key and nonce
|
||||
- `valid.calc_padded_len`: take unpadded length (first value), calculate padded length (second value)
|
||||
- `valid.encrypt_decrypt`: emulate real conversation. Calculate pub2 from sec2, verify conversation_key from (sec1, pub2), encrypt, verify payload, then calculate pub1 from sec1, verify conversation_key from (sec2, pub1), decrypt, verify plaintext.
|
||||
- `valid.encrypt_decrypt_long_msg`: same as previous step, but instead of a full plaintext and payload, their checksum is provided.
|
||||
|
||||
2
46.md
2
46.md
@@ -34,7 +34,7 @@ The signer scans the QR code and sends a `connect` message to the client in the
|
||||
|
||||
## Event payloads
|
||||
|
||||
Event payloads are [NIP-04](04.md)-encrypted JSON blobs that look like JSONRPC messages (their format is specified inside the `.content` of the event formats nelow).
|
||||
Event payloads are [NIP-04](04.md)-encrypted JSON blobs that look like JSONRPC messages (their format is specified inside the `.content` of the event formats below).
|
||||
|
||||
Events sent by the client to the remote signer have the following format:
|
||||
|
||||
|
||||
2
50.md
2
50.md
@@ -41,7 +41,7 @@ implementation details between relays.
|
||||
Clients MAY verify that events returned by a relay match the specified query in a way that suits the
|
||||
client's use case, and MAY stop querying relays that have low precision.
|
||||
|
||||
Relays SHOULD exclude spam from search results by default if they supports some form of spam filtering.
|
||||
Relays SHOULD exclude spam from search results by default if they support some form of spam filtering.
|
||||
|
||||
## Extensions
|
||||
|
||||
|
||||
3
51.md
3
51.md
@@ -10,6 +10,8 @@ This NIP defines lists of things that users can create. Lists can contain refere
|
||||
|
||||
Public items in a list are specified in the event `tags` array, while private items are specified in a JSON array that mimics the structure of the event `tags` array, but stringified and encrypted using the same scheme from [NIP-04](04.md) (the shared key is computed using the author's public and private key) and stored in the `.content`.
|
||||
|
||||
When new items are added to an existing list, clients SHOULD append them to the end of the list, so they are stored in chronological order.
|
||||
|
||||
## Types of lists
|
||||
|
||||
## Standard lists
|
||||
@@ -44,6 +46,7 @@ Aside from their main identifier, the `"d"` tag, sets can optionally have a `"ti
|
||||
| Relay sets | 30002 | user-defined relay groups the user can easily pick and choose from during various operations | `"relay"` (relay URLs) |
|
||||
| Bookmark sets | 30003 | user-defined bookmarks categories , for when bookmarks must be in labeled separate groups | `"e"` (kind:1 notes), `"a"` (kind:30023 articles), `"t"` (hashtags), `"r" (URLs)` |
|
||||
| Curation sets | 30004 | groups of articles picked by users as interesting and/or belonging to the same category | `"a"` (kind:30023 articles), `"e"` (kind:1 notes) |
|
||||
| Curation sets | 30005 | groups of videos picked by users as interesting and/or belonging to the same category | `"a"` (kind:34235 videos) |
|
||||
| Interest sets | 30015 | interest topics represented by a bunch of "hashtags" | `"t"` (hashtags) |
|
||||
| Emoji sets | 30030 | categorized emoji groups | `"emoji"` (see [NIP-30](30.md)) |
|
||||
|
||||
|
||||
18
52.md
18
52.md
@@ -35,9 +35,6 @@ The list of tags are as follows:
|
||||
* `t` (optional, repeated) hashtag to categorize calendar event
|
||||
* `r` (optional, repeated) references / links to web pages, documents, video calls, recorded videos, etc.
|
||||
|
||||
The following tags are deprecated:
|
||||
* `name` name of the calendar event. Use only if `title` is not available.
|
||||
|
||||
```json
|
||||
{
|
||||
"id": <32-bytes lowercase hex-encoded SHA-256 of the the serialized event data>,
|
||||
@@ -49,6 +46,8 @@ The following tags are deprecated:
|
||||
["d", "<UUID>"],
|
||||
|
||||
["title", "<title of calendar event>"],
|
||||
["image", "<image url>"],
|
||||
["banner", "<image url>"],
|
||||
|
||||
// Dates
|
||||
["start", "<YYYY-MM-DD>"],
|
||||
@@ -96,9 +95,6 @@ The list of tags are as follows:
|
||||
* `t` (optional, repeated) hashtag to categorize calendar event
|
||||
* `r` (optional, repeated) references / links to web pages, documents, video calls, recorded videos, etc.
|
||||
|
||||
The following tags are deprecated:
|
||||
* `name` name of the calendar event. Use only if `title` is not available.
|
||||
|
||||
```json
|
||||
{
|
||||
"id": <32-bytes lowercase hex-encoded SHA-256 of the the serialized event data>,
|
||||
@@ -110,6 +106,8 @@ The following tags are deprecated:
|
||||
["d", "<UUID>"],
|
||||
|
||||
["title", "<title of calendar event>"],
|
||||
["image", "<image url>"],
|
||||
["banner", "<image url>"],
|
||||
|
||||
// Timestamps
|
||||
["start", "<Unix timestamp in seconds>"],
|
||||
@@ -210,13 +208,7 @@ The list of tags are as follows:
|
||||
}
|
||||
```
|
||||
|
||||
## Unsolved Limitations
|
||||
|
||||
* No private events
|
||||
|
||||
## Intentionally Unsupported Scenarios
|
||||
|
||||
### Recurring Calendar Events
|
||||
## Recurring Calendar Events
|
||||
|
||||
Recurring calendar events come with a lot of complexity, making it difficult for software and humans to deal with. This complexity includes time zone differences between invitees, daylight savings, leap years, multiple calendar systems, one-off changes in schedule or other metadata, etc.
|
||||
|
||||
|
||||
2
53.md
2
53.md
@@ -94,7 +94,7 @@ Common use cases include meeting rooms/workshops, watch-together activities, or
|
||||
["title", "Adult Swim Metalocalypse"],
|
||||
["summary", "Live stream from IPTV-ORG collection"],
|
||||
["streaming", "https://adultswim-vodlive.cdn.turner.com/live/metalocalypse/stream.m3u8"],
|
||||
["starts", "1687182672"]
|
||||
["starts", "1687182672"],
|
||||
["status", "live"],
|
||||
["t", "animation"],
|
||||
["t", "iptv"],
|
||||
|
||||
2
58.md
2
58.md
@@ -28,7 +28,7 @@ The following tags MAY be present:
|
||||
- A `name` tag with a short name for the badge.
|
||||
- `image` tag whose value is the URL of a high-resolution image representing the badge. The second value optionally specifies the dimensions of the image as `width`x`height` in pixels. Badge recommended dimensions is 1024x1024 pixels.
|
||||
- A `description` tag whose value MAY contain a textual representation of the
|
||||
image, the meaning behind the badge, or the reason of it's issuance.
|
||||
image, the meaning behind the badge, or the reason of its issuance.
|
||||
- One or more `thumb` tags whose first value is an URL pointing to a thumbnail version of the image referenced in the `image` tag. The second value optionally specifies the dimensions of the thumbnail as `width`x`height` in pixels.
|
||||
|
||||
### Badge Award event
|
||||
|
||||
2
94.md
2
94.md
@@ -15,6 +15,7 @@ This NIP specifies the use of the `1063` event type, having in `content` a descr
|
||||
* `url` the url to download the file
|
||||
* `m` a string indicating the data type of the file. The [MIME types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types) format must be used, and they should be lowercase.
|
||||
* `x` containing the SHA-256 hexencoded string of the file.
|
||||
* `ox` containing the SHA-256 hexencoded string of the original file, before any transformations done by the upload server
|
||||
* `size` (optional) size of file in bytes
|
||||
* `dim` (optional) size of file in pixels in the form `<width>x<height>`
|
||||
* `magnet` (optional) URI to magnet file
|
||||
@@ -32,6 +33,7 @@ This NIP specifies the use of the `1063` event type, having in `content` a descr
|
||||
["url",<string with URI of file>],
|
||||
["m", <MIME type>],
|
||||
["x",<Hash SHA-256>],
|
||||
["ox",<Hash SHA-256>],
|
||||
["size", <size of file in bytes>],
|
||||
["dim", <size of file in pixels>],
|
||||
["magnet",<magnet URI> ],
|
||||
|
||||
302
96.md
Normal file
302
96.md
Normal file
@@ -0,0 +1,302 @@
|
||||
NIP-96
|
||||
======
|
||||
|
||||
HTTP File Storage Integration
|
||||
-----------------------------
|
||||
|
||||
`draft` `optional`
|
||||
|
||||
## Introduction
|
||||
|
||||
This NIP defines a REST API for HTTP file storage servers intended to be used in conjunction with the nostr network.
|
||||
The API will enable nostr users to upload files and later reference them by url on nostr notes.
|
||||
|
||||
The spec DOES NOT use regular nostr events through websockets for
|
||||
storing, requesting nor retrieving data because, for simplicity, the server
|
||||
will not have to learn anything about nostr relays.
|
||||
|
||||
## Server Adaptation
|
||||
|
||||
File storage servers wishing to be accessible by nostr users should opt-in by making available an https route at `/.well-known/nostr/nip96.json` with `api_url`:
|
||||
|
||||
```js
|
||||
{
|
||||
// Required
|
||||
// File upload and deletion are served from this url
|
||||
// Also downloads if "download_url" field is absent or empty string
|
||||
"api_url": "https://your-file-server.example/custom-api-path",
|
||||
// Optional
|
||||
// If absent, downloads are served from the api_url
|
||||
"download_url": "https://a-cdn.example/a-path",
|
||||
// Optional
|
||||
// Note: This field is not meant to be set by HTTP Servers.
|
||||
// Use this if you are a nostr relay using your /.well-known/nostr/nip96.json
|
||||
// just to redirect to someone else's http file storage server's /.well-known/nostr/nip96.json
|
||||
// In this case, "api_url" field must be an empty string
|
||||
"delegated_to_url": "https://your-file-server.example",
|
||||
// Optional
|
||||
"supported_nips": [60],
|
||||
// Optional
|
||||
"tos_url": "https://your-file-server.example/terms-of-service",
|
||||
// Optional
|
||||
"content_types": ["image/jpeg", "video/webm", "audio/*"],
|
||||
// Optional
|
||||
"plans": {
|
||||
// "free" is the only standardized plan key and
|
||||
// clients may use its presence to learn if server offers free storage
|
||||
"free": {
|
||||
"name": "Free Tier",
|
||||
// Default is true
|
||||
// All plans MUST support NIP-98 uploads
|
||||
// but some plans may also allow uploads without it
|
||||
"is_nip98_required": true,
|
||||
"url": "https://...", // plan's landing page if there is one
|
||||
"max_byte_size": 10485760,
|
||||
// Range in days / 0 for no expiration
|
||||
// [7, 0] means it may vary from 7 days to unlimited persistence,
|
||||
// [0, 0] means it has no expiration
|
||||
// early expiration may be due to low traffic or any other factor
|
||||
"file_expiration": [14, 90],
|
||||
"media_transformations": {
|
||||
"image": [
|
||||
'resizing'
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Relay Hints
|
||||
|
||||
Note: This section is not meant to be used by HTTP Servers.
|
||||
|
||||
A nostr relay MAY redirect to someone else's HTTP file storage server by
|
||||
adding a `/.well-known/nostr/nip96.json` with "delegated_to_url" field
|
||||
pointing to the url where the server hosts its own
|
||||
`/.well-known/nostr/nip96.json`. In this case, the "api_url" field must
|
||||
be an empty string and all other fields must be absent.
|
||||
|
||||
If the nostr relay is also an HTTP file storage server,
|
||||
it must use the "api_url" field instead.
|
||||
|
||||
### List of Supporting File Storage Servers
|
||||
|
||||
| Name | Domain |
|
||||
| ------------- | ------------------------- |
|
||||
| nostrcheck.me | https://nostrcheck.me |
|
||||
| nostrage | https://nostrage.com |
|
||||
| sove | https://sove.rent |
|
||||
| nostr.build | https://nostr.build |
|
||||
| sovbit | https://files.sovbit.host |
|
||||
| void.cat | https://void.cat |
|
||||
|
||||
## Upload
|
||||
|
||||
A file can be uploaded one at a time to `https://your-file-server.example/custom-api-path` (route from `https://your-file-server.example/.well-known/nostr/nip96.json` "api_url" field) as `multipart/form-data` content type using `POST` method with the file object set to the `file` form data field.
|
||||
|
||||
`Clients` must add an [NIP-98](98.md) `Authorization` header (**optionally** with the encoded `payload` tag set to the base64-encoded 256-bit SHA-256 hash of the file - not the hash of the whole request body).
|
||||
If using an html form, use an `Authorization` form data field instead.
|
||||
|
||||
These following **optional** form data fields MAY be used by `servers` and SHOULD be sent by `clients`:
|
||||
- `expiration`: string of the UNIX timestamp in seconds. Empty string if file should be stored forever. The server isn't required to honor this;
|
||||
- `size`: string of the file byte size. This is just a value the server can use to reject early if the file size exceeds the server limits;
|
||||
- `alt`: (recommended) strict description text for visibility-impaired users;
|
||||
- `caption`: loose description;
|
||||
- `media_type`: "avatar" or "banner". Informs the server if the file will be used as an avatar or banner. If absent, the server will interpret it as a normal upload, without special treatment;
|
||||
- `content_type`: mime type such as "image/jpeg". This is just a value the server can use to reject early if the mime type isn't supported.
|
||||
|
||||
|
||||
Others custom form data fields may be used depending on specific `server` support.
|
||||
The `server` isn't required to store any metadata sent by `clients`.
|
||||
|
||||
Note for `clients`: if using an HTML form, it is important for the `file` form field to be the **last** one, or be re-ordered right before sending or be appended as the last field of XHR2's FormData object.
|
||||
|
||||
The `filename` embedded in the file may not be honored by the `server`, which could internally store just the SHA-256 hash value as the file name, ignoring extra metadata.
|
||||
The hash is enough to uniquely identify a file, that's why it will be used on the "download" and "delete" routes.
|
||||
|
||||
The `server` MUST link the user's `pubkey` string (which is embedded in the decoded header value) as the owner of the file so to later allow them to delete the file.
|
||||
Note that if a file with the same hash of a previously received file (so the same file) is uploaded by another user, the server doesn't need to store the new file.
|
||||
It should just add the new user's `pubkey` to the list of the owners of the already stored file with said hash (if it wants to save space by keeping just one copy of the same file, because multiple uploads of the same file results in the same file hash).
|
||||
|
||||
The `server` MAY also store the `Authorization` header/field value (decoded or not) for accountability purpose as this proves that the user with the unique pubkey did ask for the upload of the file with a specific hash. However, storing the pubkey is sufficient to establish ownership.
|
||||
|
||||
The `server` MUST reject with 413 Payload Too Large if file size exceeds limits.
|
||||
|
||||
The `server` MUST reject with 400 Bad Request status if some fields are invalid.
|
||||
|
||||
The `server` MUST reply to the upload with 200 OK status if the `payload` tag value contains an already used SHA-256 hash (if file is already owned by the same pubkey) or reject the upload with 403 Forbidden status if it isn't the same of the received file.
|
||||
|
||||
The `server` MAY reject the upload with 402 Payment Required status if the user has a pending payment (Payment flow is not strictly required. Server owners decide if the storage is free or not. Monetization schemes may be added later to correlated NIPs.).
|
||||
|
||||
On successful uploads the `server` MUST reply with **201 Created** HTTP status code or **202 Accepted** if a `processing_url` field is added
|
||||
to the response so that the `client` can follow the processing status (see [Delayed Processing](#delayed-processing) section).
|
||||
|
||||
The upload response is a json object as follows:
|
||||
|
||||
```js
|
||||
{
|
||||
// "success" if successful or "error" if not
|
||||
status: "success",
|
||||
// Free text success, failure or info message
|
||||
message: "Upload successful.",
|
||||
// Optional. See "Delayed Processing" section
|
||||
processing_url: "...",
|
||||
// This uses the NIP-94 event format but DO NOT need
|
||||
// to fill some fields like "id", "pubkey", "created_at" and "sig"
|
||||
//
|
||||
// This holds the download url ("url"),
|
||||
// the ORIGINAL file hash before server transformations ("ox")
|
||||
// and, optionally, all file metadata the server wants to make available
|
||||
//
|
||||
// nip94_event field is absent if unsuccessful upload
|
||||
nip94_event: {
|
||||
// Required tags: "url" and "ox"
|
||||
tags: [
|
||||
// Can be same from /.well-known/nostr/nip96.json's "download_url" field
|
||||
// (or "api_url" field if "download_url" is absent or empty) with appended
|
||||
// original file hash.
|
||||
//
|
||||
// Note we appended .png file extension to the `ox` value
|
||||
// (it is optional but extremely recommended to add the extension as it will help nostr clients
|
||||
// with detecting the file type by using regular expression)
|
||||
//
|
||||
// Could also be any url to download the file
|
||||
// (using or not using the /.well-known/nostr/nip96.json's "download_url" prefix),
|
||||
// for load balancing purposes for example.
|
||||
["url", "https://your-file-server.example/custom-api-path/719171db19525d9d08dd69cb716a18158a249b7b3b3ec4bbdec5698dca104b7b.png"],
|
||||
// SHA-256 hash of the ORIGINAL file, before transformations.
|
||||
// The server MUST store it even though it represents the ORIGINAL file because
|
||||
// users may try to download/delete the transformed file using this value
|
||||
["ox", "719171db19525d9d08dd69cb716a18158a249b7b3b3ec4bbdec5698dca104b7b"],
|
||||
// Optional. SHA-256 hash of the saved file after any server transformations.
|
||||
// The server can but does not need to store this value.
|
||||
["x", "543244319525d9d08dd69cb716a18158a249b7b3b3ec4bbde5435543acb34443"],
|
||||
// Optional. Recommended for helping clients to easily know file type before downloading it.
|
||||
["m", "image/png"]
|
||||
// Optional. Recommended for helping clients to reserve an adequate UI space to show the file before downloading it.
|
||||
["dim", "800x600"]
|
||||
// ... other optional NIP-94 tags
|
||||
],
|
||||
content: ""
|
||||
},
|
||||
// ... other custom fields (please consider adding them to this NIP or to NIP-94 tags)
|
||||
}
|
||||
```
|
||||
|
||||
Note that if the server didn't apply any transformation to the received file, both `nip94_event.tags.*.ox` and `nip94_event.tags.*.x` fields will have the same value. The server MUST link the saved file to the SHA-256 hash of the **original** file before any server transformations (the `nip94_event.tags.*.ox` tag value). The **original** file's SHA-256 hash will be used to identify the saved file when downloading or deleting it.
|
||||
|
||||
`Clients` may upload the same file to one or many `servers`.
|
||||
After successful upload, the `client` may optionally generate and send to any set of nostr `relays` a [NIP-94](94.md) event by including the missing fields.
|
||||
|
||||
Alternatively, instead of using NIP-94, the `client` can share or embed on a nostr note just the above url with added "ox" [NIP-54](54.md) inline metadata field and optionally other ones.
|
||||
|
||||
### Delayed Processing
|
||||
|
||||
Sometimes the server may want to place the uploaded file in a processing queue for deferred file processing.
|
||||
|
||||
In that case, the server MUST serve the original file while the processing isn't done, then swap the original file for the processed one when the processing is over. The upload response is the same as usual but some optional metadata like `nip94_event.tags.*.x` and `nip94_event.tags.*.size` won't be available.
|
||||
|
||||
The expected resulting metadata that is known in advance should be returned on the response.
|
||||
For example, if the file processing would change a file from "jpg" to "webp",
|
||||
use ".webp" extension on the `nip94_event.tags.*.url` field value and set "image/webp" to the `nip94_event.tags.*.m` field.
|
||||
If some metadata are unknown before processing ends, omit them from the response.
|
||||
|
||||
The upload response MAY include a `processing_url` field informing a temporary url that may be used by clients to check if
|
||||
the file processing is done.
|
||||
|
||||
If the processing isn't done, the server should reply at the `processing_url` url with **200 OK** and the following JSON:
|
||||
|
||||
```
|
||||
{
|
||||
// It should be "processing". If "error" it would mean the processing failed.
|
||||
status: "processing",
|
||||
message: "Processing. Please check again later for updated status.",
|
||||
percentage: 15 // Processing percentage. An integer between 0 and 100.
|
||||
}
|
||||
```
|
||||
|
||||
When the processing is over, the server replies at the `processing_url` url with **201 Created** status and a regular successful JSON response already mentioned before (now **without** a `processing_url` field), possibly including optional metadata at `nip94_event.tags.*` fields
|
||||
that weren't available before processing.
|
||||
|
||||
### File compression
|
||||
|
||||
File compression and other transformations like metadata stripping can be applied by the server.
|
||||
However, for all file actions, such as download and deletion, the **original** file SHA-256 hash is what identifies the file in the url string.
|
||||
|
||||
## Download
|
||||
|
||||
`Servers` must make available the route `https://your-file-server.example/custom-api-path/<sha256-file-hash>(.ext)` (route taken from `https://your-file-server.example/.well-known/nostr/nip96.json` "api_url" or "download_url" field) with `GET` method for file download.
|
||||
|
||||
The primary file download url informed at the upload's response field `nip94_event.tags.*.url`
|
||||
can be that or not (it can be any non-standard url the server wants).
|
||||
If not, the server still MUST also respond to downloads at the standard url
|
||||
mentioned on the previous paragraph, to make it possible for a client
|
||||
to try downloading a file on any NIP-96 compatible server by knowing just the SHA-256 file hash.
|
||||
|
||||
Note that the "\<sha256-file-hash\>" part is from the **original** file, **not** from the **transformed** file if the uploaded file went through any server transformation.
|
||||
|
||||
Supporting ".ext", meaning "file extension", is required for `servers`. It is optional, although recommended, for `clients` to append it to the path.
|
||||
When present it may be used by `servers` to know which `Content-Type` header to send (e.g.: "Content-Type": "image/png" for ".png" extension).
|
||||
The file extension may be absent because the hash is the only needed string to uniquely identify a file.
|
||||
|
||||
Example: `https://your-file-server.example/custom-api-path/719171db19525d9d08dd69cb716a18158a249b7b3b3ec4bbdec5698dca104b7b.png`
|
||||
|
||||
### Media Transformations
|
||||
|
||||
`Servers` may respond to some media transformation query parameters and ignore those they don't support by serving
|
||||
the original media file without transformations.
|
||||
|
||||
#### Image Transformations
|
||||
|
||||
##### Resizing
|
||||
|
||||
Upon upload, `servers` may create resized image variants, such as thumbnails, respecting the original aspect ratio.
|
||||
`Clients` may use the `w` query parameter to request an image version with the desired pixel width.
|
||||
`Servers` can then serve the variant with the closest width to the parameter value
|
||||
or an image variant generated on the fly.
|
||||
|
||||
Example: `https://your-file-server.example/custom-api-path/<sha256-file-hash>.png?w=32`
|
||||
|
||||
## Deletion
|
||||
|
||||
`Servers` must make available the route `https://deletion.domain/deletion-path/<sha256-file-hash>(.ext)` (route taken from `https://your-file-server.example/.well-known/nostr/nip96.json` "api_url" field) with `DELETE` method for file deletion.
|
||||
|
||||
Note that the "\<sha256-file-hash\>" part is from the **original** file, **not** from the **transformed** file if the uploaded file went through any server transformation.
|
||||
|
||||
The extension is optional as the file hash is the only needed file identification.
|
||||
|
||||
`Clients` should send a `DELETE` request to the server deletion route in the above format. It must include a NIP-98 `Authorization` header.
|
||||
|
||||
The `server` should reject deletes from users other than the original uploader. The `pubkey` encoded on the header value identifies the user.
|
||||
|
||||
It should be noted that more than one user may have uploaded the same file (with the same hash). In this case, a delete must not really delete the file but just remove the user's `pubkey` from the file owners list (considering the server keeps just one copy of the same file, because multiple uploads of the same file results
|
||||
in the same file hash).
|
||||
|
||||
The successfull response is a 200 OK one with just basic JSON fields:
|
||||
|
||||
```
|
||||
{
|
||||
status: "success",
|
||||
message: "File deleted."
|
||||
}
|
||||
```
|
||||
|
||||
## Selecting a Server
|
||||
|
||||
Note: HTTP File Storage Server developers may skip this section. This is meant for client developers.
|
||||
|
||||
A File Server Preference event is a kind 10096 replaceable event meant to select one or more servers the user wants
|
||||
to upload files to. Servers are listed as `server` tags:
|
||||
|
||||
```js
|
||||
{
|
||||
// ...
|
||||
"kind": 10096,
|
||||
"content": "",
|
||||
"tags": [
|
||||
["server", "https://file.server.one"],
|
||||
["server", "https://file.server.two"]
|
||||
]
|
||||
}
|
||||
```
|
||||
@@ -72,6 +72,7 @@ They exist to document what may be implemented by [Nostr](https://github.com/nos
|
||||
- [NIP-89: Recommended Application Handlers](89.md)
|
||||
- [NIP-90: Data Vending Machines](90.md)
|
||||
- [NIP-94: File Metadata](94.md)
|
||||
- [NIP-96: HTTP File Storage Integration](96.md)
|
||||
- [NIP-98: HTTP Auth](98.md)
|
||||
- [NIP-99: Classified Listings](99.md)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user