git ssb

16+

Dominic / patchbay



Tree: 23576a5dca023c72b5a92bf3c1f5b35bb4f22744

Files: 23576a5dca023c72b5a92bf3c1f5b35bb4f22744 / modules / crypto.js

812 bytesRaw
1
2var path = require('path')
3var ssbKeys = require('ssb-keys')
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_meta = function (msg) {
35 if(msg.value.private)
36 return "PRIVATE"
37}
38

Built with git-ssb-web