Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ssbc/ssb-tribes into use-old-keyring
Browse files Browse the repository at this point in the history
  • Loading branch information
Powersource committed Nov 7, 2023
2 parents 9764982 + 6542a76 commit ab28827
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 87 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ A Secret-Stack server running the plugins:
- `ssb-tribes`
- `ssb-db2/compat`
- `ssb-db2/compat/feedstate`
- `ssb-box2` >= 7.2.0
- `ssb-box2` >= 7.4.0
- `ssb-replicate` - (optional) used to auto-replicate people who you're in groups with

The secret stack option `config.box2.legacyMode` also needs to be `true`.
Expand Down Expand Up @@ -212,6 +212,9 @@ These endpoints give you access to additional features, such as:
- `ssb.tribes.poBox.create(opts, cb)`
- `ssb.tribes.addPOBox(groupId, cb)`
- `ssb.tribes.poBox.get(groupId, cb)`
- **self-DM keys**
- `ssb.tribes.ownKeys.list(cb)`: returns a list of self-DM keyinfo. Always a length of 1 (only a list for historical reasons). The keyinfo has the format `{ key: Buffer, scheme: String }`.
- `ssb.tribes.ownKeys.register(key)`: sets the self-DM key (buffer).
- **managing people applying to join to a group**
- deprecated, please use [ssb-tribes-registration](https://gitlab.com/ahau/lib/ssb-plugins/ssb-tribes-registration)
- for the old docs, [see here](./README.deprecated.md)
Expand Down
28 changes: 12 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,24 +378,20 @@ function init (ssb, config) {
})
},
get: scuttle.group.getPOBox
}
},

// for internal use - ssb-ahau uses this for backups
// TODO: does ahau use this for backups though?
// i couldn't find a self.get function in box2 so we might have to add that if this is needed
// ownKeys: {
// list (cb) {
// onKeystoreReady(() => {
// cb(null, [keystore.self.get()])
// })
// },
// register (key, cb) {
// onKeystoreReady(() => {
// //ssb.box2.setOwnDMKey(key)
// keystore.self.set(key, cb)
// })
// }
// }
ownKeys: {
list (cb) {
ssb.box2.getOwnDMKey((err, dmKeyInfo) => {
if (err) return cb(Error("Couldn't get own dm key on ownKeys.list", { cause: err }))
return cb(null, [dmKeyInfo])
})
},
register (key) {
ssb.box2.setOwnDMKey(key)
}
}
}
}

Expand Down
167 changes: 111 additions & 56 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
"devDependencies": {
"cross-env": "^7.0.3",
"is-canonical-base64": "^1.1.1",
"scuttle-testbot": "^2.1.0",
"scuttle-testbot": "^2.2.0",
"ssb-box2": "^7.4.0",
"ssb-db2": "^7.1.1",
"ssb-db2": "^8.0.0",
"ssb-replicate": "^1.3.3",
"standard": "^17.1.0",
"tap-arc": "^0.4.0",
Expand Down
23 changes: 23 additions & 0 deletions test/api/own-keys/register-and-list.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { promisify: p } = require('util')
const test = require('tape')
const { keySchemes } = require('private-group-spec')
const { Server } = require('../../helpers')

test('can set and get own self dm key', async (t) => {
const alice = Server()

const ownKey = Buffer.from(
'30720d8f9cbf37f6d7062826f6decac93e308060a8aaaa77e6a4747f40ee1a76',
'hex'
)

alice.tribes.ownKeys.register(ownKey)

const gottenKeyList = await p(alice.tribes.ownKeys.list)()
const gottenKey = gottenKeyList[0]

t.equal(gottenKey.key, ownKey, 'got correct key')
t.equal(gottenKey.scheme, keySchemes.feed_id_self, 'got correct scheme')

await p(alice.close)()
})
5 changes: 3 additions & 2 deletions test/helpers/test-bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = function TestBot (opts = {}) {
.use(require('ssb-classic'))
.use(require('ssb-db2/compat'))
.use(require('ssb-db2/compat/feedstate'))
.use(require("ssb-db2/compat/post"))
.use(require('ssb-box2'))
.use(require('../..'))

Expand All @@ -29,8 +30,8 @@ module.exports = function TestBot (opts = {}) {
legacyMode: true,
...opts.box2
},
// we don't want testbot to import db2 for us, we want more granularity and control of dep versions
db1: true
// we don't want testbot to import db1 or db2 for us, we want to control what db2 plugins get imported
noDefaultUse: true,
})

if (opts.debug) {
Expand Down
12 changes: 2 additions & 10 deletions test/rebuild.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ test('rebuild (I am added to a group)', async t => {
// time for rebuilding
await p(setTimeout)(500)

t.true(me.status().sync.sync, 'all indexes updated')

const msgs = await pull(
me.db.query(
where(and(
Expand Down Expand Up @@ -243,12 +241,6 @@ test('rebuild from listen.addMember', t => {
// NOTE with auto-rebuild active, this listener gets hit twice:
// 1. first time we see group/add-member (unboxed with DM key)
// 2. after rebuild
function checkRebuildDone (done) {
if (A.status().sync.sync) return done()

console.log('waiting for rebuild')
setTimeout(() => checkRebuildDone(done), 500)
}
pull(
listen.addMember(A),
pull.filter(m => !m.sync),
Expand All @@ -259,12 +251,12 @@ test('rebuild from listen.addMember', t => {
// (2) B invites A

if (heardCount === 2) {
checkRebuildDone(() => {
setTimeout(() => {
A.close(err => {
t.error(err, 'A closed')
t.end()
})
})
}, 500)
}
})
)
Expand Down

0 comments on commit ab28827

Please sign in to comment.