git ssb

2+

Dominic / ssb-client



Tree: 2d0a19ee36752ffead1af06769f5f9013468a287

Files: 2d0a19ee36752ffead1af06769f5f9013468a287 / index.js

1332 bytesRaw
1var path = require('path')
2var ssbKeys = require('ssb-keys')
3var SecretStack = require('secret-stack')
4var explain = require('explain-error')
5var path = require('path')
6var fs = require('fs')
7
8var cap =
9 new Buffer('1KHLiKZvAvjbY1ziZEHMXawbCEIM6qwjCDm3VYRan/s=', 'base64')
10
11var createConfig = require('ssb-config/inject')
12
13module.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' || opts == null)
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
53
54

Built with git-ssb-web