How to use the ssb-keys.unbox 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
pull.collect(function (err, ary) {
          if (err) throw err
          console.log('ALICE', alice.id)
          console.log('SSB', ssb.id)
          var msg = ary[0].value
          var ctxt = msg.content
          var content = ssbKeys.unbox(ctxt, alice.private)
          t.deepEqual(content, { type: 'secret', okay: true }, 'alice can decrypt')

          // bob can also decrypt
          var content2 = ssbKeys.unbox(ctxt, bob.private)
          t.deepEqual(content, { type: 'secret', okay: true }, 'bob can decrypt')

          var pmsg = ssb.unbox(ary[0])
          t.notOk(msg.unbox, 'did not mutate original message')
          var unboxKey = pmsg.value.unbox
          t.equal(typeof unboxKey, 'string')
          t.ok(pmsg)
          t.deepEqual(pmsg.value.content, content2)

          console.log('boxed', ary[0].value)
          ssb2.add(ary[0].value, function (err) {
            if (err) throw err
github ssbc / ssb-db / test / end-to-end.js View on Github external
pull.collect(function (err, ary) {
          if (err) throw err
          console.log('ALICE', alice.id)
          console.log('SSB', ssb.id)
          var msg = ary[0].value
          var ctxt = msg.content
          var content = ssbKeys.unbox(ctxt, alice.private)
          t.deepEqual(content, { type: 'secret', okay: true }, 'alice can decrypt')

          // bob can also decrypt
          var content2 = ssbKeys.unbox(ctxt, bob.private)
          t.deepEqual(content, { type: 'secret', okay: true }, 'bob can decrypt')

          var pmsg = ssb.unbox(ary[0])
          t.notOk(msg.unbox, 'did not mutate original message')
          var unboxKey = pmsg.value.unbox
          t.equal(typeof unboxKey, 'string')
          t.ok(pmsg)
          t.deepEqual(pmsg.value.content, content2)

          console.log('boxed', ary[0].value)
          ssb2.add(ary[0].value, function (err) {
            if (err) throw err
            ssb2.get({ id: pmsg.key, private: true }, function (err, _msg) {
              if (err) throw err
              console.log('LOAD', _msg)
              t.deepEqual(_msg, msg) // not decrypted
github Happy0 / ssb-chess / modules_core / crypto.js View on Github external
function unbox_value(msg) {
  var plaintext = ssbKeys.unbox(msg.content, keys)
  if(!plaintext) return null
  return {
    previous: msg.previous,
    author: msg.author,
    sequence: msg.sequence,
    timestamp: msg.timestamp,
    hash: msg.hash,
    content: plaintext,
    private: true
  }
}
github ssbc / ssb-server / plugins / private.js View on Github external
unbox: function (ciphertext) {
        var data
        try { data = ssbKeys.unbox(ciphertext, sbot.keys.private) }
        catch (e) { throw explain(e, 'failed to decrypt') }
        return data
      }
    }