How to use chloride - 10 common examples

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 auditdrivencrypto / private-box / test / index.js View on Github external
var tape = require('tape')
var crypto = require('crypto')

var c = require('../')
var sodium = require('chloride')

var keypair = sodium.crypto_box_keypair

var alice = keypair()
var bob   = keypair()

function arrayOfSize (n) {
  return new Array(n+1).join('0').split('')
}

tape('simple', function (t) {

  var msg = new Buffer('hello there!')
  var ctxt = c.multibox(msg, [alice.publicKey, bob.publicKey])
  console.log(ctxt)

  ;[alice.secretKey, bob.secretKey].forEach(function (sk) {
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 / 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([
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)
])
github ssbc / multiserver / test / plugs.js View on Github external
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()