git ssb

16+

Dominic / patchbay



Tree: 437facf41d277081453b193b5e9cc808704399ef

Files: 437facf41d277081453b193b5e9cc808704399ef / modules / crypto.js

1198 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
22
23var sbot_publish = require('../plugs').first(exports.sbot_publish = [])
24
25exports.message_unbox = function (msg) {
26 if(msg.value) {
27 var value = unbox_value(msg.value)
28 if(value)
29 return {
30 key: msg.key, value: value, timestamp: msg.timestamp
31 }
32 }
33 else
34 return unbox_value(msg)
35}
36
37exports.message_box = function (content) {
38 return ssbKeys.box(content, content.recps.map(function (e) {
39 return ref.isFeed(e) ? e : e.link
40 }))
41}
42
43exports.publish = function (content, id) {
44 if(content.recps)
45 content = exports.message_box(content)
46 sbot_publish(content, function (err, msg) {
47 if(err) throw err
48 console.log('PUBLISHED', msg)
49 })
50}
51
52
53
54

Built with git-ssb-web