var ssbKeys = require('ssb-keys') var confirmer = require('./confirm') exports.name = 'publishguard' exports.version = '1.1.0' exports.manifest = { publishGetUrl: 'async', privatePublishGetUrl: 'async', } exports.init = function (sbot, config) { var confirm setTimeout(function () { var sbotPublish = sbot.publish function sbotPrivatePublish(content, recps, cb) { // don't use original sbot.private.publish, because it calls sbot.publish try { var ciphertext = ssbKeys.box(content, recps) } catch (e) { return cb(new Error('failed to encrypt: ' + e.stack || e)) } sbotPublish(ciphertext, cb) } confirm = confirmer({ publish: sbotPublish, privatePublish: sbotPrivatePublish, config: config.publishguard, ws: sbot.ws, wsConfig: config.ws }) sbot.publish = confirm.publish if (!sbot.private) sbot.private = {} sbot.private.publish = confirm.privatePublish console.log('[' + exports.name + '] enabled') }, 1000) return { publishGetUrl: function (opts, cb) { if (!opts) throw new TypeError('missing opts') if (typeof cb !== 'function') throw new TypeError('bad callback') // TODO: handle race condition with above timeout confirm.publishGetUrl(opts, cb) }, privatePublishGetUrl: function (opts, cb) { if (!opts) throw new TypeError('missing opts') if (typeof cb !== 'function') throw new TypeError('bad callback') confirm.privatePublishGetUrl(opts, cb) } } }