readme.md 4.76 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.

Aral Balkan's avatar
Aral Balkan committed
5
# REST API
Aral Balkan's avatar
Aral Balkan committed
6

Aral Balkan's avatar
Aral Balkan committed
7
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
8
9
10
11
12
13
14

All methods receive and return serialised JSON.

### GET

#### isHandleAvailable

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

Aral Balkan's avatar
Aral Balkan committed
17
18
Expects a handle to check:
 
19
	/handle
Aral Balkan's avatar
Aral Balkan committed
20
21
22
23
24
25
26

Returns:

	{
		"handleIsAvailable": Boolean
	}

Aral Balkan's avatar
Aral Balkan committed
27
28
29
30
31
32
#### getDeviceId

*Returns the device ID of the Waystone instance.*

Expects: 

33
	/
Aral Balkan's avatar
Aral Balkan committed
34
35
36
37
38
39
40

Returns:

	{
		"deviceId": "String"
	}

Aral Balkan's avatar
Aral Balkan committed
41
42
43
44
### POST 

#### addPerson

Aral Balkan's avatar
Aral Balkan committed
45
46
*Adds the passed person to Waystone* 

Aral Balkan's avatar
Aral Balkan committed
47
48
49
50
51
52
53
Expects a person:

	{
		"handle": "String",
		"name": "String",
		"bio": "String",
		"photo": "Base64EncodedString",
Aral Balkan's avatar
Aral Balkan committed
54
		"deviceId": "String",
Aral Balkan's avatar
Aral Balkan committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
		"email": "(optional) String"
	}

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

Aral Balkan's avatar
Aral Balkan committed
69
70
71
#### 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

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
99
100
101
**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
102

Aral Balkan's avatar
Aral Balkan committed
103
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
104

Aral Balkan's avatar
Aral Balkan committed
105
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
106

Aral Balkan's avatar
Aral Balkan committed
107
108
109
110
111
112
113
114
115
116
117
118
	<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

119
120
121
122
123
124
125
126
127
128
129
130
131
132
## 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
133
134
135
## From Waystone to a person

### Adding a new device.
Aral Balkan's avatar
Aral Balkan committed
136
137
138
139
140
141
142
143
144
145
146
147
148
149

#### 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
150
151
 * [confirm_new_device](#confirm-new-device)
 * [deny_new_device](#deny-new-device)
Aral Balkan's avatar
Aral Balkan committed
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168

*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
169
170
171
### Friendship

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

Aral Balkan's avatar
Aral Balkan committed
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
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
196
197
198
199
200
201
202
203
204

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
205
#### <a name='deny-new-device'></a>deny_new_device
Aral Balkan's avatar
Aral Balkan committed
206
207
208
209
210
211
212
213
214

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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
### 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
232

Aral Balkan's avatar
Aral Balkan committed
233
234
235
	{
		"to": "handle"
	}