Files: 0dc8433933a96a2338ce1948f308f6a305675003 / index.js
1494 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 | }) |
28 | sbot.publish = confirm.publish |
29 | if (!sbot.private) sbot.private = {} |
30 | sbot.private.publish = confirm.privatePublish |
31 | console.log('[' + exports.name + '] enabled') |
32 | }, 1000) |
33 | |
34 | return { |
35 | publishGetUrl: function (opts, cb) { |
36 | if (!opts) throw new TypeError('missing opts') |
37 | if (typeof cb !== 'function') throw new TypeError('bad callback') |
38 | // TODO: handle race condition with above timeout |
39 | confirm.publishGetUrl(opts, cb) |
40 | }, |
41 | privatePublishGetUrl: function (opts, cb) { |
42 | if (!opts) throw new TypeError('missing opts') |
43 | if (typeof cb !== 'function') throw new TypeError('bad callback') |
44 | confirm.privatePublishGetUrl(opts, cb) |
45 | } |
46 | } |
47 | } |
48 |
Built with git-ssb-web