Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pull.collect(function (err, ary) {
if (err) throw err
console.log('ALICE', alice.id)
console.log('SSB', ssb.id)
var msg = ary[0].value
var ctxt = msg.content
var content = ssbKeys.unbox(ctxt, alice.private)
t.deepEqual(content, { type: 'secret', okay: true }, 'alice can decrypt')
// bob can also decrypt
var content2 = ssbKeys.unbox(ctxt, bob.private)
t.deepEqual(content, { type: 'secret', okay: true }, 'bob can decrypt')
var pmsg = ssb.unbox(ary[0])
t.notOk(msg.unbox, 'did not mutate original message')
var unboxKey = pmsg.value.unbox
t.equal(typeof unboxKey, 'string')
t.ok(pmsg)
t.deepEqual(pmsg.value.content, content2)
console.log('boxed', ary[0].value)
ssb2.add(ary[0].value, function (err) {
if (err) throw err
pull.collect(function (err, ary) {
if (err) throw err
console.log('ALICE', alice.id)
console.log('SSB', ssb.id)
var msg = ary[0].value
var ctxt = msg.content
var content = ssbKeys.unbox(ctxt, alice.private)
t.deepEqual(content, { type: 'secret', okay: true }, 'alice can decrypt')
// bob can also decrypt
var content2 = ssbKeys.unbox(ctxt, bob.private)
t.deepEqual(content, { type: 'secret', okay: true }, 'bob can decrypt')
var pmsg = ssb.unbox(ary[0])
t.notOk(msg.unbox, 'did not mutate original message')
var unboxKey = pmsg.value.unbox
t.equal(typeof unboxKey, 'string')
t.ok(pmsg)
t.deepEqual(pmsg.value.content, content2)
console.log('boxed', ary[0].value)
ssb2.add(ary[0].value, function (err) {
if (err) throw err
ssb2.get({ id: pmsg.key, private: true }, function (err, _msg) {
if (err) throw err
console.log('LOAD', _msg)
t.deepEqual(_msg, msg) // not decrypted
function unbox_value(msg) {
var plaintext = ssbKeys.unbox(msg.content, keys)
if(!plaintext) return null
return {
previous: msg.previous,
author: msg.author,
sequence: msg.sequence,
timestamp: msg.timestamp,
hash: msg.hash,
content: plaintext,
private: true
}
}
unbox: function (ciphertext) {
var data
try { data = ssbKeys.unbox(ciphertext, sbot.keys.private) }
catch (e) { throw explain(e, 'failed to decrypt') }
return data
}
}