Files: 2ef5acc007ebb7702f358d1dfe780a6ac984047c / index.js
1314 bytesRaw
1 | var path = require('path') |
2 | var ssbKeys = require('ssb-keys') |
3 | var SecretStack = require('secret-stack') |
4 | var explain = require('explain-error') |
5 | var path = require('path') |
6 | var fs = require('fs') |
7 | |
8 | var cap = |
9 | new Buffer('1KHLiKZvAvjbY1ziZEHMXawbCEIM6qwjCDm3VYRan/s=', 'base64') |
10 | |
11 | var createConfig = require('ssb-config/inject') |
12 | |
13 | module.exports = function (keys, opts, cb) { |
14 | if (typeof keys == 'function') { |
15 | cb = keys |
16 | keys = null |
17 | opts = null |
18 | } |
19 | else if (typeof opts == 'function') { |
20 | cb = opts |
21 | opts = keys |
22 | keys = null |
23 | } |
24 | |
25 | if(typeof opts === 'string') |
26 | opts = createConfig(opts) |
27 | |
28 | keys = keys || ssbKeys.loadOrCreateSync(path.join(opts.path, 'secret')) |
29 | opts = opts || {} |
30 | opts.host = opts.host || 'localhost' |
31 | opts.port = opts.port || config.port |
32 | opts.key = opts.key || keys.id |
33 | |
34 | var createNode = SecretStack({appKey: cap}) |
35 | |
36 | var manifest = opts.manifest || (function () { |
37 | try { |
38 | return JSON.parse(fs.readFileSync( |
39 | path.join(opts.path, 'manifest.json') |
40 | )) |
41 | } catch (err) { |
42 | throw explain(err, 'could not load manifest file') |
43 | } |
44 | })() |
45 | |
46 | createNode.createClient({keys: keys, manifest: manifest})(opts, function (err, sbot) { |
47 | if(err) err = explain(err, 'could not connect to sbot') |
48 | cb(err, sbot) |
49 | }) |
50 | } |
51 | |
52 |
Built with git-ssb-web