api.mdView |
---|
| 1 | +# ssb-server |
| 2 | + |
| 3 | +Secure-scuttlebutt API server |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## get: async |
| 8 | + |
| 9 | +Get a message by its hash-id. |
| 10 | + |
| 11 | +```bash |
| 12 | +get {msgid} |
| 13 | +``` |
| 14 | + |
| 15 | +```js |
| 16 | +get(msgid, cb) |
| 17 | +``` |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +## createFeedStream: source |
| 22 | + |
| 23 | +(feed) Fetch messages ordered by their claimed timestamps. |
| 24 | + |
| 25 | +```bash |
| 26 | +feed [--live] [--gt index] [--gte index] [--lt index] [--lte index] [--reverse] [--keys] [--values] [--limit n] |
| 27 | +``` |
| 28 | + |
| 29 | +```js |
| 30 | +createFeedStream({ live:, gt:, gte:, lt:, lte:, reverse:, keys:, values:, limit:, fillCache:, keyEncoding:, valueEncoding: }) |
| 31 | +``` |
| 32 | + |
| 33 | +Create a stream of the data in the database, ordered by the timestamp claimed by the author. |
| 34 | +NOTE - the timestamp is not verified, and may be incorrect. |
| 35 | +The range queries (gt, gte, lt, lte) filter against this claimed timestap. |
| 36 | + |
| 37 | + - `live` (boolean, default: `false`): Keep the stream open and emit new messages as they are received. |
| 38 | + - `gt` (greater than), `gte` (greater than or equal) define the lower bound of the range to be streamed. Only records where the key is greater than (or equal to) this option will be included in the range. When `reverse=true` the order will be reversed, but the records streamed will be the same. |
| 39 | + - `lt` (less than), `lte` (less than or equal) define the higher bound of the range to be streamed. Only key/value pairs where the key is less than (or equal to) this option will be included in the range. When `reverse=true` the order will be reversed, but the records streamed will be the same. |
| 40 | + - `reverse` (boolean, default: `false`): a boolean, set true and the stream output will be reversed. Beware that due to the way LevelDB works, a reverse seek will be slower than a forward seek. |
| 41 | + - `keys` (boolean, default: `true`): whether the `data` event should contain keys. If set to `true` and `values` set to `false` then `data` events will simply be keys, rather than objects with a `key` property. |
| 42 | + - `values` (boolean, default: `true`): whether the `data` event should contain values. If set to `true` and `keys` set to `false` then `data` events will simply be values, rather than objects with a `value` property. |
| 43 | + - `limit` (number, default: `-1`): limit the number of results collected by this stream. This number represents a *maximum* number of results and may not be reached if you get to the end of the data first. A value of `-1` means there is no limit. When `reverse=true` the highest keys will be returned instead of the lowest keys. |
| 44 | + - `fillCache` (boolean, default: `false`): wheather LevelDB's LRU-cache should be filled with data read. |
| 45 | + - `keyEncoding` / `valueEncoding` (string): the encoding applied to each read piece of data. |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +## createLogStream: source |
| 50 | + |
| 51 | +(log) Fetch messages ordered by the time received. |
| 52 | + |
| 53 | +```bash |
| 54 | +log [--live] [--gt index] [--gte index] [--lt index] [--lte index] [--reverse] [--keys] [--values] [--limit n] |
| 55 | +``` |
| 56 | + |
| 57 | +```js |
| 58 | +createLogStream({ live:, gt:, gte:, lt:, lte:, reverse:, keys:, values:, limit:, fillCache:, keyEncoding:, valueEncoding: }) |
| 59 | +``` |
| 60 | + |
| 61 | +Creates a stream of the messages that have been written to this instance, in the order they arrived. |
| 62 | +The objects in this stream will be of the form: |
| 63 | + |
| 64 | +``` |
| 65 | +{ key: Hash, value: Message, timestamp: timestamp } |
| 66 | +``` |
| 67 | + |
| 68 | +`timestamp` is the time which the message was received. |
| 69 | +It is generated by [monotonic-timestamp](https://github.com/dominictarr/monotonic-timestamp). |
| 70 | +The range queries (gt, gte, lt, lte) filter against this receive timestap. |
| 71 | + |
| 72 | + |
| 73 | + - `live` (boolean, default: `false`): Keep the stream open and emit new messages as they are received. |
| 74 | + - `gt` (greater than), `gte` (greater than or equal) define the lower bound of the range to be streamed. Only records where the key is greater than (or equal to) this option will be included in the range. When `reverse=true` the order will be reversed, but the records streamed will be the same. |
| 75 | + - `lt` (less than), `lte` (less than or equal) define the higher bound of the range to be streamed. Only key/value pairs where the key is less than (or equal to) this option will be included in the range. When `reverse=true` the order will be reversed, but the records streamed will be the same. |
| 76 | + - `reverse` (boolean, default: `false`): a boolean, set true and the stream output will be reversed. Beware that due to the way LevelDB works, a reverse seek will be slower than a forward seek. |
| 77 | + - `keys` (boolean, default: `true`): whether the `data` event should contain keys. If set to `true` and `values` set to `false` then `data` events will simply be keys, rather than objects with a `key` property. |
| 78 | + - `values` (boolean, default: `false`): whether the `data` event should contain values. If set to `true` and `keys` set to `false` then `data` events will simply be values, rather than objects with a `value` property. |
| 79 | + - `limit` (number, default: `-1`): limit the number of results collected by this stream. This number represents a *maximum* number of results and may not be reached if you get to the end of the data first. A value of `-1` means there is no limit. When `reverse=true` the highest keys will be returned instead of the lowest keys. |
| 80 | + - `fillCache` (boolean, default: `false`): wheather LevelDB's LRU-cache should be filled with data read. |
| 81 | + - `keyEncoding` / `valueEncoding` (string): the encoding applied to each read piece of data. |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | +## messagesByType: source |
| 86 | + |
| 87 | +(logt) Retrieve messages with a given type, ordered by receive-time. |
| 88 | + |
| 89 | + |
| 90 | +```bash |
| 91 | +logt --type {type} [--live] [--gt index] [--gte index] [--lt index] [--lte index] [--reverse] [--keys] [--values] [--limit n] |
| 92 | +``` |
| 93 | + |
| 94 | +```js |
| 95 | +messagesByType({ type:, live:, gt:, gte:, lt:, lte:, reverse:, keys:, values:, limit:, fillCache:, keyEncoding:, valueEncoding: }) |
| 96 | +``` |
| 97 | + |
| 98 | +All messages must have a type, so this is a good way to select messages that an application might use. |
| 99 | +Like in createLogStream, the range queries (gt, gte, lt, lte) filter against the receive timestap. |
| 100 | + |
| 101 | + - `type` (string): The type of the messages to emit. |
| 102 | + - `live` (boolean, default: `false`): Keep the stream open and emit new messages as they are received. |
| 103 | + - `gt` (greater than), `gte` (greater than or equal) define the lower bound of the range to be streamed. Only records where the key is greater than (or equal to) this option will be included in the range. When `reverse=true` the order will be reversed, but the records streamed will be the same. |
| 104 | + - `lt` (less than), `lte` (less than or equal) define the higher bound of the range to be streamed. Only key/value pairs where the key is less than (or equal to) this option will be included in the range. When `reverse=true` the order will be reversed, but the records streamed will be the same. |
| 105 | + - `reverse` (boolean, default: `false`): a boolean, set true and the stream output will be reversed. Beware that due to the way LevelDB works, a reverse seek will be slower than a forward seek. |
| 106 | + - `keys` (boolean, default: `true`): whether the `data` event should contain keys. If set to `true` and `values` set to `false` then `data` events will simply be keys, rather than objects with a `key` property. |
| 107 | + - `values` (boolean, default: `true`): whether the `data` event should contain values. If set to `true` and `keys` set to `false` then `data` events will simply be values, rather than objects with a `value` property. |
| 108 | + - `limit` (number, default: `-1`): limit the number of results collected by this stream. This number represents a *maximum* number of results and may not be reached if you get to the end of the data first. A value of `-1` means there is no limit. When `reverse=true` the highest keys will be returned instead of the lowest keys. |
| 109 | + - `fillCache` (boolean, default: `false`): wheather LevelDB's LRU-cache should be filled with data read. |
| 110 | + - `keyEncoding` / `valueEncoding` (string): the encoding applied to each read piece of data. |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | +## createHistoryStream: source |
| 115 | + |
| 116 | +(hist) Fetch messages from a specific user, ordered by sequence numbers. |
| 117 | + |
| 118 | +```bash |
| 119 | +hist {feedid} [seq] [live] |
| 120 | +hist --id {feedid} [--seq n] [--live] [--limit n] [--keys] [--values] |
| 121 | +``` |
| 122 | + |
| 123 | +```js |
| 124 | +createHistoryStream(id, seq, live) |
| 125 | +createHistoryStream({ id:, seq:, live:, limit:, keys:, values: }) |
| 126 | +``` |
| 127 | + |
| 128 | +`createHistoryStream` and `createUserStream` serve the same purpose. |
| 129 | +`createHistoryStream` exists as a separate call because it provides fewer range parameters, which makes it safer for RPC between untrusted peers. |
| 130 | + |
| 131 | + - `id` (FeedID, required): The id of the feed to fetch. |
| 132 | + - `seq` (number, default: `0`): If `seq > 0`, then only stream messages with sequence numbers greater than `seq`. |
| 133 | + - `live` (boolean, default: `false`): Keep the stream open and emit new messages as they are received. |
| 134 | + - `keys` (boolean, default: `true`): whether the `data` event should contain keys. If set to `true` and `values` set to `false` then `data` events will simply be keys, rather than objects with a `key` property. |
| 135 | + - `values` (boolean, default: `true`): whether the `data` event should contain values. If set to `true` and `keys` set to `false` then `data` events will simply be values, rather than objects with a `value` property. |
| 136 | + - `limit` (number, default: `-1`): limit the number of results collected by this stream. This number represents a *maximum* number of results and may not be reached if you get to the end of the data first. A value of `-1` means there is no limit. When `reverse=true` the highest keys will be returned instead of the lowest keys. |
| 137 | + |
| 138 | + |
| 139 | +## createUserStream: source |
| 140 | + |
| 141 | +Fetch messages from a specific user, ordered by sequence numbers. |
| 142 | + |
| 143 | +```bash |
| 144 | +createUserStream --id {feedid} [--live] [--gt index] [--gte index] [--lt index] [--lte index] [--reverse] [--keys] [--values] [--limit n] |
| 145 | +``` |
| 146 | + |
| 147 | +```js |
| 148 | +createUserStream({ id:, live:, gt:, gte:, lt:, lte:, reverse:, keys:, values:, limit:, fillCache:, keyEncoding:, valueEncoding: }) |
| 149 | +``` |
| 150 | + |
| 151 | +`createHistoryStream` and `createUserStream` serve the same purpose. |
| 152 | +`createHistoryStream` exists as a separate call because it provides fewer range parameters, which makes it safer for RPC between untrusted peers. |
| 153 | + |
| 154 | +The range queries (gt, gte, lt, lte) filter against the sequence number. |
| 155 | + |
| 156 | + - `id` (FeedID, required): The id of the feed to fetch. |
| 157 | + - `live` (boolean, default: `false`): Keep the stream open and emit new messages as they are received. |
| 158 | + - `gt` (greater than), `gte` (greater than or equal) define the lower bound of the range to be streamed. Only records where the key is greater than (or equal to) this option will be included in the range. When `reverse=true` the order will be reversed, but the records streamed will be the same. |
| 159 | + - `lt` (less than), `lte` (less than or equal) define the higher bound of the range to be streamed. Only key/value pairs where the key is less than (or equal to) this option will be included in the range. When `reverse=true` the order will be reversed, but the records streamed will be the same. |
| 160 | + - `reverse` (boolean, default: `false`): a boolean, set true and the stream output will be reversed. Beware that due to the way LevelDB works, a reverse seek will be slower than a forward seek. |
| 161 | + - `keys` (boolean, default: `true`): whether the `data` event should contain keys. If set to `true` and `values` set to `false` then `data` events will simply be keys, rather than objects with a `key` property. |
| 162 | + - `values` (boolean, default: `true`): whether the `data` event should contain values. If set to `true` and `keys` set to `false` then `data` events will simply be values, rather than objects with a `value` property. |
| 163 | + - `limit` (number, default: `-1`): limit the number of results collected by this stream. This number represents a *maximum* number of results and may not be reached if you get to the end of the data first. A value of `-1` means there is no limit. When `reverse=true` the highest keys will be returned instead of the lowest keys. |
| 164 | + - `fillCache` (boolean, default: `false`): wheather LevelDB's LRU-cache should be filled with data read. |
| 165 | + - `keyEncoding` / `valueEncoding` (string): the encoding applied to each read piece of data. |
| 166 | + |
| 167 | + |
| 168 | +## createWriteStream: sink |
| 169 | + |
| 170 | +write a number of messages to the local store. |
| 171 | +will error if messages are not valid, but will accept |
| 172 | +messages that the ssb-server doesn't replicate. |
| 173 | + |
| 174 | + |
| 175 | +## links: source |
| 176 | + |
| 177 | +Get a stream of messages, feeds, or blobs that are linked to/from an id. |
| 178 | + |
| 179 | +```bash |
| 180 | +links [--source id|filter] [--dest id|filter] [--rel value] [--keys] [--values] [--live] [--reverse] |
| 181 | +``` |
| 182 | + |
| 183 | +```js |
| 184 | +links({ source:, dest:, rel:, keys:, values:, live:, reverse: }) |
| 185 | +``` |
| 186 | + |
| 187 | +The objects in this stream will be of the form: |
| 188 | + |
| 189 | +``` |
| 190 | +{ source: ID, rel: String, dest: ID, key: MsgID } |
| 191 | +``` |
| 192 | + |
| 193 | + - `source` (string, optional): An id or filter, specifying where the link should originate from. To filter, just use the sigil of the type you want: `@` for feeds, `%` for messages, and `&` for blobs. |
| 194 | + - `dest` (string, optional): An id or filter, specifying where the link should point to. To filter, just use the sigil of the type you want: `@` for feeds, `%` for messages, and `&` for blobs. |
| 195 | + - `rel` (string, optional): Filters the links by the relation string. |
| 196 | + - `live` (boolean, default: `false`): Keep the stream open and emit new messages as they are received. |
| 197 | + - `reverse` (boolean, default: `false`): a boolean, set true and the stream output will be reversed. Beware that due to the way LevelDB works, a reverse seek will be slower than a forward seek. |
| 198 | + - `keys` (boolean, default: `true`): whether the `data` event should contain keys. If set to `true` and `values` set to `false` then `data` events will simply be keys, rather than objects with a `key` property. |
| 199 | + - `values` (boolean, default: `true`): whether the `data` event should contain values. If set to `true` and `keys` set to `false` then `data` events will simply be values, rather than objects with a `value` property. |
| 200 | + |
| 201 | + |
| 202 | +## add: async |
| 203 | + |
| 204 | +Add a well-formed message to the database. |
| 205 | + |
| 206 | +```bash |
| 207 | +cat ./message.json | add |
| 208 | +add --author {feedid} --sequence {number} --previous {msgid} --timestamp {number} --hash sha256 --signature {sig} --content.type {type} --content.{...} |
| 209 | +``` |
| 210 | + |
| 211 | +```js |
| 212 | +add({ author:, sequence:, previous: timestamp:, hash: 'sha256', signature:, content: { type:, ... } }, cb) |
| 213 | +``` |
| 214 | + |
| 215 | + - `author` (FeedID): Public key of the author of the message. |
| 216 | + - `sequence` (number): Sequence number of the message. (Starts from 1.) |
| 217 | + - `previous` (MsgID): Hash-id of the previous message in the feed (null for seq=1). |
| 218 | + - `timestamp` (number): Unix timestamp for the publish time. |
| 219 | + - `hash` (string): The hash algorithm used in the message, should always be `sha256`. |
| 220 | + - `signature` (string): A signature computed using the author pubkey and the content of the message (less the `signature` attribute). |
| 221 | + - `content` (object): The content of the message. |
| 222 | + - `.type` (string): The object's type. |
| 223 | + |
| 224 | + |
| 225 | +## publish: async |
| 226 | + |
| 227 | +Construct a message using ssb-server's current user, and add it to the DB. |
| 228 | + |
| 229 | +```bash |
| 230 | +cat ./message-content.json | publish |
| 231 | +publish --type {string} [--other-attributes...] |
| 232 | +``` |
| 233 | + |
| 234 | +```js |
| 235 | +publish({ type:, ... }, cb) |
| 236 | +``` |
| 237 | + |
| 238 | +This is the recommended method for publishing new messages, as it handles the tasks of correctly setting the message's timestamp, sequence number, previous-hash, and signature. |
| 239 | + |
| 240 | + - `content` (object): The content of the message. |
| 241 | + - `.type` (string): The object's type. |
| 242 | + |
| 243 | + |
| 244 | + |
| 245 | + |
| 246 | +## getAddress: sync |
| 247 | + |
| 248 | +Get the address of the server. Default scope is public. |
| 249 | + |
| 250 | +```bash |
| 251 | +getAddress {scope} |
| 252 | +``` |
| 253 | + |
| 254 | +```js |
| 255 | +getAddress(scope, cb) |
| 256 | +``` |
| 257 | + |
| 258 | + |
| 259 | + |
| 260 | +## getLatest: async |
| 261 | + |
| 262 | +Get the latest message in the database by the given feedid. |
| 263 | + |
| 264 | +```bash |
| 265 | +getLatest {feedid} |
| 266 | +``` |
| 267 | + |
| 268 | +```js |
| 269 | +getLatest(id, cb) |
| 270 | +``` |
| 271 | + |
| 272 | + |
| 273 | + |
| 274 | +## latest: source |
| 275 | + |
| 276 | +Get the seq numbers of the latest messages of all users in the database. |
| 277 | + |
| 278 | +```bash |
| 279 | +latest |
| 280 | +``` |
| 281 | + |
| 282 | +```js |
| 283 | +latest() |
| 284 | +``` |
| 285 | + |
| 286 | + |
| 287 | + |
| 288 | +## latestSequence: async |
| 289 | + |
| 290 | +Get the sequence and local timestamp of the last received message from |
| 291 | +a given `feedId`. |
| 292 | + |
| 293 | +```bash |
| 294 | +latestSequence {feedId} |
| 295 | +``` |
| 296 | + |
| 297 | +```js |
| 298 | +latest({feedId}) |
| 299 | +``` |
| 300 | + |
| 301 | + |
| 302 | + |
| 303 | +## whoami: sync |
| 304 | + |
| 305 | +Get information about the current ssb-server user. |
| 306 | + |
| 307 | +```bash |
| 308 | +whoami |
| 309 | +``` |
| 310 | + |
| 311 | +```js |
| 312 | +whoami(cb) |
| 313 | +``` |
| 314 | + |
| 315 | +Outputs information in the following form: |
| 316 | + |
| 317 | +``` |
| 318 | +{ id: FeedID } |
| 319 | +``` |
| 320 | + |
| 321 | + |
| 322 | + |
| 323 | +## progress: sync |
| 324 | + |
| 325 | +returns an object reflecting the progress state of various plugins. |
| 326 | +the return value is a `{}` with subobjects showing `{start,current,target}` |
| 327 | +to represent progress. Currently implemented are `migration` (legacy->flume) |
| 328 | +migration progress and `indexes` (index regeneration). |
| 329 | + |
| 330 | + |
| 331 | +## status: sync |
| 332 | + |
| 333 | +returns an object reflecting the status of various ssb operations, |
| 334 | +such as db read activity, connection statuses, etc, etc. The purpose is to provide |
| 335 | +an overview of how ssb is working. |
| 336 | + |
| 337 | +## getVectorClock: async |
| 338 | + |
| 339 | +## version: sync |
| 340 | + |
| 341 | +return the current version number of the running server |