Skip to content

Commit

Permalink
Merge pull request #35 from ssbc/group-test-vectors
Browse files Browse the repository at this point in the history
Add test for group decrypt vectors
  • Loading branch information
Powersource authored Nov 7, 2023
2 parents 610120d + f9a21ef commit fe9eec2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
37 changes: 37 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit fe9eec2

Please sign in to comment.