git ssb

0+

dangerousbeans / patchbay-bootstrap



Commit ab735d7e103ab61e1882fbb1972e368f6f1a3cae

tidy up where keys are loaded from

Dominic Tarr committed on 7/3/2016, 4:22:39 AM
Parent: d9bcc5180453d63b194da471d3e225d18a337a3c

Files changed

modules/crypto.jschanged
sbot-api.jschanged
keys.jsadded
modules/crypto.jsView
@@ -1,10 +1,7 @@
1-var path = require('path')
1+var ref = require('ssb-ref')
2+var keys = require('../keys')
23 var ssbKeys = require('ssb-keys')
3-var ref = require('ssb-ref')
4-var config = require('ssb-config/inject')(process.env.ssb_appname)
5-var keys = ssbKeys
6- .loadSync(path.join(config.path, 'secret'))
74
85 function unbox_value(msg) {
96 var plaintext = ssbKeys.unbox(msg.content, keys)
107 if(!plaintext) return null
@@ -50,4 +47,6 @@
5047 }
5148
5249
5350
51+
52+
sbot-api.jsView
@@ -14,26 +14,43 @@
1414 if(err && !onHash) throw err
1515 onHash && onHash(err, '&'+hash.digest('base64')+'.sha256')
1616 })
1717 }
18-var createClient = require('ssb-client')
18+var createClient = require('ssb-lite')
19+//var createClient = require('ssb-client')
20+var createConfig = require('ssb-config/inject')
21+//var createClient = require('./lite')
22+var createFeed = require('ssb-feed')
23+var keys = require('./keys')
1924
25+
2026 module.exports = function () {
27+ var opts = createConfig()
2128 var sbot = null
29+
2230 var rec = Reconnect(function (isConn) {
23- console.log("RECONNECT", isConn)
24- createClient(function (err, _sbot) {
31+ createClient(keys, opts, function (err, _sbot) {
2532 if(err) {console.error(err.stack); isConn(err)}
2633 sbot = _sbot
2734 sbot.on('closed', function () {
28- console.log("DISCONNECT")
2935 sbot = null
3036 isConn(new Error('closed'))
3137 })
3238 isConn()
3339 })
3440 })
3541
42+ var internal = {
43+ getLatest: rec.async(function (id, cb) {
44+ sbot.getLatest(id, cb)
45+ }),
46+ add: rec.async(function (msg, cb) {
47+ sbot.add(msg, cb)
48+ })
49+ }
50+
51+ var feed = createFeed(internal, keys)
52+
3653 return {
3754 sbot_blobs_add: rec.sink(function (cb) {
3855 return pull(
3956 Hash(cb),
@@ -58,13 +75,27 @@
5875 sbot_get: rec.async(function (key, cb) {
5976 sbot.get(key, cb)
6077 }),
6178 sbot_publish: rec.async(function (msg, cb) {
62- sbot.publish(msg, cb)
79+ feed.add(msg, function (err, msg) {
80+ cb(err, msg)
81+ })
6382 }),
6483 sbot_whoami: rec.async(function (cb) {
6584 sbot.whoami(cb)
6685 })
6786 }
6887 }
6988
7089
90+
91+
92+
93+
94+
95+
96+
97+
98+
99+
100+
101+
keys.jsView
@@ -1,0 +1,5 @@
1+var config = require('ssb-config/inject')(process.env.ssb_appname)
2+var ssbKeys = require('ssb-keys')
3+var path = require('path')
4+module.exports = ssbKeys.loadOrCreateSync(path.join(config.path, 'secret'))
5+

Built with git-ssb-web