ssbc/ssb-example-pm

Name: ssb-example-pm

Owner: Secure Scuttlebutt Consortium

Description: Send and receive encrypted messages on ssb

Created: 2015-10-02 20:33:07.0

Updated: 2017-11-15 19:17:40.0

Pushed: 2017-10-07 02:21:48.0

Homepage: null

Size: 0

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Example Private Message

Send and receive encrypted messages on ssb

t clone https://github.com/ssbc/ssb-example-pm.git
 ssb-example-pm
m install

ssb-example-pm.js -h
 messages: ssb-example-pm.js
 message:  ssb-example-pm.js {recp} [message...]

ssb-example-pm.js @hxGxqPrplLjRG2vtjQL87abX4QKqeLgCwQpS730nNwE=.ed25519 "hello, this is a big secret"
ssb-example-pm.js

nute ago   you 

o there, this is a big secret
How it works

Normally, messages have an object in the content attribute. If content is a string, that means the message is encrypted – the string is the base64-encoded ciphertext. Recipients are hidden, so we try to decrypt. If successful, the message was for the user:

ist private messages
tion listPMs (sbot, selfId) {
ll(
// all type: post messages, in order received
sbot.messagesByType('post'),

// encrypted?
pull.filter(function (msg) { return typeof msg.value.content === 'string' }),

// attempt to decrypt    
pull.asyncMap(function (msg, cb) {
  sbot.private.unbox(msg.value.content, function (err, content) {
    if (content)
      msg.value.content = content
    cb(null, msg)
  })
}),

// successfully decrypted?
pull.filter(function (msg) { return typeof msg.value.content !== 'string' }),

// render
pull.drain(renderPost.bind(null, selfId), function (err) {
  if (err) throw err
  sbot.close()
})


To publish, we use https://github.com/ssbc/ssb-message-schemas to build the message content, and sbot.private.publish to write to the feed. Note, the local user is included in the recipients, so we can read our own messages.

tion publishPM (sbot, selfId, recpId, msg) {
r recps = (selfId !== recpId) ? [selfId, recpId] : [selfId]

 create the type: post message
r post = schemas.post(
msg,  // text content
null, // reply topmost msg
null, // reply parent
null, // mention links
recps // recipient links

ot.private.publish(post, recps, function (err, msg) {
if (err) throw err
sbot.close()



This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.