-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add groupkey in init msg #62
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,30 +143,31 @@ module.exports = { | |
}) | ||
} | ||
|
||
function secretKeyFromPurpose(purpose) { | ||
return new SecretKey(Buffer.from(purpose, 'base64')) | ||
function secretKeyFromString(string) { | ||
return new SecretKey(Buffer.from(string, 'base64')) | ||
} | ||
|
||
function createGroupWithoutMembers(myRoot, cb) { | ||
const content = { | ||
type: 'group/init', | ||
tangles: { | ||
group: { root: null, previous: null }, | ||
}, | ||
} | ||
if (!initSpec(content)) return cb(new Error(initSpec.errorsString)) | ||
|
||
findOrCreateGroupFeed(null, function gotGroupFeed(err, groupFeed) { | ||
// prettier-ignore | ||
if (err) return cb(clarify(err, 'Failed to find or create group feed when creating a group')) | ||
|
||
const secret = secretKeyFromPurpose(groupFeed.purpose) | ||
const secret = secretKeyFromString(groupFeed.purpose) | ||
|
||
const recps = [ | ||
{ key: secret.toBuffer(), scheme: keySchemes.private_group }, | ||
myRoot.id, | ||
] | ||
|
||
const content = { | ||
type: 'group/init', | ||
groupKey: secret.toString('base64'), | ||
tangles: { | ||
group: { root: null, previous: null }, | ||
}, | ||
} | ||
if (!initSpec(content)) return cb(new Error(initSpec.errorsString)) | ||
|
||
ssb.db.create( | ||
{ | ||
keys: groupFeed.keys, | ||
|
@@ -257,37 +258,37 @@ module.exports = { | |
function create(opts = {}, cb) { | ||
if (cb === undefined) return promisify(create)(opts) | ||
|
||
findOrCreateGroupWithoutMembers( | ||
(err, { groupInitMsg, groupFeed, myRoot }) => { | ||
// prettier-ignore | ||
if (err) return cb(clarify(err, 'Failed to create group init message when creating a group')) | ||
|
||
const secret = secretKeyFromPurpose(groupFeed.purpose) | ||
|
||
const data = { | ||
id: buildGroupId({ | ||
groupInitMsg, | ||
groupKey: secret.toBuffer(), | ||
}), | ||
secret: secret.toBuffer(), | ||
root: fromMessageSigil(groupInitMsg.key), | ||
subfeed: groupFeed.keys, | ||
} | ||
findOrCreateGroupWithoutMembers((err, group) => { | ||
// prettier-ignore | ||
if (err) return cb(clarify(err, 'Failed to create group init message when creating a group')) | ||
|
||
ssb.box2.addGroupInfo(data.id, { | ||
key: data.secret, | ||
root: data.root, | ||
}) | ||
const { groupInitMsg, groupFeed, myRoot } = group | ||
|
||
// Adding myself for recovery reasons | ||
addMembers(data.id, [myRoot.id], {}, (err) => { | ||
// prettier-ignore | ||
if (err) return cb(clarify(err, 'Failed to add myself to the group when creating a group')) | ||
const secret = secretKeyFromString(groupFeed.purpose) | ||
|
||
return cb(null, data) | ||
}) | ||
const data = { | ||
id: buildGroupId({ | ||
groupInitMsg, | ||
groupKey: secret.toBuffer(), | ||
}), | ||
secret: secret.toBuffer(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, could name this |
||
root: fromMessageSigil(groupInitMsg.key), | ||
subfeed: groupFeed.keys, | ||
} | ||
) | ||
|
||
ssb.box2.addGroupInfo(data.id, { | ||
key: data.secret, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Case in point: the key is the secret is the key is the secret. |
||
root: data.root, | ||
}) | ||
|
||
// Adding myself for recovery reasons | ||
addMembers(data.id, [myRoot.id], {}, (err) => { | ||
// prettier-ignore | ||
if (err) return cb(clarify(err, 'Failed to add myself to the group when creating a group')) | ||
|
||
return cb(null, data) | ||
}) | ||
}) | ||
} | ||
|
||
function get(id, cb) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big deal, but a small suggestion:
We seem to be going back and forth with this naming, "secret" or "group key", but we could try to be at least internally consistent (all namings of this thing in ssb-tribes2 are the same).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem here is the spec calls it groupKey and the tribes2 api says secret. I think the proper way for fixing is a separate issue/pr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this pr is just for conforming to the spec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay!