Skip to content

Commit

Permalink
Add test for group decrypt vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Powersource committed Oct 25, 2023
1 parent 6cef638 commit 2f2b032
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
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",
"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')
]

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

0 comments on commit 2f2b032

Please sign in to comment.