nip01: fix json formatting.

pull/36/head
fiatjaf 2021-10-23 13:22:52 -03:00
rodzic 69509f40cd
commit 5553654e0c
1 zmienionych plików z 37 dodań i 36 usunięć

Wyświetl plik

@ -13,34 +13,35 @@ This NIP defines the basic protocol that should be implemented by everybody. New
Each user has a keypair. Signatures, public key and encodings are done according to the [Schnorr signatures standard for the curve `secp256k1`](https://bips.xyz/340).
The single object type that exists is the `event`, which has the following format on the wire:
```
{
id: <32-bytes sha256 of the the serialized event data>
pubkey: <32-bytes hex-encoded public key of the event creator>,
created_at: <unix timestamp in seconds>,
kind: <integer>,
tags: [
["e", <32-bytes hex of the id of another event>, <recommended relay URL>],
["p", <32-bytes hex of the key>, <recommended relay URL>],
... // other kinds of tags may be included later
]
content: <arbitrary string>,
sig: <64-bytes signature of the sha256 hash of the serialized event data, which is the same as the "id" field>,
}
```
```
{
id: <32-bytes sha256 of the the serialized event data>
pubkey: <32-bytes hex-encoded public key of the event creator>,
created_at: <unix timestamp in seconds>,
kind: <integer>,
tags: [
["e", <32-bytes hex of the id of another event>, <recommended relay URL>],
["p", <32-bytes hex of the key>, <recommended relay URL>],
... // other kinds of tags may be included later
]
content: <arbitrary string>,
sig: <64-bytes signature of the sha256 hash of the serialized event data, which is the same as the "id" field>,
}
```
To obtain the `event.id`, we `sha256` the serialized event. The serialization is done over the UTF-8 JSON-serialized string (with no indentation or extra spaces) of the following structure:
```
[
0,
<pubkey, as a hex string>,
<created_at, as a number>,
<kind, as a number>,
<tags, as an array of arrays>,
<content>, as a string
]
```
```
[
0,
<pubkey, as a hex string>,
<created_at, as a number>,
<kind, as a number>,
<tags, as an array of arrays>,
<content>, as a string
]
```
### Communication between clients and relays
@ -56,17 +57,17 @@ Clients can send either 3 types of messages, which must be JSON arrays, accordin
`<filters>` is a JSON object that determines what events will be sent in that subscription, it can have the following attributes:
```
{
"id": <the id of an event>,
"author": <the pubkey of an event that identifies its author>,
"kind": <a kind number>
"#e": <an event id that is referenced in an "e" tag>,
"#p": <a pubkey that is referenced in a "p" tag>,
"since": <a timestamp, events must be newer than this to pass>,
"authors": <a list of pubkeys, the pubkey of an event must be one of these>
}
```
```
{
"id": <the id of an event>,
"author": <the pubkey of an event that identifies its author>,
"kind": <a kind number>
"#e": <an event id that is referenced in an "e" tag>,
"#p": <a pubkey that is referenced in a "p" tag>,
"since": <a timestamp, events must be newer than this to pass>,
"authors": <a list of pubkeys, the pubkey of an event must be one of these>
}
```
Upon receiving a `REQ` message, the relay MUST query its internal database and return events that match the filter, then store that filter and send again all future events it receives to that same websocket until the websocket is closed, the `CLOSE` event is received withe same `<id>` or a new `REQ` is sent using the same id, in which case it should overwrite the previous subscription.