git ssb

0+

ev / microbay



forked from Dominic / patchbay

Tree: 07376795ee2a1eb1ec1c2ae45fe872324b1edeea

Files: 07376795ee2a1eb1ec1c2ae45fe872324b1edeea / modules / crypto.js

1067 bytesRaw
1var ref = require('ssb-ref')
2var keys = require('../keys')
3var ssbKeys = require('ssb-keys')
4
5function unbox_value(msg) {
6 var plaintext = ssbKeys.unbox(msg.content, keys)
7 if(!plaintext) return null
8 return {
9 previous: msg.previous,
10 author: msg.author,
11 sequence: msg.sequence,
12 timestamp: msg.timestamp,
13 hash: msg.hash,
14 content: plaintext,
15 private: true
16 }
17}
18
19
20var sbot_publish = require('../plugs').first(exports.sbot_publish = [])
21
22exports.message_unbox = function (msg) {
23 if(msg.value) {
24 var value = unbox_value(msg.value)
25 if(value)
26 return {
27 key: msg.key, value: value, timestamp: msg.timestamp
28 }
29 }
30 else
31 return unbox_value(msg)
32}
33
34exports.message_box = function (content) {
35 return ssbKeys.box(content, content.recps.map(function (e) {
36 return ref.isFeed(e) ? e : e.link
37 }))
38}
39
40exports.publish = function (content, id) {
41 if(content.recps)
42 content = exports.message_box(content)
43 sbot_publish(content, function (err, msg) {
44 if(err) throw err
45 console.log('PUBLISHED', msg)
46 })
47}
48
49

Built with git-ssb-web