Files: 4bbdcb0f89770891b04720e98b31f99295fe0d13 / plugins / private.js
887 bytesRaw
1 | var ssbKeys = require('ssb-keys') |
2 | var explain = require('explain-error') |
3 | var mdm = require('mdmanifest') |
4 | var valid = require('../lib/validators') |
5 | var apidoc = require('../lib/apidocs').private |
6 | |
7 | module.exports = { |
8 | name: 'private', |
9 | version: '0.0.0', |
10 | manifest: mdm.manifest(apidoc), |
11 | permissions: { |
12 | anonymous: {}, |
13 | }, |
14 | init: function (sbot, opts) { |
15 | return { |
16 | publish: valid.async(function (data, recps, cb) { |
17 | var ciphertext |
18 | try { ciphertext = ssbKeys.box(data, recps) } |
19 | catch (e) { return cb(explain(e, 'failed to encrypt')) } |
20 | |
21 | sbot.publish(ciphertext, cb) |
22 | }, 'string|object', 'array'), |
23 | unbox: valid.sync(function (ciphertext) { |
24 | var data |
25 | try { data = ssbKeys.unbox(ciphertext, sbot.keys.private) } |
26 | catch (e) { throw explain(e, 'failed to decrypt') } |
27 | return data |
28 | }, 'string') |
29 | } |
30 | } |
31 | } |
Built with git-ssb-web