Files: 69a54fb3197c0348818b22c6ba647e80302543de / message / sync / unbox.js
825 bytesRaw
1 | var ssbKeys = require('ssb-keys') |
2 | var nest = require('depnest') |
3 | |
4 | exports.needs = nest({ |
5 | 'keys.sync.load': 'first' |
6 | }) |
7 | |
8 | exports.gives = nest('message.sync.unbox') |
9 | |
10 | exports.create = function (api) { |
11 | return nest('message.sync.unbox', function (msg) { |
12 | if (msg.value) { |
13 | var value = unboxValue(msg.value) |
14 | if (value) { |
15 | return { |
16 | key: msg.key, value: value, timestamp: msg.timestamp |
17 | } |
18 | } |
19 | } else { |
20 | return unboxValue(msg) |
21 | } |
22 | }) |
23 | |
24 | function unboxValue (msg) { |
25 | var plaintext = ssbKeys.unbox(msg.content, api.keys.sync.load()) |
26 | if (!plaintext) return null |
27 | return { |
28 | previous: msg.previous, |
29 | author: msg.author, |
30 | sequence: msg.sequence, |
31 | timestamp: msg.timestamp, |
32 | hash: msg.hash, |
33 | content: plaintext, |
34 | private: true |
35 | } |
36 | } |
37 | } |
38 |
Built with git-ssb-web