Merge pull request #635 from nostr-protocol/clarify-json-serialization

Clarify JSON serialization for the `id` field
This commit is contained in:
fiatjaf_ 2023-12-29 18:15:21 -03:00 committed by GitHub
commit 000c51ef44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

14
01.md
View File

@ -29,7 +29,7 @@ The only object type that exists is the `event`, which has the following format
}
```
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:
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:
```
[
@ -42,6 +42,18 @@ To obtain the `event.id`, we `sha256` the serialized event. The serialization is
]
```
To prevent implementation differences from creating a different event ID for the same event, the following rules MUST be followed while serializing:
- No whitespace, line breaks or other unnecessary formatting should be included in the output JSON.
- No characters except the following should be escaped, and instead should be included verbatim:
- A line break, `0x0A`, as `\n`
- A double quote, `0x22`, as `\"`
- A backslash, `0x5C`, as `\\`
- A carriage return, `0x0D`, as `\r`
- A tab character, `0x09`, as `\t`
- A backspace, `0x08`, as `\b`
- A form feed, `0x0C`, as `\f`
- UTF-8 should be used for encoding.
### Tags
Each tag is an array of strings of arbitrary size, with some conventions around them. Take a look at the example below: