git ssb

16+

Dominic / patchbay



Tree: cb94bd0d83fae7b007a0e33061df18c620bd6cb1

Files: cb94bd0d83fae7b007a0e33061df18c620bd6cb1 / modules / crypto.js

1217 bytesRaw
1var path = require('path')
2var ssbKeys = require('ssb-keys')
3var ref = require('ssb-ref')
4var config = require('ssb-config/inject')(process.env.ssb_appname)
5var keys = ssbKeys
6 .loadSync(path.join(config.path, 'secret'))
7
8function unbox_value(msg) {
9 var plaintext = ssbKeys.unbox(msg.content, keys)
10 if(!plaintext) return null
11 return {
12 previous: msg.previous,
13 author: msg.author,
14 sequence: msg.sequence,
15 timestamp: msg.timestamp,
16 hash: msg.hash,
17 content: plaintext,
18 private: true
19 }
20}
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.message_meta = function (msg) {
41 if(msg.value.private)
42 return "PRIVATE"
43}
44
45exports.publish = function (content, id, sbot) {
46 if(content.recps)
47 content = exports.message_box(content)
48 sbot.publish(content, function (err, msg) {
49 if(err) throw err
50 console.log('PUBLISHED', msg)
51 })
52}
53
54
55

Built with git-ssb-web