diff --git a/nips/01.md b/nips/01.md index 7e6b791..0010f9d 100644 --- a/nips/01.md +++ b/nips/01.md @@ -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: , - kind: , - tags: [ - ["e", <32-bytes hex of the id of another event>, ], - ["p", <32-bytes hex of the key>, ], - ... // other kinds of tags may be included later - ] - content: , - 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: , + kind: , + tags: [ + ["e", <32-bytes hex of the id of another event>, ], + ["p", <32-bytes hex of the key>, ], + ... // other kinds of tags may be included later + ] + content: , + 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, - , - , - , - , - , as a string - ] - ``` +``` +[ + 0, + , + , + , + , + , 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 `` is a JSON object that determines what events will be sent in that subscription, it can have the following attributes: - ``` - { - "id": , - "author": , - "kind": - "#e": , - "#p": , - "since": , - "authors": - } - ``` +``` +{ + "id": , + "author": , + "kind": + "#e": , + "#p": , + "since": , + "authors": +} +``` 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 `` or a new `REQ` is sent using the same id, in which case it should overwrite the previous subscription.