How to use the ssb-keys.generate 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 arj03 / ssb-entitydb / test / multi-write.js View on Github external
tape('multi-write', function (t) {

    var pub = createSbot({
        temp: 'test-entitydb-multi-write-pub', timeout: 200,
        allowPrivate: true,
        keys: ssbKeys.generate()
    });

    var alice = createSbot({
        temp: 'test-entitydb-multi-write-alice', timeout: 200,
        allowPrivate: true,
        keys: ssbKeys.generate(),
        seeds: [pub.getAddress()]
    });

    var bob = createSbot({
        temp: 'test-entitydb-multi-write-bob', timeout: 200,
        allowPrivate: true,
        keys: ssbKeys.generate(),
        seeds: [pub.getAddress()]
    });

    console.log("alice is: " + alice.id);
    console.log("bob is: " + bob.id);

    t.test('alice and bob follow each other', function (t) {
        t.plan(1);
        var done = multicb();
github ssbc / ssb-db / test / related-messages.js View on Github external
module.exports = function (opts) {

  var db = sublevel(level('test-ssb-related', {
    valueEncoding: require('../codec')
  }))

  var ssb = require('../')(db, opts)

  var alice = createFeed(ssb, ssbKeys.generate(), opts)
  var bob   = createFeed(ssb, ssbKeys.generate(), opts)
  var charlie = createFeed(ssb, ssbKeys.generate(), opts)

  tape('simple', function (t) {

    alice.add({
      type: 'post',
      text: 'hello, world 1'
    }, function (err, msg) {
      if(err) throw err
      msg = toKV(msg)
      console.log(msg)

      bob.add({
        type: 'post',
        text: 'welcome! 1',
        'replies-to': msg.key
github ssbc / ssb-ebt / test / resync.js View on Github external
function track(bot, name) {
  var l = 0, _ts = Date.now(), _l = 0
  bot.post(function (msg) {
    l++
  })
  setInterval(function () {
    if(_l != l) {
      console.log(name, l, l - _l)
      _l = l
    }
  }, 1000).unref()
}

var alice = ssbKeys.generate()

  var createSbot = require('ssb-server')
    .use(require('ssb-replicate'))
    .use(require('../'))
    .use(require('ssb-friends'))

  var timeout = 2000

  var a_bot = createSbot({
    temp: 'alice',
    port: 45451, host: 'localhost', timeout: timeout,
    replicate: {hops: 3, legacy: false},
    keys: alice
  })

  bob = ssbKeys.generate()
github pietgeursen / sbot-gathering / test / util / createTestSbot.js View on Github external
function createTestBot(name) {
 return createSbot({keys: ssbKeys.generate(), temp: name})
}
github ssbc / ssb-tunnel / test / tunnel.js View on Github external
var crypto = require('crypto')
var Scuttlebot = require('ssb-server')
.use(require('ssb-gossip'))
.use(require('../'))
var tape = require('tape')

Scuttlebot

var ssbKeys = require('ssb-keys')

function hash (s) {
  return crypto.createHash('sha256').update(s).digest()
}

var a_keys = ssbKeys.generate(null, hash('alice'))
var b_keys = ssbKeys.generate(null, hash('bob'))
var c_keys = ssbKeys.generate(null, hash('carol'))

var caps = {
  shs: hash('cap')
}

tape('carol tunnels through bob to get to alice', function (t) {

  var bob = Scuttlebot({
    port: 1235, temp: true, keys: b_keys,
    caps: caps,
    tunnel: { logging: true }
  })

  var carol = Scuttlebot({
    port: 1236, temp: true, keys: c_keys, caps:caps,
github ssbc / ssb-validate / test / error.js View on Github external
var tape = require('tape')
var ssbKeys = require('ssb-keys')
var crypto = require('crypto')
var path = require('path')
var fs = require('fs')

function hash (seed) {
  return crypto.createHash('sha256').update(seed).digest()
}

function id (msg) {
  return '%'+crypto.createHash('sha256').update(JSON.stringify(msg, null, 2), 'binary').digest('base64')+'.sha256'
}

var keys = ssbKeys.generate('ed25519', hash('validation-test-seed1'))
var keys2 = ssbKeys.generate('ed25519', hash('validation-test-seed2'))


//generate randomish but deterministic test data.
//this is not intended for security use.
//use a proper key stream (etc) instead.
function pseudorandom (seed, length) {
  var a = []
  for(var l = 0; l < length; l += 32)
    a.push(hash(''+seed+l))
  return Buffer.concat(a).slice(0, length)
}

var v = require('..')

var data = []
github ssbc / ssb-peer-invites / test / invalid.js View on Github external
tape('wrong invite',  function (t) {
  var seed = hash('seed1')

  var invite = v.create(null, alice, caps.sign, i.createInvite(seed, alice.id, null, null, caps), new Date('2018-03-14T06:14:18.377Z'))
  var seed2 = hash('seed2')
  var accept_content = ssbKeys.signObj(ssbKeys.generate(null, seed2), caps.peerInvite, {
    type: 'peer-invite/accept',
    receipt: '%'+ssbKeys.hash(JSON.stringify(invite, null, 2)),
    id: bob.id,
  })
  var accept2 = v.create(null, bob, caps.sign, accept_content, new Date('2018-03-14T06:32:18.377Z'))


  //just test we do not verify the incorrect invite
  throws(t, function () {
    i.verifyAccept(accept2, invite, caps)
  }, 'peer-invites:accept-invite-signature-failed')

  t.end()
})
github ssbc / ssb-validate / test / generate.js View on Github external
var tape = require('tape')
var ssbKeys = require('ssb-keys')

var seed = require('crypto').createHash('sha256').update('validation-test-seed').digest()
var seed2 = require('crypto').createHash('sha256').update('validation-test-seed2').digest()
var keys = ssbKeys.generate('ed25519', seed)
var keys2 = ssbKeys.generate('ed25519', seed2)

var v = require('../')

function test (hmac_key) { 
  var state = v.initial()

  tape('simple', function (t) {

    var msg = v.create(null, keys, hmac_key, {type: 'test'}, +new Date('2017-04-11 8:08 UTC'))
    t.notOk(v.checkInvalidCheap(null, msg), 'cheap checks are valid')
    t.notOk(v.checkInvalid(null, hmac_key, msg), 'signature is valid')

    //append sets the state for this author,
    //as well as appends the message to the queue.
    state = v.append(state, hmac_key, msg)
github ssbc / ssb-server / test / server.js View on Github external
keys: alice = ssbKeys.generate(),
    //replicate: {legacy: false},
    level: 'info'
  })
  var dbB = createSsbServer({
    temp: 'server-bob',
    port: 45452, timeout: 1400,
    keys: bob = ssbKeys.generate(),
    seeds: [dbA.getAddress()],
    //replicate: {legacy: false},
    level: 'info'
  })
  var dbC = createSsbServer({
    temp: 'server-carol',
    port: 45453, timeout: 1400,
    keys: carol = ssbKeys.generate(),
    seeds: [dbA.getAddress()],
    //replicate: {legacy: false},
    level: 'info'
  })

  var apub = cont(dbA.publish)
  var bpub = cont(dbB.publish)
  var cpub = cont(dbC.publish)

  cont.para([
    apub(u.pub(dbA.getAddress())),
    bpub(u.pub(dbB.getAddress())),
    cpub(u.pub(dbC.getAddress())),

    apub(u.follow(bob.id)),
    apub(u.follow(carol.id)),
github ssbc / ssb-server / test / block2.js View on Github external
var cont = require('cont')
var tape = require('tape')
var pull = require('pull-stream')
var ssbKeys = require('ssb-keys')
var u = require('./util')

var createSsbServer = require('../')
    .use(require('../plugins/replicate'))
    .use(require('ssb-friends'))
    .use(require('ssb-ebt'))

var alice = createSsbServer({
    temp: 'test-block-alice', //timeout: 1400,
    keys: ssbKeys.generate()
  })

var bob = createSsbServer({
    temp: 'test-block-bob', //timeout: 600,
    keys: ssbKeys.generate()
  })

tape('alice blocks bob while he is connected, she should disconnect him', function (t) {

  //in the beginning alice and bob follow each other
  cont.para([
    alice.publish(u.follow(bob.id)),
    bob  .publish(u.follow(alice.id))
  ]) (function (err) {
    if(err) throw err