Skip to content

Commit

Permalink
Merge pull request #109 from ssbc/get-own-dm-re-enable
Browse files Browse the repository at this point in the history
Re-enable ownKeys.list and ownKeys.register
  • Loading branch information
Powersource authored Nov 7, 2023
2 parents f324d2a + 5ca89c1 commit 71cd7e0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 22 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 @@ -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)
}
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
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)()
})

0 comments on commit 71cd7e0

Please sign in to comment.