const Server = require('scuttle-testbot') const Keys = require('ssb-keys') const Test = require('tape') const pull = require('pull-stream') const get = require('lodash/get') const pry = require('pryjs') // Generate two identities and start two test servers const alice = Keys.generate() const bob = Keys.generate() Server .use(require('ssb-private')) .use(require('../index.js')) const aliceConfig = { name: "alicetestbot", keys: alice } const aliceServer = new Server(aliceConfig) Server .use(require('ssb-private')) .use(require('../index.js')) const bobConfig = { name: "bobtestbot", keys: bob } const bobServer = new Server(bobConfig) var root Test("it publishes an encrypted secret root that is only visible to Alice", t => { aliceServer.private.publish({ module: "secrets", type: "root" }, [ aliceConfig.keys.id ], (err, msg) => { var { author, content } = msg.value root = msg.key // Author is Alice t.equal(alice.id, author) t.notEqual(bob.id, author) // Decrypt var decryptByAlice = aliceServer.private.unbox(content) var decryptByBob = bobServer.private.unbox(content) t.equal(get(decryptByAlice, "module"), "secrets") t.notEqual(get(decryptByBob, "module"), "secrets") t.equal(get(decryptByAlice, "type"), "root") t.notEqual(get(decryptByBob, "type"), "root") t.end() }) }) Test("it returns a collection of invites", t => { aliceServer.private.publish({ module: "secrets", type: "invite", root: root }, [ aliceConfig.keys.id, bobConfig.keys.id ], (err, invite) => { pull( aliceServer.secrets.invites.stream(), pull.drain(msg => { t.equal(msg[root].length, 1) t.equal(msg[root][0].id, invite.key) t.end() }) ) }) })