var page = require('../../page.part')
var com = require('../../com.part')
module.exports = () => page({
section: 'docs',
tab: 'docs-basics',
path :'/docs/basics/encryption.html',
content: `
Publish an Encrypted Message
${ com.code({ js: jsSnippet1 }) }
Decrypt a Message
${ com.code({ js: jsSnippet2 })}
Is a message encrypted?
${ com.code({ js: jsSnippet3 })}
Follow users
`
})
var jsSnippet1 = `
sbot.private.publish(
// message:
{
type: 'post',
text: 'Hello, friend!'
},
// recipient PKs:
[
'@hxGxqPrplLjRG2vtj...wQpS730nNwE=.ed25519',
'@EMovhfIrFk4NihAKn...8pTxJNgvCCY=.ed25519'
],
// cb:
function (err, privateMsg) {
// privateMsg.value.content is
// an encrypted string
}
)
`
var jsSnippet2 = `
sbot.private.unbox(
privateMsg.value.content,
function (err, content) {
// 'content' is now an object
// (if you were a recipient)
}
)
`
var jsSnippet3 = `
function isPlaintext (msg) {
return (typeof msg.value.content == 'object')
}
function isEncrypted (msg) {
return (typeof msg.value.content == 'string')
}
`