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