git ssb

3+

cel / ssb-publishguard



Tree: 043153f4feb56ac8a710e91fd243efb4a3ae8d03

Files: 043153f4feb56ac8a710e91fd243efb4a3ae8d03 / index.js

2835 bytesRaw
1var ssbKeys = require('ssb-keys')
2var confirmer = require('./confirm')
3
4var help = {
5 description: 'Publish messages via user-confirmation',
6 commands: {
7 publishGetUrl: {
8 description: 'Create a URL with a confirmation form for publishing a message',
9 type: 'async',
10 args: {
11 content: {
12 type: 'object',
13 optional: false,
14 description: 'message content to publish'
15 },
16 redirectBase: {
17 type: 'URL',
18 optional: false,
19 description: 'Base URL for post-publish redirect - with the message ID, URL-encoded, appended'
20 }
21 }
22 },
23 privatePublishGetUrl: {
24 description: 'Create a URL with a confirmation form for publishing a private message',
25 type: 'async',
26 args: {
27 content: {
28 type: 'object',
29 optional: false,
30 description: 'message content to publish privately'
31 },
32 redirectBase: {
33 type: 'URL',
34 optional: false,
35 description: 'base URL for post-publish redirect - with the message ID, URL-encoded, appended'
36 },
37 recps: {
38 type: 'FeedIds',
39 optional: false,
40 description: 'feed ids to encrypt message to with private-box'
41 }
42 }
43 }
44 }
45}
46
47exports.name = 'publishguard'
48exports.version = '1.1.0'
49exports.manifest = {
50 publishGetUrl: 'async',
51 privatePublishGetUrl: 'async',
52 help: 'sync',
53}
54exports.init = function (sbot, config) {
55 var confirm
56 setTimeout(function () {
57 var sbotPublish = sbot.publish
58 function sbotPrivatePublish(content, recps, cb) {
59 // don't use original sbot.private.publish, because it calls sbot.publish
60 try {
61 var ciphertext = ssbKeys.box(content, recps)
62 } catch (e) {
63 return cb(new Error('failed to encrypt: ' + e.stack || e))
64 }
65 sbotPublish(ciphertext, cb)
66 }
67 confirm = confirmer({
68 publish: sbotPublish,
69 privatePublish: sbotPrivatePublish,
70 config: config.publishguard,
71 ws: sbot.ws,
72 wsConfig: config.ws
73 })
74 sbot.publish = confirm.publish
75 if (!sbot.private) sbot.private = {}
76 sbot.private.publish = confirm.privatePublish
77 console.log('[' + exports.name + '] enabled')
78 }, 1000)
79
80 return {
81 publishGetUrl: function (opts, cb) {
82 if (!opts) throw new TypeError('missing opts')
83 if (typeof cb !== 'function') throw new TypeError('bad callback')
84 // TODO: handle race condition with above timeout
85 confirm.publishGetUrl(opts, cb)
86 },
87 privatePublishGetUrl: function (opts, cb) {
88 if (!opts) throw new TypeError('missing opts')
89 if (typeof cb !== 'function') throw new TypeError('bad callback')
90 confirm.privatePublishGetUrl(opts, cb)
91 },
92 help: function () {
93 return help
94 }
95 }
96}
97

Built with git-ssb-web