Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable ownKeys.list and ownKeys.register #109

Merged
merged 5 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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` >= TODO
Powersource marked this conversation as resolved.
Show resolved Hide resolved
- `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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be good to call it set .. as it's not just registering, but rather setting the one you will use

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah agree but i think there's so many breaking changes atm, i think it's better to do this at some later point

ssb.box2.setOwnDMKey(key)
}
}
}
}

Expand Down
6 changes: 3 additions & 3 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": "github:ssbc/ssb-box2#get-own-dm",
Powersource marked this conversation as resolved.
Show resolved Hide resolved
"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)()
})