unsigned-swarmlog

1.5.0 • Public • Published

unsigned-swarmlog

create a p2p webrtc swarm around a hyperlog

NOT cryptographically signed, as per substack's original swarmlog. Intended to be used by trusted group.

example

create a hyperlog publisher that will write a new message every second:

publish.js:

var swarmlog = require('unsigned-swarmlog')
var memdb = require('memdb')
 
var log = swarmlog({
  keys: require('./keys.json'),
  db: memdb(),
  topic: 'mytopic',
  valueEncoding: 'json',
  hubs: [ 'https://signalhub.mafintosh.com' ]
})
 
var times = 0
setInterval(function () {
  log.append({ time: Date.now(), msg: 'HELLO!x' + times })
  times++
}, 1000)

and a follower that will consume the log:

var swarmlog = require('unsigned-swarmlog')
var memdb = require('memdb')
 
var log = swarmlog({
  db: memdb(),
  topic: 'mytopic',
  valueEncoding: 'json',
  hubs: [ 'https://signalhub.mafintosh.com' ]
})
 
log.createReadStream({ live: true })
  .on('data', function (data) {
    console.log('RECEIVED', data)
  })

api

var swarmlog = require('unsigned-swarmlog')

var log = swarmlog(opts)

Create a hyperlog instance log from:

  • opts.db - a leveldb instance (use level-browserify in the browser)
  • opts.valueEncoding - valueEncoding to use for the hyperlog
  • opts.hubs - array of signalhub hubs to use
  • opts.peerStream(peer) - optional function that should return the stream to use for a peer swarm connection. Use this if you want to multiplex some other protocols on the same swarm alongside the hyperlog replication.

Optionally provide a wrtc instance as opts.wrtc to create a swarmlog in node.

log.swarm

the underlying webrtc-swarm instance

log.hub

the underlying signalhub instance

p2p

Currently the swarm relies on signalhub to assist in the webrtc swarm setup, but ideally in the future this could be replaced or augmented with a webrtc DHT.

install

npm install unsigned-swarmlog

license

BSD

Package Sidebar

Install

npm i unsigned-swarmlog

Weekly Downloads

0

Version

1.5.0

License

BSD

Last publish

Collaborators

  • brodavi