Files: 5a3cd636ffd4211ee7958de59fc2011a7d6f58eb / index.js
1540 bytesRaw
1 | var ssbKeys = require('ssb-keys') |
2 | var confirmer = require('./confirm') |
3 | |
4 | exports.name = 'publishguard' |
5 | exports.version = '1.1.0' |
6 | exports.manifest = { |
7 | publishGetUrl: 'async', |
8 | privatePublishGetUrl: 'async', |
9 | } |
10 | exports.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 | publish: sbotPublish, |
25 | privatePublish: sbotPrivatePublish, |
26 | config: config.publishguard, |
27 | ws: sbot.ws, |
28 | wsConfig: config.ws |
29 | }) |
30 | sbot.publish = confirm.publish |
31 | if (!sbot.private) sbot.private = {} |
32 | sbot.private.publish = confirm.privatePublish |
33 | console.log('[' + exports.name + '] enabled') |
34 | }, 1000) |
35 | |
36 | return { |
37 | publishGetUrl: function (opts, cb) { |
38 | if (!opts) throw new TypeError('missing opts') |
39 | if (typeof cb !== 'function') throw new TypeError('bad callback') |
40 | // TODO: handle race condition with above timeout |
41 | confirm.publishGetUrl(opts, cb) |
42 | }, |
43 | privatePublishGetUrl: function (opts, cb) { |
44 | if (!opts) throw new TypeError('missing opts') |
45 | if (typeof cb !== 'function') throw new TypeError('bad callback') |
46 | confirm.privatePublishGetUrl(opts, cb) |
47 | } |
48 | } |
49 | } |
50 |
Built with git-ssb-web