From c1ec519a5f770704f6dc418f9121927f94a46f66 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Thu, 2 Nov 2023 21:20:38 +0100 Subject: [PATCH 1/5] Install box2 with getOwnDMKey fn --- README.md | 2 +- package-lock.json | 6 +++--- package.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a250799..ab69684 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` >= TODO - `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`. diff --git a/package-lock.json b/package-lock.json index 069df3e..a5a1b03 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": "github:ssbc/ssb-box2#get-own-dm", "ssb-db2": "^7.1.1", "ssb-replicate": "^1.3.3", "standard": "^17.1.0", @@ -5073,9 +5073,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==", + "resolved": "git+ssh://git@github.com/ssbc/ssb-box2.git#39e35310591ae24a4ee1b5d8c9c9244170b7979e", "dev": true, + "license": "LGPL-3.0-only", "dependencies": { "envelope-js": "^1.3.2", "private-group-spec": "^2.1.1", diff --git a/package.json b/package.json index 2382753..8863126 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": "github:ssbc/ssb-box2#get-own-dm", "ssb-db2": "^7.1.1", "ssb-replicate": "^1.3.3", "standard": "^17.1.0", From aded0206f990168943874038721bae1d49c0db5f Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Thu, 2 Nov 2023 21:34:47 +0100 Subject: [PATCH 2/5] Re-enable ownKey functions and document in readme --- README.md | 3 +++ index.js | 28 ++++++++++++---------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index ab69684..ea304a7 100644 --- a/README.md +++ b/README.md @@ -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) + } + } } } From dc58f150a24f80e79d84857017b4ac45d697e495 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Thu, 2 Nov 2023 22:01:23 +0100 Subject: [PATCH 3/5] Add test for ownKeys --- test/api/own-keys/register-and-list.test.js | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/api/own-keys/register-and-list.test.js 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..699d8ef --- /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)() +}) \ No newline at end of file From 86e79eedbe131d02651101c5c11864d1d978b6c1 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Thu, 2 Nov 2023 22:02:12 +0100 Subject: [PATCH 4/5] Fix lint --- test/api/own-keys/register-and-list.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/api/own-keys/register-and-list.test.js b/test/api/own-keys/register-and-list.test.js index 699d8ef..55f4e62 100644 --- a/test/api/own-keys/register-and-list.test.js +++ b/test/api/own-keys/register-and-list.test.js @@ -20,4 +20,4 @@ test('can set and get own self dm key', async (t) => { t.equal(gottenKey.scheme, keySchemes.feed_id_self, 'got correct scheme') await p(alice.close)() -}) \ No newline at end of file +}) From 5ca89c13d21e83f89e0de4f2f95b73ea7fc671a6 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Tue, 7 Nov 2023 13:52:54 +0100 Subject: [PATCH 5/5] Update box2 with getDM fn --- README.md | 2 +- package-lock.json | 8 ++++---- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ea304a7..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` >= TODO +- `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`. diff --git a/package-lock.json b/package-lock.json index a5a1b03..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": "github:ssbc/ssb-box2#get-own-dm", + "ssb-box2": "^7.4.0", "ssb-db2": "^7.1.1", "ssb-replicate": "^1.3.3", "standard": "^17.1.0", @@ -5072,10 +5072,10 @@ } }, "node_modules/ssb-box2": { - "version": "7.2.0", - "resolved": "git+ssh://git@github.com/ssbc/ssb-box2.git#39e35310591ae24a4ee1b5d8c9c9244170b7979e", + "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, - "license": "LGPL-3.0-only", "dependencies": { "envelope-js": "^1.3.2", "private-group-spec": "^2.1.1", diff --git a/package.json b/package.json index 8863126..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": "github:ssbc/ssb-box2#get-own-dm", + "ssb-box2": "^7.4.0", "ssb-db2": "^7.1.1", "ssb-replicate": "^1.3.3", "standard": "^17.1.0",