diff --git a/package.json b/package.json index 146fe05..a69f034 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,6 @@ ], "dependencies": { "envelope-js": "^1.3.2", - "private-group-spec": "^2.1.1", "pull-defer": "^0.2.3", "pull-stream": "^3.6.14", "ssb-bfe": "^3.7.0", @@ -32,6 +31,7 @@ "mkdirp": "^1.0.4", "prettier": "^2.6.2", "pretty-quick": "^3.1.3", + "private-group-spec": "^8.1.0", "pull-cat": "1.1.11", "rimraf": "^3.0.2", "secret-stack": "6.3.2", diff --git a/test/index.js b/test/index.js index 2312dd1..304decc 100644 --- a/test/index.js +++ b/test/index.js @@ -375,6 +375,43 @@ test('encrypt accepts keys as recps', (t) => { }) }) +test('decrypt group vectors', async (t) => { + const vectors = [ + require('private-group-spec/vectors/unbox1.classic.json'), + require('private-group-spec/vectors/unbox2.classic.json') + ] + + for (let i = 0; i < vectors.length; i++) { + const vector = vectors[i] + + const keys = ssbKeys.generate(null, 'alice', 'classic') + const box2 = Box2() + + await p(box2.setup)({ keys }) + + // random letters, but shouldn't matter + const groupId = '%boopadoopt5CihjbOY6eZc0qCe0eKsrN2wfgXV2E3PM=.cloaked' + + await Promise.all(vector.input.trial_keys.map(trial_key => + box2.addGroupInfo(groupId, trial_key) + )) + + const msg = vector.input.msgs[0] + + const ciphertext = Buffer.from(msg.value.content.replace('.box2', ''), 'base64') + + const opts = { + previous: msg.value.previous, + author: msg.value.author + } + const decrypted = box2.decrypt(ciphertext, opts) + + const plaintext = Buffer.from(JSON.stringify(vector.output.msgsContent[0]), 'utf8') + + t.deepEqual(decrypted, plaintext, 'decrypted plaintext is the same') + } +}) + test('decrypt as pobox recipient', (t) => { const box2 = Box2() const keys = ssbKeys.generate(null, 'alice', 'classic')