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

Add test for group decrypt vectors #35

Merged
merged 6 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"ssb-meta-feeds": "~0.38.0",
"ssb-query": "^2.4.5",
"ssb-tribes": "^2.7.4",
"ssb-tribes-vectors": "github:ssbc/ssb-tribes",
Powersource marked this conversation as resolved.
Show resolved Hide resolved
"tap-arc": "^0.3.4",
"tape": "^5.2.2"
},
Expand Down
38 changes: 38 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// SPDX-License-Identifier: Unlicense

const { promisify: p } = require('util')
const test = require('tape')
const { check } = require('ssb-encryption-format')
const ssbKeys = require('ssb-keys')
Expand Down Expand Up @@ -352,3 +353,40 @@ test('encrypt accepts keys as recps', (t) => {
t.end()
})
})

test('decrypt group vectors', async (t) => {
const vectors = [
require('ssb-tribes-vectors/test/vectors/unbox1.json'),
require('ssb-tribes-vectors/test/vectors/unbox2.json')
Powersource marked this conversation as resolved.
Show resolved Hide resolved
]

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')
}
})
Loading