Files: cdcccc55e2a0881ced884e834c3ebda3fd1e9ceb / modules / crypto.js
1198 bytesRaw
1 | var path = require('path') |
2 | var ssbKeys = require('ssb-keys') |
3 | var ref = require('ssb-ref') |
4 | var config = require('ssb-config/inject')(process.env.ssb_appname) |
5 | var keys = ssbKeys |
6 | .loadSync(path.join(config.path, 'secret')) |
7 | |
8 | function 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 | |
23 | var sbot_publish = require('../plugs').first(exports.sbot_publish = []) |
24 | |
25 | exports.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 | |
37 | exports.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 | |
43 | exports.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