Files: 26afbb3703400ed773df3fdb62dd05be51b56dab / modules / crypto.js
1217 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 | exports.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 | |
34 | exports.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 | |
40 | exports.message_meta = function (msg) { |
41 | if(msg.value.private) |
42 | return "PRIVATE" |
43 | } |
44 | |
45 | exports.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