How to use the chloride.crypto_hash_sha256 function in chloride

To help you get started, we’ve selected a few chloride 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 / multiserver / test / plugs.js View on Github external
var pull = require('pull-stream')
var Pushable = require('pull-pushable')
var scopes = require('multiserver-scopes')

var Compose = require('../compose')
var Net = require('../plugins/net')
var Unix = require('../plugins/unix-socket')
var Ws = require('../plugins/ws')
var Shs = require('../plugins/shs')
var Onion = require('../plugins/onion')
var MultiServer = require('../')

var cl = require('chloride')
var seed = cl.crypto_hash_sha256(Buffer.from('TESTSEED'))
var keys = cl.crypto_sign_seed_keypair(seed)
var appKey = cl.crypto_hash_sha256(Buffer.from('TEST'))

var requested, ts

//this gets overwritten in the last test.
var check = function (id, cb) {
  cb(null, true)
}

//var net = Net({port: 4848, scope: 'device'})
var net = Net({port: 4848})
var ws = Ws({port: 4848})
var shs = Shs({keys: keys, appKey: appKey, auth: function (id, cb) {
  requested = id
  ts = Date.now()

  check(id, cb)
github ssbc / multiserver / test / multi.js View on Github external
var tape = require('tape')
var pull = require('pull-stream')
var Pushable = require('pull-pushable')

var Compose = require('../compose')
var Net = require('../plugins/net')
var Ws = require('../plugins/ws')
var Shs = require('../plugins/shs')
var Onion = require('../plugins/onion')
var MultiServer = require('../')

var cl = require('chloride')
var seed = cl.crypto_hash_sha256(new Buffer('TESTSEED'))
var keys = cl.crypto_sign_seed_keypair(seed)
var appKey = cl.crypto_hash_sha256(new Buffer('TEST'))

var requested, ts

//this gets overwritten in the last test.
var check = function (id, cb) {
  cb(null, true)
}

var net = Net({port: 4848, scope: 'public'})
var ws = Ws({port: 4849, scope: 'public'})
var shs = Shs({keys: keys, appKey: appKey, auth: function (id, cb) {
  requested = id
  ts = Date.now()
github ssbc / multiserver / test / shs.js View on Github external
var chloride = require('chloride')
var pull = require('pull-stream')
var tape = require('tape')
var MultiServer = require('../')
var Net = require('../protocols/net')
var Ws = require('../protocols/ws')
var Shs = require('../transforms/shs')

var alice = chloride.crypto_sign_keypair()
var bob = chloride.crypto_sign_keypair()
var app_key = chloride.crypto_hash_sha256(new Buffer('TEST'))

function party (id, cb) {
  if(id.toString('hex') === bob.publicKey.toString('hex'))
    cb(null, true)
  else
    cb(null, false)
}

var serverA = MultiServer([
  Net(),
  Ws(),
  Shs(alice, app_key, 10000, party)
])

var serverB = MultiServer([
  Net(),
github ssbc / multiserver / test / plugs.js View on Github external
var fs = require('fs')
var tape = require('tape')
var pull = require('pull-stream')
var Pushable = require('pull-pushable')
var scopes = require('multiserver-scopes')

var Compose = require('../compose')
var Net = require('../plugins/net')
var Unix = require('../plugins/unix-socket')
var Ws = require('../plugins/ws')
var Shs = require('../plugins/shs')
var Onion = require('../plugins/onion')
var MultiServer = require('../')

var cl = require('chloride')
var seed = cl.crypto_hash_sha256(Buffer.from('TESTSEED'))
var keys = cl.crypto_sign_seed_keypair(seed)
var appKey = cl.crypto_hash_sha256(Buffer.from('TEST'))

var requested, ts

//this gets overwritten in the last test.
var check = function (id, cb) {
  cb(null, true)
}

//var net = Net({port: 4848, scope: 'device'})
var net = Net({port: 4848})
var ws = Ws({port: 4848})
var shs = Shs({keys: keys, appKey: appKey, auth: function (id, cb) {
  requested = id
  ts = Date.now()
github ssbc / multiserver / test / plugs.js View on Github external
tape('shs with seed', function (t) {

  var close = combined.server(echo)

  var seed = cl.crypto_hash_sha256(Buffer.from('TEST SEED'))
  var bob = cl.crypto_sign_seed_keypair(seed)

  var checked
  check = function (id, cb) {
    checked = id
    if(id.toString('base64') === bob.publicKey.toString('base64'))
      cb(null, true)
    else
      cb(null, false)
  }

  var addr_with_seed = combined.stringify()+':'+seed.toString('base64')

  combined.client(addr_with_seed, function (err, stream) {
    t.notOk(err)
    t.deepEqual(checked, bob.publicKey)
github ssbc / multiserver / test / multi.js View on Github external
var tape = require('tape')
var pull = require('pull-stream')
var Pushable = require('pull-pushable')

var Compose = require('../compose')
var Net = require('../plugins/net')
var Ws = require('../plugins/ws')
var Shs = require('../plugins/shs')
var Onion = require('../plugins/onion')
var MultiServer = require('../')

var cl = require('chloride')
var seed = cl.crypto_hash_sha256(new Buffer('TESTSEED'))
var keys = cl.crypto_sign_seed_keypair(seed)
var appKey = cl.crypto_hash_sha256(new Buffer('TEST'))

var requested, ts

//this gets overwritten in the last test.
var check = function (id, cb) {
  cb(null, true)
}

var net = Net({port: 4848, scope: 'public'})
var ws = Ws({port: 4849, scope: 'public'})
var shs = Shs({keys: keys, appKey: appKey, auth: function (id, cb) {
  requested = id
  ts = Date.now()

  check(id, cb)
}})
github ssbc / ssb-peer-invites / cap.js View on Github external
function hash(s) {
  return chloride.crypto_hash_sha256(
    'string' == typeof s ? Buffer.from(s, 'utf8') : s
  )
}
github ssbc / ssb-peer-invites / util.js View on Github external
function hash(s) {
  return chloride.crypto_hash_sha256(
    'string' == typeof s ? Buffer.from(s, 'utf8') : s
  )
}
github ssbc / ssb-keys / util.js View on Github external
exports.hash = function (data, enc) {
  data = (
    'string' === typeof data && enc == null
  ? new Buffer(data, 'binary')
  : new Buffer(data, enc)
  )
  return cl.crypto_hash_sha256(data).toString('base64')+'.sha256'
}