How to use the ssb-keys.signObjHmac 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-server / test / client-auth.js View on Github external
tape('test api', function (t) {

  var u = require('./util')

  var server = u.createDB('test-alice', {
    port: 45451, host: 'localhost',
  })
  var alice = server.feed

  //request a secret that with particular permissions.
  var secret = server.createAccessKey({allow: ['publish']})

  var client = scuttlebot.createClient({port: 45451, host: 'localhost'})

  var signed = ssbkeys.signObjHmac(secret, {
    role: 'client',
    ts: Date.now(),
    keyId: server.options.hash(secret)
  })

  client.auth(signed, function (err, authed) {
    if(err) throw err
    t.ok(authed.granted)
    client.publish({type: 'msg', value: 'hello'}, function (err, data) {
      if(err) throw err
      t.equal(data.value.content.value, 'hello')
      client.close(function() {
        server.close()
        t.end()
      })
    })