git ssb

7+

dinoworm ๐Ÿ› / patchcore



Tree: 73ce52087fc4eb16ae6fef1818817c6f2fcd5a52

Files: 73ce52087fc4eb16ae6fef1818817c6f2fcd5a52 / message / sync / unbox.js

825 bytesRaw
1var ssbKeys = require('ssb-keys')
2var nest = require('depnest')
3
4exports.needs = nest({
5 'keys.sync.load': 'first'
6})
7
8exports.gives = nest('message.sync.unbox')
9
10exports.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