git ssb

3+

cel / ssb-publishguard



Tree: 4681c34eca9aa16ef5e452b7a7d54b67c65fafc1

Files: 4681c34eca9aa16ef5e452b7a7d54b67c65fafc1 / index.js

1559 bytesRaw
1var ssbKeys = require('ssb-keys')
2var confirmer = require('./confirm')
3
4exports.name = 'publishguard'
5exports.version = '1.1.0'
6exports.manifest = {
7 publishGetUrl: 'async',
8 privatePublishGetUrl: 'async',
9}
10exports.init = function (sbot, config) {
11 var confirm
12 setTimeout(function () {
13 var sbotPublish = sbot.publish
14 function sbotPrivatePublish(content, recps, cb) {
15 // don't use original sbot.private.publish, because it calls sbot.publish
16 try {
17 var ciphertext = ssbKeys.box(content, recps)
18 } catch (e) {
19 return cb(new Error('failed to encrypt: ' + e.stack || e))
20 }
21 sbotPublish(ciphertext, cb)
22 }
23 confirm = confirmer({
24 ws: sbot.ws,
25 publish: sbotPublish,
26 privatePublish: sbotPrivatePublish,
27 config: config.publishguard,
28 ws: sbot.ws,
29 wsConfig: config.ws
30 })
31 sbot.publish = confirm.publish
32 if (!sbot.private) sbot.private = {}
33 sbot.private.publish = confirm.privatePublish
34 console.log('[' + exports.name + '] enabled')
35 }, 1000)
36
37 return {
38 publishGetUrl: function (opts, cb) {
39 if (!opts) throw new TypeError('missing opts')
40 if (typeof cb !== 'function') throw new TypeError('bad callback')
41 // TODO: handle race condition with above timeout
42 confirm.publishGetUrl(opts, cb)
43 },
44 privatePublishGetUrl: function (opts, cb) {
45 if (!opts) throw new TypeError('missing opts')
46 if (typeof cb !== 'function') throw new TypeError('bad callback')
47 confirm.privatePublishGetUrl(opts, cb)
48 }
49 }
50}
51

Built with git-ssb-web