readme.md 5.98 KB
Newer Older
Aral Balkan's avatar
Aral Balkan committed
1
2
3
4
# Waystone

> But mostly because it felt like the right thing to do, and that is reason enough.

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Installation

	./install

This will set up your system and also run Pulse for the first time. Continue to the Configuration section to complete your setup.

(Note: on Linux systems, make sure g++ is installed. All other dependencies will be installed by the script.)

# Configuration

The installation script will create an empty config.json file in the root of the project folder.

	{
		"PulseAPIKey": "",
		"DeviceID": ""
	}

To configure your Waystone installation, go to the Pulse Web UI at `http://localhost:8080`. The installation script should have run Pulse for you. If it's not running, you can find it in the `node_modules/indie-pulse-process/` folder (make sure you run the correct binary for your platform).

Once you're in the Web UI, go into the gear menu and select Show ID. This is the Device ID you need to copy as the value for the "DeviceID" key in the configuration file.

Next, select the Settings option from the gear menu and, in the resulting dialog box, click the button that reads "Generate" under the API Key section. This will generate your API key. Copy that key as the value for the "PulseAPIKey" key in the configuration file. 

# Running (and for testing during development)

	./dev

This will run the server.

Aral Balkan's avatar
Aral Balkan committed
34
# REST API
Aral Balkan's avatar
Aral Balkan committed
35

Aral Balkan's avatar
Aral Balkan committed
36
Traditional REST API. Messages received are not trusted and replies should not be trusted either. For trusted messages, we use [Pulse](https://ind.ie/pulse) and the [Teleportation API](#teleportation-api).
Aral Balkan's avatar
Aral Balkan committed
37
38
39
40
41
42
43

All methods receive and return serialised JSON.

### GET

#### isHandleAvailable

Aral Balkan's avatar
Aral Balkan committed
44
45
*Checks if the passed handle is available for use.*

Aral Balkan's avatar
Aral Balkan committed
46
47
Expects a handle to check:
 
48
	/handle
Aral Balkan's avatar
Aral Balkan committed
49
50
51
52
53
54
55

Returns:

	{
		"handleIsAvailable": Boolean
	}

Aral Balkan's avatar
Aral Balkan committed
56
57
58
59
60
61
#### getDeviceId

*Returns the device ID of the Waystone instance.*

Expects: 

62
	/
Aral Balkan's avatar
Aral Balkan committed
63
64
65
66
67
68
69

Returns:

	{
		"deviceId": "String"
	}

Aral Balkan's avatar
Aral Balkan committed
70
71
72
73
### POST 

#### addPerson

Aral Balkan's avatar
Aral Balkan committed
74
75
*Adds the passed person to Waystone* 

Aral Balkan's avatar
Aral Balkan committed
76
77
78
79
80
81
82
Expects a person:

	{
		"handle": "String",
		"name": "String",
		"bio": "String",
		"photo": "Base64EncodedString",
Aral Balkan's avatar
Aral Balkan committed
83
		"deviceId": "String",
Aral Balkan's avatar
Aral Balkan committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
		"email": "(optional) String"
	}

Returns:
	
	{
		"success": Boolean,
		"error (optional)": 
		{
			"code": Number,
			"message": "String"
		}		
	}

Aral Balkan's avatar
Aral Balkan committed
98
99
100
#### confirmNewDeviceForPerson

*Registers a request to confirm that a new device should be added to the person’s account.* 
Aral Balkan's avatar
Aral Balkan committed
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

Expects a device to add to a person:

	{	
		device:
		{
			"id": "String",
			"name": "String",

		},
		person:
		{
			"handle": "String"
		}
	}

Returns:

	{
		"success": Boolean,
		"error (optional)": 
		{
			"code": Number,
			"message": "String"
		}		
	}

Aral Balkan's avatar
Aral Balkan committed
128
129
130
**Note:** *`success = true` means that the request to register the new device has been successfully stored and will be relayed to the user via the Teleportation API for confirmation. The person will have to approve the request either via a notification on the native client (by way of the Teleportation API) or via email if they have that option enabled as a backup.*

# <a name='teleportation-api'></a>Teleportation API 
Aral Balkan's avatar
Aral Balkan committed
131

Aral Balkan's avatar
Aral Balkan committed
132
Messages dropped in specific folders are teleported automatically by Pulse to the recipients. These are trusted messages between authenticated devices. The message are files. The message names are the file names and the message bodies are the file contents. All message bodies are in serialised JSON format.
Aral Balkan's avatar
Aral Balkan committed
133

Aral Balkan's avatar
Aral Balkan committed
134
Message names are automatically prefixed with a timestamp and the handle of the sender in the following format:
Aral Balkan's avatar
Aral Balkan committed
135

Aral Balkan's avatar
Aral Balkan committed
136
137
138
139
140
141
142
143
144
145
146
147
	<datetime>__<messageName>

Where:

	<datetime> = 	ISO 8601 combined date and time string with timezone 
					with colons escaped by underscores for better cross-platform
					file name compability.

Example:

	1980-10-14T00_59_59-04_00__confirm_new_device

148
149
150
151
152
153
154
155
156
157
158
159
160
161
## Message-Acknowledge-Delete (MAD) pattern

Messaging in the Teleportation API uses the MAD pattern:

1. First party writes a message
2. Second party writes an acknowledgement message
3. First party deletes the message (now that it has been acknowledged)

The second party should only acknowledge the message once it has safely received it and loaded it into memory to act on it.

Acknowledgement messages have the form:

	<datetime>__ack__<originalMessageDatetime>__<originalMessageName>

Aral Balkan's avatar
Aral Balkan committed
162
163
164
## From Waystone to a person

### Adding a new device.
Aral Balkan's avatar
Aral Balkan committed
165
166
167
168
169
170
171
172
173
174
175
176
177
178

#### verify_new_device

Asks person to verify that they asked for the device with the presented ID and name.

Message body:

	{
		"id": "String",
		"name": "String"
	}

Reply with (either):

Aral Balkan's avatar
Aral Balkan committed
179
180
 * [confirm_new_device](#confirm-new-device)
 * [deny_new_device](#deny-new-device)
Aral Balkan's avatar
Aral Balkan committed
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

*Notes:*

  1. Not replying will eventually result in the request being forgotten.
  2. If you confirm the new device, its device ID will be added to the list of approved devices for that person and the person will get a `new_device_verified` message.

#### new_device_verified

Confirms that the person’s new device has been verified.

Message body:

	{
		"id": "String",
		"name": "String"
	}

Aral Balkan's avatar
Aral Balkan committed
198
199
200
### Friendship

#### friendship_request
Aral Balkan's avatar
Aral Balkan committed
201

Aral Balkan's avatar
Aral Balkan committed
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
A notification that the sender is requesting friendship.

Message body:
	
	{
		"from": "handle"
	}

#### friendship_acceptance

A notification that your friendship request has been accepted by sender.

Message body:

	{
		"from": "handle"
	}

## From a person to Waystone

### Adding a new device

#### <a name='confirm-new-device'></a>confirm_new_device
Aral Balkan's avatar
Aral Balkan committed
225
226
227
228
229
230
231
232
233

Confirm that you want to add the device with the passed ID to your Ind.ie account. The device will gain full access to your Ind.ie account. This is a response to the `verify_new_device` message.

Message body:

	{
		"id": "String"
	}

Aral Balkan's avatar
Aral Balkan committed
234
#### <a name='deny-new-device'></a>deny_new_device
Aral Balkan's avatar
Aral Balkan committed
235
236
237
238
239
240
241
242
243

Deny access to the device with the passed ID to your Ind.ie account. This is a response to the `verify_new_device` message.

Message body:

	{
		"id": "String"
	}

Aral Balkan's avatar
Aral Balkan committed
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
### Friendship

#### friendship_request

A friendship request to be relayed to the specified person.

Message body:
	
	{
		"to": "handle"
	}

#### friendship_acceptance

A request to relay that you have accepted the specified person’s friendship request.

Message body:
Aral Balkan's avatar
Aral Balkan committed
261

Aral Balkan's avatar
Aral Balkan committed
262
263
264
	{
		"to": "handle"
	}