diff --git a/README.md b/README.md index a250799..f70c1de 100644 --- a/README.md +++ b/README.md @@ -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`. @@ -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) diff --git a/index.js b/index.js index c8cd188..6095a3b 100644 --- a/index.js +++ b/index.js @@ -371,24 +371,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) + } + } } } diff --git a/package-lock.json b/package-lock.json index 069df3e..622bcee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,7 +35,7 @@ "cross-env": "^7.0.3", "is-canonical-base64": "^1.1.1", "scuttle-testbot": "^2.1.0", - "ssb-box2": "^7.2.0", + "ssb-box2": "^7.4.0", "ssb-db2": "^7.1.1", "ssb-replicate": "^1.3.3", "standard": "^17.1.0", @@ -5072,9 +5072,9 @@ } }, "node_modules/ssb-box2": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/ssb-box2/-/ssb-box2-7.2.0.tgz", - "integrity": "sha512-LOIgzULj8wNPNk89zmLTRcc35Xq35uOuG/4Rq74ae4pPVY50oYEir7mdRNRiAjuIPTxbVmY6YwXVUehBEkxk1w==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/ssb-box2/-/ssb-box2-7.4.0.tgz", + "integrity": "sha512-LH4NeFnKrIYEYKJZOFWkaJKgjN5ZTTDdplFkuUGr7GA36oPfvapAz/xrFIVE3Q3I+ffBZmjbWGIQe/aiWuhi7A==", "dev": true, "dependencies": { "envelope-js": "^1.3.2", diff --git a/package.json b/package.json index 2382753..7ba1b2c 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "cross-env": "^7.0.3", "is-canonical-base64": "^1.1.1", "scuttle-testbot": "^2.1.0", - "ssb-box2": "^7.2.0", + "ssb-box2": "^7.4.0", "ssb-db2": "^7.1.1", "ssb-replicate": "^1.3.3", "standard": "^17.1.0", diff --git a/test/api/own-keys/register-and-list.test.js b/test/api/own-keys/register-and-list.test.js new file mode 100644 index 0000000..55f4e62 --- /dev/null +++ b/test/api/own-keys/register-and-list.test.js @@ -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)() +})