How to use the ssb-keys.box function in ssb-keys

To help you get started, we’ve selected a few ssb-keys examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ssbc / ssb-db / test / end-to-end.js View on Github external
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
github ProjectEntropy / scuttle-vue / modules / sbot.js View on Github external
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)
        })
      }),
github Happy0 / ssb-chess / modules_core / sbot.js View on Github external
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)
        })
github mmckegg / patchwork-next / api / index.js View on Github external
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)
      })
github staltz / manyverse / src / backend / plugins / feedUtilsBack.ts View on Github external
publish(content: NonNullable<content>, cb: Callback) {
        if (content.recps) {
          content = ssbKeys.box(
            content,
            content.recps.map((e: any) =&gt; {
              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) =&gt; {
                if (err) console.error(err);
              });
            }
          }
        }

        ssb.publish(content, (err: any, msg: any) =&gt; {</content>
github mmckegg / patchwork-next / modules / sbot.js View on Github external
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)
        })
github ssbc / ssb-identities / index.js View on Github external
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)
        })
      })
    },
github blockades / scuttle-dark-crystal / shard / async / build.js View on Github external
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)
  }
}
github ssbc / ssb-server / plugins / private.js View on Github external
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) {
github Happy0 / ssb-chess / modules_core / crypto.js View on Github external
exports.message_box = function (content) {
  return ssbKeys.box(content, content.recps.map(function (e) {
    return ref.isFeed(e) ? e : e.link
  }))
}