Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
tape('add encrypted message', function (t) {
var boxed = ssbKeys.box({ type: 'secret', okay: true }, [alice.public, bob.public])
ssb.post(function (msg) {
t.equal('string', typeof msg.value.content, 'messages should not be decrypted')
})
feed.add(boxed, function (err, msg) {
if (err) throw err
t.notOk(err)
pull(
ssb.messagesByType('secret'),
pull.collect(function (err, ary) {
if (err) throw err
console.log('ALICE', alice.id)
console.log('SSB', ssb.id)
var msg = ary[0].value
sbot_publish: rec.async(function (content, cb) {
if(content.recps)
content = ssbKeys.box(content, content.recps.map(function (e) {
return ref.isFeed(e) ? e : e.link
}))
else if(content.mentions)
content.mentions.forEach(function (mention) {
if(ref.isBlob(mention.link)) {
sbot.blobs.push(mention.link, function (err) {
if(err) console.error(err)
})
}
})
feed.add(content, function (err, msg) {
if(err) console.error(err)
else if(!cb) console.log(msg)
cb && cb(err, msg)
})
}),
sbot_publish: rec.async(function (content, cb) {
if(content.recps)
content = ssbKeys.box(content, content.recps.map(function (e) {
return ref.isFeed(e) ? e : e.link
}))
else if(content.mentions)
content.mentions.forEach(function (mention) {
if(ref.isBlob(mention.link)) {
sbot.blobs.push(mention.link, function (err) {
if(err) console.error(err)
})
}
})
feed.add(content, function (err, msg) {
if(err) console.error(err)
else if(!cb) console.log(msg)
cb && cb(err, msg)
})
sbot_publish: function (content, cb) {
if(content.recps)
content = ssbKeys.box(content, content.recps.map(function (e) {
return ref.isFeed(e) ? e : e.link
}))
else if(content.mentions)
content.mentions.forEach(function (mention) {
if(ref.isBlob(mention.link)) {
sbot.blobs.push(mention.link, function (err) {
if(err) console.error(err)
})
}
})
feed.add(content, function (err, msg) {
if(err) console.error(err)
else if(!cb) console.log(msg)
cb && cb(err, msg)
})
publish(content: NonNullable<content>, cb: Callback) {
if (content.recps) {
content = ssbKeys.box(
content,
content.recps.map((e: any) => {
return Ref.isFeed(e) ? e : e.link;
}),
);
} else if ((content as PostContent).mentions) {
for (const mention of (content as PostContent).mentions!) {
if (Ref.isBlob(mention.link)) {
ssb.blobs.push(mention.link, (err: any) => {
if (err) console.error(err);
});
}
}
}
ssb.publish(content, (err: any, msg: any) => {</content>
publish: rec.async(function (content, cb) {
if(content.recps)
content = ssbKeys.box(content, content.recps.map(function (e) {
return ref.isFeed(e) ? e : e.link
}))
else if(content.mentions)
content.mentions.forEach(function (mention) {
if(ref.isBlob(mention.link)) {
sbot.blobs.push(mention.link, function (err) {
if(err) console.error(err)
})
}
})
feed.add(content, function (err, msg) {
if(err) console.error(err)
else if(!cb) console.log(msg)
cb && cb(err, msg)
})
var _keys = sbot.id === id ? sbot.keys : keys.find(function (e) {
return id === e.id
})
if(!_keys) return cb(new Error('must provide id of listed identities'))
var content = opts.content
var recps = [].concat(content.recps).map(toTarget)
if(content.recps && !opts.private)
return cb(new Error('recps set, but opts.private not set'))
else if(!content.recps && opts.private)
return cb(new Error('opts.private set, but content.recps not set'))
else if(!!content.recps && opts.private) {
if(!Array.isArray(content.recps) || !~recps.indexOf(id))
return cb(new Error('content.recps must be an array containing publisher id:'+id+' was:'+JSON.stringify(recps)+' indexOf:'+recps.indexOf(id)))
content = ssbKeys.box(content, recps)
}
locks[id] = true
sbot.getLatest(id, function (err, data) {
var state = data ? {
id: data.key,
sequence: data.value.sequence,
timestamp: data.value.timestamp,
queue: []
} : {id: null, sequence: null, timestamp: null, queue: []}
sbot.add(create(state, _keys, config.caps && config.caps.sign, content, Date.now()), function (err, a, b) {
delete locks[id]
cb(err, a, b)
})
})
},
return function ({ root, shard, recp }, cb) {
const content = {
type: 'dark-crystal/shard',
version: '2.0.0',
root,
shard: box(shard, [recp]),
recps: [recp, server.id]
}
if (!isShard(content)) return cb(errorParser(content))
cb(null, content)
}
}
publish: function (data, recps, cb) {
var ciphertext
try { ciphertext = ssbKeys.box(data, recps) }
catch (e) { return cb(explain(e, 'failed to encrypt')) }
sbot.publish(ciphertext, cb)
},
unbox: function (ciphertext) {
exports.message_box = function (content) {
return ssbKeys.box(content, content.recps.map(function (e) {
return ref.isFeed(e) ? e : e.link
}))
}