|
| 1 | +# Delegated Naming HTTP API |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +**Author(s)**: |
| 6 | + |
| 7 | +- [Masih H. Derkani](https://github.com/masih) |
| 8 | + |
| 9 | +**Maintainer(s)**: |
| 10 | + |
| 11 | +* * * |
| 12 | + |
| 13 | +**Abstract** |
| 14 | + |
| 15 | +Delegated naming is a mechanism for IPFS implementations to offload naming system to another process |
| 16 | +or server. This includes naming resolution as well as publication of new naming records. This |
| 17 | +document describes an HTTP API through which such functionality is facilitated. |
| 18 | + |
| 19 | +## API Specification |
| 20 | + |
| 21 | +The Delegated Naming System HTTP API uses the `application/json` content type by default. |
| 22 | + |
| 23 | +As such, human-readable encodings of types are preferred. This spec may be updated in the future |
| 24 | +with a compact `application/cbor` encoding, in which case compact encodings of the various types |
| 25 | +would be used. |
| 26 | + |
| 27 | +## Common Data Types |
| 28 | + |
| 29 | +### IPNS Record |
| 30 | + |
| 31 | +The following snippet outlines the JSON schema of IPNS records: |
| 32 | + |
| 33 | +```json |
| 34 | +{ |
| 35 | + "Signature": "<signature>", |
| 36 | + "Payload": { |
| 37 | + "Value": "<value>", |
| 38 | + "Sequence": 0, |
| 39 | + "Validity": { |
| 40 | + "EOL": { |
| 41 | + "Timestamp": 0, |
| 42 | + "AdvisoryTTL": 0 |
| 43 | + } |
| 44 | + }, |
| 45 | + "PublicKey": "<optional-public-key>", |
| 46 | + "ExtendedData": {} |
| 47 | + } |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +Where: |
| 52 | + |
| 53 | +- `Signature` is the multibase-encoded signature of the sha256 hash of the `Payload` field, signed |
| 54 | + using the private key that corresponds to the `PublicKey` in the `Payload` if present. And |
| 55 | + Otherwise, the private key associcated to the IPNS record key. Signing details for specific key |
| 56 | + types should |
| 57 | + follow [libp2p/peerid specs](https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md#key-types), |
| 58 | + unless stated otherwise. |
| 59 | +- `Payload` is the content of the IPNS record as specified |
| 60 | + by [IPNS Record](../ipns/IPNS.md#ipns-record) specification: |
| 61 | +- `Value` is the string representation of the IPNS path, |
| 62 | + e.g. `ipns/{ipns-key}`, `/ipns/example.com`, `/ipfs/baf...`, etc. |
| 63 | +- `Sequence` represents the current version of the record starting from `0`. |
| 64 | +- `Validity` captures the mechanism by which the record is validated. Each validity type reserves a |
| 65 | + field key under this object. |
| 66 | + - `EOL` donates that the validity type is EOL, containing: |
| 67 | + - `Timestamp` represents the time in the future at which the record expires with nanoseconds |
| 68 | + precision represented as an ASCII string that follows notation |
| 69 | + from [RFC3339](https://www.ietf.org/rfc/rfc3339.txt). |
| 70 | + - `AdvisoryTTL` represents an optional field that hints at how long the record should be |
| 71 | + cached. |
| 72 | +- `PublicKey` represents the optional public key used to sign the record. This field is only |
| 73 | + required if it cannot be extracted from the IPNS name, e.g. in the case of legacy RSA keys. |
| 74 | +- `ExtendedData` represents the extensible data as arbitrary JSON object. |
| 75 | + |
| 76 | +## Versioning |
| 77 | + |
| 78 | +The path predix `/v1` donates the version number of the HTTP API. Backwards-incompatible change must |
| 79 | +increment the version number. |
| 80 | + |
| 81 | +## API |
| 82 | + |
| 83 | +### `GET /naming/v1/records/{ipns-name}` |
| 84 | + |
| 85 | +**Path Parameters** |
| 86 | + |
| 87 | +- `ipns-name` the IPNS name to resolve. |
| 88 | + |
| 89 | +**Response Status Codes** |
| 90 | + |
| 91 | +- `200` (OK): indicates that the response body containing the IPNS record that corresponds to the |
| 92 | + IPNS name. |
| 93 | +- `404` (Not Found): indicates that no matching records are found. |
| 94 | +- `400` (Bad Request): indicates that the given IPNS name is not valid. |
| 95 | +- `429` (Too Many Requests): indicates that the caller is issuing requests too many request and may |
| 96 | + retry after the time specified |
| 97 | + at [Retry-After](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) response |
| 98 | + header has elapsed. |
| 99 | +- `501` (Not Implemented): indicates that the server does not support resolution of IPNS records |
| 100 | + |
| 101 | +**Response Body** |
| 102 | + |
| 103 | +The response body contains the [IPNS record](#ipns-record). |
| 104 | + |
| 105 | +```json |
| 106 | +{ |
| 107 | + "Signature": "<signature>", |
| 108 | + "Payload": { |
| 109 | + "Value": "<value>", |
| 110 | + "Sequence": 0, |
| 111 | + "Validity": { |
| 112 | + "EOL": { |
| 113 | + "Timestamp": 0, |
| 114 | + "AdvisoryTTL": 0 |
| 115 | + } |
| 116 | + }, |
| 117 | + "PublicKey": "<optional-public-key>", |
| 118 | + "ExtendedData": {} |
| 119 | + } |
| 120 | +} |
| 121 | +``` |
| 122 | + |
| 123 | +### `PUT /naming/v1/records` |
| 124 | + |
| 125 | +**Request Body** |
| 126 | + |
| 127 | +```json |
| 128 | +{ |
| 129 | + "Signature": "<signature>", |
| 130 | + "Payload": { |
| 131 | + "Value": "<value>", |
| 132 | + "Sequence": 0, |
| 133 | + "Validity": { |
| 134 | + "EOL": { |
| 135 | + "Timestamp": 0, |
| 136 | + "AdvisoryTTL": 0 |
| 137 | + } |
| 138 | + }, |
| 139 | + "PublicKey": "<optional-public-key>", |
| 140 | + "ExtendedData": {} |
| 141 | + } |
| 142 | +} |
| 143 | +``` |
| 144 | + |
| 145 | +**Response Status Codes** |
| 146 | + |
| 147 | +- `200` (OK): indicates that the response body containing the IPNS record that corresponds to the |
| 148 | + IPNS name. |
| 149 | +- `404` (Not Found): indicates that no matching records are found. |
| 150 | +- `400` (Bad Request): indicates that the given IPNS record is not valid. |
| 151 | +- `429` (Too Many Requests): indicates that the caller is issuing requests too many request and may |
| 152 | + retry after the time specified |
| 153 | + at [Retry-After](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) response |
| 154 | + header has elapsed. |
| 155 | +- `501` (Not Implemented): indicates that the server does not support publication of IPNS records |
| 156 | + |
| 157 | +## CORS and Web Browsers |
| 158 | + |
| 159 | +Browser interoperability requires implementations to support |
| 160 | +[CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS). |
| 161 | + |
| 162 | +JavaScript client running on a third-party Origin must be able to send HTTP request to the endpoints |
| 163 | +defined in this specification, and read the received values. This means HTTP server implementing |
| 164 | +this API must: |
| 165 | + |
| 166 | +1. support [CORS preflight requests](https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request) sent as HTTP OPTIONS, and |
| 167 | +2. always respond with headers that remove CORS limits, allowing every site to query the API for results: |
| 168 | + |
| 169 | +```plaintext |
| 170 | +Access-Control-Allow-Origin: * |
| 171 | +Access-Control-Allow-Methods: GET, PUT, OPTIONS |
| 172 | +``` |
0 commit comments