Timeline specification
Purpose
The timeline specification describes a singly-linked list data structure allowing to iterate over individual items (named "chapters") in reverse chronological order. It leverages Swarm feeds in order to store and update the ID (Swarm hash) of the latest chapter, providing an immutable reference to retrieve the latest chapter of the timeline.
Data structure
A chapter is a JSON object containing the following fields:
protocol: requiredstringwith valuetimeline, used for sanity check when loading a chapter.version: required valid SemVerstringwith value1.0.0, the current version of the protocol.timestamp: requiredinteger, the UNIX timestamp in milliseconds of the creation of the chapter.author: required hexadecimalstring, the Ethereum address of the author (40 hexadecimal characters prefixed with0x).type: requiredstring, the MIME type of thecontent.content: any valid JSON data satisfying the specifiedtype.previous: hexadecimalstring, the ID (Swarm hash) of the previous chapter. It is required unless the chapter is the first in the timeline.references: optionalarrayof hexadecimalstringrepresenting the IDs (Swarm hashes) of related chapters in the given timeline.signature: optional hexadecimalstringprefixed with0xof the signed chapter (JSON-serialised fields other than thesignature).
In addition, once a chapter is downloaded and therefore its ID (Swarm hash) is know, it should be set as the id field in the chapter structure.
Implementation flows
Creating a timeline
- Create a first chapter by uploading its JSON to Swarm, the returned Swarm hash of the content is the
chapter ID. - Update the wanted Swarm feed with the value of the created
chapter ID.
Loading a known timeline chapter
- Load the chapter JSON using its
chapter ID(Swarm hash). - Inject the know
chapter IDin theidfield of the loaded JSON structure.
Loading the latest timeline chapter
- Retrieve the latest chapter
chapter IDfrom the Swarm feed. - Load the chapter JSON using its
chapter ID(Swarm hash). - Inject the know
chapter IDin theidfield of the loaded JSON structure.
Adding a chapter to a timeline
- Retrieve the latest chapter
chapter IDfrom the Swarm feed. - Create the chapter JSON structure with the retrieved
chapter IDinjected in thepreviousfield. - Upload the chapter JSON to Swarm, the returned Swarm hash of the content is the
new chapter ID. - Update the Swarm feed with the value of the created
new chapter ID.
