Files: 94d9ca2cbe74997f6ec36751cd631e2bf6305283 / modules / crypto.js
1067 bytesRaw
1 | var ref = require('ssb-ref') |
2 | var keys = require('../keys') |
3 | var ssbKeys = require('ssb-keys') |
4 | |
5 | function 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 | |
20 | var sbot_publish = require('../plugs').first(exports.sbot_publish = []) |
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.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