git ssb

2+

Dominic / ssb-client



Tree: 1e900424c4eed54c9b8e8d2ef56c1e490498b3bf

Files: 1e900424c4eed54c9b8e8d2ef56c1e490498b3bf / index.js

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

Built with git-ssb-web