diff options
| author | fiatjaf_ <fiatjaf@gmail.com> | 2023-12-29 18:15:21 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-29 18:15:21 -0300 |
| commit | 000c51ef44c3ff1e0842139ada3859ba0a9b540f (patch) | |
| tree | e6a73fc097c3dfadb597cb62ca6cea6cfca9e300 /01.md | |
| parent | 17c67ef5577c8ac5419a1081aadea57e30f8c133 (diff) | |
| parent | da19c078ab892b578a5c35968443205c9e8ac27f (diff) | |
Merge pull request #635 from nostr-protocol/clarify-json-serialization
Clarify JSON serialization for the `id` field
Diffstat (limited to '01.md')
| -rw-r--r-- | 01.md | 14 |
1 files changed, 13 insertions, 1 deletions
| @@ -29,7 +29,7 @@ The only object type that exists is the `event`, which has the following format | |||
| 29 | } | 29 | } |
| 30 | ``` | 30 | ``` |
| 31 | 31 | ||
| 32 | To obtain the `event.id`, we `sha256` the serialized event. The serialization is done over the UTF-8 JSON-serialized string (with no white space or line breaks between the fields) of the following structure: | 32 | To obtain the `event.id`, we `sha256` the serialized event. The serialization is done over the UTF-8 JSON-serialized string (which is described below) of the following structure: |
| 33 | 33 | ||
| 34 | ``` | 34 | ``` |
| 35 | [ | 35 | [ |
| @@ -42,6 +42,18 @@ To obtain the `event.id`, we `sha256` the serialized event. The serialization is | |||
| 42 | ] | 42 | ] |
| 43 | ``` | 43 | ``` |
| 44 | 44 | ||
| 45 | To prevent implementation differences from creating a different event ID for the same event, the following rules MUST be followed while serializing: | ||
| 46 | - No whitespace, line breaks or other unnecessary formatting should be included in the output JSON. | ||
| 47 | - No characters except the following should be escaped, and instead should be included verbatim: | ||
| 48 | - A line break, `0x0A`, as `\n` | ||
| 49 | - A double quote, `0x22`, as `\"` | ||
| 50 | - A backslash, `0x5C`, as `\\` | ||
| 51 | - A carriage return, `0x0D`, as `\r` | ||
| 52 | - A tab character, `0x09`, as `\t` | ||
| 53 | - A backspace, `0x08`, as `\b` | ||
| 54 | - A form feed, `0x0C`, as `\f` | ||
| 55 | - UTF-8 should be used for encoding. | ||
| 56 | |||
| 45 | ### Tags | 57 | ### Tags |
| 46 | 58 | ||
| 47 | Each tag is an array of strings of arbitrary size, with some conventions around them. Take a look at the example below: | 59 | Each tag is an array of strings of arbitrary size, with some conventions around them. Take a look at the example below: |