git ssb

2+

cel / scuttlebot.io



Tree: 9e4b77aeb7181a93a9ee3ceb1c21d11841a35f57

Files: 9e4b77aeb7181a93a9ee3ceb1c21d11841a35f57 / tmpl / basics / encryption.html.js

1350 bytesRaw
1var page = require('../page.part')
2var com = require('../com.part')
3
4module.exports = () => page({
5 tab: 'basics',
6 path: '/basics/encryption.html',
7 content: `
8 <h2>Publish an Encrypted Message</h2>
9 ${ com.code({ js: jsSnippet1 }) }
10 <h2>Decrypt a Message</h2>
11 ${ com.code({ js: jsSnippet2 })}
12 <h2>Is a message encrypted?</h2>
13 ${ com.code({ js: jsSnippet3 })}
14 <p class="next"><a href="/basics/publish-a-file.html">Publish a file</a></p>
15 <ul class="see-also">
16 <li><a href="/advanced/private-box.html">Private Box</a></li>
17 <li><a href="/advanced/linking-messages.html">Linking messages</a></li>
18 </ul>
19 `
20})
21
22var jsSnippet1 = `
23ssb.private.publish(
24 // message:
25 {
26 type: 'post',
27 text: 'Hello, friend!'
28 },
29 // recipient PKs:
30 [
31 '@hxGxqPrplLjRG2vtj...wQpS730nNwE=.ed25519',
32 '@EMovhfIrFk4NihAKn...8pTxJNgvCCY=.ed25519'
33 ],
34 // cb:
35 function (err, privateMsg) {
36 // privateMsg.value.content is
37 // an encrypted string
38 }
39)
40`
41
42var jsSnippet2 = `
43ssb.private.unbox(
44 privateMsg.value.content,
45 function (err, content) {
46 // 'content' is now an object
47 // (if you were a recipient)
48 }
49)
50`
51
52var jsSnippet3 = `
53function isPlaintext (msg) {
54 return (typeof msg.value.content == 'object')
55}
56function isEncrypted (msg) {
57 return (typeof msg.value.content == 'string')
58}
59`

Built with git-ssb-web